license; $authenticator = $params->authenticator; $username = $params->username; $password = $params->password; $logged_in_key = $params->logged_in_key; // Verify input if (!preg_match('/^([0-9A-Z]{4}\-){7}[0-9A-Z]{4}$/', trim($license))) { throw new MOXMAN_Exception("Invalid license: " . $license); } if ($authenticator == "basic") { $params->authenticator = "BasicAuthenticator"; if (!$username) { throw new MOXMAN_Exception("User name can't be empty."); } if (!$password) { throw new MOXMAN_Exception("Password can't be empty."); } } if ($authenticator == "session") { $params->authenticator = "SessionAuthenticator"; if (!$logged_in_key) { throw new MOXMAN_Exception("Session name can't be empty."); } } // Replace template variables $template = file_get_contents($templatePath); foreach ($params as $key => $value) { $template = str_replace('<' . $key . '>', $value, $template); } if (!is_writable(MOXMAN_ROOT . "/config.php") || !file_put_contents(MOXMAN_ROOT . "/config.php", $template)) { return $template; } } else { throw new MOXMAN_Exception("Failed to locate config template."); } return true; } } ?>