From 132a730d7133793a9c398c708ba6d1968d058f5e Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 5 Sep 2018 21:46:18 +0200 Subject: [PATCH 1/5] Removed last offline duration parentheses if empty (#641) --- CHANGELOG.rst | 1 + src/psm/Module/Server/Controller/AbstractServerController.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c69b5ecf..6ef6f223 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Changelog Not yet released ---------------- +* #640: Removed () after last offline value when the last offline duration is unknown. * #637: Added php extensions to composer required list, spelling fixes in changelog and composer update. * #635: Changed server order on ?&mod=user&action=edit&id=x. * #634: Changed ' to " in sql query, both were used. diff --git a/src/psm/Module/Server/Controller/AbstractServerController.php b/src/psm/Module/Server/Controller/AbstractServerController.php index 0e5d8b4d..53145b66 100644 --- a/src/psm/Module/Server/Controller/AbstractServerController.php +++ b/src/psm/Module/Server/Controller/AbstractServerController.php @@ -107,7 +107,8 @@ abstract class AbstractServerController extends AbstractController { $server['last_online'] = psm_timespan($server['last_online']); $server['last_offline'] = psm_timespan($server['last_offline']); if ($server['last_offline'] != psm_get_lang('system', 'never')) { - $server['last_offline_duration'] = "(".$server['last_offline_duration'].")"; + $server['last_offline_duration'] = is_null($server['last_offline_duration']) ? + null : "(".$server['last_offline_duration'].")"; } $server['last_check'] = psm_timespan($server['last_check']); $server['active'] = psm_get_lang('system', $server['active']); From 7aa7ec363b41e6b9c193641b4330dd60a0f39e49 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 5 Sep 2018 22:34:19 +0200 Subject: [PATCH 2/5] Mark specific HTTP status codes as online (#628) Add option to specify which HTTP status codes are considered as "online". Closing #175. --- CHANGELOG.rst | 1 + src/includes/psmconfig.inc.php | 2 +- src/lang/en_US.lang.php | 2 ++ src/lang/nl_NL.lang.php | 2 ++ .../Controller/AbstractServerController.php | 1 + .../Module/Server/Controller/ServerController.php | 4 ++++ src/psm/Util/Install/Installer.php | 15 ++++++++++++++- src/psm/Util/Server/Updater/StatusUpdater.php | 5 +++-- .../default/module/server/server/update.tpl.html | 6 ++++++ 9 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6ef6f223..272f724f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Changelog Not yet released ---------------- +* #628: Added the option to mark specific HTTP status codes as online. * #640: Removed () after last offline value when the last offline duration is unknown. * #637: Added php extensions to composer required list, spelling fixes in changelog and composer update. * #635: Changed server order on ?&mod=user&action=edit&id=x. diff --git a/src/includes/psmconfig.inc.php b/src/includes/psmconfig.inc.php index 51753238..f4435097 100644 --- a/src/includes/psmconfig.inc.php +++ b/src/includes/psmconfig.inc.php @@ -29,7 +29,7 @@ /** * Current PSM version */ -define('PSM_VERSION', '3.3.1'); +define('PSM_VERSION', '3.4.0'); /** * 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 57eb41b9..12bdc42e 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -169,6 +169,8 @@ $sm_lang = array( 'pattern_description' => 'If this pattern is not found on the website, the server will be marked online/offline. Regular expressions are allowed.', 'pattern_online' => 'Pattern indicates website is', 'pattern_online_description' => 'Online: If this pattern is not found on the website, the server will be marked online. Offline: If this pattern is not found on the website, the server will be marked offline.', + 'allow_http_status' => 'Allow HTTP status code', + 'allow_http_status_description' => 'Mark website as online. HTTP Status codes lower then 400 are marked as online by default. Seperate with |. Example: 401|403.', 'header' => 'Header', 'header_name_description' => 'Header name (case-sensitive)', 'header_value_description' => 'Header value. Regular expressions are allowed.', diff --git a/src/lang/nl_NL.lang.php b/src/lang/nl_NL.lang.php index b167596d..ae3bb39d 100644 --- a/src/lang/nl_NL.lang.php +++ b/src/lang/nl_NL.lang.php @@ -142,6 +142,8 @@ $sm_lang = array( 'type_service' => 'Service', 'pattern' => 'Zoek voor tekst/regex', 'pattern_description' => 'Als dit patroon niet gevonden wordt op de website, zal de server als offline gemarkeerd worden. Regular expressions zijn toegestaan.', + 'allow_http_status' => 'Sta HTTP status code toe', + 'allow_http_status_description' => 'Markeer website als online. HTTP status code lager dan 400 worden standaard als online gemarkeerd. Scheiden met |. Bijvoorbeeld: 401|403.', 'last_check' => 'Laatst gecontroleerd', 'last_online' => 'Laatst online', 'last_offline' => 'Laatst offline', diff --git a/src/psm/Module/Server/Controller/AbstractServerController.php b/src/psm/Module/Server/Controller/AbstractServerController.php index 53145b66..07a74a9e 100644 --- a/src/psm/Module/Server/Controller/AbstractServerController.php +++ b/src/psm/Module/Server/Controller/AbstractServerController.php @@ -65,6 +65,7 @@ abstract class AbstractServerController extends AbstractController { `s`.`label`, `s`.`pattern`, `s`.`pattern_online`, + `s`.`allow_http_status`, `s`.`header_name`, `s`.`header_value`, `s`.`status`, diff --git a/src/psm/Module/Server/Controller/ServerController.php b/src/psm/Module/Server/Controller/ServerController.php index fdeed658..5998e7a6 100644 --- a/src/psm/Module/Server/Controller/ServerController.php +++ b/src/psm/Module/Server/Controller/ServerController.php @@ -200,6 +200,7 @@ class ServerController extends AbstractServerController { 'default_value_timeout' => PSM_CURL_TIMEOUT, 'edit_value_pattern' => $edit_server['pattern'], 'edit_pattern_selected_'.$edit_server['pattern_online'] => 'selected="selected"', + 'edit_value_allow_http_status' => $edit_server['allow_http_status'], 'edit_value_header_name' => $edit_server['header_name'], 'edit_value_header_value' => $edit_server['header_value'], 'edit_value_warning_threshold' => $edit_server['warning_threshold'], @@ -267,6 +268,7 @@ class ServerController extends AbstractServerController { 'type' => psm_POST('type', ''), 'pattern' => psm_POST('pattern', ''), 'pattern_online' => in_array($_POST['pattern_online'], array('yes', 'no')) ? $_POST['pattern_online'] : 'yes', + 'allow_http_status' => psm_POST('allow_http_status', ''), 'header_name' => psm_POST('header_name', ''), 'header_value' => psm_POST('header_value', ''), 'rtime' => psm_POST('rtime', '0.0000000'), @@ -473,6 +475,8 @@ class ServerController extends AbstractServerController { 'label_pattern_description' => psm_get_lang('servers', 'pattern_description'), 'label_pattern_online' => psm_get_lang('servers', 'pattern_online'), 'label_pattern_online_description' => psm_get_lang('servers', 'pattern_online_description'), + 'label_allow_http_status' => psm_get_lang('servers', 'allow_http_status'), + 'label_allow_http_status_description' => psm_get_lang('servers', 'allow_http_status_description'), 'label_header' => psm_get_lang('servers', 'header'), 'label_header_name_description' => psm_get_lang('servers', 'header_name_description'), 'label_header_value_description' => psm_get_lang('servers', 'header_value_description'), diff --git a/src/psm/Util/Install/Installer.php b/src/psm/Util/Install/Installer.php index cfc328dc..dd81afde 100644 --- a/src/psm/Util/Install/Installer.php +++ b/src/psm/Util/Install/Installer.php @@ -227,8 +227,9 @@ class Installer { `port` int(5) unsigned NOT NULL, `label` varchar(255) NOT NULL, `type` enum('ping','service','website') NOT NULL default 'service', - `pattern` varchar(255) NOT NULL, + `pattern` varchar(255) NOT NULL default '', `pattern_online` enum('yes','no') NOT NULL default 'yes', + `allow_http_status` varchar(255) NOT NULL default '', `header_name` varchar(255) NOT NULL default '', `header_value` varchar(255) NOT NULL default '', `status` enum('on','off') NOT NULL default 'on', @@ -313,6 +314,9 @@ class Installer { if (version_compare($version_from, '3.3.0', '<')) { $this->upgrade330(); } + if (version_compare($version_from, '3.4.0', '<')) { + $this->upgrade340(); + } psm_update_conf('version', $version_to); } @@ -539,6 +543,15 @@ class Installer { if (psm_get_conf('sms_gateway') == 'mollie') { psm_update_conf('sms_gateway', 'messagebird'); } + } + + /** + * Upgrade for v3.4.0 release + */ + protected function upgrade340() { + $queries = array(); + $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD `allow_http_status` VARCHAR(255) NOT NULL DEFAULT '' AFTER j`pattern_online`;"; + $this->execSQL($queries); } } diff --git a/src/psm/Util/Server/Updater/StatusUpdater.php b/src/psm/Util/Server/Updater/StatusUpdater.php index 3879c57a..045aeed3 100644 --- a/src/psm/Util/Server/Updater/StatusUpdater.php +++ b/src/psm/Util/Server/Updater/StatusUpdater.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', 'pattern_online', 'header_name', 'header_value', 'status', 'active', 'warning_threshold', + 'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'pattern_online', 'allow_http_status', 'header_name', 'header_value', 'status', 'active', 'warning_threshold', 'warning_threshold_counter', 'timeout', 'website_username', 'website_password', 'last_offline' )); if (empty($this->server)) { @@ -250,8 +250,9 @@ class StatusUpdater { $code = $code_matches[1][0]; $msg = $code_matches[2][0]; + $allow_http_status = explode("|", $this->server['allow_http_status']); // All status codes starting with a 4 or higher mean trouble! - if (substr($code, 0, 1) >= '4') { + if (substr($code, 0, 1) >= '4' && !in_array($code ,$allow_http_status)) { $this->error = "HTTP STATUS ERROR: ".$code.' '.$msg; $result = false; } else { diff --git a/src/templates/default/module/server/server/update.tpl.html b/src/templates/default/module/server/server/update.tpl.html index dee8558d..55b42ae9 100644 --- a/src/templates/default/module/server/server/update.tpl.html +++ b/src/templates/default/module/server/server/update.tpl.html @@ -74,6 +74,12 @@ +
+ +
+ +
+
From 72b262c7060f91897d5f58b4f689e05bba1c59ad Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 5 Sep 2018 22:42:08 +0200 Subject: [PATCH 3/5] Added the option to specify the request method (#631) --- CHANGELOG.rst | 1 + src/includes/functions.inc.php | 7 +- src/lang/en_US.lang.php | 4 ++ .../Controller/AbstractServerController.php | 1 + .../Server/Controller/ServerController.php | 8 ++- src/psm/Util/Install/Installer.php | 5 +- src/psm/Util/Server/Updater/StatusUpdater.php | 5 +- .../module/server/server/update.tpl.html | 26 +++++++ static/js/scripts.js | 67 ++++++++++++------- 9 files changed, 93 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 272f724f..64692cb5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Changelog Not yet released ---------------- +* #631: Added option to specify the request method. * #628: Added the option to mark specific HTTP status codes as online. * #640: Removed () after last offline value when the last offline duration is unknown. * #637: Added php extensions to composer required list, spelling fixes in changelog and composer update. diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 0b2ceba2..a0e3b32d 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -343,9 +343,10 @@ function psm_parse_msg($status, $type, $vars) { * @param boolean $add_agent add user agent? * @param string|bool $website_username Username website * @param string|bool $website_password Password website + * @param string|bool $request_method Request method like GET, POST etc. * @return string cURL result */ -function psm_curl_get($href, $header = false, $body = true, $timeout = null, $add_agent = true, $website_username = false, $website_password = false) { +function psm_curl_get($href, $header = false, $body = true, $timeout = null, $add_agent = true, $website_username = false, $website_password = false, $request_method = null) { $timeout = $timeout == null ? PSM_CURL_TIMEOUT : intval($timeout); $ch = curl_init(); @@ -358,6 +359,10 @@ function psm_curl_get($href, $header = false, $body = true, $timeout = null, $ad curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_ENCODING, ''); + + if (!empty($request_method)) { + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request_method); + } if ($website_username !== false && $website_password !== false && !empty($website_username) && !empty($website_password)) { curl_setopt($ch, CURLOPT_USERPWD, $website_username.":".$website_password); diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 12bdc42e..f9f76f83 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -48,6 +48,7 @@ $sm_lang = array( 'go_back' => 'Go back', 'ok' => 'OK', 'cancel' => 'Cancel', + 'none' => 'None', 'activate' => 'Activate', // date/time format according the strftime php function format parameter http://php.net/manual/function.strftime.php 'short_day_format' => '%B %e', @@ -160,6 +161,9 @@ $sm_lang = array( 'port' => 'Port', 'custom_port' => 'Custom Port', 'popular_ports' => 'Popular Ports', + 'request_method' => 'Request method', + 'custom_request_method' => 'Custom request method', + 'popular_request_methods' => 'Popular request methods', 'please_select' => 'Please select', 'type' => 'Type', 'type_website' => 'Website', diff --git a/src/psm/Module/Server/Controller/AbstractServerController.php b/src/psm/Module/Server/Controller/AbstractServerController.php index 07a74a9e..0e6b8fe8 100644 --- a/src/psm/Module/Server/Controller/AbstractServerController.php +++ b/src/psm/Module/Server/Controller/AbstractServerController.php @@ -61,6 +61,7 @@ abstract class AbstractServerController extends AbstractController { `s`.`server_id`, `s`.`ip`, `s`.`port`, + `s`.`request_method`, `s`.`type`, `s`.`label`, `s`.`pattern`, diff --git a/src/psm/Module/Server/Controller/ServerController.php b/src/psm/Module/Server/Controller/ServerController.php index 5998e7a6..193ba20c 100644 --- a/src/psm/Module/Server/Controller/ServerController.php +++ b/src/psm/Module/Server/Controller/ServerController.php @@ -196,6 +196,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_request_method' => $edit_server['request_method'], 'edit_value_timeout' => $edit_server['timeout'], 'default_value_timeout' => PSM_CURL_TIMEOUT, 'edit_value_pattern' => $edit_server['pattern'], @@ -265,6 +266,7 @@ class ServerController extends AbstractServerController { 'website_username' => psm_POST('website_username'), 'website_password' => $encrypted_password, 'port' => intval(psm_POST('port', 0)), + 'request_method' => empty(psm_POST('request_method')) ? null : psm_POST('request_method'), 'type' => psm_POST('type', ''), 'pattern' => psm_POST('pattern', ''), 'pattern_online' => in_array($_POST['pattern_online'], array('yes', 'no')) ? $_POST['pattern_online'] : 'yes', @@ -465,8 +467,12 @@ class ServerController extends AbstractServerController { 'label_fieldset_permissions' => psm_get_lang('servers', 'fieldset_permissions'), 'label_port' => psm_get_lang('servers', 'port'), 'label_custom_port' => psm_get_lang('servers', 'custom_port'), - 'label_please_select' => psm_get_lang('servers', 'please_select'), 'label_popular_ports' => psm_get_lang('servers', 'popular_ports'), + 'label_request_method' => psm_get_lang('servers', 'request_method'), + 'label_custom_request_method' => psm_get_lang('servers', 'custom_request_method'), + 'label_popular_request_methods' => psm_get_lang('servers', 'popular_request_methods'), + 'label_none' => psm_get_lang('system', 'none'), + 'label_please_select' => psm_get_lang('servers', 'please_select'), 'label_type' => psm_get_lang('servers', 'type'), 'label_website' => psm_get_lang('servers', 'type_website'), 'label_service' => psm_get_lang('servers', 'type_service'), diff --git a/src/psm/Util/Install/Installer.php b/src/psm/Util/Install/Installer.php index dd81afde..5cfe126a 100644 --- a/src/psm/Util/Install/Installer.php +++ b/src/psm/Util/Install/Installer.php @@ -225,6 +225,7 @@ class Installer { `server_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `ip` varchar(500) NOT NULL, `port` int(5) unsigned NOT NULL, + `request_method` varchar(50) unsigned NULL, `label` varchar(255) NOT NULL, `type` enum('ping','service','website') NOT NULL default 'service', `pattern` varchar(255) NOT NULL default '', @@ -550,8 +551,8 @@ class Installer { */ protected function upgrade340() { $queries = array(); - $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD `allow_http_status` VARCHAR(255) NOT NULL DEFAULT '' AFTER j`pattern_online`;"; + $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `request_method` varchar(50) NULL AFTER `port`;"; + $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `allow_http_status` VARCHAR(255) NOT NULL DEFAULT '' AFTER `pattern_online`;"; $this->execSQL($queries); - } } diff --git a/src/psm/Util/Server/Updater/StatusUpdater.php b/src/psm/Util/Server/Updater/StatusUpdater.php index 045aeed3..8f9dcbb8 100644 --- a/src/psm/Util/Server/Updater/StatusUpdater.php +++ b/src/psm/Util/Server/Updater/StatusUpdater.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', 'pattern_online', 'allow_http_status', 'header_name', 'header_value', 'status', 'active', 'warning_threshold', + 'server_id', 'ip', 'port', 'request_method', 'label', 'type', 'pattern', 'pattern_online', 'allow_http_status', 'header_name', 'header_value', 'status', 'active', 'warning_threshold', 'warning_threshold_counter', 'timeout', 'website_username', 'website_password', 'last_offline' )); if (empty($this->server)) { @@ -229,7 +229,8 @@ class StatusUpdater { $this->server['timeout'], true, $this->server['website_username'], - psm_password_decrypt($this->server['server_id'].psm_get_conf('password_encrypt_key'), $this->server['website_password']) + psm_password_decrypt($this->server['server_id'].psm_get_conf('password_encrypt_key'), $this->server['website_password']), + $this->server['request_method'] ); $this->rtime = (microtime(true) - $starttime); diff --git a/src/templates/default/module/server/server/update.tpl.html b/src/templates/default/module/server/server/update.tpl.html index 55b42ae9..6b4f0a6c 100644 --- a/src/templates/default/module/server/server/update.tpl.html +++ b/src/templates/default/module/server/server/update.tpl.html @@ -59,6 +59,32 @@
+
+ +
+ +
+
+
+ +
+ +
+
diff --git a/static/js/scripts.js b/static/js/scripts.js index 46669303..bcebcabd 100755 --- a/static/js/scripts.js +++ b/static/js/scripts.js @@ -6,11 +6,11 @@ $().ready(function() { } var $modal_id = $this.attr('data-modal-id') || 'main'; var $modal = $('#' + $modal_id + 'Modal'); - if($modal.length) { + if ($modal.length) { $modal.find('.modalOKButton').data('modal-origin', $this); var param = $this.attr('data-modal-param'); - if(param) { + if (param) { var ary = param.split(','); for (var index = 0; index < ary.length && index < 9; ++index) { var value = ary[index]; @@ -56,25 +56,42 @@ $().ready(function() { if (portInput != '') { var findPopularPorts = $('#popularPorts').find('option[value=' + portInput + ']'); - if(findPopularPorts.length) { + if (findPopularPorts.length) { $(findPopularPorts).attr("selected", "selected"); } else { $('#popularPorts').find('option[value=custom]').attr("selected", "selected"); $('.portGroup').slideDown(); } - } + } $('#popularPorts').change(function () { - changePopularPorts($(this).val(), false, $('#type').val()); + changePopular($(this).val(), $('#type').val()); }); + // popularRequestMethods + // initial + $('.requestMethodGroup').hide(); + var requestMethodInput = $('#requestMethod').val(); + + if (requestMethodInput != '') { + var findPopularRequestMethods = $('#popularRequestMethods').find('option[value=' + requestMethodInput + ']'); + if (findPopularRequestMethods.length) { + $(findPopularRequestMethods).attr("selected", "selected"); + } else { + $('#popularRequestMethods').find('option[value=custom]').attr("selected", "selected"); + $('.requestMethodGroup').slideDown(); + } + } + + $('#popularRequestMethods').change(function () { + changePopular($(this).val(), $('#type').val()); + }); // server type $('.types').hide(); changeTypeSwitch($('#type').val()); $('#type').change(function () { changeTypeSwitch($('#type').val()); - changePopularPorts($('#popularPorts').val(), true, $('#type').val()); }); }); @@ -83,34 +100,34 @@ function changeTypeSwitch(typeInput) { case 'service': $('.types').slideUp(); $('.typeService').slideDown(); + changePopular($('#popularPorts').val(), typeInput, true); break; case 'website': $('.types').slideUp(); $('.typeWebsite').slideDown(); + changePopular($('#popularRequestMethods').val(), typeInput, true); break; default: - $('.types').hide(); + $('.types').slideUp(); } } -function changePopularPorts(popularPorts, changeType, typeInput) { - if (changeType === true) { - if (typeInput == 'service') { - if (popularPorts == 'custom') { - $('.portGroup').slideDown(); - } else { - $('.portGroup').hide(); - } - } +function changePopular(inputValue, typeInput, changedType = false) { + if (typeInput == 'website') { + htmlClass = '.requestMethodGroup'; + htmlID = '#requestMethod'; + } else if (typeInput == 'service') { + htmlClass = '.portGroup'; + htmlID = '#port'; + } + + if (inputValue == 'custom') { + $(htmlClass).slideDown(); } else { - if (popularPorts == 'custom') { - $('.portGroup').slideDown(); - } else { - $('#port').val(popularPorts); - $('.portGroup').slideUp(); - } + changedType ? $(htmlClass).hide() : $(htmlClass).slideUp(); + $(htmlID).val(inputValue); } } @@ -173,14 +190,14 @@ function rtrim(str) { function psm_flash_message(message) { var flashmessage = $('#flashmessage'); - if(flashmessage.length){ - if(typeof message != 'undefined') { + if (flashmessage.length) { + if (typeof message != 'undefined') { flashmessage.html(message); } var t = flashmessage.html(); var c = trim(t); var t = c.replace(' ', ''); - if(t){ + if (t) { flashmessage.slideDown(); } } From b26f85d975bcfacad2d3439fc41958ddf9c1009f Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 5 Sep 2018 22:52:23 +0200 Subject: [PATCH 4/5] Added option to view latest (failing) server response and error (#627) Shows: - latest error. - latest positive response. - latest failure response. --- CHANGELOG.rst | 1 + src/lang/en_US.lang.php | 4 ++++ .../Controller/AbstractServerController.php | 9 ++++++++- .../Server/Controller/ServerController.php | 5 ++++- src/psm/Util/Install/Installer.php | 6 ++++++ src/psm/Util/Server/Updater/StatusUpdater.php | 17 +++++++++++++++-- .../default/module/server/server/view.tpl.html | 16 ++++++++++++++++ static/css/style.css | 3 +++ 8 files changed, 57 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 64692cb5..c8cc710a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Changelog Not yet released ---------------- +* #627: Latest server output, error and output during a failure will be saved and are shown on the server page. * #631: Added option to specify the request method. * #628: Added the option to mark specific HTTP status codes as online. * #640: Removed () after last offline value when the last offline duration is unknown. diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index f9f76f83..dff43c83 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -50,6 +50,7 @@ $sm_lang = array( 'cancel' => 'Cancel', 'none' => 'None', 'activate' => 'Activate', + 'advanced' => 'Advanced', // date/time format according the strftime php function format parameter http://php.net/manual/function.strftime.php 'short_day_format' => '%B %e', 'long_day_format' => '%B %e, %Y', @@ -181,6 +182,9 @@ $sm_lang = array( 'last_check' => 'Last check', 'last_online' => 'Last online', 'last_offline' => 'Last offline', + 'last_output' => 'Last positive output', + 'last_error' => 'Last error', + 'last_error_output' => 'Last error output', 'monitoring' => 'Monitoring', 'no_monitoring' => 'No monitoring', 'email' => 'Email', diff --git a/src/psm/Module/Server/Controller/AbstractServerController.php b/src/psm/Module/Server/Controller/AbstractServerController.php index 0e6b8fe8..dab57c25 100644 --- a/src/psm/Module/Server/Controller/AbstractServerController.php +++ b/src/psm/Module/Server/Controller/AbstractServerController.php @@ -85,7 +85,10 @@ abstract class AbstractServerController extends AbstractController { `s`.`warning_threshold_counter`, `s`.`timeout`, `s`.`website_username`, - `s`.`website_password` + `s`.`website_password`, + `s`.`last_error`, + `s`.`last_error_output`, + `s`.`last_output` FROM `".PSM_DB_PREFIX."servers` AS `s` {$sql_join} {$sql_where} @@ -127,6 +130,10 @@ abstract class AbstractServerController extends AbstractController { $server['type'] = psm_get_lang('servers', 'type_'.$server['type']); $server['timeout'] = ($server['timeout'] > 0) ? $server['timeout'] : PSM_CURL_TIMEOUT; + $server['last_error'] = htmlentities($server['last_error']); + $server['last_error_output'] = htmlentities($server['last_error_output']); + $server['last_output'] = htmlentities($server['last_output']); + $url_actions = array('delete', 'edit', 'view'); foreach ($url_actions as $action) { $server['url_'.$action] = psm_build_url(array( diff --git a/src/psm/Module/Server/Controller/ServerController.php b/src/psm/Module/Server/Controller/ServerController.php index 193ba20c..46d1f371 100644 --- a/src/psm/Module/Server/Controller/ServerController.php +++ b/src/psm/Module/Server/Controller/ServerController.php @@ -490,6 +490,9 @@ class ServerController extends AbstractServerController { 'label_rtime' => psm_get_lang('servers', 'latency'), 'label_last_online' => psm_get_lang('servers', 'last_online'), 'label_last_offline' => psm_get_lang('servers', 'last_offline'), + 'label_last_output' => psm_get_lang('servers', 'last_output'), + 'label_last_error' => psm_get_lang('servers', 'last_error'), + 'label_last_error_output' => psm_get_lang('servers', 'last_error_output'), 'label_monitoring' => psm_get_lang('servers', 'monitoring'), 'label_email' => psm_get_lang('servers', 'email'), 'label_send_email' => psm_get_lang('servers', 'send_email'), @@ -508,6 +511,7 @@ class ServerController extends AbstractServerController { 'label_yes' => psm_get_lang('system', 'yes'), 'label_no' => psm_get_lang('system', 'no'), 'label_add_new' => psm_get_lang('system', 'add_new'), + 'label_advanced' => psm_get_lang('system', 'advanced'), 'label_online' => psm_get_lang('system', 'online'), 'label_offline' => psm_get_lang('system', 'offline'), ); @@ -531,4 +535,3 @@ class ServerController extends AbstractServerController { return $result; } } - diff --git a/src/psm/Util/Install/Installer.php b/src/psm/Util/Install/Installer.php index 5cfe126a..2ad74fe9 100644 --- a/src/psm/Util/Install/Installer.php +++ b/src/psm/Util/Install/Installer.php @@ -250,6 +250,9 @@ class Installer { `timeout` smallint(1) unsigned NULL DEFAULT NULL, `website_username` varchar(255) DEFAULT NULL, `website_password` varchar(255) DEFAULT NULL, + `last_error` varchar(255) DEFAULT NULL, + `last_error_output` varchar(255) DEFAULT NULL, + `last_output` varchar(255) 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` ( @@ -551,6 +554,9 @@ class Installer { */ protected function upgrade340() { $queries = array(); + $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `last_error` VARCHAR(255) NULL AFTER `website_password`;"; + $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `last_error_output` TEXT NULL AFTER `last_error`;"; + $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `last_output` TEXT NULL AFTER `last_error_output`;"; $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `request_method` varchar(50) NULL AFTER `port`;"; $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `allow_http_status` VARCHAR(255) NOT NULL DEFAULT '' AFTER `pattern_online`;"; $this->execSQL($queries); diff --git a/src/psm/Util/Server/Updater/StatusUpdater.php b/src/psm/Util/Server/Updater/StatusUpdater.php index 8f9dcbb8..a55a4978 100644 --- a/src/psm/Util/Server/Updater/StatusUpdater.php +++ b/src/psm/Util/Server/Updater/StatusUpdater.php @@ -37,6 +37,8 @@ use psm\Service\Database; class StatusUpdater { public $error = ''; + public $header = ''; + public $rtime = 0; public $status_new = false; @@ -69,6 +71,9 @@ class StatusUpdater { * * Please note: if the server is down but has not met the warning threshold, this will return true * to avoid any "we are down" events. + * + * @todo Get last_output when there is a HPPT 50x error. + * * @param int $server_id * @param int $max_runs how many times should the script recheck the server if unavailable. default is 2 * @return boolean TRUE if server is up, FALSE otherwise @@ -76,6 +81,7 @@ class StatusUpdater { public function update($server_id, $max_runs = 2) { $this->server_id = $server_id; $this->error = ''; + $this->header = ''; $this->rtime = ''; // get server info from db @@ -105,8 +111,11 @@ class StatusUpdater { $save = array( 'last_check' => date('Y-m-d H:i:s'), 'error' => $this->error, - 'rtime' => $this->rtime, + 'rtime' => $this->rtime ); + if(!empty($this->error)){ + $save['last_error'] = $this->error; + } // log the uptime before checking the warning threshold, // so that the warnings can still be reviewed in the server history. @@ -116,6 +125,7 @@ class StatusUpdater { // if the server is on, add the last_online value and reset the error threshold counter $save['status'] = 'on'; $save['last_online'] = date('Y-m-d H:i:s'); + $save['last_output'] = $this->header; $save['warning_threshold_counter'] = 0; if ($this->server['status'] == 'off') { $online_date = new \DateTime($save['last_online']); @@ -124,8 +134,10 @@ class StatusUpdater { $save['last_offline_duration'] = trim(psm_format_interval($difference)); } } else { - // server is offline, increase the error counter + // server is offline, increase the error counter and set last offline $save['warning_threshold_counter'] = $this->server['warning_threshold_counter'] + 1; + $save['last_offline'] = date('Y-m-d H:i:s'); + $save['last_error_output'] = empty($this->header) ? "Could not get headers. probably HTTP 50x error." : $this->header; if ($save['warning_threshold_counter'] < $this->server['warning_threshold']) { // the server is offline but the error threshold has not been met yet. @@ -232,6 +244,7 @@ class StatusUpdater { psm_password_decrypt($this->server['server_id'].psm_get_conf('password_encrypt_key'), $this->server['website_password']), $this->server['request_method'] ); + $this->header = $curl_result; $this->rtime = (microtime(true) - $starttime); diff --git a/src/templates/default/module/server/server/view.tpl.html b/src/templates/default/module/server/server/view.tpl.html index af5224ea..2aeee9b2 100644 --- a/src/templates/default/module/server/server/view.tpl.html +++ b/src/templates/default/module/server/server/view.tpl.html @@ -93,6 +93,22 @@ {% endif %} + + {{ label_advanced }}  +   + + + {{ label_last_error }}: + {{ last_error }} + + + {{ label_last_output }}: + {{ last_output }} + + + {{ label_last_error_output }}: + {{ last_error_output }} + {% if has_admin_actions %}   diff --git a/static/css/style.css b/static/css/style.css index ece2d6fb..89f618b6 100755 --- a/static/css/style.css +++ b/static/css/style.css @@ -676,3 +676,6 @@ legend{ .icon-telegram { background-position: -96px -168px; } +.icon-expand-arrow { + background-position: -312px -120px; +} From d33c891be2af587eaacb525a8a51f4f490bcaa5f Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 5 Sep 2018 22:58:50 +0200 Subject: [PATCH 5/5] Added redirect check (#626) --- CHANGELOG.rst | 1 + src/lang/en_US.lang.php | 3 ++ src/lang/nl_NL.lang.php | 37 ++++++++----------- .../Controller/AbstractServerController.php | 1 + .../Server/Controller/ServerController.php | 6 +++ src/psm/Util/Install/Installer.php | 12 +++++- src/psm/Util/Server/Updater/StatusUpdater.php | 16 +++++++- .../module/server/server/update.tpl.html | 9 +++++ 8 files changed, 59 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c8cc710a..338b2aa9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Changelog Not yet released ---------------- +* #626: Added redirect check. * #627: Latest server output, error and output during a failure will be saved and are shown on the server page. * #631: Added option to specify the request method. * #628: Added the option to mark specific HTTP status codes as online. diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index dff43c83..d474ece3 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -47,6 +47,7 @@ $sm_lang = array( 'back_to_top' => 'Back to top', 'go_back' => 'Go back', 'ok' => 'OK', + 'bad' => 'bad', 'cancel' => 'Cancel', 'none' => 'None', 'activate' => 'Activate', @@ -174,6 +175,8 @@ $sm_lang = array( 'pattern_description' => 'If this pattern is not found on the website, the server will be marked online/offline. Regular expressions are allowed.', 'pattern_online' => 'Pattern indicates website is', 'pattern_online_description' => 'Online: If this pattern is not found on the website, the server will be marked online. Offline: If this pattern is not found on the website, the server will be marked offline.', + 'redirect_check' => 'Redirecting to another domain is', + 'redirect_check_description' => 'Redirect to another domain is usually a bad sign.', 'allow_http_status' => 'Allow HTTP status code', 'allow_http_status_description' => 'Mark website as online. HTTP Status codes lower then 400 are marked as online by default. Seperate with |. Example: 401|403.', 'header' => 'Header', diff --git a/src/lang/nl_NL.lang.php b/src/lang/nl_NL.lang.php index ae3bb39d..b29493ec 100644 --- a/src/lang/nl_NL.lang.php +++ b/src/lang/nl_NL.lang.php @@ -27,7 +27,11 @@ $sm_lang = array( 'name' => 'Nederlands - Dutch', - 'locale' => array('nl_NL.UTF-8', 'nl_NL', 'dutch'), + 'locale' => array( + '0' => 'nl_NL.UTF-8', + '1' => 'nl_NL', + '2' => 'dutch', + ), 'locale_tag' => 'nl', 'locale_dir' => 'ltr', 'system' => array( @@ -47,8 +51,8 @@ $sm_lang = array( 'back_to_top' => 'Terug naar boven', 'go_back' => 'Terug', 'ok' => 'OK', + 'bad' => 'niet goed', 'cancel' => 'Cancel', - // date/time format according the strftime php function format parameter http://php.net/manual/function.strftime.php 'short_day_format' => '%B %e', 'long_day_format' => '%B %e, %Y', 'yesterday_format' => 'Gisteren om %k:%M', @@ -142,6 +146,8 @@ $sm_lang = array( 'type_service' => 'Service', 'pattern' => 'Zoek voor tekst/regex', 'pattern_description' => 'Als dit patroon niet gevonden wordt op de website, zal de server als offline gemarkeerd worden. Regular expressions zijn toegestaan.', + 'redirect_check' => 'Omleiden naar een ander domein is', + 'redirect_check_description' => 'Een omleiding naar een ander domein is meestal een slecht teken.', 'allow_http_status' => 'Sta HTTP status code toe', 'allow_http_status_description' => 'Markeer website als online. HTTP status code lager dan 400 worden standaard als online gemarkeerd. Scheiden met |. Bijvoorbeeld: 401|403.', 'last_check' => 'Laatst gecontroleerd', @@ -174,7 +180,6 @@ $sm_lang = array( 'warning_threshold_description' => 'Aantal mislukte pogingen voordat de server als offline gemarkeerd wordt.', 'chart_last_week' => 'Afgelopen week', 'chart_history' => 'Geschiedenis', - // Charts date format according jqPlot date format http://www.jqplot.com/docs/files/plugins/jqplot-dateAxisRenderer-js.html 'chart_day_format' => '%d-%m-%Y', 'chart_long_date_format' => '%d-%m-%Y %H:%M:%S', 'chart_short_date_format' => '%d-%m %H:%M', @@ -216,14 +221,7 @@ $sm_lang = array( 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Voordat je Pushover kunt gebruiken moet je een App registreren via hun website, en daarvan de App API Token hier invullen.', 'alert_type' => 'Selecteer wanneer je een notificatie wilt', - 'alert_type_description' => 'Status verandert: '. - 'Je ontvangt alleen bericht wanneer een server van status verandert. Dus van online -> offline of offline -> online.
'. - '
Offline: '. - 'Je ontvangt bericht wanneer een server offline gaat voor de *EERSTE KEER*. Bijvoorbeeld, '. - 'je cronjob draait iedere 15 min en je server gaat down om 01:00 en blijft offline tot 06:00. '. - 'Je krijgt 1 bericht om 01:00 en dat is het.
'. - '
Altijd: '. - 'Je krijgt een bericht elke keer dat het script draait en een website is down, ook al is de site al een paar uur offline.', + 'alert_type_description' => 'Status verandert: Je ontvangt alleen bericht wanneer een server van status verandert. Dus van online -> offline of offline -> online.

Offline: Je ontvangt bericht wanneer een server offline gaat voor de *EERSTE KEER*. Bijvoorbeeld, je cronjob draait iedere 15 min en je server gaat down om 01:00 en blijft offline tot 06:00. Je krijgt 1 bericht om 01:00 en dat is het.

Altijd: Je krijgt een bericht elke keer dat het script draait en een website is down, ook al is de site al een paar uur offline.', 'alert_type_status' => 'Status verandering', 'alert_type_offline' => 'Offline', 'alert_type_always' => 'Altijd', @@ -242,11 +240,7 @@ $sm_lang = array( 'settings_notification' => 'Notificatie instellingen', 'settings_log' => 'Log instellingen', 'auto_refresh' => 'Auto-refresh', - 'auto_refresh_servers' => - 'Auto-herladen servers pagina.
'. - ''. - 'Tijd in seconden, als de tijd 0 is wordt de pagina niet ververst.'. - '', + 'auto_refresh_servers' => 'Auto-herladen servers pagina.
Tijd in seconden, als de tijd 0 is wordt de pagina niet ververst.', 'seconds' => 'seconden', 'test' => 'Test', 'test_email' => 'Er zal een email verstuurd worden naar het email adres in je profiel.', @@ -268,18 +262,17 @@ $sm_lang = array( 'log_retention_period_description' => 'Aantal dagen dat logs van notificaties en archieven van server uptime worden bewaard. Vul 0 in om log opruiming uit te zetten.', 'log_retention_days' => 'dagen', ), - // for newlines in the email messages use
'notifications' => array( 'off_sms' => 'Server %LABEL% is DOWN: ip=%IP%, poort=%PORT%. Fout=%ERROR%', 'off_email_subject' => 'BELANGRIJK: Server %LABEL% is DOWN', - 'off_email_body' => "De server kon niet worden bereikt:

Server: %LABEL%
IP: %IP%
Poort: %PORT%
Fout: %ERROR%
Datum: %DATE%", + 'off_email_body' => 'De server kon niet worden bereikt:

Server: %LABEL%
IP: %IP%
Poort: %PORT%
Fout: %ERROR%
Datum: %DATE%', 'off_pushover_title' => 'Server %LABEL% is DOWN', - 'off_pushover_message' => "De server kon niet worden bereikt:

Server: %LABEL%
IP: %IP%
Poort: %PORT%
Fout: %ERROR%
Datum: %DATE%", + 'off_pushover_message' => 'De server kon niet worden bereikt:

Server: %LABEL%
IP: %IP%
Poort: %PORT%
Fout: %ERROR%
Datum: %DATE%', 'on_sms' => 'Server %LABEL% is RUNNING: ip=%IP%, poort=%PORT%, tijd offline=%LAST_OFFLINE_DURATION%', 'on_email_subject' => 'BELANGRIJK: Server %LABEL% is RUNNING', - 'on_email_body' => "Server %LABEL% is na %LAST_OFFLINE_DURATION% weer online:

Server: %LABEL%
IP: %IP%
Poort: %PORT%
Datum: %DATE%", + 'on_email_body' => 'Server %LABEL% is na %LAST_OFFLINE_DURATION% weer online:

Server: %LABEL%
IP: %IP%
Poort: %PORT%
Datum: %DATE%', 'on_pushover_title' => 'Server %LABEL% is RUNNING', - 'on_pushover_message' => "Server %LABEL% is na %LAST_OFFLINE_DURATION% weer online:

Server: %LABEL%
IP: %IP%
Poort: %PORT%
Datum: %DATE%", + 'on_pushover_message' => 'Server %LABEL% is na %LAST_OFFLINE_DURATION% weer online:

Server: %LABEL%
IP: %IP%
Poort: %PORT%
Datum: %DATE%', ), 'login' => array( 'welcome_usermenu' => 'Welkom, %user_name%', @@ -308,4 +301,4 @@ $sm_lang = array( '401_unauthorized' => 'Unauthorized', '401_unauthorized_description' => 'Je hebt niet de juiste bevoegdheden om deze pagina te bekijken.', ), -); +); \ No newline at end of file diff --git a/src/psm/Module/Server/Controller/AbstractServerController.php b/src/psm/Module/Server/Controller/AbstractServerController.php index dab57c25..b5c7ee83 100644 --- a/src/psm/Module/Server/Controller/AbstractServerController.php +++ b/src/psm/Module/Server/Controller/AbstractServerController.php @@ -66,6 +66,7 @@ abstract class AbstractServerController extends AbstractController { `s`.`label`, `s`.`pattern`, `s`.`pattern_online`, + `s`.`redirect_check`, `s`.`allow_http_status`, `s`.`header_name`, `s`.`header_value`, diff --git a/src/psm/Module/Server/Controller/ServerController.php b/src/psm/Module/Server/Controller/ServerController.php index 46d1f371..5dc88438 100644 --- a/src/psm/Module/Server/Controller/ServerController.php +++ b/src/psm/Module/Server/Controller/ServerController.php @@ -201,6 +201,7 @@ class ServerController extends AbstractServerController { 'default_value_timeout' => PSM_CURL_TIMEOUT, 'edit_value_pattern' => $edit_server['pattern'], 'edit_pattern_selected_'.$edit_server['pattern_online'] => 'selected="selected"', + 'edit_redirect_check_selected_'.$edit_server['redirect_check'] => 'selected="selected"', 'edit_value_allow_http_status' => $edit_server['allow_http_status'], 'edit_value_header_name' => $edit_server['header_name'], 'edit_value_header_value' => $edit_server['header_value'], @@ -270,6 +271,7 @@ class ServerController extends AbstractServerController { 'type' => psm_POST('type', ''), 'pattern' => psm_POST('pattern', ''), 'pattern_online' => in_array($_POST['pattern_online'], array('yes', 'no')) ? $_POST['pattern_online'] : 'yes', + 'redirect_check' => in_array($_POST['redirect_check'], array('ok', 'bad')) ? $_POST['redirect_check'] : 'bad', 'allow_http_status' => psm_POST('allow_http_status', ''), 'header_name' => psm_POST('header_name', ''), 'header_value' => psm_POST('header_value', ''), @@ -481,6 +483,8 @@ class ServerController extends AbstractServerController { 'label_pattern_description' => psm_get_lang('servers', 'pattern_description'), 'label_pattern_online' => psm_get_lang('servers', 'pattern_online'), 'label_pattern_online_description' => psm_get_lang('servers', 'pattern_online_description'), + 'label_redirect_check' => psm_get_lang('servers', 'redirect_check'), + 'label_redirect_check_description' => psm_get_lang('servers', 'redirect_check_description'), 'label_allow_http_status' => psm_get_lang('servers', 'allow_http_status'), 'label_allow_http_status_description' => psm_get_lang('servers', 'allow_http_status_description'), 'label_header' => psm_get_lang('servers', 'header'), @@ -514,6 +518,8 @@ class ServerController extends AbstractServerController { 'label_advanced' => psm_get_lang('system', 'advanced'), 'label_online' => psm_get_lang('system', 'online'), 'label_offline' => psm_get_lang('system', 'offline'), + 'label_ok' => psm_get_lang('system', 'ok'), + 'label_bad' => psm_get_lang('system', 'bad'), ); } diff --git a/src/psm/Util/Install/Installer.php b/src/psm/Util/Install/Installer.php index 2ad74fe9..ccb4a299 100644 --- a/src/psm/Util/Install/Installer.php +++ b/src/psm/Util/Install/Installer.php @@ -126,7 +126,7 @@ class Installer { $this->log('Populating database...'); $queries = array(); - $queries[] = "INSERT INTO `".PSM_DB_PREFIX."servers` (`ip`, `port`, `label`, `type`, `pattern`, `pattern_online`, `status`, `rtime`, `active`, `email`, `sms`, `pushover`, `telegram`) VALUES ('http://sourceforge.net/index.php', 80, 'SourceForge', 'website', '', 'yes','on', '0.0000000', 'yes', 'yes', 'yes', 'yes', 'yes'), ('smtp.gmail.com', 465, 'Gmail SMTP', 'service', '', 'yes', 'on', '0.0000000', 'yes', 'yes', 'yes', 'yes', 'yes')"; + $queries[] = "INSERT INTO `".PSM_DB_PREFIX."servers` (`ip`, `port`, `label`, `type`, `pattern`, `pattern_online`, `redirect_check`, `status`, `rtime`, `active`, `email`, `sms`, `pushover`, `telegram`) VALUES ('http://sourceforge.net/index.php', 80, 'SourceForge', 'website', '', 'yes', 'bad', 'on', '0.0000000', 'yes', 'yes', 'yes', 'yes', 'yes'), ('smtp.gmail.com', 465, 'Gmail SMTP', 'service', '', 'yes', 'bad','on', '0.0000000', 'yes', 'yes', 'yes', 'yes', 'yes')"; $queries[] = "INSERT INTO `".PSM_DB_PREFIX."users_servers` (`user_id`,`server_id`) VALUES (1, 1), (1, 2);"; $queries[] = "INSERT INTO `".PSM_DB_PREFIX."config` (`key`, `value`) VALUE ('language', 'en_US'), @@ -230,6 +230,7 @@ class Installer { `type` enum('ping','service','website') NOT NULL default 'service', `pattern` varchar(255) NOT NULL default '', `pattern_online` enum('yes','no') NOT NULL default 'yes', + `redirect_check` enum('ok','bad') NOT NULL default 'bad', `allow_http_status` varchar(255) NOT NULL default '', `header_name` varchar(255) NOT NULL default '', `header_value` varchar(255) NOT NULL default '', @@ -554,11 +555,18 @@ class Installer { */ protected function upgrade340() { $queries = array(); + /** + * Redirect_check is first set to default ok. + * If you have a lot of server that are redirecting, + * this will make sure you're servers stay online. + */ + $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `allow_http_status` VARCHAR(255) NOT NULL DEFAULT '' AFTER `pattern_online`;"; + $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD `redirect_check` ENUM( 'ok','bad' ) NOT NULL DEFAULT 'ok' AFTER `allow_http_status`;"; + $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` CHANGE `redirect_check` `redirect_check` ENUM('ok','bad') NOT NULL DEFAULT 'bad';"; $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `last_error` VARCHAR(255) NULL AFTER `website_password`;"; $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `last_error_output` TEXT NULL AFTER `last_error`;"; $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `last_output` TEXT NULL AFTER `last_error_output`;"; $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `request_method` varchar(50) NULL AFTER `port`;"; - $queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `allow_http_status` VARCHAR(255) NOT NULL DEFAULT '' AFTER `pattern_online`;"; $this->execSQL($queries); } } diff --git a/src/psm/Util/Server/Updater/StatusUpdater.php b/src/psm/Util/Server/Updater/StatusUpdater.php index a55a4978..3e9fffab 100644 --- a/src/psm/Util/Server/Updater/StatusUpdater.php +++ b/src/psm/Util/Server/Updater/StatusUpdater.php @@ -88,7 +88,7 @@ class StatusUpdater { $this->server = $this->db->selectRow(PSM_DB_PREFIX.'servers', array( 'server_id' => $server_id, ), array( - 'server_id', 'ip', 'port', 'request_method', 'label', 'type', 'pattern', 'pattern_online', 'allow_http_status', 'header_name', 'header_value', 'status', 'active', 'warning_threshold', + 'server_id', 'ip', 'port', 'request_method', 'label', 'type', 'pattern', 'pattern_online', 'allow_http_status', 'redirect_check', 'header_name', 'header_value', 'status', 'active', 'warning_threshold', 'warning_threshold_counter', 'timeout', 'website_username', 'website_password', 'last_offline' )); if (empty($this->server)) { @@ -272,7 +272,7 @@ class StatusUpdater { } else { $result = true; - //Okay, the HTTP status is good : 2xx or 3xx. Now we have to test the pattern if it's set up + // Okay, the HTTP status is good : 2xx or 3xx. Now we have to test the pattern if it's set up if ($this->server['pattern'] != '') { // Check to see if the body should not contain specified pattern // Check to see if the pattern was [not] found. @@ -284,6 +284,18 @@ class StatusUpdater { } } + // Check if the website redirects to another domain + if ($this->server['redirect_check'] == 'bad'){ + $location_matches = array(); + preg_match('/(Location: )(https*:\/\/)([a-zA-Z.:0-9]*)([\/][[:alnum:][:punct:]]*)/', $curl_result, $location_matches); + $ip_matches = array(); + preg_match('/(https*:\/\/)([a-zA-Z.:0-9]*)([\/][[:alnum:][:punct:]]*)/', $this->server['ip'], $ip_matches); + if($location_matches[3] !== $ip_matches[2]){ + $this->error = "The IP/URL redirects to another domain."; + $result = false; + } + } + // Should we check a header ? if ($this->server['header_name'] != '' && $this->server['header_value'] != '') { $header_flag = false; diff --git a/src/templates/default/module/server/server/update.tpl.html b/src/templates/default/module/server/server/update.tpl.html index 6b4f0a6c..c0934dd9 100644 --- a/src/templates/default/module/server/server/update.tpl.html +++ b/src/templates/default/module/server/server/update.tpl.html @@ -101,6 +101,15 @@
+ +
+ +
+
+