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

<?

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

$action = $_GET['action'];
$server = $_GET['server'];


if ($action=="remove") {
	`sudo rm/etc/rc.d/rc.firewall`;
}
$path = "/usr/local/etc/";
$filepath= "$path" . "server$server" . "_csr.pem";
$filepath2= "$path" . "server$server" . "_key_signed.pem";
$filepath3= "$path" . "server$server" . ".pem";
$filepath4= "$path" . "server" . ".pem";

if ($action=="remove") {
	`sudo rm $filepath`;
	`sudo rm $filepath2`;
	`sudo cp $filepath4 $filepath3`;
}

$CSRCREATED="FALSE";
if (file_exists($filepath)) {
	$CSRCREATED="TRUE";
}

$SIGNEDCREATED="FALSE";
if (file_exists($filepath2)) {
	$SIGNEDCREATED="TRUE";
}
if ($action!="editdata" && $action!="editsigned" && $CSRCREATED=="FALSE" && $SIGNEDCREATED=="FALSE") {
	
					// Setup the java script first
					?>
					<script language="javascript" type="text/javascript">
					<!--
					function checkformmodglobal()
					{ // Check the new user fields are correct



						return true
					}
					//-->
					</script>
			<?
			$per=0;
			//echo "<h2>Edit Global Settings</h2>";
			$trans="120";
			$a120 = "${$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; <?=$a120?></h1>
<div class="border">
<?

			$trans="7c";
			$a7c = "${$l.$trans}";
			$trans="113";
			$a113 = "${$l.$trans}";
			$trans="114";
			$a114 = "${$l.$trans}";
			$trans="115";
			$a115 = "${$l.$trans}";
			$trans="116";
			$a116 = "${$l.$trans}";
			$trans="117";
			$a117 = "${$l.$trans}";
			$trans="118";
			$a118 = "${$l.$trans}";
			$trans="119";
			$a119 = "${$l.$trans}";
			//echo "You can edit the frequency of the real server health checks here :</br>";
			//echo "Don't set it too small ! <i>(checkinterval=10, checktimeout=5 is fine for most situations)</i></br>";
			//echo "NB. If you require persistent virtual servers Quiescent=no should be used.</br></br>";
			echo "<FORM method=\"post\" name=\"modglobal\" action=\"manage_ssl.php?action=editdata&t=$t\">";
			?><table border="0" cellspacing="0" align="center" class="form"><td colspan="3" class="sep2"></td><?


			echo "<tr><td>$a113 </td><td> <INPUT type=\"text\" size=2 name=\"C\" value=\"US\"></td><td>";
			helpitem(6);
			echo "</td></tr>";
?><td colspan="3" class="sep1"></td><?
			echo "<tr class=\"altLine\"><td>$a114 </td><td> <INPUT type=\"text\" size=19 name=\"ST\" value=\"Delaware\"></td><td>";
			helpitem(6);
			echo "</td></tr>";
?><td colspan="3" class="sep1"></td><?
			echo "<tr><td>$a115 </td><td> <INPUT type=\"text\" size=19 name=\"L\" value=\"Wilmington\"></td><td>";
			helpitem(6);
			echo "</td></tr>";
?><td colspan="3" class="sep1"></td><?
			echo "<tr class=\"altLine\"><td>$a116 </td><td> <INPUT type=\"text\" size=19 name=\"O\" value=\"Loadbalancer.org, Inc.\"></td><td>";
			helpitem(6);
			echo "</td></tr>";
?><td colspan="3" class="sep1"></td><?
			echo "<tr><td>$a117 </td><td> <INPUT type=\"text\" size=19 name=\"OU\" value=\"Support\"></td><td>";
			helpitem(6);
			echo "</td></tr>";
?><td colspan="3" class="sep1"></td><?
			echo "<tr class=\"altLine\"><td>$a118 </td><td> <INPUT type=\"text\" size=19 name=\"CN\" value=\"www.SCOP.org\"></td><td>";
			helpitem(6);
			echo "</td></tr>";
?><td colspan="3" class="sep1"></td><?
			echo "<tr><td>$a119 </td><td> <INPUT type=\"text\" size=19 name=\"email\" value=\"hide@address.com\"></td><td>";
			helpitem(6);
			echo "</td></tr>";
?><td colspan="3" class="sep1"></td><?
			echo "<INPUT type=\"hidden\" name=\"server\" value=\"$server\">";
			echo "</table> </br><center><INPUT type=\"submit\" value=\"$a120 (Server$server)\" name=\"go\" onclick=\"return checkformmodglobal()\"></center>";
?><td colspan="3" class="sep1"></td><?
echo "</FORM>";
?>
</div>
<div class="bottom"><span>-----</span></div>
</div>
<?
}



