From 6e190639724dcb7216d935003999fd1c69b278fa Mon Sep 17 00:00:00 2001 From: Pepijn Over Date: Sat, 8 Feb 2014 18:40:22 +0100 Subject: [PATCH] Adding new install mode with upgrade support. Config file has been moved one more (and last..) time so its back in the root directory. --- ...config.inc.php.sample => config.php.sample | 6 - install.php | 126 +------ src/bootstrap.php | 37 +- src/includes/functions.inc.php | 12 +- src/lang/br.lang.php | 1 + src/lang/de.lang.php | 1 + src/lang/en.lang.php | 1 + src/lang/fr.lang.php | 1 + src/lang/kr.lang.php | 1 + src/lang/nl.lang.php | 1 + src/psm/Module/AbstractModule.class.php | 64 ++-- src/psm/Module/Install.class.php | 321 ++++++++++++++++++ src/psm/Util/Install/Queries.class.php | 132 +++++++ src/templates/install.tpl.html | 137 +++++--- src/templates/main.tpl.html | 76 ++--- src/templates/servers.tpl.html | 5 - src/templates/users.tpl.html | 3 - static/js/scripts.js | 15 + 18 files changed, 675 insertions(+), 265 deletions(-) rename src/includes/config.inc.php.sample => config.php.sample (92%) create mode 100644 src/psm/Module/Install.class.php create mode 100644 src/psm/Util/Install/Queries.class.php diff --git a/src/includes/config.inc.php.sample b/config.php.sample similarity index 92% rename from src/includes/config.inc.php.sample rename to config.php.sample index 6b740bcd..b36afe6d 100755 --- a/src/includes/config.inc.php.sample +++ b/config.php.sample @@ -26,15 +26,9 @@ **/ define('PSM_CONFIG', true); -// Prefix used for tables define('PSM_DB_PREFIX', 'monitor_'); -// Database username define('PSM_DB_USER', 'db_user'); -// Database password define('PSM_DB_PASS', 'db_pass'); -// Database name define('PSM_DB_NAME', 'db_name'); -// Database host define('PSM_DB_HOST', 'localhost'); - ?> \ No newline at end of file diff --git a/install.php b/install.php index 3dd19100..054283dc 100755 --- a/install.php +++ b/install.php @@ -25,127 +25,15 @@ * @link http://phpservermon.neanderthal-technology.com/ **/ -// this script creates all the database tables required for server monitor -error_reporting(0x0ffffff); +define('PSM_INSTALL', true); require 'src/bootstrap.php'; -if(!function_exists('curl_init')) { - die('PHP is installed without the cURL module. Please install cURL first.'); -} +psm_no_cache(); -$tpl = new psm\Service\Template(); +$type = 'install'; +$tpl = new \psm\Service\Template(); +$mod = new psm\Module\Install($db, $tpl); +$mod->initialize(); -$tpl->newTemplate('install', 'install.tpl.html'); - - -if(!is_resource($db->getLink())) { - // no valid db info - $tpl->addTemplatedata( - 'install', - array('error' => 'Couldn\'t connect to database!') - ); - echo $tpl->display('install'); - die(); -} - -$tables = array( - 'users' => - array( - 0 => "CREATE TABLE `" . PSM_DB_PREFIX . "users` ( - `user_id` int(11) NOT NULL auto_increment, - `server_id` varchar(255) NOT NULL, - `name` varchar(255) NOT NULL, - `mobile` varchar(15) NOT NULL, - `email` varchar(255) NOT NULL, - PRIMARY KEY (`user_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", - 1 => "INSERT INTO `" . PSM_DB_PREFIX . "users` (`server_id`, `name`, `mobile`, `email`) VALUES ('1,2', 'example_user', '0123456789', 'user@example.com')" - ), - 'log' => - array( - 0 => "CREATE TABLE `" . PSM_DB_PREFIX . "log` ( - `log_id` int(11) NOT NULL auto_increment, - `server_id` int(11) NOT NULL, - `type` enum('status','email','sms') NOT NULL, - `message` varchar(255) NOT NULL, - `datetime` timestamp NOT NULL default CURRENT_TIMESTAMP, - `user_id` varchar(255) NOT NULL, - PRIMARY KEY (`log_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", - ), - 'servers' => - array( - 0 => "CREATE TABLE `" . PSM_DB_PREFIX . "servers` ( - `server_id` int(11) NOT NULL auto_increment, - `ip` varchar(100) NOT NULL, - `port` int(5) NOT NULL, - `label` varchar(255) NOT NULL, - `type` enum('service','website') NOT NULL default 'service', - `status` enum('on','off') NOT NULL default 'on', - `error` varchar(255) NULL, - `rtime` FLOAT(9, 7) NULL, - `last_online` datetime NULL, - `last_check` datetime NULL, - `active` enum('yes','no') NOT NULL default 'yes', - `email` enum('yes','no') NOT NULL default 'yes', - `sms` enum('yes','no') NOT NULL default 'no', - PRIMARY KEY (`server_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", - 1 => "INSERT INTO `" . PSM_DB_PREFIX . "servers` (`ip`, `port`, `label`, `type`, `status`, `error`, `rtime`, `last_online`, `last_check`, `active`, `email`, `sms`) VALUES ('http://sourceforge.net/index.php', 80, 'SourceForge', 'website', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes'), ('smtp.gmail.com', 465, 'Gmail SMTP', 'service', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes')", - ), - 'config' => - array( - 0 => "CREATE TABLE `" . PSM_DB_PREFIX . "config` ( - `config_id` int(11) NOT NULL AUTO_INCREMENT, - `key` varchar(255) NOT NULL, - `value` varchar(255) NOT NULL, - PRIMARY KEY (`config_id`), - KEY `key` (`key`(50)) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", - 1 => "INSERT INTO `" . PSM_DB_PREFIX . "config` (`config_id`, `key`, `value`) VALUES - (null, 'language', 'en'), - (null, 'email_status', '1'), - (null, 'email_from_email', 'monitor@example.org'), - (null, 'email_from_name', 'Server Monitor'), - (null, 'sms_status', '1'), - (null, 'sms_gateway', 'mollie'), - (null, 'sms_gateway_username', 'username'), - (null, 'sms_gateway_password', 'password'), - (null, 'sms_from', '1234567890'), - (null, 'alert_type', 'status'), - (null, 'log_status', '1'), - (null, 'log_email', '1'), - (null, 'log_sms', '1'), - (null, 'version', '200'), - (null, 'auto_refresh_servers', '0'), - (null, 'show_update', '1'), - (null, 'last_update_check', '0');", - ) -); - -$result = array(); - -foreach($tables as $name => $queries) { - $if_table_exists = $db->query('SHOW TABLES LIKE \'' . PSM_DB_PREFIX . $name.'\''); - - if(!empty($if_table_exists)) { - $message = 'Table ' . PSM_DB_PREFIX . $name . ' already exists in your database!'; - } else { - $message = ''; - - foreach($queries as $query) { - $message .= 'Executing ' . $query . '

