summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/inc/interfaces.inc19
-rw-r--r--etc/inc/pfsense-utils.inc61
-rwxr-xr-xusr/local/sbin/ppp-linkdown11
-rw-r--r--usr/local/sbin/ppp-log-uptime.sh5
-rw-r--r--usr/local/sbin/ppp-uptime.sh3
5 files changed, 36 insertions, 63 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc
index 9dc9f9b..8bf674f 100644
--- a/etc/inc/interfaces.inc
+++ b/etc/inc/interfaces.inc
@@ -1033,25 +1033,6 @@ EOD;
fwrite($fd, $mpdconf);
fclose($fd);
- $fdlnkq = fopen("{$g['varetc_path']}/mpd_{$interface}.query", "w");
- if (!$fdlnkq) {
- /* NOTE: It is not fatal if we cannot write the query.") */
- log_error("Error: cannot open mpd_{$interface}.query in interface_ppp_configure().\n");
- } else {
- $linkquery = <<<EOD
-admin
-pfsense
-link lnk{$interface}
-show iface
-exit
-
-EOD;
-
- // Write out linkquery file for each configured PPP interface.
- fwrite($fdlnkq, $linkquery);
- fclose($fdlnkq);
- }
-
// Launch specified ppp instance
if (file_exists("{$ppp['port']}")) {
/* fire up mpd */
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:
diff --git a/usr/local/sbin/ppp-linkdown b/usr/local/sbin/ppp-linkdown
index 83d1790..420216f 100755
--- a/usr/local/sbin/ppp-linkdown
+++ b/usr/local/sbin/ppp-linkdown
@@ -1,7 +1,8 @@
#!/bin/sh
-
+if [ -f /tmp/$1up ] && [ -f /conf/$1.log ]; then
+ seconds=$((`date -j +%s` - `/usr/bin/stat -f %m /tmp/$1up`))
+ /usr/local/sbin/ppp-log-uptime.sh $seconds $1 &
+fi
# delete the node just in case mpd cannot do that
-/usr/sbin/ngctl shutdown $1:
-/bin/rm -f /var/etc/nameserver_$1
-/bin/rm -f /tmp/$1_router
-/bin/rm -f /tmp/$1up
+#/usr/sbin/ngctl shutdown $1:
+/bin/rm -f /var/etc/nameserver_$1 \ No newline at end of file
diff --git a/usr/local/sbin/ppp-log-uptime.sh b/usr/local/sbin/ppp-log-uptime.sh
new file mode 100644
index 0000000..6fd8def
--- /dev/null
+++ b/usr/local/sbin/ppp-log-uptime.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+#write the uptime in seconds to the persistent log in /conf/
+/etc/rc.conf_mount_rw
+/bin/echo `date -j +%Y.%m.%d-%H:%M:%S` $1 >> /conf/$2.log
+/etc/rc.conf_mount_ro
diff --git a/usr/local/sbin/ppp-uptime.sh b/usr/local/sbin/ppp-uptime.sh
new file mode 100644
index 0000000..d7a8441
--- /dev/null
+++ b/usr/local/sbin/ppp-uptime.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+#get ppp uptime from age of /tmp/{interface}up file
+[ -f /tmp/$1up ] && /bin/echo $((`date -j +%s` - `/usr/bin/stat -f %m /tmp/$1up`)) \ No newline at end of file
OpenPOWER on IntegriCloud