Adding new install mode with upgrade support. Config file has been moved

one more (and last..) time so its back in the root directory.
This commit is contained in:
Pepijn Over 2014-02-08 18:40:22 +01:00
parent 6075bc80ab
commit 6e19063972
18 changed files with 675 additions and 265 deletions

View File

@ -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');
?>

View File

@ -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 . '<br/><br/>';
$db->query($query);
}
}
$result[] = array(
'name' => $name,
'result' => $message,
);
}
$tpl->addTemplateDataRepeat('install', 'tables', $result);
echo $tpl->display('install');
?>
?>

View File

@ -1,5 +1,6 @@
<?php
define('PSM_VERSION', '2.1.0');
// Include paths
define('PSM_PATH_SRC', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('PSM_PATH_VENDOR', PSM_PATH_SRC . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR);
@ -7,6 +8,20 @@ define('PSM_PATH_INC', PSM_PATH_SRC . 'includes' . DIRECTORY_SEPARATOR);
define('PSM_PATH_TPL', PSM_PATH_SRC . 'templates' . DIRECTORY_SEPARATOR);
define('PSM_PATH_LANG', PSM_PATH_SRC . 'lang' . DIRECTORY_SEPARATOR);
// find config file
$path_conf = PSM_PATH_SRC . '../config.php';
if(file_exists($path_conf)) {
include_once $path_conf;
}
// check for a debug var
if(defined('PSM_DEBUG') && PSM_DEBUG) {
error_reporting(E_ALL);
ini_set('display_erors', 1);
} else {
error_reporting(0);
ini_set('display_errors', 0);
}
// set autoloader, make sure to set $prepend = true so that our autoloader is called first
function __autoload($class) {
// remove leading \
@ -36,22 +51,20 @@ $includes = glob(PSM_PATH_INC . '*.inc.php');
foreach($includes as $file) {
include_once $file;
}
if(!defined('PSM_CONFIG')) {
// redirect to install.php
die('Failed to locate config file. Please read README.md for more information on how to setup PHP Server Monitor.');
}
// init db connection
$db = new psm\Service\Database();
psm_load_conf();
if($db->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);
?>
?>

View File

@ -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;
}

View File

@ -34,6 +34,7 @@ $sm_lang = array(
'update' => 'Atualização',
'config' => 'Configuração',
'help' => 'Ajuda',
'install' => 'Install',
'action' => 'Ação',
'save' => 'Salvar',
'edit' => 'Editar',

View File

@ -34,6 +34,7 @@ $sm_lang = array(
'update' => 'Updates',
'config' => 'Einstellungen',
'help' => 'Hilfe',
'install' => 'Install',
'action' => 'Aktion',
'save' => 'Speichern',
'edit' => 'Bearbeiten',

View File

@ -34,6 +34,7 @@ $sm_lang = array(
'update' => 'Update',
'config' => 'Config',
'help' => 'Help',
'install' => 'Install',
'action' => 'Action',
'save' => 'Save',
'edit' => 'Edit',

View File

@ -34,6 +34,7 @@ $sm_lang = array(
'update' => 'Mise &agrave; jour',
'config' => 'Configuration',
'help' => 'Aide',
'install' => 'Install',
'action' => 'Action',
'save' => 'Enregistrer',
'edit' => 'Editer',

View File

@ -35,6 +35,7 @@ $sm_lang = array(
'update' => '업데이트',
'config' => '설정',
'help' => '도움말',
'install' => 'Install',
'action' => 'Action',
'save' => '저장',
'edit' => '수정',

View File

@ -34,6 +34,7 @@ $sm_lang = array(
'update' => 'Update',
'config' => 'Config',
'help' => 'Help',
'install' => 'Install',
'action' => 'Actie',
'save' => 'Opslaan',
'edit' => 'Wijzig',

View File

@ -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)) ? '&nbsp' : implode('<br/>', $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)) ? '&nbsp' : implode('<br/>', $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' => '<div id="update">'.psm_get_lang('system', 'update_available').'</div>',
)
);
$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

View File

@ -0,0 +1,321 @@
<?php
/**
* PHP Server Monitor
* Monitor your servers and websites.
*
* This file is part of PHP Server Monitor.
* PHP Server Monitor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PHP Server Monitor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
*
* @package phpservermon
* @author Pepijn Over <pep@neanderthal-technology.com>
* @copyright Copyright (c) 2008-2014 Pepijn Over <pep@neanderthal-technology.com>
* @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.<br/>' .
'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 =
"<?php".PHP_EOL;
"define('PSM_CONFIG', true);".PHP_EOL;
foreach($db_vars as $key => $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;
}
}
?>

View File

@ -0,0 +1,132 @@
<?php
/**
* PHP Server Monitor
* Monitor your servers and websites.
*
* This file is part of PHP Server Monitor.
* PHP Server Monitor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PHP Server Monitor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
*
* @package phpservermon
* @author Pepijn Over <pep@neanderthal-technology.com>
* @copyright Copyright (c) 2008-2014 Pepijn Over <pep@neanderthal-technology.com>
* @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;
}
}
?>

View File

@ -1,53 +1,94 @@
<!--%tpl_install-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PHP Server Monitor</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="static/plugin/twitter-bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="static/plugin/twitter-bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<link href="static/css/style.css" rel="stylesheet">
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="install">
<div class="container">
<div class="hero-unit">
<h1><img class="pull-right" src="static/opensource.png" width="100" alt="" /> &nbsp;PHP Server Monitor</h1>
<p>&nbsp;</p>
<p>
<a class="btn btn-primary btn-large" target="_blank" href="http://phpservermon.neanderthal-technology.com">PHP Server Monitor</a>
<a class="btn btn-large" target="_blank" href="http://twitter.github.com/bootstrap/">Twitter Bootstrap</a>
</p>
<p>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.</p>
<p>To install PHP Server Monitor, please follow the instructions below.</p>
</div>
<div class="row-fluid">
<div class="span12">{html_results}</div>
</div>
{html_install}
<!--%%tpl_install-->
<div class="hero-unit">
<h1>PHP Server Monitor</h1>
<p>
<a class="btn btn-large" target="_blank" href="http://phpservermon.sourceforge.net">PHP Server Monitor</a>
<a class="btn btn-large" target="_blank" href="http://twitter.github.com/bootstrap/">Twitter Bootstrap</a>
</p>
</div>
<!--%tpl_install_config_new-->
<div class="row-fluid">
<div class="span6">
<form id="psm_config" class="form-horizontal" action="install.php" method="post">
<!--<input type="hidden" name="action" value="config" />-->
<h3>Please enter your database info:</h3>
<div class="control-group">
<label class="control-label" for="host">Database host</label>
<div class="controls">
<input type="text" id="host" name="host" value="{host}" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="name">Database name</label>
<div class="controls">
<input type="text" id="name" name="name" value="{name}" placeholder="db name" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="user">Database user</label>
<div class="controls">
<input type="text" id="user" name="user" value="{user}" placeholder="db user" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="pass">Database password</label>
<div class="controls">
<input type="password" id="pass" name="pass" value="{pass}" placeholder="db password" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="prefix">Table prefix</label>
<div class="controls">
<input type="text" id="prefix" name="prefix" value="{prefix}" />
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Save configuration</button>
</div>
</div>
</form>
</div>
{html_config_copy}
</div>
<!--%%tpl_install_config_new-->
<div class="row">
<div class="span12">
<!--%tpl_repeat_tables-->
<div class="alert alert-success">
<b>Creating table {name}...</b><br/><br/>
{result}
</div>
<!--%%tpl_repeat_tables-->
{tables}
<!--%tpl_install_config_new_copy-->
<div class="span6">
<h3>Your config file:</h3>
<div class="alert alert-error">Unable to save your configuration.</div>
<p>Please create a new file in the project directory called "config.php" and copy the information below.</p>
<p>After you have copied the configuration, press the button to continue.</p>
<p class="pull-left"><textarea rows="10">{php_config}</textarea></p>
<p class="offset2"><input type="submit" class="btn btn-primary" value="I have saved the configuration" onclick="location.reload(true);" /></p>
</div>
<!--%%tpl_install_config_new_copy-->
<div class="alert alert-info">
The installation is complete. Please check above if errors have occured.<br/>
If no errors have occured, you can remove this file.<br><br>
<a class="btn btn-primary" href="index.php">Click here to go to your index</a>
</div>
<!--%tpl_install_success-->
<div class="row-fluid">
<div class="span12">
The installation is complete. Please check above if errors have occured.<br/>
If no errors have occurred, you are good to go.<br><br>
<a class="btn btn-primary" href="index.php">Click here to go to the monitor</a>
</div>
</div>
<!--%%tpl_install_success-->
</div>
</div>
</div>
</body>
</html>
<!--%%tpl_install-->
<!--%tpl_install_results-->
<!--%tpl_repeat_resultmsgs-->
<div>
<p class="pull-left"><span class="label label-{shortcode}">{status}</span></p>
<p class="offset1">{message}</p>
</div>
<!--%%tpl_repeat_resultmsgs-->
{resultmsgs}
<!--%%tpl_install_results-->

View File

@ -19,6 +19,11 @@
<script type="text/javascript" src="static/plugin/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="static/plugin/twitter-bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="static/js/scripts.js"></script>
<script type="text/javascript">
$(document).bind('ready', function(){
psm_flash_message();
});
</script>
</head>
<body data-spy="scroll" data-target=".subnav" data-offset="50">
<!-- navbar -->
@ -31,6 +36,36 @@
<span class="icon-bar"></span>
</a>
<a class="brand" href="index.php">{title}</a>
{html_menu}
</div>
</div>
</div>
<!-- /navbar -->
<!-- container -->
<div class="container">
<div class="page-header">
<h1>
{subtitle}
<small>&nbsp;</small>
</h1>
</div>
<div class="row-fluid">
<div class="span12">
<div id="flashmessage" class="alert alert-info hide">{message}</div>
</div>
</div>
<div class="row-fluid">{content}</div>
{html_footer}
</div>
<!-- /container -->
</body>
</html>
<!--%%tpl_main-->
<!--%tpl_main_menu-->
<div class="nav-collapse">
<ul class="nav">
<li id="nav_option_servers" class="{active_servers}">
@ -56,46 +91,7 @@
</li>
</ul>
</div>
</div>
</div>
</div>
<!-- /navbar -->
<!-- container -->
<div class="container">
<div class="page-header">
<h1>
{subtitle}
<small>&nbsp;</small>
</h1>
</div>
<div class="row">
{content}
</div>
{update_available}
{html_footer}
</div>
<!-- /container -->
<script type="text/javascript">
$(document).bind('ready', function(){
var flashmessage = $('#flashmessage');
if(flashmessage.length){
var t = flashmessage.html();
var c = trim(t);
var t = c.replace('&nbsp;', '');
if(t){
flashmessage.slideDown();
}
}
});
</script>
</body>
</html>
<!--%%tpl_main-->
<!--%%tpl_main_menu-->
<!--%tpl_main_auto_refresh-->
<meta http-equiv="refresh" content="{seconds}" />

View File

@ -1,10 +1,5 @@
<!--%tpl_servers_list-->
<div class="span12">
<div id="flashmessage" class="alert alert-info hide">
{message}
</div>
<div class="top_buutons">
<a class="btn btn-success" href="index.php?type=servers&action=edit">
<i class="icon-plus icon-white"></i>

View File

@ -1,8 +1,5 @@
<!--%tpl_users_list-->
<div class="span12">
<div id="flashmessage" class="alert alert-info hide">
{message}
</div>
<div class="top_buutons">
<a class="btn btn-success" href="index.php?type=users&action=edit">
<i class="icon-plus icon-white"></i>

View File

@ -18,4 +18,19 @@ function ltrim(str) {
//right trim
function rtrim(str) {
return str.replace(/\s+$/,"");
}
function psm_flash_message(message) {
var flashmessage = $('#flashmessage');
if(flashmessage.length){
if(typeof message != 'undefined') {
flashmessage.html(message);
}
var t = flashmessage.html();
var c = trim(t);
var t = c.replace('&nbsp;', '');
if(t){
flashmessage.slideDown();
}
}
}