From 962236bd42518f2c4d46fcd1473fbdb71aeee669 Mon Sep 17 00:00:00 2001 From: Pepijn Over Date: Fri, 10 Jan 2014 15:49:45 +0100 Subject: [PATCH] Adding full screen status page (partly merging from https://github.com/doctorjbeam/PHP-Server-Monitor-Plus/commit/6176db708409e6a9f4315fe28fae9e2a003deee9), and fixing menu highlighting --- CHANGELOG | 1 + README.md | 1 + classes/mod/modStatus.class.php | 93 +++++++++++++++++++++++++++++++++ functions.inc.php | 32 ++++++++++++ index.php | 4 +- tpl/config.tpl.html | 5 -- tpl/log.tpl.html | 5 -- tpl/main.tpl.html | 45 +++++++++------- tpl/servers.tpl.html | 10 ---- tpl/status.tpl.html | 71 +++++++++++++++++++++++++ tpl/users.tpl.html | 10 ---- 11 files changed, 225 insertions(+), 52 deletions(-) create mode 100755 classes/mod/modStatus.class.php create mode 100755 tpl/status.tpl.html diff --git a/CHANGELOG b/CHANGELOG index ff0e5a93..203badb2 100755 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ - Support for mosms provider by Andreas Ek (https://github.com/EkAndreas/PHP-Server-Monitor-Plus/commit/105c734a02477befc01831e3b9b2b8fefd9b5ca5). - Language files are now automatically detected, instead of a hardcoded list. - Adding Korean language file (thanks to Ik-Jun). +- Large status page by Michael Greenhill. ######################### # diff --git a/README.md b/README.md index 663ffc1a..f42b3210 100755 --- a/README.md +++ b/README.md @@ -162,6 +162,7 @@ The second part is the actual message. There are a few variables you can use in * Korean translation - Ik-Jun * Bootstrap implementation - Luiz Alberto S. Ribeiro * Mosms implementation - Andreas Ek + * Status page - Michael Greenhill ## License diff --git a/classes/mod/modStatus.class.php b/classes/mod/modStatus.class.php new file mode 100755 index 00000000..44ece599 --- /dev/null +++ b/classes/mod/modStatus.class.php @@ -0,0 +1,93 @@ +. + * + * @package phpservermon + * @author Michael Greenhill + * @author Pepijn Over + * @copyright Copyright (c) 2008-2014 Pepijn Over + * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 + * @version Release: @package_version@ + * @link http://phpservermon.neanderthal-technology.com/ + **/ + +/** + * Status module + */ +class modStatus extends modCore { + + function __construct() { + parent::__construct(); + } + + // override parent::createHTML() + public function createHTML() { + $this->createHTMLList(); + + return parent::createHTML(); + } + + /** + * Prepare the template to show a list of all servers + * @todo move the background colurs to the config + */ + protected function createHTMLList() { + $this->setTemplateId('status', 'status.tpl.html'); + $this->addFooter(false); + + // get the active servers from database + $servers = $this->db->select( + SM_DB_PREFIX.'servers', + array('active' => 'yes'), + array('server_id', 'label', 'status', 'last_online', 'last_check', 'rtime') + ); + + $offline = array(); + $online = array(); + + $tpl_data = array( + 'bg' => '#000000', + 'offline_bg' => '#a00000', + 'offline_fg' => '#f7cece', + 'online_bg' => '#53a000', + 'online_fg' => '#d8f7ce', + ); + $this->tpl->addTemplateData($this->getTemplateId(), $tpl_data); + + foreach ($servers as $server) { + $server['last_checked_nice'] = sm_timespan($server['last_check']); + $server['last_online_nice'] = sm_timespan($server['last_online']); + + if ($server['status'] == "off") { + $offline[$server['server_id']] = $server; + } else { + $online[$server['server_id']] = $server; + } + } + + // add servers to template + $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'servers_offline', $offline); + $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'servers_online', $online); + // add refresh (bit overkill perhaps to do it this way..?) + $this->tpl->newTemplate('main_auto_refresh', 'main.tpl.html'); + $this->tpl->addTemplateData('main_auto_refresh', array('seconds' => 30)); + $this->tpl->addTemplateData('main', array('auto_refresh' => $this->tpl->getTemplate('main_auto_refresh'))); + } +} + +?> \ No newline at end of file diff --git a/functions.inc.php b/functions.inc.php index 7eb28ff6..f7a333ad 100755 --- a/functions.inc.php +++ b/functions.inc.php @@ -228,6 +228,38 @@ function sm_curl_get($href) { return $result; } +/** + * Get a "nice" timespan message + * + * Source: http://www.interactivetools.com/forum/forum-posts.php?postNum=2208966 + * @param int $time + * @return string + * @todo add translation to timespan messages + */ +function sm_timespan($time) { + if ($time !== intval($time)) { $time = strtotime($time); } + $d = time() - $time; + if ($time < strtotime(date('Y-m-d 00:00:00')) - 60*60*24*3) { + $format = 'F j'; + if (date('Y') !== date('Y', $time)) { + $format .= ", Y"; + } + return date($format, $time); + } + if ($d >= 60*60*24) { + $day = 'Yesterday'; + if (date('l', time() - 60*60*24) !== date('l', $time)) { $day = date('l', $time); } + return $day . " at " . date('g:ia', $time); + } + if ($d >= 60*60*2) { return intval($d / (60*60)) . " hours ago"; } + if ($d >= 60*60) { return "about an hour ago"; } + if ($d >= 60*2) { return intval($d / 60) . " minutes ago"; } + if ($d >= 60) { return "about a minute ago"; } + if ($d >= 2) { return intval($d) . " seconds ago"; } + + return "a few seconds ago"; +} + /** * Check if an update is available for PHP Server Monitor * diff --git a/index.php b/index.php index 5e76666a..21ed3175 100755 --- a/index.php +++ b/index.php @@ -26,7 +26,7 @@ **/ if(!file_exists('config.inc.php')) { - die('Failed to locate config file. Please read docs/README for more information on how to setup PHP Server Monitor.'); + die('Failed to locate config file. Please read README.md for more information on how to setup PHP Server Monitor.'); } require_once 'config.inc.php'; @@ -38,7 +38,7 @@ if(isset($_GET['action']) && $_GET['action'] == 'check') { } $type = (!isset($_GET['type'])) ? 'servers' : $_GET['type']; -$allowed_types = array('servers', 'users', 'log', 'config'); +$allowed_types = array('servers', 'users', 'log', 'config', 'status'); // make sure user selected a valid type. if so, include the file and add to template if(!in_array($type, $allowed_types)) { diff --git a/tpl/config.tpl.html b/tpl/config.tpl.html index 92d6accb..9b574c93 100755 --- a/tpl/config.tpl.html +++ b/tpl/config.tpl.html @@ -124,11 +124,6 @@ - diff --git a/tpl/log.tpl.html b/tpl/log.tpl.html index 57aa9ab8..c4f99c3e 100755 --- a/tpl/log.tpl.html +++ b/tpl/log.tpl.html @@ -19,11 +19,6 @@ - diff --git a/tpl/main.tpl.html b/tpl/main.tpl.html index 35bada22..769026da 100755 --- a/tpl/main.tpl.html +++ b/tpl/main.tpl.html @@ -33,17 +33,20 @@ {title} {update_available} - - - + {html_footer} @@ -106,4 +99,16 @@ - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/tpl/servers.tpl.html b/tpl/servers.tpl.html index 61320b8a..7c3c508e 100755 --- a/tpl/servers.tpl.html +++ b/tpl/servers.tpl.html @@ -61,11 +61,6 @@ - @@ -136,9 +131,4 @@ - \ No newline at end of file diff --git a/tpl/status.tpl.html b/tpl/status.tpl.html new file mode 100755 index 00000000..a8f6024f --- /dev/null +++ b/tpl/status.tpl.html @@ -0,0 +1,71 @@ + + +
+ +
+

{label}

+

Last online: {last_online_nice}

+

Last checked: {last_checked_nice}

+
+ + {servers_offline} +
+
+ +
+

{label}

+

Last checked: {last_checked_nice}

+

Latency: {rtime}s

+
+ + {servers_online} +
+ \ No newline at end of file diff --git a/tpl/users.tpl.html b/tpl/users.tpl.html index cf1f399d..f24f7895 100755 --- a/tpl/users.tpl.html +++ b/tpl/users.tpl.html @@ -40,11 +40,6 @@ - @@ -93,9 +88,4 @@ $(document).bind('ready', function(){ - \ No newline at end of file