Esempio n. 1
0
function knj_error_reporter_activate($args = array()){
	global $knj_error_reporter;
	
	if (!$knj_error_reporter["emails"]){
		$knj_error_reporter["emails"] = array();
	}
	
	foreach($args AS $key => $value){
		if ($key == "emails"){
			foreach($value AS $email){
				$knj_error_reporter["emails"][] = $email;
			}
		}elseif($key == "email"){
			$knj_error_reporter["emails"][] = $value;
		}elseif($key == "email_title" || $key == "email_from" || $key == "ignore_javabots" || $key == "ignore_bots"){
			$knj_error_reporter[$key] = $value;
		}else{
			throw new Exception("Invalid key: \"" . $key . "\".");
		}
	}
	
	require_once "knj/web.php";
	
	$activate = true;
	if (
		(
			(array_key_exists("ignore_javabots", $knj_error_reporter) and $knj_error_reporter["ignore_javabots"]) or
			(array_key_exists("ignore_bots", $knj_error_reporter) and $knj_error_reporter["ignore_bots"])
		) and (
			array_key_exists("HTTP_USER_AGENT", $_SERVER) and
			preg_match("/Java\/[0-9\.]+/i", $_SERVER["HTTP_USER_AGENT"], $match)
		)
	){
		$activate = false;
	}elseif(array_key_exists("ignore_bots", $knj_error_reporter) and $knj_error_reporter["ignore_bots"] && knj_browser::getOS() == "bot"){
		$activate = false;
	}
	
	if ($activate){
		set_exception_handler("knj_error_reporter_exception_handler");
		set_error_handler("knj_error_reporter_error_handeler");
		error_reporting(E_ALL ^ E_NOTICE);
		register_shutdown_function("knj_error_shutdown");
	}
}
Esempio n. 2
0
	static function getOSVersion(){
		$version = "unknown";
		
		if (knj_browser::getOS() == "windows"){
			if (preg_match("/Windows\s+NT\s+([\d\.]+)/", $_SERVER["HTTP_USER_AGENT"], $match)){
				if ($match[1] == 6.0){
					$version = "vista";
				}elseif($match[1] == 5.1){
					$version = "xp";
				}
			}else{
				throw new exception("Could not match version.");
			}
		}elseif(knj_browser::getOS() == "linux"){
			if (preg_match("/Ubuntu\/([\d+\.]+)/", $_SERVER["HTTP_USER_AGENT"], $match)){
				$version = "ubuntu_" . str_replace(".", "_", $match[1]);
			}else{
				throw new exception("Unknown user-agent for OS '" . knj_browser::getOS() . "': " . $_SERVER["HTTP_USER_AGENT"]);
			}
		}else{
			throw new exception("Unknown user-agent for OS '" . knj_browser::getOS() . "': " . $_SERVER["HTTP_USER_AGENT"]);
		}
		
		return array(
			"version" => $version
		);
	}