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
110
111
112
113
114
115
116
117
118
119
120
121
|
#!/usr/bin/perl
# Drakwizard
# Copyright (C) 2002 MandrakeSoft Arnaud Desmons (adesmons@mandrakesoft.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
package Squidconf;
use lib '/usr/lib/libDrakX';
require "__WIZ_HOME__/common/scripts/Vareqval.pm";
require "__WIZ_HOME__/common/scripts/Varspaceval.pm";
require "__WIZ_HOME__/common/scripts/IFCFG.pm";
use MDK::Common;
use services;
use strict;
use standalone;
sub network_mask {
my $o = IFCFG->new();
my $wiz_ip_server = $o->itf_get("IPADDR");
my $mask = $o->itf_get("NETMASK");
"$1.$2.$3.0/$mask" if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
}
sub testport {
if ($ENV{wiz_squid_port} == 3128 || $ENV{wiz_squid_port} == 8080) {
return 0;
}
elsif ($ENV{wiz_squid_port} <= 1024 || $ENV{wiz_squid_port} >= 65536) {
return 2;
}
1;
}
sub port {
my $ret;
my @lines = grep(/$ENV{wiz_squid_port}\/tcp/, cat_("/etc/services"));
foreach (@lines) {
s/\t/ /g;
$ret .= "\n$_";
}
$ret;
}
sub do_it_squid {
my $file="/etc/squid/squid.conf";
-f $file and MDK::Common::cp_af($file, $file.".orig");
MDK::Common::cp_af("__WIZ_HOME__/proxy_wizard/scripts/squid.conf.default", $file);
substInFile {
s|^\s*\#?\s*(cache_dir.*$ENV{wiz_squid_defdir}\s*)\d*(.*)|$1$ENV{wiz_squid_disk}$2|;
s|^\s*\#?\s*(acl\s*mynetwork\s*src\s*).*$|$1$ENV{wiz_squid_mynetw}\n|;
s|^\s*\#?\s*(cache_mem\s*)\d*(\s*MB.*)|$1$ENV{wiz_squid_mem}$2|;
s|^\s*\#?\s*(http_port\s*)\d*(.*)|$1$ENV{wiz_squid_port}$2|;
} $file;
print "LEVEL $ENV{'wiz_squid_level'}\n\n";
exit;
standalone::explanations("$file: cache_dir = $ENV{wiz_squid_defdir} $ENV{wiz_squid_disk}
mynetw = $ENV{wiz_squid_mynetw} cache_mem = $ENV{wiz_squid_mem} http_port = $ENV{wiz_squid_port}
level = $ENV{wiz_squid_level}");
if ($ENV{wiz_squid_level} == 1) {
substInFile {
s|^\s*\#?\s*(http_access\s*)deny(\s*all.*)|\#$&\n$1allow$2|;
} $file;
}
elsif ($ENV{wiz_squid_level} == 2) {
substInFile {
s|^\s*\#?\s*(http_access\s*)allow(\s*all.*)|\#$&\n$1deny$2|;
s|^\s*\#?\s*(http_access\s*allow\s*)localhost|\#$&\n$1mynetwork|;
} $file;
}
elsif ($ENV{wiz_squid_level} == 3) {
substInFile {
s|^\s*\#?\s*(http_access\s*)allow(\s*all.*)|\#$&\n$1deny$2|;
s|^\s*\#?\s*(http_access\s*allow\s*)mynetwork|\#$&\n$1localhost|;
} $file;
} else { # should not happen
die "wiz_squid_level error";
}
my $t = 0;
foreach (cat_($file)) {
if (/^\s*cache_peer.*/) {
$t = $_;;
last;
}
}
if ($ENV{wiz_squid_menupeer} == 1 && length $t) {
substInFile {
s|^\s*!\#\s*(cache_peer.*)|\#$&|;
} $file;
}
elsif ($ENV{wiz_squid_menupeer} == 2 && length $ENV{wiz_squid_cachepeer}) {
if (lenght $t) {
substInFile {
s|^\s*\#?\s*(cache_peer.*)|\#$&|;
} $file;
}
append_to_file($file, "cache_peer $ENV{wiz_squid_cachepeer} parent $ENV{wiz_squid_peerport} 3130");
}
system("/sbin/chkconfig --level 345 squid on");
if (services::is_service_running('squid')) {
services::restart('squid')
} else {
services::start('squid')
}
10;
}
1;
|