| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#! /usr/bin/perl |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# $Id: Replace.pm 75 2009-08-12 22:08:28Z lem $ |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::Radius::Server::Set::Replace; |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1809
|
use 5.008; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
38
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
28
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
10
|
|
|
|
1
|
|
|
|
|
77
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = do { sprintf "%0.3f", 1+(q$Revision: 75 $ =~ /\d+/g)[0]/1000 }; |
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use Net::Radius::Server::Base qw/:set/; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
7
|
|
|
15
|
1
|
|
|
1
|
|
31
|
use base qw/Net::Radius::Server::Set/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
86
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/attr vsattr result/); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub set_attr |
|
19
|
|
|
|
|
|
|
{ |
|
20
|
|
|
|
|
|
|
my $self = shift; |
|
21
|
|
|
|
|
|
|
my $r_data = shift; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $rep = $r_data->{response}; |
|
24
|
|
|
|
|
|
|
my $spec = $self->attr || []; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $i = 0; |
|
27
|
|
|
|
|
|
|
while ($i < @$spec) |
|
28
|
|
|
|
|
|
|
{ |
|
29
|
|
|
|
|
|
|
my $attr = $spec->[$i]; |
|
30
|
|
|
|
|
|
|
my $cond = $spec->[$i + 1]; |
|
31
|
|
|
|
|
|
|
my $newv = $spec->[$i + 2]; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
if (not grep { $_ eq $attr } $rep->attributes) |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
|
|
|
|
|
|
$self->log(4, "Skip $attr replacement"); |
|
36
|
|
|
|
|
|
|
$i += 3; |
|
37
|
|
|
|
|
|
|
next; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $curv = $rep->attr($attr); |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
if (not ref($cond)) |
|
43
|
|
|
|
|
|
|
{ |
|
44
|
|
|
|
|
|
|
if ($curv eq $cond) |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
|
|
|
|
|
|
$self->log(4, "Replace $attr $curv with $newv (eq $cond)"); |
|
47
|
|
|
|
|
|
|
$rep->set_attr($attr, $newv); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
else |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
|
|
|
|
|
|
$self->log(4, |
|
52
|
|
|
|
|
|
|
"Don't replace $attr $curv with $newv (!= $cond)"); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
elsif (ref($cond) eq 'Regexp') |
|
56
|
|
|
|
|
|
|
{ |
|
57
|
|
|
|
|
|
|
if ($curv =~ m/$cond/) |
|
58
|
|
|
|
|
|
|
{ |
|
59
|
|
|
|
|
|
|
$self->log(4, "Replace $attr $curv with $newv (=~ $cond)"); |
|
60
|
|
|
|
|
|
|
$rep->set_attr($attr, $newv); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
else |
|
63
|
|
|
|
|
|
|
{ |
|
64
|
|
|
|
|
|
|
$self->log(4, |
|
65
|
|
|
|
|
|
|
"Don't replace $attr $curv with $newv (!~ $cond)"); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
elsif (ref($cond) eq 'NetAddr::IP') |
|
69
|
|
|
|
|
|
|
{ |
|
70
|
|
|
|
|
|
|
my $ip = new NetAddr::IP $curv; |
|
71
|
|
|
|
|
|
|
if ($ip and $cond->contains($ip)) |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
|
|
|
|
|
|
$self->log(4, "Replace $attr $curv with $newv ($ip)"); |
|
74
|
|
|
|
|
|
|
$rep->set_attr($attr, $newv); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
else |
|
77
|
|
|
|
|
|
|
{ |
|
78
|
|
|
|
|
|
|
$self->log(4, |
|
79
|
|
|
|
|
|
|
"Don't replace $attr $curv with $newv " |
|
80
|
|
|
|
|
|
|
. "(!contains $cond)"); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
else |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
|
|
|
|
|
|
die $self->description . ": Don't know how to work with $cond\n"; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$i += 3; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub set_vsattr |
|
94
|
|
|
|
|
|
|
{ |
|
95
|
|
|
|
|
|
|
my $self = shift; |
|
96
|
|
|
|
|
|
|
my $r_data = shift; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $rep = $r_data->{response}; |
|
99
|
|
|
|
|
|
|
my $spec = $self->vsattr || []; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $i = 0; |
|
102
|
|
|
|
|
|
|
while ($i < @$spec) |
|
103
|
|
|
|
|
|
|
{ |
|
104
|
|
|
|
|
|
|
my $vend = $spec->[$i]; |
|
105
|
|
|
|
|
|
|
my $attr = $spec->[$i + 1]; |
|
106
|
|
|
|
|
|
|
my $cond = $spec->[$i + 2]; |
|
107
|
|
|
|
|
|
|
my $newv = $spec->[$i + 3]; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
if (not grep { $_ eq $attr } $rep->vsattributes($vend)) |
|
110
|
|
|
|
|
|
|
{ |
|
111
|
|
|
|
|
|
|
$self->log(4, "Skip $vend" . ".$attr replacement"); |
|
112
|
|
|
|
|
|
|
$i += 4; |
|
113
|
|
|
|
|
|
|
next; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
for my $curv (@{$rep->vsattr($vend, $attr) || []}) |
|
117
|
|
|
|
|
|
|
{ |
|
118
|
|
|
|
|
|
|
if (not ref($cond)) |
|
119
|
|
|
|
|
|
|
{ |
|
120
|
|
|
|
|
|
|
if ($curv eq $cond) |
|
121
|
|
|
|
|
|
|
{ |
|
122
|
|
|
|
|
|
|
$self->log(4, "Replace $vend" . ".$attr $curv with $newv" |
|
123
|
|
|
|
|
|
|
. " (eq $cond)"); |
|
124
|
|
|
|
|
|
|
$curv = $newv; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
else |
|
127
|
|
|
|
|
|
|
{ |
|
128
|
|
|
|
|
|
|
$self->log(4, "Don't replace $vend" |
|
129
|
|
|
|
|
|
|
. ".$attr $curv with $newv (ne $cond)"); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
elsif (ref($cond) eq 'Regexp') |
|
133
|
|
|
|
|
|
|
{ |
|
134
|
|
|
|
|
|
|
if ($curv =~ m/$cond/) |
|
135
|
|
|
|
|
|
|
{ |
|
136
|
|
|
|
|
|
|
$self->log(4, "Replace $vend" . ".$attr $curv with $newv" |
|
137
|
|
|
|
|
|
|
. " (=~ $cond)"); |
|
138
|
|
|
|
|
|
|
$curv = $newv; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
else |
|
141
|
|
|
|
|
|
|
{ |
|
142
|
|
|
|
|
|
|
$self->log(4, "Don't replace $vend" |
|
143
|
|
|
|
|
|
|
. ".$attr $curv with $newv (=~ $cond)"); |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
elsif (ref($cond) eq 'NetAddr::IP') |
|
147
|
|
|
|
|
|
|
{ |
|
148
|
|
|
|
|
|
|
my $ip = new NetAddr::IP $curv; |
|
149
|
|
|
|
|
|
|
if ($ip and $cond->contains($ip)) |
|
150
|
|
|
|
|
|
|
{ |
|
151
|
|
|
|
|
|
|
$self->log(4, "Replace $vend" . ".$attr $curv with $newv" |
|
152
|
|
|
|
|
|
|
. " ($cond)"); |
|
153
|
|
|
|
|
|
|
$curv = $newv; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
else |
|
156
|
|
|
|
|
|
|
{ |
|
157
|
|
|
|
|
|
|
$self->log(4, "Don't replace $vend" |
|
158
|
|
|
|
|
|
|
. ".$attr $curv with $newv ($cond)"); |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
else |
|
163
|
|
|
|
|
|
|
{ |
|
164
|
|
|
|
|
|
|
die $self->description . |
|
165
|
|
|
|
|
|
|
": Don't know how to work with $cond\n"; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
$i += 4; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
42; |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
__END__ |