'; - $db->query($query); - } - } - - $result[] = array( - 'name' => $name, - 'result' => $message, - ); -} -$tpl->addTemplateDataRepeat('install', 'tables', $result); - -echo $tpl->display('install'); -?> +?> \ No newline at end of file diff --git a/src/bootstrap.php b/src/bootstrap.php index cf1fd295..754e0609 100755 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -1,5 +1,6 @@ getLink() !== null) { -$lang = psm_get_conf('language'); - -if(!$lang) { - $lang = 'en'; + psm_load_conf(); +} else { + // no config yet! lets help them in the right direction + if(!defined('PSM_INSTALL')) { + header('Location: install.php'); + die(); + } } +$lang = psm_get_conf('language', 'en'); psm_load_lang($lang); -?> +?> \ No newline at end of file diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index a65ef9dc..774ac32f 100755 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -93,11 +93,12 @@ function psm_get_langs() { * The config must have been loaded first using psm_load_conf() * * @param string $key + * @param mixed $alt if not set, return this alternative * @return string * @see psm_load_conf() */ -function psm_get_conf($key) { - $result = (isset($GLOBALS['sm_config'][$key])) ? $GLOBALS['sm_config'][$key] : null; +function psm_get_conf($key, $alt = null) { + $result = (isset($GLOBALS['sm_config'][$key])) ? $GLOBALS['sm_config'][$key] : $alt; return $result; } @@ -243,13 +244,10 @@ function psm_check_updates() { // been more than a week since update, lets go // update "update-date" $db->save(PSM_DB_PREFIX . 'config', array('value' => time()), array('key' => 'last_update_check')); - $latest = psm_curl_get('http://phpservermon.neanderthal-technology.com/version'); + $latest = psm_curl_get('http://phpservermon.neanderthal-technology.com/version.php'); $current = psm_get_conf('version'); - if((int) $current < (int) $latest) { - // new update available - return true; - } + return version_compare($latest, $current, '>'); } return false; } diff --git a/src/lang/br.lang.php b/src/lang/br.lang.php index 1264c4ea..8885ef36 100755 --- a/src/lang/br.lang.php +++ b/src/lang/br.lang.php @@ -34,6 +34,7 @@ $sm_lang = array( 'update' => 'Atualização', 'config' => 'Configuração', 'help' => 'Ajuda', + 'install' => 'Install', 'action' => 'Ação', 'save' => 'Salvar', 'edit' => 'Editar', diff --git a/src/lang/de.lang.php b/src/lang/de.lang.php index cecdffae..b8cb1f74 100755 --- a/src/lang/de.lang.php +++ b/src/lang/de.lang.php @@ -34,6 +34,7 @@ $sm_lang = array( 'update' => 'Updates', 'config' => 'Einstellungen', 'help' => 'Hilfe', + 'install' => 'Install', 'action' => 'Aktion', 'save' => 'Speichern', 'edit' => 'Bearbeiten', diff --git a/src/lang/en.lang.php b/src/lang/en.lang.php index 757d0bb8..c1ea45be 100755 --- a/src/lang/en.lang.php +++ b/src/lang/en.lang.php @@ -34,6 +34,7 @@ $sm_lang = array( 'update' => 'Update', 'config' => 'Config', 'help' => 'Help', + 'install' => 'Install', 'action' => 'Action', 'save' => 'Save', 'edit' => 'Edit', diff --git a/src/lang/fr.lang.php b/src/lang/fr.lang.php index 254ae908..02999319 100755 --- a/src/lang/fr.lang.php +++ b/src/lang/fr.lang.php @@ -34,6 +34,7 @@ $sm_lang = array( 'update' => 'Mise à jour', 'config' => 'Configuration', 'help' => 'Aide', + 'install' => 'Install', 'action' => 'Action', 'save' => 'Enregistrer', 'edit' => 'Editer', diff --git a/src/lang/kr.lang.php b/src/lang/kr.lang.php index b4b07acd..9d652df1 100755 --- a/src/lang/kr.lang.php +++ b/src/lang/kr.lang.php @@ -35,6 +35,7 @@ $sm_lang = array( 'update' => '업데이트', 'config' => '설정', 'help' => '도움말', + 'install' => 'Install', 'action' => 'Action', 'save' => '저장', 'edit' => '수정', diff --git a/src/lang/nl.lang.php b/src/lang/nl.lang.php index e82aaf97..463ff6aa 100755 --- a/src/lang/nl.lang.php +++ b/src/lang/nl.lang.php @@ -34,6 +34,7 @@ $sm_lang = array( 'update' => 'Update', 'config' => 'Config', 'help' => 'Help', + 'install' => 'Install', 'action' => 'Actie', 'save' => 'Opslaan', 'edit' => 'Wijzig', diff --git a/src/psm/Module/AbstractModule.class.php b/src/psm/Module/AbstractModule.class.php index 89cd58d6..15c46119 100755 --- a/src/psm/Module/AbstractModule.class.php +++ b/src/psm/Module/AbstractModule.class.php @@ -62,9 +62,17 @@ abstract class AbstractModule implements ModuleInterface { /** * Add footer to page? * @var boolean $add_footer + * @see addFooter() */ protected $add_footer = true; + /** + * Add menu to page? + * @var boolean $add_menu + * @see addMenu() + */ + protected $add_menu = true; + /** * Messages to show the user * @var array $messages @@ -141,34 +149,36 @@ abstract class AbstractModule implements ModuleInterface { * Then the tpl_id set in $this->getTemplateId() will be added to the main template automatically */ protected function createHTML() { - // add footer to page? - if($this->add_footer) { - $this->tpl->newTemplate('main_footer', 'main.tpl.html'); - $html_footer = $this->tpl->getTemplate('main_footer'); - } else { - $html_footer = ''; - } - if(psm_get_conf('show_update')) { // user wants updates, lets see what we can do $this->createHTMLUpdateAvailable(); } + $tpl_data = array( + 'message' => (empty($this->messages)) ? ' ' : implode('
', $this->messages), + ); + // add menu to page? + if($this->add_menu) { + $this->tpl->newTemplate('main_menu', 'main.tpl.html'); + $tpl_data['html_menu'] = $this->tpl->getTemplate('main_menu'); + } + // add footer to page? + if($this->add_footer) { + $this->tpl->newTemplate('main_footer', 'main.tpl.html'); + $tpl_data['html_footer'] = $this->tpl->getTemplate('main_footer'); + } - $this->createHTMLLabels(); + $tpl_id_content = $this->getTemplateId(); + if($tpl_id_content) { + $tpl_data['content'] = $this->tpl->getTemplate($tpl_id_content); + } // add the module's custom template to the main template to get some content - $this->tpl->addTemplatedata( - 'main', - array( - 'content' => $this->tpl->getTemplate($this->getTemplateId()), - 'message' => (empty($this->messages)) ? ' ' : implode('
', $this->messages), - 'html_footer' => $html_footer, - 'label_back_to_top' => psm_get_lang('system', 'back_to_top'), - ) - ); + $this->setTemplateId('main'); + $this->tpl->addTemplatedata($this->getTemplateId(), $tpl_data); + $this->createHTMLLabels(); // display main template - echo $this->tpl->display('main'); + echo $this->tpl->display($this->getTemplateId()); } /** @@ -180,12 +190,7 @@ abstract class AbstractModule implements ModuleInterface { if(psm_check_updates()) { // yay, new update available =D - $this->tpl->addTemplateData( - 'main', - array( - 'update_available' => '
'.psm_get_lang('system', 'update_available').'
', - ) - ); + $this->addMessage(psm_get_lang('system', 'update_available')); } } @@ -209,6 +214,7 @@ abstract class AbstractModule implements ModuleInterface { 'label_config' => psm_get_lang('system', 'config'), 'label_update' => psm_get_lang('system', 'update'), 'label_help' => psm_get_lang('system', 'help'), + 'label_back_to_top' => psm_get_lang('system', 'back_to_top'), ) ); } @@ -248,6 +254,14 @@ abstract class AbstractModule implements ModuleInterface { $this->add_footer = $value; } + /** + * Hide or show the menu of the page + * @param boolean $value + */ + protected function addMenu($value) { + $this->add_menu = $value; + } + /** * Set actions available * @param string|array $actions diff --git a/src/psm/Module/Install.class.php b/src/psm/Module/Install.class.php new file mode 100644 index 00000000..2b32864e --- /dev/null +++ b/src/psm/Module/Install.class.php @@ -0,0 +1,321 @@ +. + * + * @package phpservermon + * @author Pepijn Over + * @copyright Copyright (c) 2008-2014 Pepijn Over + * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 + * @version Release: @package_version@ + * @link http://phpservermon.neanderthal-technology.com/ + * @since phpservermon 2.1.0 + **/ + +namespace psm\Module; +use psm\Service\Database; +use psm\Service\Template; + +class Install extends AbstractModule { + + /** + * Result messages to add to the main template + * @var array $install_results + * @see addResult() + */ + protected $install_results = array(); + + /** + * Full path to config file + * @var string $path_config + */ + protected $path_config; + + /** + * Full path to old config file (2.0) + * @var string $path_config_old + */ + protected $path_config_old; + + function __construct(Database $db, Template $tpl) { + parent::__construct($db, $tpl); + + $this->path_config = PSM_PATH_SRC . '../config.php'; + $this->path_config_old = PSM_PATH_SRC . '../config.inc.php'; + + $this->setActions(array( + 'index', 'config', 'install' + ), 'index'); + } + + protected function createHTML() { + $tpl_id_custom = $this->getTemplateId(); + $this->setTemplateId('install', 'install.tpl.html'); + $html_install = ($tpl_id_custom) ? $this->tpl->getTemplate($tpl_id_custom) : ''; + + $html_results = ''; + if(!empty($this->install_results)) { + $this->tpl->newTemplate('install_results', 'install.tpl.html'); + $this->tpl->addTemplateDataRepeat('install_results', 'resultmsgs', $this->install_results); + $html_results = $this->tpl->getTemplate('install_results'); + } + $this->tpl->addTemplateData($this->getTemplateId(), array( + 'html_install' => $html_install, + 'html_results' => $html_results, + )); + + return parent::createHTML(); + } + + /** + * Generate the main install page with prerequisites + */ + protected function executeIndex() { + $this->addMenu(false); + $tpl_data = array(); + + // build prerequisites + $errors = 0; + + $phpv = phpversion(); + if(version_compare($phpv, '5.3.0', '<')) { + $errors++; + $this->addResult('PHP 5.3+ is required to run PHP Server Monitor.', 'error'); + } else { + $this->addResult('PHP version: ' . $phpv); + } + if(!function_exists('curl_init')) { + $this->addResult('PHP is installed without the cURL module. Please install cURL.', 'warning'); + } else { + $this->addResult('cURL installed'); + } + if(!function_exists('mysql_connect')) { + $errors++; + $this->addResult('php-mysql needs to be installed.', 'error'); + } + + if($errors > 0) { + // cannot continue + $this->addResult($errors . ' error(s) have been encountered. Please fix them and refresh this page.', 'error'); + } else { + if(defined('PSM_CONFIG')) { + $this->addResult('Configuration file found.'); + return $this->executeInstall(); + } else { + return $this->executeConfig(); + } + } + } + + /** + * Help the user create a new config file + */ + protected function executeConfig() { + if(defined('PSM_CONFIG')) { + return $this->executeInstall(); + } + // first detect "old" config file (2.0) + if(file_exists($this->path_config_old)) { + // oldtimer huh + $this->addResult('Configuration file for v2.0 found.'); + $this->addResult( + 'The location of the config file has been changed since the previous version.
' . + 'We will attempt to create a new config file for you.' + , 'warning'); + $values = $this->parseConfig20(); + } else { + // fresh install + $values = $_POST; + } + + $config = array( + 'host' => 'localhost', + 'name' => '', + 'user' => '', + 'pass' => '', + 'prefix' => 'psm_', + ); + $this->setTemplateId('install_config_new', 'install.tpl.html'); + + $changed = false; + foreach($config as $ckey => &$cvalue) { + if(isset($values[$ckey])) { + $changed = true; + $cvalue = $values[$ckey]; + } + } + // add config to template data for prefilling the form + $tpl_data = $config; + + if($changed) { + // test db connection + $this->db = new \psm\Service\Database( + $config['host'], + $config['user'], + $config['pass'], + $config['name'] + ); + + if(is_resource($this->db->getLink())) { + $this->addResult('Connection to MySQL successful.'); + $config_php = $this->writeConfigFile($config); + if($config_php === true) { + $this->addResult('Configuration file written successfully.'); + return $this->executeInstall(); + } else { + $this->addResult('Config file is not writable, we cannot save it for you.', 'error'); + $this->tpl->newTemplate('install_config_new_copy', 'install.tpl.html'); + $tpl_data['html_config_copy'] = $this->tpl->getTemplate('install_config_new_copy'); + $tpl_data['php_config'] = $config_php; + } + } else { + $this->addResult('Unable to connect to MySQL. Please check your information.', 'error'); + } + } + + $this->tpl->addTemplateData($this->getTemplateId(), $tpl_data); + } + + /** + * Parse the 2.0 config file for prefilling + * @return array + */ + protected function parseConfig20() { + $config_old = file_get_contents($this->path_config_old); + $vars = array( + 'prefix' => '', + 'user' => '', + 'pass' => '', + 'name' => '', + 'host' => '', + ); + $pattern = "/define\('SM_DB_{key}', '(.*?)'/u"; + + foreach($vars as $key => $value) { + $pattern_key = str_replace('{key}', strtoupper($key), $pattern); + preg_match($pattern_key, $config_old, $value_matches); + $vars[$key] = (isset($value_matches[1])) ? $value_matches[1] : ''; + } + + return $vars; + } + + /** + * Execute the upgrade process to a newer version + */ + protected function executeInstall() { + if(!defined('PSM_CONFIG')) { + $this->addResult('No valid configuration found.', 'error'); + return $this->executeConfig(); + } + if(!is_resource($this->db->getLink())) { + $this->addResult('MySQL connection failed.', 'error'); + return; + } + $queries = new \psm\Util\Install\Queries; + $tables = $queries->install(); + foreach($tables as $name => $sql) { + $if_table_exists = $this->db->query("SHOW TABLES LIKE '{$name}'"); + + if(!empty($if_table_exists)) { + $this->addResult('Table ' . $name . ' already exists in your database!'); + } else { + $this->db->query($sql); + $this->addResult('Table ' . $name . ' added.'); + } + } + $version_conf = $this->db->selectRow(PSM_DB_PREFIX . 'config', array('key' => 'version'), array('key', 'value')); + + if(empty($version_conf)) { + // fresh install + $version_from = null; + } else { + // existing install + $version_from = $version_conf['value']; + if(strpos($version_from, '.') === false) { + // yeah, my bad.. previous version did not follow proper naming scheme + $version_from = rtrim(chunk_split($version_from, 1, '.'), '.'); + } + $this->addResult('Upgrade detected, upgrading from ' . $version_from); + } + $this->addResult('Executing database changes for version ' . PSM_VERSION); + $install_queries = $queries->upgrade(PSM_VERSION, $version_from); + + foreach($install_queries as $sql) { + $this->db->query($sql); + } + + $this->addResult('Installation finished!'); + $this->setTemplateId('install_success', 'install.tpl.html'); + } + + /** + * Write config file with db variables + * @param array $db_vars prefix,user,pass,name,host + * @return boolean|string TRUE on success, string with config otherwise + */ + protected function writeConfigFile($db_vars) { + $config = + " $value) { + $line = "define('PSM_DB_{key}', '{value}');".PHP_EOL; + $line = str_replace( + array('{key}', '{value}'), + array(strtoupper($key), $value), + $line + ); + $config .= $line; + } + $config .= "?>".PHP_EOL; + if(is_writeable($this->path_config)) { + file_put_contents($this->path_config, $config); + return true; + } else { + return $config; + } + } + + /** + * Add install result to be added to the main template + * @param string|array $msg + * @param string $status success/warning/error + * @return \psm\Module\Install + */ + protected function addResult($msg, $status = 'success') { + if(!is_array($msg)) { + $msg = array($msg); + } + if($status == 'error') { + $shortcode = 'important'; + } else { + $shortcode = $status; + } + + foreach($msg as $m) { + $this->install_results[] = array( + 'message' => $m, + 'status' => strtoupper($status), + 'shortcode' => $shortcode, + ); + } + return $this; + } +} + +?> \ No newline at end of file diff --git a/src/psm/Util/Install/Queries.class.php b/src/psm/Util/Install/Queries.class.php new file mode 100644 index 00000000..4ce77c93 --- /dev/null +++ b/src/psm/Util/Install/Queries.class.php @@ -0,0 +1,132 @@ +. + * + * @package phpservermon + * @author Pepijn Over + * @copyright Copyright (c) 2008-2014 Pepijn Over + * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 + * @version Release: @package_version@ + * @link http://phpservermon.neanderthal-technology.com/ + * @since phpservermon 2.1.0 + **/ + +namespace psm\Util\Install; + +/** + * Query class provides al queries required for installing/upgrading. + */ +class Queries { + /** + * Retrieve table queries for install + * @return array + */ + public function install() { + $tables = array( + PSM_DB_PREFIX . 'users' => "CREATE TABLE `" . PSM_DB_PREFIX . "users` ( + `user_id` int(11) NOT NULL auto_increment, + `server_id` varchar(255) NOT NULL, + `name` varchar(255) NOT NULL, + `mobile` varchar(15) NOT NULL, + `email` varchar(255) NOT NULL, + PRIMARY KEY (`user_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", + PSM_DB_PREFIX . 'log' => "CREATE TABLE `" . PSM_DB_PREFIX . "log` ( + `log_id` int(11) NOT NULL auto_increment, + `server_id` int(11) NOT NULL, + `type` enum('status','email','sms') NOT NULL, + `message` varchar(255) NOT NULL, + `datetime` timestamp NOT NULL default CURRENT_TIMESTAMP, + `user_id` varchar(255) NOT NULL, + PRIMARY KEY (`log_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", + PSM_DB_PREFIX . 'servers' => "CREATE TABLE `" . PSM_DB_PREFIX . "servers` ( + `server_id` int(11) NOT NULL auto_increment, + `ip` varchar(100) NOT NULL, + `port` int(5) NOT NULL, + `label` varchar(255) NOT NULL, + `type` enum('service','website') NOT NULL default 'service', + `status` enum('on','off') NOT NULL default 'on', + `error` varchar(255) NULL, + `rtime` FLOAT(9, 7) NULL, + `last_online` datetime NULL, + `last_check` datetime NULL, + `active` enum('yes','no') NOT NULL default 'yes', + `email` enum('yes','no') NOT NULL default 'yes', + `sms` enum('yes','no') NOT NULL default 'no', + PRIMARY KEY (`server_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", + PSM_DB_PREFIX . 'config' => "CREATE TABLE `" . PSM_DB_PREFIX . "config` ( + `key` varchar(255) NOT NULL, + `value` varchar(255) NOT NULL, + PRIMARY KEY (`key`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", + ); + return $tables; + } + + /** + * Get queries for upgrading + * @param string $version + * @param string $version_from + * @return array + */ + public function upgrade($version, $version_from = null) { + $queries = array(); + + if($version_from === null) { + $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "users` (`server_id`, `name`, `mobile`, `email`) VALUES ('1,2', 'example_user', '0123456789', 'user@example.com')"; + $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "servers` (`ip`, `port`, `label`, `type`, `status`, `error`, `rtime`, `last_online`, `last_check`, `active`, `email`, `sms`) VALUES ('http://sourceforge.net/index.php', 80, 'SourceForge', 'website', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes'), ('smtp.gmail.com', 465, 'Gmail SMTP', 'service', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes')"; + $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE + ('language', 'en'), + ('email_status', '1'), + ('email_from_email', 'monitor@example.org'), + ('email_from_name', 'Server Monitor'), + ('sms_status', '1'), + ('sms_gateway', 'mollie'), + ('sms_gateway_username', 'username'), + ('sms_gateway_password', 'password'), + ('sms_from', '1234567890'), + ('alert_type', 'status'), + ('log_status', '1'), + ('log_email', '1'), + ('log_sms', '1'), + ('version', '{$version}'), + ('auto_refresh_servers', '0'), + ('show_update', '1'), + ('last_update_check', '0');"; + } else { + if(version_compare($version_from, '2.1.0', '<')) { + // 2.0 upgrade + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "config` DROP `config_id`;"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "config` ADD PRIMARY KEY ( `key` );"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "config` DROP INDEX `key`;"; + + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `error` `error` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL;"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `rtime` `rtime` FLOAT( 9, 7 ) NULL;"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `last_online` `last_online` DATETIME NULL;"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `last_check` `last_check` DATETIME NULL;"; + + } + $queries[] = "UPDATE `" . PSM_DB_PREFIX . "config` SET `value` = '{$version}' WHERE `key` = 'version';"; + } + return $queries; + } +} + +?> \ No newline at end of file diff --git a/src/templates/install.tpl.html b/src/templates/install.tpl.html index 18c7e270..48842200 100755 --- a/src/templates/install.tpl.html +++ b/src/templates/install.tpl.html @@ -1,53 +1,94 @@ - - - - - PHP Server Monitor - - - - - - - - - - - -
+
+

 PHP Server Monitor

+

 

+

+ PHP Server Monitor + Twitter Bootstrap +

+

PHP Server Monitor is a script that checks whether the servers on your list are up and running on the selected ports. It comes with a web based user interface where you can add and remove servers or websites from the MySQL database, and you can manage users for each server with a mobile number and email address.

+

To install PHP Server Monitor, please follow the instructions below.

+
+
+
{html_results}
+
+{html_install} + -
-

PHP Server Monitor

-

- PHP Server Monitor - Twitter Bootstrap -

-
+ +
+
+
+ +

Please enter your database info:

+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+{html_config_copy} +
+ -
-
- -
- Creating table {name}...

- {result} -
- - {tables} + +
+

Your config file:

+
Unable to save your configuration.
+

Please create a new file in the project directory called "config.php" and copy the information below.

+

After you have copied the configuration, press the button to continue.

+

+

+
+ -
- The installation is complete. Please check above if errors have occured.
- If no errors have occured, you can remove this file.

- Click here to go to your index -
+ +
+
+The installation is complete. Please check above if errors have occured.
+If no errors have occurred, you are good to go.

+Click here to go to the monitor +
+
+ -
-
- -
- - - - \ No newline at end of file + + +
+

{status}

+

{message}

+
+ +{resultmsgs} + \ No newline at end of file diff --git a/src/templates/main.tpl.html b/src/templates/main.tpl.html index 149eadae..020ede6b 100755 --- a/src/templates/main.tpl.html +++ b/src/templates/main.tpl.html @@ -19,6 +19,11 @@ + @@ -31,6 +36,36 @@ {title} +{html_menu} + + + + + + +
+ + +
+
+
{message}
+
+
+
{content}
+ + {html_footer} +
+ + + + + + - - - - - - -
- - -
- {content} -
- - {update_available} - {html_footer} -
- - - - - - - + diff --git a/src/templates/servers.tpl.html b/src/templates/servers.tpl.html index 32ef0ae6..0cf7c77b 100755 --- a/src/templates/servers.tpl.html +++ b/src/templates/servers.tpl.html @@ -1,10 +1,5 @@