]> git.openstreetmap.org Git - nominatim.git/blob - lib/log.php
install executables and call settings.php explicitly
[nominatim.git] / lib / log.php
1 <?php
2
3         function logStart(&$oDB, $sType = '', $sQuery = '', $aLanguageList = array())
4         {
5                 $aStartTime = explode('.',microtime(true));
6                 if (!isset($aStartTime[1])) $aStartTime[1] = '0';
7
8                 $sOutputFormat = '';
9                 if (isset($_GET['format'])) $sOutputFormat = $_GET['format'];
10
11                 $hLog = array(
12                                 date('Y-m-d H:i:s',$aStartTime[0]).'.'.$aStartTime[1],
13                                 $_SERVER["REMOTE_ADDR"],
14                                 $_SERVER['QUERY_STRING'],
15                                 $sQuery
16                                 );
17
18                 if (CONST_Log_DB)
19                 {
20                         // Log
21                         if ($sType == 'search')
22                         {
23                                 $oDB->query('insert into query_log values ('.getDBQuoted($hLog[0]).','.getDBQuoted($hLog[3]).','.getDBQuoted($hLog[1]).')');
24                         }
25
26                         $sSQL = 'insert into new_query_log (type,starttime,query,ipaddress,useragent,language,format)';
27                         $sSQL .= ' values ('.getDBQuoted($sType).','.getDBQuoted($hLog[0]).','.getDBQuoted($hLog[2]);
28                         $sSQL .= ','.getDBQuoted($hLog[1]).','.getDBQuoted($_SERVER['HTTP_USER_AGENT']).','.getDBQuoted(join(',',$aLanguageList)).','.getDBQuoted($sOutputFormat).')';
29                         $oDB->query($sSQL);
30                 }
31
32                 if (CONST_Log_File && CONST_Log_File_ReverseLog != '')
33                 {
34                         if ($sType == 'reverse')
35                         {
36                                 $aStartTime = explode('.',$hLog[0]);
37                                 file_put_contents(CONST_Log_File_ReverseLog,
38                                                                 $aStartTime[0].','.$aStartTime[1].','.
39                                                                 php_uname('n').','.
40                                                                 '"'.addslashes(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'').'",'.
41                                                                 '"'.addslashes($hLog[1]).'",'.
42                                                                 $_GET['lat'].','.
43                                                                 $_GET['lon'].','.
44                                                                 $_GET['zoom'].','.
45                                                                 '"'.addslashes($_SERVER['HTTP_USER_AGENT']).'",'.
46                                                                 '"'.addslashes($sOutputFormat).'"'."\n",
47                                                                 FILE_APPEND);
48                         }
49                 }
50
51                 return $hLog;
52         }
53
54         function logEnd(&$oDB, $hLog, $iNumResults)
55         {
56                 $aEndTime = explode('.',microtime(true));
57                 if (!$aEndTime[1]) $aEndTime[1] = '0';
58                 $sEndTime = date('Y-m-d H:i:s',$aEndTime[0]).'.'.$aEndTime[1];
59
60                 if (CONST_Log_DB)
61                 {
62                         $sSQL = 'update query_log set endtime = '.getDBQuoted($sEndTime).', results = '.$iNumResults;
63                         $sSQL .= ' where starttime = '.getDBQuoted($hLog[0]);
64                         $sSQL .= ' and ipaddress = '.getDBQuoted($hLog[1]);
65                         $sSQL .= ' and query = '.getDBQuoted($hLog[3]);
66                         $oDB->query($sSQL);
67
68                         $sSQL = 'update new_query_log set endtime = '.getDBQuoted($sEndTime).', results = '.$iNumResults;
69                         $sSQL .= ' where starttime = '.getDBQuoted($hLog[0]);
70                         $sSQL .= ' and ipaddress = '.getDBQuoted($hLog[1]);
71                         $sSQL .= ' and query = '.getDBQuoted($hLog[2]);
72                         $oDB->query($sSQL);
73                 }
74
75                 if (CONST_Log_File && CONST_Log_File_SearchLog != '')
76                 {
77                         $aStartTime = explode('.',$hLog[0]);
78                         file_put_contents(CONST_Log_File_SearchLog,
79                                         $aStartTime[0].','.$aStartTime[1].','.
80                                         php_uname('n').','.
81                                         '"'.addslashes(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'').'",'.
82                                         '"'.addslashes($hLog[1]).'",'.
83                                         '"'.addslashes($hLog[3]).'",'.
84                                         '"'.addslashes($_SERVER['HTTP_USER_AGENT']).'",'.
85                                         '"'.addslashes((isset($_GET['format']))?$_GET['format']:'').'",'.
86                                         $iNumResults."\n",
87                                         FILE_APPEND);
88                 }
89
90         }