root/tags/omega-1.0.0-rc2/engine/ispcp-als-mngr

Revision 512, 53.9 kB (checked in by rats, 2 years ago)

- DISTS:

  • Fedora: updated files
  • Gentoo: updated files

- GUI:

  • fixed bug #165: encoding not set
  • changed all ISPCP Pro to ispCP
  • changed debugger layout

- TOOLS:

  • PMA update 2.10.2-RC1
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
34 use FindBin;
35 use lib "$FindBin::Bin/";
36 require 'ispcp_common_code.pl';
37
38 use strict;
39
40 use warnings;
41
42 $main::als_task_id = undef;
43
44 sub als_mngr_start_up {
45
46     my ($rs, $rdata) = (undef, undef);
47
48     push_el(\@main::el, 'als_mngr_start_up()', 'Starting...');
49
50     # checking for master process;
51
52     $rs = check_master();
53
54     return $rs if ($rs != 0);
55
56     # Let's clear Execution Logs, if any.
57
58     if (-e $main::ispcp_als_mngr_el) {
59
60         $rs = del_file($main::ispcp_als_mngr_el);
61
62         return $rs if ($rs != 0);
63
64     }
65
66     # config check;
67
68     $rs = get_conf();
69
70     return $rs if ($rs != 0);
71
72     # sql check;
73
74     #
75     # getting initial data also must be done here;
76     #
77
78     my $sql = "select * from domain;";
79
80     ($rs, $rdata) = doSQL($sql);
81
82     return $rs if ($rs != 0);
83
84     $rs = get_domain_ids();
85
86     return $rs if ($rs != 0);
87
88     $rs = get_subdom_ids();
89
90     return $rs if ($rs != 0);
91
92     $rs = get_alias_ids();
93
94     return $rs if ($rs != 0);
95
96     $rs = get_ip_nums();
97
98     return $rs if ($rs != 0);
99
100
101     #
102     # getting task id and domain record id;
103     #
104
105     $main::als_task_id = $ARGV[0];
106
107     push_el(\@main::el, 'als_mngr_start_up()', 'Ending...');
108
109     return 0;
110
111 }
112
113 sub als_mngr_shut_down {
114
115     my $rs = undef;
116
117     push_el(\@main::el, 'als_mngr_shut_down()', 'Starting...');
118
119     push_el(\@main::el, 'als_mngr_shut_down()', 'Ending...');
120
121     return 0;
122
123 }
124
125 #
126 # domain named data managment;
127 #
128
129 sub als_add_named_cfg_data {
130
131     my ($als_data) = @_;
132
133     my ($rs, $rdata) = (undef, undef);
134
135     push_el(\@main::el, 'als_add_named_cfg_data()', 'Starting...');
136
137     if (!defined($als_data) || $als_data eq '') {
138
139         push_el(\@main::el, 'als_add_named_cfg_data()', 'ERROR: Undefined Input Data...');
140
141         return -1;
142
143     }
144
145     #
146     # Initial data we need;
147     #
148
149     my $als_name = @$als_data[2];
150
151     my $conf_dir = $main::cfg{'CONF_DIR'};
152
153     my $sys_cfg = $main::cfg{'BIND_CONF_FILE'};
154
155     my $named_db_dir = $main::cfg{'BIND_DB_DIR'};
156
157
158     my $tpl_dir = "$conf_dir/bind/parts";
159
160     my $backup_dir = "$conf_dir/bind/backup";
161
162     my $working_dir = "$conf_dir/bind/working";
163
164
165     my $timestamp = time;
166
167     my $backup_cfg = "$backup_dir/named.conf.$timestamp";
168
169     my $working_cfg = "$working_dir/named.conf";
170
171     #
172     #  BEGIN/END tags, and templates needed for this config;
173     #
174
175     my ($dta_b, $dta_e, $entry_b, $entry_e, $entry) = ('', '', '', '', '');
176
177     (
178      $rs,
179      $dta_b,
180      $dta_e,
181      $entry_b,
182      $entry_e,
183      $entry
184     ) = get_tpl(
185                 $tpl_dir,
186                 'cfg_dta_b.tpl',
187                 'cfg_dta_e.tpl',
188                 'cfg_entry_b.tpl',
189                 'cfg_entry_e.tpl',
190                 'cfg_entry.tpl'
191                );
192
193     return $rs if ($rs != 0);
194
195     #
196     # Let's construct nedded tags and entries;
197     #
198
199     my %tag_hash = (
200                     '{DMN_NAME}' => $als_name,
201                     '{DB_DIR}' => $named_db_dir
202                    );
203
204     my ($entry_b_val, $entry_e_val, $entry_val) = ('', '', '');
205
206     (
207      $rs,
208      $entry_b_val,
209      $entry_e_val,
210      $entry_val
211     ) = prep_tpl(
212                  \%tag_hash,
213                  $entry_b,
214                  $entry_e,
215                  $entry
216                 );
217
218     return $rs if ($rs != 0);
219
220     #
221     # Let's get Sytem and Workind config files;
222     #
223
224     my ($sys, $working) = ('', '');
225
226
227     ($rs, $sys) = get_file($sys_cfg);
228
229     return $rs  if ($rs != 0);
230
231     ($rs, $working) = get_file($working_cfg);
232
233     return $rs  if ($rs != 0);
234
235     ($rs, $rdata) = get_tag($dta_b, $dta_e, $working);
236
237     return $rs if ($rs != 0);
238
239     #
240     # Is the new domain entry exists ?
241     #
242
243     ($rs, $rdata) = get_tag($entry_b_val, $entry_e_val, $working);
244
245     if ($rs == 0) {
246
247         # Yes it exists ! Then we must delete it !
248
249         ($rs, $working) = del_tag($entry_b_val, "$entry_e_val\n", $working);
250
251         return $rs if ($rs != 0);
252
253     }
254
255     ($rs, $rdata) = get_tag($entry_b, $entry_e, $working);
256
257     return $rs if ($rs != 0);
258
259     #
260     # Let's contruct the replacement and do it;
261     #
262
263     my $entry_repl = "$entry_b_val$entry_val$entry_e_val\n$entry_b$entry_e";
264
265     ($rs, $working) = repl_tag($entry_b, $entry_e, $working, $entry_repl);
266
267     return $rs if ($rs != 0);
268
269     #
270     # Here we'll backup production config file;
271     #
272
273     $rs = sys_command("cp -p $sys_cfg $backup_cfg");
274
275     return $rs if ($rs != 0);
276
277     #
278     # Let's save working copy;
279     #
280
281     $rs = store_file($working_cfg, $working, 'root', 'root', 0644);
282
283     return $rs if ($rs != 0);
284
285     #
286     # Here we'll replace data in production config file with data in working
287     # confing file. A little workaround will be done. If working copy data does not exist
288     # in production config then we will add it;
289     #
290
291     ($rs, $rdata) = get_tag($dta_b, $dta_e, $sys);
292
293     if ($rs == 0) { # YES ! Data is here ! /in production config file/;
294
295         ($rs, $sys) = repl_tag($dta_b, $dta_e, $sys, $working);
296
297         return $rs if ($rs != 0);
298
299     } elsif ($rs == -5) {
300
301         $sys .= $working;
302
303     } else {
304
305         return $rs;
306
307     }
308
309     $rs = store_file($sys_cfg, $sys, 'root', 'root', 0644);
310
311     return $rs if ($rs != 0);
312
313
314     push_el(\@main::el, 'als_add_named_cfg_data()', 'Ending...');
315
316     return 0;
317 }
318
319 sub als_del_named_cfg_data {
320
321     my ($als_data) = @_;
322
323     my ($rs, $rdata) = (undef, undef);
324
325     push_el(\@main::el, 'als_del_named_cfg_data()', 'Starting...');
326
327     if (!defined($als_data) || $als_data eq '') {
328
329         push_el(\@main::el, 'als_del_named_cfg_data()', 'ERROR: Undefined Input Data...');
330
331         return -1;
332
333     }
334
335     #
336     # Initial data we need;
337     #
338
339     my $als_name = @$als_data[2];
340
341     my $conf_dir = $main::cfg{'CONF_DIR'};
342
343     my $sys_cfg = $main::cfg{'BIND_CONF_FILE'};
344
345     my $named_db_dir = $main::cfg{'BIND_DB_DIR'};
346
347
348     my $tpl_dir = "$conf_dir/bind/parts";
349
350     my $backup_dir = "$conf_dir/bind/backup";
351
352     my $working_dir = "$conf_dir/bind/working";
353
354
355     my $timestamp = time;
356
357     my $backup_cfg = "$backup_dir/named.conf.$timestamp";
358
359     my $working_cfg = "$working_dir/named.conf";
360
361     #
362     #  BEGIN/END tags, and templates needed for this config;
363     #
364
365     my ($dta_b, $dta_e, $entry_b, $entry_e, $entry) = ('', '', '', '', '');
366
367     (
368      $rs,
369      $dta_b,
370      $dta_e,
371      $entry_b,
372      $entry_e,
373      $entry
374     ) = get_tpl(
375                 $tpl_dir,
376                 'cfg_dta_b.tpl',
377                 'cfg_dta_e.tpl',
378                 'cfg_entry_b.tpl',
379                 'cfg_entry_e.tpl',
380                 'cfg_entry.tpl'
381                );
382
383     return $rs if ($rs != 0);
384
385     #
386     # Let's construct nedded tags and entries;
387     #
388
389     my %tag_hash = (
390                     '{DMN_NAME}' => $als_name,
391                     '{DB_DIR}' => $named_db_dir
392                    );
393
394     my ($entry_b_val, $entry_e_val, $entry_val) = ('', '', '');
395
396     (
397      $rs,
398      $entry_b_val,
399      $entry_e_val,
400      $entry_val
401     ) = prep_tpl(
402                  \%tag_hash,
403                  $entry_b,
404                  $entry_e,
405                  $entry
406                 );
407
408     return $rs if ($rs != 0);
409
410     #
411     # Let's get Sytem and Workind config files;
412     #
413
414     my ($sys, $working) = ('', '');
415
416
417     ($rs, $sys) = get_file($sys_cfg);
418
419     return $rs  if ($rs != 0);
420
421     ($rs, $working) = get_file($working_cfg);
422
423     return $rs  if ($rs != 0);
424
425     ($rs, $rdata) = get_tag($dta_b, $dta_e, $working);
426
427     return $rs if ($rs != 0);
428
429     #
430     # Is the new domain entry exists ?
431     #
432
433     ($rs, $rdata) = get_tag($entry_b_val, $entry_e_val, $working);
434
435     if ($rs == 0) {
436
437         # Yes it exists ! Then we must delete it !
438
439         ($rs, $working) = del_tag($entry_b_val, "$entry_e_val\n", $working);
440
441         return $rs if ($rs != 0);
442
443     }
444
445     ($rs, $rdata) = get_tag($entry_b, $entry_e, $working);
446
447     return $rs if ($rs != 0);
448
449     #
450     # Let's contruct the replacement and do it;
451     #
452     #
453     #my $entry_repl = "$entry_b_val$entry_val$entry_e_val\n$entry_b$entry_e";
454     #
455     #($rs, $working) = repl_tag($entry_b, $entry_e, $working, $entry_repl);
456     #
457     #return $rs if ($rs != 0);
458     #
459
460     #
461     # Here we'll backup production config file;
462     #
463
464     $rs = sys_command("cp -p $sys_cfg $backup_cfg");
465
466     return $rs if ($rs != 0);
467
468     #
469     # Let's save working copy;
470     #
471
472     $rs = store_file($working_cfg, $working, 'root', 'root', 0644);
473
474     return $rs if ($rs != 0);
475
476     #
477     # Here we'll replace data in production config file with data in working
478     # confing file. A little workaround will be done. If working copy data does not exist
479     # in production config then we will add it;
480     #
481
482     ($rs, $rdata) = get_tag($dta_b, $dta_e, $sys);
483
484     if ($rs == 0) { # YES ! Data is here ! /in production config file/;
485
486         ($rs, $sys) = repl_tag($dta_b, $dta_e, $sys, $working);
487
488         return $rs if ($rs != 0);
489
490     } elsif ($rs == -5) {
491
492         $sys .= $working;
493
494     } else {
495
496         return $rs;
497
498     }
499
500     $rs = store_file($sys_cfg, $sys, 'root', 'root', 0644);
501
502     return $rs if ($rs != 0);
503
504
505     push_el(\@main::el, 'als_del_named_cfg_data()', 'Ending...');
506
507     return 0;
508 }
509
510 sub als_add_named_db_data {
511
512     my ($als_data) = @_;
513
514     my ($rs, $rdata) = (undef, undef);
515
516     push_el(\@main::el, 'als_add_named_db_data()', 'Starting...');
517
518     if (!defined($als_data) || $als_data eq '') {
519
520         push_el(\@main::el, 'als_add_named_db_data()', 'ERROR: Undefined Input Data...');
521
522         return -1;
523
524     }
525
526     #
527     # Initial data we need;
528     #
529
530     my $als_name = @$als_data[2];
531
532     my $als_ip_id = @$als_data[5];
533
534     my $als_ip = $main::ip_id_num{$als_ip_id};
535
536
537     my $conf_dir = $main::cfg{'CONF_DIR'};
538
539     my $named_db_dir = $main::cfg{'BIND_DB_DIR'};
540
541     my $base_svr_ip = $main::cfg{'BASE_SERVER_IP'};
542
543     my $sec_dns_ip = $main::cfg{'SECONDARY_DNS'};
544
545     #
546     # Any secondary DNS defined;
547     #
548
549         if (!$sec_dns_ip) {
550                 $sec_dns_ip = $base_svr_ip;
551         }
552
553     my $tpl_dir = "$conf_dir/bind/parts";
554
555     my $backup_dir = "$conf_dir/bind/backup";
556
557     my $working_dir = "$conf_dir/bind/working";
558
559
560     my $db_fname = "$als_name.db";
561
562
563     my $sys_cfg = "$named_db_dir/$db_fname";
564
565     my $working_cfg = "$working_dir/$db_fname";
566
567     #
568     # Let's get needed tags and templates;
569     #
570
571     my ($entry, $dns2_b, $dns2_e) = ('', '', '');
572
573     ($rs, $entry, $dns2_b, $dns2_e) = get_tpl(
574                                               $tpl_dir,
575                                               'db_e.tpl',
576                                               'db_dns2_b.tpl',
577                                               'db_dns2_e.tpl'
578                                              );
579
580     return $rs if ($rs != 0);
581
582
583         #
584         # RFC 1912 template fix by Puuhis ;)
585         #
586
587         my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
588
589         my $time2 = sprintf "%4d%02d%02d00",$year+1900,$mon+1,$mday;
590
591     #
592     # Let's prepare them;
593     #
594
595     my %tag_hash = (
596                     '{DMN_NAME}' => $als_name,
597                     '{DMN_IP}' => $als_ip,
598                     '{BASE_SERVER_IP}' => $base_svr_ip,
599                     '{SECONDARY_DNS_IP}' => $sec_dns_ip,
600                     '{TIMESTAMP}' => $time2
601                    );
602
603     ($rs, $entry, $dns2_b, $dns2_e) = prep_tpl(
604                                                \%tag_hash,
605                                                $entry,
606                                                $dns2_b,
607                                                $dns2_e
608                                               );
609
610     return $rs if ($rs != 0);
611
612     #if ($main::cfg{'SECONDARY_DNS'}) {
613
614     #   my $dns2 = undef;
615
616     #    $dns2 = "\t\t \t NS \t $main::cfg{'SECONDARY_DNS'}.\n";
617
618     #    $dns2 = "$dns2_b$dns2$dns2_e";
619
620     #    ($rs, $entry) = repl_tag($dns2_b, $dns2_e, $entry, $dns2);
621
622     #    return $rs if ($rs != 0);
623
624     #} else {
625
626     #    ($rs, $entry) = del_tag($dns2_b, $dns2_e, $entry);
627
628     #    return $rs if ($rs != 0);
629
630     #}
631
632     #
633     # Let's store generated data;
634     #
635
636     $rs = store_file($working_cfg, $entry, 'root', 'root', 0644);
637
638     return $rs if ($rs != 0);
639
640     $rs = store_file($sys_cfg, $entry, 'root', 'root', 0644);
641
642     return $rs if ($rs != 0);
643
644     push_el(\@main::el, 'als_add_named_db_data()', 'Ending...');
645
646
647     return 0;
648 }
649
650 sub als_del_named_db_data {
651
652     my ($als_data) = @_;
653
654     my ($rs, $rdata) = (undef, undef);
655
656     push_el(\@main::el, 'als_del_named_db_data()', 'Starting...');
657
658     if (!defined($als_data) || $als_data eq '') {
659
660         push_el(\@main::el, 'als_del_named_db_data()', 'ERROR: Undefined Input Data...');
661
662         return -1;
663
664     }
665
666     #
667     # Initial data we need;
668     #
669
670     my $als_name = @$als_data[2];
671
672     my $als_ip_id = @$als_data[5];
673
674     my $als_ip = $main::ip_id_num{$als_ip_id};
675
676
677     my $conf_dir = $main::cfg{'CONF_DIR'};
678
679     my $named_db_dir = $main::cfg{'BIND_DB_DIR'};
680
681
682     my $tpl_dir = "$conf_dir/bind/parts";
683
684     my $backup_dir = "$conf_dir/bind/backup";
685
686     my $working_dir = "$conf_dir/bind/working";
687
688
689     my $db_fname = "$als_name.db";
690
691
692     my $sys_cfg = "$named_db_dir/$db_fname";
693
694     my $working_cfg = "$working_dir/$db_fname";
695
696     #
697     # Let's remove .db files for this domain;
698     #
699
700     $rs = del_file($working_cfg);
701
702     return $rs if ($rs != 0);
703
704     $rs = del_file($sys_cfg);
705
706     return $rs if ($rs != 0);
707
708     push_el(\@main::el, 'als_del_named_db_data()', 'Ending...');
709
710
711     return 0;
712 }
713
714 sub als_add_named_data {
715
716     my ($als_data) = @_;
717
718     my $rs = undef;
719
720     push_el(\@main::el, 'als_add_named_data()', 'Starting...');
721
722     if (!defined($als_data) || $als_data eq '') {
723
724         push_el(\@main::el, 'als_add_named_data()', 'ERROR: Undefined Input Data...');
725
726         return -1;
727
728     }
729
730     $rs = als_add_named_cfg_data($als_data);
731
732     return $rs if ($rs != 0);
733
734     $rs = als_add_named_db_data($als_data);
735
736     return $rs if ($rs != 0);
737
738     push_el(\@main::el, 'als_add_named_data()', 'Ending...');
739
740     return 0;
741 }
742
743 sub als_change_named_data {
744
745     my ($als_data) = @_;
746
747     my $rs = undef;
748
749     push_el(\@main::el, 'als_change_named_data()', 'Starting...');
750
751     if (!defined($als_data) || $als_data eq '') {
752
753         push_el(\@main::el, 'als_change_named_data()', 'ERROR: Undefined Input Data...');
754
755         return -1;
756
757     }
758
759     $rs = als_add_named_data($als_data);
760
761     return $rs if ($rs != 0);
762
763     push_el(\@main::el, 'als_change_named_data()', 'Ending...');
764
765     return 0;
766 }
767
768 sub als_del_named_data {
769
770     my ($als_data) = @_;
771
772     my $rs = undef;
773
774     push_el(\@main::el, 'als_del_named_data()', 'Starting...');
775
776     if (!defined($als_data) || $als_data eq '') {
777
778         push_el(\@main::el, 'als_del_named_data()', 'ERROR: Undefined Input Data...');
779
780         return -1;
781
782     }
783
784     $rs = als_del_named_cfg_data($als_data);
785
786     return $rs if ($rs != 0);
787
788     $rs = als_del_named_db_data($als_data);
789
790     return $rs if ($rs != 0);
791
792     push_el(\@main::el, 'als_del_named_data()', 'Ending...');
793
794     return 0;
795 }
796
797 #
798 # alias httpd data managment;
799 #
800
801 sub gen_httpd_als_entry {
802
803     my ($als_data) = @_;
804
805     push_el(\@main::el, 'gen_httpd_als_entry()', 'Starting...');
806
807     if (!defined($als_data) || $als_data eq '') {
808
809         push_el(\@main::el, 'gen_httpd_als_entry()', "ERORR: Undefined input data...");
810
811         return (-1, '');
812
813     }
814
815     my ($rs, $rdata) = (undef, undef);
816
817     my $als_name = @$als_data[2];
818
819     my $als_ip_id = @$als_data[5];
820
821     my $als_ip = $main::ip_id_num{$als_ip_id};
822
823     my $dmn_id = @$als_data[7];
824
825     my $dmn_name = @$als_data[8];
826
827     my $mount_point = @$als_data[4];
828
829     my ($als_php, $als_cgi) = (@$als_data[26], @$als_data[27]);
830
831     my $url_forward = @$als_data[6];
832
833     my $conf_dir = $main::cfg{'CONF_DIR'};
834
835     my $tpl_dir = "$conf_dir/apache/parts";
836
837     my (
838         $als_b,
839         $als_entry,
840         $als_e,
841         $als_rdr_b,
842         $als_rdr_entry,
843         $als_rdr_e,
844         $als_cgi_b,
845         $als_cgi_entry,
846         $als_cgi_e,
847         $als_php_b,
848         $als_php_entry,
849         $als_php_e,
850         $als_php2_b,
851         $als_php2_entry,
852         $als_php2_e
853        ) = ('', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
854
855     (
856      $rs,
857      $als_b,
858      $als_entry,
859      $als_e,
860      $als_rdr_b,
861      $als_rdr_entry,
862      $als_rdr_e,
863      $als_cgi_b,
864      $als_cgi_entry,
865      $als_cgi_e,
866      $als_php_b,
867      $als_php_entry,
868      $als_php_e,
869      $als_php2_b,
870      $als_php2_entry,
871      $als_php2_e
872     ) = get_tpl (
873                  $tpl_dir,
874                  'als_b.tpl',
875                  'als_entry.tpl',
876                  'als_e.tpl',
877                  'als_rdr_b.tpl',
878                  'als_rdr_entry.tpl',
879                  'als_rdr_e.tpl',
880                  'als_cgi_b.tpl',
881                  'als_cgi_entry.tpl',
882                  'als_cgi_e.tpl',
883                  'als_php_b.tpl',
884                  'als_php_entry.tpl',
885                  'als_php_e.tpl',
886                  'als_php2_b.tpl',
887                  'als_php2_entry.tpl',
888                  'als_php2_e.tpl'
889                 );
890
891     return ($rs, '') if ($rs != 0);
892
893     push_el(\@main::el, 'als_entry:', "$als_e");
894
895     my ($suexec_uid, $suexec_gid) = get_dmn_suexec_user($dmn_id);
896
897     my $suexec_user_pref = $main::cfg{'APACHE_SUEXEC_USER_PREF'};
898
899     my ($suexec_user, $suexec_group) = ("$suexec_user_pref$suexec_uid", "$suexec_user_pref$suexec_gid");
900
901     my %tag_hash =
902
903         (
904          '{DMN_NAME}' => $dmn_name,
905          '{ALS_NAME}' => $als_name,
906          '{ALS_IP}' => $als_ip,
907          '{URI}' => $url_forward,
908          '{MOUNT_POINT}' => $mount_point,
909          '{STARTER_DIR}' => $main::cfg{'PHP_STARTER_DIR'},
910          '{WWW_DIR}' => $main::cfg{'APACHE_WWW_DIR'},
911          '{APACHE_LOG_DIR}' => $main::cfg{'APACHE_LOG_DIR'},
912          '{GUI_ROOT_DIR}' => $main::cfg{'GUI_ROOT_DIR'},
913          '{PEAR_DIR}' => $main::cfg{'PEAR_DIR'},
914          '{APACHE_USERS_LOG_DIR}' => $main::cfg{'APACHE_USERS_LOG_DIR'},
915          '{SUEXEC_USER}' => $suexec_user,
916          '{SUEXEC_GROUP}' => $suexec_group
917         );
918
919     (
920      $rs,
921      $als_b,
922      $als_entry,
923      $als_e,
924      $als_rdr_entry,
925      $als_cgi_entry,
926      $als_php_entry,
927      $als_php2_entry
928     ) = prep_tpl(
929                  \%tag_hash,
930                  $als_b,
931                  $als_entry,
932                  $als_e,
933                  $als_rdr_entry,
934                  $als_cgi_entry,
935                  $als_php_entry,
936                  $als_php2_entry
937                 );
938
939     return ($rs, '') if ($rs != 0);
940
941     #
942     # Any CGI entry?
943     #
944
945     my $cgi_entry = undef;
946
947     if ($als_cgi eq 'yes') {
948
949         $cgi_entry = "$als_cgi_b$als_cgi_entry$als_cgi_e";
950
951     } else {
952
953         $cgi_entry = "$als_cgi_b$als_cgi_e";
954
955     }
956
957     ($rs, $als_entry) = repl_tag(
958                                  $als_cgi_b,
959                                  $als_cgi_e,
960                                  $als_entry,
961                                  $cgi_entry
962                                 );
963
964     return ($rs, '') if ($rs != 0);
965
966     #
967     # Any PHP entry?
968     #
969
970     my $php_entry = undef;
971
972     if ($als_php eq 'no') {
973
974         $php_entry = "$als_php_b$als_php_entry$als_php_e";
975
976
977     } else {
978
979         $php_entry = "$als_php_b$als_php_e";
980
981         my $php2_entry = "$als_php2_b$als_php2_entry$als_php2_e";
982
983         ($rs, $als_entry) = repl_tag(
984                                      $als_php2_b,
985                                      $als_php2_e,
986                                      $als_entry,
987                                      $php2_entry
988                                     );
989
990         return ($rs, '') if ($rs != 0);
991
992     }
993
994     ($rs, $als_entry) = repl_tag(
995                                  $als_php_b,
996                                  $als_php_e,
997                                  $als_entry,
998                                  $php_entry
999                                 );
1000
1001     return ($rs, '') if ($rs != 0);
1002
1003     #
1004     # Any REDIRECT entry?
1005     #
1006
1007     if ($url_forward ne 'no') {
1008
1009         my $rdr_entry = "$als_rdr_b$als_rdr_entry$als_rdr_e";
1010
1011         ($rs, $als_entry) = repl_tag(
1012                                      $als_rdr_b,
1013                                      $als_rdr_e,
1014                                      $als_entry,
1015                                      $rdr_entry
1016                                     );
1017
1018         return ($rs, '') if ($rs != 0);
1019
1020     }
1021
1022
1023     my $als_result_entry = "$als_b$als_entry$als_e";
1024
1025     push_el(\@main::el, 'gen_httpd_als_entry()', "\n$als_result_entry");
1026
1027     return (0, $als_result_entry);
1028
1029 }
1030
1031 sub als_add_httpd_cfg_data {
1032
1033     my ($als_data) = @_;
1034
1035     my ($rs, $rdata) = (undef, undef);
1036
1037     push_el(\@main::el, 'als_add_httpd_cfg_data()', 'Starting...');
1038
1039     if (!defined($als_data) || $als_data eq '') {
1040
1041         push_el(\@main::el, 'als_add_httpd_cfg_data()', 'ERROR: Undefined Input Data...');
1042
1043         return -1;
1044
1045     }
1046
1047     my $als_name = @$als_data[2];
1048
1049     my $als_ip_id = @$als_data[5];
1050
1051     my $als_ip = $main::ip_id_num{$als_ip_id};
1052
1053
1054     my $conf_dir = $main::cfg{'CONF_DIR'};
1055
1056
1057     my $tpl_dir = "$conf_dir/apache/parts";
1058
1059     my $working_dir = "$conf_dir/apache/working";
1060
1061     my $backup_dir = "$conf_dir/apache/backup";
1062
1063
1064     my $sys_cfg = "$main::cfg{'APACHE_SITES_DIR'}/ispcp.conf";
1065
1066     my $working_cfg = "$working_dir/ispcp.conf";
1067
1068
1069     my $timestamp = time;
1070
1071     my $backup_cfg = "$backup_dir/httpd.conf.$timestamp";
1072
1073     #
1074     # Getting needed templates;
1075     #
1076
1077     my (
1078         $cfg_b,
1079         $cfg_e,
1080         $vh_b,
1081         $vh_entry,
1082         $vh_e,
1083         $als_b,
1084         $als_e
1085        ) = ('', '', '', '', '', '', '');
1086
1087     (
1088      $rs,
1089      $cfg_b,
1090      $cfg_e,
1091      $vh_b,
1092      $vh_entry,
1093      $vh_e,
1094      $als_b,
1095      $als_e
1096     ) = get_tpl (
1097                  $tpl_dir,
1098                  'cfg_b.tpl',
1099                  'cfg_e.tpl',
1100                  'vh_b.tpl',
1101                  'vh_entry.tpl',
1102                  'vh_e.tpl',
1103                  'als_b.tpl',
1104                  'als_e.tpl'
1105                 );
1106
1107     return $rs if ($rs != 0);
1108
1109     #
1110     # Preparing templates;
1111     #
1112
1113     my (
1114         $vh_b_val,
1115         $vh_entry_val,
1116         $vh_e_val
1117        ) = ('', '', '');
1118
1119     my %tag_hash = ('{IP}' => $als_ip);
1120
1121     (
1122      $rs,
1123      $vh_b_val,
1124      $vh_entry_val,
1125      $vh_e_val
1126     ) = prep_tpl (
1127                   \%tag_hash,
1128                   $vh_b,
1129                   $vh_entry,
1130                   $vh_e
1131                  );
1132
1133     return $rs if ($rs != 0);
1134
1135     my (
1136         $als_b_val,
1137         $als_e_val
1138        ) = ('', '');
1139
1140     %tag_hash = ('{ALS_NAME}' => $als_name);
1141
1142     (
1143      $rs,
1144      $als_b_val,
1145      $als_e_val
1146     ) = prep_tpl (
1147                   \%tag_hash,
1148                   $als_b,
1149                   $als_e
1150                  );
1151
1152     return $rs if ($rs != 0);
1153
1154     #
1155     # Let's construct alias entry.
1156     #
1157
1158     my $als_entry_contents = '';
1159
1160     ($rs, $als_entry_contents) = gen_httpd_als_entry($als_data);
1161
1162     return $rs if ($rs != 0);
1163
1164     #
1165     # Let's get some configs;
1166     #
1167
1168     my ($sys, $working) = ('', '');
1169
1170
1171     ($rs, $sys) = get_file($sys_cfg);
1172
1173     return $rs if ($rs != 0);
1174
1175
1176     ($rs, $working) = get_file($working_cfg);
1177
1178     return $rs if ($rs != 0);
1179
1180     #
1181     # Check for $cfg_b, $cfg_e in working config;
1182     #
1183
1184     ($rs, $rdata) = get_tag($cfg_b, $cfg_e, $working);
1185
1186     return $rs if ($rs != 0);
1187
1188     #
1189     # Check for $vh_b_val, $vh_e_val in working config;
1190     # Have we valued virtual host entry in working config?
1191     #
1192
1193     my $vh_entry_contents = '';
1194
1195     ($rs, $vh_entry_contents) = get_tag($vh_b_val, $vh_e_val, $working);
1196
1197     push_el(\@main::el, 'als_add_httpd_cfg_data()', "\n$vh_entry_contents");
1198
1199     if ($rs == -5) { # No, we have not! We must add it here.
1200
1201         my $repl = "$als_entry_contents\n$als_b$als_e";
1202
1203         ($rs, $vh_entry_val) = repl_tag(
1204                                         $als_b,
1205                                         $als_e,
1206                                         $vh_entry_val,
1207                                         $repl
1208                                        );
1209         return $rs if ($rs != 0);
1210
1211         $repl = "$vh_b_val$vh_entry_val$vh_e_val\n";
1212
1213         $repl .= "$vh_b$vh_e";
1214
1215         ($rs, $working) = repl_tag(
1216                                    $vh_b,
1217                                    $vh_e,
1218                                    $working,
1219                                    $repl
1220                                   );
1221
1222         return $rs if ($rs != 0);
1223
1224         # ?!
1225
1226         ($rs, $rdata) = get_tag($vh_b_val, $vh_e_val, $working);
1227
1228         return $rs if ($rs != 0);
1229
1230     } elsif ($rs == 0) { # Yes, we have! We must edit it here.
1231
1232
1233         # Check for valued Domain Group Entry in this Virtual Host Entry;
1234
1235
1236         ($rs, $rdata) = get_tag(
1237                                 $als_b_val,
1238                                 $als_e_val,
1239                                 $vh_entry_contents
1240                                );
1241
1242         if ($rs == 0) {
1243
1244             # We have one ! We must delete it!
1245
1246             ($rs, $vh_entry_contents) = del_tag(
1247                                                 $als_b_val,
1248                                                 "$als_e_val\n",
1249                                                 $vh_entry_contents
1250                                                );
1251
1252             return $rs if ($rs != 0);
1253
1254         }
1255
1256
1257         # Tag check.
1258
1259
1260         ($rs, $rdata) = get_tag($als_b, $als_e, $vh_entry_contents);
1261
1262         return $rs if ($rs != 0);
1263
1264
1265         # Constructing als entry.
1266
1267
1268         my $repl = "$als_entry_contents\n$als_b$als_e";
1269
1270         ($rs, $vh_entry_contents) = repl_tag(
1271                                              $als_b,
1272                                              $als_e,
1273                                              $vh_entry_contents,
1274                                              $repl
1275                                             );
1276
1277         return $rs if ($rs != 0);
1278
1279         # Let's put new vh entry in the working config.
1280
1281         ($rs, $working) = repl_tag(
1282                                    $vh_b_val,
1283</