SF.net SVN: postfixadmin:[1853] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2016-05-22 19:58:56
|
Revision: 1853 http://sourceforge.net/p/postfixadmin/code/1853 Author: christian_boltz Date: 2016-05-22 19:58:54 +0000 (Sun, 22 May 2016) Log Message: ----------- Add checks to login.php and cli to ensure database layout is up to date - add check_db_version() to functions.inc.php - add $min_db_version (needs to be updated at least before the release) - call check_db_version in login.php, users/login.php and CLI - they'll error out if the database layout is outdated - change setup.php to use check_db_version() Modified Paths: -------------- trunk/functions.inc.php trunk/login.php trunk/scripts/postfixadmin-cli.php trunk/upgrade.php trunk/users/login.php Modified: trunk/functions.inc.php =================================================================== --- trunk/functions.inc.php 2016-05-22 19:26:52 UTC (rev 1852) +++ trunk/functions.inc.php 2016-05-22 19:58:54 UTC (rev 1853) @@ -16,6 +16,7 @@ */ $version = '2.93'; +$min_db_version = 1835; # update (at least) before a release with the latest function numbrer in upgrade.php /** * check_session @@ -1754,8 +1755,35 @@ return $CONF['database_prefix'].$table; } +/* + * check if the database layout is up to date + * returns the current 'version' value from the config table + * if $error_out is True (default), die() with a message that recommends to run setup.php. + */ +function check_db_version($error_out = True) { + global $min_db_version; + $table = table_by_key('config'); + $sql = "SELECT value FROM $table WHERE name = 'version'"; + $r = db_query($sql); + + if($r['rows'] == 1) { + $row = db_assoc($r['result']); + $dbversion = $row['value']; + } else { + $dbversion = 0; + db_query("INSERT INTO $table (name, value) VALUES ('version', '0')", 0, ''); + } + + if ( ($dbversion < $min_db_version) && $error_out == True) { + echo "ERROR: The PostfixAdmin database layout is outdated (you have r$dbversion, but r$min_db_version is expected).\nPlease run setup.php to upgrade the database.\n"; + exit(1); + } + + return $dbversion; +} + /* Called after an alias_domain has been deleted in the DBMS. Returns: boolean. Modified: trunk/login.php =================================================================== --- trunk/login.php 2016-05-22 19:26:52 UTC (rev 1852) +++ trunk/login.php 2016-05-22 19:58:54 UTC (rev 1853) @@ -34,6 +34,7 @@ exit; } +check_db_version(); # check if the database layout is up to date (and error out if not) if ($_SERVER['REQUEST_METHOD'] == "POST") { Modified: trunk/scripts/postfixadmin-cli.php =================================================================== --- trunk/scripts/postfixadmin-cli.php 2016-05-22 19:26:52 UTC (rev 1852) +++ trunk/scripts/postfixadmin-cli.php 2016-05-22 19:58:54 UTC (rev 1853) @@ -177,6 +177,9 @@ return false; } + # make sure global variables fron functions.inc.php end up in the global namespace, instead of being local to this function + global $version, $min_db_version; + if (!require_once(PATH . '/common.php')) { $this->stderr("Failed to load " . PATH . '/common.php'); return false; @@ -190,6 +193,8 @@ public function dispatch() { $CONF = Config::read('all'); + check_db_version(); # ensure the database layout is up to date + if (!isset($this->args[0])) { $this->help(); return; Modified: trunk/upgrade.php =================================================================== --- trunk/upgrade.php 2016-05-22 19:26:52 UTC (rev 1852) +++ trunk/upgrade.php 2016-05-22 19:58:54 UTC (rev 1853) @@ -131,21 +131,7 @@ db_query_parsed($mysql, 0, " ENGINE = MYISAM COMMENT = 'PostfixAdmin settings'"); } -$sql = "SELECT * FROM $table WHERE name = 'version'"; - -// insert into config('version', '01'); - -$r = db_query($sql); - -if($r['rows'] == 1) { - $rs = $r['result']; - $row = db_array($rs); - $version = $row['value']; -} else { - db_query_parsed("INSERT INTO $table (name, value) VALUES ('version', '0')", 0, ''); - $version = 0; -} - +$version = check_db_version(False); _do_upgrade($version); function _do_upgrade($current_version) { Modified: trunk/users/login.php =================================================================== --- trunk/users/login.php 2016-05-22 19:26:52 UTC (rev 1852) +++ trunk/users/login.php 2016-05-22 19:58:54 UTC (rev 1853) @@ -30,6 +30,7 @@ define('POSTFIXADMIN_LOGOUT', 1); require_once("../common.php"); +check_db_version(); # check if the database layout is up to date (and error out if not) if ($_SERVER['REQUEST_METHOD'] == "POST") { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |