summaryrefslogtreecommitdiffstats
path: root/usr
diff options
context:
space:
mode:
authorRenato Botelho <garga@FreeBSD.org>2014-07-07 20:06:37 -0300
committerRenato Botelho <garga@FreeBSD.org>2014-07-07 20:06:37 -0300
commit971de1f98a991a42c448415d34805d2970b86c4f (patch)
tree3c09598d67f04060af6113153c1995d804fb1244 /usr
parent79cd8239ed8dd7d2dd0d86475b62ee25c5d5736d (diff)
downloadpfsense-971de1f98a991a42c448415d34805d2970b86c4f.zip
pfsense-971de1f98a991a42c448415d34805d2970b86c4f.tar.gz
Convert almost all /sbin/sysctl calls to php functions
Diffstat (limited to 'usr')
-rw-r--r--usr/local/www/carp_status.php5
-rw-r--r--usr/local/www/diag_nanobsd.php2
-rw-r--r--usr/local/www/includes/functions.inc.php43
-rw-r--r--usr/local/www/widgets/include/thermal_sensors.inc2
-rw-r--r--usr/local/www/widgets/widgets/system_information.widget.php7
5 files changed, 23 insertions, 36 deletions
diff --git a/usr/local/www/carp_status.php b/usr/local/www/carp_status.php
index 30251d5..192875e 100644
--- a/usr/local/www/carp_status.php
+++ b/usr/local/www/carp_status.php
@@ -34,7 +34,6 @@
##|-PRIV
/*
- pfSense_BUILDER_BINARIES: /sbin/sysctl
pfSense_MODULE: carp
*/
@@ -56,7 +55,7 @@ if($_POST['carp_maintenancemode'] <> "") {
}
if($_POST['disablecarp'] <> "") {
if($status == true) {
- mwexec("/sbin/sysctl net.inet.carp.allow=0");
+ set_single_sysctl('net.inet.carp.allow', '0');
if(is_array($config['virtualip']['vip'])) {
$viparr = &$config['virtualip']['vip'];
foreach ($viparr as $vip) {
@@ -83,7 +82,7 @@ if($_POST['disablecarp'] <> "") {
}
}
interfaces_carp_setup();
- mwexec("/sbin/sysctl net.inet.carp.allow=1");
+ set_single_sysctl('net.inet.carp.allow', '1');
}
}
diff --git a/usr/local/www/diag_nanobsd.php b/usr/local/www/diag_nanobsd.php
index 139d764..2d5998a 100644
--- a/usr/local/www/diag_nanobsd.php
+++ b/usr/local/www/diag_nanobsd.php
@@ -28,7 +28,7 @@
/*
pfSense_BUILDER_BINARIES: /sbin/mount /sbin/glabel /usr/bin/grep /usr/bin/cut /usr/bin/head /bin/cp
- pfSense_BUILDER_BINARIES: /usr/sbin/boot0cfg /bin/mkdir /sbin/fsck_ufs /sbin/mount /sbin/sysctl /bin/dd /sbin/tunefs
+ pfSense_BUILDER_BINARIES: /usr/sbin/boot0cfg /bin/mkdir /sbin/fsck_ufs /sbin/mount /bin/dd /sbin/tunefs
pfSense_MODULE: nanobsd
*/
diff --git a/usr/local/www/includes/functions.inc.php b/usr/local/www/includes/functions.inc.php
index 78043e8..48bc408 100644
--- a/usr/local/www/includes/functions.inc.php
+++ b/usr/local/www/includes/functions.inc.php
@@ -114,9 +114,9 @@ function get_uptime() {
function cpu_usage() {
$duration = 1;
$diff = array('user', 'nice', 'sys', 'intr', 'idle');
- $cpuTicks = array_combine($diff, explode(" ", `/sbin/sysctl -n kern.cp_time`));
+ $cpuTicks = array_combine($diff, explode(" ", get_single_sysctl('kern.cp_time')));
sleep($duration);
- $cpuTicks2 = array_combine($diff, explode(" ", `/sbin/sysctl -n kern.cp_time`));
+ $cpuTicks2 = array_combine($diff, explode(" ", get_single_sysctl('kern.cp_time')));
$totalStart = array_sum($cpuTicks);
$totalEnd = array_sum($cpuTicks2);
@@ -180,15 +180,12 @@ function get_mbuf($percent=false) {
}
function get_temp() {
- $temp_out = "";
- exec("/sbin/sysctl dev.cpu.0.temperature | /usr/bin/awk '{ print $2 }' | /usr/bin/cut -d 'C' -f 1", $dfout);
- $temp_out = trim($dfout[0]);
- if ($temp_out == "") {
- exec("/sbin/sysctl hw.acpi.thermal.tz0.temperature | /usr/bin/awk '{ print $2 }' | /usr/bin/cut -d 'C' -f 1", $dfout);
- $temp_out = trim($dfout[0]);
- }
+ $temp_out = get_single_sysctl("dev.cpu.0.temperature");
+ if ($temp_out == "")
+ $temp_out = get_single_sysctl("hw.acpi.thermal.tz0.temperature");
- return $temp_out;
+ // Remove 'C' from the end
+ return rtrim($temp_out, 'C');
}
/* Get mounted filesystems and usage. Do not display entries for virtual filesystems (e.g. devfs, nullfs, unionfs) */
@@ -232,16 +229,14 @@ function swap_usage() {
}
function mem_usage() {
- $memory = "";
- exec("/sbin/sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_inactive_count " .
- "vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
-
- $totalMem = $memory[0];
- $availMem = $memory[1] + $memory[2] + $memory[3];
- $usedMem = $totalMem - $availMem;
- if ($totalMem > 0)
+ $totalMem = get_single_sysctl("vm.stats.vm.v_page_count");
+ if ($totalMem > 0) {
+ $inactiveMem = get_single_sysctl("vm.stats.vm.v_inactive_count");
+ $cachedMem = get_single_sysctl("vm.stats.vm.v_cache_count");
+ $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;
@@ -255,22 +250,18 @@ function update_date_time() {
function get_cpufreq() {
$cpufreqs = "";
$out = "";
- exec("/sbin/sysctl -n dev.cpu.0.freq_levels", $cpufreqs);
- $cpufreqs = explode(" ", trim($cpufreqs[0]));
+ $cpufreqs = explode(" ", get_single_sysctl('dev.cpu.0.freq_levels'));
$maxfreq = explode("/", $cpufreqs[0]);
$maxfreq = $maxfreq[0];
$curfreq = "";
- exec("/sbin/sysctl -n dev.cpu.0.freq", $curfreq);
- $curfreq = trim($curfreq[0]);
+ $curfreq = get_single_sysctl('dev.cpu.0.freq');
if (($curfreq > 0) && ($curfreq != $maxfreq))
$out = "Current: {$curfreq} MHz, Max: {$maxfreq} MHz";
return $out;
}
function get_cpu_count($show_detail = false) {
- $cpucount = "";
- exec("/sbin/sysctl -n kern.smp.cpus", $cpucount);
- $cpucount = $cpucount[0];
+ $cpucount = get_single_sysctl('kern.smp.cpus');
if ($show_detail) {
$cpudetail = "";
diff --git a/usr/local/www/widgets/include/thermal_sensors.inc b/usr/local/www/widgets/include/thermal_sensors.inc
index 2ebc31d..e193b15 100644
--- a/usr/local/www/widgets/include/thermal_sensors.inc
+++ b/usr/local/www/widgets/include/thermal_sensors.inc
@@ -19,7 +19,7 @@ $thermal_sensors_widget_title = "Thermal Sensors";
//NOTE: depends on proper cofing in System >> Advanced >> Miscellaneous tab >> Thermal Sensors section.
function getThermalSensorsData() {
- exec("/sbin/sysctl -a | grep temperature", $dfout);
+ $_gb = exec("/sbin/sysctl -a | grep temperature", $dfout);
$thermalSensorsData = join("|", $dfout);
return $thermalSensorsData;
diff --git a/usr/local/www/widgets/widgets/system_information.widget.php b/usr/local/www/widgets/widgets/system_information.widget.php
index 3705937..694eefd 100644
--- a/usr/local/www/widgets/widgets/system_information.widget.php
+++ b/usr/local/www/widgets/widgets/system_information.widget.php
@@ -167,10 +167,7 @@ $filesystems = get_mounted_filesystems();
<td width="25%" class="vncellt"><?=gettext("CPU Type");?></td>
<td width="75%" class="listr">
<?php
- $cpumodel = "";
- exec("/sbin/sysctl -n hw.model", $cpumodel);
- $cpumodel = implode(" ", $cpumodel);
- echo (htmlspecialchars($cpumodel));
+ echo (htmlspecialchars(get_single_sysctl("hw.model")));
?>
<div id="cpufreq"><?= get_cpufreq(); ?></div>
<?php $cpucount = get_cpu_count();
@@ -264,7 +261,7 @@ $filesystems = get_mounted_filesystems();
<td width="75%" class="listr">
<?php $memUsage = mem_usage(); ?>
<div id="memUsagePB"></div>
- <span id="memusagemeter"><?= $memUsage.'%'; ?></span> of <?= sprintf("%.0f", `/sbin/sysctl -n hw.physmem` / (1024*1024)) ?> MB
+ <span id="memusagemeter"><?= $memUsage.'%'; ?></span> of <?= sprintf("%.0f", get_single_sysctl('hw.physmem') / (1024*1024)) ?> MB
</td>
</tr>
<?php if($showswap == true): ?>
OpenPOWER on IntegriCloud