Location: PHPKode > projects > easydialup > easydialup/index.php
<?php

include('./config/config.php');  
include('./version.php');  
/*Show the Internet On page and start the internet connection, the after 5 seconds refresh to the Connecting page*/
if ($_GET[submit] == "Internet On") {
	exec("/usr/bin/$dialer $isp");
	header( 'refresh: 5; url=index.php?submit=Connecting' );

	/*Create the Connecting.log file used in the Connecting section*/
	$fp_count_create = fopen("connecting.log", "w");
	fclose($fp_count_create);

	$display_block = "<b>The Internet is now CONNECTING</b>, <br><br>The Internet will be ON in <b>$time_out_in_seconds seconds</b>, please be patient. <br><br>To disconnect from the Internet please  click Internet Off

	<th colspan=2></th>
	</tr>

	</tr>
	</table>
	<p><input type=submit name=\"submit\" value=\"Internet Off\"></p>

	"
	;

}
/*Show the Internet Off page and kill the internet connect*/
elseif ($_GET[submit] == "Internet Off") {
	exec("/usr/bin/$disconnect");
	
	/*remove connecting.log if internet is not on*/
	$filename_connecting = 'connecting.log';

	if (file_exists($filename_connecting)) {
		exec("rm connecting.log");
	} 
	/*end of connecting.log if internet is not on*/

	/*remove ppp.log if internet is not on*/
	$filename = 'ppp.log';

	if (file_exists($filename)) {
		exec("rm ppp.log");
	} 
	/*end of remove ppp.log if internet is not on*/

	$display_block = "<b>The Internet is now OFF</b>, <br><br>To connect to the Internet please click Internet On

	<th colspan=2></th>
	</tr>

	</tr>
	</table>
	<p><input type=submit name=\"submit\" value=\"Internet On\"></p>
	";
}

