From d00cdec296569aa0d565643faccf55e50a6b49ca Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Tue, 25 Feb 2014 07:48:46 +0100 Subject: [PATCH] added cronjob-auto-update-feature (beware and READ), fixes #1342; remove old backup-ftp-users on update, fixes #1381 Signed-off-by: Michael Kaufmann (d00p) --- actions/admin/settings/125.cronjob.php | 18 ++++++- install/froxlor.sql | 4 +- install/lib/class.FroxlorInstall.php | 2 +- .../updates/froxlor/0.9/update_0.9.inc.php | 26 +++++++++ .../preconfig/0.9/preconfig_0.9.inc.php | 8 +++ lib/cron_init.php | 53 +++++++++++++------ .../function.checkCrondConfigurationFile.php | 7 ++- lib/tables.inc.php | 2 +- lng/english.lng.php | 2 + lng/german.lng.php | 2 + 10 files changed, 103 insertions(+), 21 deletions(-) diff --git a/actions/admin/settings/125.cronjob.php b/actions/admin/settings/125.cronjob.php index fa8246d6..e23a2379 100644 --- a/actions/admin/settings/125.cronjob.php +++ b/actions/admin/settings/125.cronjob.php @@ -29,6 +29,14 @@ return array( 'default' => '/etc/cron.d/froxlor', 'save_method' => 'storeSettingField', ), + 'system_croncmdline' => array( + 'label' => $lng['serversettings']['system_croncmdline'], + 'settinggroup' => 'system', + 'varname' => 'croncmdline', + 'type' => 'string', + 'default' => '/usr/bin/nice -n 5 /usr/bin/php5 -q', + 'save_method' => 'storeSettingField', + ), 'system_crondreload' => array( 'label' => $lng['serversettings']['system_crondreload'], 'settinggroup' => 'system', @@ -36,7 +44,15 @@ return array( 'type' => 'string', 'default' => '/etc/init.d/cron reload', 'save_method' => 'storeSettingField', - ), + ), + 'system_cron_allowautoupdate' => array( + 'label' => $lng['serversettings']['system_cron_allowautoupdate'], + 'settinggroup' => 'system', + 'varname' => 'cron_allowautoupdate', + 'type' => 'bool', + 'default' => false, + 'save_method' => 'storeSettingField', + ), 'system_debug_cron' => array( 'label' => $lng['serversettings']['cron']['debug'], 'settinggroup' => 'system', diff --git a/install/froxlor.sql b/install/froxlor.sql index 583120cc..ce4fdec7 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -501,6 +501,8 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'mailtraffic_enabled', '1'), ('system', 'cronconfig', '/etc/cron.d/froxlor'), ('system', 'crondreload', '/etc/init.d/cron reload'), + ('system', 'croncmdline', '/usr/bin/nice -n 5 /usr/bin/php5 -q'), + ('system', 'cron_allowautoupdate', '0'), ('panel', 'decimal_places', '4'), ('panel', 'adminmail', 'admin@SERVERNAME'), ('panel', 'phpmyadmin_url', ''), @@ -528,7 +530,7 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('panel', 'phpconfigs_hidestdsubdomain', '0'), ('panel', 'allow_theme_change_admin', '1'), ('panel', 'allow_theme_change_customer', '1'), - ('panel', 'version', '0.9.32-rc1'); + ('panel', 'version', '0.9.32-rc2'); DROP TABLE IF EXISTS `panel_tasks`; diff --git a/install/lib/class.FroxlorInstall.php b/install/lib/class.FroxlorInstall.php index a3742b94..894c30e3 100644 --- a/install/lib/class.FroxlorInstall.php +++ b/install/lib/class.FroxlorInstall.php @@ -275,7 +275,7 @@ class FroxlorInstall { $navigation = ''; $msgcolor = 'red'; $message = $this->_lng['install']['testing_mysql_fail']; - $link = 'install.php'; + $link = 'install.php?check=1'; $linktext = $this->_lng['click_here_to_goback']; } else { // all good diff --git a/install/updates/froxlor/0.9/update_0.9.inc.php b/install/updates/froxlor/0.9/update_0.9.inc.php index 7e2256c6..a5f86bbc 100644 --- a/install/updates/froxlor/0.9/update_0.9.inc.php +++ b/install/updates/froxlor/0.9/update_0.9.inc.php @@ -2727,3 +2727,29 @@ if (isFroxlorVersion('0.9.32-dev6')) { updateToVersion('0.9.32-rc1'); } + +if (isFroxlorVersion('0.9.32-rc1')) { + + showUpdateStep("Updating from 0.9.32-rc1 to 0.9.32-rc2", false); + + showUpdateStep("Removing autoresponder-cronjob (deprecated)"); + Database::query("DELETE FROM `".TABLE_PANEL_CRONRUNS."` WHERE `module` = 'froxlor/autoresponder';"); + lastStepStatus(0); + + showUpdateStep("Adding new settings for cron"); + // get user-chosen value + $croncmdline = isset($_POST['croncmdline']) ? $_POST['croncmdline'] : "/usr/bin/nice -n 5 /usr/bin/php5 -q"; + Settings::AddNew("system.croncmdline", $croncmdline); + // add task to generate cron.d-file + inserttask('99'); + // silenty add the auto-update setting - we do not want everybody to know and use this + // as it is a very dangerous setting + Settings::AddNew("system.cron_allowautoupdate", 0); + lastStepStatus(0); + + showUpdateStep("Removing backup-module ftp-users (deprecated)"); + Database::query("DELETE FROM `".TABLE_FTP_USERS."` WHERE `username` LIKE '%_backup';"); + lastStepStatus(0); + + updateToVersion('0.9.32-rc2'); +} diff --git a/install/updates/preconfig/0.9/preconfig_0.9.inc.php b/install/updates/preconfig/0.9/preconfig_0.9.inc.php index 670f3be9..f830de38 100644 --- a/install/updates/preconfig/0.9/preconfig_0.9.inc.php +++ b/install/updates/preconfig/0.9/preconfig_0.9.inc.php @@ -650,4 +650,12 @@ function parseAndOutputPreconfig(&$has_preconfig, &$return, $current_version) { eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";"); } + if (versionInUpdate($current_version, '0.9.32-rc2')) { + $has_preconfig = true; + $description = 'To customize the command which executes the cronjob (php - basically) change the path below according to your system.

