1 |
brianr |
1.1 |
diff -urN smeserver-manager-0.1.4.old/root/usr/share/smanager/lib/SrvMngr/Controller/Hostentries.pm smeserver-manager-0.1.4/root/usr/share/smanager/lib/SrvMngr/Controller/Hostentries.pm |
2 |
|
|
--- smeserver-manager-0.1.4.old/root/usr/share/smanager/lib/SrvMngr/Controller/Hostentries.pm 2024-02-21 11:20:59.155611136 +0000 |
3 |
|
|
+++ smeserver-manager-0.1.4/root/usr/share/smanager/lib/SrvMngr/Controller/Hostentries.pm 2024-02-21 15:00:00.000000000 +0000 |
4 |
|
|
@@ -27,557 +27,574 @@ |
5 |
|
|
use esmith::NetworksDB; |
6 |
|
|
use HTML::Entities; |
7 |
|
|
use Net::IPv4Addr qw(ipv4_in_network); |
8 |
|
|
-#use URI::Escape; |
9 |
|
|
|
10 |
|
|
+#use URI::Escape; |
11 |
|
|
|
12 |
|
|
-our $ddb = esmith::DomainsDB->open || die "Couldn't open hostentries db"; |
13 |
|
|
-our $cdb = esmith::ConfigDB->open || die "Couldn't open configuration db"; |
14 |
|
|
-our $hdb = esmith::HostsDB->open || die "Couldn't open hosts db"; |
15 |
|
|
+our $ddb = esmith::DomainsDB->open || die "Couldn't open hostentries db"; |
16 |
|
|
+our $cdb = esmith::ConfigDB->open || die "Couldn't open configuration db"; |
17 |
|
|
+our $hdb = esmith::HostsDB->open || die "Couldn't open hosts db"; |
18 |
|
|
our $ndb = esmith::NetworksDB->open || die "Couldn't open networks db"; |
19 |
|
|
|
20 |
|
|
- |
21 |
|
|
sub main { |
22 |
|
|
|
23 |
|
|
my $c = shift; |
24 |
|
|
- $c->app->log->info($c->log_req); |
25 |
|
|
+ $c->app->log->info( $c->log_req ); |
26 |
|
|
|
27 |
|
|
my %hos_datas = (); |
28 |
|
|
- my $title = $c->l('hos_FORM_TITLE'); |
29 |
|
|
- my $notif = ''; |
30 |
|
|
+ my $title = $c->l('hos_FORM_TITLE'); |
31 |
|
|
+ my $notif = ''; |
32 |
|
|
|
33 |
|
|
$hos_datas{trt} = 'LIST'; |
34 |
|
|
|
35 |
|
|
my %dom_hosts = (); |
36 |
|
|
|
37 |
|
|
- foreach my $d ( @{domains_list()} ) |
38 |
|
|
- { |
39 |
|
|
- $dom_hosts {$d} = { COUNT => 0, HOSTS => [] }; |
40 |
|
|
+ foreach my $d ( @{ domains_list() } ) { |
41 |
|
|
+ $dom_hosts{$d} = { COUNT => 0, HOSTS => [] }; |
42 |
|
|
|
43 |
|
|
- if (my @hosts = $hdb->get_hosts_by_domain($d)) |
44 |
|
|
- { |
45 |
|
|
- $dom_hosts {$d} {'COUNT'} = scalar( @hosts ); |
46 |
|
|
- # my @entries; |
47 |
|
|
- push @{ $dom_hosts {$d} {'HOSTS'} }, |
48 |
|
|
- host_data( $_ ) foreach (@hosts); |
49 |
|
|
+ if ( my @hosts = $hdb->get_hosts_by_domain($d) ) { |
50 |
|
|
+ $dom_hosts{$d}{'COUNT'} = scalar(@hosts); |
51 |
|
|
+ |
52 |
|
|
+ # my @entries; |
53 |
|
|
+ push @{ $dom_hosts{$d}{'HOSTS'} }, host_data($_) foreach (@hosts); |
54 |
|
|
} |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
- $c->stash( title => $title, notif => $notif, hos_datas => \%hos_datas, dom_hosts => \%dom_hosts ); |
58 |
|
|
- $c->render(template => 'hostentries'); |
59 |
|
|
- |
60 |
|
|
-}; |
61 |
|
|
+ $c->stash( |
62 |
|
|
+ title => $title, |
63 |
|
|
+ notif => $notif, |
64 |
|
|
+ hos_datas => \%hos_datas, |
65 |
|
|
+ dom_hosts => \%dom_hosts |
66 |
|
|
+ ); |
67 |
|
|
+ $c->render( template => 'hostentries' ); |
68 |
|
|
|
69 |
|
|
+} |
70 |
|
|
|
71 |
|
|
sub do_display { |
72 |
|
|
|
73 |
|
|
my $c = shift; |
74 |
|
|
- $c->app->log->info($c->log_req); |
75 |
|
|
+ $c->app->log->info( $c->log_req ); |
76 |
|
|
|
77 |
|
|
- my $rt = $c->current_route; |
78 |
|
|
- my $trt = $c->param('trt') || 'LST'; |
79 |
|
|
+ my $rt = $c->current_route; |
80 |
|
|
+ my $trt = $c->param('trt') || 'LST'; |
81 |
|
|
my $hostname = $c->param('Hostname') || ''; |
82 |
|
|
|
83 |
|
|
$trt = 'ADD' if ( $rt eq 'hostentryadd' ); |
84 |
|
|
- $trt = 'LST' if ($trt ne 'DEL' && $trt ne 'UPD' && $trt ne 'ADD'); |
85 |
|
|
+ $trt = 'LST' if ( $trt ne 'DEL' && $trt ne 'UPD' && $trt ne 'ADD' ); |
86 |
|
|
|
87 |
|
|
my %hos_datas = (); |
88 |
|
|
- my $title = $c->l('hos_FORM_TITLE'); |
89 |
|
|
- my $notif = ''; |
90 |
|
|
+ my $title = $c->l('hos_FORM_TITLE'); |
91 |
|
|
+ my $notif = ''; |
92 |
|
|
|
93 |
|
|
$hos_datas{'trt'} = $trt; |
94 |
|
|
|
95 |
|
|
- if ( $trt eq 'ADD' ) { |
96 |
|
|
- |
97 |
|
|
- } |
98 |
|
|
- |
99 |
|
|
- if ( $trt eq 'UPD' or $trt eq 'DEL' ) { |
100 |
|
|
- |
101 |
|
|
- my $rec = $hdb->get($hostname); |
102 |
|
|
- if ( $rec ) { |
103 |
|
|
- $hos_datas{hostname} = $rec->key; |
104 |
|
|
- ( $hos_datas{name}, $hos_datas{domain} ) = split_hostname($hostname); |
105 |
|
|
- $hos_datas{internalip} = $rec->prop('InternalIP') || ''; |
106 |
|
|
- $hos_datas{externalip} = $rec->prop('ExternalIP') || ''; |
107 |
|
|
- $hos_datas{macaddress} = $rec->prop('MACAddress') || ''; |
108 |
|
|
- $hos_datas{hosttype} = $rec->prop('HostType'); |
109 |
|
|
- $hos_datas{comment} = HTML::Entities::encode($rec->prop('Comment')); |
110 |
|
|
- } else { |
111 |
|
|
- $notif = "Hostname $hostname not found !" |
112 |
|
|
- } |
113 |
|
|
- } |
114 |
|
|
- |
115 |
|
|
- #if ( $trt eq 'DEL' ) { |
116 |
|
|
- |
117 |
|
|
- # my $rec = $hdb->get($hostname); |
118 |
|
|
- # if ( $rec ) { |
119 |
|
|
- # get_hos_datas( $rec, %hos_datas ); |
120 |
|
|
- # } else { |
121 |
|
|
- # $notif = "Hostname $hostname not found !" |
122 |
|
|
- # } |
123 |
|
|
- #} |
124 |
|
|
+ if ( $trt eq 'ADD' ) { |
125 |
|
|
|
126 |
|
|
- if ( $trt eq 'LIST' ) { |
127 |
|
|
+ } |
128 |
|
|
|
129 |
|
|
- } |
130 |
|
|
+ if ( $trt eq 'UPD' or $trt eq 'DEL' ) { |
131 |
|
|
+ |
132 |
|
|
+ my $rec = $hdb->get($hostname); |
133 |
|
|
+ if ($rec) { |
134 |
|
|
+ $hos_datas{hostname} = $rec->key; |
135 |
|
|
+ ( $hos_datas{name}, $hos_datas{domain} ) = |
136 |
|
|
+ split_hostname($hostname); |
137 |
|
|
+ $hos_datas{internalip} = $rec->prop('InternalIP') || ''; |
138 |
|
|
+ $hos_datas{externalip} = $rec->prop('ExternalIP') || ''; |
139 |
|
|
+ $hos_datas{macaddress} = $rec->prop('MACAddress') || ''; |
140 |
|
|
+ $hos_datas{hosttype} = $rec->prop('HostType'); |
141 |
|
|
+ $hos_datas{comment} = |
142 |
|
|
+ HTML::Entities::encode( $rec->prop('Comment') ); |
143 |
|
|
+ } |
144 |
|
|
+ else { |
145 |
|
|
+ $notif = "Hostname $hostname not found !"; |
146 |
|
|
+ } |
147 |
|
|
+ } |
148 |
|
|
+ |
149 |
|
|
+ #if ( $trt eq 'DEL' ) { |
150 |
|
|
+ |
151 |
|
|
+ # my $rec = $hdb->get($hostname); |
152 |
|
|
+ # if ( $rec ) { |
153 |
|
|
+ # get_hos_datas( $rec, %hos_datas ); |
154 |
|
|
+ # } else { |
155 |
|
|
+ # $notif = "Hostname $hostname not found !" |
156 |
|
|
+ # } |
157 |
|
|
+ #} |
158 |
|
|
+ |
159 |
|
|
+ if ( $trt eq 'LIST' ) { |
160 |
|
|
+ |
161 |
|
|
+ } |
162 |
|
|
|
163 |
|
|
$c->stash( title => $title, notif => $notif, hos_datas => \%hos_datas ); |
164 |
|
|
$c->render( template => 'hostentries' ); |
165 |
|
|
|
166 |
|
|
-}; |
167 |
|
|
- |
168 |
|
|
+} |
169 |
|
|
|
170 |
|
|
sub do_update { |
171 |
|
|
|
172 |
|
|
my $c = shift; |
173 |
|
|
- $c->app->log->info($c->log_req); |
174 |
|
|
+ $c->app->log->info( $c->log_req ); |
175 |
|
|
|
176 |
|
|
my $rt = $c->current_route; |
177 |
|
|
- my $trt = ($c->param('trt') || 'LIST'); |
178 |
|
|
+ my $trt = ( $c->param('trt') || 'LIST' ); |
179 |
|
|
|
180 |
|
|
my %hos_datas = (); |
181 |
|
|
- my $title = $c->l('hos_FORM_TITLE'); |
182 |
|
|
- my $notif = ''; |
183 |
|
|
- my $result = ''; |
184 |
|
|
- |
185 |
|
|
- $hos_datas{'name'} = lc $c->param('Name'); |
186 |
|
|
- $hos_datas{'domain'} = lc $c->param('Domain'); |
187 |
|
|
- $hos_datas{'hostname'} = $c->param('Hostname'); |
188 |
|
|
- $hos_datas{'comment'} = $c->param('Comment'); |
189 |
|
|
- $hos_datas{'hosttype'} = $c->param('Hosttype'); |
190 |
|
|
+ my $title = $c->l('hos_FORM_TITLE'); |
191 |
|
|
+ my $notif = ''; |
192 |
|
|
+ my $result = ''; |
193 |
|
|
+ |
194 |
|
|
+ $hos_datas{'name'} = lc $c->param('Name'); |
195 |
|
|
+ $hos_datas{'domain'} = lc $c->param('Domain'); |
196 |
|
|
+ $hos_datas{'hostname'} = $c->param('Hostname'); |
197 |
|
|
+ $hos_datas{'comment'} = $c->param('Comment'); |
198 |
|
|
+ $hos_datas{'hosttype'} = $c->param('Hosttype'); |
199 |
|
|
$hos_datas{'internalip'} = $c->param('Internalip'); |
200 |
|
|
$hos_datas{'macaddress'} = $c->param('Macaddress'); |
201 |
|
|
$hos_datas{'externalip'} = $c->param('Externalip'); |
202 |
|
|
my $hostname = "$hos_datas{'name'}.$hos_datas{'domain'}"; |
203 |
|
|
- |
204 |
|
|
if ( $trt eq 'ADD' ) { |
205 |
|
|
+ |
206 |
|
|
+ $hos_datas{'hostname'} = $hostname; |
207 |
|
|
|
208 |
|
|
- # controls |
209 |
|
|
- my $res = ''; |
210 |
|
|
- unless ( $hos_datas{'name'} =~ /^[a-z0-9][a-z0-9-]*$/ ) { |
211 |
|
|
- $result .= $c->l('hos_HOSTNAME_VALIDATOR_ERROR') . '<br>'; |
212 |
|
|
- } |
213 |
|
|
- |
214 |
|
|
- unless ( $hos_datas{comment} =~ /^([a-zA-Z0-9][\_\.\-,A-Za-z0-9\s]*)$/ || $hos_datas{comment} eq '' ) { |
215 |
|
|
- $result .= $c->l('hos_HOSTNAME_COMMENT_ERROR') . '<br>'; |
216 |
|
|
- } |
217 |
|
|
- |
218 |
|
|
- # Look for duplicate hosts. |
219 |
|
|
- my $hostrec = undef; |
220 |
|
|
- if ( $hostrec = $hdb->get($hostname) ) { |
221 |
|
|
- $result .= $c->l('hos_HOSTNAME_EXISTS_ERROR', |
222 |
|
|
- {fullHostName => $hostname, type => $hostrec->prop('HostType')}) . '<br>',; |
223 |
|
|
- } |
224 |
|
|
- |
225 |
|
|
- if ( ! $result and $hos_datas{hosttype} ne 'Self' ) { |
226 |
|
|
- if ( $hos_datas{hosttype} eq 'Local' ) { |
227 |
|
|
- $hos_datas{'trt'} = 'ALC'; # ADD/LOCAL |
228 |
|
|
- } else { |
229 |
|
|
- $hos_datas{'trt'} = 'ARM'; # ADD/REMOVE |
230 |
|
|
- } |
231 |
|
|
- |
232 |
|
|
- $c->stash( title => $title, notif => '', hos_datas => \%hos_datas ); |
233 |
|
|
- return $c->render( template => 'hostentries' ); |
234 |
|
|
- } |
235 |
|
|
- |
236 |
|
|
- #!#$result .= ' blocked'; |
237 |
|
|
- |
238 |
|
|
- if ( ! $result ) { |
239 |
|
|
- $res = create_modify_hostentry( $c, $trt, %hos_datas ); |
240 |
|
|
- $result .= $res unless $res eq 'OK'; |
241 |
|
|
- } |
242 |
|
|
- if ( ! $result ) { |
243 |
|
|
- $result = $c->l('hos_CREATE_OR_MODIFY_SUCCEEDED') . ' ' . $hostname; |
244 |
|
|
- $trt = 'SUC'; |
245 |
|
|
- } |
246 |
|
|
- } |
247 |
|
|
+ # controls |
248 |
|
|
+ my $res = ''; |
249 |
|
|
+ unless ( $hos_datas{'name'} =~ /^[a-z0-9][a-z0-9-]*$/ ) { |
250 |
|
|
+ $result .= $c->l('hos_HOSTNAME_VALIDATOR_ERROR') . '<br>'; |
251 |
|
|
+ } |
252 |
|
|
|
253 |
|
|
+ unless ( $hos_datas{comment} =~ /^([a-zA-Z0-9][\_\.\-,A-Za-z0-9\s]*)$/ |
254 |
|
|
+ || $hos_datas{comment} eq '' ) |
255 |
|
|
+ { |
256 |
|
|
+ $result .= $c->l('hos_HOSTNAME_COMMENT_ERROR') . '<br>'; |
257 |
|
|
+ } |
258 |
|
|
|
259 |
|
|
- if ( $trt eq 'UPD' ) { |
260 |
|
|
+ # Look for duplicate hosts. |
261 |
|
|
+ my $hostrec = undef; |
262 |
|
|
+ if ( $hostrec = $hdb->get($hostname) ) { |
263 |
|
|
+ $result .= $c->l( |
264 |
|
|
+ 'hos_HOSTNAME_EXISTS_ERROR', |
265 |
|
|
+ { |
266 |
|
|
+ fullHostName => $hostname, |
267 |
|
|
+ type => $hostrec->prop('HostType') |
268 |
|
|
+ } |
269 |
|
|
+ ) . '<br>',; |
270 |
|
|
+ } |
271 |
|
|
+ |
272 |
|
|
+ if ( !$result and $hos_datas{hosttype} ne 'Self' ) { |
273 |
|
|
+ if ( $hos_datas{hosttype} eq 'Local' ) { |
274 |
|
|
+ $hos_datas{'trt'} = 'ALC'; # ADD/LOCAL |
275 |
|
|
+ } |
276 |
|
|
+ else { |
277 |
|
|
+ $hos_datas{'trt'} = 'ARM'; # ADD/REMOVE |
278 |
|
|
+ } |
279 |
|
|
+ |
280 |
|
|
+ $c->stash( title => $title, notif => '', hos_datas => \%hos_datas ); |
281 |
|
|
+ return $c->render( template => 'hostentries' ); |
282 |
|
|
+ } |
283 |
|
|
+ |
284 |
|
|
+ #!#$result .= ' blocked'; |
285 |
|
|
|
286 |
|
|
- # controls |
287 |
|
|
- my $res = ''; |
288 |
|
|
- #$res = validate_description( $c, $account ); |
289 |
|
|
- #$result .= $res unless $res eq 'OK'; |
290 |
|
|
- |
291 |
|
|
- unless ( $hos_datas{comment} =~ /^([a-zA-Z0-9][\_\.\-,A-Za-z0-9\s]*)$/ || $hos_datas{comment} eq '' ) { |
292 |
|
|
- $result .= $c->l('hos_HOSTNAME_COMMENT_ERROR') . '<br>'; |
293 |
|
|
- } |
294 |
|
|
- |
295 |
|
|
- if ( ! $result and $hos_datas{hosttype} ne 'Self' ) { |
296 |
|
|
- if ( $hos_datas{hosttype} eq 'Local' ) { |
297 |
|
|
- $hos_datas{'trt'} = 'ULC'; # UPDATE/LOCAL |
298 |
|
|
- } else { |
299 |
|
|
- $hos_datas{'trt'} = 'URM'; # UPDATE/REMOVE |
300 |
|
|
- } |
301 |
|
|
- |
302 |
|
|
- $c->stash( title => $title, notif => '', hos_datas => \%hos_datas ); |
303 |
|
|
- return $c->render( template => 'hostentries' ); |
304 |
|
|
- } |
305 |
|
|
- |
306 |
|
|
- #!#$result .= 'blocked'; |
307 |
|
|
- |
308 |
|
|
- if ( ! $result ) { |
309 |
|
|
- $res = create_modify_hostentry( $c, $trt, %hos_datas ); |
310 |
|
|
- $result .= $res unless $res eq 'OK'; |
311 |
|
|
- } |
312 |
|
|
- |
313 |
|
|
- if ( ! $result ) { |
314 |
|
|
- $result = $c->l('hos_MODIFY_SUCCEEDED') . ' ' . $hostname; |
315 |
|
|
- $trt = 'SUC'; |
316 |
|
|
- } |
317 |
|
|
+ if ( !$result ) { |
318 |
|
|
+ $res = create_modify_hostentry( $c, $trt, %hos_datas ); |
319 |
|
|
+ $result .= $res unless $res eq 'OK'; |
320 |
|
|
+ } |
321 |
|
|
+ if ( !$result ) { |
322 |
|
|
+ $result = $c->l('hos_CREATE_OR_MODIFY_SUCCEEDED') . ' ' . $hostname; |
323 |
|
|
+ $trt = 'SUC'; |
324 |
|
|
+ } |
325 |
|
|
} |
326 |
|
|
|
327 |
|
|
+ if ( $trt eq 'UPD' ) { |
328 |
|
|
|
329 |
|
|
- if ( $trt =~ /^.LC$/ ) { |
330 |
|
|
+ # controls |
331 |
|
|
+ my $res = ''; |
332 |
|
|
+ |
333 |
|
|
+ #$res = validate_description( $c, $account ); |
334 |
|
|
+ #$result .= $res unless $res eq 'OK'; |
335 |
|
|
+ |
336 |
|
|
+ unless ( $hos_datas{comment} =~ /^([a-zA-Z0-9][\_\.\-,A-Za-z0-9\s]*)$/ |
337 |
|
|
+ || $hos_datas{comment} eq '' ) |
338 |
|
|
+ { |
339 |
|
|
+ $result .= $c->l('hos_HOSTNAME_COMMENT_ERROR') . '<br>'; |
340 |
|
|
+ } |
341 |
|
|
+ |
342 |
|
|
+ if ( !$result and $hos_datas{hosttype} ne 'Self' ) { |
343 |
|
|
+ if ( $hos_datas{hosttype} eq 'Local' ) { |
344 |
|
|
+ $hos_datas{'trt'} = 'ULC'; # UPDATE/LOCAL |
345 |
|
|
+ } |
346 |
|
|
+ else { |
347 |
|
|
+ $hos_datas{'trt'} = 'URM'; # UPDATE/REMOVE |
348 |
|
|
+ } |
349 |
|
|
+ |
350 |
|
|
+ $c->stash( title => $title, notif => '', hos_datas => \%hos_datas ); |
351 |
|
|
+ return $c->render( template => 'hostentries' ); |
352 |
|
|
+ } |
353 |
|
|
+ |
354 |
|
|
+ #!#$result .= 'blocked'; |
355 |
|
|
+ |
356 |
|
|
+ if ( !$result ) { |
357 |
|
|
+ $res = create_modify_hostentry( $c, $trt, %hos_datas ); |
358 |
|
|
+ $result .= $res unless $res eq 'OK'; |
359 |
|
|
+ } |
360 |
|
|
|
361 |
|
|
- # controls |
362 |
|
|
- my $res = ''; |
363 |
|
|
- $res = ip_number( $c, $hos_datas{internalip} ); |
364 |
|
|
- $result .= $res . ' ' unless $res eq 'OK'; |
365 |
|
|
- |
366 |
|
|
- $res = not_in_dhcp_range( $c, $hos_datas{internalip} ); |
367 |
|
|
- $result .= $res . ' ' unless $res eq 'OK'; |
368 |
|
|
- |
369 |
|
|
- $res = not_taken( $c, $hos_datas{internalip} ); |
370 |
|
|
- $result .= $res . ' ' unless $res eq 'OK'; |
371 |
|
|
- |
372 |
|
|
- $res = must_be_local( $c, $hos_datas{internalip} ); |
373 |
|
|
- $result .= $res . ' ' unless $res eq 'OK'; |
374 |
|
|
- |
375 |
|
|
- $res = mac_address_or_blank( $c, $hos_datas{macaddress} ); |
376 |
|
|
- $result .= $res . ' ' unless $res eq 'OK'; |
377 |
|
|
- |
378 |
|
|
- #!#$result .= 'blocked'; |
379 |
|
|
- |
380 |
|
|
- if ( ! $result ) { |
381 |
|
|
- $res = create_modify_hostentry( $c, $trt, %hos_datas ); |
382 |
|
|
- $result .= $res unless $res eq 'OK'; |
383 |
|
|
- } |
384 |
|
|
- |
385 |
|
|
- if ( ! $result ) { |
386 |
|
|
- $result = $c->l('hos_MODIFY_SUCCEEDED') . ' ' . $hostname; |
387 |
|
|
- $trt = 'SUC'; |
388 |
|
|
- } |
389 |
|
|
+ if ( !$result ) { |
390 |
|
|
+ $result = $c->l('hos_MODIFY_SUCCEEDED') . ' ' . $hostname; |
391 |
|
|
+ $trt = 'SUC'; |
392 |
|
|
+ } |
393 |
|
|
} |
394 |
|
|
|
395 |
|
|
+ if ( $trt =~ /^.LC$/ ) { |
396 |
|
|
+ |
397 |
|
|
+ # controls |
398 |
|
|
+ my $res = ''; |
399 |
|
|
+ $res = ip_number( $c, $hos_datas{internalip} ); |
400 |
|
|
+ $result .= $res . ' ' unless $res eq 'OK'; |
401 |
|
|
|
402 |
|
|
- if ( $trt =~ /^.RM$/ ) { |
403 |
|
|
+ $res = not_in_dhcp_range( $c, $hos_datas{internalip} ); |
404 |
|
|
+ $result .= $res . ' ' unless $res eq 'OK'; |
405 |
|
|
+ |
406 |
|
|
+ $res = not_taken( $c, $hos_datas{internalip} ); |
407 |
|
|
+ $result .= $res . ' ' unless $res eq 'OK'; |
408 |
|
|
+ |
409 |
|
|
+ $res = must_be_local( $c, $hos_datas{internalip} ); |
410 |
|
|
+ $result .= $res . ' ' unless $res eq 'OK'; |
411 |
|
|
+ |
412 |
|
|
+ $res = mac_address_or_blank( $c, $hos_datas{macaddress} ); |
413 |
|
|
+ $result .= $res . ' ' unless $res eq 'OK'; |
414 |
|
|
|
415 |
|
|
- # controls |
416 |
|
|
- my $res = ''; |
417 |
|
|
- $res = ip_number_or_blank( $c, $hos_datas{externalip} ); |
418 |
|
|
- $result .= $res . '<br>' unless $res eq 'OK'; |
419 |
|
|
- |
420 |
|
|
- #!#$result .= 'blocked'; |
421 |
|
|
- |
422 |
|
|
- if ( ! $result ) { |
423 |
|
|
- $res = create_modify_hostentry( $c, $trt, %hos_datas ); |
424 |
|
|
- $result .= $res unless $res eq 'OK'; |
425 |
|
|
- } |
426 |
|
|
- |
427 |
|
|
- if ( ! $result ) { |
428 |
|
|
- $result = $c->l('hos_MODIFY_SUCCEEDED') . ' ' . $hostname; |
429 |
|
|
- $trt = 'SUC'; |
430 |
|
|
- } |
431 |
|
|
+ #!#$result .= 'blocked'; |
432 |
|
|
|
433 |
|
|
+ if ( !$result ) { |
434 |
|
|
+ $res = create_modify_hostentry( $c, $trt, %hos_datas ); |
435 |
|
|
+ $result .= $res unless $res eq 'OK'; |
436 |
|
|
+ } |
437 |
|
|
+ |
438 |
|
|
+ if ( !$result ) { |
439 |
|
|
+ $result = $c->l('hos_MODIFY_SUCCEEDED') . ' ' . $hostname; |
440 |
|
|
+ $trt = 'SUC'; |
441 |
|
|
+ } |
442 |
|
|
} |
443 |
|
|
|
444 |
|
|
+ if ( $trt =~ /^.RM$/ ) { |
445 |
|
|
+ |
446 |
|
|
+ # controls |
447 |
|
|
+ my $res = ''; |
448 |
|
|
+ $res = ip_number_or_blank( $c, $hos_datas{externalip} ); |
449 |
|
|
+ $result .= $res . '<br>' unless $res eq 'OK'; |
450 |
|
|
+ |
451 |
|
|
+ #!#$result .= 'blocked'; |
452 |
|
|
+ |
453 |
|
|
+ if ( !$result ) { |
454 |
|
|
+ $res = create_modify_hostentry( $c, $trt, %hos_datas ); |
455 |
|
|
+ $result .= $res unless $res eq 'OK'; |
456 |
|
|
+ } |
457 |
|
|
+ |
458 |
|
|
+ if ( !$result ) { |
459 |
|
|
+ $result = $c->l('hos_MODIFY_SUCCEEDED') . ' ' . $hostname; |
460 |
|
|
+ $trt = 'SUC'; |
461 |
|
|
+ } |
462 |
|
|
+ |
463 |
|
|
+ } |
464 |
|
|
|
465 |
|
|
#if ( $trt eq 'ULC' ) { |
466 |
|
|
#} |
467 |
|
|
|
468 |
|
|
- |
469 |
|
|
#if ( $trt eq 'URM' ) { |
470 |
|
|
#} |
471 |
|
|
|
472 |
|
|
- |
473 |
|
|
if ( $trt eq 'DEL' ) { |
474 |
|
|
|
475 |
|
|
- # controls |
476 |
|
|
- my $res = ''; |
477 |
|
|
- #$res = validate_is_hostentry($c, $hostname); |
478 |
|
|
- #$result .= $res unless $res eq 'OK'; |
479 |
|
|
- |
480 |
|
|
- #!#$result .= 'blocked'; |
481 |
|
|
- |
482 |
|
|
- if ( ! $result ) { |
483 |
|
|
- my $res = delete_hostentry( $c, $hos_datas{hostname} ); |
484 |
|
|
- $result .= $res unless $res eq 'OK'; |
485 |
|
|
- } |
486 |
|
|
- if ( ! $result ) { |
487 |
|
|
- $result = $c->l('hos_REMOVE_SUCCEEDED') . ' ' . $hostname; |
488 |
|
|
- $trt = 'SUC'; |
489 |
|
|
- } |
490 |
|
|
+ # controls |
491 |
|
|
+ my $res = ''; |
492 |
|
|
+ |
493 |
|
|
+ #$res = validate_is_hostentry($c, $hostname); |
494 |
|
|
+ #$result .= $res unless $res eq 'OK'; |
495 |
|
|
+ |
496 |
|
|
+ #!#$result .= 'blocked'; |
497 |
|
|
+ |
498 |
|
|
+ if ( !$result ) { |
499 |
|
|
+ my $res = delete_hostentry( $c, $hos_datas{hostname} ); |
500 |
|
|
+ $result .= $res unless $res eq 'OK'; |
501 |
|
|
+ } |
502 |
|
|
+ if ( !$result ) { |
503 |
|
|
+ $result = $c->l('hos_REMOVE_SUCCEEDED') . ' ' . $hostname; |
504 |
|
|
+ $trt = 'SUC'; |
505 |
|
|
+ } |
506 |
|
|
} |
507 |
|
|
|
508 |
|
|
$hos_datas{'hostname'} = $hostname; |
509 |
|
|
- $hos_datas{'trt'} = $trt; |
510 |
|
|
+ $hos_datas{'trt'} = $trt; |
511 |
|
|
|
512 |
|
|
$c->stash( title => $title, notif => $result, hos_datas => \%hos_datas ); |
513 |
|
|
|
514 |
|
|
- if ($hos_datas{trt} ne 'SUC') { |
515 |
|
|
- return $c->render(template => 'hostentries'); |
516 |
|
|
+ if ( $hos_datas{trt} ne 'SUC' ) { |
517 |
|
|
+ return $c->render( template => 'hostentries' ); |
518 |
|
|
} |
519 |
|
|
$c->redirect_to('/hostentries'); |
520 |
|
|
|
521 |
|
|
- |
522 |
|
|
-}; |
523 |
|
|
- |
524 |
|
|
+} |
525 |
|
|
|
526 |
|
|
sub create_modify_hostentry { |
527 |
|
|
|
528 |
|
|
- my ($c, $trt, %hos_datas) = @_; |
529 |
|
|
+ my ( $c, $trt, %hos_datas ) = @_; |
530 |
|
|
|
531 |
|
|
my $hostname = $hos_datas{hostname}; |
532 |
|
|
my $action; |
533 |
|
|
- |
534 |
|
|
- if ($trt eq 'ADD' or $trt eq 'ALC' or $trt eq 'ARM') { |
535 |
|
|
- $action = 'create'; |
536 |
|
|
+ |
537 |
|
|
+ if ( $trt eq 'ADD' or $trt eq 'ALC' or $trt eq 'ARM' ) { |
538 |
|
|
+ $action = 'create'; |
539 |
|
|
} |
540 |
|
|
- if ( $trt eq 'UPD' or $trt eq 'ULC' or $trt eq 'URM') { |
541 |
|
|
- $action = 'modify'; |
542 |
|
|
+ if ( $trt eq 'UPD' or $trt eq 'ULC' or $trt eq 'URM' ) { |
543 |
|
|
+ $action = 'modify'; |
544 |
|
|
} |
545 |
|
|
|
546 |
|
|
unless ($hostname) { |
547 |
|
|
- return $c->l($action eq 'create' ? $c->l('hos_ERROR_CREATING_HOST') |
548 |
|
|
- : $c->l('hos_ERROR_MODIFYING_HOST')); |
549 |
|
|
+ return $c->l( |
550 |
|
|
+ $action eq 'create' |
551 |
|
|
+ ? $c->l('hos_ERROR_CREATING_HOST') |
552 |
|
|
+ : $c->l('hos_ERROR_MODIFYING_HOST') |
553 |
|
|
+ ); |
554 |
|
|
} |
555 |
|
|
|
556 |
|
|
# Untaint and lowercase $hostname |
557 |
|
|
- $hostname =~ /([\w\.-]+)/; $hostname = lc($1); |
558 |
|
|
+ $hostname =~ /([\w\.-]+)/; |
559 |
|
|
+ $hostname = lc($1); |
560 |
|
|
|
561 |
|
|
my $rec = $hdb->get($hostname); |
562 |
|
|
- if ($rec and $action eq 'create') { |
563 |
|
|
+ if ( $rec and $action eq 'create' ) { |
564 |
|
|
return $c->l('hos_HOSTNAME_IN_USE_ERROR'); |
565 |
|
|
} |
566 |
|
|
- if (not $rec and $action eq 'modify') { |
567 |
|
|
+ if ( not $rec and $action eq 'modify' ) { |
568 |
|
|
return $c->l('hos_NONEXISTENT_HOSTNAME_ERROR'); |
569 |
|
|
} |
570 |
|
|
|
571 |
|
|
my %props = ( |
572 |
|
|
- type => 'host', |
573 |
|
|
- HostType => $hos_datas{hosttype}, |
574 |
|
|
- ExternalIP => $hos_datas{externalip}, |
575 |
|
|
- InternalIP => $hos_datas{internalip}, |
576 |
|
|
- MACAddress => $hos_datas{macaddress}, |
577 |
|
|
- Comment => $hos_datas{comment}, |
578 |
|
|
+ type => 'host', |
579 |
|
|
+ HostType => $hos_datas{hosttype}, |
580 |
|
|
+ ExternalIP => $hos_datas{externalip}, |
581 |
|
|
+ InternalIP => $hos_datas{internalip}, |
582 |
|
|
+ MACAddress => $hos_datas{macaddress}, |
583 |
|
|
+ Comment => $hos_datas{comment}, |
584 |
|
|
); |
585 |
|
|
|
586 |
|
|
- if ($action eq 'create') { |
587 |
|
|
- if ($hdb->new_record($hostname, \%props)) { |
588 |
|
|
- if (system("/sbin/e-smith/signal-event", "host-$action", $hostname) != 0) { |
589 |
|
|
- return $c->l('hos_ERROR_WHILE_CREATING_HOST'); |
590 |
|
|
- } |
591 |
|
|
- } |
592 |
|
|
- } |
593 |
|
|
- |
594 |
|
|
- if ($action eq 'modify') { |
595 |
|
|
- if ($rec->merge_props(%props)) { |
596 |
|
|
- if (system("/sbin/e-smith/signal-event", "host-$action", $hostname) != 0) { |
597 |
|
|
- rturn $c->l('hos_ERROR_WHILE_MODIFYING_HOST'); |
598 |
|
|
- } |
599 |
|
|
- } |
600 |
|
|
+ if ( $action eq 'create' ) { |
601 |
|
|
+ if ( $hdb->new_record( $hostname, \%props ) ) { |
602 |
|
|
+ if ( |
603 |
|
|
+ system( "/sbin/e-smith/signal-event", "host-$action", |
604 |
|
|
+ $hostname ) != 0 |
605 |
|
|
+ ) |
606 |
|
|
+ { |
607 |
|
|
+ return $c->l('hos_ERROR_WHILE_CREATING_HOST'); |
608 |
|
|
+ } |
609 |
|
|
+ } |
610 |
|
|
+ } |
611 |
|
|
+ |
612 |
|
|
+ if ( $action eq 'modify' ) { |
613 |
|
|
+ if ( $rec->merge_props(%props) ) { |
614 |
|
|
+ if ( |
615 |
|
|
+ system( "/sbin/e-smith/signal-event", "host-$action", |
616 |
|
|
+ $hostname ) != 0 |
617 |
|
|
+ ) |
618 |
|
|
+ { |
619 |
|
|
+ rturn $c->l('hos_ERROR_WHILE_MODIFYING_HOST'); |
620 |
|
|
+ } |
621 |
|
|
+ } |
622 |
|
|
} |
623 |
|
|
return 'OK'; |
624 |
|
|
|
625 |
|
|
} |
626 |
|
|
|
627 |
|
|
- |
628 |
|
|
sub delete_hostentry { |
629 |
|
|
|
630 |
|
|
- my ($c, $hostname) = @_; |
631 |
|
|
+ my ( $c, $hostname ) = @_; |
632 |
|
|
|
633 |
|
|
# Untaint $hostname before use in system() |
634 |
|
|
- $hostname =~ /([\w\.-]+)/; $hostname = $1; |
635 |
|
|
+ $hostname =~ /([\w\.-]+)/; |
636 |
|
|
+ $hostname = $1; |
637 |
|
|
|
638 |
|
|
- return ($c->l('hos_ERROR_WHILE_REMOVING_HOST')) unless ($hostname); |
639 |
|
|
+ return ( $c->l('hos_ERROR_WHILE_REMOVING_HOST') ) unless ($hostname); |
640 |
|
|
|
641 |
|
|
my $rec = $hdb->get($hostname); |
642 |
|
|
- return ($c->l('hos_NONEXISTENT_HOST_ERROR')) if (not $rec); |
643 |
|
|
- |
644 |
|
|
+ return ( $c->l('hos_NONEXISTENT_HOST_ERROR') ) if ( not $rec ); |
645 |
|
|
|
646 |
|
|
- if ($rec->delete()) { |
647 |
|
|
- if (system("/sbin/e-smith/signal-event", "host-delete", "$hostname") == 0) { |
648 |
|
|
- return 'OK'; |
649 |
|
|
- } |
650 |
|
|
+ if ( $rec->delete() ) { |
651 |
|
|
+ if ( |
652 |
|
|
+ system( "/sbin/e-smith/signal-event", "host-delete", "$hostname" ) |
653 |
|
|
+ == 0 ) |
654 |
|
|
+ { |
655 |
|
|
+ return 'OK'; |
656 |
|
|
+ } |
657 |
|
|
} |
658 |
|
|
- return ($c->l('hos_ERROR_WHILE_DELETING_HOST')); |
659 |
|
|
+ return ( $c->l('hos_ERROR_WHILE_DELETING_HOST') ); |
660 |
|
|
} |
661 |
|
|
|
662 |
|
|
- |
663 |
|
|
sub domains_list { |
664 |
|
|
|
665 |
|
|
my $d = esmith::DomainsDB->open_ro() or die "Couldn't open DomainsDB"; |
666 |
|
|
my @domains; |
667 |
|
|
- for ($d->domains) |
668 |
|
|
- { |
669 |
|
|
- my $ns = $_->prop("Nameservers") || 'localhost'; |
670 |
|
|
- push @domains, $_->key if ($ns eq 'localhost'); |
671 |
|
|
+ for ( $d->domains ) { |
672 |
|
|
+ my $ns = $_->prop("Nameservers") || 'localhost'; |
673 |
|
|
+ push @domains, $_->key if ( $ns eq 'localhost' ); |
674 |
|
|
} |
675 |
|
|
|
676 |
|
|
return \@domains; |
677 |
|
|
} |
678 |
|
|
|
679 |
|
|
- |
680 |
|
|
sub host_data { |
681 |
|
|
|
682 |
|
|
my $host_record = shift; |
683 |
|
|
|
684 |
|
|
my $ht = $host_record->prop('HostType'); |
685 |
|
|
my $ip = |
686 |
|
|
- ($ht eq 'Self') ? $cdb->get_value('LocalIP') : |
687 |
|
|
- ($ht eq 'Remote') ? $host_record->prop('ExternalIP') : |
688 |
|
|
- $host_record->prop('InternalIP'); |
689 |
|
|
- |
690 |
|
|
- my %data = ('IP' => $ip, |
691 |
|
|
- 'HostName' => $host_record->key(), |
692 |
|
|
- 'HostType' => $host_record->prop('HostType'), |
693 |
|
|
- 'MACAddress' => ($host_record->prop('MACAddress') || ''), |
694 |
|
|
- 'Comment' => ($host_record->prop('Comment') || ''), |
695 |
|
|
- 'static' => ($host_record->prop('static') || 'no')); |
696 |
|
|
- return \%data |
697 |
|
|
+ ( $ht eq 'Self' ) ? $cdb->get_value('LocalIP') |
698 |
|
|
+ : ( $ht eq 'Remote' ) ? $host_record->prop('ExternalIP') |
699 |
|
|
+ : $host_record->prop('InternalIP'); |
700 |
|
|
+ |
701 |
|
|
+ my %data = ( |
702 |
|
|
+ 'IP' => $ip, |
703 |
|
|
+ 'HostName' => $host_record->key(), |
704 |
|
|
+ 'HostType' => $host_record->prop('HostType'), |
705 |
|
|
+ 'MACAddress' => ( $host_record->prop('MACAddress') || '' ), |
706 |
|
|
+ 'Comment' => ( $host_record->prop('Comment') || '' ), |
707 |
|
|
+ 'static' => ( $host_record->prop('static') || 'no' ) |
708 |
|
|
+ ); |
709 |
|
|
+ return \%data |
710 |
|
|
|
711 |
|
|
} |
712 |
|
|
|
713 |
|
|
- |
714 |
|
|
sub hosttype_list { |
715 |
|
|
|
716 |
|
|
my $c = shift; |
717 |
|
|
|
718 |
|
|
- return [[ $c->l('SELF') => 'Self'], |
719 |
|
|
- [ $c->l('LOCAL') => 'Local'], |
720 |
|
|
- [ $c->l('REMOTE') => 'Remote']]; |
721 |
|
|
+ return [ |
722 |
|
|
+ [ $c->l('SELF') => 'Self' ], |
723 |
|
|
+ [ $c->l('LOCAL') => 'Local' ], |
724 |
|
|
+ [ $c->l('REMOTE') => 'Remote' ] |
725 |
|
|
+ ]; |
726 |
|
|
} |
727 |
|
|
|
728 |
|
|
- |
729 |
|
|
sub split_hostname { |
730 |
|
|
my $hostname = shift; |
731 |
|
|
- return ($hostname =~ /^([^\.]+)\.(.+)$/); |
732 |
|
|
+ return ( $hostname =~ /^([^\.]+)\.(.+)$/ ); |
733 |
|
|
} |
734 |
|
|
|
735 |
|
|
- |
736 |
|
|
sub mac_address_or_blank { |
737 |
|
|
- my ($c, $data) = @_; |
738 |
|
|
+ my ( $c, $data ) = @_; |
739 |
|
|
return "OK" unless $data; |
740 |
|
|
- return mac_address($c, $data); |
741 |
|
|
+ return mac_address( $c, $data ); |
742 |
|
|
} |
743 |
|
|
|
744 |
|
|
- |
745 |
|
|
sub mac_address { |
746 |
|
|
|
747 |
|
|
-# from CGI::FormMagick::Validator::Network |
748 |
|
|
+ # from CGI::FormMagick::Validator::Network |
749 |
|
|
|
750 |
|
|
- my ($c, $data) = @_; |
751 |
|
|
+ my ( $c, $data ) = @_; |
752 |
|
|
|
753 |
|
|
- $_ = lc $data; # easier to match on $_ |
754 |
|
|
- if (not defined $_) { |
755 |
|
|
+ $_ = lc $data; # easier to match on $_ |
756 |
|
|
+ if ( not defined $_ ) { |
757 |
|
|
return $c->l('FM_MAC_ADDRESS1'); |
758 |
|
|
- } elsif (/^([0-9a-f][0-9a-f](:[0-9a-f][0-9a-f]){5})$/) { |
759 |
|
|
+ } |
760 |
|
|
+ elsif (/^([0-9a-f][0-9a-f](:[0-9a-f][0-9a-f]){5})$/) { |
761 |
|
|
return "OK"; |
762 |
|
|
- } else { |
763 |
|
|
+ } |
764 |
|
|
+ else { |
765 |
|
|
return $c->l('FM_MAC_ADDRESS2'); |
766 |
|
|
} |
767 |
|
|
} |
768 |
|
|
|
769 |
|
|
- |
770 |
|
|
sub ip_number_or_blank { |
771 |
|
|
|
772 |
|
|
# XXX - FIXME - we should push this down into CGI::FormMagick |
773 |
|
|
|
774 |
|
|
- my $c = shift; |
775 |
|
|
+ my $c = shift; |
776 |
|
|
my $ip = shift; |
777 |
|
|
|
778 |
|
|
- if (!defined($ip) || $ip eq "") |
779 |
|
|
- { |
780 |
|
|
+ if ( !defined($ip) || $ip eq "" ) { |
781 |
|
|
return 'OK'; |
782 |
|
|
} |
783 |
|
|
- |
784 |
|
|
- return ip_number( $c, $ip ); |
785 |
|
|
-} |
786 |
|
|
|
787 |
|
|
+ return ip_number( $c, $ip ); |
788 |
|
|
+} |
789 |
|
|
|
790 |
|
|
sub ip_number { |
791 |
|
|
|
792 |
|
|
-# from CGI::FormMagick::Validator qw( ip_number ); |
793 |
|
|
+ # from CGI::FormMagick::Validator qw( ip_number ); |
794 |
|
|
|
795 |
|
|
- my ($c, $data) = @_; |
796 |
|
|
+ my ( $c, $data ) = @_; |
797 |
|
|
|
798 |
|
|
return undef unless defined $data; |
799 |
|
|
|
800 |
|
|
return $c->l('FM_IP_NUMBER1') unless $data =~ /^[\d.]+$/; |
801 |
|
|
|
802 |
|
|
my @octets = split /\./, $data; |
803 |
|
|
- my $dots = ($data =~ tr/.//); |
804 |
|
|
+ my $dots = ( $data =~ tr/.// ); |
805 |
|
|
|
806 |
|
|
- return $c->l('FM_IP_NUMBER2') unless (scalar @octets == 4 and $dots == 3); |
807 |
|
|
+ return $c->l('FM_IP_NUMBER2') unless ( scalar @octets == 4 and $dots == 3 ); |
808 |
|
|
|
809 |
|
|
foreach my $octet (@octets) { |
810 |
|
|
- return $c->l("FM_IP_NUMBER3", $octet) if $octet > 255; |
811 |
|
|
+ return $c->l( "FM_IP_NUMBER3", $octet ) if $octet > 255; |
812 |
|
|
} |
813 |
|
|
|
814 |
|
|
return 'OK'; |
815 |
|
|
} |
816 |
|
|
|
817 |
|
|
- |
818 |
|
|
sub not_in_dhcp_range { |
819 |
|
|
|
820 |
|
|
- my $c = shift; |
821 |
|
|
+ my $c = shift; |
822 |
|
|
my $address = shift; |
823 |
|
|
|
824 |
|
|
my $status = $cdb->get('dhcpd')->prop('status') || "disabled"; |
825 |
|
|
return 'OK' unless $status eq "enabled"; |
826 |
|
|
|
827 |
|
|
my $start = $cdb->get('dhcpd')->prop('start'); |
828 |
|
|
- my $end = $cdb->get('dhcpd')->prop('end'); |
829 |
|
|
+ my $end = $cdb->get('dhcpd')->prop('end'); |
830 |
|
|
|
831 |
|
|
- return (esmith::util::IPquadToAddr($start) |
832 |
|
|
- <= esmith::util::IPquadToAddr($address) |
833 |
|
|
- && |
834 |
|
|
- esmith::util::IPquadToAddr($address) |
835 |
|
|
- <= esmith::util::IPquadToAddr($end)) ? |
836 |
|
|
- $c->l('hos_ADDR_IN_DHCP_RANGE') : |
837 |
|
|
- 'OK'; |
838 |
|
|
+ return ( esmith::util::IPquadToAddr($start) <= |
839 |
|
|
+ esmith::util::IPquadToAddr($address) |
840 |
|
|
+ && esmith::util::IPquadToAddr($address) <= |
841 |
|
|
+ esmith::util::IPquadToAddr($end) ) |
842 |
|
|
+ ? $c->l('hos_ADDR_IN_DHCP_RANGE') |
843 |
|
|
+ : 'OK'; |
844 |
|
|
} |
845 |
|
|
|
846 |
|
|
- |
847 |
|
|
sub not_taken { |
848 |
|
|
|
849 |
|
|
- my $c = shift; |
850 |
|
|
+ my $c = shift; |
851 |
|
|
my $localip = shift; |
852 |
|
|
|
853 |
|
|
- my $server_localip = $cdb->get_value('LocalIP') || ''; |
854 |
|
|
- my $server_gateway = $cdb->get_value('GatewayIP') || ''; |
855 |
|
|
- my $server_extip = $cdb->get_value('ExternalIP') || ''; |
856 |
|
|
+ my $server_localip = $cdb->get_value('LocalIP') || ''; |
857 |
|
|
+ my $server_gateway = $cdb->get_value('GatewayIP') || ''; |
858 |
|
|
+ my $server_extip = $cdb->get_value('ExternalIP') || ''; |
859 |
|
|
|
860 |
|
|
#$c->debug_msg("\$localip is $localip"); |
861 |
|
|
#$c->debug_msg("\$server_localip is $server_localip"); |
862 |
|
|
#$c->debug_msg("\$server_gateway is $server_gateway"); |
863 |
|
|
#$c->debug_msg("\$server_extip is $server_extip"); |
864 |
|
|
|
865 |
|
|
- if ($localip eq $server_localip) { |
866 |
|
|
+ if ( $localip eq $server_localip ) { |
867 |
|
|
return $c->l('hos_ERR_IP_IS_LOCAL_OR_GATEWAY'); |
868 |
|
|
} |
869 |
|
|
|
870 |
|
|
- if ($localip eq $server_gateway) { |
871 |
|
|
+ if ( $localip eq $server_gateway ) { |
872 |
|
|
return $c->l('hos_ERR_IP_IS_LOCAL_OR_GATEWAY'); |
873 |
|
|
} |
874 |
|
|
|
875 |
|
|
- if (($cdb->get_value('SystemMode') ne 'serveronly') && |
876 |
|
|
- ($server_extip eq $localip)) { |
877 |
|
|
+ if ( ( $cdb->get_value('SystemMode') ne 'serveronly' ) |
878 |
|
|
+ && ( $server_extip eq $localip ) ) |
879 |
|
|
+ { |
880 |
|
|
return $c->l('hos_ERR_IP_IS_LOCAL_OR_GATEWAY'); |
881 |
|
|
} |
882 |
|
|
|
883 |
|
|
- if ($localip eq '127.0.0.1') { |
884 |
|
|
+ if ( $localip eq '127.0.0.1' ) { |
885 |
|
|
return $c->l('hos_ERR_IP_IS_LOCAL_OR_GATEWAY'); |
886 |
|
|
- } else { |
887 |
|
|
+ } |
888 |
|
|
+ else { |
889 |
|
|
return 'OK'; |
890 |
|
|
} |
891 |
|
|
} |
892 |
|
|
|
893 |
|
|
- |
894 |
|
|
sub must_be_local { |
895 |
|
|
|
896 |
|
|
- my $c = shift; |
897 |
|
|
+ my $c = shift; |
898 |
|
|
my $localip = shift; |
899 |
|
|
|
900 |
|
|
# Make sure that the IP is indeed local. |
901 |
|
|
@@ -586,13 +603,13 @@ |
902 |
|
|
|
903 |
|
|
foreach my $spec (@local_list) { |
904 |
|
|
next if $spec eq '127.0.0.1'; |
905 |
|
|
- if (eval{Net::IPv4Addr::ipv4_in_network($spec, $localip)}) { |
906 |
|
|
+ if ( eval { Net::IPv4Addr::ipv4_in_network( $spec, $localip ) } ) { |
907 |
|
|
return 'OK'; |
908 |
|
|
} |
909 |
|
|
} |
910 |
|
|
+ |
911 |
|
|
# Not OK. The IP is not on any of our local networks. |
912 |
|
|
return $c->l('hos_ERR_IP_NOT_LOCAL'); |
913 |
|
|
} |
914 |
|
|
|
915 |
|
|
- |
916 |
|
|
1; |
917 |
|
|
diff -urN smeserver-manager-0.1.4.old/root/usr/share/smanager/themes/default/templates/partials/_dom_list.html.ep smeserver-manager-0.1.4/root/usr/share/smanager/themes/default/templates/partials/_dom_list.html.ep |
918 |
|
|
--- smeserver-manager-0.1.4.old/root/usr/share/smanager/themes/default/templates/partials/_dom_list.html.ep 2024-02-21 11:20:59.129610364 +0000 |
919 |
|
|
+++ smeserver-manager-0.1.4/root/usr/share/smanager/themes/default/templates/partials/_dom_list.html.ep 2024-02-21 11:39:00.000000000 +0000 |
920 |
|
|
@@ -12,7 +12,7 @@ |
921 |
|
|
%= submit_button "$btn", class => 'action' |
922 |
|
|
</p> |
923 |
|
|
|
924 |
|
|
- %= hidden_field 'trt' => 'UP2' |
925 |
|
|
+ %= hidden_field 'trt' => 'ADD' |
926 |
|
|
|
927 |
|
|
% end |
928 |
|
|
|