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

Revision 12009, 23.1 kB (checked in by mickecarlsson, 2 years ago)

Closes 5075, better logic in checking if fop is running

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