Location: PHPKode > projects > SCOP Heartbeat Administration interface > scop-2.0/html/scop/config/changenet.php
<?
include ("../inc/header.inc");
include ("../inc/functions.inc");


echo "<h2>Physical Network Configuration</h2>";

if ($action==modnet) {

			#$ipfwd = $_POST['ipfwd'];
			$hostname = $_POST['hostname'];
			$gateway = $_POST['gateway'];
			$gatewaydev = $_POST['gatewaydev'];
			$master = $_POST['master'];
			$slave = $_POST['slave'];
			$dns1 = $_POST['dns1'];
			$dns2 = $_POST['dns2'];

			echo "<p>The network configuration has now been changed.</p>";
			SCOP_log("Config : network settings changed.");

			# open a new file
			exec ("sudo chmod 777 /etc/sysconfig/network");
			if ($file=fopen("/etc/sysconfig/network","w")) {

				fputs($file,"#Auto generated by SCOP.org appliance\n");
				fputs($file,"NETWORKING=yes\n");
				fputs($file,"IPV4_FORWARD=no\n");
				fputs($file,"HOSTNAME=$hostname\n");
				fputs($file,"DOMAINNAME=localdomain\n");
				fputs($file,"GATEWAY=$gateway\n");
				fputs($file,"GATEWAYDEV=$gatewaydev\n");

			fclose($file);

			exec ("sudo route delete default");
			exec ("sudo route add default gw $gateway");
			exec ("sudo hostname $hostname");

			# Update the displayed hostname
			exec ("sudo chmod 777 /var/www/html/scop/inc/hostname.inc");
			exec ("sudo echo $hostname > /var/www/html/scop/inc/hostname.inc");

			# Make sure that SSH now works
			$otherhost = "master";
			if ($hostname == "master") {
				$otherhost = "slave";
			}
			exec ("sudo cp /root/.ssh/$otherhost /root/.ssh/authorized_keys2");

			} else {
				draw_no_access ("/etc/sysconfig/network");
			}

			// Now the host file bit
			echo "<p>The local hosts file has now been changed.</p>";
			SCOP_log("Config : local hosts fille changed.");

			# open a new file
			exec ("sudo chmod 777 /etc/hosts");

			if ($file=fopen("/etc/hosts","w")) {

				fputs($file,"#Auto generated by SCOP.org appliance\n");
				fputs($file,"127.0.0.1  localhost\n");
				fputs($file,"$slave  slave\n");
			fclose($file);
		}
			// Now the DNS bit

			echo "<p>The DNS resolver has now been changed.</p>";
			SCOP_log("Config : DNS settings changed.");
			# open a new file
			exec ("sudo chmod 777 /etc/resolv.conf");
			if ($file=fopen("/etc/resolv.conf","w")) {

				fputs($file,"#Auto generated by SCOP.org appliance\n");
				fputs($file,"search localdomain\n");
				fputs($file,"nameserver $dns1\n");
				fputs($file,"nameserver $dns2\n");

			fclose($file);
			#Copy settings to slave
			flush();
			exec ("sudo scp /etc/resolv.conf hide@address.com:/etc/resolv.conf");

			# Send info back to SCOP.org

			if ($spy=="on") {
					// Now try connecting to Loadbalancer.org
				$time_limit=30;
				set_time_limit($time_limit);
				$page = $updateurl;
				$a=0;


				// Find the ip address

				exec ("sudo chmod 777 /etc/sysconfig/network-scripts/ifcfg-eth0");
				if ($arrtext = file("/etc/sysconfig/network-scripts/ifcfg-eth0")) {

				} else {
					draw_no_access("/etc/sysconfig/network-scripts/ifcfg-eth0");
				}

				$tok = strtok(ltrim($arrtext[2]),"=\n\t");
				$tok = strtok("=\n\t");
				$oldip = $tok;
				$tok = strtok(ltrim($arrtext[3]),"=\n\t");
				$tok = strtok("=\n\t");
				$oldnetmask = $tok;
				$tok = strtok(ltrim($arrtext[4]),"=\n\t");
				$tok = strtok("=\n\t");
				$oldbroadcast = $tok;


				$file = fsockopen($page,80,$errno,$error,$time_limit);
				if ($file) {
					fputs($file, "GET /pickup.php?physip=$oldip&source=$source HTTP/1.0\r\n\r\n");
					//while(!feof($file))
					//{
					//$a=$a+1;
					//$buffer[] = fgets($file,1000);
					//}
					fclose($file);
				}
				else {
					# Don't show the error for now
					# draw_error ("Error: Could not access online update " . $errno . " " . $error );
				}
				}


				} else {
					draw_no_access ("/etc/resolv.conf");
				}

} else {

	exec ("sudo chmod 777 /etc/sysconfig/network");
	if ($arrtext = file("/etc/sysconfig/network")) {

	} else {
		draw_no_access ("/etc/sysconfig/network");
	}



	#$tok = strtok(ltrim($arrtext[2]),"=\n\t");

	#$tok = strtok("=\n\t");

	#$ipfwd = $tok;

	$tok = strtok(ltrim($arrtext[3]),"=\n\t");

	$tok = strtok("=\n\t");

	$hostname = $tok;
	$tok = strtok(ltrim($arrtext[5]),"=\n\t");

	$tok = strtok("=\n\t");

	$gateway = $tok;

	$tok = strtok(ltrim($arrtext[6]),"=\n\t");

	$tok = strtok("=\n\t");

	$gatewaydev = $tok;

	// NOW the DNS bit

	exec ("sudo chmod 777 /etc/resolv.conf");
	if ($arrtext = file("/etc/resolv.conf")) {

	} else {
		draw_no_access("/etc/resolv.conf");
	}

	$tok = strtok(ltrim($arrtext[2])," \n\t");
	$tok = strtok(" \n\t");
	$dns1 = $tok;
	$tok = strtok(ltrim($arrtext[3])," \n\t");
	$tok = strtok(" \n\t");
	$dns2 = $tok;

	// And now the hosts file :

	exec ("sudo chmod 777 /etc/hosts");
	if ($arrtext = file("/etc/hosts")) {

	} else {
		draw_no_access ("/etc/hosts");
	}


	$tok = strtok(ltrim($arrtext[2])," \n\t");
	$slave = $tok;


	// Setup the java script first
			?>
			<script language="javascript" type="text/javascript">
			<!--
			function checkformmodifynetconfig()
			{ // Check the new user fields are correct
				var gate = document.modifynetconfig.gateway.value;
				if (gate =="" )
				{
					alert  ("Please specify a default gateway ip address");
					document.modifynetconfig.gateway.select();
					return false
				}

				var stringtotest = document.modifynetconfig.gateway.value;

				if ( stringtotest.length < 8)
				{
					alert  ("ERROR: The default gateway must be a valid ip address ");
					document.modifynetconfig.gateway.select();
					return false

				}

				var stringtotest2 = document.modifynetconfig.slave.value;

				if ( stringtotest2.length < 8)
				{
					alert  ("WARNING: The location of the slave SCOP should be a valid ip address ");
					document.modifynetconfig.slave.select();
					return true

				}

				return true
			}
			//-->
			</script>
			<?


	echo "<table><FORM method=\"post\" name =\"modifynetconfig\" action=\"changenet.php?action=modnet\" >";
	#echo "<tr><td><b>Hostname :</b></td><td><INPUT type=\"text\" size=20 name=\"hostname\" value=\"$hostname\"></td></tr>";

		echo "<tr><td><b>Hostname :</b></td>";
		echo "<td><select name=\"hostname\">";
		echo "<OPTION VALUE=\"master\" ";
		if ($hostname=="master") { echo "selected=\"true\""; }
		echo ">master";
		echo "<OPTION VALUE=\"slave\" ";
		if ($hostname=="slave") { echo "selected=\"true\""; }
		echo ">slave";
		echo "</select></td></tr>";

	echo "</select></td></tr>";

	echo "</select></td></tr>";
	echo "<tr><td><b>Slave SCOP :</b></td><td><INPUT type=\"text\" size=16 name=\"slave\" value=\"$slave\"></td></tr>";

	echo "<INPUT type=\"HIDDEN\" size=20 name=\"master\" value=\"$master\">";
	echo "<tr><td><b>Domain Name Server 1 :</b></td><td><INPUT type=\"text\" size=16 name=\"dns1\" value=\"$dns1\"></td></tr>";
	echo "<tr><td><b>Domain Name Server 2 :</b></td><td><INPUT type=\"text\" size=16 name=\"dns2\" value=\"$dns2\"></td></tr>";
	echo "<tr><td><INPUT type=\"submit\" value=\"Change network config\" name=\"go\" onclick=\"return checkformmodifynetconfig()\"></td></tr>";
	echo "</FORM></table>";


}


include ("../inc/footer.inc");
?>
Return current item: SCOP Heartbeat Administration interface