auth->check_module_permissions('monitor');
$mod = $_GET["mod"];
$output = '';
switch($mod) {
case 'load':
$template = 'templates/system.htm';
$output .= show_load();
$title = 'System Load';
$description = '';
break;
case 'disk':
$template = 'templates/system.htm';
$output .= show_disk();
$title = 'Disk usage';
$description = '';
break;
case 'memusage':
$template = 'templates/system.htm';
$output .= show_memusage();
$title = 'Memory usage';
$description = '';
break;
case 'cpu':
$template = 'templates/system.htm';
$output .= show_cpu();
$title = 'CPU Info';
$description = '';
break;
case 'services':
$template = 'templates/system.htm';
$output .= show_services();
$title = 'Status of services';
$description = '';
break;
case 'index':
$template = 'templates/system.htm';
$output .= show_load();
$output .= ' '. show_disk();
$output .= ' '.show_services();
$title = 'System Monitor';
$description = '';
break;
default:
$template = '';
break;
}
// Loading the template
$app->uses('tpl');
$app->tpl->newTemplate("form.tpl.htm");
$app->tpl->setInclude('content_tpl',$template);
$app->tpl->setVar("output",$output);
$app->tpl->setVar("title",$title);
$app->tpl->setVar("description",$description);
$app->tpl_defaults();
$app->tpl->pparse();
function show_load(){
global $app;
$html_out .= '
';
$fd = popen ("uptime", "r");
while (!feof($fd)) {
$buffer .= fgets($fd, 4096);
}
$uptime = split(",",strrev($buffer));
$online = split(" ",strrev($uptime[4]));
$proc_uptime = shell_exec("cat /proc/uptime | cut -f1 -d' '");
$days = floor($proc_uptime/86400);
$hours = floor(($proc_uptime-$days*86400)/3600);
$minutes = str_pad(floor(($proc_uptime-$days*86400-$hours*3600)/60), 2, "0", STR_PAD_LEFT);
$html_out .= '
'.$app->lng("Server Online seit").': |
'.$days.'d, '.$hours.':'.$minutes.'h |
';
$html_out .= '
'.$app->lng("User Online").': |
'.strrev($uptime[3]).' |
';
$ausl = split(":",strrev($uptime[2]));
$ausl1 = $ausl[1];
$html_out .= '
'.$app->lng("System Load 1 Minute").': |
'.$ausl1.' |
';
$html_out .= '
'.$app->lng("System Load 5 Minuten").': |
'.strrev($uptime[1]).' |
';
$html_out .= '
'.$app->lng("System Load 15 Minuten").': |
'.strrev($uptime[0]).' |
';
$html_out .= '
';
return $html_out;
}
function show_disk () {
global $app;
$html_out .= '';
$fd = popen ("df -h", "r");
while (!feof($fd)) {
$buffer .= fgets($fd, 4096);
}
$df_out = split("\n",$buffer);
$df_num = sizeof($df_out);
for($i=0;$i<$df_num;$i++){
if(ltrim($df_out[$i]) != $df_out[$i]){
if(isset($df_out[($i-1)])){
$df_out[($i-1)] .= $df_out[$i];
unset($df_out[$i]);
}
}
}
$html_out .= '';
$mrow = 0;
foreach($df_out as $df_line) {
$values = preg_split ("/[\s]+/", $df_line);
$mln = 0;
$font_class = 'normal_bold';
if($mrow > 0) $font_class = 'normal';
foreach($values as $value) {
$align = 'left';
if($mln > 0 and $mln < 5) $align = 'right';
if($mln < 6 and $value != "") $html_out .= ''.$value.' | ';
$mln++;
}
$mrow++;
$html_out .= '
';
}
$html_out .= '
';
return $html_out;
}
function show_memusage ()
{
global $app;
$html_out .= '';
$fd = fopen ("/proc/meminfo", "r");
while (!feof($fd)) {
$buffer .= fgets($fd, 4096);
}
fclose($fd);
$meminfo = split("\n",$buffer);
foreach($meminfo as $mline){
if($x > 2 and trim($mline) != "") {
$mpart = split(":",$mline);
$html_out .= '
'.$mpart[0].': |
'.$mpart[1].' |
';
}
$x++;
}
$html_out .= '
';
return $html_out;
}
function show_cpu ()
{
global $app;
$html_out .= '';
$n = 0;
if(is_readable("/proc/cpuinfo")) {
if($fd = fopen ("/proc/cpuinfo", "r")) {
while (!feof($fd)) {
$buffer .= fgets($fd, 4096);
$n++;
if($n > 100) break;
}
fclose($fd);
}
}
$meminfo = split("\n",$buffer);
if(is_array($meminfo)) {
foreach($meminfo as $mline){
if(trim($mline) != "") {
$mpart = split(":",$mline);
$html_out .= '
'.$mpart[0].': |
'.$mpart[1].' |
';
}
}
$x++;
}
$html_out .= '
';
return $html_out;
}
function show_services ()
{
global $app;
$html_out .= '';
// Checke Webserver
if(_check_tcp('localhost',80)) {
$status = 'Online';
} else {
$status = 'Offline';
}
$html_out .= '
Web-Server: |
'.$status.' |
';
// Checke FTP-Server
if(_check_ftp('localhost',21)) {
$status = 'Online';
} else {
$status = 'Offline';
}
$html_out .= '
FTP-Server: |
'.$status.' |
';
// Checke SMTP-Server
if(_check_tcp('localhost',25)) {
$status = 'Online';
} else {
$status = 'Offline';
}
$html_out .= '
SMTP-Server: |
'.$status.' |
';
// Checke POP3-Server
if(_check_tcp('localhost',110)) {
$status = 'Online';
} else {
$status = 'Offline';
}
$html_out .= '
POP3-Server: |
'.$status.' |
';
// Checke BIND-Server
if(_check_tcp('localhost',53)) {
$status = 'Online';
} else {
$status = 'Offline';
}
$html_out .= '
DNS-Server: |
'.$status.' |
';
// Checke MYSQL-Server
//if($this->_check_tcp('localhost',3306)) {
$status = 'Online';
//} else {
//$status = 'Offline';
//}
$html_out .= '
mySQL-Server: |
'.$status.' |
';
$html_out .= '
';
return $html_out;
}
function _check_tcp ($host,$port) {
$fp = @fsockopen ($host, $port, &$errno, &$errstr, 2);
if ($fp) {
return true;
fclose($fp);
} else {
return false;
fclose($fp);
}
}
function _check_udp ($host,$port) {
$fp = @fsockopen ('udp://'.$host, $port, &$errno, &$errstr, 2);
if ($fp) {
return true;
fclose($fp);
} else {
return false;
fclose($fp);
}
}
function _check_ftp ($host,$port){
$conn_id = @ftp_connect($host, $port);
if($conn_id){
@ftp_close($conn_id);
return true;
} else {
@ftp_close($conn_id);
return false;
}
}
?>