<html>
<head><title>Installer Page STEP 3</title></head>
<body>
<?php 
echo "INSTALLING...STEP 3<br>";
include ("../Site/mysql.php");

$ovpnconfdir = db_getconfval("ovpnconfdir");
$ovpnkeydir = db_getconfval("ovpnkeydir");
mysql_close();

//Generate DH, CA, Server cert...
$vars = 
"export EASY_RSA=\"`pwd`\"
export OPENSSL=\"openssl\"
export PKCS11TOOL=\"pkcs11-tool\"
export GREP=\"grep\"
export KEY_CONFIG=`\$EASY_RSA/whichopensslcnf \$EASY_RSA`
export KEY_DIR=\"\$EASY_RSA/keys/\"
echo NOTE: If you run ./clean-all, I will be doing a rm -rf on \$KEY_DIR
export PKCS11_MODULE_PATH=\"dummy\"
export PKCS11_PIN=\"dummy\"
export KEY_SIZE=1024
export CA_EXPIRE=3650
export KEY_EXPIRE=3650
export KEY_COUNTRY=\"".$_REQUEST["country"]."\"
export KEY_PROVINCE=\"".$_REQUEST["province"]."\"
export KEY_CITY=\"".$_REQUEST["city"]."\"
export KEY_ORG=\"".$_REQUEST["organisation"]."\"
export KEY_EMAIL=\"".$_REQUEST["email"]."\"";

$dateiname = $ovpnkeydir."/vars";
$handler = fOpen($dateiname , "a+");
fWrite($handler , $vars);
fClose($handler);
$res = exec("chmod 777 ".$ovpnkeydir."/vars");
if($res =="")
{
	echo "Umgebungsvariablen erfolgreich angelegt! [<b><font color=lime>OK</b></font>]<br>\n";
}
else
{
	die("Fehler beim Anlegen der Umgebungsvariablen! (evt Rechteproblem??) [<b><font color=red>FAIL</b></font>]<br>");
}
chdir ("$ovpnkeydir");
$res=exec("./install");
chdir ("/var/www/install/");
$res = exec("chmod -R 777 ".$ovpnkeydir."/keys");
//##############################################################################
// How to fix?
exec("cp ".$ovpnkeydir."/keys/ca.crt /var/www/downloads/ca.crt");
exec("cp ".$ovpnkeydir."/keys/ca.crt /var/www/admin/downloads/ca.crt");
//##############################################################################
if($res =="")
{
	echo "Server Zertifikate erfolgreich angelegt! [<b><font color=lime>OK</b></font>]<br>\n";
	echo "<form action=\"install4.php\" method=\"post\">
	<input type=\"submit\" value=\"Install! STEP 4\">
	</form> ";
}
else
{
	die("Fehler beim Anlegen der Server Zertifikate! (evt Rechteproblem??) [<b><font color=red>FAIL</b></font>]<br>");
}

?>

</body>
</html> 
