commit | author | age
|
313e33
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
require("lib/config.inc.php"); |
|
32 |
require("lib/app.inc.php"); |
|
33 |
|
|
34 |
set_time_limit(0); |
|
35 |
|
|
36 |
// make sure server_id is always an int |
|
37 |
$conf["server_id"] = intval($conf["server_id"]); |
|
38 |
|
|
39 |
|
|
40 |
// Load required base-classes |
|
41 |
$app->uses('ini_parser,file,services'); |
|
42 |
|
|
43 |
|
|
44 |
####################################################################################################### |
|
45 |
// store the mailbox statistics in the database |
|
46 |
####################################################################################################### |
|
47 |
|
|
48 |
$sql = "SELECT mailuser_id,maildir FROM mail_user WHERE server_id = ".$conf["server_id"]; |
|
49 |
$records = $app->db->queryAllRecords($sql); |
|
50 |
foreach($records as $rec) { |
|
51 |
if(@is_file($rec["maildir"].'.ispconfig_mailsize')) { |
|
52 |
|
|
53 |
// rename file |
|
54 |
rename($rec["maildir"].'.ispconfig_mailsize',$rec["maildir"].'.ispconfig_mailsize_save'); |
|
55 |
|
|
56 |
// Read the file |
|
57 |
$lines = file($rec["maildir"].'.ispconfig_mailsize_save'); |
|
58 |
$mail_traffic = 0; |
|
59 |
foreach($lines as $line) { |
|
60 |
$mail_traffic += intval($line); |
|
61 |
} |
|
62 |
unset($lines); |
|
63 |
|
|
64 |
// Delete backup file |
|
65 |
if(@is_file($rec["maildir"].'.ispconfig_mailsize_save')) unlink($rec["maildir"].'.ispconfig_mailsize_save'); |
|
66 |
|
|
67 |
// Save the traffic stats in the sql database |
|
68 |
$tstamp = date("Y-m"); |
|
69 |
|
|
70 |
$sql = "SELECT * FROM mail_traffic WHERE month = '$tstamp' AND mailuser_id = ".$rec["mailuser_id"]; |
|
71 |
$tr = $app->db->queryOneRecord($sql); |
|
72 |
|
|
73 |
$mail_traffic += $tr["traffic"]; |
|
74 |
if($tr["traffic_id"] > 0) { |
|
75 |
$sql = "UPDATE mail_traffic SET traffic = $mail_traffic WHERE traffic_id = ".$tr["traffic_id"]; |
|
76 |
} else { |
|
77 |
$sql = "INSERT INTO mail_traffic (month,mailuser_id,traffic) VALUES ('$tstamp',".$rec["mailuser_id"].",$mail_traffic)"; |
|
78 |
} |
|
79 |
$app->db->query($sql); |
|
80 |
echo $sql; |
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
} |
|
85 |
|
|
86 |
####################################################################################################### |
|
87 |
// Create webalizer statistics |
|
88 |
####################################################################################################### |
|
89 |
|
|
90 |
|
|
91 |
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE server_id = ".$conf["server_id"]; |
|
92 |
$records = $app->db->queryAllRecords($sql); |
|
93 |
foreach($records as $rec) { |
|
94 |
$yesterday = date("mdY",time() - 86400); |
|
95 |
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log'); |
|
96 |
if(@is_file($logfile)) { |
|
97 |
$domain = escapeshellcmd($rec["domain"]); |
|
98 |
$statsdir = escapeshellcmd($rec["document_root"].'/web/stats'); |
|
99 |
$webalizer = '/usr/bin/webalizer'; |
|
100 |
$webalizer_conf = '/etc/webalizer/webalizer.conf'; |
|
101 |
if(!@is_dir($statsdir)) mkdir($statsdir); |
|
102 |
exec("$webalizer -c $webalizer_conf -n $domain -s $domain -r $domain -q -T -o $statsdir $logfile"); |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
####################################################################################################### |
|
107 |
// Manage and compress web logfiles |
|
108 |
####################################################################################################### |
|
109 |
|
|
110 |
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE server_id = ".$conf["server_id"]; |
|
111 |
$records = $app->db->queryAllRecords($sql); |
|
112 |
foreach($records as $rec) { |
|
113 |
$yesterday = date("mdY",time() - 86400); |
|
114 |
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log'); |
|
115 |
if(@is_file($logfile)) { |
|
116 |
// Compress yesterdays logfile |
|
117 |
exec("gzip -c $logfile > $logfile.gz"); |
|
118 |
} |
|
119 |
|
|
120 |
// delete logfiles after 30 days |
|
121 |
$month_ago = date("mdY",time() - 86400 * 30); |
|
122 |
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log.gz'); |
|
123 |
if(@is_file($logfile)) { |
|
124 |
unlink($logfile); |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
die("finished.\n"); |
|
134 |
?> |