Project

General

Profile

« Previous | Next » 

Revision 8eb2f33a

Added by Scott Ullrich over 15 years ago

These patches give you a display of the uptime of the active PPP link
on the "Status-> Interfaces" page, and also logging on /conf (to
survive reboot) of uptimes of each session after it is closed. In
addition, the status_interfaces.php page displays the cumulative
uptime total so users can manage their links that are on pay by the
minute arrangements.

Shortcomings: partial minutes are just added as cumulative seconds
where most providers probably charge you for a minute after you're 1
second into that minute. I may fix this later.

Submitted-by: Gabriel B

View differences:

etc/inc/interfaces.inc
879 879

  
880 880
		// Start ppp.linkup file
881 881
		$rclinkup = "default:\n";
882
		// Start ppp.linkdown file
883
		$rclinkdown = "default:\n";
882 884

  
883 885
 	   	if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
884 886
			foreach ($config['ppps']['ppp'] as $ppp) {
......
911 913
				$peerfile .= "\n";
912 914
				$i++;
913 915
				$startingip++;
914
				$rclinkup.= "{$dev}:\n";
915
				$rclinkup.= "	! sh -c \"/sbin/ppp-script HISADDR INTERFACE DNS0 DNS1 \"\n";
916
				$rclinkup.= "	! sh -c \"/etc/rc.linkup INTERFACE start\"\n";
917
				$rclinkup.= "	! sh -c \"/etc/rc.filter_configure_sync\"\n";
916
				$rclinkup .= "{$dev}:\n";
917
				$rclinkup .= "	! sh -c \"/etc/rc.conf_mount_rw\"\n";
918
 				$rclinkup .= "	! sh -c \"/bin/echo `date -j +%Y.%m.%d-%H:%M:%S` 00:00:00 >> /conf/ppp-up.{$dev}.log\"\n";
919
				$rclinkup .= "	! sh -c \"/sbin/ppp-script HISADDR INTERFACE DNS0 DNS1\"\n";
920
				$rclinkup .= "	! sh -c \"/etc/rc.linkup INTERFACE start\"\n";
921
				$rclinkup .= "	! sh -c \"/etc/rc.conf_mount_ro\"\n";
922
				// Link down file
923
				$rclinkdown .= "{$dev}:\n";
924
				$rclinkdown .= "	! sh -c \"/etc/rc.conf_mount_rw\"\n";
925
				$rclinkdown .= "	! sh -c \"/bin/echo `date -j +%Y.%m.%d-%H:%M:%S` UPTIME >> /conf/ppp-up.{$dev}.log\"\n";
926
				$rclinkdown .= "	! sh -c \"/etc/rc.conf_mount_ro\"\n";
918 927
			}	
919 928
    		}
920 929

  
......
923 932

  
924 933
		// Write out linkup file
925 934
		file_put_contents("/etc/ppp/ppp.linkup", $rclinkup);
926

  
935
		file_put_contents("/etc/ppp/ppp.linkdown", $rclinkdown);
927 936
		// Make executable
928 937
		exec("chmod a+rx /etc/ppp/ppp.linkup");
938
		exec("chmod a+rx /etc/ppp/ppp.linkdown");
929 939
	}
930 940
	// Launch specified ppp instance