/*Show Connecting page*/
elseif ($_GET[submit] == "Connecting") {
	/*Show the initial connecting page for 5 seconds*/
	header( 'refresh: 5; url=index.php?submit=Connecting' );
	/*Connecting page - if ppp0 up show main page and refresh the page every 5 seconds to check */
	/*$is_ppp_up=exec("cat /proc/net/dev | grep ppp0 | gawk {'print $1'}");*/
	$ppp_check=exec("cat /proc/net/dev | grep ppp0");
	$is_ppp_up=substr($ppp_check,2,4);

	if ($is_ppp_up == 'ppp0')  {
		
		header( 'refresh: 5; url=index.php' );
		/*PPP timer section*/
		$time = time();
		// Open the file and erase the contents if any
		$fp = fopen("ppp.log", "w");

		// Write the data to the file
		fwrite($fp, $time);

		// Close the file
		fclose($fp);
		/*end of PPP timer section*/

		$display_block = "<b>The Internet is now On</b>, <br><br>To disconnect from the Internet 	please  click Internet Off

		<th colspan=2></th>
		</tr>
		</tr>
		</table>
		<br><input type=submit name=\"submit\" value=\"Internet Off\"></p>
	 	";

	}
	/*Connecting page - if ppp0 not up show connecting page with animated gif(div)(check the css) and refresh the page every 5 seconds to check*/
	elseif ($is_ppp_up != 'ppp0') {
		header( 'refresh: 5; url=index.php?submit=Connecting' );

		/*This is the Connecting page Timeout counter*/ 
		$fp_count = fopen("connecting.log", "r");
		$count = fread($fp_count, 1024);
		fclose($fp_count);
		$count = $count + 1;
		$fp_count = fopen("connecting.log", "w");
		fwrite($fp_count, $count);
		fclose($fp_count);
		/*This is the end of the Connecting page Timeout counter*/ 
		
		

		/*remove ppp.log if internet is not on*/
		$filename = 'ppp.log';

		if (file_exists($filename)) {
			exec("rm ppp.log");
		} 
		/*end of remove ppp.log if internet is not on*/
		
		/*initialse the variable to use to determine timeout figures*/
		$time_since_connection_attempted = $count * 5;

		$time_to_internet_on = $time_out_in_seconds - $time_since_connection_attempted;

		$refreshes_to_time_out = $time_out_in_seconds/5;

		/*if Connecting page hasnt reached timeout level do*/
		if ($count <= $refreshes_to_time_out) {
		$display_block = "<b>The Internet is now CONNECTING</b>, <br><br>The Internet will be ON 	in <b>$time_to_internet_on seconds</b>, please be patient. <br><br>This page will automatically alert you once the Internet is ON<br><br>To disconnect from the Internet please click Internet Off
		<br><br><div id=\"connecting\"><br><Br><br><BR><br>
		</div>

		<th colspan=2></th>
		</tr>
		
		</tr>
		</table>
		<p><input type=submit name=\"submit\" value=\"Internet Off\"></p>
		";
		}; 
	
		/*if Connecting page has reached timeout level do*/
		if ($count >= $refreshes_to_time_out) {

		header( 'refresh: 15; url=index.php' );
		
		$display_block = "<b>The attempt to connect to the Internet has TIMED OUT</b>, <br><br>This means that for some reason the Internet has failed to connect. Pleaes check that all modem/phone cables are plugged in and that the login details are correct<br><br>You will now be redirected back to the home page where you can attempt to connect to the Internet again
		<br><br><div id=\"connecting\"><br><Br><br><BR><br>
		</div>

		<th colspan=2></th>
		</tr>
		
		</tr>
		</table>
		<p><input type=submit name=\"submit\" value=\"Internet Off\"></p>
		";
		}; 
		
	}
}
/*Show Configuration page*/
elseif ($_GET[submit] == "conf") {
	header( 'refresh: 5; url=index.php?submit=conf' );

	/*retarded part - please fix*/
	/*test is the connections up and refresh the page every 5 seconds to check*/
	/*$is_ppp_up=exec("cat /proc/net/dev | grep ppp0 | gawk {'print $1'}");*/
	$ppp_check=exec("cat /proc/net/dev | grep ppp0");
	$is_ppp_up=substr($ppp_check,2,4);

	if ($is_ppp_up == 'ppp0')  {

		/*create log file if not already exists*/
		$filename = 'ppp.log';
		if (!file_exists($filename)) {
			/*PPP timer section*/
			$time = time();
			echo $time;
			// Open the file and erase the contents if any
			$fp = fopen("ppp.log", "w");

			// Write the data to the file
			fwrite($fp, $time);

			// Close the file
			fclose($fp);
			/*end of PPP timer section*/
		} 



		$display_block = "<b>The Internet is now On</b>, <br><br>To disconnect from the Internet please  click Internet Off

		<th colspan=2></th>
		</tr>
		</tr>
		</table>
		<br><input type=submit name=\"submit\" value=\"Internet Off\"></p>
		 ";
	}
	/*test is the connections down and refresh the page every 5 seconds to check*/
	elseif ($is_ppp_ip != 'ppp0')  {
				
		$filename = 'ppp.log';

		if (file_exists($filename)) {
			exec("rm ppp.log");
		} 

		$display_block = "<b>The Internet is now OFF</b>, <br><br>To connect to the Internet please  click Internet On

		<th colspan=2></th>
		</tr>
		</tr>
		</table>
		<p><input type=submit name=\"submit\" value=\"Internet On\"></p>
		 ";
	}

	$display_block .= "

	<div id=\"rightconf\">
	<b>Easy DialUp Configuration</b><br><br>
	The dialer is set to: $dialer<br>The dialer profile is: $isp<br>The theme is: $theme<br>The disconnect command is: $disconnect<br>The connection timeout is :$time_out_in_seconds seconds<br>Easy DialUp version: $version $version_status<br><br>To edit these settings open the config.php file thats in /you webserver document root/easydialup/conf directory

	<th colspan=2></th>
	</tr>

	</tr>

	</table>

	</div>
	"

	;

}
/*Shows Stats Page*/
elseif ($_GET[submit] == "stats") {
	header( 'refresh: 5; url=index.php?submit=stats' );

	/*restarded part - please fix*/
	/*test is the connections up and refresh the page every 5 seconds to check*/
	/*$is_ppp_up=exec("cat /proc/net/dev | grep ppp0 | gawk {'print $1'}");*/
	$ppp_check=exec("cat /proc/net/dev | grep ppp0");
	$is_ppp_up=substr($ppp_check,2,4);

	if ($is_ppp_up == 'ppp0')  {
		

		/*create log file if not already exists*/
		$filename = 'ppp.log';
		if (!file_exists($filename)) {
			/*PPP timer section*/
			$time = time();
			/*think this line can be removed*/
			echo $time;
			// Open the file and erase the contents if any
			$fp = fopen("ppp.log", "w");

			// Write the data to the file
			fwrite($fp, $time);

			// Close the file
			fclose($fp);
			/*end of PPP timer section*/
		} 
	
		$display_block = "<b>The Internet is now On</b>, <br><br>To disconnect from the Internet please  click Internet Off

		<th colspan=2></th>
		</tr>
		</tr>
		</table>
		<br><input type=submit name=\"submit\" value=\"Internet Off\"></p>
		 ";
	}
	/*test is the connections down and refresh the page every 5 seconds to check*/
	elseif ($is_ppp_ip != 'ppp0')  {

		/*remove ppp.log if internet is not on*/
		$filename = 'ppp.log';

		if (file_exists($filename)) {
			exec("rm ppp.log");
		} 
		/*end of remove ppp.log if internet is not on*/


		$display_block = "<b>The Internet is now OFF</b>, <br><br>To connect to the Internet please  click Internet On

		<th colspan=2></th>
		</tr>
		</tr>
		</table>
		<p><input type=submit name=\"submit\" value=\"Internet On\"></p>
		";

	}



	/*check for ppp.log*/
	$filename = 'ppp.log';
	/* If Internet is ON show the stats using the following code*/
	if (file_exists($filename)) {

		/*find the download amount in bytes*/
		/*$stat_download=exec("cat /proc/net/dev | grep ppp0 | gawk {'print $2'}");*/
		$downloads_raw=exec("cat /proc/net/dev | grep ppp0");
		$downloads_bytes = substr($downloads_raw,7,10);
		/*find the upload amount in bytes*/
		$stat_upload=exec("cat /proc/net/dev | grep ppp0 | gawk {'print $10'}");
		/*convert the bytes to megabytes*/
		$downloads = ($downloads_bytes/1048576);
		$downloads_format = number_format($downloads, 2, '.', ''). ' MBs';
		$uploads = ($stat_upload/1048576) . ' MBs';
		$uploads_format = number_format($uploads, 2, '.', ''). ' MBs';
		// Example use of getenv()
		$ip = getenv('REMOTE_ADDR');

		

		/*Connection timer code*/
		$timer_time = time();
		$timer_fp = fopen( "ppp.log", "r" );
		$timer_filename ="ppp.log";
		$timer_content = fread( $timer_fp, filesize( $timer_filename ) );
				
		$timer_dif= $timer_time-$timer_content;


		$timer_hms = "";
		$timer_hours = intval(intval($timer_dif) / 3600);
		    $timer_hms .= ($padHours) 
		          ? str_pad($timer_hours, 2, "0", STR_PAD_LEFT). ':'
		          : $timer_hours. ' hours ';
		      
		$timer_minutes = intval(($timer_dif / 60) % 60); 
		    $timer_hms .= str_pad($timer_minutes, 2, "0", STR_PAD_LEFT). ' minutes ';
		$timer_seconds = intval($timer_dif % 60); 
		$timer_hms .= str_pad($timer_seconds, 2, "0", STR_PAD_LEFT) . ' seconds ';
		/*end of Connection timer code*/

		/*get IP addresses*/
		$local_ip_grep  = exec("/sbin/ifconfig | grep -A1 Local | grep addr | gawk {'print $2'}");
		$local_ip = substr($local_ip_grep,5,15);

		$remote_ip_grep  = exec("/sbin/ifconfig | grep -A1 ppp0 | grep addr | gawk {'print $2'}");
		$remote_ip = substr($remote_ip_grep,5,15);
		/*end get IP addresses*/

		/*format the numbers*/
		$avg_download_speed = (($downloads_bytes/$timer_dif)/1024);
		$avg_download_speed_format = number_format($avg_download_speed, 2, '.', ''). ' KB/s';
		$avg_upload_speed = (($stat_upload/$timer_dif)/1024);
		$avg_upload_speed_format = number_format($avg_upload_speed, 2, '.', '') . ' KB/s';
		$internet_is_down = "n/a";
		$download_speed = $internet_is_down;
		$upload_speed = $internet_is_down;
	/*If Internet is OFF shown the stats using the following*/
	} elseif (!file_exists($filename)) {

		/*find the download amount in bytes*/
		/*$stat_download=exec("cat /proc/net/dev | grep ppp0 | gawk {'print $2'}");*/
		$internet_is_down = "n/a";
		$avg_download_speed_format = $internet_is_down;
		$avg_upload_speed_format = $internet_is_down;
		$download_speed = $internet_is_down;
		$upload_speed = $internet_is_down;
		$downloads_format = $internet_is_down;
		$uploads_format = $internet_is_down;
		$local_ip_grep  = exec("/sbin/ifconfig | grep -A1 Local | grep addr | gawk {'print $2'}");
		$local_ip = substr($local_ip_grep,5,15);

		$remote_ip = $internet_is_down;
		$timer_hms = "n/a";
	}

	$display_block .= "
	<div id=\"rightconf\">
	<b>Internet Connection Statistics</b><br><br>
	Current download speed: $download_speed<br>Current upload speed: $upload_speed<br><br>Average download speed: $avg_download_speed_format<br>Average upload speed: $avg_upload_speed_format<br><br>The Internet connection uptime: <br>$timer_hms<br><br>Downloads: $downloads_format  <br>Uploads: $uploads_format <br><br>Remote IP: $remote_ip<br>Local IP: $local_ip <br>
	<th colspan=2></th>
	</tr>
	</tr>
	</table>
	</div>
	"
	;

}