'; + $question = 'Please specify the command to execute cronscripts (default: "/usr/bin/nice -n 5 /usr/bin/php5 -q")
'; + $question.= '
'; + eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";"); + } + } diff --git a/lib/cron_init.php b/lib/cron_init.php index 87ffa74a..28c4acfb 100644 --- a/lib/cron_init.php +++ b/lib/cron_init.php @@ -64,7 +64,7 @@ $lockDirHandle = opendir($lockdir); while ($fName = readdir($lockDirHandle)) { if ($lockFilename == substr($fName, 0, strlen($lockFilename)) - && $lockfName != $fName + && $lockfName != $fName ) { // Check if last run jailed out with an exception $croncontent = file($lockdir . $fName); @@ -169,19 +169,44 @@ if (((int)Settings::Get('system.mod_fcgid') == 1 && (int)Settings::Get('system.m // be sure HTMLPurifier's cache folder is writable safe_exec('chmod -R 0755 '.escapeshellarg(dirname(__FILE__).'/classes/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer')); +// Initialize logging +$cronlog = FroxlorLogger::getInstanceOf(array('loginname' => 'cronjob')); +fwrite($debugHandler, 'Logger has been included' . "\n"); + if (Settings::Get('panel.version') == null - || Settings::Get('panel.version') != $version + || Settings::Get('panel.version') != $version ) { - /** - * Do not proceed further if the Database version is not the same as the script version - */ - fclose($debugHandler); - unlink($lockfile); - $errormessage = "Version of file doesnt match version of database. Exiting...\n\n"; - $errormessage.= "Possible reason: Froxlor update\n"; - $errormessage.= "Information: Current version in database: ".Settings::Get('panel.version')." - version of Froxlor files: ".$version."\n"; - $errormessage.= "Solution: Please visit your Foxlor admin interface for further information.\n"; - die($errormessage); + if (Settings::Get('system.cron_allowautoupdate') == null + || Settings::Get('system.cron_allowautoupdate') == 0 + ) { + /** + * Do not proceed further if the Database version is not the same as the script version + */ + fclose($debugHandler); + unlink($lockfile); + $errormessage = "Version of file doesnt match version of database. Exiting...\n\n"; + $errormessage.= "Possible reason: Froxlor update\n"; + $errormessage.= "Information: Current version in database: ".Settings::Get('panel.version')." - version of Froxlor files: ".$version."\n"; + $errormessage.= "Solution: Please visit your Foxlor admin interface for further information.\n"; + die($errormessage); + } + + if (Settings::Get('system.cron_allowautoupdate') == 1) { + /** + * let's walk the walk - do the dangerous shit + */ + $cronlog->logAction(CRON_ACTION, LOG_WARNING, 'Automatic update is activated and we are going to proceed without any notices'); + $cronlog->logAction(CRON_ACTION, LOG_WARNING, 'all new settings etc. will be stored with the default value, that might not always be right for your system!'); + $cronlog->logAction(CRON_ACTION, LOG_WARNING, 'If you dont want this to happen in the future consider removing the --allow-autoupdate flag from the cronjob'); + fwrite($debugHandler, '*** WARNING *** - Automatic update is activated and we are going to proceed without any notices' . "\n"); + fwrite($debugHandler, '*** WARNING *** - all new settings etc. will be stored with the default value, that might not always be right for your system!' . "\n"); + fwrite($debugHandler, '*** WARNING *** - If you dont want this to happen in the future consider removing the --allow-autoupdate flag from the cronjob' . "\n"); + // including update procedures + include_once FROXLOR_INSTALL_DIR.'/install/updatesql.php'; + // pew - everything went better than expected + $cronlog->logAction(CRON_ACTION, LOG_WARNING, 'Automatic update done - you should check your settings to be sure everything is fine'); + fwrite($debugHandler, '*** WARNING *** - Automatic update done - you should check your settings to be sure everything is fine' . "\n"); + } } fwrite($debugHandler, 'Froxlor version and database version are correct' . "\n"); @@ -191,9 +216,5 @@ $cronscriptDebug = (Settings::Get('system.debug_cron') == '1') ? true : false; // Create a new idna converter $idna_convert = new idna_convert_wrapper(); -// Initialize logging -$cronlog = FroxlorLogger::getInstanceOf(array('loginname' => 'cronjob')); -fwrite($debugHandler, 'Logger has been included' . "\n"); - // check for cron.d-generation task and create it if necessary checkCrondConfigurationFile(); diff --git a/lib/functions/froxlor/function.checkCrondConfigurationFile.php b/lib/functions/froxlor/function.checkCrondConfigurationFile.php index bffb7795..7490e03d 100644 --- a/lib/functions/froxlor/function.checkCrondConfigurationFile.php +++ b/lib/functions/froxlor/function.checkCrondConfigurationFile.php @@ -80,7 +80,12 @@ function checkCrondConfigurationFile() { } // create entry-line - $binpath = "/usr/bin/nice -n 5 /usr/bin/php5 -q"; + $binpath = Settings::Get("system.croncmdline"); + // fallback as it is important + if ($binpath === null) { + $binpath = "/usr/bin/nice -n 5 /usr/bin/php5 -q"; + } + $cronfile .= "root " . $binpath." " . FROXLOR_INSTALL_DIR . "/scripts/froxlor_master_cronjob.php --" . $row_cronentry['cronfile'] . " 1> /dev/null\n"; } } diff --git a/lib/tables.inc.php b/lib/tables.inc.php index e0120774..f9d37b4d 100644 --- a/lib/tables.inc.php +++ b/lib/tables.inc.php @@ -51,6 +51,6 @@ define('TABLE_PANEL_DOMAIN_SSL_SETTINGS', 'domain_ssl_settings'); define('TABLE_DOMAINTOIP', 'panel_domaintoip'); // VERSION INFO -$version = '0.9.32-rc1'; +$version = '0.9.32-rc2'; $dbversion = '2'; $branding = ''; diff --git a/lng/english.lng.php b/lng/english.lng.php index f885aca4..fe4cbdd4 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1815,3 +1815,5 @@ $lng['serversettings']['system_croncmdline']['title'] = 'Cron execution command $lng['serversettings']['system_croncmdline']['description'] = 'Command to execute our cronjobs. Change this only if you know what you are doing (default: "/usr/bin/nice -n 5 /usr/bin/php5 -q")!'; $lng['error']['cannotdeletehostnamephpconfig'] = 'This PHP-configuration is used by the Froxlor-vhost and cannot be deleted.'; $lng['error']['cannotdeletedefaultphpconfig'] = 'This PHP-configuration is set as default and cannot be deleted.'; +$lng['serversettings']['system_cron_allowautoupdate']['title'] = 'Allow automatic database updates'; +$lng['serversettings']['system_cron_allowautoupdate']['description'] = '
ATTENTION:
This settings allows the cronjob to bypass the version-check of froxlors files and database and runs the database-updates in case a version-mismatch occurs.

