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

Revision 7342, 22.6 kB (checked in by p_lindheimer, 4 years ago)

Merged revisions 7177,7179-7185,7191-7201,7204-7211,7213-7221,7223-7226,7228-7249,7252-7260,7262-7272,7279-7285,7289-7291,7294-7295,7297-7312,7317-7320,7322-7331,7333-7340 via svnmerge from
http://svn.freepbx.org/modules/branches/2.6

........

r7177 | p_lindheimer | 2008-10-29 10:51:38 -0700 (Wed, 29 Oct 2008) | 1 line


Auto Check-in of any outstanding patches

........

r7196 | mickecarlsson | 2008-10-30 23:25:31 -0700 (Thu, 30 Oct 2008) | 1 line


Fixed type in code fro fw_fop

........

r7228 | mickecarlsson | 2008-11-05 09:14:56 -0800 (Wed, 05 Nov 2008) | 1 line


Changed some enclosed text string with proper enclosures so that localization with apostrophe will work

........

r7255 | mbrevda | 2008-11-12 07:57:37 -0800 (Wed, 12 Nov 2008) | 1 line


ref #3358

........

r7300 | mickecarlsson | 2008-11-23 01:15:27 -0800 (Sun, 23 Nov 2008) | 1 line


Fixes #3409, dashboard display wrong statistics and color when disk storage is above 1Tb

........

r7301 | mickecarlsson | 2008-11-23 06:11:19 -0800 (Sun, 23 Nov 2008) | 1 line


Enclosed text strings for translation. Updated .pot file and swedish language

........

r7302 | mickecarlsson | 2008-11-23 06:26:47 -0800 (Sun, 23 Nov 2008) | 1 line


Enclosed text string for translation in core

........

r7306 | mickecarlsson | 2008-12-01 08:45:04 -0800 (Mon, 01 Dec 2008) | 1 line


Closes #932 adds permit/deny to sip and iax devices

........

r7307 | mickecarlsson | 2008-12-01 09:00:09 -0800 (Mon, 01 Dec 2008) | 1 line


Adds default 0.0.0.0/0.0.0.0 in deny and permit for sip and iax devices

........

r7308 | mickecarlsson | 2008-12-03 22:20:02 -0800 (Wed, 03 Dec 2008) | 1 line


Fixes #3426, sets code to follow tool tip. Thank you ryand

........

r7310 | mickecarlsson | 2008-12-06 06:07:17 -0800 (Sat, 06 Dec 2008) | 1 line


Closes #3224 removes hard coded database name

........

r7317 | mickecarlsson | 2008-12-15 10:55:17 -0800 (Mon, 15 Dec 2008) | 1 line


Closes #3443 adding check for uppercase file extensions

........

r7320 | ethans | 2008-12-17 16:31:52 -0800 (Wed, 17 Dec 2008) | 3 lines


Adds hook support into IVR page

........

r7322 | mickecarlsson | 2008-12-17 22:08:41 -0800 (Wed, 17 Dec 2008) | 1 line


Closes 3448 adding check for server side DND in normal paging

........

r7340 | mickecarlsson | 2008-12-30 14:22:14 -0800 (Tue, 30 Dec 2008) | 1 line


Closes #3448 finally fixes the DND in paging. Thank you jjshoe

