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

Revision 10147, 23.3 kB (checked in by mbrevda, 3 years ago)

real fix for #4175

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 (isset($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         if ($procinfo->check_fop_server()) {
349             $out .= draw_status_box(_("Op Panel"), "ok", _('FOP Operator Panel Server is running'));
350         } else {
351             if ($amp_conf['FOPRUN']) {
352                 // it should be running
353                 $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.'));
354             } else {
355                 $out .= draw_status_box(_("Op Panel"), "disabled", _('FOP Operator Panel is disabled in amportal.conf'));
356             }
357         }
358     }
359     
360     // mysql
361     if ($amp_conf['AMPDBENGINE'] == "mysql") {
362         /* this is silly- it's always running, if the web interface loads
363         if ($procinfo->check_mysql($amp_conf['AMPDBHOST'])) {
364             $out .= draw_status_box(_("MySQL"), "ok", _('MySQL Server is running'));
365         } else {
366             $out .= draw_status_box(_("MySQL"), "error", _('MySQL Server is not running, this is a critical service for the web interface and call logs!'));
367         }
368         */
369         $out .= draw_status_box(_("MySQL"), "ok", _('MySQL Server is running'));
370     }
371     
372     // web always runs .. HOWEVER, we can turn it off with dhtml
373     $out .= draw_status_box(_("Web Server"), "ok", _('Web Server is running'));
374     
375     // ssh   
376     $ssh_port = (isset($amp_conf['SSHPORT']) && ctype_digit($amp_conf['SSHPORT']) && ($amp_conf['SSHPORT'] > 0) && ($amp_conf['SSHPORT'] < 65536))?$amp_conf['SSHPORT']:22;
377     if ($procinfo->check_port($ssh_port)) {
378         $out .= draw_status_box(_("SSH Server"), "ok", _('SSH Server is running'));
379     } else {
380         $out .= draw_status_box(_("SSH Server"), "warn", _('SSH Server is not running, you will not be able to connect to the system console remotely'));
381     }
382     return $out;
383 }
384
385 function show_syslog(&$md5_checksum) {
386     global $db;
387     $out = '';
388     $checksum = '';
389
390     // notify_classes are also used as the image names
391     $notify_classes = array(
392         NOTIFICATION_TYPE_CRITICAL => 'notify_critical',
393         NOTIFICATION_TYPE_SECURITY => 'notify_security',
394         NOTIFICATION_TYPE_UPDATE => 'notify_update',
395         NOTIFICATION_TYPE_ERROR => 'notify_error',
396         NOTIFICATION_TYPE_WARNING => 'notify_warning',
397         NOTIFICATION_TYPE_NOTICE => 'notify_notice',
398     );
399     $notify_descriptions = array(
400         NOTIFICATION_TYPE_CRITICAL => _('Critical Error'),
401         NOTIFICATION_TYPE_SECURITY => _('Security Update'),
402         NOTIFICATION_TYPE_UPDATE => _('Update'),
403         NOTIFICATION_TYPE_ERROR => _('Error'),
404         NOTIFICATION_TYPE_WARNING => _('Warning'),
405         NOTIFICATION_TYPE_NOTICE => _('Notice'),
406     );
407     
408     $notify =& notifications::create($db);
409     
410     $showall = (isset($_SESSION['syslog_showall']) ? $_SESSION['syslog_showall'] : false);
411     
412     $items = $notify->list_all($showall);
413
414     $out .= "<h3>"._("FreePBX Notices")."</h3>";
415     
416     if (count($items)) {
417         $out .= '<ul>';
418         foreach ($items as $item) {
419             $checksum .= $item['module'].$item['id']; // checksum, so it is only updated on the page if this has changed
420             
421             $domid = "notify_item_".str_replace(' ','_',$item['module']).'_'.str_replace(' ','_',$item['id']);
422             
423             $out .= "\n";
424             $out .= '<li id="'.$domid.'" ';
425             if (isset($notify_classes[$item['level']])) {
426                 $out .= ' class="'.$notify_classes[$item['level']].'"';
427             }
428             $out .= '><div>';
429             
430             $out .= '<div class="syslog_text">';
431             $out .= '<h4>';
432             $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;';
433             $out .= $item['display_text'].'</span>';
434             $out .= '</h4>';
435             $out .= "\n";
436             $out .= '<div class="notification_buttons">';
437             if (isset($item['candelete']) && $item['candelete']) {
438                 $out .= '<a class="notify_ignore_btn" title="'._('Delete this').'" '.
439                         'onclick="delete_notification(\''.$domid.'\', \''.$item['module'].'\', \''.$item['id'].'\');">'.
440                         '<img src="images/cancel.png" width="16" height="16" border="0" alt="'._('Delete this').'" /></a>';
441             }
442             if (!$item['reset']) {
443                 $out .= '<a class="notify_ignore_btn" title="'._('Ignore this').'" '.
444                         'onclick="hide_notification(\''.$domid.'\', \''.$item['module'].'\', \''.$item['id'].'\');">'.
445                         '<img src="'.dirname($_SERVER['PHP_SELF']).'/images/notify_delete.png" width="16" height="16" border="0" alt="'._('Ignore this').'" /></a>';
446             }
447             $out .= '</div>';
448             $out .= '</div>';
449             $out .= "\n";
450             $out .= '<div class="syslog_detail">';
451             $out .= nl2br($item['extended_text']);
452             $out .= '<br/><span>'.sprintf(_('Added %s ago'), time_string(time() - $item['timestamp'])).'<br/>'.
453                     '('.$item['module'].'.'.$item['id'].')</span>';
454             $out .= '</div>';
455             
456             $out .= '</div></li>';
457         }
458         $out .= '</ul>';
459     } else {
460         if ($showall) {
461             $out .= _('No notifications');
462         } else {
463             $out .= _('No new notifications');
464         }
465     }
466     
467     $md5_checksum = md5($checksum);
468     
469     $out .= '<div id="syslog_button">';
470     
471     if ($showall) {
472         $out .= '<a href="#" onclick="changeSyslog(0);">'._('show new').'</a>';
473     } else {
474       $out .= '<a href="#" onclick="changeSyslog(1);">'._('show all').'</a>';
475     }
476     $out .= '</div>';
477     return $out;
478 }
479
480 function do_syslog_ack() {   
481     global $db;
482     $notify =& notifications::create($db);
483     
484     if (isset($_REQUEST['module']) && $_REQUEST['id']) {
485         $notify->reset($_REQUEST['module'], $_REQUEST['id']);
486     }
487 }
488 function do_syslog_delete() {   
489     global $db;
490     $notify =& notifications::create($db);
491     
492     if (isset($_REQUEST['module']) && $_REQUEST['id']) {
493     var_dump($_REQUEST);
494         $notify->safe_delete($_REQUEST['module'], $_REQUEST['id']);
495     }
496 }
497
498 /********************************************************************************************/
499
500
501 define("IN_PHPSYSINFO", "1");
502 define("APP_ROOT", dirname(__FILE__).'/phpsysinfo');
503 include APP_ROOT."/common_functions.php";
504 include APP_ROOT."/class.".PHP_OS.".inc.php";
505 include_once "common/json.inc.php";
506 include dirname(__FILE__)."/class.astinfo.php";
507 include dirname(__FILE__)."/class.average_rate_calculator.php";
508 include dirname(__FILE__)."/class.procinfo.php";
509 include dirname(__FILE__)."/class.error.inc.php";
510
511 $error = new Error;
512
513
514 $sysinfo = new sysinfo;
515 $astinfo = new astinfo($astman);
516 $procinfo = new procinfo;
517
518
519 if (!$quietmode) {
520     ?>
521    
522     <script type="text/javascript">
523     $(document).ready(function(){
524     $.ajaxSetup({
525       timeout:10000
526     });
527         scheduleInfoUpdate();
528         scheduleStatsUpdate();
529        
530         makeSyslogClickable();
531     });
532    
533     function makeSyslogClickable() {
534         $('#syslog h4 span').click(function() {
535             $(this).parent().parent().next('div').slideToggle('fast');
536         });
537     }
538    
539     var syslog_md5;
540     var webserver_fail = 0;
541     var info_timer = null;
542     var stats_timer = null;
543
544     function updateFailed(reqObj, status) {
545         // stop updating
546         clearTimeout(stats_timer);
547         stats_timer = null;
548         clearTimeout(info_timer);
549         info_timer = null;
550
551         webserver_fail += 1;
552         webobj = $('#datavalue_Web_Server')
553
554         if (webserver_fail == 1) {
555             webobj.text("Timeout");
556             webobj.removeClass("graphok");
557             webobj.addClass("graphwarn");   
558         } else {
559             webobj.text("ERROR");
560             webobj.removeClass("graphok");
561             webobj.removeClass("graphwarn");
562             webobj.addClass("grapherror");
563         }
564         scheduleInfoUpdate();
565     }
566
567
568     function updateInfo() {
569         $.ajax({
570             type: 'GET',
571             url: "<?php echo $_SERVER["PHP_SELF"]; ?>?type=tool&display=<?php echo $module_page; ?>&quietmode=1&info=info&restrictmods=core/dashboard",
572             dataType: 'json',
573             success: function(data) {
574                 $('#procinfo').html(data.procinfo);
575                 $('#sysinfo').html(data.sysinfo);
576                 // only update syslog div if the md5 has changed
577                 if (syslog_md5 != data.syslog_md5) {
578                     $('#syslog').html(data.syslog);
579                     makeSyslogClickable();
580                     syslog_md5 = data.syslog_md5;
581                 }
582
583                 // webserver is ok
584                 webserver_fail = 0;
585
586                 scheduleInfoUpdate();
587                 if (stats_timer == null) {
588                     // restart stats updates
589                     scheduleStatsUpdate();
590                 }
591             },
592             error: updateFailed
593         });
594     }
595     function scheduleInfoUpdate() {
596         info_timer = setTimeout('updateInfo();',<?php echo INFO_UPDATE_TIME; ?>000);
597     }
598    
599    
600     function updateStats() {
601         $.ajax({
602             type: 'GET',
603             url: "<?php echo $_SERVER["PHP_SELF"]; ?>?type=tool&display=<?php echo $module_page; ?>&quietmode=1&info=stats&restrictmods=core/dashboard",
604             dataType: 'json',
605             success: function(data) {
606                 $('#sysstats').html(data.sysstats);
607                 $('#aststats').html(data.aststats);
608                 scheduleStatsUpdate();
609             },
610             error: updateFailed
611         });
612     }
613     function scheduleStatsUpdate() {
614         stats_timer = setTimeout('updateStats();',<?php echo STATS_UPDATE_TIME; ?>000);
615     }
616    
617    
618     function changeSyslog(showall) {
619         $('#syslog_button').text('<?php echo _('loading...'); ?>');
620         $('#syslog').load("<?php echo $_SERVER["PHP_SELF"]; ?>?type=tool&display=<?php echo $module_page; ?>&quietmode=1&restrictmods=core/dashboard&info=syslog&showall="+showall,{}, function() {
621             makeSyslogClickable();
622         });
623     }
624
625     function hide_notification(domid, module, id) {
626         $('#'+domid).fadeOut('slow');
627         $.post('config.php', {display:'<?php echo $module_page; ?>', quietmode:1, info:'syslog_ack', module:module, id:id, restrictmods:'core/dashboard'});
628     }
629     function delete_notification(domid, module, id) {
630         $('#'+domid).fadeOut('slow');
631         $.post('config.php', {display:'<?php echo $module_page; ?>', quietmode:1, info:'syslog_delete', module:module, id:id, restrictmods:'core/dashboard'});
632     }
633     </script>
634
635     <h2><?php echo _("FreePBX System Status");?></h2>
636     </div>
637     <div class="content">
638     <div id="dashboard">
639     <?php
640     echo '<div id="sysinfo-left">';
641     
642     // regular page
643     echo '<div id="syslog" class="infobox">';
644     echo show_syslog($syslog_md5);
645     // syslog_md5 is used by javascript updateInfo() to determine if the syslog div contents have changed
646     echo '<script type="text/javascript"> syslog_md5 = "'.$syslog_md5.'"; </script>';
647     //echo "log goes here<br/><br/><br/>";
648     echo '</div>';
649     
650     echo '<div id="aststats" class="infobox">';
651     echo show_aststats();
652     echo '</div>';
653     
654     echo '<div id="sysinfo" class="infobox">';
655     echo show_sysinfo();
656     echo '</div>';
657     
658     
659     echo '</div><div id="sysinfo-right">';
660     
661     echo '<div id="sysstats" class="infobox">';
662     echo show_sysstats();
663     echo '</div>';
664     
665     echo '<div id="procinfo" class="infobox">';
666     echo show_procinfo();
667     echo '</div>';
668     
669     echo '<div style="clear:both;"></div>';
670     echo '</div>'; // #sysinfo-right, #dashboard
671     echo '<div id="sysinfo-bot">&nbsp</div>';
672
673     if($dashboard_debug && $error->ErrorsExist()) {
674         $fh = fopen($amp_conf['ASTLOGDIR']."/dashboard-error.log","a");
675         fwrite($fh, $error->ErrorsAsText());
676         fclose($fh);
677     }           
678
679 } else {
680     // Handle AJAX updates
681     
682     switch ($info) {
683         case "sysstats":
684             echo show_sysstats();
685         break;
686         case "aststats":
687             echo show_aststats();
688         break;
689         case "procinfo":
690             echo show_procinfo();
691         break;
692         case 'sysinfo':
693             echo show_sysinfo();
694         break;
695         case 'syslog':
696             echo show_syslog($syslog_md5);   
697             // syslog_md5 is used by javascript updateInfo() to determine if the syslog div contents have changed
698             echo '<script type="text/javascript"> syslog_md5 = "'.$syslog_md5.'"; </script>';
699         break;
700         case 'syslog_ack':
701             do_syslog_ack();
702         break;
703         case 'syslog_delete':
704             do_syslog_delete();
705         break;
706         
707         case 'info':
708             $json = new Services_JSON();
709             header("Content-type: application/json");
710             echo $json->encode(
711                 array(
712                     'procinfo'=>show_procinfo(),
713                     'sysinfo'=>show_sysinfo(),
714                     'syslog'=>show_syslog($syslog_md5),
715                     'syslog_md5'=>$syslog_md5,
716                 )
717             );
718         break;
719         case 'stats':
720             $json = new Services_JSON();
721             header("Content-type: application/json");
722             echo $json->encode(
723                 array(
724                     'sysstats'=>show_sysstats(),
725                     'aststats'=>show_aststats(),
726                 )
727             );
728         break;
729         case 'all':
730             $json = new Services_JSON();
731             header("Content-type: application/json");
732             echo $json->encode(
733                 array(
734                     'sysstats'=>show_sysstats(),
735                     'aststats'=>show_aststats(),
736                     'procinfo'=>show_procinfo(),
737                     'sysinfo'=>show_sysinfo(),
738                     'syslog'=>show_syslog(),
739                 )
740             );
741         break;
742     }
743 }
744
745 ?>
746
Note: See TracBrowser for help on using the browser.