summaryrefslogtreecommitdiffstats
path: root/web_wizard/scripts/Webconf.pm
blob: 69f99194140a270199974d5bc8a4cb609f5d85e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl

package Webconf;
require "__WIZ_HOME__/common/scripts/Vareqval.pm";

use strict;

my	$that;
my	%mdk;
my	$device;
my	$s;

sub	finish {
    my	$old = "/etc/httpd/conf/commonhttpd.conf";
    my	$new = "/tmp/commonhttpd.conf";
    my	$bak = "/etc/httpd/conf/commonhttpd.conf.orig";

    open(OLD, "< $old")		or die "can't open $old: $!";
    open(NEW, "> $new")		or die "can't open $new: $!";

    if ($ENV{wiz_web_external} eq "1") {
	$that = "all";
    }
    elsif ($ENV{wiz_web_internal} eq "1") {
	$device = $mdk{wiz_device};
	%mdk = Vareqval->get("/etc/sysconfig/network-scripts/ifcfg-".$device);
	$that = "$mdk{IPADDR}";
    }
    else {
	$that = "localhost";
    }

    if ($ENV{wiz_web_external} eq "1") {
	my $that = "all";
    }
    elsif ($ENV{wiz_web_internal} eq "1") {
	%mdk = Vareqval->get("/etc/sysconfig/mdk_serv");
	defined $mdk{wiz_device} and $device = $mdk{wiz_device} or die "wiz_device not found in mdk_serv\n";
	%mdk = Vareqval->get("/etc/sysconfig/network-scripts/ifcfg-".$device);
	defined $mdk{IPADDR} and $that = $mdk{IPADDR} or die "IPADDR not found in /etc/sysconfig/network-scripts/ifcfg-xxx\n";
    }
    else {
	$that = "localhost";
	print "hello\n"
    }
    while (<OLD>) {
	if( m /^[[:space:]]*<Directory \/home/s...m/^[[:space:]]*<\/Directory>/s ) {
	    { s /^[[:space:]]*Allow .*$/    Allow from $that\n/s;}
	    ;}
	if( m /^[[:space:]]*<Directory \/var\/www/s...m/^[[:space:]]*<\/Directory>/s ) {
	    { s /^[[:space:]]*Allow .*$/    Allow from $that\n/s;}
	    ;}
	print NEW $_		or die "can't write to $new: $!";
    }
    close(OLD)			or die "can't close $old: $!";
    close(NEW)			or die "can't close $new: $!";

    rename($old, $bak)		or die "can't rename $old to $bak: $!";
    rename($new, $old)		or die "can't rename $new to $old: $!";
}

1;