root/trunk/engine/ispcp-rqst-mngr

Revision 1405, 17.7 kB (checked in by scitech, 5 days ago)

Fixed #837: AWStats password protection

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-2008 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 use FindBin;
34 use lib "$FindBin::Bin/";
35 require 'ispcp_common_code.pl';
36
37 use strict;
38
39 use warnings;
40
41 sub mngr_start_up {
42
43     my ($rs, $rdata) = (undef, undef);
44
45     push_el(\@main::el, 'mngr_start_up()', 'Starting...');
46
47     # lock check;
48
49     $rs = lock_system();
50
51     return $rs if ($rs != 0);
52
53     # Let's clear Execution Logs, if any.
54
55     if (-e $main::ispcp_rqst_mngr_el) {
56
57         $rs = del_file($main::ispcp_rqst_mngr_el);
58
59         return $rs if ($rs != 0);
60
61     }
62
63     # config check;
64
65     $rs = get_conf();
66
67     return $rs if ($rs != 0);
68
69     # sql check;
70
71     my $sql = "select admin_id from admin where admin_id = 1;";
72
73     ($rs, $rdata) = doSQL($sql);
74
75     return $rs if ($rs != 0);
76
77     push_el(\@main::el, 'mngr_start_up()', 'Ending...');
78
79     return 0;
80
81 }
82
83 sub mngr_shut_down {
84
85     my $rs = undef;
86
87     push_el(\@main::el, 'mngr_shut_down()', 'Starting...');
88
89     $rs = unlock_system();
90
91     return $rs if ($rs != 0);
92
93     push_el(\@main::el, 'mngr_shut_down()', 'Ending...');
94
95     return 0;
96
97 }
98
99 sub mngr_engine {
100
101     my ($rs, $rdata) = (undef, undef);
102
103     push_el(\@main::el, 'mngr_engine()', 'Starting...');
104
105     my $sql;
106
107     #
108     # Proceed tasks, if any.
109     #
110
111     $sql = "select domain_id, domain_name, domain_status from domain where domain_status != 'ok' order by domain_id";
112
113     ($rs, $rdata) = doSQL($sql);
114
115     my $dmn_count = @$rdata;
116
117     if ($dmn_count > 0) {
118
119         foreach (@$rdata) {
120
121             my $row = $_;
122
123             my ($dmn_id, $dmn_name, $dmn_status) = (@$row[0], @$row[1], @$row[2]);
124
125             if (
126                 $dmn_status eq "toadd" ||
127                 $dmn_status eq "change" ||
128                 $dmn_status eq "restore" ||
129                 $dmn_status eq "toenable" ||
130                 $dmn_status eq "todisable"
131                ) {
132
133                 if ($dmn_status eq "restore") {
134
135                     $dmn_count--;
136
137                 }
138
139                 if (defined($main::engine_debug)) {
140
141                     push_el(\@main::el, 'mngr_engine()', "processing $dmn_id, $dmn_name, $dmn_status.");
142
143                 }
144
145                 $rs = sys_command("$main::ispcp_dmn_mngr $dmn_id 1>$main::ispcp_dmn_mngr_stdout 2>$main::ispcp_dmn_mngr_stderr");
146
147                 if ($rs != 0) {
148
149                     if (-e $main::ispcp_dmn_mngr_el) {
150
151                         my $rs1 = undef;
152
153                         pop_el(\@main::el); # removing 'sys_command()' error message;
154
155                         ($rs1, $rdata) = get_el_error($main::ispcp_dmn_mngr_el);
156
157                         return $rs1 if ($rs1 != 0);
158
159                         push_el(\@main::el, $main::ispcp_dmn_mngr, $rdata);
160
161                     }
162
163                     if (!defined($main::engine_debug)) {
164
165                         del_file($main::ispcp_dmn_mngr_stdout); del_file($main::ispcp_dmn_mngr_stderr);
166
167                     }
168
169                     return $rs;
170
171                 }
172
173                 if (!defined($main::engine_debug)) {
174
175                     del_file($main::ispcp_dmn_mngr_stdout); del_file($main::ispcp_dmn_mngr_stderr);
176
177                 }
178
179
180             }
181
182         }
183
184     }
185
186     $sql = "select mail_id, mail_acc, status from mail_users where status != 'ok' and status != 'ordered' order by mail_id";
187
188     ($rs, $rdata) = doSQL($sql);
189
190     my $mail_count = @$rdata;
191
192     if ($mail_count > 0) {
193
194         foreach (@$rdata) {
195
196             my $row = $_;
197
198             my ($mail_id, $mail_acc, $mail_status) = (@$row[0], @$row[1], @$row[2]);
199
200             if ($mail_status eq "toadd" || $mail_status eq "change" || $mail_status eq "delete") {
201
202                 if (defined($main::engine_debug)) {
203
204                     push_el(\@main::el, 'mngr_engine()', "processing $mail_id, $mail_acc, $mail_status.");
205
206                 }
207
208             }
209
210             $rs = sys_command("$main::ispcp_mbox_mngr $mail_id 1>$main::ispcp_mbox_mngr_stdout 2>$main::ispcp_mbox_mngr_stderr");
211
212             if ($rs != 0) {
213
214                 if (-e $main::ispcp_mbox_mngr_el) {
215
216                     my $rs1 = undef;
217
218                     pop_el(\@main::el); # removing 'sys_command()' error message;
219
220                     ($rs1, $rdata) = get_el_error($main::ispcp_mbox_mngr_el);
221
222                     return $rs1 if ($rs1 != 0);
223
224                     push_el(\@main::el, $main::ispcp_mbox_mngr, $rdata);
225
226                 }
227
228                 if (!defined($main::engine_debug)) {
229
230                     del_file($main::ispcp_mbox_mngr_stdout); del_file($main::ispcp_mbox_mngr_stderr);
231
232                 }
233
234                 return $rs;
235
236             }
237
238             if (!defined($main::engine_debug)) {
239
240                 del_file($main::ispcp_mbox_mngr_stdout); del_file($main::ispcp_mbox_mngr_stderr);
241
242             }
243
244         }
245
246     }
247
248     $sql = "select subdomain_id, subdomain_name, subdomain_status from subdomain where subdomain_status != 'ok' order by subdomain_id";
249
250     ($rs, $rdata) = doSQL($sql);
251
252     my $sub_count = @$rdata;
253
254     if ($sub_count > 0) {
255
256         foreach (@$rdata) {
257
258             my $row = $_;
259
260             my ($sub_id, $sub_name, $sub_status) = (@$row[0], @$row[1], @$row[2]);
261
262             if ($sub_status eq "toadd" || $sub_status eq "change" || $sub_status eq "delete") {
263
264                 if (defined($main::engine_debug)) {
265
266                     push_el(\@main::el, 'mngr_engine()', "processing $sub_id, $sub_name, $sub_status.");
267
268                 }
269
270                 $rs = sys_command("$main::ispcp_sub_mngr $sub_id 1>$main::ispcp_sub_mngr_stdout 2>$main::ispcp_sub_mngr_stderr");
271
272                 if ($rs != 0) {
273
274                     if (-e $main::ispcp_sub_mngr_el) {
275
276                         my $rs1 = undef;
277
278                         pop_el(\@main::el); # removing 'sys_command()' error message;
279
280                         ($rs1, $rdata) = get_el_error($main::ispcp_sub_mngr_el);
281
282                         return $rs1 if ($rs1 != 0);
283
284                         push_el(\@main::el, $main::ispcp_sub_mngr, $rdata);
285
286                     }
287
288                     if (!defined($main::engine_debug)) {
289
290                         del_file($main::ispcp_sub_mngr_stdout); del_file($main::ispcp_sub_mngr_stderr);
291
292                     }
293
294                     return $rs;
295
296                 }
297
298                 if (!defined($main::engine_debug)) {
299
300                     del_file($main::ispcp_sub_mngr_stdout); del_file($main::ispcp_sub_mngr_stderr);
301
302                 }
303
304             }
305
306         }
307
308     }
309
310     $sql = "select alias_id, alias_name, alias_status from domain_aliasses where alias_status != 'ok' and alias_status != 'ordered' order by alias_id";
311
312     ($rs, $rdata) = doSQL($sql);
313
314     my $als_count = @$rdata;
315
316     if ($als_count > 0) {
317
318         foreach (@$rdata) {
319
320             my $row = $_;
321
322             my ($als_id, $als_name, $als_status) = (@$row[0], @$row[1], @$row[2]);
323
324             if ($als_status eq "toadd" || $als_status eq "change" || $als_status eq "delete") {
325
326                 if (defined($main::engine_debug)) {
327
328                     push_el(\@main::el, 'mngr_engine()', "processing $als_id, $als_name, $als_status.");
329
330                 }
331
332                 $rs = sys_command("$main::ispcp_als_mngr $als_id 1>$main::ispcp_als_mngr_stdout 2>$main::ispcp_als_mngr_stderr");
333
334                 if ($rs != 0) {
335
336                     if (-e $main::ispcp_als_mngr_el) {
337
338                         my $rs1 = undef;
339
340                         pop_el(\@main::el); # removing 'sys_command()' error message;
341
342                         ($rs1, $rdata) = get_el_error($main::ispcp_als_mngr_el);
343
344                         return $rs1 if ($rs1 != 0);
345
346                         push_el(\@main::el, $main::ispcp_als_mngr, $rdata);
347
348                     }
349
350                     if (!defined($main::engine_debug)) {
351
352                         del_file($main::ispcp_als_mngr_stdout); del_file($main::ispcp_als_mngr_stderr);
353
354                     }
355
356                     return $rs;
357
358                 }
359
360                 if (!defined($main::engine_debug)) {
361
362                     del_file($main::ispcp_als_mngr_stdout); del_file($main::ispcp_als_mngr_stderr);
363
364                 }
365
366
367             }
368
369         }
370
371     }
372
373     $sql = "select subdomain_alias_id, subdomain_alias_name, subdomain_alias_status from subdomain_alias where subdomain_alias_status != 'ok' order by subdomain_alias_id";
374
375     ($rs, $rdata) = doSQL($sql);
376
377     my $alssub_count = @$rdata;
378
379     if ($alssub_count > 0) {
380         foreach (@$rdata) {
381
382             my $row = $_;
383
384             my ($sub_id, $sub_name, $sub_status) = (@$row[0], @$row[1], @$row[2]);
385
386             if ($sub_status eq "toadd" || $sub_status eq "change" || $sub_status eq "delete") {
387
388                 if (defined($main::engine_debug)) {
389
390                     push_el(\@main::el, 'mngr_engine()', "processing $sub_id, $sub_name, $sub_status.");
391
392                 }
393
394                 $rs = sys_command("$main::ispcp_alssub_mngr $sub_id 1>$main::ispcp_alssub_mngr_stdout 2>$main::ispcp_alssub_mngr_stderr");
395
396                 if ($rs != 0) {
397
398                     if (-e $main::ispcp_alssub_mngr_el) {
399
400                         my $rs1 = undef;
401
402                         pop_el(\@main::el); # removing 'sys_command()' error message;
403
404                         ($rs1, $rdata) = get_el_error($main::ispcp_alssub_mngr_el);
405
406                         return $rs1 if ($rs1 != 0);
407
408                         push_el(\@main::el, $main::ispcp_alssub_mngr, $rdata);
409
410                     }
411
412                     if (!defined($main::engine_debug)) {
413
414                         del_file($main::ispcp_alssub_mngr_stdout); del_file($main::ispcp_alssub_mngr_stderr);
415
416                     }
417
418                     return $rs;
419
420                 }
421
422                 if (!defined($main::engine_debug)) {
423
424                     del_file($main::ispcp_alssub_mngr_stdout); del_file($main::ispcp_alssub_mngr_stderr);
425
426                 }
427
428             }
429
430         }
431
432     }
433
434     if ($dmn_count > 0 || $sub_count > 0 || $als_count > 0 || $mail_count > 0 || $alssub_count > 0) {
435
436         $rs = sys_command("$main::ispcp_serv_mngr $dmn_count $sub_count $als_count $mail_count $alssub_count 1>$main::ispcp_serv_mngr_stdout 2>$main::ispcp_serv_mngr_stderr");
437
438         if ($rs != 0) {
439
440             if (-e $main::ispcp_serv_mngr_el) {
441
442                 my $rs1 = undef;
443
444                 pop_el(\@main::el); # removing 'sys_command()' error message;
445
446                 ($rs1, $rdata) = get_el_error($main::ispcp_serv_mngr_el);
447
448                 return $rs1 if ($rs1 != 0);
449
450                 push_el(\@main::el, $main::ispcp_serv_mngr, $rdata);
451
452             }
453
454             if (!defined($main::engine_debug)) {
455
456                 del_file($main::ispcp_serv_mngr_stdout); del_file($main::ispcp_serv_mngr_stderr);
457
458             }
459
460             return $rs;
461
462         }
463
464         if (!defined($main::engine_debug)) {
465
466             del_file($main::ispcp_serv_mngr_stdout); del_file($main::ispcp_serv_mngr_stderr);
467
468         }
469
470
471     }
472
473     $sql = "select domain_id, domain_name, domain_status from domain where domain_status != 'ok' order by domain_id";
474
475     ($rs, $rdata) = doSQL($sql);
476
477     $dmn_count = @$rdata;
478
479     if ($dmn_count > 0) {
480
481         foreach (@$rdata) {
482
483             my $row = $_;
484
485             my ($dmn_id, $dmn_name, $dmn_status) = (@$row[0], @$row[1], @$row[2]);
486
487             if ($dmn_status eq "delete") {
488
489                 if (defined($main::engine_debug)) {
490
491                     push_el(\@main::el, 'mngr_engine()', "processing $dmn_id, $dmn_name, $dmn_status.");
492
493                 }
494
495                 $rs = sys_command("$main::ispcp_dmn_mngr $dmn_id 1>$main::ispcp_dmn_mngr_stdout 2>$main::ispcp_dmn_mngr_stderr");
496
497                 if ($rs != 0) {
498
499                     if (-e $main::ispcp_dmn_mngr_el) {
500
501                         my $rs1 = undef;
502
503                         pop_el(\@main::el); # removing 'sys_command()' error message;
504
505                         ($rs1, $rdata) = get_el_error($main::ispcp_dmn_mngr_el);
506
507                         return $rs1 if ($rs1 != 0);
508
509                         push_el(\@main::el, $main::ispcp_dmn_mngr, $rdata);
510
511                     }
512
513                     if (!defined($main::engine_debug)) {
514
515                         del_file($main::ispcp_dmn_mngr_stdout); del_file($main::ispcp_dmn_mngr_stderr);
516
517                     }
518
519                     return $rs;
520
521                 }
522
523                 if (!defined($main::engine_debug)) {
524
525                     del_file($main::ispcp_dmn_mngr_stdout); del_file($main::ispcp_dmn_mngr_stderr);
526
527                 }
528
529
530             }
531
532         }
533
534     }
535
536         #
537         # .htusers management BEGIN.
538         #
539
540         $sql = "select `id`, `status` from `htaccess_users` where `status` != 'ok' order by `id`";
541
542         ($rs, $rdata) = doSQL($sql);
543
544         my $htusers_count = @$rdata;
545
546         if ($htusers_count > 0) {
547
548                 foreach (@$rdata) {
549
550                         my $row = $_;
551
552                         my ($htusers_id, $htusers_status) = (@$row[0], @$row[1]);
553
554                         if ($htusers_status eq "toadd" || $htusers_status eq "change" || $htusers_status eq "delete") {
555
556                                 push_el(\@main::el, 'mngr_engine()', "processing $htusers_id, $htusers_status.")
557
558                                         if (defined($main::engine_debug));
559
560                                 $rs = sys_command("$main::ispcp_htusers_mngr $htusers_id 1>$main::ispcp_htusers_mngr_stdout 2>$main::ispcp_htusers_mngr_stderr");
561
562                                 if ($rs != 0) {
563
564                                         if (-e $main::ispcp_htusers_mngr_el) {
565
566                                                 my $rs1 = undef;
567
568                                                 pop_el(\@main::el); # removing 'sys_command()' error message;
569
570                                                 ($rs1, $rdata) = get_el_error($main::ispcp_htusers_mngr_el);
571
572                                                 return $rs1 if ($rs1 != 0);
573
574                                                 push_el(\@main::el, $main::ispcp_htusers_mngr, $rdata);
575
576                                         }
577
578                                         if (!defined($main::engine_debug)) {
579
580                                                 del_file($main::ispcp_htusers_mngr_stdout); del_file($main::ispcp_htusers_mngr_stderr);
581
582                                         }
583
584                                         return $rs;
585
586                                 }
587
588                                 if (!defined($main::engine_debug)) {
589
590                                         del_file($main::ispcp_htusers_mngr_stdout); del_file($main::ispcp_htusers_mngr_stderr);
591
592                                 }
593
594                         }
595
596                 }
597
598         }
599
600         #
601         # .htusers management END.
602         #
603
604         #
605         # .htgroups management BEGIN.
606         #
607
608         $sql = "select `dmn_id`, `id`, `status` from `htaccess_groups` where `status` in ('toadd', 'change', 'delete') group by `dmn_id` order by `dmn_id`";
609
610         ($rs, $rdata) = doSQL($sql);
611
612         my $htgroups_count = @$rdata;
613
614         if ($htgroups_count > 0) {
615
616                 foreach (@$rdata) {
617
618                         my $row = $_;
619
620                         my ($htdmn_id, $htgroups_id, $htgroups_status) = (@$row[0], @$row[1], @$row[2]);
621
622                         push_el(\@main::el, 'mngr_engine()', "processing $htdmn_id -> $htgroups_id, $htgroups_status.")
623
624                                 if (defined($main::engine_debug));
625
626                         $rs = sys_command("$main::ispcp_htgroups_mngr $htdmn_id 1>$main::ispcp_htgroups_mngr_stdout 2>$main::ispcp_htgroups_mngr_stderr");
627
628                         if ($rs != 0) {
629
630                                 if (-e $main::ispcp_htgroups_mngr_el) {
631
632                                         my $rs1 = undef;
633
634                                         pop_el(\@main::el); # removing 'sys_command()' error message;
635                                         ($rs1, $rdata) = get_el_error($main::ispcp_htgroups_mngr_el);
636
637                                         return $rs1 if ($rs1 != 0);
638
639                                         push_el(\@main::el, $main::ispcp_htgroups_mngr, $rdata);
640
641                                 }
642
643                                 if (!defined($main::engine_debug)) {
644
645                                         del_file($main::ispcp_htgroups_mngr_stdout); del_file($main::ispcp_htgroups_mngr_stderr);
646
647                                 }
648
649                                 return $rs;
650
651                         }
652
653                         if (!defined($main::engine_debug)) {
654
655                                 del_file($main::ispcp_htgroups_mngr_stdout); del_file($main::ispcp_htgroups_mngr_stderr);
656
657                         }
658
659                 }
660
661         }
662
663         #
664         # .htgroups management END.
665         #
666
667         #
668         # .htaccess management BEGIN.
669         #
670
671         $sql = "select id, status from htaccess where status != 'ok' order by id";
672
673         ($rs, $rdata) = doSQL($sql);
674
675         my $htaccess_count = @$rdata;
676
677         if ($htaccess_count > 0) {
678
679                 foreach (@$rdata) {
680
681                         my $row = $_;
682
683                         my ($htaccess_id, $htaccess_status) = (@$row[0], @$row[1]);
684
685                         if ($htaccess_status eq "toadd" || $htaccess_status eq "change" || $htaccess_status eq "delete") {
686
687                                 push_el(\@main::el, 'mngr_engine()', "processing $htaccess_id, $htaccess_status.")
688
689                                         if (defined($main::engine_debug));
690
691                                 $rs = sys_command("$main::ispcp_htaccess_mngr $htaccess_id 1>$main::ispcp_htaccess_mngr_stdout 2>$main::ispcp_htaccess_mngr_stderr");
692
693                                 if ($rs != 0) {
694
695                                         if (-e $main::ispcp_htaccess_mngr_el) {
696
697                                                 my $rs1 = undef;
698
699                                                 pop_el(\@main::el); # removing 'sys_command()' error message;
700
701                                                 ($rs1, $rdata) = get_el_error($main::ispcp_htaccess_mngr_el);
702
703                                                 return $rs1 if ($rs1 != 0);
704
705                                                 push_el(\@main::el, $main::ispcp_htaccess_mngr, $rdata);
706
707                                         }
708
709                                         if (!defined($main::engine_debug)) {
710
711                                                 del_file($main::ispcp_htaccess_mngr_stdout); del_file($main::ispcp_htaccess_mngr_stderr);
712
713                                         }
714
715                                         return $rs;
716
717                                 }
718
719                                 if (!defined($main::engine_debug)) {
720
721                                         del_file($main::ispcp_htaccess_mngr_stdout); del_file($main::ispcp_htaccess_mngr_stderr);
722
723                                 }
724
725                         }
726
727                 }
728
729         }
730
731         #
732         # .htaccess management END.
733         #
734
735         push_el(\@main::el, 'mngr_engine()', 'Ending...');
736
737         return 0;
738
739 }
740
741 my $rs = undef;
742
743 $rs = mngr_start_up();
744
745 if ($rs != 0) {
746
747     dump_el(\@main::el, $main::ispcp_rqst_mngr_el);
748
749     mngr_shut_down();
750
751     exit 1;
752
753 }
754
755 $rs = mngr_engine();
756
757 if ($rs != 0) {
758
759     dump_el(\@main::el, $main::ispcp_rqst_mngr_el);
760
761     mngr_shut_down();
762
763     exit 1;
764
765 }
766
767 $rs = mngr_shut_down();
768
769 if ($rs != 0) {
770
771     dump_el(\@main::el, $main::ispcp_rqst_mngr_el);
772
773     exit 1;
774
775 }
Note: See TracBrowser for help on using the browser.