| 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 | 1 | require 5.004; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use HTML::EP (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use HTML::EP::Locale (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | package HTML::EP::Examples::Admin; | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | $HTML::EP::Examples::Admin::VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | @HTML::EP::Examples::Admin::ISA = qw(HTML::EP::Locale HTML::EP); | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if (!exists($self->{'admin_config'})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $self->SUPER::init(); | |||||||||||||||||||||||||||||||||||||||||
| 38 | $self->{'admin_config'} = | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $self->{'_ep_config'}->{'examples'}->{'admin'} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'_ep_config'}{'examples'}{'admin'} || {}
MC/DC0%0/1
$self->{'_ep_config'}{'examples'}{'admin'} || {}
$self->{'_ep_config'}{'examples'}{'admin'}
Truth table0%0/2
A
A= $self->{'_ep_config'}{'examples'}{'admin'}
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | $self->{'admin_config'}->{'vardir'} ||= '/home/httpd/html/admin/var'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"admin_config"}{"vardir"} ||= "/home/httpd/html/admin/var"
MC/DC0%0/1
$self->{"admin_config"}{"vardir"} ||= "/home/httpd/html/admin/var"
$self->{"admin_config"}{"vardir"}
Truth table0%0/2
A
A= $self->{"admin_config"}{"vardir"}
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub _prefs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prefs: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $self = shift; my $prefs = shift; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $vardir = $self->{'admin_config'}->{'vardir'}; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $prefs_file = "$vardir/prefs"; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if (!$prefs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | # Load Prefs | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $self->{'prefs'} = (do $prefs_file) || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
do $prefs_file || {}
MC/DC0%0/1
do $prefs_file || {}
do $prefs_file
Truth table0%0/2
A
A= 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 | ▶ | if ($self->{'debug'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | print "Saving Preferences to $prefs_file.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $self->print("Saving data:\n$d\n"); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if (!open($fh, ">$prefs_file") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
open $fh, ">$prefs_file" and print $fh "$d\n" and close $fh
open $fh, ">$prefs_file" and print $fh "$d\n"
MC/DC0%0/3
open $fh, ">$prefs_file" and print $fh "$d\n" and close $fh
open $fh, ">$prefs_file"
print $fh "$d\n"
close $fh
Truth table0%0/4
A and B and C
A= open $fh, ">$prefs_file"B= print $fh "$d\n"C= close $fh
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _ep_html_ep_examples_admin_squid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ep_html_ep_examples_admin_squid: not called CC=20 SCAR=60.4
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $self = shift; my $attr = shift; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $cgi = $self->{'cgi'}; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $prefs = $self->_prefs(); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $debug = $self->{'debug'}; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my $verify_squid_range = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my($from, $to, $active, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | require Socket; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my($f, $t); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if (!($f = Socket::inet_aton($from))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | die "Invalid IP address: $from"; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if (!($t = Socket::inet_aton($to))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | if ($from or $to) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$from or $to
MC/DC0%0/2
$from or $to
$from
$to
Truth table0%0/3
A or B
A= $fromB= $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 | ▶ | if ($cgi->param("delete_ip_$i")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | if (!defined($from) && !defined($to)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $from or defined $to
MC/DC0%0/2
defined $from or defined $to
defined $from
defined $to
Truth table0%0/3
A or B
A= defined $fromB= 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 | ▶ | if ($modified) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | $self->print("Modifications detected.\n") if $debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $prefs->{'squid_ranges'} = \@range; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $self->_prefs($prefs); | |||||||||||||||||||||||||||||||||||||||||
| 129 | my $path_users_modified = | ||||||||||||||||||||||||||||||||||||||||||
| 130 | ($attr->{'users-modified-path'} || | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | $self->{'admin_config'}->{'users_modified_path'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attr->{'users-modified-path'} || $self->{'admin_config'}{'users_modified_path'}
MC/DC0%0/2
$attr->{'users-modified-path'} || $self->{'admin_config'}{'users_modified_path'}
$attr->{'users-modified-path'}
$self->{'admin_config'}{'users_modified_path'}
Truth table0%0/3
A || B
A= $attr->{'users-modified-path'}B= $self->{'admin_config'}{'users_modified_path'}
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | or die "Path of usersModified binary not set"; | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ($path_users_modified ne 'none') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | die "No such binary: $path_users_modified" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | unless -f $path_users_modified; | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my @command = ($path_users_modified, '--squid'); | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | foreach my $r (@range) { | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | next unless $r->{'active'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | push(@command, | |||||||||||||||||||||||||||||||||||||||||
| 140 | "--range", "$r->{'from'},$r->{'to'},$r->{'name'}"); | ||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | $self->print("Executing command: ", join(" ", @command), "\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | system @command; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | $self->print("No modifications detected.\n") if $debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | $prefs->{'squid_ranges'} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$prefs->{"squid_ranges"} ||= []
MC/DC0%0/1
$prefs->{"squid_ranges"} ||= []
$prefs->{"squid_ranges"}
Truth table0%0/2
A
A= $prefs->{"squid_ranges"}
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | @range = sort { $a->{name} cmp $b->{name}} @{$prefs->{'squid_ranges'}}; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $self->{'ranges'} = \@range; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ($debug) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $self->print("Squid IP ranges:\n"); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | foreach my $r (@{$prefs->{'squid_ranges'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 155 | $self->printf(" Name %s, From %s, To %s, Active %s\n", | ||||||||||||||||||||||||||||||||||||||||||
| 156 | $r->{'name'}, $r->{'from'}, $r->{'to'}, | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $r->{'active'}); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $self->{'admin_config'}->{'squid_conf_path'} ||= '/etc/squid.conf'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"admin_config"}{"squid_conf_path"} ||= "/etc/squid.conf"
MC/DC0%0/1
$self->{"admin_config"}{"squid_conf_path"} ||= "/etc/squid.conf"
$self->{"admin_config"}{"squid_conf_path"}
Truth table0%0/2
A
A= $self->{"admin_config"}{"squid_conf_path"}
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ''; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub _format_RANGE_SELECTED { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_RANGE_SELECTED: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $self = shift; my $val = shift; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | $val ? "" : "SELECTED"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||