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

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