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

Revision 919, 57.4 kB (checked in by pasichnyk, 1 year ago)

Modified ispcp-setup and some of the ispcp-*-mngr scripts to replace {PHP_VERSION} in the .tpl files it
works with. This is for mod_fcgid support in domains, subdomains, and aliases.

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