#!/usr/local/bin/php &1 ", "r"); echo "\n"; $counter = 0; $counter2 = 0; while(!feof($fd)) { $tmp = fread($fd,49); $tmp1 = ereg_replace("\n","\\n", $tmp); $text = ereg_replace("\"","'", $tmp1); if($lasttext == "..") { $text = ""; $lasttext = ""; $counter=$counter-2; } else { $lasttext .= $text; } if($counter > 51) { $counter = 0; $extrabreak = "\\n"; } else { $extrabreak = ""; $counter++; } if($counter2 > 600) { echo "\n"; $counter2 = 0; } else $counter2++; echo "\n"; } fclose($fd); } $fd = fopen("/etc/ssl/openssl.cnf", "r"); $openssl = fread($fd,8096); fclose($fd); /* Lets match the fileds in the read in file and populate the variables for the form */ preg_match('/\nC\=(.*)\n/', $openssl, $countrycodeA); preg_match('/\nST\=(.*)\n/', $openssl, $stateorprovinceA); preg_match('/\nL\=(.*)\n/', $openssl, $citynameA); preg_match('/\nO\=(.*)\n/', $openssl, $orginizationnameA); preg_match('/\nOU\=(.*)\n/', $openssl, $orginizationdepartmentA); preg_match('/\nCN\=(.*)\n/', $openssl, $commonnameA); $countrycode = $countrycodeA[1]; $stateorprovince = $stateorprovinceA[1]; $cityname = $citynameA[1]; $orginizationname = $orginizationnameA[1]; $orginizationdepartment = $orginizationdepartmentA[1]; $commonname = $commonnameA[1]; if ($_POST) { /* Grab posted variables and create a new openssl.cnf */ $countrycode=$_POST['countrycode']; $stateorprovince=$_POST['stateorprovince']; $cityname=$_POST['cityname']; $orginizationname=$_POST['orginizationname']; $orginizationdepartment=$_POST['orginizationdepartment']; $commonname=$_POST['commonname']; /* Write out /etc/ssl/openssl.cnf */ $fd = fopen("/etc/ssl/openssl.cnf", "w"); fwrite($fd, ""); fwrite($fd, "[ req ]\n"); fwrite($fd, "distinguished_name=req_distinguished_name \n"); fwrite($fd, "req_extensions = v3_req \n"); fwrite($fd, "prompt=no\n"); fwrite($fd, "default_bits = 1024\n"); fwrite($fd, "default_keyfile = privkey.pem\n"); fwrite($fd, "distinguished_name = req_distinguished_name\n"); fwrite($fd, "attributes = req_attributes\n"); fwrite($fd, "x509_extensions = v3_ca # The extentions to add to the self signed cert\n"); fwrite($fd, "[ req_distinguished_name ] \n"); fwrite($fd, "C=" . $countrycode . " \n"); fwrite($fd, "ST=" . $stateorprovince. " \n"); fwrite($fd, "L=" . $cityname . " \n"); fwrite($fd, "O=" . $orginizationname . " \n"); fwrite($fd, "OU=" . $orginizationdepartment . " \n"); fwrite($fd, "CN=" . $commonname . " \n"); fwrite($fd, "[EMAIL PROTECTED] \n"); fwrite($fd, "[EMAIL PROTECTED] \n"); fwrite($fd, "[ v3_req ] \n"); fwrite($fd, "basicConstraints = critical,CA:FALSE \n"); fwrite($fd, "keyUsage = nonRepudiation, digitalSignature, keyEncipherment, dataEncipherment, keyAgreement \n"); fwrite($fd, "extendedKeyUsage=emailProtection,clientAuth \n"); fwrite($fd, "[ ca ]\n"); fwrite($fd, "default_ca = CA_default\n"); fwrite($fd, "[ CA_default ]\n"); fwrite($fd, "certificate = /tmp/cacert.pem \n"); fwrite($fd, "private_key = /tmp/cakey.pem \n"); fwrite($fd, "dir = /tmp/\n"); fwrite($fd, "certs = /tmp/certs\n"); fwrite($fd, "crl_dir = /tmp/crl\n"); fwrite($fd, "database = /tmp/index.txt \n"); fwrite($fd, "new_certs_dir = /tmp/newcerts \n"); fwrite($fd, "serial = /tmp/serial \n"); fwrite($fd, "crl = /tmp/crl.pem \n"); fwrite($fd, "RANDFILE = /tmp/.rand \n"); fwrite($fd, "x509_extensions = usr_cert \n"); fwrite($fd, "name_opt = ca_default \n"); fwrite($fd, "cert_opt = ca_default \n"); fwrite($fd, "default_days = 365 \n"); fwrite($fd, "default_crl_days = 30 \n"); fwrite($fd, "default_md = md5 \n"); fwrite($fd, "preserve = no \n"); fwrite($fd, "policy = policy_match\n"); fwrite($fd, "[ policy_match ]\n"); fwrite($fd, "countryName = match\n"); fwrite($fd, "stateOrProvinceName = match\n"); fwrite($fd, "organizationName = match\n"); fwrite($fd, "organizationalUnitName = optional\n"); fwrite($fd, "commonName = supplied\n"); fwrite($fd, "emailAddress = optional\n"); fwrite($fd, "[ policy_anything ]\n"); fwrite($fd, "countryName = optional\n"); fwrite($fd, "stateOrProvinceName = optional\n"); fwrite($fd, "localityName = optional\n"); fwrite($fd, "organizationName = optional\n"); fwrite($fd, "organizationalUnitName = optional\n"); fwrite($fd, "commonName = supplied\n"); fwrite($fd, "emailAddress = optional\n"); fwrite($fd, "[ req_distinguished_name ]\n"); fwrite($fd, "countryName = US\n"); fwrite($fd, "[ req_attributes ]\n"); fwrite($fd, "challengePassword = A challenge password\n"); fwrite($fd, "unstructuredName = An optional company name\n"); fwrite($fd, "[ usr_cert ]\n"); fwrite($fd, "basicConstraints=CA:FALSE\n"); fwrite($fd, "[ v3_ca ]\n"); fwrite($fd, "subjectKeyIdentifier=hash\n"); fwrite($fd, "authorityKeyIdentifier=keyid:always,issuer:always\n"); fwrite($fd, "basicConstraints = CA:true\n"); fwrite($fd, "[ crl_ext ]\n"); fwrite($fd, "authorityKeyIdentifier=keyid:always,issuer:always\n"); fclose($fd); ?> <?=gentitle("System: Advanced functions");?>

