<?

include_once("config.php");
class Stat extends Fly5 {
	var $COLLISIONTEXT="[[[충돌발견 - 충돌 내용을 해결하고 이 라인도 삭제한 후 다시 저장할것]]]";
	function execute(&$view, $path, $args)
	{
		$a = $_REQUEST;
		switch($path) {
		
		case "System/api/am-i-logged-in":
			$this->checklogin();
			
			break;
		
		default:
			$view = "$path.pug";
			return;
		}
		reply_json($result);
	}
	function process_apache2_log()
	{
		//print_r($_SERVER);
		$log = $_REQUEST[l];
		echo "log comming: $log\n";
		
		$regex = '/^(\S+) (\S+) (\S+) \[([^:]+):(\d+:\d+:\d+) ([^\]]+)\] \"(\S+) (.*?) (\S+)\" (\S+) (\S+) "([^"]*)" "([^"]*)"$/';
		preg_match($regex ,$log, $m);
		
		
		$fp = sha1($log);
		try {
			query("insert into logfingerprint (sha1) values (:sha1)", array('sha1'=>$fp));
		}catch(Exception $e){
			// 이미 있는 로그
			die();
		}
		
		print_r($m);
		
		query("insert into logaccess (ip, url, agent, time)
				values
			(:ip, :url, :agent:, time)", array(
				ip=>$m[1],
				
				
			", a[]);, 
		
		//$a = $_REQUEST;
		//print_r($a);
		echo "ok\n";
	}
}
