WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 8a7e2a4

Browse files
author
5050
committed
Improved services check and display
1 parent ff8a4e6 commit 8a7e2a4

File tree

2 files changed

+47
-93
lines changed

2 files changed

+47
-93
lines changed

dryden/sys/monitoring.class.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,39 @@ class sys_monitoring {
2121
* @param int $port The port number of which to check (eg. 25 for SMTP).
2222
* @param boolean $udp Port is a UDP port as opposed to a TCP port.
2323
* @return boolean
24+
* @change P.Peyremorte
25+
* - added port close if open successes
2426
*/
2527
static function PortStatus($port, $udp = false) {
2628
$timeout = ctrl_options::GetSystemOption('servicechk_to');
27-
if ($udp) {
28-
$ip = 'udp://' . $_SERVER['SERVER_ADDR'];
29-
} else {
30-
$ip = $_SERVER['SERVER_ADDR'];
31-
}
29+
$ip = ($udp) ? 'udp://' . $_SERVER['SERVER_ADDR'] : $_SERVER['SERVER_ADDR'];
3230
$fp = @fsockopen($ip, $port, $errno, $errstr, $timeout);
3331
if (!$fp) {
3432
runtime_hook::Execute('OnPortStatusDown');
35-
$retval = false;
36-
} else {
37-
runtime_hook::Execute('OnPortStatusUp');
38-
$retval = true;
33+
return false;
3934
}
40-
return $retval;
35+
fclose($fp);
36+
runtime_hook::Execute('OnPortStatusUp');
37+
return true;
38+
}
39+
40+
/**
41+
* Reports on whether a TCP port is listening for connections.
42+
* @author Pascal peyremorte
43+
* @param int $port The port number of which to check (eg. 25 for SMTP).
44+
* @return boolean
45+
*/
46+
static function LocalPortStatus($port) {
47+
$timeout = ctrl_options::GetSystemOption('servicechk_to');
48+
$fp = @fsockopen('127.0.0.1', $port, $errno, $errstr, $timeout);
49+
if ($fp !== false) {
50+
fclose($fp); #do not leave the port open.
51+
return true;
52+
}
53+
return false;
4154
}
4255

56+
4357
/**
4458
* Returns a nice human readable copy of the server uptime.
4559
* @author Bobby Allen ([email protected])

modules/services/code/controller.ext.php

Lines changed: 23 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -25,98 +25,38 @@
2525
* You should have received a copy of the GNU General Public License
2626
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2727
*
28+
* @changes P.Peyremorte
29+
* - added display of ports checked (80 may be not used!)
30+
* - refactored (replacement of duplicate string constructions by a fucntion)
2831
*/
2932
class module_controller extends ctrl_module
3033
{
34+
static private function status_port($PortNum, $iconpath)
35+
{
36+
$status = sys_monitoring::LocalPortStatus($PortNum);
37+
return ($status ? $iconpath.'up.gif">' : $iconpath.'down.gif">') . ' (port ' . $PortNum .' is ' . ($status ? 'open' : 'closed') . ')';
38+
}
3139

3240
static public function getServices()
3341
{
3442
global $controller;
43+
$iconpath = '<img src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/';
44+
3545
$line = "<h2>" . ui_language::translate("Checking status of services...") . "</h2>";
3646
$line .= "<table>";
37-
$line .= "<tr>";
38-
$line .= "<th>HTTP</th>";
39-
$line .= "<td>";
40-
41-
if (fs_director::CheckForEmptyValue(sys_monitoring::PortStatus(80))) {
42-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/down.gif\">";
43-
} else {
44-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
45-
}
46-
47-
$line .= "</td>";
48-
$line .= "</tr>";
49-
$line .= "<tr>";
50-
$line .= "<th>FTP</th>";
51-
$line .= "<td>";
52-
53-
if (fs_director::CheckForEmptyValue(sys_monitoring::PortStatus(21))) {
54-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/down.gif\">";
55-
} else {
56-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
57-
}
58-
59-
$line .= "</td>";
60-
$line .= "</tr>";
61-
$line .= "<tr>";
62-
$line .= "<th>SMTP</th>";
63-
$line .= "<td>";
64-
65-
if (fs_director::CheckForEmptyValue(sys_monitoring::PortStatus(25))) {
66-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/down.gif\">";
67-
} else {
68-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
69-
}
70-
71-
$line .= "</td>";
72-
$line .= "</tr>";
73-
$line .= "<tr>";
74-
$line .= "<th>POP3</th>";
75-
$line .= "<td>";
76-
77-
if (fs_director::CheckForEmptyValue(sys_monitoring::PortStatus(110))) {
78-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/down.gif\">";
79-
} else {
80-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
81-
}
82-
83-
$line .= "</td>";
84-
$line .= "</tr>";
85-
$line .= "<tr>";
86-
$line .= "<th>IMAP</th>";
87-
$line .= "<td>";
88-
89-
if (fs_director::CheckForEmptyValue(sys_monitoring::PortStatus(143))) {
90-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/down.gif\">";
91-
} else {
92-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
93-
}
94-
95-
$line .= "</td>";
96-
$line .= "</tr>";
97-
$line .= "<tr>";
98-
$line .= "<th>MySQL</th>";
99-
$line .= "<td>";
100-
/* MySQL has to be on-line as you are viewing this page, we made this 'static' to save on port queries (saves time) amongst other reasons. */
101-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
102-
103-
$line .= "</td>";
104-
$line .= "</tr>";
105-
$line .= "<tr>";
106-
$line .= "<th>DNS</th>";
107-
$line .= "<td>";
108-
109-
if (fs_director::CheckForEmptyValue(sys_monitoring::PortStatus(53))) {
110-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/down.gif\">";
111-
} else {
112-
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
113-
}
114-
115-
$line .= "</td>";
116-
$line .= "</tr>";
117-
$line .= "</table>";
118-
$line .= "<br><h2>" . ui_language::translate("Server Uptime") . "</h2>";
119-
$line .= ui_language::translate("Uptime") . ": " . sys_monitoring::ServerUptime();
47+
48+
$status = fs_director::CheckForEmptyValue(sys_monitoring::PortStatus($PortNum));
49+
50+
$line .= '<tr><th>HTTP</th><td>' . module_controller::status_port(80, $iconpath) . '</td></tr>';
51+
$line .= '<tr><th>FTP</th><td>' . module_controller::status_port(21, $iconpath) . '</td></tr>';
52+
$line .= '<tr><th>SMTP</th><td>' . module_controller::status_port(25, $iconpath) . '</td></tr>';
53+
$line .= '<tr><th>POP3</th><td>' . module_controller::status_port(110, $iconpath) . '</td></tr>';
54+
$line .= '<tr><th>IMAP</th><td>' . module_controller::status_port(143, $iconpath) . '</td></tr>';
55+
$line .= '<tr><th>MySQL</th><td>' . module_controller::status_port(3306, $iconpath) . '</td></tr>';
56+
$line .= '<tr><th>DNS</th><td>' . module_controller::status_port(53, $iconpath) . '</td></tr>';
57+
$line .= '</table>';
58+
$line .= '<br><h2>' . ui_language::translate('Server Uptime') . '</h2>';
59+
$line .= ui_language::translate('Uptime') . ": " . sys_monitoring::ServerUptime();
12060
return $line;
12161
}
12262

0 commit comments

Comments
 (0)