Added foundation

Not ready for use!
- Added translation
- Added fields to GUI
- Updated install script
- Added last_offline
- Display last_error

ToDo:
- Collect Raw output
- Collect Error raw output
- Save output to database
pull/627/head
Timz99 2018-04-25 17:23:36 +02:00
parent 46311d569e
commit 9c8b7e4842
No known key found for this signature in database
GPG Key ID: 4D8268DC68E8339D
9 changed files with 143 additions and 63 deletions

View File

@ -29,7 +29,7 @@
/** /**
* Current PSM version * Current PSM version
*/ */
define('PSM_VERSION', '3.2.2'); define('PSM_VERSION', '3.3.0');
/** /**
* URL to check for updates. Will not be checked if turned off on config page. * URL to check for updates. Will not be checked if turned off on config page.

View File

@ -49,6 +49,7 @@ $sm_lang = array(
'ok' => 'OK', 'ok' => 'OK',
'cancel' => 'Cancel', 'cancel' => 'Cancel',
'activate' => 'Activate', 'activate' => 'Activate',
'advanced' => 'Advanced',
// date/time format according the strftime php function format parameter http://php.net/manual/function.strftime.php // date/time format according the strftime php function format parameter http://php.net/manual/function.strftime.php
'short_day_format' => '%B %e', 'short_day_format' => '%B %e',
'long_day_format' => '%B %e, %Y', 'long_day_format' => '%B %e, %Y',
@ -158,6 +159,10 @@ $sm_lang = array(
'header_value_description' => 'Header value. Regular expressions are allowed.', 'header_value_description' => 'Header value. Regular expressions are allowed.',
'last_check' => 'Last check', 'last_check' => 'Last check',
'last_online' => 'Last online', 'last_online' => 'Last online',
'last_offline' => 'Last offline',
'last_raw' => 'Last positive raw output',
'last_error' => 'Last error',
'last_error_raw' => 'Last error raw output',
'monitoring' => 'Monitoring', 'monitoring' => 'Monitoring',
'no_monitoring' => 'No monitoring', 'no_monitoring' => 'No monitoring',
'email' => 'Email', 'email' => 'Email',

View File

@ -71,6 +71,7 @@ abstract class AbstractServerController extends AbstractController {
`s`.`rtime`, `s`.`rtime`,
`s`.`last_check`, `s`.`last_check`,
`s`.`last_online`, `s`.`last_online`,
`s`.`last_offline`,
`s`.`active`, `s`.`active`,
`s`.`email`, `s`.`email`,
`s`.`sms`, `s`.`sms`,
@ -80,7 +81,10 @@ abstract class AbstractServerController extends AbstractController {
`s`.`warning_threshold_counter`, `s`.`warning_threshold_counter`,
`s`.`timeout`, `s`.`timeout`,
`s`.`website_username`, `s`.`website_username`,
`s`.`website_password` `s`.`website_password`,
`s`.`last_offline`,
`s`.`last_error_raw`,
`s`.`last_raw`
FROM `".PSM_DB_PREFIX."servers` AS `s` FROM `".PSM_DB_PREFIX."servers` AS `s`
{$sql_join} {$sql_join}
{$sql_where} {$sql_where}
@ -102,6 +106,7 @@ abstract class AbstractServerController extends AbstractController {
protected function formatServer($server) { protected function formatServer($server) {
$server['rtime'] = round((float) $server['rtime'], 4); $server['rtime'] = round((float) $server['rtime'], 4);
$server['last_online'] = psm_timespan($server['last_online']); $server['last_online'] = psm_timespan($server['last_online']);
$server['last_offline'] = psm_timespan($server['last_offline']);
$server['last_check'] = psm_timespan($server['last_check']); $server['last_check'] = psm_timespan($server['last_check']);
$server['active'] = psm_get_lang('system', $server['active']); $server['active'] = psm_get_lang('system', $server['active']);
$server['email'] = psm_get_lang('system', $server['email']); $server['email'] = psm_get_lang('system', $server['email']);
@ -117,6 +122,9 @@ abstract class AbstractServerController extends AbstractController {
$server['type'] = psm_get_lang('servers', 'type_' . $server['type']); $server['type'] = psm_get_lang('servers', 'type_' . $server['type']);
$server['timeout'] = ($server['timeout'] > 0) ? $server['timeout'] : PSM_CURL_TIMEOUT; $server['timeout'] = ($server['timeout'] > 0) ? $server['timeout'] : PSM_CURL_TIMEOUT;
$server['last_error_raw'] = htmlentities($server['last_error_raw']);
$server['last_raw'] = htmlentities($server['last_raw']);
$url_actions = array('delete', 'edit', 'view'); $url_actions = array('delete', 'edit', 'view');
foreach($url_actions as $action) { foreach($url_actions as $action) {
$server['url_' . $action] = psm_build_url(array( $server['url_' . $action] = psm_build_url(array(

View File

@ -477,6 +477,10 @@ class ServerController extends AbstractServerController {
'label_last_check' => psm_get_lang('servers', 'last_check'), 'label_last_check' => psm_get_lang('servers', 'last_check'),
'label_rtime' => psm_get_lang('servers', 'latency'), 'label_rtime' => psm_get_lang('servers', 'latency'),
'label_last_online' => psm_get_lang('servers', 'last_online'), 'label_last_online' => psm_get_lang('servers', 'last_online'),
'label_last_offline' => psm_get_lang('servers', 'last_offline'),
'label_last_raw' => psm_get_lang('servers', 'last_raw'),
'label_last_error' => psm_get_lang('servers', 'last_error'),
'label_last_error_raw' => psm_get_lang('servers', 'last_error_raw'),
'label_monitoring' => psm_get_lang('servers', 'monitoring'), 'label_monitoring' => psm_get_lang('servers', 'monitoring'),
'label_email' => psm_get_lang('servers', 'email'), 'label_email' => psm_get_lang('servers', 'email'),
'label_send_email' => psm_get_lang('servers', 'send_email'), 'label_send_email' => psm_get_lang('servers', 'send_email'),
@ -495,6 +499,7 @@ class ServerController extends AbstractServerController {
'label_yes' => psm_get_lang('system', 'yes'), 'label_yes' => psm_get_lang('system', 'yes'),
'label_no' => psm_get_lang('system', 'no'), 'label_no' => psm_get_lang('system', 'no'),
'label_add_new' => psm_get_lang('system', 'add_new'), 'label_add_new' => psm_get_lang('system', 'add_new'),
'label_advanced' => psm_get_lang('system', 'advanced'),
); );
} }
@ -516,4 +521,3 @@ class ServerController extends AbstractServerController {
return $result; return $result;
} }
} }

View File

@ -307,6 +307,9 @@ class Installer {
if(version_compare($version_from, '3.2.2', '<')) { if(version_compare($version_from, '3.2.2', '<')) {
$this->upgrade322(); $this->upgrade322();
} }
if(version_compare($version_from, '3.3.0', '<')) {
$this->upgrade330();
}
psm_update_conf('version', $version_to); psm_update_conf('version', $version_to);
} }
@ -515,4 +518,16 @@ class Installer {
('telegram_api_token', '');"; ('telegram_api_token', '');";
$this->execSQL($queries); $this->execSQL($queries);
} }
/**
* Upgrade for v3.3.0 release
*/
protected function upgrade330() {
$queries = array();
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers`
ADD COLUMN VARCHAR(255) `last_offline` AFTER `last_online`,
ADD COLUMN VARCHAR(255) `last_error_raw` AFTER `website_password`,
ADD COLUMN VARCHAR(255) `last_raw` AFTER `last_error_raw`;";
$this->execSQL($queries);
}
} }

View File

@ -118,8 +118,9 @@ class StatusUpdater {
$save['last_online'] = date('Y-m-d H:i:s'); $save['last_online'] = date('Y-m-d H:i:s');
$save['warning_threshold_counter'] = 0; $save['warning_threshold_counter'] = 0;
} else { } 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['warning_threshold_counter'] = $this->server['warning_threshold_counter'] + 1;
$save['last_offline'] = date('Y-m-d H:i:s');
if($save['warning_threshold_counter'] < $this->server['warning_threshold']) { if($save['warning_threshold_counter'] < $this->server['warning_threshold']) {
// the server is offline but the error threshold has not been met yet. // the server is offline but the error threshold has not been met yet.

View File

@ -89,6 +89,26 @@
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
<tr>
<td id="advanced">{{ label_advanced }}&nbsp;<i class="icon-expand-arrow"></i></td>
<td>&nbsp;</td>
</tr>
<tr class="advanced">
<td>{{ label_last_offline }}:</td>
<td>{{ last_offline }}</td>
</tr>
<tr class="advanced">
<td>{{ label_last_error }}:</td>
<td>{{ error }}</td>
</tr>
<tr class="advanced">
<td>{{ label_last_error_raw }}:</td>
<td>{{ last_error_raw }}</td>
</tr>
<tr class="advanced">
<td>{{ label_last_raw }}:</td>
<td>{{ last_raw }}</td>
</tr>
{% if has_admin_actions %} {% if has_admin_actions %}
<tr> <tr>
<td class="hidden-small">&nbsp;</td> <td class="hidden-small">&nbsp;</td>

View File

@ -676,3 +676,6 @@ legend{
.icon-telegram { .icon-telegram {
background-position: -96px -168px; background-position: -96px -168px;
} }
.icon-expand-arrow {
background-position: -312px -120px;
}

View File

@ -1,24 +1,24 @@
$().ready(function() { $().ready(function() {
$('.show-modal').click(function (e) { $(".show-modal").click(function (e) {
var $this = $(this); var $this = $(this);
if ($this.is('a')) { if ($this.is("a")) {
e.preventDefault(); e.preventDefault();
} }
var $modal_id = $this.attr('data-modal-id') || 'main'; var $modal_id = $this.attr("data-modal-id") || "main";
var $modal = $('#' + $modal_id + 'Modal'); var $modal = $("#" + $modal_id + "Modal");
if($modal.length) { if($modal.length) {
$modal.find('.modalOKButton').data('modal-origin', $this); $modal.find(".modalOKButton").data("modal-origin", $this);
var param = $this.attr('data-modal-param'); var param = $this.attr("data-modal-param");
if(param) { if(param) {
var ary = param.split(','); var ary = param.split(",");
for (var index = 0; index < ary.length && index < 9; ++index) { for (var index = 0; index < ary.length && index < 9; ++index) {
var value = ary[index]; var value = ary[index];
$($modal).find('span.modalP' + (index+1)).text(value); $($modal).find("span.modalP" + (index+1)).text(value);
} }
} }
scroll(0, 0); scroll(0, 0);
$modal.modal('show'); $modal.modal("show");
} else { } else {
// Just in case we forgot the dialog box // Just in case we forgot the dialog box
var conf = confirm("Are you sure?"); var conf = confirm("Are you sure?");
@ -29,18 +29,19 @@ $().ready(function() {
return false; return false;
}); });
$('.modalOKButton').click(function(e) { $(".modalOKButton").click(function(e) {
var $this = $(this); var $this = $(this);
var $origin = $this.data('modal-origin'); var $origin = $this.data("modal-origin");
if ($origin.is('a')) { if ($origin.is("a")) {
window.location = $origin.attr('href'); window.location = $origin.attr("href");
} else { } else {
$origin.next('input[type=hidden]').attr('value', 1); $origin.next("input[type=hidden]").attr("value", 1);
$origin.closest('form').submit(); $origin.closest("form").submit();
} }
return false; return false;
}); });
$('select.multiselect').multiselect({
$("select.multiselect").multiselect({
includeSelectAllOption: true, includeSelectAllOption: true,
maxHeight: 400, maxHeight: 400,
enableCaseInsensitiveFiltering: true enableCaseInsensitiveFiltering: true
@ -51,71 +52,94 @@ $().ready(function() {
// popularPorts // popularPorts
// initial // initial
$('.portGroup').hide(); $(".portGroup").hide();
var portInput = $('#port').val(); var portInput = $("#port").val();
if (portInput != '') { if (portInput !== "") {
var findPopularPorts = $('#popularPorts').find('option[value=' + portInput + ']'); var findPopularPorts = $("#popularPorts").find('option[value=" + portInput + "]');
if(findPopularPorts.length) { if(findPopularPorts.length) {
$(findPopularPorts).attr("selected", "selected"); $(findPopularPorts).attr("selected", "selected");
} else { } else {
$('#popularPorts').find('option[value=custom]').attr("selected", "selected"); $("#popularPorts").find('option[value=custom]').attr("selected", "selected");
$('.portGroup').slideDown(); $(".portGroup").slideDown();
} }
} }
$('#popularPorts').change(function () { $("#popularPorts").change(function () {
changePopularPorts($(this).val(), false, $('#type').val()); changePopularPorts($(this).val(), false, $("#type").val());
}); });
// server type // server type
$('.types').hide(); $(".types").hide();
changeTypeSwitch($('#type').val()); changeTypeSwitch($("#type").val());
$('#type').change(function () { $("#type").change(function () {
changeTypeSwitch($('#type').val()); changeTypeSwitch($("#type").val());
changePopularPorts($('#popularPorts').val(), true, $('#type').val()); changePopularPorts($("#popularPorts").val(), true, $("#type").val());
});
// advanced information
$(".advanced").hide();
var advancedopen = 0;
$("#advanced").click(
function() {
advancedSwitch((advancedopen += 1) % 2);
}); });
}); });
function changeTypeSwitch(typeInput) { function advancedSwitch(statusInput) {
switch (typeInput) { switch (statusInput) {
case 'service': case 0:
$('.types').slideUp(); $(".advanced").slideUp();
$('.typeService').slideDown();
break; break;
case 'website': case 1:
$('.types').slideUp(); $(".advanced").slideDown();
$('.typeWebsite').slideDown();
break; break;
default: default:
$('.types').hide(); $(".advanced").hide();
}
}
function changeTypeSwitch(typeInput) {
switch (typeInput) {
case "service":
$(".types").slideUp();
$(".typeService").slideDown();
break;
case "website":
$(".types").slideUp();
$(".typeWebsite").slideDown();
break;
default:
$(".types").hide();
} }
} }
function changePopularPorts(popularPorts, changeType, typeInput) { function changePopularPorts(popularPorts, changeType, typeInput) {
if (changeType === true) { if (changeType === true) {
if (typeInput == 'service') { if (typeInput == "service") {
if (popularPorts == 'custom') { if (popularPorts == "custom") {
$('.portGroup').slideDown(); $(".portGroup").slideDown();
} else { } else {
$('.portGroup').hide(); $(".portGroup").hide();
} }
} }
} else { } else {
if (popularPorts == 'custom') { if (popularPorts == "custom") {
$('.portGroup').slideDown(); $(".portGroup").slideDown();
} else { } else {
$('#port').val(popularPorts); $("#port").val(popularPorts);
$('.portGroup').slideUp(); $(".portGroup").slideUp();
} }
} }
} }
function psm_xhr(mod, params, method, on_complete, options) { function psm_xhr(mod, params, method, on_complete, options) {
method = (typeof method == 'undefined') ? 'GET' : method; method = (typeof method == "undefined") ? "GET" : method;
var xhr_options = { var xhr_options = {
data: params, data: params,
@ -127,29 +151,29 @@ function psm_xhr(mod, params, method, on_complete, options) {
}; };
$.extend(xhr_options, options); $.extend(xhr_options, options);
var result = $.ajax('index.php?xhr=1&mod=' + mod, xhr_options); var result = $.ajax("index.php?xhr=1&mod=" + mod, xhr_options);
return result; return result;
} }
function psm_saveLayout(layout) { function psm_saveLayout(layout) {
var params = { var params = {
action: 'saveLayout', action: "saveLayout",
csrf: $("input[name=saveLayout_csrf]").val(), csrf: $("input[name=saveLayout_csrf]").val(),
layout: layout layout: layout
}; };
psm_xhr('server_status', params, 'POST'); psm_xhr("server_status", params, "POST");
} }
function psm_tooltips() { function psm_tooltips() {
$('input[data-toggle="tooltip"]').tooltip({ $('input[data-toggle="tooltip"]').tooltip({
'trigger':'hover', "trigger":"hover",
'placement': 'right', "placement": "right",
'container': 'body' "container": "body"
}); });
$('i[data-toggle="tooltip"]').tooltip({ $('i[data-toggle="tooltip"]').tooltip({
'trigger':'hover', "trigger":"hover",
'placement': 'bottom' "placement": "bottom"
}); });
} }
@ -172,14 +196,14 @@ function rtrim(str) {
} }
function psm_flash_message(message) { function psm_flash_message(message) {
var flashmessage = $('#flashmessage'); var flashmessage = $("#flashmessage");
if(flashmessage.length){ if(flashmessage.length){
if(typeof message != 'undefined') { if(typeof message != "undefined") {
flashmessage.html(message); flashmessage.html(message);
} }
var t = flashmessage.html(); var t = flashmessage.html();
var c = trim(t); var c = trim(t);
var t = c.replace('&nbsp;', ''); var t = c.replace("&nbsp;", "");
if(t){ if(t){
flashmessage.slideDown(); flashmessage.slideDown();
} }