Auto-update will always set default values for new settings or changes. This might not always suite your system. Please think twice before activating this option
'; diff --git a/lng/german.lng.php b/lng/german.lng.php index 2e66dd04..f79da0d1 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1540,3 +1540,5 @@ $lng['serversettings']['system_croncmdline']['title'] = 'Cron Startbefehl (php P $lng['serversettings']['system_croncmdline']['description'] = 'Befehl zum Ausführen des Cronjobs. Ändern dieser Einstellung nur wenn nötig (Standard: "/usr/bin/nice -n 5 /usr/bin/php5 -q")!'; $lng['error']['cannotdeletehostnamephpconfig'] = 'Diese PHP-Konfiguration ist dem Froxlor-Vhost zugewiesen und kann daher nicht gelöscht werden.'; $lng['error']['cannotdeletedefaultphpconfig'] = 'Diese PHP-Konfiguration ist als Standard hinterlegt und kann daher nicht gelöscht werden.'; +$lng['serversettings']['system_cron_allowautoupdate']['title'] = 'Erlaube automatische Datenbank-Aktualisierungen'; +$lng['serversettings']['system_cron_allowautoupdate']['description'] = '
WARNUNG:
Diese Einstellung erlaubt es dem Cronjob die Prüfung der Dateien- und Datenbank-Version zu umgehen und bei einem Versions-Unterschied die Datenbank-Aktualisierungen automatisiert auszuführen.

Das automatische Update setzt für neue Einstellungen und Änderungen immer die default-Werte. Diese müssen nicht zwingend zu dem genutzten System passen. Bitte zwei mal nachdenken, bevor diese Option aktiviert wird.
';