| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# -*- perl -*- |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# HTML::EP - A Perl based HTML extension. |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# Copyright (C) 1998 Jochen Wiedmann |
|
7
|
|
|
|
|
|
|
# Am Eisteich 9 |
|
8
|
|
|
|
|
|
|
# 72555 Metzingen |
|
9
|
|
|
|
|
|
|
# Germany |
|
10
|
|
|
|
|
|
|
# |
|
11
|
|
|
|
|
|
|
# Phone: +49 7123 14887 |
|
12
|
|
|
|
|
|
|
# Email: joe@ispsoft.de |
|
13
|
|
|
|
|
|
|
# |
|
14
|
|
|
|
|
|
|
# All rights reserved. |
|
15
|
|
|
|
|
|
|
# |
|
16
|
|
|
|
|
|
|
# You may distribute this module under the terms of either |
|
17
|
|
|
|
|
|
|
# the GNU General Public License or the Artistic License, as |
|
18
|
|
|
|
|
|
|
# specified in the Perl README file. |
|
19
|
|
|
|
|
|
|
# |
|
20
|
|
|
|
|
|
|
############################################################################ |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
require 5.004; |
|
23
|
1
|
|
|
1
|
|
1046
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
67
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
5
|
use HTML::EP (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
23
|
|
|
26
|
1
|
|
|
1
|
|
6
|
use HTML::EP::Locale (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1419
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
package HTML::EP::Examples::Admin; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$HTML::EP::Examples::Admin::VERSION = '0.03'; |
|
31
|
|
|
|
|
|
|
@HTML::EP::Examples::Admin::ISA = qw(HTML::EP::Locale HTML::EP); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub init { |
|
35
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
36
|
0
|
0
|
|
|
|
|
if (!exists($self->{'admin_config'})) { |
|
37
|
0
|
|
|
|
|
|
$self->SUPER::init(); |
|
38
|
0
|
|
0
|
|
|
|
$self->{'admin_config'} = |
|
39
|
|
|
|
|
|
|
$self->{'_ep_config'}->{'examples'}->{'admin'} || {}; |
|
40
|
0
|
|
0
|
|
|
|
$self->{'admin_config'}->{'vardir'} ||= '/home/httpd/html/admin/var'; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _prefs { |
|
46
|
0
|
|
|
0
|
|
|
my $self = shift; my $prefs = shift; |
|
|
0
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $vardir = $self->{'admin_config'}->{'vardir'}; |
|
48
|
0
|
|
|
|
|
|
my $prefs_file = "$vardir/prefs"; |
|
49
|
0
|
0
|
|
|
|
|
if (!$prefs) { |
|
50
|
|
|
|
|
|
|
# Load Prefs |
|
51
|
0
|
|
0
|
|
|
|
$self->{'prefs'} = (do $prefs_file) || {}; |
|
52
|
|
|
|
|
|
|
} else { |
|
53
|
|
|
|
|
|
|
# Save Prefs |
|
54
|
0
|
|
|
|
|
|
require Data::Dumper; |
|
55
|
0
|
|
|
|
|
|
my $dump = Data::Dumper->new([$prefs], ['PREFS']); |
|
56
|
0
|
|
|
|
|
|
$dump->Indent(1); |
|
57
|
0
|
|
|
|
|
|
require Symbol; |
|
58
|
0
|
|
|
|
|
|
my $fh = Symbol::gensym(); |
|
59
|
0
|
|
|
|
|
|
my $d = $dump->Dump(); |
|
60
|
0
|
0
|
|
|
|
|
if ($self->{'debug'}) { |
|
61
|
0
|
|
|
|
|
|
print "Saving Preferences to $prefs_file.\n"; |
|
62
|
0
|
|
|
|
|
|
$self->print("Saving data:\n$d\n"); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
0
|
0
|
0
|
|
|
|
if (!open($fh, ">$prefs_file") |
|
|
|
|
0
|
|
|
|
|
|
65
|
|
|
|
|
|
|
or !(print $fh "$d\n") |
|
66
|
|
|
|
|
|
|
or !close($fh)) { |
|
67
|
0
|
|
|
|
|
|
die "Couldn't save data: $!"; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
0
|
|
|
|
|
|
$self->{'prefs'} = $prefs; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _ep_html_ep_examples_admin_squid { |
|
75
|
0
|
|
|
0
|
|
|
my $self = shift; my $attr = shift; |
|
|
0
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $cgi = $self->{'cgi'}; |
|
77
|
0
|
|
|
|
|
|
my $prefs = $self->_prefs(); |
|
78
|
0
|
|
|
|
|
|
my $debug = $self->{'debug'}; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $verify_squid_range = sub { |
|
81
|
0
|
|
|
0
|
|
|
my($from, $to, $active, $name) = @_; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
require Socket; |
|
84
|
0
|
|
|
|
|
|
my($f, $t); |
|
85
|
0
|
0
|
|
|
|
|
if (!($f = Socket::inet_aton($from))) { |
|
86
|
0
|
|
|
|
|
|
die "Invalid IP address: $from"; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
0
|
0
|
|
|
|
|
if (!($t = Socket::inet_aton($to))) { |
|
89
|
0
|
|
|
|
|
|
die "Invalid IP address: $to"; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
{ |
|
92
|
0
|
|
|
|
|
|
'from' => Socket::inet_ntoa($f), |
|
93
|
|
|
|
|
|
|
'to' => Socket::inet_ntoa($t), |
|
94
|
|
|
|
|
|
|
'active' => $active, |
|
95
|
|
|
|
|
|
|
'name' => $name |
|
96
|
|
|
|
|
|
|
} |
|
97
|
0
|
|
|
|
|
|
}; |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my @range; |
|
100
|
|
|
|
|
|
|
my $modified; |
|
101
|
0
|
|
|
|
|
|
my $from = $cgi->param('insert_ip_from'); |
|
102
|
0
|
|
|
|
|
|
my $to = $cgi->param('insert_ip_to'); |
|
103
|
0
|
0
|
0
|
|
|
|
if ($from or $to) { |
|
104
|
0
|
|
|
|
|
|
push(@range, |
|
105
|
|
|
|
|
|
|
&$verify_squid_range($from, $to, $cgi->param("insert_active"), |
|
106
|
|
|
|
|
|
|
$cgi->param("insert_name"))); |
|
107
|
0
|
|
|
|
|
|
$modified = 1; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
0
|
|
|
|
|
|
for (my $i = 0; 1; $i++) { |
|
110
|
0
|
0
|
|
|
|
|
if ($cgi->param("delete_ip_$i")) { |
|
111
|
0
|
|
|
|
|
|
$modified = 1; |
|
112
|
0
|
|
|
|
|
|
next; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
0
|
|
|
|
|
|
$from = $cgi->param("edit_ip_from_$i"); |
|
115
|
0
|
|
|
|
|
|
$to = $cgi->param("edit_ip_to_$i"); |
|
116
|
0
|
0
|
0
|
|
|
|
if (!defined($from) && !defined($to)) { |
|
117
|
0
|
|
|
|
|
|
last; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
0
|
|
|
|
|
|
push(@range, |
|
120
|
|
|
|
|
|
|
&$verify_squid_range($from, $to, $cgi->param("edit_active_$i"), |
|
121
|
|
|
|
|
|
|
$cgi->param("edit_name_$i"))); |
|
122
|
0
|
|
|
|
|
|
$modified = 1; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
if ($modified) { |
|
126
|
0
|
0
|
|
|
|
|
$self->print("Modifications detected.\n") if $debug; |
|
127
|
0
|
|
|
|
|
|
$prefs->{'squid_ranges'} = \@range; |
|
128
|
0
|
|
|
|
|
|
$self->_prefs($prefs); |
|
129
|
0
|
0
|
0
|
|
|
|
my $path_users_modified = |
|
130
|
|
|
|
|
|
|
($attr->{'users-modified-path'} || |
|
131
|
|
|
|
|
|
|
$self->{'admin_config'}->{'users_modified_path'}) |
|
132
|
|
|
|
|
|
|
or die "Path of usersModified binary not set"; |
|
133
|
0
|
0
|
|
|
|
|
if ($path_users_modified ne 'none') { |
|
134
|
0
|
0
|
|
|
|
|
die "No such binary: $path_users_modified" |
|
135
|
|
|
|
|
|
|
unless -f $path_users_modified; |
|
136
|
0
|
|
|
|
|
|
my @command = ($path_users_modified, '--squid'); |
|
137
|
0
|
|
|
|
|
|
foreach my $r (@range) { |
|
138
|
0
|
0
|
|
|
|
|
next unless $r->{'active'}; |
|
139
|
0
|
|
|
|
|
|
push(@command, |
|
140
|
|
|
|
|
|
|
"--range", "$r->{'from'},$r->{'to'},$r->{'name'}"); |
|
141
|
|
|
|
|
|
|
} |
|
142
|
0
|
0
|
|
|
|
|
$self->print("Executing command: ", join(" ", @command), "\n") |
|
143
|
|
|
|
|
|
|
if $debug; |
|
144
|
0
|
|
|
|
|
|
system @command; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
} else { |
|
147
|
0
|
0
|
|
|
|
|
$self->print("No modifications detected.\n") if $debug; |
|
148
|
0
|
|
0
|
|
|
|
$prefs->{'squid_ranges'} ||= []; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
0
|
|
|
|
|
|
@range = sort { $a->{name} cmp $b->{name}} @{$prefs->{'squid_ranges'}}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
$self->{'ranges'} = \@range; |
|
152
|
0
|
0
|
|
|
|
|
if ($debug) { |
|
153
|
0
|
|
|
|
|
|
$self->print("Squid IP ranges:\n"); |
|
154
|
0
|
|
|
|
|
|
foreach my $r (@{$prefs->{'squid_ranges'}}) { |
|
|
0
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
$self->printf(" Name %s, From %s, To %s, Active %s\n", |
|
156
|
|
|
|
|
|
|
$r->{'name'}, $r->{'from'}, $r->{'to'}, |
|
157
|
|
|
|
|
|
|
$r->{'active'}); |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
0
|
|
|
|
$self->{'admin_config'}->{'squid_conf_path'} ||= '/etc/squid.conf'; |
|
162
|
0
|
|
|
|
|
|
''; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub _format_RANGE_SELECTED { |
|
166
|
0
|
|
|
0
|
|
|
my $self = shift; my $val = shift; |
|
|
0
|
|
|
|
|
|
|
|
167
|
0
|
0
|
|
|
|
|
$val ? "" : "SELECTED"; |
|
168
|
|
|
|
|
|
|
} |