931
	if( !$edit){
941
	if( !$edit && file_exists("/dev/{$orig_dev}")){
932 942
		$running = `ps awux | grep ppp | grep -v grep | grep $orig_dev`;
933 943
		if(!$running)
934 944
			mwexec("/usr/sbin/ppp -background {$orig_dev}");
etc/inc/pfsense-utils.inc
1119 1119
	return $dhcpdenable;
1120 1120
}
1121 1121

  
1122
/* Compute the total uptime from the ppp uptime log file in the conf directory */
1123
/* Written by: gnoahb@gmail.com */
1124

  
1125
function get_ppp_uptime($serialport){
1126
	if (file_exists("/conf/ppp-up.".$serialport . ".log")){
1127
        	$saved_time = file_get_contents("/conf/ppp-up." . $serialport . ".log");
1128
        	$uptime_data = explode("\n",$saved_time);
1129
    		$sec=0;
1130
		$min=0;
1131
		$hrs=0;
1132
		foreach($uptime_data as $upt) {
1133
        	        $time = substr($upt, 1 + strpos($upt, " "));
1134
        	        if ($time != "00:00:00"){
1135
        	                $hms = explode(":",$time);
1136
        	                $hrs += $hms[0];
1137
        	                $min += $hms[1];
1138
        	                $sec += $hms[2];
1139
               		 }
1140
 		}
1141
        	if ($sec != 0){
1142
                	$min += floor($sec/60);
1143
                	$sec %= 60;
1144
        	}
1145
        	if($min !=0){
1146
                	$hrs += floor($min/60);
1147
                	$min %= 60;
1148
        	}
1149
		$total_time = $hrs.":".$min.":".$sec;
1150
		return $total_time;
1151

  
1152
	} else {
1153
		$total_time = "No session history data found!";
1154
		return $total_time;
1155
	}
1156
}
1157

  
1158

  
1159

  
1160

  
1122 1161
//returns interface information
1123 1162
function get_interface_info($ifdescr) {
1124 1163
	global $config, $linkinfo, $netstatrninfo;
......
1262 1301
		else
1263 1302
			$ifinfo['pptplink'] = "down";
1264 1303
		break;
1304
	/* PPP interface? -> get uptime for this session and cumulative uptime from the persistant log file in conf */
1265 1305
	case "":
1266
		if ($config['interfaces'][$if]['serialport'])
1267
			$ifinfo['ppplink'] = $config['interfaces'][$if]['serialport'];
1306
		if ($config['interfaces'][$if]['serialport']){
1307
			$dev = $config['interfaces'][$if]['serialport'];
1308
			if (file_exists("/dev/{$dev}")){
1309
				$ifinfo['ppplink'] = $dev;
1310
				
1311
				if (file_exists("/var/run/{$dev}.sock") && file_exists("/var/run/{$dev}.if")){
1312
					$ifinfo['ppp_uptime'] = `/usr/sbin/pppctl /var/run/$dev.sock show physical | grep 'Connect time' | cut -c 15-`;
1313
				} //else if (`/sbin/ifconfig 
1314
				$ifinfo['missing_device'] = 0;
1315
			}
1316
			else{
1317
				$ifinfo['ppplink'] = $dev . " device not present! Is the modem attached to the system?";
1318
				$ifinfo['missing_device'] = 1;	
1319
			}
1320
			// Calculate cumulative uptime for PPP link. Useful for connections that have per minute/hour contracts so you don't go over!
1321
			$ifinfo['ppp_uptime_accumulated'] = get_ppp_uptime($dev);
1322
		}
1323

  
1268 1324
		break;
1269 1325
	default:
1270 1326
		break;
usr/local/www/status_interfaces.php
149 149
			</a>
150 150
		</td>
151 151
	</tr>
152
	<?php  endif; if ($ifinfo['ppp_uptime'] || $ifinfo['ppp_uptime_accumulated']): ?>
153
	<tr>
154
                <td width="22%" class="vncellt">PPP uptime</td>
155
                <td width="78%" class="listr">
156
                        <?=htmlspecialchars($ifinfo['ppp_uptime']);?>&nbsp;&nbsp;Previous Sessions:&nbsp;<?=htmlspecialchars($ifinfo['ppp_uptime_accumulated']);?>&nbsp;&nbsp;
157
                </td>
158
        </tr>
152 159
	<?php  endif; if ($ifinfo['macaddr']): ?>
153 160
	<tr>
154 161
		<td width="22%" class="vncellt">MAC address</td>

Also available in: Unified diff