|
87 | 87 | // Create webalizer statistics |
88 | 88 | ####################################################################################################### |
89 | 89 |
|
| 90 | +function setConfigVar( $filename, $varName, $varValue ) { |
| 91 | + if($lines = @file($filename)) { |
| 92 | + $out = ''; |
| 93 | + $found = 0; |
| 94 | + foreach($lines as $line) { |
| 95 | + list($key, $value) = split("[\t= ]+", $line, 2); |
| 96 | + if($key == $varName) { |
| 97 | + $out .= $varName." ".$varValue."\n"; |
| 98 | + $found = 1; |
| 99 | + } else { |
| 100 | + $out .= $line; |
| 101 | + } |
| 102 | + } |
| 103 | + if($found == 0) { |
| 104 | + //* add \n if the last line does not end with \n or \r |
| 105 | + if(substr($out,-1) != "\n" && substr($out,-1) != "\r") $out .= "\n"; |
| 106 | + //* add the new line at the end of the file |
| 107 | + if($append == 1) $out .= $varName." ".$varValue."\n"; |
| 108 | + } |
| 109 | + |
| 110 | + file_put_contents($filename,$out); |
| 111 | + } |
| 112 | +} |
| 113 | + |
90 | 114 |
|
91 | 115 | $sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE server_id = ".$conf["server_id"]; |
92 | 116 | $records = $app->db->queryAllRecords($sql); |
| 117 | + |
93 | 118 | foreach($records as $rec) { |
94 | 119 | $yesterday = date("Ymd",time() - 86400); |
95 | 120 | $logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log'); |
96 | 121 | if(!@is_file($logfile)) { |
97 | 122 | $logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log.gz'); |
98 | | - if(!@is_file($logfile)) { |
99 | | - continue; |
100 | | - } |
| 123 | + if(!@is_file($logfile)) { |
| 124 | + continue; |
101 | 125 | } |
102 | | - $domain = escapeshellcmd($rec["domain"]); |
103 | | - $statsdir = escapeshellcmd($rec["document_root"].'/web/stats'); |
104 | | - $webalizer = '/usr/bin/webalizer'; |
105 | | - $webalizer_conf = '/etc/webalizer/webalizer.conf'; |
106 | | - if(!@is_dir($statsdir)) mkdir($statsdir); |
| 126 | +} |
| 127 | + |
| 128 | +$domain = escapeshellcmd($rec["domain"]); |
| 129 | +$statsdir = escapeshellcmd($rec["document_root"].'/web/stats'); |
| 130 | +$webalizer = '/usr/bin/webalizer'; |
| 131 | +$webalizer_conf_main = '/etc/webalizer/webalizer.conf'; |
| 132 | +$webalizer_conf = escapeshellcmd($rec["document_root"].'/log/webalizer.conf'); |
| 133 | + |
| 134 | +if(!@is_file($webalizer_conf)) { |
| 135 | + exec("cp $webalizer_conf_main $webalizer_conf"); |
| 136 | + |
| 137 | + setConfigVar($webalizer_conf, 'Incremental', 'yes'); |
| 138 | + setConfigVar($webalizer_conf, 'IncrementalName', $logdir.'/webalizer.current'); |
| 139 | + setConfigVar($webalizer_conf, 'HistoryName', $logdir.'/webalizer.hist'); |
| 140 | +} |
| 141 | + |
| 142 | +if(!@is_dir($statsdir)) mkdir($statsdir); |
107 | 143 | exec("$webalizer -c $webalizer_conf -n $domain -s $domain -r $domain -q -T -p -o $statsdir $logfile"); |
108 | 144 | } |
109 | 145 |
|
|
0 commit comments