// Copyright: Copyright (C) 2001-2008 Pristine Communications // Set the include path if (!defined("INCPATH_SET")) { require_once dirname(__FILE__) . "/incpath.inc.php"; } // Referenced subroutines require_once "monica/a2html.inc.php"; require_once "monica/addget.inc.php"; require_once "monica/cgiemu.inc.php"; require_once "monica/chkpriv.inc.php"; require_once "monica/curtime.inc.php"; require_once "monica/altlang.inc.php"; require_once "monica/getlang.inc.php"; require_once "monica/gettext.inc.php"; require_once "monica/geoip.inc.php"; require_once "monica/hires.inc.php"; require_once "monica/htmlchar.inc.php"; require_once "monica/lninfo.inc.php"; require_once "monica/login.inc.php"; require_once "monica/mail.inc.php"; require_once "monica/page2rel.inc.php"; require_once "monica/pagefunc.inc.php"; require_once "monica/rel2abs.inc.php"; require_once "monica/requri.inc.php"; require_once "monica/unicode.inc.php"; // Settings $_HTTP_ERROR_TYPES = array ( E_ERROR => "Error", E_WARNING => "Warning", E_PARSE => "Parsing Error", E_NOTICE => "Notice", E_CORE_ERROR => "Core Error", E_CORE_WARNING => "Core Warning", E_COMPILE_ERROR => "Compile Error", E_COMPILE_WARNING => "Compile Warning", E_USER_ERROR => "User Error", E_USER_WARNING => "User Warning", E_USER_NOTICE => "User Notice", E_STRICT => "Runtime Notice", E_RECOVERABLE_ERROR => "Catchable Fatal Error", ); // http_204: HTTP 204 No Content function http_204() { // Stop and clean the previous output buffering if (!defined("LAST_OB_LEVEL")) { define("LAST_OB_LEVEL", (ini_get("output_buffering") == "")? 0: 1); } while (ob_get_level() > LAST_OB_LEVEL) { ob_end_clean(); } // Output the status message header("HTTP/1.1 204 No Content"); header("Content-Length: 0"); // Client cache if (array_key_exists("LAST_MODIFIED", $GLOBALS)) { if (!is_null(get_login_sn())) { header("Cache-Control: private"); } else { header("Cache-Control: public"); } header("Last-Modified: " . date("r", $GLOBALS["LAST_MODIFIED"])); } else { header("Cache-Control: no-cache"); } // Print the processing time for debugging purpose if (defined("LOGTIME") && LOGTIME) { error_log("Process time: " . (time_hires() - T_START) . " sec."); } // No need to return exit; } // http_301: HTTP 301 Moved Permanently function http_301($url) { // Stop and clean the previous output buffering if (!defined("LAST_OB_LEVEL")) { define("LAST_OB_LEVEL", (ini_get("output_buffering") == "")? 0: 1); } while (ob_get_level() > LAST_OB_LEVEL) { ob_end_clean(); } $url = rel2abs($url); $url = _http_uri_add_sid($url); // Obtain the status message $html = _http_get_custom_status_message(301); if (is_null($html)) { ob_start(); ?>
You should refer to the new location.
1 && $_SERVER["REQUEST_METHOD"] != "POST" && $_SERVER["REQUEST_METHOD"] != "PUT" && !array_key_exists("lang", $_GET)) { header("Content-Location: " . rel2abs(altlang(getlang(), page_param()))); header("Vary: accept-language,cookie"); } if ($_SERVER["REQUEST_METHOD"] != "HEAD") { echo $html; } // Print the processing time for debugging purpose if (defined("LOGTIME") && LOGTIME) { error_log("Process time: " . (time_hires() - T_START) . " sec."); } // No need to return exit; } // http_303: HTTP 303 See Others function http_303($url) { // Stop and clean the previous output buffering if (!defined("LAST_OB_LEVEL")) { define("LAST_OB_LEVEL", (ini_get("output_buffering") == "")? 0: 1); } while (ob_get_level() > LAST_OB_LEVEL) { ob_end_clean(); } $url = rel2abs($url); $url = _http_uri_add_sid($url); // Obtain the status message $html = _http_get_custom_status_message(303); if (is_null($html)) { ob_start(); ?>Please follow this location.
1 && $_SERVER["REQUEST_METHOD"] != "POST" && $_SERVER["REQUEST_METHOD"] != "PUT" && !array_key_exists("lang", $_GET)) { header("Content-Location: " . rel2abs(altlang(getlang(), page_param()))); header("Vary: accept-language,cookie"); } if ($_SERVER["REQUEST_METHOD"] != "HEAD") { echo $html; } // Print the processing time for debugging purpose if (defined("LOGTIME") && LOGTIME) { error_log("Process time: " . (time_hires() - T_START) . " sec."); } // No need to return exit; } // http_304: HTTP 304 Not Modified function http_304() { // Stop and clean the previous output buffering if (!defined("LAST_OB_LEVEL")) { define("LAST_OB_LEVEL", (ini_get("output_buffering") == "")? 0: 1); } while (ob_get_level() > LAST_OB_LEVEL) { ob_end_clean(); } // Output the status message // See HTTP/1.1 sec 10.3.5 for appropriate headers to send header("HTTP/1.1 304 Not Modified"); // We must send them if (count($GLOBALS["ALL_LINGUAS"]) > 1) { header("Content-Location: " . rel2abs(altlang(getlang(), page_param()))); } // Print the processing time for debugging purpose if (defined("LOGTIME") && LOGTIME) { error_log("Process time: " . (time_hires() - T_START) . " sec."); } // No need to return exit; } // http_307: HTTP 307 Temporary Redirect function http_307($url) { // Stop and clean the previous output buffering if (!defined("LAST_OB_LEVEL")) { define("LAST_OB_LEVEL", (ini_get("output_buffering") == "")? 0: 1); } while (ob_get_level() > LAST_OB_LEVEL) { ob_end_clean(); } $url = rel2abs($url); $url = _http_uri_add_sid($url); // Obtain the status message $html = _http_get_custom_status_message(307); if (is_null($html)) { ob_start(); ?>Please refer to the following location.
1 && $_SERVER["REQUEST_METHOD"] != "POST" && $_SERVER["REQUEST_METHOD"] != "PUT" && !array_key_exists("lang", $_GET)) { header("Content-Location: " . rel2abs(altlang(getlang(), page_param()))); header("Vary: accept-language,cookie"); } if ($_SERVER["REQUEST_METHOD"] != "HEAD") { echo $html; } // Print the processing time for debugging purpose if (defined("LOGTIME") && LOGTIME) { error_log("Process time: " . (time_hires() - T_START) . " sec."); } // No need to return exit; } // http_400: HTTP 400 Bad Request // False to disable error page output function http_400($errmsg = null) { // Stop and clean the previous output buffering if (!defined("LAST_OB_LEVEL")) { define("LAST_OB_LEVEL", (ini_get("output_buffering") == "")? 0: 1); } while (ob_get_level() > LAST_OB_LEVEL) { ob_end_clean(); } // No error page output if ($errmsg === false) { $html = ""; } else { // Obtain the status message $html = _http_get_custom_status_message(400); if (is_null($html)) { ob_start(); ?>Sorry, there is some error in your request.
", is_null($errmsg)? "": h(C_($errmsg)), $html); // Convert the URLs to relative $html = page2rel($html, REQUEST_PATH); // Encode the e-mail at-signs (@) $html = str_replace("@", "@", $html); // Decode the e-mail at-signs (@) of spamtrap $html = str_replace("spamtrap@", "spamtrap@", $html); // Convert to the desired character set $html = page_encode($html); } // Output the status message header("HTTP/1.1 400 Bad Request"); header("Content-Language: " . getlang()); header("Content-Length: " . strlen($html)); // Content negotiation, see HTTP/1.1 section 13.6 if ( count($GLOBALS["ALL_LINGUAS"]) > 1 && $_SERVER["REQUEST_METHOD"] != "POST" && $_SERVER["REQUEST_METHOD"] != "PUT" && !array_key_exists("lang", $_GET)) { header("Content-Location: " . rel2abs(altlang(getlang(), page_param()))); header("Vary: accept-language,cookie"); } if ($_SERVER["REQUEST_METHOD"] != "HEAD") { echo $html; } // Log the error message to the server error log if (is_null($errmsg)) { error_log("Bad Request: " . REQUEST_URI); } elseif ($errmsg === false) { $request = $_SERVER["REQUEST_METHOD"] . " " . $_SERVER["REQUEST_URI"] . " " . $_SERVER["SERVER_PROTOCOL"]; error_log("Invalid URI in request $request"); } else { error_log("Bad Request: " . REQUEST_URI . ": " . $errmsg); } // Print the processing time for debugging purpose if (defined("LOGTIME") && LOGTIME) { error_log("Process time: " . (time_hires() - T_START) . " sec."); } // No need to return exit; } // http_403: HTTP 403 Forbidden function http_403($errmsg = null) { // Stop and clean the previous output buffering if (!defined("LAST_OB_LEVEL")) { define("LAST_OB_LEVEL", (ini_get("output_buffering") == "")? 0: 1); } while (ob_get_level() > LAST_OB_LEVEL) { ob_end_clean(); } // No error page output if ($errmsg === false) { $html = ""; } else { // Obtain the status message $html = _http_get_custom_status_message(403); if (is_null($html)) { ob_start(); ?>You are not allowed to enter here.
", is_null($errmsg)? "": h(C_($errmsg)), $html); // Convert the URLs to relative $html = page2rel($html, REQUEST_PATH); // Encode the e-mail at-signs (@) $html = str_replace("@", "@", $html); // Decode the e-mail at-signs (@) of spamtrap $html = str_replace("spamtrap@", "spamtrap@", $html); // Convert to the desired character set $html = page_encode($html); } // Output the status message header("HTTP/1.1 403 Forbidden"); header("Content-Language: " . getlang()); header("Content-Length: " . strlen($html)); // Content negotiation, see HTTP/1.1 section 13.6 if ( count($GLOBALS["ALL_LINGUAS"]) > 1 && $_SERVER["REQUEST_METHOD"] != "POST" && $_SERVER["REQUEST_METHOD"] != "PUT" && !array_key_exists("lang", $_GET)) { header("Content-Location: " . rel2abs(altlang(getlang(), page_param()))); header("Vary: accept-language,cookie"); } if ($_SERVER["REQUEST_METHOD"] != "HEAD") { echo $html; } // Log the error message to the server error log if (is_null($errmsg)) { error_log("Forbidden: " . REQUEST_URI); } else { error_log("Forbidden: " . REQUEST_URI . ": " . $errmsg); } // Print the processing time for debugging purpose if (defined("LOGTIME") && LOGTIME) { error_log("Process time: " . (time_hires() - T_START) . " sec."); } // No need to return exit; } // http_404: HTTP 404 Not Found function http_404() { // Stop and clean the previous output buffering if (!defined("LAST_OB_LEVEL")) { define("LAST_OB_LEVEL", (ini_get("output_buffering") == "")? 0: 1); } while (ob_get_level() > LAST_OB_LEVEL) { ob_end_clean(); } // Obtain the status message $html = _http_get_custom_status_message(404); if (is_null($html)) { ob_start(); ?>The document you requested was not found.
1 && $_SERVER["REQUEST_METHOD"] != "POST" && $_SERVER["REQUEST_METHOD"] != "PUT" && !array_key_exists("lang", $_GET)) { header("Content-Location: " . rel2abs(altlang(getlang(), page_param()))); header("Vary: accept-language,cookie"); } if ($_SERVER["REQUEST_METHOD"] != "HEAD") { echo $html; } // Log the error message to the server error log error_log("File does not exist: " . REQUEST_URI); // Print the processing time for debugging purpose if (defined("LOGTIME") && LOGTIME) { error_log("Process time: " . (time_hires() - T_START) . " sec."); } // No need to return exit; } // http_405: HTTP 405 Method Not Allowed function http_405($allowed) { // Stop and clean the previous output buffering if (!defined("LAST_OB_LEVEL")) { define("LAST_OB_LEVEL", (ini_get("output_buffering") == "")? 0: 1); } while (ob_get_level() > LAST_OB_LEVEL) { ob_end_clean(); } $allowed = implode(", ", $allowed); // Obtain the status message $html = _http_get_custom_status_message(405); if (is_null($html)) { ob_start(); ?>You should use the following methods: $allowed.
1 && $_SERVER["REQUEST_METHOD"] != "POST" && $_SERVER["REQUEST_METHOD"] != "PUT" && !array_key_exists("lang", $_GET)) { header("Content-Location: " . rel2abs(altlang(getlang(), page_param()))); header("Vary: accept-language,cookie"); } if ($_SERVER["REQUEST_METHOD"] != "HEAD") { echo $html; } // Log the error message to the server error log error_log("Method not allowed (" . $_SERVER["REQUEST_METHOD"] . "): " . REQUEST_URI); // Print the processing time for debugging purpose if (defined("LOGTIME") && LOGTIME) { error_log("Process time: " . (time_hires() - T_START) . " sec."); } // No need to return exit; } // http_410: HTTP 410 Gone function http_410() { // Stop and clean the previous output buffering if (!defined("LAST_OB_LEVEL")) { define("LAST_OB_LEVEL", (ini_get("output_buffering") == "")? 0: 1); } while (ob_get_level() > LAST_OB_LEVEL) { ob_end_clean(); } // Obtain the status message $html = _http_get_custom_status_message(410); if (is_null($html)) { ob_start(); ?>Sorry, this page is removed permanently, and there is no forwarding address available. Please remove your bookmarks, and stop referring to this page any more. Thanks.
1 && $_SERVER["REQUEST_METHOD"] != "POST" && $_SERVER["REQUEST_METHOD"] != "PUT" && !array_key_exists("lang", $_GET)) { header("Content-Location: " . rel2abs(altlang(getlang(), page_param()))); header("Vary: accept-language,cookie"); } if ($_SERVER["REQUEST_METHOD"] != "HEAD") { echo $html; } // Log error message into server error log error_log("Gone: " . REQUEST_URI); // Print the processing time for debugging purpose if (defined("LOGTIME") && LOGTIME) { error_log("Process time: " . (time_hires() - T_START) . " sec."); } // No need to return exit; } // http_413: HTTP 413 Request Entity Too Large function http_413() { // Stop and clean the previous output buffering if (!defined("LAST_OB_LEVEL")) { define("LAST_OB_LEVEL", (ini_get("output_buffering") == "")? 0: 1); } while (ob_get_level() > LAST_OB_LEVEL) { ob_end_clean(); } // Obtain the status message $html = _http_get_custom_status_message(413); if (is_null($html)) { ob_start(); ?>The server refuses to process your large submitted data.
1 && $_SERVER["REQUEST_METHOD"] != "POST" && $_SERVER["REQUEST_METHOD"] != "PUT" && !array_key_exists("lang", $_GET)) { header("Content-Location: " . rel2abs(altlang(getlang(), page_param()))); header("Vary: accept-language,cookie"); } if ($_SERVER["REQUEST_METHOD"] != "HEAD") { echo $html; } // Log error message into server error log error_log("Request Entity Too Large: " . REQUEST_URI); // Print the processing time for debugging purpose if (defined("LOGTIME") && LOGTIME) { error_log("Process time: " . (time_hires() - T_START) . " sec."); } // No need to return exit; } // http_500: HTTP 500 Internal Server Error function http_500($errmsg) { // Do not call the error handler recursively if (defined("_HTTP_HTTP_500_IN_PROGRESS")) { return; } define("_HTTP_HTTP_500_IN_PROGRESS", true); // Find out our context $trace = debug_backtrace(); // Obtain the caller information for ($i = 0, $callers = array(); $i < count($trace); $i++) { if (!array_key_exists("file", $trace[$i]) || !array_key_exists("line", $trace[$i])) { continue; } $callers[] = $trace[$i]; } // Stop and clean the previous output buffering if (!defined("LAST_OB_LEVEL")) { define("LAST_OB_LEVEL", (ini_get("output_buffering") == "")? 0: 1); } while (ob_get_level() > LAST_OB_LEVEL) { ob_end_clean(); } // Get the environment infomation needed for error reporting // Get the request information $request = array(); foreach (array_keys($_SERVER) as $name) { if (substr($name, 0, 5) == "HTTP_") { $name1 = substr($name, 5); $name1 = strtolower($name1); $name1 = str_replace("_", " ", $name1); $name1 = ucwords($name1); $name1 = str_replace(" ", "-", $name1); $request[$name1] = $_SERVER[$name]; } } if (!array_key_exists("Referer", $request)) { $request["Referer"] = "(not set)"; } if (!array_key_exists("Accept-Language", $request)) { $request["Accept-Language"] = "(not set)"; } if (!array_key_exists("User-Agent", $request)) { $request["User-Agent"] = "(not set)"; } // Mail the error message to the webmaster if (!defined("MAIL_ERROR") || MAIL_ERROR) { // Get the webmaster address to notify to if (defined("WEBMASTER")) { $webmaster = WEBMASTER; } elseif (array_key_exists("SERVER_ADMIN", $_SERVER)) { $webmaster = $_SERVER["SERVER_ADMIN"]; } else { $webmaster = "webmaster@" . $_SERVER["SERVER_NAME"]; } // Get the site name $site = (defined("SITENAME_ABBR")? SITENAME_ABBR: (defined("PACKAGE")? PACKAGE: REQUEST_HOST)); $body = ""; // Basic information ob_start(); ?>[%s] HTTP 500 Server Error Report %s ============================== * Time: %s * URI: %s * Request: %s %s %s * Error Message: %s %s. from("monica-http500@" . $_SERVER["SERVER_NAME"], "$site Website"); $mail->to($webmaster, "$site Webmaster"); $mail->subject(sprintf("[%s] HTTP 500 Server Error Report %s", $site, TODAY)); $mail->body($body); $mail->send(); } // Obtain the status message $html = _http_get_custom_status_message(500); if (is_null($html)) { ob_start(); ?>Sorry, our service is currently not available. Please come back later.
", is_null($errmsg)? "": h($errmsg), $html); // Convert the URLs to relative $html = page2rel($html, REQUEST_PATH); // Encode the e-mail at-signs (@) $html = str_replace("@", "@", $html); // Decode the e-mail at-signs (@) of spamtrap $html = str_replace("spamtrap@", "spamtrap@", $html); // Convert to the desired character set $html = page_encode($html); // Output the status message header("HTTP/1.1 503 Service Unavailable"); header("Content-Language: " . getlang()); header("Content-Length: " . strlen($html)); // Content negotiation, see HTTP/1.1 section 13.6 if ( count($GLOBALS["ALL_LINGUAS"]) > 1 && $_SERVER["REQUEST_METHOD"] != "POST" && $_SERVER["REQUEST_METHOD"] != "PUT" && !array_key_exists("lang", $_GET)) { header("Content-Location: " . rel2abs(altlang(getlang(), page_param()))); header("Vary: accept-language,cookie"); } if ($_SERVER["REQUEST_METHOD"] != "HEAD") { echo $html; } // Log the error message to the server error log // No logging due to maintainance // Print the processing time for debugging purpose if (defined("LOGTIME") && LOGTIME) { error_log("Process time: " . (time_hires() - T_START) . " sec."); } // No need to return exit; } // http500_error_handler: Standard error handler for Monica function http500_error_handler($no, $message, $file, $line, $context) { $prefix = $no; if (array_key_exists($no, $GLOBALS["_HTTP_ERROR_TYPES"])) { $prefix .= " " . $GLOBALS["_HTTP_ERROR_TYPES"][$no]; } http_500("$prefix: $message"); return; } // _http_need_302: Is this browser capable of HTTP 303 and HTTP 307? // Currently only older Netscape without Gecko (version <= 4.xx) // is known of this problem. // Return: // false: Standard behavior to send HTTP 303 or 307. // true: Browser lacks the capability of redirecting // HTTP 303 and 307. Send HTTP 302 instead. function _http_need_302() { // Unable to identify User-Agent, default to the standard behavior. if (!array_key_exists("HTTP_USER_AGENT", $_SERVER)) { return false; } $ua = $_SERVER["HTTP_USER_AGENT"]; // Mozilla/Netscape series if (preg_match("/^Mozilla\//", $ua)) { // True Mozilla/Netscape if (stristr($ua, "compatible") === false) { // Netscape without Gecko (version <= 4.xx) if (stristr($ua, "Gecko") === false) { return true; } // Mozilla/Netscape with Gecko return false; } // Netscape compatible return false; } // Others return false; } // _http_uri_add_sid: Add session ID into an URI function _http_uri_add_sid($url) { // No session if (!isset($_SESSION)) { return $url; } // Session ID already set in the cookies if (array_key_exists(session_name(), $_COOKIE)) { return $url; } // Add the session ID to the GET argument list return add_get_arg($url, session_name(), session_id()); } // _http_get_custom_status_message: Obtain the custom status message function _http_get_custom_status_message($status) { $langfile = getlang(LN_FILENAME); unset($file); if (is_file(DOC_ROOT . "/$langfile/errors/$status.html.xhtml")) { $file = "/%s/errors/$status.html.xhtml"; } elseif (is_file(DOC_ROOT . "/$langfile/errors/$status.html")) { $file = "/%s/errors/$status.html"; } elseif (is_file(DOC_ROOT . "/errors/$status.html.xhtml")) { $file = "/errors/$status.html.xhtml"; } elseif (is_file(DOC_ROOT . "/errors/$status.html")) { $file = "/errors/$status.html"; } // Not found if (!isset($file)) { return null; } $html = readpage($file); if (is_null($html)) { return null; } $charset = h(getlang(LN_CHARSET)); $html = preg_replace("/(?<=\bencoding=\")$charset(?=\")/", "", $html); $html = preg_replace("/(?<=\bcontent=\"text\/html; charset=)$charset(?=\")/", "", $html); $html = preg_replace("/(?<=\bcontent=\"application\/xhtml\+xml; charset=)$charset(?=\")/", "", $html); $html = preg_replace("/(?<=\btype=\"hidden\" name=\"charset\" value=\")$charset(?=\" \/>)/", "", $html); $html = preg_replace("/(?<=\baccept-charset=\")$charset(?=\")/", "", $html); return $html; } ?>