summaryrefslogtreecommitdiffstats
path: root/usr/local/www/includes/functions.inc.php
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@inf.org>2015-04-14 14:10:58 +0545
committerPhil Davis <phil.davis@inf.org>2015-04-14 14:10:58 +0545
commitf3ec04877ba7ef9aa4e0c43d34cec0f58a53891f (patch)
tree05bf5b60f03bcba80cdfbe6de0394b09fab8e14e /usr/local/www/includes/functions.inc.php
parent460610b2076ed39fd3f0d36a5c758c2bc9afefb0 (diff)
downloadpfsense-f3ec04877ba7ef9aa4e0c43d34cec0f58a53891f.zip
pfsense-f3ec04877ba7ef9aa4e0c43d34cec0f58a53891f.tar.gz
Code style for small things in usr-local-www
Diffstat (limited to 'usr/local/www/includes/functions.inc.php')
-rw-r--r--usr/local/www/includes/functions.inc.php160
1 files changed, 90 insertions, 70 deletions
diff --git a/usr/local/www/includes/functions.inc.php b/usr/local/www/includes/functions.inc.php
index f2e1191..8d89969 100644
--- a/usr/local/www/includes/functions.inc.php
+++ b/usr/local/www/includes/functions.inc.php
@@ -5,7 +5,7 @@
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
*/
-if(Connection_Aborted()) {
+if (Connection_Aborted()) {
exit;
}
@@ -37,34 +37,35 @@ function get_gatewaystats() {
$gateways_status = return_gateways_status(true);
$data = "";
$isfirst = true;
- foreach($a_gateways as $gname => $gw) {
- if(!$isfirst)
+ foreach ($a_gateways as $gname => $gw) {
+ if (!$isfirst) {
$data .= ",";
+ }
$isfirst = false;
$data .= $gw['name'] . ",";
if ($gateways_status[$gname]) {
$data .= "<b>" . lookup_gateway_ip_by_name($gname) . "</b>,";
$gws = $gateways_status[$gname];
- switch(strtolower($gws['status'])) {
- case "none":
- $online = "Online";
- $bgcolor = "#90EE90"; // lightgreen
- break;
- case "down":
- $online = "Offline";
- $bgcolor = "#F08080"; // lightcoral
- break;
- case "delay":
- $online = "Latency";
- $bgcolor = "#F0E68C"; // khaki
- break;
- case "loss":
- $online = "Packetloss";
- $bgcolor = "#F0E68C"; // khaki
- break;
- default:
- $online = "Pending";
- break;
+ switch (strtolower($gws['status'])) {
+ case "none":
+ $online = "Online";
+ $bgcolor = "#90EE90"; // lightgreen
+ break;
+ case "down":
+ $online = "Offline";
+ $bgcolor = "#F08080"; // lightcoral
+ break;
+ case "delay":
+ $online = "Latency";
+ $bgcolor = "#F0E68C"; // khaki
+ break;
+ case "loss":
+ $online = "Packetloss";
+ $bgcolor = "#F0E68C"; // khaki
+ break;
+ default:
+ $online = "Pending";
+ break;
}
} else {
$data .= "~,";
@@ -82,8 +83,9 @@ function get_gatewaystats() {
function get_uptime() {
$uptime = get_uptime_sec();
- if(intval($uptime) == 0)
+ if (intval($uptime) == 0) {
return;
+ }
$updays = (int)($uptime / 86400);
$uptime %= 86400;
@@ -94,19 +96,23 @@ function get_uptime() {
$upsecs = (int)($uptime);
$uptimestr = "";
- if ($updays > 1)
+ if ($updays > 1) {
$uptimestr .= "$updays Days ";
- else if ($updays > 0)
+ } else if ($updays > 0) {
$uptimestr .= "1 Day ";
+ }
- if ($uphours > 1)
+ if ($uphours > 1) {
$hours = "s";
+ }
- if ($upmins > 1)
+ if ($upmins > 1) {
$minutes = "s";
+ }
- if ($upmins > 1)
+ if ($upmins > 1) {
$seconds = "s";
+ }
$uptimestr .= sprintf("%02d Hour$hours %02d Minute$minutes %02d Second$seconds", $uphours, $upmins, $upsecs);
return $uptimestr;
@@ -124,8 +130,9 @@ function cpu_usage() {
$totalEnd = array_sum($cpuTicks2);
// Something wrapped ?!?!
- if ($totalEnd <= $totalStart)
+ if ($totalEnd <= $totalStart) {
return 0;
+ }
// Calculate total cycles used
$totalUsed = ($totalEnd - $totalStart) - ($cpuTicks2['idle'] - $cpuTicks['idle']);
@@ -139,23 +146,27 @@ function cpu_usage() {
function get_pfstate($percent=false) {
global $config;
$matches = "";
- if (isset($config['system']['maximumstates']) and $config['system']['maximumstates'] > 0)
+ if (isset($config['system']['maximumstates']) and $config['system']['maximumstates'] > 0) {
$maxstates="{$config['system']['maximumstates']}";
- else
+ } else {
$maxstates=pfsense_default_state_size();
+ }
$curentries = `/sbin/pfctl -si |grep current`;
if (preg_match("/([0-9]+)/", $curentries, $matches)) {
$curentries = $matches[1];
}
- if (!is_numeric($curentries))
+ if (!is_numeric($curentries)) {
$curentries = 0;
- if ($percent)
- if (intval($maxstates) > 0)
+ }
+ if ($percent) {
+ if (intval($maxstates) > 0) {
return round(($curentries / $maxstates) * 100, 0);
- else
+ } else {
return "NA";
- else
+ }
+ } else {
return $curentries . "/" . $maxstates;
+ }
}
function has_temp() {
@@ -171,20 +182,23 @@ function get_hwtype() {
function get_mbuf($percent=false) {
$mbufs_output=trim(`/usr/bin/netstat -mb | /usr/bin/grep "mbuf clusters in use" | /usr/bin/awk '{ print $1 }'`);
- list( $mbufs_current, $mbufs_cache, $mbufs_total, $mbufs_max ) = explode( "/", $mbufs_output);
- if ($percent)
- if ($mbufs_max > 0)
+ list($mbufs_current, $mbufs_cache, $mbufs_total, $mbufs_max) = explode("/", $mbufs_output);
+ if ($percent) {
+ if ($mbufs_max > 0) {
return round(($mbufs_total / $mbufs_max) * 100, 0);
- else
+ } else {
return "NA";
- else
+ }
+ } else {
return "{$mbufs_total}/{$mbufs_max}";
+ }
}
function get_temp() {
$temp_out = get_single_sysctl("dev.cpu.0.temperature");
- if ($temp_out == "")
+ if ($temp_out == "") {
$temp_out = get_single_sysctl("hw.acpi.thermal.tz0.temperature");
+ }
// Remove 'C' from the end
return rtrim($temp_out, 'C');
@@ -221,11 +235,12 @@ function disk_usage($slice = '/') {
function swap_usage() {
exec("/usr/sbin/swapinfo", $swap_info);
$swap_used = "";
- foreach ($swap_info as $line)
+ foreach ($swap_info as $line) {
if (preg_match('/(\d+)%$/', $line, $matches)) {
$swap_used = $matches[1];
break;
}
+ }
return $swap_used;
}
@@ -238,8 +253,9 @@ function mem_usage() {
$freeMem = get_single_sysctl("vm.stats.vm.v_free_count");
$usedMem = $totalMem - ($inactiveMem + $cachedMem + $freeMem);
$memUsage = round(($usedMem * 100) / $totalMem, 0);
- } else
+ } else {
$memUsage = "NA";
+ }
return $memUsage;
}
@@ -257,8 +273,9 @@ function get_cpufreq() {
$maxfreq = $maxfreq[0];
$curfreq = "";
$curfreq = get_single_sysctl('dev.cpu.0.freq');
- if (($curfreq > 0) && ($curfreq != $maxfreq))
+ if (($curfreq > 0) && ($curfreq != $maxfreq)) {
$out = "Current: {$curfreq} MHz, Max: {$maxfreq} MHz";
+ }
return $out;
}
@@ -295,24 +312,24 @@ function get_interfacestats() {
$new_data = "";
//build data arrays
- foreach ($ifdescrs as $ifdescr => $ifname){
+ 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,";
+ $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;
@@ -325,25 +342,28 @@ function get_interfacestatus() {
//build interface list for widget use
$ifdescrs = get_configured_interface_with_descr();
- foreach ($ifdescrs as $ifdescr => $ifname){
+ foreach ($ifdescrs as $ifdescr => $ifname) {
$ifinfo = get_interface_info($ifdescr);
$data .= $ifname . ",";
- if($ifinfo['status'] == "up" || $ifinfo['status'] == "associated") {
+ if ($ifinfo['status'] == "up" || $ifinfo['status'] == "associated") {
$data .= "up";
- }else if ($ifinfo['status'] == "no carrier") {
+ } else if ($ifinfo['status'] == "no carrier") {
$data .= "down";
- }else if ($ifinfo['status'] == "down") {
+ } else if ($ifinfo['status'] == "down") {
$data .= "block";
}
$data .= ",";
- if ($ifinfo['ipaddr'])
+ if ($ifinfo['ipaddr']) {
$data .= "<strong>" . htmlspecialchars($ifinfo['ipaddr']) . "</strong>";
+ }
$data .= ",";
- if ($ifinfo['ipaddrv6'])
+ if ($ifinfo['ipaddrv6']) {
$data .= "<strong>" . htmlspecialchars($ifinfo['ipaddrv6']) . "</strong>";
+ }
$data .= ",";
- if ($ifinfo['status'] != "down")
+ if ($ifinfo['status'] != "down") {
$data .= htmlspecialchars($ifinfo['media']);
+ }
$data .= "~";
OpenPOWER on IntegriCloud