System: Advanced functions - Create Certificates

document.forms[0].status.value=\"Creating CA...\";"; mwexec("rm -rf /tmp/*"); //mwexec("rm -rf /tmp/newcerts"); mwexec("mkdir /tmp/newcerts"); mwexec("touch /tmp/index.txt"); $fd = fopen("/tmp/serial","w"); fwrite($fd, "01\n"); fclose($fd); /* mkdir /tmp/newcerts touch /tmp/index.txt echo 01 > serial #Create The Certificate Authority Root Certificate cd /tmp/ && openssl req -nodes -new -x509 -keyout cakey.pem -out cacert.pem -config /etc/ssl/openssl.cnf #Create User Certificates cd /tmp/ && openssl req -nodes -new -keyout vpnkey.pem -out vpncert-req.pem -config /etc/ssl/openssl.cnf mkdir /tmp/newcerts openssl ca -out vpncert.pem -in vpncert-req.pem -batch # Diffie-Hellman Parameters (tls-server only) dh dh1024.pem # Root certificate ca CA-DB/cacert.pem # Server certificate cert vpncert.pem # Server private key key vpnkey.pem */ execute_command_return_output("cd /tmp/ && openssl req -nodes -new -x509 -keyout cakey.pem -out cacert.pem -config /etc/ssl/openssl.cnf"); echo "\n"; execute_command_return_output("cd /tmp/ && openssl req -nodes -new -keyout vpnkey.pem -out vpncert-req.pem -config /etc/ssl/openssl.cnf"); execute_command_return_output("cd /tmp/ && openssl ca -out vpncert.pem -in vpncert-req.pem -batch"); echo "\n"; execute_command_return_output("cd /tmp/ && openssl dhparam -out dh1024.pem 1024"); echo "\n"; //CLIENT //mwexec("openssl req -nodes -new -keyout home.key -out home.csr"); //mwexec("openssl ca -out home.crt -in home.csr"); $cacertA = get_file_contents("/tmp/cacert.pem"); $serverkeyA = get_file_contents("/tmp/vpnkey.pem"); $servercertA = get_file_contents("/tmp/vpncert.pem"); $dhpemA = get_file_contents("/tmp/dh1024.pem"); $cacert = ereg_replace("\n","\\n", $cacertA); $serverkey = ereg_replace("\n","\\n", $serverkeyA); $dhpem = ereg_replace("\n","\\n", $dhpemA); //$servercert = ereg_replace("\n","\\n", $servercertA); $tmp = strstr($servercertA, "-----BEGIN CERTIFICATE-----"); $servercert = ereg_replace("\n","\\n", $tmp); ?> <?=gentitle("OpenVPN: Create Certificates");?>

System: Advanced - Create Certificates

Country Code (2 Letters)
State or Province name
City name
Organization name
Organization department
Common Name (Your name)