diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 2346a114..52043f50 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -16,6 +16,7 @@ not yet released
* #105: Fixing check for websites with unverified SSL certificates.
* #107: Fixing update job for Synology DSM Task Scheduler.
* #108: URLs on Windows contained both back- and forward slashes.
+* #109: Custom time-out per server.
* #111: Generated urls for non-default ports included the port twice.
* #110: Support for SMSGlobal SMS gateway .
* Support for Danish SMS provider Smsit
diff --git a/docs/credits.rst b/docs/credits.rst
index 9f557578..15f1f240 100644
--- a/docs/credits.rst
+++ b/docs/credits.rst
@@ -50,6 +50,10 @@ The following people have contributed to the development of PHP Server Monitor:
* SMSGlobal SMS gateway
+* Julien Lebouteiller
+
+ * Custom time-out per server
+
Translators
+++++++++++
diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php
index 6178e1e3..75600c40 100644
--- a/src/includes/functions.inc.php
+++ b/src/includes/functions.inc.php
@@ -263,11 +263,13 @@ function psm_parse_msg($status, $type, $vars) {
* @param string $href
* @param boolean $header return headers?
* @param boolean $body return body?
- * @param int $timeout connection timeout in seconds
+ * @param int $timeout connection timeout in seconds. defaults to PSM_CURL_TIMEOUT (10 secs).
* @param boolean $add_agent add user agent?
* @return string cURL result
*/
-function psm_curl_get($href, $header = false, $body = true, $timeout = 10, $add_agent = true) {
+function psm_curl_get($href, $header = false, $body = true, $timeout = null, $add_agent = true) {
+ $timeout = $timeout == null ? PSM_CURL_TIMEOUT : intval($timeout);
+
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_NOBODY, (!$body));
diff --git a/src/includes/psmconfig.inc.php b/src/includes/psmconfig.inc.php
index d5062f78..588cf21f 100644
--- a/src/includes/psmconfig.inc.php
+++ b/src/includes/psmconfig.inc.php
@@ -96,3 +96,8 @@ define('PSM_LOGIN_RESET_RUNTIME', 3600);
* Number of seconds the cron is supposedly dead and we will run another cron anyway.
*/
define('PSM_CRON_TIMEOUT', 600);
+
+/**
+ * Default timeout in seconds for curl requests (can be overwritten per-server).
+ */
+define('PSM_CURL_TIMEOUT', 10);
diff --git a/src/lang/bg_BG.lang.php b/src/lang/bg_BG.lang.php
index d2594220..ed4bd7fa 100644
--- a/src/lang/bg_BG.lang.php
+++ b/src/lang/bg_BG.lang.php
@@ -111,6 +111,8 @@ $sm_lang = array(
'status' => 'Статус',
'label' => 'Име',
'domain' => 'Хост',
+ 'timeout' => 'Timeout',
+ 'timeout_description' => 'Number of seconds to wait for the server to respond.',
'port' => 'Порт',
'type' => 'Тип',
'type_website' => 'Сайт',
diff --git a/src/lang/da_DK.lang.php b/src/lang/da_DK.lang.php
index d556a284..78897094 100644
--- a/src/lang/da_DK.lang.php
+++ b/src/lang/da_DK.lang.php
@@ -111,6 +111,8 @@ $sm_lang = array(
'status' => 'Status',
'label' => 'Label',
'domain' => 'Domæne/IP',
+ 'timeout' => 'Timeout',
+ 'timeout_description' => 'Number of seconds to wait for the server to respond.',
'port' => 'Port',
'type' => 'Type',
'type_website' => 'Hjemmeside',
diff --git a/src/lang/de_DE.lang.php b/src/lang/de_DE.lang.php
index adf5f496..d68edb95 100644
--- a/src/lang/de_DE.lang.php
+++ b/src/lang/de_DE.lang.php
@@ -111,6 +111,8 @@ $sm_lang = array(
'status' => 'Status',
'label' => 'Beschriftung',
'domain' => 'Domain/IP',
+ 'timeout' => 'Timeout',
+ 'timeout_description' => 'Number of seconds to wait for the server to respond.',
'port' => 'Port',
'type' => 'Type',
'type_website' => 'Website',
diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php
index d05c81ac..4e0f40f3 100644
--- a/src/lang/en_US.lang.php
+++ b/src/lang/en_US.lang.php
@@ -111,6 +111,8 @@ $sm_lang = array(
'status' => 'Status',
'label' => 'Label',
'domain' => 'Domain/IP',
+ 'timeout' => 'Timeout',
+ 'timeout_description' => 'Number of seconds to wait for the server to respond.',
'port' => 'Port',
'type' => 'Type',
'type_website' => 'Website',
diff --git a/src/lang/es_ES.lang.php b/src/lang/es_ES.lang.php
index b3c19d5b..ab40d797 100644
--- a/src/lang/es_ES.lang.php
+++ b/src/lang/es_ES.lang.php
@@ -111,6 +111,8 @@ $sm_lang = array(
'status' => 'Status',
'label' => 'Titulo',
'domain' => 'Domain/IP',
+ 'timeout' => 'Timeout',
+ 'timeout_description' => 'Number of seconds to wait for the server to respond.',
'port' => 'Port',
'type' => 'Tipo',
'type_website' => 'Website',
diff --git a/src/lang/fr_FR.lang.php b/src/lang/fr_FR.lang.php
index e35a6f62..5f85c3be 100644
--- a/src/lang/fr_FR.lang.php
+++ b/src/lang/fr_FR.lang.php
@@ -111,6 +111,8 @@ $sm_lang = array(
'status' => 'État',
'label' => 'Nom',
'domain' => 'Domaine/IP',
+ 'timeout' => 'Timeout',
+ 'timeout_description' => 'Number of seconds to wait for the server to respond.',
'port' => 'Port',
'type' => 'Type',
'type_website' => 'Site Web',
diff --git a/src/lang/it_IT.lang.php b/src/lang/it_IT.lang.php
index d11ca077..91e5f247 100644
--- a/src/lang/it_IT.lang.php
+++ b/src/lang/it_IT.lang.php
@@ -111,6 +111,8 @@ $sm_lang = array(
'status' => 'Status',
'label' => 'Nome',
'domain' => 'Dominio/IP',
+ 'timeout' => 'Timeout',
+ 'timeout_description' => 'Number of seconds to wait for the server to respond.',
'port' => 'Porta',
'type' => 'Tipo',
'type_website' => 'Website',
diff --git a/src/lang/ko_KR.lang.php b/src/lang/ko_KR.lang.php
index 3fbcb2ca..0050349c 100644
--- a/src/lang/ko_KR.lang.php
+++ b/src/lang/ko_KR.lang.php
@@ -111,6 +111,8 @@ $sm_lang = array(
'status' => 'Status',
'label' => 'Label',
'domain' => 'Domain/IP',
+ 'timeout' => 'Timeout',
+ 'timeout_description' => 'Number of seconds to wait for the server to respond.',
'port' => 'Port',
'type' => 'Type',
'type_website' => 'Website',
diff --git a/src/lang/nl_NL.lang.php b/src/lang/nl_NL.lang.php
index 7bd1d21c..9488bad4 100644
--- a/src/lang/nl_NL.lang.php
+++ b/src/lang/nl_NL.lang.php
@@ -111,6 +111,8 @@ $sm_lang = array(
'status' => 'Status',
'label' => 'Label',
'domain' => 'Domein/IP',
+ 'timeout' => 'Timeout',
+ 'timeout_description' => 'Aantal seconden te wachten op een reactie van de server.',
'port' => 'Poort',
'type' => 'Type',
'type_website' => 'Website',
diff --git a/src/lang/pt_BR.lang.php b/src/lang/pt_BR.lang.php
index fc436eea..7cd76c3b 100644
--- a/src/lang/pt_BR.lang.php
+++ b/src/lang/pt_BR.lang.php
@@ -111,6 +111,8 @@ $sm_lang = array(
'status' => 'Status',
'label' => 'Etiqueta',
'domain' => 'Domínio/IP',
+ 'timeout' => 'Timeout',
+ 'timeout_description' => 'Number of seconds to wait for the server to respond.',
'port' => 'Porta',
'type' => 'Tipo',
'type_website' => 'Website',
diff --git a/src/lang/ru_RU.lang.php b/src/lang/ru_RU.lang.php
index eefd430d..4dd0d6f8 100644
--- a/src/lang/ru_RU.lang.php
+++ b/src/lang/ru_RU.lang.php
@@ -111,6 +111,8 @@ $sm_lang = array(
'status' => 'Статус',
'label' => 'Лейбл',
'domain' => 'Домен/IP',
+ 'timeout' => 'Timeout',
+ 'timeout_description' => 'Number of seconds to wait for the server to respond.',
'port' => 'Порт',
'type' => 'Тип',
'type_website' => 'Веб-сайт',
diff --git a/src/lang/zh_CN.lang.php b/src/lang/zh_CN.lang.php
index 7da4897a..6649dd35 100644
--- a/src/lang/zh_CN.lang.php
+++ b/src/lang/zh_CN.lang.php
@@ -111,6 +111,8 @@ $sm_lang = array(
'status' => '状态',
'label' => '标签',
'domain' => '域名/IP',
+ 'timeout' => 'Timeout',
+ 'timeout_description' => 'Number of seconds to wait for the server to respond.',
'port' => '端口',
'type' => '类型',
'type_website' => '网站',
diff --git a/src/psm/Module/Server/Controller/AbstractServerController.class.php b/src/psm/Module/Server/Controller/AbstractServerController.class.php
index 4a763b2f..c2ac5955 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}
@@ -112,7 +113,8 @@ abstract class AbstractServerController extends AbstractController {
$server['error'] = htmlentities($server['error']);
$server['type'] = psm_get_lang('servers', 'type_' . $server['type']);
+ $server['timeout'] = ($server['timeout'] > 0) ? $server['timeout'] : PSM_CURL_TIMEOUT;
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..128b7ba0 100644
--- a/src/psm/Module/Server/Controller/ServerController.class.php
+++ b/src/psm/Module/Server/Controller/ServerController.class.php
@@ -190,6 +190,8 @@ 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'],
+ 'default_value_timeout' => PSM_CURL_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 +218,7 @@ class ServerController extends AbstractServerController {
$clean = array(
'label' => trim(strip_tags(psm_POST('label', ''))),
'ip' => trim(strip_tags(psm_POST('ip', ''))),
+ 'timeout' => (isset($_POST['timeout']) && intval($_POST['timeout']) > 0) ? intval($_POST['timeout']) : null,
'port' => intval(psm_POST('port', 0)),
'type' => psm_POST('type', ''),
'pattern' => psm_POST('pattern', ''),
@@ -362,6 +365,8 @@ 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_timeout_description' => psm_get_lang('servers', 'timeout_description'),
'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..3634aca6 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.0', '<')) {
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` smallint(1) unsigned NULL DEFAULT NULL,
PRIMARY KEY (`server_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
PSM_DB_PREFIX . 'servers_uptime' => "CREATE TABLE IF NOT EXISTS `" . PSM_DB_PREFIX . "servers_uptime` (
@@ -397,6 +398,7 @@ class Installer {
`value` varchar(255) NOT NULL,
PRIMARY KEY (`user_id`, `key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
+ $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `timeout` smallint(1) unsigned NULL DEFAULT NULL;";
$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
old mode 100755
new mode 100644
index e62a2b26..693dceb1
--- a/src/templates/server/server.tpl.html
+++ b/src/templates/server/server.tpl.html
@@ -146,10 +146,16 @@
+
+
{label_timeout}
+
+ s
+
+
-
\ No newline at end of file
+
diff --git a/src/templates/server/view.tpl.html b/src/templates/server/view.tpl.html
index eaf0a4db..87fed922 100644
--- a/src/templates/server/view.tpl.html
+++ b/src/templates/server/view.tpl.html
@@ -67,6 +67,10 @@
{label_sms}:
{sms}
+
+ {label_timeout}:
+ {timeout} s
+
{html_actions}
@@ -85,4 +89,4 @@
-
\ No newline at end of file
+