return $cache;
}
-// Database version detector. Should behave corretly on any
-// working dataset a user might have.
-function getDatabaseVersion ()
-{
- $result = usePreparedSelectBlade ('SELECT varvalue FROM Config WHERE varname = "DB_VERSION" and vartype = "string"');
- if ($result == NULL)
- {
- // FIXME: this code is never executed, but an exception thrown instead
- global $dbxlink;
- $errorInfo = $dbxlink->errorInfo();
- if ($errorInfo[0] == '42S02') // ER_NO_SUCH_TABLE
- return '0.14.4';
- die (__FUNCTION__ . ': SQL query #1 failed with error ' . $errorInfo[2]);
- }
- $rows = $result->fetchAll (PDO::FETCH_NUM);
- unset ($result);
- if (count ($rows) != 1 || !strlen ($rows[0][0]))
- die (__FUNCTION__ . ': Cannot guess database version. Config table is present, but DB_VERSION is missing or invalid. Giving up.');
- $ret = $rows[0][0];
- return $ret;
-}
-
// Return an array of virtual services. For each of them list real server pools
// with their load balancers and other stats.
function getSLBSummary ()
if (isset ($_SERVER['REMOTE_USER']))
$_SERVER['REMOTE_USER'] = escapeString ($_SERVER['REMOTE_USER']);
-$dbver = getDatabaseVersion();
-if ($dbver != CODE_VERSION)
+loadConfigDefaults();
+
+if (getConfigVar ('DB_VERSION') != CODE_VERSION)
{
echo '<p align=justify>This Racktables installation seems to be ' .
'just upgraded to version ' . CODE_VERSION . ', while the '.
- 'database version is ' . $dbver . '.<br>No user will be ' .
+ 'database version is ' . getConfigVar ('DB_VERSION') . '.<br>No user will be ' .
'either authenticated or shown any page until the upgrade is ' .
"finished.<br>Follow <a href='upgrade.php'>this link</a> and " .
'authenticate as administrator to finish the upgrade.</p>';
if (!mb_internal_encoding ('UTF-8'))
throw new RackTablesError ('Failed setting multibyte string encoding to UTF-8', RackTablesError::INTERNAL);
-loadConfigDefaults();
-
$rackCodeCache = loadScript ('RackCodeCache');
if ($rackCodeCache == NULL or !strlen ($rackCodeCache))
{
// create tables for storing files (requires InnoDB support)
if (!isInnoDBSupported ())
{
- showError ("Cannot upgrade because InnoDB tables are not supported by your MySQL server. See the README for details.", 'inline');
+ showError ("Cannot upgrade because InnoDB tables are not supported by your MySQL server. See the README for details.");
die;
}
$query[] = "UPDATE Config SET varvalue = '0.19.0' WHERE varname = 'DB_VERSION'";
break;
default:
- showError ("executeUpgradeBatch () failed, because batch '${batchid}' isn't defined", 'inline');
+ showError ("executeUpgradeBatch () failed, because batch '${batchid}' isn't defined");
die;
break;
}
// ******************************************************************
require_once 'inc/config.php'; // for CODE_VERSION
-require_once 'inc/functions.php'; // for showError()
-require_once 'inc/database.php'; // for getDatabaseVersion()
require_once 'inc/dictionary.php';
// Enforce default value for now, releases prior to 0.17.0 didn't support 'httpd' auth source.
$user_auth_src = 'database';
return $rows[0][0] == 1;
}
+// Database version detector. Should behave corretly on any
+// working dataset a user might have.
+function getDatabaseVersion ()
+{
+ $result = usePreparedSelectBlade ('SELECT varvalue FROM Config WHERE varname = "DB_VERSION" and vartype = "string"');
+ if ($result == NULL)
+ {
+ // FIXME: this code is never executed, but an exception thrown instead
+ global $dbxlink;
+ $errorInfo = $dbxlink->errorInfo();
+ if ($errorInfo[0] == '42S02') // ER_NO_SUCH_TABLE
+ return '0.14.4';
+ die (__FUNCTION__ . ': SQL query #1 failed with error ' . $errorInfo[2]);
+ }
+ $rows = $result->fetchAll (PDO::FETCH_NUM);
+ unset ($result);
+ if (count ($rows) != 1 || !strlen ($rows[0][0]))
+ die (__FUNCTION__ . ': Cannot guess database version. Config table is present, but DB_VERSION is missing or invalid. Giving up.');
+ $ret = $rows[0][0];
+ return $ret;
+}
+
+function showError ($info = '', $location = 'upgrade.php')
+{
+ if (preg_match ('/\.php$/', $location))
+ $location = basename ($location);
+ elseif ($location != 'N/A')
+ $location = $location . '()';
+ echo "<div class=msg_error>An error has occured in [${location}]. ";
+ if (!strlen ($info))
+ echo 'No additional information is available.';
+ else
+ echo "Additional information:<br><p>\n<pre>\n${info}\n</pre></p>";
+ echo "Go back or try starting from <a href='".makeHref()."'>index page</a>.<br></div>\n";
+}
+
switch ($user_auth_src)
{
case 'database':
{
header ('WWW-Authenticate: Basic realm="RackTables upgrade"');
header ('HTTP/1.0 401 Unauthorized');
- showError ('You must be authenticated as an administrator to complete the upgrade.', 'inline');
+ showError ('You must be authenticated as an administrator to complete the upgrade.');
die;
}
break; // cleared
!strlen ($_SERVER['REMOTE_USER'])
)
{
- showError ('System misconfiguration. The web-server didn\'t authenticate the user, although ought to do.', 'inline');
+ showError ('System misconfiguration. The web-server didn\'t authenticate the user, although ought to do.');
die;
}
break; // cleared
default:
- showError ('authentication source misconfiguration', 'inline');
+ showError ('authentication source misconfiguration');
die;
}