root/tags/omega-1.0.0-rc3/engine/tools/ispcp-httpd-logs-mngr

Revision 595, 8.5 KB (checked in by rats, 20 months ago)

in addition to #256 changed some license things

Line 
1#!/usr/bin/perl
2
3# ispCP ω (OMEGA) a Virtual Hosting Control Panel
4# Copyright (c) 2001-2006 by moleSoftware GmbH
5# http://www.molesoftware.com
6# Copyright (c) 2006-2007 by isp Control Panel
7# http://isp-control.net
8#
9#
10# License:
11#    This program is free software; you can redistribute it and/or
12#    modify it under the terms of the MPL Mozilla Public License
13#    as published by the Free Software Foundation; either version 1.1
14#    of the License, or (at your option) any later version.
15#
16#    This program is distributed in the hope that it will be useful,
17#    but WITHOUT ANY WARRANTY; without even the implied warranty of
18#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19#    MPL Mozilla Public License for more details.
20#
21#    You may have received a copy of the MPL Mozilla Public License
22#    along with this program.
23#
24#    An on-line copy of the MPL Mozilla Public License can be found
25#    http://www.mozilla.org/MPL/MPL-1.1.html
26#
27#
28# The ispCP ω Home Page is at:
29#
30#    http://isp-control.net
31#
32
33
34use FindBin;
35use lib "$FindBin::Bin/..";
36require 'ispcp_common_code.pl';
37
38use strict;
39
40use warnings;
41
42my $rs = undef;
43
44sub httpd_logs_mngr_start_up {
45
46    my ($rs, $rdata) = (undef, undef);
47
48    push_el(\@main::el, 'httpd_logs_mngr_start_up()', 'Starting...');
49
50    # Let's clear Execution Logs, if any.
51
52    if (-e $main::ispcp_httpd_logs_mngr_el) {
53
54        $rs = del_file($main::ispcp_httpd_logs_mngr_el);
55
56        return $rs if ($rs != 0);
57
58    }
59
60    # config check;
61
62    $rs = get_conf();
63
64    return $rs if ($rs != 0);
65
66    #
67    # getting initial data also must be done here;
68    #
69
70    my $sql = "select * from domain;";
71
72    ($rs, $rdata) = doSQL($sql);
73
74    return $rs if ($rs != 0);
75
76    push_el(\@main::el, 'httpd_logs_mngr_start_up()', 'Ending...');
77
78    return 0;
79
80}
81
82sub copy_subdomain_logs {
83
84    my ($rs, $rows) = (undef, undef);
85
86    push_el(\@main::el, 'copy_subdomain_logs()', 'Starting...');
87
88    my $sql = "select t1.subdomain_name, t2.domain_name, t2.domain_uid from subdomain as t1, domain as t2 where t1.domain_id = t2.domain_id and t1.subdomain_status = 'ok' order by t1.subdomain_id;";
89
90    ($rs, $rows) = doSQL($sql);
91
92    return $rs if ($rs != 0);
93
94    if (scalar(@$rows) > 0) {
95
96        foreach (@$rows) {
97
98            my ($sub_pref, $domain_name, $domain_uid) = (@$_[0], @$_[1], @$_[2]);
99
100            my $subdomain_name = "$sub_pref.$domain_name";
101
102            my $src_access_file = "$main::cfg{'APACHE_USERS_LOG_DIR'}/$subdomain_name-access.log";
103
104            my $dest_access_file = "$main::cfg{'APACHE_WWW_DIR'}/$domain_name/logs/$subdomain_name-access.log";
105
106            my $src_error_file = "$main::cfg{'APACHE_USERS_LOG_DIR'}/$subdomain_name-error.log";
107
108            my $dest_error_file = "$main::cfg{'APACHE_WWW_DIR'}/$domain_name/logs/$subdomain_name-error.log";
109
110            my $dest_dir = "$main::cfg{'APACHE_WWW_DIR'}/$domain_name/logs";
111
112            if (! -d $dest_dir)
113            {
114               $rs = make_dir($dest_dir, $domain_uid, $main::cfg{'APACHE_GROUP'}, 0770);
115
116               return $rs if ($rs != 0);
117
118            }
119
120            my $cmd_cp = "$main::cfg{'CMD_CP'} -f $src_access_file $dest_access_file";
121
122            $rs = sys_command($cmd_cp);
123
124            return $rs if ($rs != 0);
125
126            $rs = setfmode($dest_access_file, $main::cfg{'APACHE_USER'}, $main::cfg{'APACHE_GROUP'}, 0666);
127
128            return $rs if ($rs != 0);
129
130            $cmd_cp = "$main::cfg{'CMD_CP'} -f $src_error_file $dest_error_file";
131
132            $rs = sys_command($cmd_cp);
133
134            return $rs if ($rs != 0);
135
136            $rs = setfmode($dest_error_file, $main::cfg{'APACHE_USER'}, $main::cfg{'APACHE_GROUP'}, 0666);
137
138            return $rs if ($rs != 0);
139
140        }
141
142    }
143
144    push_el(\@main::el, 'copy_subdomain_logs()', 'Ending...');
145
146    return 0;
147
148}
149
150sub copy_domain_logs {
151
152    my ($rs, $rows) = (undef, undef);
153
154    push_el(\@main::el, 'copy_domain_logs()', 'Starting...');
155
156    my $sql = "select domain_name, domain_uid from domain where domain_status = 'ok' order by domain_id";
157
158    ($rs, $rows) = doSQL($sql);
159
160    return $rs if ($rs != 0);
161
162    if (scalar(@$rows) > 0) {
163
164        foreach (@$rows) {
165
166            my ($domain_name, $domain_uid ) = (@$_[0], @$_[1]);
167
168            my $src_access_file = "$main::cfg{'APACHE_USERS_LOG_DIR'}/$domain_name-access.log";
169
170            my $dest_access_file = "$main::cfg{'APACHE_WWW_DIR'}/$domain_name/logs/$domain_name-access.log";
171
172            my $src_error_file = "$main::cfg{'APACHE_USERS_LOG_DIR'}/$domain_name-error.log";
173
174            my $dest_error_file = "$main::cfg{'APACHE_WWW_DIR'}/$domain_name/logs/$domain_name-error.log";
175
176            my $dest_dir = "$main::cfg{'APACHE_WWW_DIR'}/$domain_name/logs";
177
178            if (! -d $dest_dir)
179            {
180               $rs = make_dir($dest_dir, $domain_uid, $main::cfg{'APACHE_GROUP'}, 0770);
181
182               return $rs if ($rs != 0);
183
184            }
185
186            my $cmd_cp = "$main::cfg{'CMD_CP'} -f $src_access_file $dest_access_file";
187
188            $rs = sys_command($cmd_cp);
189
190            return $rs if ($rs != 0);
191
192            $rs = setfmode($dest_access_file, $main::cfg{'APACHE_USER'}, $main::cfg{'APACHE_GROUP'}, 0666);
193
194            return $rs if ($rs != 0);
195
196            $cmd_cp = "$main::cfg{'CMD_CP'} -f $src_error_file $dest_error_file";
197
198            $rs = sys_command($cmd_cp);
199
200            return $rs if ($rs != 0);
201
202            $rs = setfmode($dest_error_file, $main::cfg{'APACHE_USER'}, $main::cfg{'APACHE_GROUP'}, 0666);
203
204            return $rs if ($rs != 0);
205
206        }
207
208    }
209
210    push_el(\@main::el, 'copy_domain_logs()', 'Ending...');
211
212    return 0;
213
214}
215
216sub copy_alias_logs {
217
218    my ($rs, $rows) = (undef, undef);
219
220    push_el(\@main::el, 'copy_alias_logs()', 'Starting...');
221
222    my $sql = "select t1.*, t2.* from domain_aliasses as t1, domain as t2 where t1.domain_id = t2.domain_id and t1.alias_status = 'ok'";
223
224    ($rs, $rows) = doSQL($sql);
225
226    return $rs if ($rs != 0);
227
228    if (scalar(@$rows) > 0) {
229
230        foreach (@$rows) {
231
232            my $als_name = @$_[2];
233
234            my $domain_uid = @$_[10];
235
236            my $als_mount = @$_[4];
237
238            my $dmn_name = @$_[8];
239
240            my $src_access_file = "$main::cfg{'APACHE_USERS_LOG_DIR'}/$als_name-access.log";
241
242            my $dest_access_file = "$main::cfg{'APACHE_WWW_DIR'}/$dmn_name$als_mount/logs/$als_name-access.log";
243
244            my $src_error_file = "$main::cfg{'APACHE_USERS_LOG_DIR'}/$als_name-error.log";
245
246            my $dest_error_file = "$main::cfg{'APACHE_WWW_DIR'}/$dmn_name$als_mount/logs/$als_name-error.log";
247
248            my $dest_dir = "$main::cfg{'APACHE_WWW_DIR'}/$dmn_name$als_mount/logs";
249
250            if (! -d $dest_dir)
251            {
252               $rs = make_dir($dest_dir, $domain_uid, $main::cfg{'APACHE_GROUP'}, 0770);
253
254               return $rs if ($rs != 0);
255
256            }
257
258            my $cmd_cp = "$main::cfg{'CMD_CP'} -f $src_access_file $dest_access_file";
259
260            $rs = sys_command($cmd_cp);
261
262            return $rs if ($rs != 0);
263
264            $rs = setfmode($dest_access_file, $main::cfg{'APACHE_USER'}, $main::cfg{'APACHE_GROUP'}, 0666);
265
266            return $rs if ($rs != 0);
267
268            $cmd_cp = "$main::cfg{'CMD_CP'} -f $src_error_file $dest_error_file";
269
270            $rs = sys_command($cmd_cp);
271
272            return $rs if ($rs != 0);
273
274            $rs = setfmode($dest_error_file, $main::cfg{'APACHE_USER'}, $main::cfg{'APACHE_GROUP'}, 0666);
275
276            return $rs if ($rs != 0);
277
278        }
279
280    }
281
282    push_el(\@main::el, 'copy_alias_logs()', 'Ending...');
283
284    return 0;
285
286}
287
288sub httpd_logs_mngr_engine {
289
290    my ($rs, $rdata) = (undef, undef);
291
292    push_el(\@main::el, 'httpd_logs_mngr_engine_up()', 'Starting...');
293
294    $rs = copy_subdomain_logs();
295
296    return $rs if ($rs != 0);
297
298    $rs = copy_domain_logs();
299
300    return $rs if ($rs != 0);
301
302    $rs = copy_alias_logs();
303
304    return $rs if ($rs != 0);
305
306    push_el(\@main::el, 'httpd_logs_mngr_engine_up()', 'Ending...');
307
308    return 0;
309
310}
311
312sub httpd_logs_mngr_shut_down {
313
314    my $rs = undef;
315
316    push_el(\@main::el, 'httpd_logs_mngr_shut_down()', 'Starting...');
317
318    push_el(\@main::el, 'httpd_logs_mngr_shut_down()', 'Ending...');
319
320    return 0;
321
322}
323
324$rs = httpd_logs_mngr_start_up();
325
326if ($rs != 0) {
327
328    dump_el(\@main::el, $main::ispcp_httpd_logs_mngr_el);
329
330    httpd_logs_mngr_shut_down();
331
332    exit 1;
333
334}
335
336
337$rs = httpd_logs_mngr_engine();
338
339if ($rs != 0) {
340
341    dump_el(\@main::el, $main::ispcp_httpd_logs_mngr_el);
342
343    httpd_logs_mngr_shut_down();
344
345    exit 1;
346
347}
348
349
350$rs = httpd_logs_mngr_shut_down();
351
352if ($rs != 0) {
353
354    dump_el(\@main::el, $main::ispcp_httpd_logs_mngr_el);
355
356    exit 1;
357
358}
359
360exit 0;
361
Note: See TracBrowser for help on using the browser.