From e60f69e58101af8ffb7720be705dafb6b1f0098a Mon Sep 17 00:00:00 2001 From: jl Date: Fri, 27 Jun 2014 14:26:26 +0200 Subject: [PATCH] Adding timeout config for a server. --- src/includes/psmconfig.inc.php | 2 +- src/lang/en_US.lang.php | 1 + src/lang/fr_FR.lang.php | 1 + .../Controller/AbstractServerController.class.php | 5 +++-- .../Server/Controller/ServerController.class.php | 3 +++ src/psm/Util/Install/Installer.class.php | 13 ++++++++++++- src/psm/Util/Updater/StatusUpdater.class.php | 7 ++++--- src/templates/server/server.tpl.html | 8 +++++++- src/templates/server/view.tpl.html | 6 +++++- 9 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/includes/psmconfig.inc.php b/src/includes/psmconfig.inc.php index d5062f78..2a3d43a5 100644 --- a/src/includes/psmconfig.inc.php +++ b/src/includes/psmconfig.inc.php @@ -29,7 +29,7 @@ /** * Current PSM version */ -define('PSM_VERSION', '3.1.0-dev'); +define('PSM_VERSION', '3.1.1-dev'); /** * URL to check for updates. Will not be checked if turned off on config page. diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 919a9377..038449e0 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -111,6 +111,7 @@ $sm_lang = array( 'status' => 'Status', 'label' => 'Label', 'domain' => 'Domain/IP', + 'timeout' => 'Timeout', 'port' => 'Port', 'type' => 'Type', 'type_website' => 'Website', diff --git a/src/lang/fr_FR.lang.php b/src/lang/fr_FR.lang.php index 7c64447b..cb97c609 100644 --- a/src/lang/fr_FR.lang.php +++ b/src/lang/fr_FR.lang.php @@ -111,6 +111,7 @@ $sm_lang = array( 'status' => 'État', 'label' => 'Nom', 'domain' => 'Domaine/IP', + 'timeout' => 'Timeout', 'port' => 'Port', 'type' => 'Type', 'type_website' => 'Site Web', diff --git a/src/psm/Module/Server/Controller/AbstractServerController.class.php b/src/psm/Module/Server/Controller/AbstractServerController.class.php index 4a763b2f..a89d71a6 100644 --- a/src/psm/Module/Server/Controller/AbstractServerController.class.php +++ b/src/psm/Module/Server/Controller/AbstractServerController.class.php @@ -74,7 +74,8 @@ abstract class AbstractServerController extends AbstractController { `s`.`email`, `s`.`sms`, `s`.`warning_threshold`, - `s`.`warning_threshold_counter` + `s`.`warning_threshold_counter`, + `s`.`timeout` FROM `".PSM_DB_PREFIX."servers` AS `s` {$sql_join} {$sql_where} @@ -115,4 +116,4 @@ abstract class AbstractServerController extends AbstractController { return $server; } -} \ No newline at end of file +} diff --git a/src/psm/Module/Server/Controller/ServerController.class.php b/src/psm/Module/Server/Controller/ServerController.class.php index ef41d72c..e677c522 100644 --- a/src/psm/Module/Server/Controller/ServerController.class.php +++ b/src/psm/Module/Server/Controller/ServerController.class.php @@ -190,6 +190,7 @@ class ServerController extends AbstractServerController { 'edit_value_label' => $edit_server['label'], 'edit_value_ip' => $edit_server['ip'], 'edit_value_port' => $edit_server['port'], + 'edit_value_timeout' => $edit_server['timeout'], 'edit_value_pattern' => $edit_server['pattern'], 'edit_value_warning_threshold' => $edit_server['warning_threshold'], 'edit_type_selected_' . $edit_server['type'] => 'selected="selected"', @@ -216,6 +217,7 @@ class ServerController extends AbstractServerController { $clean = array( 'label' => trim(strip_tags(psm_POST('label', ''))), 'ip' => trim(strip_tags(psm_POST('ip', ''))), + 'timeout' => intval(psm_POST('timeout', 0)), 'port' => intval(psm_POST('port', 0)), 'type' => psm_POST('type', ''), 'pattern' => psm_POST('pattern', ''), @@ -362,6 +364,7 @@ class ServerController extends AbstractServerController { 'label_label' => psm_get_lang('servers', 'label'), 'label_status' => psm_get_lang('servers', 'status'), 'label_domain' => psm_get_lang('servers', 'domain'), + 'label_timeout' => psm_get_lang('servers', 'timeout'), 'label_port' => psm_get_lang('servers', 'port'), 'label_type' => psm_get_lang('servers', 'type'), 'label_website' => psm_get_lang('servers', 'type_website'), diff --git a/src/psm/Util/Install/Installer.class.php b/src/psm/Util/Install/Installer.class.php index 9b8deab7..7ddb82a6 100644 --- a/src/psm/Util/Install/Installer.class.php +++ b/src/psm/Util/Install/Installer.class.php @@ -78,7 +78,7 @@ class Installer { // different DB version, check if the version requires any changes // @todo this is currently a manual check for each version, similar to upgrade().. not a clean way - if(version_compare($version_db, '3.0.0', '<')) { + if(version_compare($version_db, '3.1.1', '<')) { return true; } else { // change database version to current version so this check won't be required next time @@ -218,6 +218,7 @@ class Installer { `sms` enum('yes','no') NOT NULL default 'no', `warning_threshold` mediumint(1) unsigned NOT NULL DEFAULT '1', `warning_threshold_counter` mediumint(1) unsigned NOT NULL DEFAULT '0', + `timeout` int(1) NOT NULL DEFAULT '10', PRIMARY KEY (`server_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", PSM_DB_PREFIX . 'servers_uptime' => "CREATE TABLE IF NOT EXISTS `" . PSM_DB_PREFIX . "servers_uptime` ( @@ -274,6 +275,10 @@ class Installer { // upgrade to 3.1.0 $this->upgrade310(); } + if(version_compare($version_from, '3.1.1', '<')) { + // upgrade to 3.1.1 + $this->upgrade311(); + } psm_update_conf('version', $version_to); } @@ -399,4 +404,10 @@ class Installer { ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; $this->execSQL($queries); } + + protected function upgrade311() { + $queries = array(); + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `timeout` INT( 1 ) NOT NULL DEFAULT '10';"; + $this->execSQL($queries); + } } diff --git a/src/psm/Util/Updater/StatusUpdater.class.php b/src/psm/Util/Updater/StatusUpdater.class.php index 62063505..f0686387 100644 --- a/src/psm/Util/Updater/StatusUpdater.class.php +++ b/src/psm/Util/Updater/StatusUpdater.class.php @@ -82,7 +82,7 @@ class StatusUpdater { $this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array( 'server_id' => $server_id, ), array( - 'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'active', 'warning_threshold', 'warning_threshold_counter', + 'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'active', 'warning_threshold', 'warning_threshold_counter', 'timeout', )); if(empty($this->server)) { return false; @@ -175,11 +175,12 @@ class StatusUpdater { $curl_result = psm_curl_get( $this->server['ip'], true, - ($this->server['pattern'] == '' ? false : true) + ($this->server['pattern'] == '' ? false : true), + $this->server['timeout'] ); $this->rtime = (microtime(true) - $starttime); - + // the first line would be the status code.. $status_code = strtok($curl_result, "\r\n"); // keep it general diff --git a/src/templates/server/server.tpl.html b/src/templates/server/server.tpl.html index e62a2b26..bcd0346e 100755 --- a/src/templates/server/server.tpl.html +++ b/src/templates/server/server.tpl.html @@ -92,6 +92,12 @@ +
+ +
+ +
+
@@ -152,4 +158,4 @@
- \ No newline at end of file + diff --git a/src/templates/server/view.tpl.html b/src/templates/server/view.tpl.html index eaf0a4db..7d789e27 100644 --- a/src/templates/server/view.tpl.html +++ b/src/templates/server/view.tpl.html @@ -39,6 +39,10 @@ {label_domain}: {ip} + + {label_timeout}: + {timeout} + {label_port}: {port} @@ -85,4 +89,4 @@ - \ No newline at end of file +