root/modules/branches/2.5/dashboard/page.index.php

Revision 6990, 22.4 kB (checked in by mickecarlsson, 5 years ago)

Fixed error introduced in 6989 for dashboard

Line 
1 <?php /* $Id: page.parking.php 2243 2006-08-12 17:13:17Z p_lindheimer $ */
2 //Copyright (C) 2006 Astrogen LLC
3 //
4 //This program is free software; you can redistribute it and/or
5 //modify it under the terms of the GNU General Public License
6 //as published by the Free Software Foundation; either version 2
7 //of the License, or (at your option) any later version.
8 //
9 //This program is distributed in the hope that it will be useful,
10 //but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //GNU General Public License for more details.
13
14 $dashboard_debug = false;
15
16 $dispnum = 'sysinfo'; //used for switch on config.php
17 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
18
19 $quietmode = isset($_REQUEST['quietmode'])?$_REQUEST['quietmode']:'';
20 $info = isset($_REQUEST['info'])?$_REQUEST['info']:false;
21
22 $title="FreePBX: Sysinfo Info";
23 $message="System Info";
24
25 if (isset($_REQUEST['showall'])) {
26     $_SESSION['syslog_showall'] = (bool)$_REQUEST['showall'];
27 }
28
29 //require_once('functions.inc.php');
30
31 define('BAR_WIDTH_LEFT', 400);
32 define('BAR_WIDTH_RIGHT', 200);
33
34 // AJAX update intervals (in seconds)
35 if (isset($amp_conf['DASHBOARD_STATS_UPDATE_TIME']) && $amp_conf['DASHBOARD_STATS_UPDATE_TIME'] && ctype_digit($amp_conf['DASHBOARD_STATS_UPDATE_TIME'])) {
36     define('STATS_UPDATE_TIME', $amp_conf['DASHBOARD_STATS_UPDATE_TIME']);
37 } else {
38     define('STATS_UPDATE_TIME', 6); // update interval for system information
39 }
40 if (isset($amp_conf['DASHBOARD_INFO_UPDATE_TIME']) && $amp_conf['DASHBOARD_INFO_UPDATE_TIME'] && ctype_digit($amp_conf['DASHBOARD_INFO_UPDATE_TIME'])) {
41     define('INFO_UPDATE_TIME', $amp_conf['DASHBOARD_INFO_UPDATE_TIME']);
42 } else {
43     define('INFO_UPDATE_TIME', 30); // update interval for system uptime information
44 }
45
46 /** draw_graph
47  *  draw a bar graph
48  *
49  *  $text         Title of text
50  *  $real_units   Units to display
51  *  $val          Value to graph
52  *  $total        Total of graph
53  *  $classes      CSS classes to use based on value percent
54  *  $show_percent If results should be shown as percent
55  *  $total_width  Width of graph
56  */
57
58 function draw_graph($text, $real_units, $val, $total = 100, $classes = null, $show_percent = true, $total_width = 200) {
59     if ($classes == null) {
60         $classes = array(
61             0=>'graphok',
62             70=>'graphwarn',
63             90=>'grapherror',
64         );
65     }
66
67     $chars_per_pixel = 7;
68     if (strlen($text) * $chars_per_pixel > $total_width - 35) {
69         $text_trimmed = substr($text,0, floor(($total_width - 35) / $chars_per_pixel)).'..';
70     } else {
71         $text_trimmed = $text;
72     }
73
74     $clean_val = preg_replace("/[^0-9\.]*/","",$val);
75
76     if ($total == 0) {
77         $percent = ($clean_val == 0) ? 0 : 100;
78     } else {
79         $percent = round($clean_val/$total*100);
80     }
81     
82     $graph_class = false;
83     foreach ($classes as $limit=>$class) {
84         if (!$graph_class) {
85             $graph_class = $class;
86         }
87         if ($limit <= $percent) {
88             $graph_class = $class;
89         } else {
90             break;
91         }
92     }
93     $width = $total_width * ($percent/100);
94     if ($width > $total_width) {
95         $width = $total_width;
96     }
97     
98     $tooltip = $text.": ".$val.$real_units." / ".$total.$real_units." (".$percent."%)";
99     $display_value = ($show_percent ? $percent."%" : $val.$real_units);
100     
101     $out = "<div class=\"databox graphbox\" style=\"width:".$total_width."px;\" title=\"".$tooltip."\">\n";
102     $out .= " <div class=\"bargraph ".$graph_class."\" style=\"width:".$width."px;\"></div>\n";
103     $out .= " <div class=\"dataname\">".$text_trimmed."</div>\n";
104     $out .= " <div class=\"datavalue\">".$display_value."</div>\n";
105     $out .= "</div>\n";
106     
107     return $out;
108 }
109
110 function draw_status_box($text, $status, $tooltip = false, $total_width = 200) {
111     switch ($status) {
112         case "ok":
113             $status_text = _("OK");
114             $class = "graphok";
115         break;
116         case "warn":
117             $status_text = _("Warn");
118             $class = "graphwarn";
119         break;
120         case "error":
121             $status_text = _("ERROR");
122             $class = "grapherror";
123         break;
124         case "disabled":
125             $status_text = "Disabled";
126             $class = "";
127         break;
128     }
129     if ($tooltip !== false) {
130         $status_text = '<a href="#" title="'.$tooltip.'">'.$status_text.'</a>';
131     }
132     
133     $out = "<div class=\"databox statusbox\" style=\"width:".$total_width."px;\">\n";
134     $out .= " <div class=\"dataname\">".$text."</div>\n";
135     $out .= " <div id=\"datavalue_".str_replace(" ","_",$text)."\" class=\"datavalue ".$class."\">".$status_text."</div>\n";
136     $out .= "</div>\n";
137     
138     return $out;
139 }
140
141 function draw_box($text, $value, $total_width = 200) {
142     $tooltip = $text.": ".$value;
143     
144     $out = "<div class=\"databox\" style=\"width:".$total_width."px;\">\n";
145     $out .= " <div class=\"dataname\">".$text."</div>\n";
146     $out .= " <div class=\"datavalue\"><a href=\"#\" title=\"".$tooltip."\">".$value."</a></div>\n";
147     $out .= "</div>\n";
148     
149     return $out;
150 }
151
152 function time_string($seconds) {
153     if ($seconds == 0) {
154         return "0 "._("minutes");
155     }
156
157     $minutes = floor($seconds / 60);
158     $seconds = $seconds % 60;
159
160     $hours = floor($minutes / 60);
161     $minutes = $minutes % 60;
162
163     $days = floor($hours / 24);
164     $hours = $hours % 24;
165     
166     $weeks = floor($days / 7);
167     $days = $days % 7;
168     
169     $output = array();
170     if ($weeks) {
171         $output[] = $weeks." ".($weeks == 1 ? _("week") : _("weeks"));
172     }
173     if ($days) {
174         $output[] = $days." ".($days == 1 ? _("days") : _("days"));
175     }
176     if ($hours) {
177         $output[] = $hours." ".($hours == 1 ? _("hour") : _("hours"));
178     }
179     if ($minutes) {
180         $output[] = $minutes." ".($minutes == 1 ? _("minute") : _("minutes"));
181     }
182     
183     return implode(", ",$output);
184 }
185
186 function show_sysstats() {
187     global $sysinfo;
188     $out = '';
189     
190     $out .= "<h3>"._("System Statistics")."</h3>";
191     $out .= "<h4>"._("Processor")."</h4>";
192     $loadavg = $sysinfo->loadavg(true);
193     $out .= draw_box(_("Load Average"), $loadavg['avg'][0]);
194     $out .= draw_graph(_("CPU"), "", number_format($loadavg['cpupercent'],2), 100);
195     
196     $out .= "<h4>"._("Memory")."</h4>";
197     $memory = $sysinfo->memory();
198     $app_memory = isset($memory["ram"]["app"]) ? $memory["ram"]["app"] : $memory["ram"]["total"] - $memory["ram"]["t_free"];
199     $out .= draw_graph(_("App Memory"), "MB", number_format($app_memory/1024,2), $memory["ram"]["total"]/1024);
200     $out .= draw_graph(_("Swap"), "MB", number_format(($memory["swap"]["total"]-$memory["swap"]["free"])/1024,2), $memory["swap"]["total"]/1024);
201     
202     $out .= "<h4>"._("Disks")."</h4>";
203     foreach ($sysinfo->filesystems() as $fs) {
204         $out .= draw_graph($fs["mount"], "GB", number_format($fs["used"]/1024/1024, 2), number_format($fs["size"]/1024/1024,2), strpos( $fs["options"],"ro" )!==false ? array(0=>"graphok"):null);
205     }
206     
207     $out .= "<h4>"._("Networks")."</h4>";
208     foreach ($sysinfo->network() as $net_name=>$net) {
209         $net_name = trim($net_name);
210         if ($net_name == 'lo' || $net_name == 'sit0' || preg_match('/w.g./',$net_name)) continue;
211         
212         $tx = new average_rate_calculator($_SESSION["netstats"][$net_name]["tx"], 10); // 30s max age
213         $rx = new average_rate_calculator($_SESSION["netstats"][$net_name]["rx"], 10); // 30s max age
214         
215         $rx->add( $net["rx_bytes"] );
216         $tx->add( $net["tx_bytes"] );
217         
218         $out .= draw_box($net_name." "._("receive"), number_format($rx->average()/1000,2)." KB/s");
219         $out .= draw_box($net_name." "._("transmit"), number_format($tx->average()/1000,2)." KB/s");
220     }
221     return $out;
222 }
223
224 function show_aststats() {
225     global $amp_conf;
226     global $astinfo;
227     $out = '';
228     
229     $channels = $astinfo->get_channel_totals();
230     // figure out max_calls
231     
232     // guess at the max calls: number of users
233     if (!isset($_SESSION["calculated_max_calls"])) {
234         // set max calls to either MAXCALLS in amportal.conf, or the number of users in the system
235         if (isset($amp_conf['MAXCALLS'])) {
236             $_SESSION["calculated_max_calls"] = $amp_conf["MAXCALLS"];
237         } else if (function_exists('core_users_list')) {
238             $_SESSION["calculated_max_calls"] = count(core_users_list());
239         } else {
240             $_SESSION["calculated_max_calls"] = 1;
241         }
242     }
243     // we currently see more calls than we guessed, increase it
244     if ($channels['total_calls'] > $_SESSION["calculated_max_calls"]) {
245         $_SESSION["calculated_max_calls"] = $channels['total_calls'];
246     }
247     $max_calls = $_SESSION["calculated_max_calls"];
248     
249     $classes = array(0=>'graphok');
250     $max_chans = $max_calls * 2;
251     
252     $out .= "<h3>"._("FreePBX Statistics")."</h3>";
253     $out .= draw_graph(_('Total active calls'), '', $channels['total_calls'], $max_calls, $classes , false, BAR_WIDTH_LEFT);
254     $out .= draw_graph(_('Internal calls'), '', $channels['internal_calls'], $max_calls, $classes , false, BAR_WIDTH_LEFT);
255     $out .= draw_graph(_('External calls'), '', $channels['external_calls'], $max_calls, $classes , false, BAR_WIDTH_LEFT);
256     $out .= draw_graph(_('Total active channels'), '', $channels['total_channels'], $max_chans, $classes , false, BAR_WIDTH_LEFT);
257     
258     $out .= "<h4>"._("FreePBX Connections")."</h4>";
259     
260     if (function_exists('core_trunks_list')) {
261         $trunks = core_trunks_list(true);
262     } else {
263         $trunks = false;
264     }
265     $conns = $astinfo->get_connections( $trunks );
266
267     if ($conns['users_total'] > 0) {
268         $out .= draw_graph(_('IP Phones Online'), '', $conns['users_online'], $conns['users_total'], $classes, false, BAR_WIDTH_LEFT);
269     }
270     if ($conns['trunks_total'] > 0) {
271         $out .= draw_graph(_('IP Trunks Online'), '', $conns['trunks_online'], $conns['trunks_total'], $classes, false, BAR_WIDTH_LEFT);
272     }
273     if ($conns['registrations_total'] > 0) {
274         $out .= draw_graph(_('IP Trunk Registrations'), '', $conns['registrations_online'], $conns['registrations_total'], $classes, false, BAR_WIDTH_LEFT);
275     }
276
277     return $out;
278 }
279
280 function show_sysinfo() {
281     global $sysinfo;
282     global $astinfo;
283     $out = "<h3>"._("Uptime")."</h3></br>";
284     $out .= '<table>';
285     /*
286     $out .= '<tr><th>Distro:</th><td>'.$sysinfo->distro().'</td></tr>';
287     $out .= '<tr><th>Kernel:</th><td>'.$sysinfo->kernel().'</td></tr>';
288     $cpu = $sysinfo->cpu_info();
289     $out .= '<tr><th>CPU:</th><td>'.$cpu['model'].' '.$cpu['cpuspeed'].'</td></tr>';
290     */
291     
292     $out .= '<tr><th>'._('System Uptime').':</th><td>'.time_string($sysinfo->uptime()).'</td></tr>';
293     $ast_uptime = $astinfo->get_uptime();
294     if (empty($ast_uptime['system'])) {
295         $ast_uptime['system'] = time_string(0);
296     }
297     if (empty($ast_uptime['reload'])) {
298         $ast_uptime['reload'] = time_string(0);
299     }
300     $out .= '<tr><th>'._('Asterisk Uptime').':</th><td>'.$ast_uptime['system'].'</td></tr>';
301     $out .= '<tr><th>'._('Last Reload').':</th><td>'.$ast_uptime['reload'].'</td></tr>';
302     
303     $out .= '</table>';
304     return $out;
305 }
306
307 function show_procinfo() {
308     global $procinfo;
309     global $astinfo;
310     global $amp_conf;
311     $out = '';
312     
313     $out .= "<h3>"._("Server Status")."</h3>";
314     // asterisk
315     if ($astver = $astinfo->check_asterisk()) {
316         $out .= draw_status_box(_("Asterisk"), "ok", _('Asterisk is running: '.$astver));
317     } else {
318         $out .= draw_status_box(_("Asterisk"), "error", _('Asterisk is not running, this is a critical service!'));
319     }
320     
321     // asterisk proxy (optionally)
322     if (isset($amp_conf['ASTMANAGERPROXYPORT'])) {
323         if ($procinfo->check_port($amp_conf['ASTMANAGERPROXYPORT'])) {
324             $out .= draw_status_box(_("Manager Proxy"), "ok", _('Asterisk Manager Proxy is running'));
325         } else {
326             $out .= draw_status_box(_("Manager Proxy"), "warn", _('Asterisk Manager Proxy is not running, FreePBX will fall back to using Asterisk directly, which may result in poor performance'));
327         }       
328     }
329     
330     // fop
331     if(!$amp_conf['FOPDISABLE'])  {
332         if ($procinfo->check_fop_server()) {
333             $out .= draw_status_box(_("Op Panel"), "ok", _('FOP Operator Panel Server is running'));
334         } else {
335             if ($amp_conf['FOPRUN']) {
336                 // it should be running
337                 $out .= draw_status_box(_("Op Panel"), "warn", _('FOP Operator Panel Server is not running, you will not be able to use the operator panel, but the system will run fine without it.'));
338             } else {
339                 $out .= draw_status_box(_("Op Panel"), "disabled", _('FOP Operator Panel is disabled in amportal.conf'));
340             }
341         }
342     }
343     
344     // mysql
345     if ($amp_conf['AMPDBENGINE'] == "mysql") {
346         /* this is silly- it's always running, if the web interface loads
347         if ($procinfo->check_mysql($amp_conf['AMPDBHOST'])) {
348             $out .= draw_status_box(_("MySQL"), "ok", _('MySQL Server is running'));
349         } else {
350             $out .= draw_status_box(_("MySQL"), "error", _('MySQL Server is not running, this is a critical service for the web interface and call logs!'));
351         }
352         */
353         $out .= draw_status_box(_("MySQL"), "ok", _('MySQL Server is running'));
354     }
355     
356     // web always runs .. HOWEVER, we can turn it off with dhtml
357     $out .= draw_status_box(_("Web Server"), "ok", _('Web Server is running'));
358     
359     // ssh   
360     $ssh_port = (isset($amp_conf['SSHPORT']) && ctype_digit($amp_conf['SSHPORT']) && ($amp_conf['SSHPORT'] > 0) && ($amp_conf['SSHPORT'] < 65536))?$amp_conf['SSHPORT']:22;
361     if ($procinfo->check_port($ssh_port)) {
362         $out .= draw_status_box(_("SSH Server"), "ok", _('SSH Server is running'));
363     } else {
364         $out .= draw_status_box(_("SSH Server"), "warn", _('SSH Server is not running, you will not be able to connect to the system console remotely'));
365     }
366     return $out;
367 }
368
369 function show_syslog(&$md5_checksum) {
370     global $db;
371     $out = '';
372     $checksum = '';
373
374     // notify_classes are also used as the image names
375     $notify_classes = array(
376         NOTIFICATION_TYPE_CRITICAL => 'notify_critical',
377         NOTIFICATION_TYPE_SECURITY => 'notify_security',
378         NOTIFICATION_TYPE_UPDATE => 'notify_update',
379         NOTIFICATION_TYPE_ERROR => 'notify_error',
380         NOTIFICATION_TYPE_WARNING => 'notify_warning',
381         NOTIFICATION_TYPE_NOTICE => 'notify_notice',
382     );
383     $notify_descriptions = array(
384         NOTIFICATION_TYPE_CRITICAL => _('Critical Error'),
385         NOTIFICATION_TYPE_SECURITY => _('Security Update'),
386         NOTIFICATION_TYPE_UPDATE => _('Update'),
387         NOTIFICATION_TYPE_ERROR => _('Error'),
388         NOTIFICATION_TYPE_WARNING => _('Warning'),
389         NOTIFICATION_TYPE_NOTICE => _('Notice'),
390     );
391     
392     $notify =& notifications::create($db);
393     
394     $showall = (isset($_SESSION['syslog_showall']) ? $_SESSION['syslog_showall'] : false);
395     
396     $items = $notify->list_all($showall);
397
398     $out .= "<h3>"._("FreePBX Notices")."</h3>";
399     
400     if (count($items)) {
401         $out .= '<ul>';
402         foreach ($items as $item) {
403             $checksum .= $item['module'].$item['id']; // checksum, so it is only updated on the page if this has changed
404             
405             $domid = "notify_item_".str_replace(' ','_',$item['module']).'_'.str_replace(' ','_',$item['id']);
406             
407             $out .= '<li id="'.$domid.'" ';
408             if (isset($notify_classes[$item['level']])) {
409                 $out .= ' class="'.$notify_classes[$item['level']].'"';
410             }
411             $out .= '><div>';
412
413             $out .= '<h4 class="syslog_text">';
414             $out .= '<span><img src="images/'.$notify_classes[$item['level']].'.png" alt="'.$notify_descriptions[$item['level']].'" title="'.$notify_descriptions[$item['level']].'" width="16" height="16" border="0" />&nbsp;';
415             $out .= $item['display_text'].'</span>';
416             $out .= '<div class="notification_buttons">';
417             if (isset($item['candelete']) && $item['candelete']) {
418                 $out .= '<a class="notify_ignore_btn" title="'._('Delete this').'" '.
419                         'onclick="delete_notification(\''.$domid.'\', \''.$item['module'].'\', \''.$item['id'].'\');">'.
420                         '<img src="images/cancel.png" width="16" height="16" border="0" alt="'._('Delete this').'" /></a>';
421             }
422             if (!$item['reset']) {
423                 $out .= '<a class="notify_ignore_btn" title="'._('Ignore this').'" '.
424                         'onclick="hide_notification(\''.$domid.'\', \''.$item['module'].'\', \''.$item['id'].'\');">'.
425                         '<img src="'.dirname($_SERVER['PHP_SELF']).'/images/notify_delete.png" width="16" height="16" border="0" alt="'._('Ignore this').'" /></a>';
426             }
427             $out .= '</div>';
428             $out .= '</h4>';
429             
430             $out .= '<div class="syslog_detail">';
431             $out .= nl2br($item['extended_text']);
432             $out .= '<br/><span>'.sprintf('Added %s ago', time_string(time() - $item['timestamp'])).'<br/>'.
433                     '('.$item['module'].'.'.$item['id'].')</span>';
434             $out .= '</div>';
435             
436             $out .= '</div></li>';
437         }
438         $out .= '</ul>';
439     } else {
440         if ($showall) {
441             $out .= _('No notifications');
442         } else {
443             $out .= _('No new notifications');
444         }
445     }
446     
447     $md5_checksum = md5($checksum);
448     
449     $out .= '<div id="syslog_button">';
450     if ($showall) {
451         $out .= '<a href="#" onclick="changeSyslog(0);">'._('show new').'</a>';
452     } else {
453         $out .= '<a href="#" onclick="changeSyslog(1);">'._('show all').'</a>';
454     }
455     $out .= '</div>';
456     return $out;
457 }
458
459 function do_syslog_ack() {   
460     global $db;
461     $notify =& notifications::create($db);
462     
463     if (isset($_REQUEST['module']) && $_REQUEST['id']) {
464         $notify->reset($_REQUEST['module'], $_REQUEST['id']);
465     }
466 }
467 function do_syslog_delete() {   
468     global $db;
469     $notify =& notifications::create($db);
470     
471     if (isset($_REQUEST['module']) && $_REQUEST['id']) {
472     var_dump($_REQUEST);
473         $notify->safe_delete($_REQUEST['module'], $_REQUEST['id']);
474     }
475 }
476
477 /********************************************************************************************/
478
479
480 define("IN_PHPSYSINFO", "1");
481 define("APP_ROOT", dirname(__FILE__).'/phpsysinfo');
482 include APP_ROOT."/common_functions.php";
483 include APP_ROOT."/class.".PHP_OS.".inc.php";
484 include_once "common/json.inc.php";
485 include dirname(__FILE__)."/class.astinfo.php";
486 include dirname(__FILE__)."/class.average_rate_calculator.php";
487 include dirname(__FILE__)."/class.procinfo.php";
488 include dirname(__FILE__)."/class.error.inc.php";
489
490 $error = new Error;
491
492
493 $sysinfo = new sysinfo;
494 $astinfo = new astinfo($astman);
495 $procinfo = new procinfo;
496
497
498 if (!$quietmode) {
499     ?>
500    
501     <script language="javascript">
502     $(document).ready(function(){
503         $.ajaxTimeout( 20000 );
504         scheduleInfoUpdate();
505         scheduleStatsUpdate();
506        
507         makeSyslogClickable();
508     });
509    
510     function makeSyslogClickable() {
511         $('#syslog h4 span').click(function() {
512             $(this).parent().next('div').slideToggle('fast');
513         });
514     }
515    
516     var syslog_md5;
517     var webserver_fail = 0;
518     var info_timer = null;
519     var stats_timer = null;
520
521     function updateFailed(reqObj, status) {
522         // stop updating
523         clearTimeout(stats_timer);
524         stats_timer = null;
525         clearTimeout(info_timer);
526         info_timer = null;
527
528         webserver_fail += 1;
529         webobj = $('#datavalue_Web_Server')
530
531         if (webserver_fail == 1) {
532             webobj.text("Timeout");
533             webobj.removeClass("graphok");
534             webobj.addClass("graphwarn");   
535         } else {
536             webobj.text("ERROR");
537             webobj.removeClass("graphok");
538             webobj.removeClass("graphwarn");
539             webobj.addClass("grapherror");
540         }
541         scheduleInfoUpdate();
542     }
543
544
545     function updateInfo() {
546         $.ajax({
547             type: 'GET',
548             url: "<?php echo $_SERVER["PHP_SELF"]; ?>?type=tool&display=<?php echo $module_page; ?>&quietmode=1&info=info&restrictmods=core/dashboard",
549             dataType: 'json',
550             success: function(data) {
551                 $('#procinfo').html(data.procinfo);
552                 $('#sysinfo').html(data.sysinfo);
553                 // only update syslog div if the md5 has changed
554                 if (syslog_md5 != data.syslog_md5) {
555                     $('#syslog').html(data.syslog);
556                     makeSyslogClickable();
557                     syslog_md5 = data.syslog_md5;
558                 }
559
560                 // webserver is ok
561                 webserver_fail = 0;
562
563                 scheduleInfoUpdate();
564                 if (stats_timer == null) {
565                     // restart stats updates
566                     scheduleStatsUpdate();
567                 }
568             },
569             error: updateFailed
570         });
571     }
572     function scheduleInfoUpdate() {
573         info_timer = setTimeout('updateInfo();',<?php echo INFO_UPDATE_TIME; ?>000);
574     }
575    
576    
577     function updateStats() {
578         $.ajax({
579             type: 'GET',
580             url: "<?php echo $_SERVER["PHP_SELF"]; ?>?type=tool&display=<?php echo $module_page; ?>&quietmode=1&info=stats&restrictmods=core/dashboard",
581             dataType: 'json',
582             success: function(data) {
583                 $('#sysstats').html(data.sysstats);
584                 $('#aststats').html(data.aststats);
585                 scheduleStatsUpdate();
586             },
587             error: updateFailed
588         });
589     }
590     function scheduleStatsUpdate() {
591         stats_timer = setTimeout('updateStats();',<?php echo STATS_UPDATE_TIME; ?>000);
592     }
593    
594    
595     function changeSyslog(showall) {
596         $('#syslog_button').text('<?php echo _('loading...'); ?>');
597         $('#syslog').load("<?php echo $_SERVER["PHP_SELF"]; ?>?type=tool&display=<?php echo $module_page; ?>&quietmode=1&restrictmods=core/dashboard&info=syslog&showall="+showall,{}, function() {
598             makeSyslogClickable();
599         });
600     }
601
602     function hide_notification(domid, module, id) {
603         $('#'+domid).fadeOut('slow');
604         $.post('config.php', {display:'<?php echo $module_page; ?>', quietmode:1, info:'syslog_ack', module:module, id:id, restrictmods:'core/dashboard'});
605     }
606     function delete_notification(domid, module, id) {
607         $('#'+domid).fadeOut('slow');
608         $.post('config.php', {display:'<?php echo $module_page; ?>', quietmode:1, info:'syslog_delete', module:module, id:id, restrictmods:'core/dashboard'});
609     }
610     </script>
611
612     <h2><?php echo _("FreePBX System Status");?></h2>
613     </div>
614     <div id="dashboard">
615     <?php
616     echo '<div id="sysinfo-left">';
617     
618     // regular page
619     echo '<div id="syslog" class="infobox">';
620     echo show_syslog($syslog_md5);
621     // syslog_md5 is used by javascript updateInfo() to determine if the syslog div contents have changed
622     echo '<script type="text/javascript"> syslog_md5 = "'.$syslog_md5.'"; </script>';
623     //echo "log goes here<br/><br/><br/>";
624     echo '</div>';
625     
626     echo '<div id="aststats" class="infobox">';
627     echo show_aststats();
628     echo '</div>';
629     
630     
631     echo '<div id="sysinfo" class="infobox">';
632     echo show_sysinfo();
633     echo '</div>';
634     
635     
636     
637     echo '</div><div id="sysinfo-right">';
638     
639     
640     
641     echo '<div id="sysstats" class="infobox">';
642     echo show_sysstats();
643     echo '</div>';
644     
645     echo '<div id="procinfo" class="infobox">';
646     echo show_procinfo();
647     echo '</div>';
648     
649     echo '<div style="clear:both;"></div>';
650     
651     echo '</div></div>'; // #sysinfo, #sysinfo-right
652     
653     echo '<div class="content">';
654
655     if($dashboard_debug && $error->ErrorsExist()) {
656         $fh = fopen($amp_conf['ASTLOGDIR']."/dashboard-error.log","a");
657         fwrite($fh, $error->ErrorsAsText());
658         fclose($fh);
659     }           
660
661 } else {
662     // Handle AJAX updates
663     
664     switch ($info) {
665         case "sysstats":
666             echo show_sysstats();
667         break;
668         case "aststats":
669             echo show_aststats();
670         break;
671         case "procinfo":
672             echo show_procinfo();
673         break;
674         case 'sysinfo':
675             echo show_sysinfo();
676         break;
677         case 'syslog':
678             echo show_syslog($syslog_md5);   
679             // syslog_md5 is used by javascript updateInfo() to determine if the syslog div contents have changed
680             echo '<script type="text/javascript"> syslog_md5 = "'.$syslog_md5.'"; </script>';
681         break;
682         case 'syslog_ack':
683             do_syslog_ack();
684         break;
685         case 'syslog_delete':
686             do_syslog_delete();
687         break;
688         
689         case 'info':
690             $json = new Services_JSON();
691             header("Content-type: application/json");
692             echo $json->encode(
693                 array(
694                     'procinfo'=>show_procinfo(),
695                     'sysinfo'=>show_sysinfo(),
696                     'syslog'=>show_syslog($syslog_md5),
697                     'syslog_md5'=>$syslog_md5,
698                 )
699             );
700         break;
701         case 'stats':
702             $json = new Services_JSON();
703             header("Content-type: application/json");
704             echo $json->encode(
705                 array(
706                     'sysstats'=>show_sysstats(),
707                     'aststats'=>show_aststats(),
708                 )
709             );
710         break;
711         case 'all':
712             $json = new Services_JSON();
713             header("Content-type: application/json");
714             echo $json->encode(
715                 array(
716                     'sysstats'=>show_sysstats(),
717                     'aststats'=>show_aststats(),
718                     'procinfo'=>show_procinfo(),
719                     'sysinfo'=>show_sysinfo(),
720                     'syslog'=>show_syslog(),
721                 )
722             );
723         break;
724     }
725 }
726
727 ?>
728
Note: See TracBrowser for help on using the browser.