<?PHP
	#maff.inc.php-The things that Firefox on Mac OS X will understand as a certificate request
	switch ($part)
	{
		case "display":
			$osbrdisplay="Firefox on Macintosh";
			break;
		case "header":			##What goes into the header called between processing the command and sending the page
			##This is used when the page for filling out name parts is presented.
			echo "</HEAD>";
			echo "<BODY>";	#might have an onload component
			break;
		case "form":			##FORM statement for this browser-os system
			echo "After pressing the button, it will appear that nothing happens.  This might be the case but "
			."it is more likely that your new certificate is installed and you can start playing with it.";
			echo "<FORM METHOD=POST ACTION='".$_SERVER["PHP_SELF"]."' NAME='GenReqForm'>";
			echo "<KEYGEN NAME=\"SPKAC\" CHALLENGE=\"challengePassword\">";
			break;
		case "certheader":		#Again the transition from HEAD to BODY, this time for returning the certificate
			echo "</HEAD>";
			echo "<BODY>";
			break;
		case "makecert":		#Actual certificate construction commands
			$msgs.="<BR>We are at makecert in wiff.";
			$req_names = array('commonName', 'emailAddress', 'organizationName',
							   'organizationalUnitName', 'localityName', 'stateOrProvinceName',
							   'countryName');
			$reqp=fopen($req_file,"w");
			$nnames=count($req_names);
			for ($i=0;$i<$nnames;$i++)
			{
				$id=$req_names[$i];
				$value=str_replace("\r\n","",$_REQUEST[$id]);
				fwrite($reqp,sprintf("%s = %s\n",$id,$value));
			}
			fwrite($reqp,sprintf("SPKAC = %s\n",str_replace("\r\n","",$_REQUEST["SPKAC"])));
			fclose($reqp);
			$req=file_get_contents($req_file);
			$cmd="$openssldir/openssl ca -batch -config $cnffile -extensions "
				."certificate_extensions $CACERT "
				."$CAKEY "
				."-verbose -spkac $req_file $DAYS "
				."2>$ERRORFILE";
			$cert = shell_exec ($cmd);
			header("Content-Type: application/x-x509-user-cert");
			#	header("Content-Length: ".strlen($cert));
			#	header("Location: $PHP_SELF?command=info");
			echo $cert;
			$page="done";
			break;
		default:
			break;
	}
?>