Location: PHPKode > projects > SCOP Heartbeat Administration interface > scop-2.0/html/scop/config/changevips.php
<?

include ("../inc/header.inc");
include ("../inc/functions.inc");

$newvip = $_POST['newvip'];
$id = $_GET['id'];
# This code opens a file, reads it into an array and then writes it back to a file.


exec ("sudo chmod 777 /etc/ha.d/haresources");
if ($arrtext = file("/etc/ha.d/haresources")) {

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

}

$i=0;
$tok = strtok(ltrim($arrtext[1])," \n\t");
while ($tok && $tok!="haproxy") {

	$VIPS[$i] = $tok;
	$tok = strtok(" \n\t");
	$i++;
}

if ($action=="remove") {
	if ($id==count($VIPS)-1) {
				array_splice ($VIPS, $id) ;
			}
			else {
				$a = count($VIPS)-$id-1;
				array_splice ($VIPS, $id, -$a) ;
			}
	$WRITEFILE=TRUE;

}

$trans="62";
$a62 = "${$l.$trans}";
$trans="20";
$a20 = "${$l.$trans}";
$trans="63";
$a63 = "${$l.$trans}";
$trans="3";
$a3 = "${$l.$trans}";
//echo "<center><h2>$a62</h2></center>";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=editconf&l=<?=$l?>"><?=$a3?></a> &gt; <?=$a62?></h1>
<div class="border">			
<?
//echo "These Virtual IP addresses are shared by the master & slave SCOPs, normally only the master will be active.";
//echo "</br>NB. You must <a href=\"restart.php?service=heartbeat&t=$t\" onclick=\"return areyousure('Are you sure you want to restart heartbeat?')\">restart the heartbeat service</a> to activate a new VIP.</br></br>";

echo "<table align=\"center\" class=\"datagrid\">";
	?><td colspan="3" class="sep2"></td><?
//echo "<tr><th>VIP</th></tr>";

for ( $i=1; $i<count($VIPS)-1; $i++) {
	echo "<tr><td><b>$VIPS[$i]</b></td><td>[ <a href=\"?action=remove&id=$i&t=$t\" class=\"action\" onclick=\"return areyousure('Are you sure you want to remove the physical virtual ip? ($VIPS[$i])')\">$a20</a> ]</td></tr>";
	?><td colspan="3" class="sep1"></td><?

}
if ($action=="new" and $newvip<>"") {
	echo "<tr><td><b>$newvip</b></td><td>[ <a href=\"?action=remove&id=$i&t=$t\" class=\"action\" onclick=\"return areyousure('Are you sure you want to remove the physical virtual ip? ($newvip)')\">$a20</a> ]</td></tr>";
	?><td colspan="3" class="sep1"></td><?
	$WRITEFILE=TRUE;
}
echo "</table>";
?>
</div>
<div class="bottom"><span>-----</span></div>
</div>
<br />
<?

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


				var stringtotest = document.changevip.newvip.value;
				var check = verifyIP(stringtotest);
				if ( !check  ) return check

				return true
			}

			//-->
			</script>
			<?

//echo "<center><h2>$a63</h2></center>";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=editconf&l=<?=$l?>"><?=$a3?></a> &gt; <?=$a63?></h1>
<div class="border">			
<?
echo "<FORM method=\"post\" name=\"changevip\" action=\"?action=new&t=$t\">";
echo "<table align=\"center\" class=\"form\">";
	?><td colspan="3" class="sep2"></td><?
echo "<tr><td><INPUT type=\"text\" size=20 name=\"newvip\" value=\"10.0.0.35\"></td></tr>";
	?><td colspan="3" class="sep1"></td><?
echo "</table>";
echo "<center><INPUT type=\"submit\" value=\"$a63\" name=\"go\" onclick=\"return checkform()\"></center>";
echo "</FORM>";
?>
</div>
<div class="bottom"><span>-----</span></div>
</div>
<?


if ($WRITEFILE==TRUE) {

		if ($file=fopen("/etc/ha.d/haresources","w")) {
			fputs($file, "# File auto-generated by Loadbalancer.org\n");
			fputs($file, $VIPS[0] . " ");
			for ( $i=1; $i<count($VIPS)-1; $i++) {
				fputs($file, $VIPS[$i] . " ");
			}
			if ($action=="new") {
				fputs($file, $newvip . " ");
			}
			fputs ($file, "ldirectord haproxy pound\n");
		}
		fclose($file);
		#Copy settings to slave
			flush();
			exec ("sudo scp /etc/ha.d/haresources hide@address.com:/etc/ha.d/haresources > /dev/null 2>&1 &");
		#Now force the activiation
			#This only works if you have a clustered pair communicating
			exec ("sudo /usr/lib/heartbeat/hb_takeover local > /dev/null 2>&1 &");
			


}


include ("../inc/footer.inc");

?>
Return current item: SCOP Heartbeat Administration interface