You've already forked postfixadmin
mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2025-07-29 22:41:11 +03:00
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() git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1853 a1433add-5e2c-0410-b055-b7f2511e0802
This commit is contained in:
@ -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,7 +1755,34 @@ function table_by_key ($table_key) {
|
||||
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.
|
||||
|
@ -34,6 +34,7 @@ if($CONF['configured'] !== true) {
|
||||
exit;
|
||||
}
|
||||
|
||||
check_db_version(); # check if the database layout is up to date (and error out if not)
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == "POST")
|
||||
{
|
||||
|
@ -177,6 +177,9 @@ class PostfixAdmin {
|
||||
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 @@ class PostfixAdmin {
|
||||
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;
|
||||
|
16
upgrade.php
16
upgrade.php
@ -131,21 +131,7 @@ if($CONF['database_type'] == 'pgsql') {
|
||||
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) {
|
||||
|
@ -30,6 +30,7 @@ $rel_path = '../';
|
||||
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")
|
||||
{
|
||||
|
Reference in New Issue
Block a user