summaryrefslogtreecommitdiffstats
path: root/web_wizard/scripts/Webconf.pm
blob: fa815aee1ab4e88cd99fe4b7943b53e66b6a607a (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl

package Webconf;
require "__WIZ_HOME__/common/scripts/Varspaceval.pm";
require "__WIZ_HOME__/common/scripts/DrakconnectConf.pm";
use MDK::Common;

use strict;

my $o = DrakconnectConf->new();

sub	check {
    $> and return 1;
    $o->is_dhcp() and return 2;
    0;
}

my $file = "/etc/httpd/conf/commonhttpd.conf";
my $root;

if (-f $file) {
    open(FH, "< $file") or die "$! ($file)";
    while (<FH>) {
	if (/^\s*\#?\s*DocumentRoot\s+(.*)/) {
	    close(FH);
	    $root = "$1";
	    last;
	}
    }
    close(FH);
}

sub	get_docroot {
    $root;
}

sub	check_dir {
    -d ($ENV{wiz_dir}) and return 10;
    1;
}

sub	chg_docroot {
    substInFile {
	s|(^\s*\#?\s*DocumentRoot\s*).*|$1$ENV{wiz_dir}|;
    } "/etc/httpd/conf/commonhttpd.conf";
}

sub	is_user_mod {
    if ($ENV{wiz_user_mod}) {
	return 1;
    }
    $ENV{wiz_user_dir} = "disabled";
    0;
}

sub	is_last_user_mod {
    my $root = get_user_dir();
    chomp($root);
    !($root eq 'disabled');
}

sub     get_user_dir {
    my %conf = Varspaceval->get("/etc/httpd/conf/commonhttpd.conf");    
    $conf{UserDir};
}

sub     chg_user_dir {
    my  $root = get_user_dir();
    if ($ENV{wiz_user_mod}) {
	substInFile {
            s|(/home/\*/)$root(/?)|$1$ENV{wiz_user_dir}$2|g;
        } "/etc/httpd/conf/commonhttpd.conf";
        substInFile {
	    s|(\s*)UserDir\s*$root(/?)|$1UserDir $ENV{wiz_user_dir}$2|g;
            s|(/home/\*/)$root(/?)|$1$ENV{wiz_user_dir}$2|g;
        } "/etc/httpd/conf/commonhttpd.conf";
    }
    else {
	substInFile {
	    s|(\s*)UserDir\s*$root(/?)|$1UserDir disabled$2|g;
        } "/etc/httpd/conf/commonhttpd.conf";
    }
    10;
}

sub	do_it {
    my	$file = "/etc/httpd/conf/commonhttpd.conf";
    my	$that = "localhost";

    if ($ENV{wiz_web_external} eq "1") {
	$that = "all";
    }
    elsif ($ENV{wiz_web_internal} eq "1") {
	($that) = $o->get_from_known_dev("IP") =~ qr/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)\d{1,3}$/;
	$that .= " 127.0.0.1";
    }
    cp_af($file, $file.".orig");
    substInFile {    
	if( m /^\s*<Directory.*>/s...m/^\s*<\/Directory>/s ) {
	    { s /^\s*Allow .*$/    Allow from $that\n/s;}
	    ;}
    } $file;
    chg_docroot();
    chg_user_dir();
    system("/etc/rc.d/init.d/httpd restart");
    10;
}

1;