diff options
-rw-r--r-- | usr/local/www/includes/functions.inc.php | 129 | ||||
-rwxr-xr-x | usr/local/www/index.php | 101 |
2 files changed, 152 insertions, 78 deletions
diff --git a/usr/local/www/includes/functions.inc.php b/usr/local/www/includes/functions.inc.php index b7c5b4f..dc58e9c 100644 --- a/usr/local/www/includes/functions.inc.php +++ b/usr/local/www/includes/functions.inc.php @@ -5,6 +5,9 @@ if(Connection_Aborted()) { } require_once("config.inc"); +require_once('guiconfig.inc'); + + function get_stats() { $stats['cpu'] = cpu_usage(); @@ -12,6 +15,9 @@ function get_stats() { $stats['uptime'] = get_uptime(); $stats['states'] = get_pfstate(); $stats['temp'] = get_temp(); + $stats['datetime'] = update_date_time(); + $stats['interfacestatistics'] = get_interfacestats(); + $stats['interfacestatus'] = get_interfacestatus(); $stats = join("|", $stats); @@ -43,25 +49,25 @@ function get_uptime() { } function cpu_usage() { - $cpuTicks = explode(" ", `/sbin/sysctl -n kern.cp_time`); - sleep(1); - $cpuTicks2 = explode(" ", `/sbin/sysctl -n kern.cp_time`); + exec("sysctl -n kern.cp_time && sleep 1 && sysctl -n kern.cp_time",$cpuTicksEx); + + $cpuTicks = explode(" ", $cpuTicksEx[0]); + $cpuTicks2 = explode(" ", $cpuTicksEx[1]); $diff = array(); - $diff['user'] = ($cpuTicks2[0] - $cpuTicks[0]); - $diff['nice'] = ($cpuTicks2[1] - $cpuTicks[1]); - $diff['sys'] = ($cpuTicks2[2] - $cpuTicks[2]); - $diff['intr'] = ($cpuTicks2[3] - $cpuTicks[3]); - $diff['idle'] = ($cpuTicks2[4] - $cpuTicks[4]); - - //echo "<!-- user: {$diff['user']} nice {$diff['nice']} sys {$diff['sys']} intr {$diff['intr']} idle {$diff['idle']} -->"; - $totalDiff = $diff['user'] + $diff['nice'] + $diff['sys'] + $diff['intr'] + $diff['idle']; - $totalused = $diff['user'] + $diff['nice'] + $diff['sys'] + $diff['intr']; - if (isset($totalused)&&$totalused <= 0) { - $totalused = 0.001; - } - $cpuUsage = floor(100 * ($totalused / $totalDiff)); - + $diff['user'] = ($cpuTicks2[0] - $cpuTicks[0]); + $diff['nice'] = ($cpuTicks2[1] - $cpuTicks[1]); + $diff['sys'] = ($cpuTicks2[2] - $cpuTicks[2]); + $diff['intr'] = ($cpuTicks2[3] - $cpuTicks[3]); + $diff['idle'] = ($cpuTicks2[4] - $cpuTicks[4]); + + //echo "<!-- user: {$diff['user']} nice {$diff['nice']} sys {$diff['sys']} intr {$diff['intr']} idle {$diff['idle']} -->"; + $totalDiff = $diff['user'] + $diff['nice'] + $diff['sys'] + $diff['intr'] + $diff['idle']; + $totalused = $diff['user'] + $diff['nice'] + $diff['sys'] + $diff['intr']; + if (isset($totalused)&&$totalused <= 0) { + $totalused = 0.001; + } + $cpuUsage = floor(100 * ($totalused / $totalDiff)); return $cpuUsage; } @@ -142,3 +148,92 @@ function mem_usage() return $memUsage; } +function update_date_time() { + + $datetime = date("D M j G:i:s T Y"); + return $datetime; +} + +function get_interfacestats(){ + + global $config; + //build interface list for widget use + $i = 0; $ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN'); + for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) { + $ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr']; + } + $array_in_packets = array(); + $array_out_packets = array(); + $array_in_bytes = array(); + $array_out_bytes = array(); + $array_in_errors = array(); + $array_out_errors = array(); + $array_collisions = array(); + $array_interrupt = array(); + $new_data = ""; + + //build data arrays + foreach ($ifdescrs as $ifdescr => $ifname){ + $ifinfo = get_interface_info($ifdescr); + $new_data .= "{$ifinfo['inpkts']},"; + $new_data .= "{$ifinfo['outpkts']},"; + $new_data .= format_bytes($ifinfo['inbytes']) . ","; + $new_data .= format_bytes($ifinfo['outbytes']) . ","; + if (isset($ifinfo['inerrs'])){ + $new_data .= "{$ifinfo['inerrs']},"; + $new_data .= "{$ifinfo['outerrs']},"; + } + else{ + $new_data .= "0,"; + $new_data .= "0,"; + } + if (isset($ifinfo['collisions'])) + $new_data .= htmlspecialchars($ifinfo['collisions']) . ","; + else + $new_data .= "0,"; + + + + }//end for + + return $new_data; + +} + +function get_interfacestatus(){ + $data = ""; + global $config; + + //build interface list for widget use + $i = 0; $ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN'); + for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) { + $ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr']; + } + + foreach ($ifdescrs as $ifdescr => $ifname){ + $ifinfo = get_interface_info($ifdescr); + $data .= $ifname . ","; + if($ifinfo['status'] == "up" || $ifinfo['status'] == "associated") { + $data .= "up"; + }else if ($ifinfo['status'] == "no carrier") { + $data .= "down"; + }else if ($ifinfo['status'] == "down") { + $data .= "block"; + } + $data .= ","; + if ($ifinfo['ipaddr']){ + $data .= htmlspecialchars($ifinfo['ipaddr']); + if ($ifinfo['dhcplink']) { + $data .= " (DHCP)"; + } + } + $data .= ","; + if ($ifinfo['status'] != "down") + $data .= htmlspecialchars($ifinfo['media']); + + $data .= "~"; + + } + return $data; +} + diff --git a/usr/local/www/index.php b/usr/local/www/index.php index 91f88eb..128aaf9 100755 --- a/usr/local/www/index.php +++ b/usr/local/www/index.php @@ -51,8 +51,8 @@ $oSajax->sajax_export("get_stats"); $oSajax->sajax_handle_client_request(); ############################################################################ - - + + ## Check to see if we have a swap space, ## if true, display, if false, hide it ... if(file_exists("/usr/sbin/swapinfo")) { @@ -191,57 +191,43 @@ foreach($phpincludefiles as $includename) { include($directory . $includename); } -//function to create widget tabs when called -function display_widget_tabs(& $tab_array) { - echo "<div id='tabs'>"; - $tabscounter = 0; - foreach ($tab_array as $ta) { - $dashpos = strpos($ta[2],'-'); - $tabname = $ta[2] . "-tab"; - $tabclass = substr($ta[2],0,$dashpos); - $tabclass = $tabclass . "-class"; - if ($ta[1] == true) { - $tabActive = "table-cell"; - $tabNonActive = "none"; - } - else { - $tabActive = "none"; - $tabNonActive = "table-cell"; - } - echo "<div id='{$ta[2]}-active' class='{$tabclass}-tabactive' style='display:{$tabActive}; background-color:#EEEEEE; color:black;'>"; - echo "<B> {$ta[0]}"; - echo " </B>"; - echo "</div>"; - - echo "<div id='{$ta[2]}-deactive' class='{$tabclass}-tabdeactive' style='display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;' onClick=\"return changeTabDIV('{$ta[2]}')\">"; - echo "<B> {$ta[0]}"; - echo " </B>"; - echo "</div>"; - } - - echo "<script type=\"text/javascript\">"; - echo "NiftyCheck();\n"; - echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n"; - echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n"; - echo "</script>"; - echo "</div>"; -} - $jscriptstr = <<<EOD <script language="javascript" type="text/javascript"> + +function widgetAjax(widget) { + uri = "widgets/widgets/" + widget + ".widget.php"; + var opt = { + // Use GET + method: 'get', + evalScripts: 'true', + asynchronous: true, + // Handle 404 + on404: function(t) { + alert('Error 404: location "' + t.statusText + '" was not found.'); + }, + // Handle other errors + onFailure: function(t) { + alert('Error ' + t.status + ' -- ' + t.statusText); + } + } + new Ajax.Updater(widget, uri, opt); + } + + function addDiv(selectedDiv){ - selectedDiv = selectedDiv + "-div"; - textlink = d.getElementById(selectedDiv); + selectedDiv2 = selectedDiv + "-container"; + d = document; + textlink = d.getElementById(selectedDiv2); if (textlink.style.display != "none") { - Effect.Shake(selectedDiv); + Effect.Shake(selectedDiv2); } else { - Effect.Appear(selectedDiv, {duration:1}); - d = document; - selectIntLink = selectedDiv + "-input"; + widgetAjax(selectedDiv); + Effect.Appear(selectedDiv2, {duration:1}); + selectIntLink = selectedDiv2 + "-input"; textlink = d.getElementById(selectIntLink); textlink.value = "show"; showSave(); @@ -259,7 +245,7 @@ function configureDiv(selectedDiv){ } function showDiv(selectedDiv,swapButtons){ - //appear element + //appear element Effect.BlindDown(selectedDiv, {duration:1}); showSave(); d = document; @@ -274,7 +260,7 @@ function showDiv(selectedDiv,swapButtons){ textlink.style.display = "none"; } - selectIntLink = selectedDiv + "-div-input"; + selectIntLink = selectedDiv + "-container-input"; textlink = d.getElementById(selectIntLink); textlink.value = "show"; @@ -294,7 +280,7 @@ function minimizeDiv(selectedDiv,swapButtons){ textlink = d.getElementById(selectIntLink); textlink.style.display = "none"; } - selectIntLink = selectedDiv + "-div-input"; + selectIntLink = selectedDiv + "-container-input"; textlink = d.getElementById(selectIntLink); textlink.value = "hide"; @@ -302,7 +288,7 @@ function minimizeDiv(selectedDiv,swapButtons){ function closeDiv(selectedDiv){ showSave(); - selectedDiv = selectedDiv + "-div"; + selectedDiv = selectedDiv + "-container"; Effect.Fade(selectedDiv, {duration:1}); d = document; selectIntLink = selectedDiv + "-input"; @@ -423,9 +409,6 @@ echo $jscriptstr; if(!file_exists("/usr/local/www/themes/{$g['theme']}/no_big_logo")) echo "<center><img src=\"./themes/".$g['theme']."/images/logobig.jpg\"></center><br>"; ?> - -<?php - ?> <div id="widgetcontainer" style="display:none"> <div id="content1"><h1>Available Widgets</h1><p><?php $widgetfiles_add = $widgetfiles; @@ -462,7 +445,7 @@ echo $jscriptstr; </div> <div id="welcomecontainer" style="display:none"> - <div id="welcome-div"> + <div id="welcome-container"> <h1> <div style="float:left;width:80%;padding: 2px"> Welcome to the New Dashboard page! @@ -486,7 +469,7 @@ echo $jscriptstr; <input type="hidden" value="" name="sequence" id="sequence"> <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="Click here to add widgets" style="cursor: pointer;" onmouseup="domTT_activate(this, event, 'content', document.getElementById('content1'), 'type', 'velcro', 'delay', 0, 'fade', 'both', 'fadeMax', 100, 'styleClass', 'niceTitle');" /> -<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_info_pkg.gif" alt="Click here for help" style="cursor: help;" onmouseup="hideAllWidgets();domTT_activate(this, event, 'content', document.getElementById('welcome-div'), 'type', 'sticky', 'closeLink', '','delay', 0, 'fade', 'both', 'fadeMax', 100, 'styleClass', 'niceTitle');" /> +<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_info_pkg.gif" alt="Click here for help" style="cursor: help;" onmouseup="hideAllWidgets();domTT_activate(this, event, 'content', document.getElementById('welcome-container'), 'type', 'sticky', 'closeLink', '','delay', 0, 'fade', 'both', 'fadeMax', 100, 'styleClass', 'niceTitle');" /> @@ -605,8 +588,8 @@ echo $jscriptstr; ?> <div style="clear:both;"></div> - <div id="<?php echo $widgetname;?>-div" class="widgetdiv" style="display:<?php echo $divdisplay; ?>;"> - <input type="hidden" value="<?php echo $inputdisplay;?>" id="<?php echo $widgetname;?>-div-input" name="<?php echo $widgetname;?>-div-input"> + <div id="<?php echo $widgetname;?>-container" class="widgetdiv" style="display:<?php echo $divdisplay; ?>;"> + <input type="hidden" value="<?php echo $inputdisplay;?>" id="<?php echo $widgetname;?>-container-input" name="<?php echo $widgetname;?>-container-input"> <div id="<?php echo $widgetname;?>topic" class="widgetheader" style="cursor:move"> <div style="float:left;"> <?php @@ -646,13 +629,9 @@ echo $jscriptstr; </div> <div id="<?php echo $widgetname;?>" style="display:<?php echo $display; ?>;"> <?php - if (file_exists($directory . $widget)) + if ($displayarray[$widgetcounter] != "close") { include($directory . $widget); - } - else - { - echo "Widget does not exists in the widget folder. <br>Please reinstall the dashboard package to correct this issue."; } ?> </div> @@ -684,7 +663,7 @@ echo $jscriptstr; window.onload = function(in_event) { hideAllWidgets(); - domTT_activate('welcome1', null, 'x', 287, 'y', 107, 'content', document.getElementById('welcome-div'), 'type', 'sticky', 'closeLink', '','delay', 1000, 'fade', 'both', 'fadeMax', 100, 'styleClass', 'niceTitle'); + domTT_activate('welcome1', null, 'x', 287, 'y', 107, 'content', document.getElementById('welcome-container'), 'type', 'sticky', 'closeLink', '','delay', 1000, 'fade', 'both', 'fadeMax', 100, 'styleClass', 'niceTitle'); } <?php } ?> // <![CDATA[ |