Location: PHPKode > projects > SCOP Heartbeat Administration interface > scop-2.0/html/scop/config/pound.php
<?
// SCOP administration software.
//  Copyright (C) 2002  Loadbalancer.org Limited

//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.

//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.

//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

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


?>

<?



SLLparse_config_file();
global $SLLvnum,$SLLrnum,$v,$r,$action,$subaction,$SLLDELETEVIRTUAL,$SLLVIRTUAL,$SLLVIRTUAL_LABEL,$SLLREAL,$SLLREAL_LABEL,$SLLVIRTUAL_COOKIE,$SLLREAL_WEIGHT;

$SLLDELETEVIRTUAL=NULL;
$trans="108";
 $t108 = "${$l.$trans}";




# Now the modify Virtual Server Section....
	if ($action=="modvirtual") {

		if ($subaction=="remove") {
			$SLLWRITEFILE=TRUE;
			$SLLDELETEVIRTUAL=$v;
			SCOP_log("Config : SLLVirtual Server removed.");
		}

		if ($subaction=="add") {

			$trans="7aa";
			$a7aa = "${$l.$trans}";
			$trans="3";
			$a3 = "${$l.$trans}";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=editconf&l=<?=$l?>"><?=$a3?></a> &gt; <? echo"$a7aa $t108"; ?></h1>
<div class="border">
<?

			// Need some Javascript
			echo "<script language=\"javascript\" type=\"text/javascript\"> \n ";
			echo "<!-- \n";
			?>

			function checkformaddvirt()
			{ // Check the new user fields are correct
				var virt = document.addvirt.virt.value;

				if (  isNaN(virt) && virt.length<4)
				{
					alert  ("VIP is not a valid IPAddress:Port or Firewall Mark");
					document.modifyrealserver.newweight.select();
					return false
				}

				var stringtotest = document.addvirt.virt.value;
				var testresult = -1;
				var testresult = -1;
				testresult = stringtotest.indexOf(':',0);
				testresult2 = stringtotest.indexOf('IPAddress',0);
				if (testresult == -1 || testresult2 != -1 || stringtotest.length < 10)
				{
					alert  ("VIP is not a valid IPAddress:Port or Firewall Mark");
					document.addvirt.virt.select();
					return false

				}

				if (  virt.length>4)
				{
					var ipbit = Left (stringtotest,testresult);
					var check = verifyIP(ipbit);
						if ( !check  ) return check

					var rightbit =(String(stringtotest).length - testresult) -1;
					var portbit = Right (stringtotest,rightbit);
					if (  isNaN(portbit) || portbit.length<1 )
					{
						alert ("Please enter a valid IPAddress:Port i.e. 10.0.0.20:80");
						document.addvirt.virt.select();
						return false
					}
				}

			return true
			}

			<?
			echo "function updateportno() \n";
			echo "{ \n";
			echo " var text = document.addvirt.portno.value; \n";
			echo " alert(text); \n";
			echo "} \n";
			echo "//-->";
			echo "</script>";

			// Now draw the form
			//echo "<h2>$anvs Add A New Virtual Server</h2>";

			//echo "A virtual server only responds to one service i.e. HTTP (port 80) or HTTPS (port 443)..</br>";
			//echo "Please specify the IP address and service in the following format :</br>";
			//echo " IPAddress:Port i.e. 10.0.0.20:80 </br>";
			//echo "NB. Dont forget to add the physical IP Address relating to the Virtual one...</br> </br>";
			$trans="21";
			$label = "${$l.$trans}";
			$trans="22";
			$persistent = "${$l.$trans}";
			$trans="24";
			$a24 = "${$l.$trans}";
			echo "<FORM method=\"post\" action=\"pound.php?action=modvirtual&subaction=adddata&t=$t\" name=\"addvirt\">";
			?><table border="0" cellspacing="0" align="center" class="form"><td colspan="3" class="sep2"></td><?
			echo "<tr class=\"altLine\"><th>$a24 </th><td> <INPUT type=\"text\" size=20 name=\"virt\" value=\"10.0.0.20:443\"></td>";

			?><td colspan="3" class="sep1"><?

			echo "<tr><th>Backend </th><td> <INPUT type=\"text\" size=20 name=\"label\" value=\"10.0.0.20:80\"></td></tr>";
			?><td colspan="3" class="sep1"><?
			// echo "<td>";
			// draw_portlist();
			//echo "</td>";
			echo "</tr>";

			
			echo "<input type=\"HIDDEN\" name=\"addphys\" value=\"yes\" >";
			echo "</table>";
			echo "<center><INPUT type=\"submit\" value=\"$a7aa\" name=\"go\" onclick=\"return checkformaddvirt()\" ></center>";


			echo "</FORM>";
?></div>
<div class="bottom"><span>-----</span></div>
</div>
<?
		}
		if ($subaction=="adddata") {

			$virt = $_POST['virt'];
			$persist = $_POST['persist'];
			$label = $_POST['label'];
			$addphys = $_POST['addphys'];
			$portno = $_POST['portno'];

			$label = str_replace(" ","_",$label);

			# Check for valid virt:port or fwmark
			$exists = VIP_Exists($virt);
			#$vipcount = count($VIRTUAL);
			if (!$exists) {
				If ( strstr($virt,":") OR strlen($virt)<=4 ) {
					$SLLWRITEFILE=TRUE;
					//echo "<p>The virtual server has now been added.</p>";
					SCOP_log("Config : Virtual server $label added.");

					$SLLvnum++;
					$SLLrnum=0;
					$SLLVIRTUAL[$SLLvnum]=$virt;
					$SLLVIRTUAL_LABEL[$SLLvnum]=$label;

					if ($persist=="yes" ) {
						$SLLVIRTUAL_COOKIE[$SLLvnum]="SERVERID insert indirect";
					}
					//Copy a valid SSL.pem file across
					exec ("sudo cp /usr/local/etc/server.pem /usr/local/etc/server$SLLvnum.pem");
					//And copy that to the slave
					exec ("sudo scp /usr/local/etc/server$SLLvnum.pem hide@address.com:/usr/local/etc/server$SLLvnum.pem > /dev/null 2>&1 &");
					// Now check if we need to add the physical VIP to haresources
					
					if ($demo=="FALSE") {
						$ip = Get_ip($virt);
						if ($addphys=="yes" && strlen($virt)>4) {
										add_physical_vip($ip);

						}
					}
				}
				else {
					draw_error ("ERROR : The virtual server didn't contain a port number.  Are you sure that is correct?");
				}
			} else {
				draw_error ("ERROR: $virt</b> <i>is a duplicate entry</i>");
			}

		}

		if ($subaction=="edit") {


					// Need some Javascript
					echo "<script language=\"javascript\" type=\"text/javascript\"> \n ";
					echo "<!-- \n";
					?>

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


							if (  isNaN(document.editvirt.persisttime.value) || document.editvirt.persisttime.value==0 )
							{
								alert ("Persistence time should be an integer >0.");
								document.editvirt.persisttime.select();
								return false
							}
							if (  isNaN(document.editvirt.checkport.value) )
							{
								alert ("Checkport should be an integer.");
								document.editvirt.checkport.select();
								return false
							}

								var fall = document.editvirt.fall.value;
								var stringtotest = fall;
								var testresult = -1;
								var testresult = -1;
								testresult = stringtotest.indexOf(':',0);
								testresult2 = stringtotest.indexOf('IPAddress',0);
								if (testresult == -1 || testresult2 != -1 || stringtotest.length < 10)
								{

									alert  ("Fallback is not a valid IPAddress:Port");
									document.editvirt.fall.select();
									return false

								}

								if (  fall.length>4)
								{

									var ipbit = Left (stringtotest,testresult);
									var check = verifyIP(ipbit);
										if ( !check  ) return check

									var rightbit =(String(stringtotest).length - testresult) -1;
									var portbit = Right (stringtotest,rightbit);
									if (  isNaN(portbit) || portbit.length<1 )
									{
										alert ("Please enter a valid Fallback IPAddress:Port i.e. 127.0.0.1:80");
										document.editvirt.fall.select();
										return false
									}
								}


						var virt = document.editvirt.virt.value;


								if (  isNaN(virt) && virt.length<4)
								{

									alert  ("VIP is not a valid IPAddress:Port or Firewall Mark");
									document.editvirt.virt.select();
									return false
								}
								if (  !isNaN(virt) && virt.length<4)
								{
									//Firewall mark so return true
									return true
								}


								var stringtotest = virt;
								var testresult = -1;
								var testresult = -1;
								testresult = stringtotest.indexOf(':',0);
								testresult2 = stringtotest.indexOf('IPAddress',0);
								if (testresult == -1 || testresult2 != -1 || stringtotest.length < 10)
								{

									alert  ("VIP is not a valid IPAddress:Port or Firewall Mark");
									document.editvirt.virt.select();
									return false

								}

								if (  virt.length>4)
								{

									var ipbit = Left (stringtotest,testresult);
									var check = verifyIP(ipbit);
										if ( !check  ) return check

									var rightbit =(String(stringtotest).length - testresult) -1;
									var portbit = Right (stringtotest,rightbit);
									if (  isNaN(portbit) || portbit.length<1 )
									{
										alert ("Please enter a valid IPAddress:Port i.e. 10.0.0.20:80");
										document.editvirt.virt.select();
										return false
									}
								}


					return true
					}

					<?
					echo "function updateportno() \n";
					echo "{ \n";
					echo " var text = document.addvirt.portno.value; \n";
					echo " alert(text); \n";
					echo "} \n";
					echo "//-->";
			echo "</script>";

			$per=0;
			//echo "<h2>Edit Virtual Server $v Configuration</h2>";
			$trans="7a";
			$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; <? echo"$txt $t108"; ?></h1>
<div class="border">
<?

echo "<FORM method=\"post\" name=\"editvirt\" action=\"pound.php?action=modvirtual&subaction=editdata&v=$v&t=$t\">";
			?><table border="0" cellspacing="0" align="center" class="form">
				<tr><td colspan="3" class="sep2"></td></tr>	<?

			$trans="21";
			$a21 = "${$l.$trans}";
			$trans="24";
			$a24 = "${$l.$trans}";
			$trans="22";
			$a22 = "${$l.$trans}";
			$trans="25";
			$a25 = "${$l.$trans}";
			$trans="26";
			$a26 = "${$l.$trans}";
			$trans="27";
			$a27 = "${$l.$trans}";
			$trans="28";
			$a28 = "${$l.$trans}";
			$trans="29";
			$a29 = "${$l.$trans}";
			$trans="30";
			$a30 = "${$l.$trans}";
			$trans="31";
			$a31 = "${$l.$trans}";
			$trans="32";
			$a32 = "${$l.$trans}";
			$trans="33";
			$a33 = "${$l.$trans}";
			$trans="34";
			$a34 = "${$l.$trans}";
			$trans="35";
			$a35 = "${$l.$trans}";
			$trans="36";
			$a36 = "${$l.$trans}";
			$trans="37";
			$a37 = "${$l.$trans}";
			$trans="38";
			$a38 = "${$l.$trans}";
			$trans="38b";
			$a38b = "${$l.$trans}";


			echo "<tr class=\"altLine\"><th>$a24</th><td> <INPUT type=\"text\" size=20 name=\"virt\" value=\"$SLLVIRTUAL[$v]\"></td><td> ";

			#helpitem("5-1-1");
			echo "</td></tr>";
			?><tr><td colspan="3" class="sep1"></td></tr><?
			echo "<tr><th>Backend</th><td> <INPUT type=\"text\" size=20 name=\"label\" value=\"$SLLVIRTUAL_LABEL[$v]\"></td><td>";
			// draw_portlist();
			#helpitem("5-1-2");

			?><tr><td colspan="3" class="sep1"></td></tr><?
			echo "</table><center><INPUT type=\"submit\" value=\"$txt\" name=\"go\" onclick=\"return checkformeditvirt()\" ></center>";
			echo "</FORM>";



?>
	<br />
	<form enctype="multipart/form-data" action="recieve_pem.php" method="post">
	 <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
	 <center><input name="userfile" type="file" /> 
	 <input type="hidden" name="name" value="server<?=$v?>.pem" /></br>
	 <input type="submit" value="Upload PEM file" /></center>
	</form>
	<br />
<?
	$trans="120";
	$a120 = "${$l.$trans}";
	echo "<center>[ <a href=\"manage_ssl.php?server=$v&t=$t\" class=\"action\"><b>$a120</b></a> ]</center> ";
?>
</div>
<div class="bottom"><span>-----</span></div>
</div>
<br />
<?
		}
		if ($subaction=="editdata") {
			$label = $_POST['label'];
			$virt = $_POST['virt'];
			$persist = $_POST['persist'];
			$persisttime = $_POST['persisttime'];
			$label = str_replace(" ","_",$label);
			$thevirtport = Get_port($virt);
			$thefallport = Get_port($fall);
			$thevirtip = Get_ip($virt);





				$SLLWRITEFILE=TRUE;

				SCOP_log("Config : Virtual server $label modified.");
				//If a VIP has been modified need to check haresources to see if we need to add it.

				add_physical_vip($thevirtip);



			$SLLVIRTUAL[$v]=$virt;
			$SLLVIRTUAL_LABEL[$v]=$label;

			if ($persist=="yes") {
				$SLLVIRTUAL_COOKIE[$v]="SERVERID insert inderect";

			} else {
				$SLLVIRTUAL_COOKIE[$v]="";
			}


		}

		//echo "<h2>Modify Virtual Servers</h2>";
		$trans="7a";
		$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; <? echo"$txt $t108"; ?></h1>
