Merge branch 'Halvra-develop' into develop

This commit is contained in:
Pepijn Over 2014-07-28 11:14:26 +02:00
commit 239ece7848
22 changed files with 66 additions and 10 deletions

View File

@ -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 <https://www.smsglobal.com/>.
* Support for Danish SMS provider Smsit <http://www.smsit.dk/>

View File

@ -50,6 +50,10 @@ The following people have contributed to the development of PHP Server Monitor:
* SMSGlobal SMS gateway
* Julien Lebouteiller <https://github.com/Halvra>
* Custom time-out per server
Translators
+++++++++++

View File

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

View File

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

View File

@ -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' => 'Сайт',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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' => 'Веб-сайт',

View File

@ -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' => '网站',

View File

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

View File

@ -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'),

View File

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

View File

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

8
src/templates/server/server.tpl.html Executable file → Normal file
View File

@ -146,10 +146,16 @@
<input class="input-mini" type="text" id="warning_threshold" name="warning_threshold" value="{edit_value_warning_threshold}" maxlength="5" data-toggle="tooltip" title="{label_warning_threshold_description}" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="timeout">{label_timeout}</label>
<div class="controls">
<input class="input-mini" type="text" id="timeout" name="timeout" value="{edit_value_timeout}" placeholder="{default_value_timeout}" maxlength="10" data-toggle="tooltip" title="{label_timeout_description}" /> s
</div>
</div>
<div class="form-actions">
<button class="btn btn-success" type="submit">{label_save}</button>
<a class="btn" href="{url_go_back}" >{label_go_back}</a>
</div>
</fieldset>
</form>
<!--%%tpl_server_update-->
<!--%%tpl_server_update-->

View File

@ -67,6 +67,10 @@
<td>{label_sms}:</td>
<td>{sms}</td>
</tr>
<tr>
<td>{label_timeout}:</td>
<td>{timeout} s</td>
</tr>
{html_actions}
</tbody>
</table>
@ -85,4 +89,4 @@
</a>
</td>
</tr>
<!--%%tpl_server_view_admin_actions-->
<!--%%tpl_server_view_admin_actions-->