........

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 summary="'._('System Information 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", sprintf(_('Asterisk is running: %s'),$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 .= "\n";
408             $out .= '<li id="'.$domid.'" ';
409             if (isset($notify_classes[$item['level']])) {
410                 $out .= ' class="'.$notify_classes[$item['level']].'"';
411             }
412             $out .= '><div>';
413             
414             $out .= '<div class="syslog_text">';
415             $out .= '<h4>';
416             $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;';
417             $out .= $item['display_text'].'</span>';
418             $out .= '</h4>';
419             $out .= "\n";
420             $out .= '<div class="notification_buttons">';
421             if (isset($item['candelete']) && $item['candelete']) {
422                 $out .= '<a class="notify_ignore_btn" title="'._('Delete this').'" '.
423                         'onclick="delete_notification(\''.$domid.'\', \''.$item['module'].'\', \''.$item['id'].'\');">'.
424                         '<img src="images/cancel.png" width="16" height="16" border="0" alt="'._('Delete this').'" /></a>';
425             }
426             if (!$item['reset']) {
427                 $out .= '<a class="notify_ignore_btn" title="'._('Ignore this').'" '.
428                         'onclick="hide_notification(\''.$domid.'\', \''.$item['module'].'\', \''.$item['id'].'\');">'.
429                         '<img src="'.dirname($_SERVER['PHP_SELF']).'/images/notify_delete.png" width="16" height="16" border="0" alt="'._('Ignore this').'" /></a>';
430             }
431             $out .= '</div>';
432             $out .= '</div>';
433             $out .= "\n";
434             $out .= '<div class="syslog_detail">';
435             $out .= nl2br($item['extended_text']);
436             $out .= '<br/><span>'.sprintf(_('Added %s ago'), time_string(time() - $item['timestamp'])).'<br/>'.
437                     '('.$item['module'].'.'.$item['id'].')</span>';
438             $out .= '</div>';
439             
440             $out .= '</div></li>';
441         }
442         $out .= '</ul>';
443     } else {
444         if ($showall) {
445             $out .= _('No notifications');
446         } else {
447             $out .= _('No new notifications');
448         }
449     }
450     
451     $md5_checksum = md5($checksum);
452     
453     $out .= '<div id="syslog_button">';
454     if ($showall) {
455         $out .= '<a href="#" onclick="changeSyslog(0);">'._('show new').'</a>';
456     } else {
457         $out .= '<a href="#" onclick="changeSyslog(1);">'._('show all').'</a>';
458     }
459     $out .= '</div>';
460     return $out;
461 }
462
463 function do_syslog_ack() {   
464     global $db;
465     $notify =& notifications::create($db);
466     
467     if (isset($_REQUEST['module']) && $_REQUEST['id']) {
468         $notify->reset($_REQUEST['module'], $_REQUEST['id']);
469     }
470 }
471 function do_syslog_delete() {   
472     global $db;
473     $notify =& notifications::create($db);
474     
475     if (isset($_REQUEST['module']) && $_REQUEST['id']) {
476     var_dump($_REQUEST);
477         $notify->safe_delete($_REQUEST['module'], $_REQUEST['id']);
478     }
479 }
480
481 /********************************************************************************************/
482
483
484 define("IN_PHPSYSINFO", "1");
485 define("APP_ROOT", dirname(__FILE__).'/phpsysinfo');
486 include APP_ROOT."/common_functions.php";
487 include APP_ROOT."/class.".PHP_OS.".inc.php";
488 include_once "common/json.inc.php";
489 include dirname(__FILE__)."/class.astinfo.php";
490 include dirname(__FILE__)."/class.average_rate_calculator.php";
491 include dirname(__FILE__)."/class.procinfo.php";
492 include dirname(__FILE__)."/class.error.inc.php";
493
494 $error = new Error;
495
496
497 $sysinfo = new sysinfo;
498 $astinfo = new astinfo($astman);
499 $procinfo = new procinfo;
500
501
502 if (!$quietmode) {
503     ?>
504    
505     <script type="text/javascript">
506     $(document).ready(function(){
507         $.ajaxTimeout( 20000 );
508         scheduleInfoUpdate();
509         scheduleStatsUpdate();
510        
511         makeSyslogClickable();
512     });
513    
514     function makeSyslogClickable() {
515         $('#syslog h4 span').click(function() {
516             $(this).parent().parent().next('div').slideToggle('fast');
517         });
518     }
519    
520     var syslog_md5;
521     var webserver_fail = 0;
522     var info_timer = null;
523     var stats_timer = null;
524
525     function updateFailed(reqObj, status) {
526         // stop updating
527         clearTimeout(stats_timer);
528         stats_timer = null;
529         clearTimeout(info_timer);
530         info_timer = null;
531
532         webserver_fail += 1;
533         webobj = $('#datavalue_Web_Server')
534
535         if (webserver_fail == 1) {
536             webobj.text("Timeout");
537             webobj.removeClass("graphok");
538             webobj.addClass("graphwarn");   
539         } else {
540             webobj.text("ERROR");
541             webobj.removeClass("graphok");
542             webobj.removeClass("graphwarn");
543             webobj.addClass("grapherror");
544         }
545         scheduleInfoUpdate();
546     }
547
548
549     function updateInfo() {
550         $.ajax({
551             type: 'GET',
552             url: "<?php echo $_SERVER["PHP_SELF"]; ?>?type=tool&display=<?php echo $module_page; ?>&quietmode=1&info=info&restrictmods=core/dashboard",
553             dataType: 'json',
554             success: function(data) {
555                 $('#procinfo').html(data.procinfo);
556                 $('#sysinfo').html(data.sysinfo);
557                 // only update syslog div if the md5 has changed
558                 if (syslog_md5 != data.syslog_md5) {
559                     $('#syslog').html(data.syslog);
560                     makeSyslogClickable();
561                     syslog_md5 = data.syslog_md5;
562                 }
563
564                 // webserver is ok
565                 webserver_fail = 0;
566
567                 scheduleInfoUpdate();
568                 if (stats_timer == null) {
569                     // restart stats updates
570                     scheduleStatsUpdate();
571                 }
572             },
573             error: updateFailed
574         });
575     }
576     function scheduleInfoUpdate() {
577         info_timer = setTimeout('updateInfo();',<?php echo INFO_UPDATE_TIME; ?>000);
578     }
579    
580    
581     function updateStats() {
582         $.ajax({
583             type: 'GET',
584             url: "<?php echo $_SERVER["PHP_SELF"]; ?>?type=tool&display=<?php echo $module_page; ?>&quietmode=1&info=stats&restrictmods=core/dashboard",
585             dataType: 'json',
586             success: function(data) {
587                 $('#sysstats').html(data.sysstats);
588                 $('#aststats').html(data.aststats);
589                 scheduleStatsUpdate();
590             },
591             error: updateFailed
592         });
593     }
594     function scheduleStatsUpdate() {
595         stats_timer = setTimeout('updateStats();',<?php echo STATS_UPDATE_TIME; ?>000);
596     }
597    
598    
599     function changeSyslog(showall) {
600         $('#syslog_button').text('<?php echo _('loading...'); ?>');
601         $('#syslog').load("<?php echo $_SERVER["PHP_SELF"]; ?>?type=tool&display=<?php echo $module_page; ?>&quietmode=1&restrictmods=core/dashboard&info=syslog&showall="+showall,{}, function() {
602             makeSyslogClickable();
603         });
604     }
605
606     function hide_notification(domid, module, id) {
607         $('#'+domid).fadeOut('slow');
608         $.post('config.php', {display:'<?php echo $module_page; ?>', quietmode:1, info:'syslog_ack', module:module, id:id, restrictmods:'core/dashboard'});
609     }
610     function delete_notification(domid, module, id) {
611         $('#'+domid).fadeOut('slow');
612         $.post('config.php', {display:'<?php echo $module_page; ?>', quietmode:1, info:'syslog_delete', module:module, id:id, restrictmods:'core/dashboard'});
613     }
614     </script>
615
616     <h2><?php echo _("FreePBX System Status");?></h2>
617     </div>
618     <div id="dashboard">
619     <?php
620     echo '<div id="sysinfo-left">';
621     
622     // regular page
623     echo '<div id="syslog" class="infobox">';
624     echo show_syslog($syslog_md5);
625     // syslog_md5 is used by javascript updateInfo() to determine if the syslog div contents have changed
626     echo '<script type="text/javascript"> syslog_md5 = "'.$syslog_md5.'"; </script>';
627     //echo "log goes here<br/><br/><br/>";
628     echo '</div>';
629     
630     echo '<div id="aststats" class="infobox">';
631     echo show_aststats();
632     echo '</div>';
633     
634     
635     echo '<div id="sysinfo" class="infobox">';
636     echo show_sysinfo();
637     echo '</div>';
638     
639     
640     
641     echo '</div><div id="sysinfo-right">';
642     
643     
644     
645     echo '<div id="sysstats" class="infobox">';
646     echo show_sysstats();
647     echo '</div>';
648     
649     echo '<div id="procinfo" class="infobox">';
650     echo show_procinfo();
651     echo '</div>';
652     
653     echo '<div style="clear:both;"></div>';
654     
655     echo '</div></div>'; // #sysinfo, #sysinfo-right
656     
657     echo '<div class="content">';
658
659     if($dashboard_debug && $error->ErrorsExist()) {
660         $fh = fopen($amp_conf['ASTLOGDIR']."/dashboard-error.log","a");
661         fwrite($fh, $error->ErrorsAsText());
662         fclose($fh);
663     }           
664
665 } else {
666     // Handle AJAX updates
667     
668     switch ($info) {
669         case "sysstats":
670             echo show_sysstats();
671         break;
672         case "aststats":
673             echo show_aststats();
674         break;
675         case "procinfo":
676             echo show_procinfo();
677         break;
678         case 'sysinfo':
679             echo show_sysinfo();
680         break;
681         case 'syslog':
682             echo show_syslog($syslog_md5);   
683             // syslog_md5 is used by javascript updateInfo() to determine if the syslog div contents have changed
684             echo '<script type="text/javascript"> syslog_md5 = "'.$syslog_md5.'"; </script>';
685         break;
686         case 'syslog_ack':
687             do_syslog_ack();
688         break;
689         case 'syslog_delete':
690             do_syslog_delete();
691         break;
692         
693         case 'info':
694             $json = new Services_JSON();
695             header("Content-type: application/json");
696             echo $json->encode(
697                 array(
698                     'procinfo'=>show_procinfo(),
699                     'sysinfo'=>show_sysinfo(),
700                     'syslog'=>show_syslog($syslog_md5),
701                     'syslog_md5'=>$syslog_md5,
702                 )
703             );
704         break;
705         case 'stats':
706             $json = new Services_JSON();
707             header("Content-type: application/json");
708             echo $json->encode(
709                 array(
710                     'sysstats'=>show_sysstats(),
711                     'aststats'=>show_aststats(),
712                 )
713             );
714         break;
715         case 'all':
716             $json = new Services_JSON();
717             header("Content-type: application/json");
718             echo $json->encode(
719                 array(
720                     'sysstats'=>show_sysstats(),
721                     'aststats'=>show_aststats(),
722                     'procinfo'=>show_procinfo(),
723                     'sysinfo'=>show_sysinfo(),
724                     'syslog'=>show_syslog(),
725                 )
726             );
727         break;
728     }
729 }
730
731 ?>
732
Note: See TracBrowser for help on using the browser.