<div class="border">
<?

		$trans="7b";
		$mlrs = "${$l.$trans}";
		$trans="7aa";
		$anvs = "${$l.$trans}";
					$trans="19";
					$mod = "${$l.$trans}";
					$trans="20";
			$del = "${$l.$trans}";


		?><table border="0" class="datagrid" align="center">
			<tr><td colspan="3" style="text-align:left;">
		<?
		echo "[ <a href=\"pound.php?action=modvirtual&subaction=add&t=$t\" class=\"action\">$anvs</a> ] ";
		#echo "[ <a href=\"pound.php?action=modreal&t=$t\" class=\"action\">$mlrs</a> ]</td></tr>";

		for ( $i=1; $i<=count($SLLVIRTUAL); $i++) {
			if ($SLLDELETEVIRTUAL<>$i) {
				echo "<tr><td>VIP<b>$i</b></td><td><b>$SLLVIRTUAL[$i]</td><td> -> </td><td>$SLLVIRTUAL_LABEL[$i] </b></td>";
				echo "<td style=\"text-align:right\">[ <a href=\"pound.php?action=modvirtual&subaction=edit&v=$i&t=$t\" class=\"action\"> $mod </a> ]</td> ";

				echo "<td style=\"text-align:right\">[ <a href=\"pound.php?action=modvirtual&subaction=remove&v=$i&t=$t\" class=\"action\" onclick=\"return areyousure('Are you sure you want to remove the virtual server ? ($SLLVIRTUAL[$i])')\"> $del </a> ]</td></tr>";
			?><tr><td colspan="4" class="sep1"></td></tr><?
			} //End of check for deleted virtual

		}
		echo "</table>";

?>
</div>
<div class="bottom"><span>-----</span></div>
</div>
<?

} //end of ifaction=modvirtual







	
if ($SLLWRITEFILE==TRUE){
SLLwrite_config_file();
}

				 
				








?>



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