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

$ftarget = "/etc/rc.d/rc.inet1.conf";




if ($action==modnet) {

			// Modify net code here :

			$hostname = $_POST['hostname'];
			$slave = $_POST['slave'];
			$sync = $_POST['sync'];
			$dns1 = $_POST['dns1'];
			$dns2 = $_POST['dns2'];

			if ($hostname=="") { exit("No data posted ?"); }

				# 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");
				# And change the real hostname to boot sequence
				exec ("sudo chmod 777 /etc/HOSTNAME");
				exec ("sudo echo $hostname > /etc/HOSTNAME");
				exec ("sudo hostname $hostname");



				// Now the host file bit
				$trans="57";
				$a57 = "${$l.$trans}";
				echo "<center><p>$a57</p></center>";
				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");
					if ($hostname=="master" && $slave!=""){
						fputs($file,"$slave  slave\n");
					}
				fclose($file);
				}
				// Now the DNS bit
				$trans="58";
				$a58 = "${$l.$trans}";
				echo "<center><p>$a58</p></center>";
				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);




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

				#Copy settings to slave
				exec ("sudo scp /etc/resolv.conf hide@address.com:/etc/resolv.conf > /dev/null 2>&1 &");

				#If Full Sync is selected then copy ALL settings to the slave
				if ($sync==TRUE){
					exec ("sudo scp /etc/rc.d/rc.firewall hide@address.com:/etc/rc.d/rc.firewall > /dev/null 2>&1 &");
					exec ("sudo scp /etc/ha.d/haresources hide@address.com:/etc/ha.d/haresources > /dev/null 2>&1 &");
					exec ("sudo scp /etc/ha.d/conf/ldirectord.cf hide@address.com:/etc/ha.d/conf/ldirectord.cf > /dev/null 2>&1 &");
					exec ("sudo scp /usr/local/etc/pound.cfg hide@address.com:/usr/local/etc/pound.cfg > /dev/null 2>&1 &");
					exec ("sudo scp /etc/haproxy/haproxy.cfg hide@address.com:/etc/haproxy/haproxy.cfg > /dev/null 2>&1 &");
					$trans="59";
					$a59 = "${$l.$trans}";
					echo "<center><p>$a59</p></center>";
				}


		}
}