/*If there is no GET data ie. this is the users first page test if connection is up or down and show the required screen*/
else {
	/*test is the connections up and refresh the page every 5 seconds to check*/
	/*$is_ppp_up=exec("cat /proc/net/dev | grep ppp0 | gawk {'print $1'}");*/
	$ppp_check=exec("cat /proc/net/dev | grep ppp0");
	$is_ppp_up=substr($ppp_check,2,4);

	if ($is_ppp_up == 'ppp0')  {

		/*remove connecting.log if internet is on*/
		$filename_connecting = 'connecting.log';

		if (file_exists($filename_connecting)) {
			exec("rm connecting.log");
		} 
		/*end of connecting.log if internet is on*/

		/*create log file if not already exists*/
		$filename = 'ppp.log';
		if (!file_exists($filename)) {
			/*PPP timer section*/
			$time = time();
			echo $time;
			// Open the file and erase the contents if any
			$fp = fopen("ppp.log", "w");

			// Write the data to the file
			fwrite($fp, $time);

			// Close the file
			fclose($fp);
			/*end of PPP timer section*/
		} 


		header( 'refresh: 5; url=index.php' );
		$display_block = "<b>The Internet is now On</b>, <br><br>To disconnect from the Internet please  click Internet Off

		<th colspan=2></th>
		</tr>
		</tr>
		</table>
		<br><input type=submit name=\"submit\" value=\"Internet Off\"></p>
		 ";
	}
	/*test is the connections down and refresh the page every 5 seconds to check*/
	elseif ($is_ppp_ip != 'ppp0')  {
		header( 'refresh: 5; url=index.php' );

		/*remove connecting.log if internet is not on*/
		$filename_connecting = 'connecting.log';

		if (file_exists($filename_connecting)) {
			exec("rm connecting.log");
		} 
		/*end of connecting.log if internet is not on*/

		/*remove ppp.log if internet is not on*/
		$filename = 'ppp.log';

		if (file_exists($filename)) {
			exec("rm ppp.log");
		} 
		/*end of remove ppp.log if internet is not on*/


		$display_block = "<b>The Internet is now OFF</b>, <br><br>To connect to the Internet please  click Internet On
		<th colspan=2></th>
		</tr>
		</tr>
		</table>
		<p><input type=submit name=\"submit\" value=\"Internet On\"></p>
		  ";
	}
}