if ($action=="editdata") {
	$C = $_POST['C'];
	$ST = $_POST['ST'];
	$L = $_POST['L'];
	$O = $_POST['O'];
	$OU = $_POST['OU'];
	$CN = $_POST['CN'];
	$email = $_POST['email'];
	$server = $_POST['server'];

	
	# Echo CSR generated
	#$trans="56";
	#$a56 = "${$l.$trans}";
	#echo "<center><p>$a56</p></center>";
#openssl req -new -md5 -newkey rsa:1024 -passout pass:apple -keyout p_myhost_key.pem -out myhost_csr.pem -subj "/C=GB/ST=SURREY/L=PORTSMOUTH/#O=LOADBALANCER/OU=HQ/CN=www.SCOP.org/emailAddress=hide@address.com" -batchGenerating a 1024 bit RSA private key

$subj = "/C=$C/ST=$ST/L=$L/O=$O/OU=$OU/CN=$CN/emailAddress=$email";
$path = "/usr/local/etc/";
$command = "sudo openssl req -new -md5 -newkey rsa:1024 -passout pass:apple -keyout $path" . "server$server" . "_key.pem -out $path" . "server$server" . "_csr.pem -subj \"$subj\" ";
exec ($command);

	#$filepath= "$path" . "server$server" . "_csr.pem";
	#if ($file=fopen("$filepath","r")) {
	#	while (!feof ($file)) {
	#		$result = $result . fgets($file);
	#	}
	#		fclose($file);

	#} else {
  	#	draw_no_access ("$filepath");
	#}



#Remove the password from the key Now
$command = "sudo openssl rsa -in " . "$path" . "server$server" . "_key.pem" . " -out " . "$path" . "server$server" . "_key_nopass.pem" . " -passin pass:apple";
exec ($command);


$CSRCREATED="TRUE";

} //end of editdata


if ($CSRCREATED=="TRUE" && $SIGNEDCREATED=="FALSE") {
	if ($server=="") {$_GET['server'];}
	$filepath= "$path" . "server$server" . "_csr.pem";
	if ($file=fopen("$filepath","r")) {
		while (!feof ($file)) {
			$result = $result . fgets($file);
		}
			fclose($file);

	} else {
  		draw_no_access ("$filepath");
	}	
	#Display the CSR
	echo "<center>Server$server Certificate Signing Request:</center>";
	echo "<center><textarea cols=\"70\" rows=\"8\" name=\"CSR\">$result</textarea></center><br>";
	#Allow upload of signed cert
	echo "<center>Server$server Signed Key:</center>";
	echo "<FORM method=\"post\" name=\"signed\" action=\"manage_ssl.php?action=editsigned&t=$t\">";
	echo "<center><textarea cols=\"70\" rows=\"8\" name=\"signedcert\">Paste your signed certificate here.</textarea></center><br>";
	echo "<INPUT type=\"hidden\" name=\"server\" value=\"$server\">";
	echo "<center><INPUT type=\"submit\" value=\"Upload Signed Certificate\" name=\"go\" \">";
	#Display the server key
	$result="";
	$filepath= "$path" . "server$server" . "_key_nopass.pem";
	if ($file=fopen("$filepath","r")) {
		while (!feof ($file)) {
			$result = $result . fgets($file);
		}
			fclose($file);

	} else {
  		draw_no_access ("$filepath");
	}	
	#Display the server key
	echo "<br><br><center>Server$server Private Key:</center>";
	echo "<center><textarea cols=\"70\" rows=\"8\" name=\"CSR\">$result</textarea></center><br>";
}




if ($WRITEFILE==TRUE) {
	# open a new file
	write_config_file();
}

if ($action=="editsigned") {
	$server = $_POST['server'];

		SCOP_log("Config : New certificate installed");
		$signedcert = $_POST['signedcert'];
		$signedcert = str_replace("\r","",$signedcert);
		$signedcert = stripslashes($signedcert);
		$signedcert = "$signedcert" . "\n";
		# . addlinebr($mainfirewall);
		# Open a file and write the contents of the field to it !
		$path = "/usr/local/etc/";
		$filepath= "$path" . "server$server" . "_key_signed.pem";
		$filepath2= "$path" . "server$server" . "_key_nopass.pem";
		$filepath3= "$path" . "server$server" . ".pem";
		exec ("sudo touch $filepath");
		exec ("sudo chmod 777 $filepath");
		if ($file=fopen("$filepath","w")) {

				fputs($file,$signedcert,strlen($signedcert));
				fclose($file);
				#`sudo /etc/rc.d/rc.firewall`;
				#echo "</br></br><center><p>The signed cert has now been updated. </p></br></br></center>";
				#Copy settings to slave
			flush();
			exec ("sudo cat $filepath $filepath2 > $filepath3");
			flush();
			exec ("sudo scp $filepath3 hide@address.com:$filepath3 > /dev/null 2>&1 &");
		} else {

			draw_no_access ("$filepath");
		}
$SIGNEDCREATED="TRUE";
} //end of editsigned

if ($SIGNEDCREATED=="TRUE") {
	$trans="20";
	$a20 = "${$l.$trans}";
	$filepath= "$path" . "server$server" . ".pem";
	if ($file=fopen("$filepath","r")) {
		while (!feof ($file)) {
			$result = $result . fgets($file);
		}
			fclose($file);

	} else {
  		draw_no_access ("$filepath");
	}	
	#Display the fully signed PEM file
	echo "<center>Server$server Signed Certificate:</center>";
	echo "<center><textarea cols=\"70\" rows=\"8\" name=\"CSR\">$result</textarea></center><br>";
	echo "<center>[ <a href=\"?action=remove&server=$server&t=$t\" class=\"action\" onclick=\"return areyousure('Are you sure you want to remove this signed certificate? (Server$server)')\">$a20</a> ]</center>";


}



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


Return current item: SCOP Heartbeat Administration interface