/** * If a post has been done, gather all the posted data * and save it to the database */ protected function executeSave() { if (!empty($_POST)) { // save new config $clean = array('language' => $_POST['language'], 'sms_gateway' => $_POST['sms_gateway'], 'alert_type' => $_POST['alert_type'], 'email_smtp_security' => in_array($_POST['email_smtp_security'], array('', 'ssl', 'tls')) ? $_POST['email_smtp_security'] : '', 'auto_refresh_servers' => intval(psm_POST('auto_refresh_servers', 0)), 'log_retention_period' => intval(psm_POST('log_retention_period', 365)), 'password_encrypt_key' => psm_POST('password_encrypt_key', sha1(microtime()))); foreach ($this->checkboxes as $input_key) { $clean[$input_key] = isset($_POST[$input_key]) ? '1' : '0'; } foreach ($this->fields as $input_key) { if (isset($_POST[$input_key])) { $clean[$input_key] = $_POST[$input_key]; } } $language_refresh = $clean['language'] != psm_get_conf('language'); foreach ($clean as $key => $value) { psm_update_conf($key, $value); } $this->addMessage(psm_get_lang('config', 'updated'), 'success'); if (!empty($_POST['test_email'])) { $this->testEmail(); } elseif (!empty($_POST['test_sms'])) { $this->testSMS(); } elseif (!empty($_POST['test_pushover'])) { $this->testPushover(); } if ($language_refresh) { header('Location: ' . psm_build_url(array('mod' => 'config'), true, false)); die; } if (isset($_POST['general_submit'])) { $this->default_tab = 'general'; } elseif (isset($_POST['email_submit']) || !empty($_POST['test_email'])) { $this->default_tab = 'email'; } elseif (isset($_POST['sms_submit']) || !empty($_POST['test_sms'])) { $this->default_tab = 'sms'; } elseif (isset($_POST['pushover_submit']) || !empty($_POST['test_pushover'])) { $this->default_tab = 'pushover'; } } return $this->runAction('index'); }
/** * Check if an update is available for PHP Server Monitor. * * Will only check for new version if user turned updates on in config. * @return boolean */ function psm_update_available() { if (!psm_get_conf('show_update')) { // user does not want updates, fair enough. return false; } $last_update = psm_get_conf('last_update_check'); if (time() - PSM_UPDATE_INTERVAL > $last_update) { // been more than a week since update, lets go // update last check date psm_update_conf('last_update_check', time()); $latest = psm_curl_get(PSM_UPDATE_URL); // add latest version to database if ($latest !== false && strlen($latest) < 15) { psm_update_conf('version_update_check', $latest); } } else { $latest = psm_get_conf('version_update_check'); } if ($latest != false) { $current = psm_get_conf('version'); return version_compare($latest, $current, '>'); } else { return false; } }
/** * Upgrade for v3.2.0 release */ protected function upgrade320() { $queries = array(); psm_update_conf('password_encrypt_key', sha1(microtime())); $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `ip` `ip` VARCHAR(500) NOT NULL;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `website_username` varchar(255) NULL, ADD `website_password` varchar(255) NULL AFTER `website_username`;"; $this->execSQL($queries); }
protected function upgrade310() { $queries = array(); psm_update_conf('log_retention_period', '365'); psm_update_conf('pushover_status', 0); psm_update_conf('log_pushover', 1); psm_update_conf('pushover_api_token', ''); $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "users` ADD `pushover_key` VARCHAR( 255 ) NOT NULL AFTER `mobile`;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "users` ADD `pushover_device` VARCHAR( 255 ) NOT NULL AFTER `pushover_key`;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `pushover` ENUM( 'yes','no' ) NOT NULL DEFAULT 'yes' AFTER `sms`;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "log` CHANGE `type` `type` ENUM( 'status', 'email', 'sms', 'pushover' ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `timeout` smallint(1) unsigned NULL DEFAULT NULL;"; $queries[] = "CREATE TABLE IF NOT EXISTS `" . PSM_DB_PREFIX . "users_preferences` (\n\t\t\t\t\t\t`user_id` int(11) unsigned NOT NULL,\n\t\t\t\t\t\t`key` varchar(255) NOT NULL,\n\t\t\t\t\t\t`value` varchar(255) NOT NULL,\n\t\t\t\t\t\tPRIMARY KEY (`user_id`, `key`)\n\t\t\t\t\t ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; $this->execSQL($queries); }
foreach ($_SERVER['argv'] as $argv) { $argi = explode('=', ltrim($argv, '--')); if (count($argi) !== 2) { continue; } switch ($argi[0]) { case 'uri': define('PSM_BASE_URL', $argi[1]); break; case 'timeout': $cron_timeout = intval($argi[1]); break; } } } // prevent cron from running twice at the same time // however if the cron has been running for X mins, we'll assume it died and run anyway // if you want to change PSM_CRON_TIMEOUT, have a look in src/includes/psmconfig.inc.php. // or you can provide the --timeout=x argument $time = time(); if (psm_get_conf('cron_running') == 1 && $cron_timeout > 0 && $time - psm_get_conf('cron_running_time') < $cron_timeout) { die('Cron is already running. Exiting.'); } if (!defined('PSM_DEBUG') || !PSM_DEBUG) { psm_update_conf('cron_running', 1); } psm_update_conf('cron_running_time', $time); $autorun = $router->getService('util.server.updatemanager'); $autorun->run(true); psm_update_conf('cron_running', 0);