';
switch ($stage) {
case 'validate':
$er = '';
if (! $country) {
$er .= 'Missing Country ';
}
if (! $province) {
$er .= 'Missing State/Province ';
}
if (! $locality) {
$er .= 'Missing Locality ';
}
if (! $organization) {
$er .= 'Missing Organization ';
}
if (! $unit) {
$er .= 'Missing Unit/Department ';
}
if (! $contact) {
$er .= 'Missing Contact E-mail Address ';
}
if (! $common_name) {
$er .= 'Missing Common Name ';
}
if (! $passwd) {
$er .= 'Missing Certificate Password ';
}
if (! $passwdv) {
$er .= 'Missing Certificate Password Verification "Again" ';
}
if (! $header_title) {
$er .= 'Missing Header Title ';
}
if (! $passwd_file) {
$er .= 'Missing User Password File Location';
}
if (! $store_dir) {
$er .= 'Missing Storage Directory ';
}
$countrycode = strtoupper($country);
if (! preg_match("/\b[A-Z][A-Z]\b/", $countrycode, $match)) {
$er .= 'Country Code must be ISO 3166 two letters ';
}
if ($passwd && strlen($passwd) < 8) {
$er .= 'Certificate password is too short. ';
}
if ($passwd and $passwd != $passwdv) {
$er .= 'Password and password verification do not match. ';
}
if ($contact && ! is_email($contact)) {
$er .= 'E-mail address ('. htvar($contact) . ') may be invalid. ';
}
// reetp this was the wrong way round - swapped
// strpos ($haystack, $needle)
if (strpos($_SERVER['DOCUMENT_ROOT'], $store_dir) === 0) {
$er .= 'Store directory ('.$store_dir.') must exist somewhere outside of DOCUMENT_ROOT ('.$_SERVER['DOCUMENT_ROOT'].'). ';
}
// reetp this was the wrong way round - swapped
// strpos ($haystack, $needle)
if (strpos(dirname($_SERVER['SCRIPT_FILENAME']), $store_dir) === 0) {
$er .= 'Store directory ('.$store_dir.') cannot exist within the PHPki installation directory ('.dirname($_SERVER['SCRIPT_FILENAME']).'). ';
}
if (! $er) {
if (! file_exists($store_dir)) {
if (! mkdir("$store_dir", $store_perms)) {
$er .= "Could not create the store directory \"$store_dir\" ";
}
}
if (file_exists($store_dir)) {
if (! chmod($store_dir, $store_perms)) {
$er .= "Could not change permissions on the store directory \"$store_dir\" ";
}
if (! is_readable($store_dir)) {
$er .= "The store directory \"$store_dir\" is not readable by the web server user \"$uname\" ";
}
if (! is_writeable($store_dir)) {
$er .= "The store directory \"$store_dir\: is not writable by the web server user \"$uname\" ";
}
} else {
$er .= "Store directory \"$store_dir\" does not exist. You will have to manually create it as described in the setup form. ";
}
}
if ($er) {
$er = '