if ($action==modip) {

				$ip = $_POST['ip'];
				$netmask = $_POST['netmask'];
				$gateway = $_POST['gateway'];
				$ip1 = $_POST['ip1'];
				$netmask1 = $_POST['netmask1'];
				$ip2 = $_POST['ip2'];
				$netmask2 = $_POST['netmask2'];
				$ip3 = $_POST['ip3'];
				$netmask3 = $_POST['netmask3'];

				if ($ip=="" && $ip1=="" && $ip2=="" && $ip3=="") { exit("No data posted ?"); }

				# Now calculate the broadcast address

			  	$ipC = ip2long($ip);
			  	$nmC = ip2long($netmask);
			  	$nwC = ($ipC & $nmC);
			  	$bcC = $nwC | (~$nmC);

				$broadcast = long2ip($bcC);

			  	$ipC = ip2long($ip1);
			  	$nmC = ip2long($netmask1);
			  	$nwC = ($ipC & $nmC);
			  	$bcC = $nwC | (~$nmC);

				$broadcast1 = long2ip($bcC);

				$ipC = ip2long($ip2);
			  	$nmC = ip2long($netmask2);
			  	$nwC = ($ipC & $nmC);
			  	$bcC = $nwC | (~$nmC);

				$broadcast2 = long2ip($bcC);

				$ipC = ip2long($ip3);
			  	$nmC = ip2long($netmask3);
			  	$nwC = ($ipC & $nmC);
			  	$bcC = $nwC | (~$nmC);

				$broadcast3 = long2ip($bcC);

				# open a new file

				exec ("sudo chmod 777 $ftarget");
				if ($file=fopen("$ftarget","w")) {
					fputs($file,"#/etc/rc.d/rc.inet1.conf Auto Generated bySCOP\n");
					fputs($file,"IPADDR[0]=\"$ip\"\n");
					fputs($file,"NETMASK[0]=\"$netmask\"\n");
					fputs($file,"IPADDR[1]=\"$ip1\"\n");
					fputs($file,"NETMASK[1]=\"$netmask1\"\n");
					fputs($file,"IPADDR[2]=\"$ip2\"\n");
					fputs($file,"NETMASK[2]=\"$netmask2\"\n");
					fputs($file,"IPADDR[3]=\"$ip3\"\n");
					fputs($file,"NETMASK[3]=\"$netmask3\"\n");
					fputs($file,"GATEWAY=\"$gateway\"\n");

				fclose($file);
				} else {
					draw_no_access("$ftarget");
				}
				$trans="66";
				$a66 = "${$l.$trans}";
				echo "<center><p>$a66</p></center>";

				SCOP_log("Config : Real IP address changed.");


				# Now change the ip address
				exec ("sudo ifconfig eth0 $ip netmask $netmask broadcast $broadcast");
				update_haproxy_stats($ip);
				SCOP_log("Config : eth0 changed.");
				if ( $ip1=="" ) {
						exec ("sudo ifconfig eth1 down");
					} else {
						exec ("sudo ifconfig eth1 $ip1 netmask $netmask1 broadcast $broadcast1");
						SCOP_log("Config : eth1 changed.");
					}
				if ( $ip2=="" ) {
						exec ("sudo ifconfig eth2 down");
					} else {
						exec ("sudo ifconfig eth2 $ip2 netmask $netmask2 broadcast $broadcast2");
						SCOP_log("Config : eth2 changed.");
					}
				if ( $ip3=="" ) {
						exec ("sudo ifconfig eth3 down");
					} else {
						exec ("sudo ifconfig eth3 $ip3 netmask $netmask3 broadcast $broadcast3");
						SCOP_log("Config : eth3 changed.");
					}

				# Add the default gateway last otherwise it wont take effect
				exec ("sudo route delete default");
				exec ("sudo route add default gw $gateway");
				SCOP_log("Config : Default Gateway Changed.");

				// And finally re-start heartbeat because the aliases will have been dropped !
				// Should we re-run the firewall script as well ?
				flush();
				exec ("sudo /etc/rc.d/rc.firewall > /dev/null 2>&1 &");
				exec ("sudo /etc/init.d/heartbeat restart > /dev/null 2>&1 &");
				SCOP_log("Config : Restart Firewall & Heartbeat.");
				}

			# 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;

						$file = @fsockopen($page,80,$errno,$error,$time_limit);
						if ($file) {
							fputs($file, "GET /pickup.php?physip=$ip&source=$source HTTP/1.0\r\n\r\n");
							fclose($file);
						}

		}

 else {  //Draw the form in order to update the settings

	exec ("sudo chmod 777 $ftarget");
	if ($arrtext = file("$ftarget")) {

	} else {
		draw_no_access("$ftarget");
	}

	$tok = strtok(ltrim($arrtext[1]),"=\n\t");
	$tok = strtok("=\n\t");
	$oldip = str_replace("\"", "",$tok);
	$tok = strtok(ltrim($arrtext[2]),"=\n\t");
	$tok = strtok("=\n\t");
	$oldnetmask = str_replace("\"", "",$tok);
	$tok = strtok(ltrim($arrtext[3]),"=\n\t");
	$tok = strtok("=\n\t");
	$oldip1 = str_replace("\"", "",$tok);
	$tok = strtok(ltrim($arrtext[4]),"=\n\t");
	$tok = strtok("=\n\t");
	$oldnetmask1 = str_replace("\"", "",$tok);
	$tok = strtok(ltrim($arrtext[5]),"=\n\t");
	$tok = strtok("=\n\t");
	$oldip2 = str_replace("\"", "",$tok);
	$tok = strtok(ltrim($arrtext[6]),"=\n\t");
	$tok = strtok("=\n\t");
	$oldnetmask2 = str_replace("\"", "",$tok);
	$tok = strtok(ltrim($arrtext[7]),"=\n\t");
	$tok = strtok("=\n\t");
	$oldip3 = str_replace("\"", "",$tok);
	$tok = strtok(ltrim($arrtext[8]),"=\n\t");
	$tok = strtok("=\n\t");
	$oldnetmask3 = str_replace("\"", "",$tok);
	$tok = strtok(ltrim($arrtext[9]),"=\n\t");
	$tok = strtok("=\n\t");
	$oldgateway = str_replace("\"", "",$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;

	// And now the hostname

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

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

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

	// Setup the java script first
			?>
			<script language="javascript" type="text/javascript">
			<!--
			function checkformmodifyipconfig()
			{ // Check the new user fields are correct


				var stringtotest = document.modifyipconfig.ip.value;
				var check = verifyIP(stringtotest);
				if ( !check  ) return check

				var stringtotest2 = document.modifyipconfig.netmask.value;
				var check = verifyIP(stringtotest2);
				if ( !check  ) return check

				var stringtotest3 = document.modifyipconfig.ip1.value;
				var check = verifyIP(stringtotest3);
				if ( !check  ) return check

				var stringtotest4 = document.modifyipconfig.netmask1.value;
				var check = verifyIP(stringtotest4);
				if ( !check  ) return check

				var stringtotest5 = document.modifyipconfig.gateway.value;
				var check = verifyIP(stringtotest5);
				if ( !check  ) return check



				var stringtotest7 = document.modifyipconfig.ip2.value;
				var check = verifyIP(stringtotest7);
				if ( !check  ) return check

				var stringtotest8 = document.modifyipconfig.netmask2.value;
				var check = verifyIP(stringtotest8);
				if ( !check  ) return check

				var stringtotest9 = document.modifyipconfig.ip3.value;
				var check = verifyIP(stringtotest9);
				if ( !check  ) return check

				var stringtotest10 = document.modifyipconfig.netmask3.value;
				var check = verifyIP(stringtotest10);
				if ( !check  ) return check

				return true
			}

			function checkformmodifynetconfig()
			{ // Check the new user fields are correct


				var stringtotest11 = document.modifynetconfig.slave.value;
				var check = verifyIP(stringtotest11);
				if ( !check  ) return check
				var stringtotest12 = document.modifynetconfig.dns1.value;
				var check = verifyIP(stringtotest12);
				if ( !check  ) return check
				var stringtotest13 = document.modifynetconfig.dns2.value;
				var check = verifyIP(stringtotest13);
				if ( !check  ) return check

				return true
			}

			//-->
			</script>
			<?


	//echo "<center><img src=\"../images/enterprise.jpg\"></img></center>";



// Now the second for for network info

if ($action==shownet) {

	//echo "<h2>Physical Network Configuration</h2>";
	$trans="8b";
	$txt = "${$l.$trans}";
	$trans="3";
	$a3 = "${$l.$trans}";
	$trans="70";
	$a70 = "${$l.$trans}";
	$trans="71";
	$a71 = "${$l.$trans}";
	$trans="72";
	$a72 = "${$l.$trans}";
	$trans="73";
	$a73 = "${$l.$trans}";
	//echo "<center><h2>$txt</h2></center>";

?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=editconf&l=<?=$l?>"><?=$a3?></a> &gt; <?=$txt?></h1>
<div class="border">			
<?
	//echo "<i>It is important to have the correct hostname for the master or slave appliance.</br>";
	//echo "Entering the slave appliances ip address enables replication of settings from the master.</i></br></br>";

	//echo "<table align=\"center\">
	?><table border="0" cellspacing="0" align="center" class="form"><td colspan="3" class="sep2"></td><?
	echo "<FORM method=\"post\" action=\"changeip.php?action=modnet&l=$l\" name=\"modifynetconfig\">";
	echo "<tr><th>$a70:</th>";
	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>";
	?><td colspan="3" class="sep1"></td><?
	echo "<tr class=\"altLine\"><th>$a71:</th><td><INPUT type=\"text\" size=16 name=\"slave\" value=\"$slave\"></td></tr>";
	?><td colspan="3" class="sep1"></td><?
	echo "<tr><th>$a72:</th><td><INPUT type=\"checkbox\" name=\"sync\"></td></tr>";
	?><td colspan="3" class="sep1"></td><?
	echo "<tr class=\"altLine\"><th>$a73:</th><td><INPUT type=\"text\" size=16 name=\"dns1\" value=\"$dns1\"></td></tr>";
	?><td colspan="3" class="sep1"></td><?
	//echo "<tr><td><b>Domain Name Server 2:</b></td><td><INPUT type=\"text\" size=16 name=\"dns2\" value=\"$dns2\"></td></tr>";


	?><td colspan="3" class="sep1"></td><?
	echo "</table>";
	echo "</br><p align=\"center\"><INPUT type=\"submit\" value=\"$txt\" name=\"go\" onclick=\"return checkformmodifynetconfig()\"></p> ";
	echo "</FORM>";
?>
</div>
<div class="bottom"><span>-----</span></div>
</div>
<?
	} else {
		if ($action!=modnet) {

			//echo "<h2>Physical Real IP Address Configuration</h2>";
			$trans="8a";
			$txt = "${$l.$trans}";
			$trans="3";
			$a3 = "${$l.$trans}";
			//echo "<center><h2>$txt</h2></center>";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=editconf&l=<?=$l?>"><?=$a3?></a> &gt; <?=$txt?></h1>
<div class="border">			
<?
			
			$trans="64";
			$a64 = "${$l.$trans}";
			$trans="65";
			$a65 = "${$l.$trans}";
			$trans="67";
			$a67 = "${$l.$trans}";
			$trans="68";
			$a68 = "${$l.$trans}";
			$trans="69";
			$a69 = "${$l.$trans}";
			//echo " Are you sure that you want to change the real IP address of this SCOP ?</br>";
			//echo "<i>This is the address that you use to access the server, clients access the VIP(s) only.</i></br>";
			//echo "<i>DR and TUN modes require any one NIC to be configured, NAT can be either one or two NICs</i></br>";
			//echo "<i>NAT with one NIC requires an alias to be set up on that NIC for the second network.</i></br>";

			//echo "</br><table align=\"center\">
			?><table border="0" cellspacing="0" align="center" class="form"><td colspan="4" class="sep2"></td><?
			echo "<FORM method=\"post\" action=\"changeip.php?action=modip&l=$l\" name=\"modifyipconfig\">";
			//echo "<tr><th colspan=\"2\">$a64</th><th colspan=\"2\">$a65</th></tr>";
			echo "<tr><th>$a67 (eth0) :</th><td><INPUT type=\"text\" size=20 name=\"ip\" value=\"$oldip\"></td>";
			echo "<th>$a67 (eth1) :</th><td><INPUT type=\"text\" size=20 name=\"ip1\" value=\"$oldip1\"></td></tr>";
			?><td colspan="4" class="sep1"></td><?
			echo "<tr class=\"altLine\"><th>$a68 :</th><td><INPUT type=\"text\" size=20 name=\"netmask\" value=\"$oldnetmask\">";
			echo "<th>$a68 :</th><td><INPUT type=\"text\" size=20 name=\"netmask1\" value=\"$oldnetmask1\"></td></tr>";
			?><td colspan="4" class="sep1"></td><?
			echo "<tr><th>$a69 :</th><td><INPUT type=\"text\" size=20 name=\"gateway\" value=\"$oldgateway\"></td>";
			echo "<th>$a67 (eth2) :</th><td><INPUT type=\"text\" size=20 name=\"ip2\" value=\"$oldip2\"></td></tr>";
			?><td colspan="4" class="sep1"></td><?
			echo "<tr class=\"altLine\"><td> </td><td> </td>";
			echo "<th>$a68 :</th><td><INPUT type=\"text\" size=20 name=\"netmask2\" value=\"$oldnetmask2\"></td></tr>";
			?><td colspan="4" class="sep1"></td><?
			echo "<tr><td> </td><td> </td>";
			echo "<th>$a67 (eth3) :</th><td><INPUT type=\"text\" size=20 name=\"ip3\" value=\"$oldip3\"></td></tr>";
			?><td colspan="4" class="sep1"></td><?
			echo "<tr class=\"altLine\"><td> </td><td> </td>";
			echo "<th>$a68 :</th><td><INPUT type=\"text\" size=20 name=\"netmask3\" value=\"$oldnetmask3\"></td></tr>";
			?><td colspan="4" class="sep1"></td><?
			echo "</table>";
			echo "</br><p align=\"center\"><INPUT type=\"submit\" value=\"$txt\" name=\"go\" onclick=\"return checkformmodifyipconfig()\"></p></br>";
			echo "</FORM>";
?>
</div>
<div class="bottom"><span>-----</span></div>
</div>
<?
			}
	}

}



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