Skip to content

Commit

Permalink
Improved services check and display
Browse files Browse the repository at this point in the history
  • Loading branch information
5050 committed Nov 6, 2014
1 parent ff8a4e6 commit 8a7e2a4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 93 deletions.
34 changes: 24 additions & 10 deletions dryden/sys/monitoring.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,39 @@ class sys_monitoring {
* @param int $port The port number of which to check (eg. 25 for SMTP).
* @param boolean $udp Port is a UDP port as opposed to a TCP port.
* @return boolean
* @change P.Peyremorte
* - added port close if open successes
*/
static function PortStatus($port, $udp = false) {
$timeout = ctrl_options::GetSystemOption('servicechk_to');
if ($udp) {
$ip = 'udp://' . $_SERVER['SERVER_ADDR'];
} else {
$ip = $_SERVER['SERVER_ADDR'];
}
$ip = ($udp) ? 'udp://' . $_SERVER['SERVER_ADDR'] : $_SERVER['SERVER_ADDR'];
$fp = @fsockopen($ip, $port, $errno, $errstr, $timeout);
if (!$fp) {
runtime_hook::Execute('OnPortStatusDown');
$retval = false;
} else {
runtime_hook::Execute('OnPortStatusUp');
$retval = true;
return false;
}
return $retval;
fclose($fp);
runtime_hook::Execute('OnPortStatusUp');
return true;
}

/**
* Reports on whether a TCP port is listening for connections.
* @author Pascal peyremorte
* @param int $port The port number of which to check (eg. 25 for SMTP).
* @return boolean
*/
static function LocalPortStatus($port) {
$timeout = ctrl_options::GetSystemOption('servicechk_to');
$fp = @fsockopen('127.0.0.1', $port, $errno, $errstr, $timeout);
if ($fp !== false) {
fclose($fp); #do not leave the port open.
return true;
}
return false;
}


/**
* Returns a nice human readable copy of the server uptime.
* @author Bobby Allen (ballen@bobbyallen.me)
Expand Down
106 changes: 23 additions & 83 deletions modules/services/code/controller.ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,98 +25,38 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @changes P.Peyremorte
* - added display of ports checked (80 may be not used!)
* - refactored (replacement of duplicate string constructions by a fucntion)
*/
class module_controller extends ctrl_module
{
static private function status_port($PortNum, $iconpath)
{
$status = sys_monitoring::LocalPortStatus($PortNum);
return ($status ? $iconpath.'up.gif">' : $iconpath.'down.gif">') . ' (port ' . $PortNum .' is ' . ($status ? 'open' : 'closed') . ')';
}

static public function getServices()
{
global $controller;
$iconpath = '<img src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/';

$line = "<h2>" . ui_language::translate("Checking status of services...") . "</h2>";
$line .= "<table>";
$line .= "<tr>";
$line .= "<th>HTTP</th>";
$line .= "<td>";

if (fs_director::CheckForEmptyValue(sys_monitoring::PortStatus(80))) {
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/down.gif\">";
} else {
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
}

$line .= "</td>";
$line .= "</tr>";
$line .= "<tr>";
$line .= "<th>FTP</th>";
$line .= "<td>";

if (fs_director::CheckForEmptyValue(sys_monitoring::PortStatus(21))) {
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/down.gif\">";
} else {
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
}

$line .= "</td>";
$line .= "</tr>";
$line .= "<tr>";
$line .= "<th>SMTP</th>";
$line .= "<td>";

if (fs_director::CheckForEmptyValue(sys_monitoring::PortStatus(25))) {
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/down.gif\">";
} else {
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
}

$line .= "</td>";
$line .= "</tr>";
$line .= "<tr>";
$line .= "<th>POP3</th>";
$line .= "<td>";

if (fs_director::CheckForEmptyValue(sys_monitoring::PortStatus(110))) {
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/down.gif\">";
} else {
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
}

$line .= "</td>";
$line .= "</tr>";
$line .= "<tr>";
$line .= "<th>IMAP</th>";
$line .= "<td>";

if (fs_director::CheckForEmptyValue(sys_monitoring::PortStatus(143))) {
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/down.gif\">";
} else {
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
}

$line .= "</td>";
$line .= "</tr>";
$line .= "<tr>";
$line .= "<th>MySQL</th>";
$line .= "<td>";
/* 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. */
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";

$line .= "</td>";
$line .= "</tr>";
$line .= "<tr>";
$line .= "<th>DNS</th>";
$line .= "<td>";

if (fs_director::CheckForEmptyValue(sys_monitoring::PortStatus(53))) {
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/down.gif\">";
} else {
$line .= "<img src=\"modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/up.gif\">";
}

$line .= "</td>";
$line .= "</tr>";
$line .= "</table>";
$line .= "<br><h2>" . ui_language::translate("Server Uptime") . "</h2>";
$line .= ui_language::translate("Uptime") . ": " . sys_monitoring::ServerUptime();

$status = fs_director::CheckForEmptyValue(sys_monitoring::PortStatus($PortNum));

$line .= '<tr><th>HTTP</th><td>' . module_controller::status_port(80, $iconpath) . '</td></tr>';
$line .= '<tr><th>FTP</th><td>' . module_controller::status_port(21, $iconpath) . '</td></tr>';
$line .= '<tr><th>SMTP</th><td>' . module_controller::status_port(25, $iconpath) . '</td></tr>';
$line .= '<tr><th>POP3</th><td>' . module_controller::status_port(110, $iconpath) . '</td></tr>';
$line .= '<tr><th>IMAP</th><td>' . module_controller::status_port(143, $iconpath) . '</td></tr>';
$line .= '<tr><th>MySQL</th><td>' . module_controller::status_port(3306, $iconpath) . '</td></tr>';
$line .= '<tr><th>DNS</th><td>' . module_controller::status_port(53, $iconpath) . '</td></tr>';
$line .= '</table>';
$line .= '<br><h2>' . ui_language::translate('Server Uptime') . '</h2>';
$line .= ui_language::translate('Uptime') . ": " . sys_monitoring::ServerUptime();
return $line;
}

Expand Down

0 comments on commit 8a7e2a4

Please sign in to comment.