?>
<html>
<head>
<title> Easy DialUp
</title>
<BODY>
<!-- Show the CSS page based on the users choice in the config.php file -->
<link rel="stylesheet" type="text/css" href="themes/<?php include('./config/config.php'); echo $theme; ?>/style.css">
<div id="top">

</div>

<div id="container">
<div id="skip">
	<p><a href="#content" title="Skip to site content">Skip to content</a></p>
	<p><a href="#search" title="Skip to search" accesskey="s">Skip to search - Accesskey = s</a></p>
</div>
<hr />
	<h1><a href="index.php">Easy DialUp</a></h1>
<!-- CSS stuff, make page look nice -->
<div id="content_bg">
	<!-- Needed for dropshadows -->
	<div class="container_left">
	<div class="container_right">
	<div class="topline">
	<!-- Start float clearing -->
<div id="content">
	
<br>

<FORM ACTION="index.php" METHOD=PUT>

<table align=center>
<tr>
<!-- Show all the PHP stuff -->
<?php echo $display_block; ?>

<BR><BR><BR><BR><BR><BR><BR><BR><BR><br>

</div></div></div></div>

<!-- More CSS stuff -->
	<div id="footer">
	<p> <a href="http://easydialup.sf.net" >Easy DialUp Website</a> </p>
		<div class="extras">
			<ul>
				<li><a href="index.php" title="Easy DialUp Home">Home</a></li>
				<li><a href="index.php?submit=stats" title="Your Internet connection stats.">Connection Stats.</a></li>
				<li><a href="index.php?submit=conf" title="Easy DialUp configuration">Easy DialUp configuration</a></li>

			</ul>
		</div>
	</div>
</div></div>

</FORM>

</BODY>
</HTML>

Return current item: easydialup