diff options
author | gnhb <gnoahb@gmail.com> | 2010-04-10 22:07:48 +0700 |
---|---|---|
committer | gnhb <gnoahb@gmail.com> | 2010-04-10 22:07:48 +0700 |
commit | 632921995c58c6dadced140ca4f2aed2932e3b74 (patch) | |
tree | 5636313589460fcc625b7fa9ecb86ab51737fb0b /etc/inc/pfsense-utils.inc | |
parent | 73ee49f20460fe724258153aabcd61be8bc4f52f (diff) | |
download | pfsense-632921995c58c6dadced140ca4f2aed2932e3b74.zip pfsense-632921995c58c6dadced140ca4f2aed2932e3b74.tar.gz |
Implement reporting and logging of historical PPP uptime with data persistent through reboot.
Also, change the way uptime is captured. The mpd console is no longer used to
get PPP uptime data, which will prevent spamming of PPP logs with console access messages.
This means we no longer have to write out mpd_<interface>.query files to /var/etc.
Now, a simple calculation of the age of the /tmp/<interface>up file is used. This
gives the same data within the second as the console data so it seems acceptable.
I removed some "rm -f" calls from ppp-linkdown as there was already code in interfaces.inc
interface_bring_down function that unlinks the <interface>up and <interface>_router files.
There is still the rm -r nameserver_<interface> call in the linkdown script. Maybe this should
be moved to the interfac_bring_down function for consistency? Also, I commented out the
ngctl shutdown <interface>: call. I think it's probably not necessary any more.
Diffstat (limited to 'etc/inc/pfsense-utils.inc')
-rw-r--r-- | etc/inc/pfsense-utils.inc | 61 |
1 files changed, 22 insertions, 39 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 7a27a81..9be78e8 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -1141,43 +1141,8 @@ function is_dhcp_server_enabled() return $dhcpdenable; } -/* Compute the total uptime from the ppp uptime log file in the conf directory */ -/* Written by: gnoahb@gmail.com */ - -function get_ppp_uptime($serialport){ - if (file_exists("/conf/ppp-up.".$serialport . ".log")){ - $saved_time = file_get_contents("/conf/ppp-up." . $serialport . ".log"); - $uptime_data = explode("\n",$saved_time); - $sec=0; - $min=0; - $hrs=0; - foreach($uptime_data as $upt) { - $time = substr($upt, 1 + strpos($upt, " ")); - if ($time != "00:00:00"){ - $hms = explode(":",$time); - $hrs += $hms[0]; - $min += $hms[1]; - $sec += $hms[2]; - } - } - if ($sec != 0){ - $min += floor($sec/60); - $sec %= 60; - } - if($min !=0){ - $hrs += floor($min/60); - $min %= 60; - } - $total_time = $hrs.":".$min.":".$sec; - return $total_time; - - } else { - $total_time = "No session history data found!"; - return $total_time; - } -} - function convert_seconds_to_hms($sec){ + $min=$hrs=0; if ($sec != 0){ $min = floor($sec/60); $sec %= 60; @@ -1196,6 +1161,25 @@ function convert_seconds_to_hms($sec){ return $result; } +/* Compute the total uptime from the ppp uptime log file in the conf directory */ +/* Written by: gnoahb@gmail.com */ + +function get_ppp_uptime($port){ + if (file_exists("/conf/{$port}.log")){ + $saved_time = file_get_contents("/conf/{$port}.log"); + $uptime_data = explode("\n",$saved_time); + $sec=0; + $min=0; + $hrs=0; + foreach($uptime_data as $upt) { + $sec += substr($upt, 1 + strpos($upt, " ")); + } + return convert_seconds_to_hms($sec); + } else { + $total_time = "No session history data found!"; + return $total_time; + } +} //returns interface information function get_interface_info($ifdescr) { @@ -1329,8 +1313,7 @@ function get_interface_info($ifdescr) { if (file_exists("/dev/{$dev}")) { if (file_exists("{$g['varrun_path']}/ppp_{$if}.pid") && file_exists("{$g['varetc_path']}/mpd_{$if}.query")) { $ifinfo['pppinfo'] = "{$ifinfo['if']}"; - $pppid = substr($ifinfo['if'], 3); - $sec = trim(`/usr/bin/nc 127.0.0.1 500{$pppid} < {$g['varetc_path']}/mpd_{$if}.query | grep 'Session time' | cut -f7 -d ' '`); + $sec = trim(`/usr/local/sbin/ppp-uptime.sh {$ifinfo['if']}`); $ifinfo['ppp_uptime'] = convert_seconds_to_hms($sec); } } else { @@ -1338,7 +1321,7 @@ function get_interface_info($ifdescr) { $ifinfo['pppinfo'] = $dev . " device not present! Is the modem attached to the system?"; } // Calculate cumulative uptime for PPP link. Useful for connections that have per minute/hour contracts so you don't go over! - $ifinfo['ppp_uptime_accumulated'] = get_ppp_uptime($dev); + $ifinfo['ppp_uptime_accumulated'] = get_ppp_uptime($ifinfo['if']); break; default: |