<?PHP
	$certsdir="/home/phadley/websites/certs/1";
	$req_file = "$certsdir/$count.req"; # certificate request filename

	# The configuration file made on the fly for vivos cheapo certificates.
	function cnf_make($filename,$count,$dir,$email)
	{
		#$certs_dir="$dir/certs";
		$certs_dir=$dir;
		$cnfp=fopen($filename,"w");
		fwrite($cnfp,"[ ca ]\n");									##Lazim mi?
		fwrite($cnfp,"default_ca	= $count"."ca\n\n");
		
		fwrite($cnfp,"[ $count"."ca ]\n");							##Lazim mi?
		fwrite($cnfp,"certificate      = $dir/root.pem\n");
		fwrite($cnfp,"new_certs_dir    = $certs_dir\n");
		fwrite($cnfp,"database		  = $certs_dir/$count.txt\n");
		fwrite($cnfp,"private_key      = $dir/rootkey.pem\n");
		fwrite($cnfp,"serial           = $certs_dir/$count.srl\n");
		
		fwrite($cnfp,"default_crl_days = 7\n");
		fwrite($cnfp,"default_days     = 365\n");
		fwrite($cnfp,"default_md       = sha1\n");
		
		fwrite($cnfp,"policy           = $count"."_policy\n");
		fwrite($cnfp,"x509_extensions  = certificate_extensions\n");	##Belki lazim, no, it's in the cmd line
		
		fwrite($cnfp,"[ $count"."_policy ]\n");						##Lazim mi?  I think so.
		fwrite($cnfp,"countryName            = optional\n");
		fwrite($cnfp,"stateOrProvinceName    = optional\n");
		fwrite($cnfp,"localityName           = optional\n");
		fwrite($cnfp,"organizationName       = optional\n");
		fwrite($cnfp,"organizationalUnitName = optional\n");
		fwrite($cnfp,"commonName             = supplied\n");
		fwrite($cnfp,"emailAddress           = optional\n");
		
		fwrite($cnfp,"[ req ]\n");
		fwrite($cnfp,"default_bits		= 2048\n");
		fwrite($cnfp,"default_keyfile 	= privkey.pem\n");
		fwrite($cnfp,"default_md              = sha1\n");
		
		fwrite($cnfp,"prompt                  = no\n");
		fwrite($cnfp,"distinguished_name	= req_distinguished_name\n");
		fwrite($cnfp,"x509_extensions		= req_extensions\n");
		
		# the following sections are specific to the request we're building
		
		fwrite($cnfp,"[ certificate_extensions ]\n");
		fwrite($cnfp,"basicConstraints = CA:false\n");
		fwrite($cnfp,"keyUsage = digitalSignature, keyEncipherment, dataEncipherment\n");
		fwrite($cnfp,"extendedKeyUsage = clientAuth, emailProtection\n");
		#fwrite($cnfp,"subjectAltName = CN:Village Registrant,email:$email\n");
		
		fwrite($cnfp,"[ req_distinguished_name ]\n");					##Lazim mi?
		fwrite($cnfp,"countryName         	= US\n");
		fwrite($cnfp,"stateOrProvinceName 	= New York\n");
		fwrite($cnfp,"localityName        	= Wantagh\n");
		fwrite($cnfp,"organizationName    	= Suffolk County\n");
		fwrite($cnfp,"organizationalUnitName	= Birth Certificates\n");
		fwrite($cnfp,"commonName          	= William F. Schmitt\n");
		
		fwrite($cnfp,"[ req_extensions ]\n");							##Lazim mi?
		fwrite($cnfp,"basicConstraints = CA:true\n");
		fwrite($cnfp,"subjectAltName = DNS:Bill Schmitt\n");
		#subjectAltName = DNS:splat.zork.org,DNS:localhost\n");
		fclose($cnfp);
		return;
	}