From df0cb10bbe3f2e61b37eeec786b5cfd96084d9cc Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 29 Aug 2013 00:09:40 -0700 Subject: [PATCH 1/2] Provide get_uptime_sec in a common include file so it is available to anything that cares. --- etc/inc/pfsense-utils.inc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 763d869f0a..a688d7bbb5 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -1445,6 +1445,19 @@ function get_cpu_speed() { return exec("sysctl hw.clockrate | awk '{ print $2 }'"); } +function get_uptime_sec() { + $boottime = ""; + $matches = ""; + exec("/sbin/sysctl -n kern.boottime", $boottime); + preg_match("/sec = (\d+)/", $boottime[0], $matches); + $boottime = $matches[1]; + if(intval($boottime) == 0) + return 0; + + $uptime = time() - $boottime; + return $uptime; +} + function add_hostname_to_watch($hostname) { if(!is_dir("/var/db/dnscache")) { mkdir("/var/db/dnscache"); From 806e59790949110bfc7c5ca0588c1793d5e84ea7 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 29 Aug 2013 00:12:54 -0700 Subject: [PATCH 2/2] Call get_uptime_sec from functions.inc.php to avoid code duplication --- usr/local/www/includes/functions.inc.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/usr/local/www/includes/functions.inc.php b/usr/local/www/includes/functions.inc.php index 2d3295a792..90efcc5548 100644 --- a/usr/local/www/includes/functions.inc.php +++ b/usr/local/www/includes/functions.inc.php @@ -8,6 +8,7 @@ if(Connection_Aborted()) { } require_once("config.inc"); +require_once("pfsense-utils.inc"); function get_stats() { $stats['cpu'] = cpu_usage(); @@ -77,15 +78,8 @@ function get_gatewaystats() { } function get_uptime() { - $boottime = ""; - $matches = ""; - exec("/sbin/sysctl -n kern.boottime", $boottime); - preg_match("/sec = (\d+)/", $boottime[0], $matches); - $boottime = $matches[1]; - $uptime = time() - $boottime; + $uptime = get_uptime_sec(); - if(intval($boottime) == 0) - return; if(intval($uptime) == 0) return;