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


echo "<h2>Alias configuration</h2>";

if ($action==modip) {

			$ip = $_POST['ip'];
			$netmask = $_POST['netmask'];
			$broadcast = $_POST['broadcast'];
			$alias = $_POST['alias'];
			$iface = $_POST['iface'];
			if ($iface="") {
				$iface = $_GET['iface'];
			}

		
			echo "<p>The alias for <i>$iface</i> has now been changed.</p>";
			SCOP_log("Config : alias for $iface changed.");

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

				fputs($file,"DEVICE=$iface:$alias\n");
				fputs($file,"BOOTPROTO=static\n");
				fputs($file,"IPADDR=$ip\n");
				fputs($file,"NETMASK=$netmask\n");
				#fputs($file,"NETWORK=10.0.0.0\n");
				fputs($file,"BROADCAST=$broadcast\n");
				fputs($file,"ONBOOT=yes\n");

			fclose($file);
			} else {
				draw_no_access("/etc/sysconfig/network-scripts/ifcfg-$iface:$alias");
			}
		exec ("sudo ifconfig $iface:$alias $ip netmask $netmask broadcast $broadcast up");
		echo ("sudo ifconfig $iface:$alias $ip netmask $netmask broadcast $broadcast up");
} else {

	
	echo "An alias is an extra ip address on a single network card, this has many uses including allowing</br>";
	echo "NAT load balancing across two networks with only network card. </br>";	
		
// 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;
				
				if ( stringtotest.length < 10)
				{
					alert  ("ERROR: Not a valid ip address ");
					document.modifyipconfig.gateway.select();
					return false

				}
				
				var stringtotest2 = document.modifyipconfig.netmask.value;
				
				if ( stringtotest2.length < 10)
				{
					alert  ("ERROR: The netmask should be a valid ip address ");
					document.modifyipconfig.netmask.select();
					return false

				}
				
				var stringtotest3 = document.modifyipconfig.broadcast.value;
				
				if ( stringtotest3.length < 10)
				{
					alert  ("ERROR: The lbroadcast network should be a valid ip address ");
					document.modifyipconfig.broadcast.select();
					return false

				}
				
				

				return true
			}
			//-->
			</script>
			<?
	
	
	
	echo "<h2>Configure <i>$iface</i> network alias.</h2>";
	echo "<table><FORM method=\"post\" action=\"changeipalias.php?action=modip\" name=\"modifyipconfig\">";
	echo "<tr><td><b>Alias :</b></td><td><INPUT type=\"text\" size=20 name=\"alias\" value=\"$alias\"></td></tr>";
	echo "<tr><td><b>IP Address :</b></td><td><INPUT type=\"text\" size=20 name=\"ip\" value=\"$oldip\"></td></tr>";
	echo "<tr><td><b>Netmask :</b></td><td><INPUT type=\"text\" size=20 name=\"netmask\" value=\"$oldnetmask\"></td></tr>";
	echo "<tr><td><b>Broadcast :</b></td><td><INPUT type=\"text\" size=20 name=\"broadcast\" value=\"$oldbroadcast\"></td></tr>";
	echo "<tr><td><INPUT type=\"hidden\" value=\"$iface\" name=\"iface\" ></td></tr>";
	echo "<tr><td><INPUT type=\"submit\" value=\"Update alias\" name=\"go\" onclick=\"return checkformmodifyipconfig()\">";
	
	echo "</FORM></table>";

}


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