]>
Commit | Line | Data |
---|---|---|
2a81ab0d AM |
1 | #!/usr/bin/perl |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2011 IPFire Team <info@ipfire.org> # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | # New function for forwarding firewall. To make it comfortable to create # | |
22 | # rules, we need "spelling names" for single Hosts. If you have any questions # | |
23 | # <amarx@ipfire.org> # | |
24 | ############################################################################### | |
25 | use strict; | |
26 | ||
27 | # enable only the following on debugging purpose | |
28 | use warnings; | |
29 | use CGI::Carp 'fatalsToBrowser'; | |
30 | no warnings 'uninitialized'; | |
31 | require '/var/ipfire/general-functions.pl'; | |
32 | require "${General::swroot}/lang.pl"; | |
33 | require "${General::swroot}/header.pl"; | |
34 | ||
35 | my %fwhostsettings=(); | |
36 | my %customnetwork=(); | |
37 | my %customhost=(); | |
38 | my %customgrp=(); | |
39 | my %customservice=(); | |
40 | my %customservicegrp=(); | |
41 | my %ccdnet=(); | |
42 | my %ccdhost=(); | |
43 | my %ipsecconf=(); | |
44 | my %icmptypes=(); | |
45 | my %color=(); | |
46 | my %defaultNetworks=(); | |
47 | my %mainsettings=(); | |
48 | my %ownnet=(); | |
49 | my %ipsecsettings=(); | |
62fc8511 AM |
50 | my %fwfwd=(); |
51 | my %fwinp=(); | |
2a81ab0d AM |
52 | |
53 | my $errormessage; | |
54 | my $hint; | |
55 | my $update=0; | |
56 | my $confignet = "${General::swroot}/fwhosts/customnetworks"; | |
57 | my $confighost = "${General::swroot}/fwhosts/customhosts"; | |
58 | my $configgrp = "${General::swroot}/fwhosts/customgroups"; | |
59 | my $configccdnet = "${General::swroot}/ovpn/ccd.conf"; | |
60 | my $configccdhost = "${General::swroot}/ovpn/ovpnconfig"; | |
61 | my $configipsec = "${General::swroot}/vpn/config"; | |
62 | my $configsrv = "${General::swroot}/fwhosts/customservices"; | |
63 | my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp"; | |
62fc8511 AM |
64 | my $fwconfigfwd = "${General::swroot}/forward/config"; |
65 | my $fwconfiginp = "${General::swroot}/forward/input"; | |
2a81ab0d AM |
66 | |
67 | unless (-e $confignet) { system("touch $confignet"); } | |
68 | unless (-e $confighost) { system("touch $confighost"); } | |
69 | unless (-e $configgrp) { system("touch $configgrp"); } | |
70 | unless (-e $configsrv) { system("touch $configsrv"); } | |
71 | unless (-e $configsrvgrp) { system("touch $configsrvgrp"); } | |
72 | ||
73 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
74 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
75 | &General::readhash("${General::swroot}/ethernet/settings", \%ownnet); | |
76 | &Header::getcgihash(\%fwhostsettings); | |
77 | ||
78 | &Header::showhttpheaders(); | |
79 | &Header::openpage($Lang::tr{'fwhost hosts'}, 1, ''); | |
80 | &Header::openbigbox('100%', 'center'); | |
81 | ||
82 | ## ACTION #### | |
cd9d9d8a AM |
83 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'}) |
84 | { | |
85 | &reread_rules; | |
86 | &showmenu; | |
87 | } | |
2a81ab0d AM |
88 | # Update |
89 | if ($fwhostsettings{'ACTION'} eq 'updatenet' ) | |
90 | { | |
91 | &General::readhasharray("$confignet", \%customnetwork); | |
92 | foreach my $key (keys %customnetwork) | |
93 | { | |
94 | if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}) | |
95 | { | |
96 | $fwhostsettings{'orgname'} = $customnetwork{$key}[0]; | |
97 | $fwhostsettings{'orgip'} = $customnetwork{$key}[1]; | |
98 | $fwhostsettings{'orgsub'} = $customnetwork{$key}[2]; | |
e5a058c1 AM |
99 | $fwhostsettings{'netremark'} = $customnetwork{$key}[3]; |
100 | $fwhostsettings{'count'} = $customnetwork{$key}[4]; | |
2a81ab0d AM |
101 | delete $customnetwork{$key}; |
102 | ||
103 | } | |
104 | } | |
105 | &General::writehasharray("$confignet", \%customnetwork); | |
106 | $fwhostsettings{'actualize'} = 'on'; | |
107 | $fwhostsettings{'ACTION'} = 'savenet'; | |
108 | } | |
109 | if ($fwhostsettings{'ACTION'} eq 'updatehost') | |
110 | { | |
111 | my ($ip,$subnet); | |
112 | &General::readhasharray("$confighost", \%customhost); | |
113 | foreach my $key (keys %customhost) | |
114 | { | |
115 | if($customhost{$key}[0] eq $fwhostsettings{'orgname'}) | |
116 | { | |
2a81ab0d AM |
117 | if ($customhost{$key}[1] eq 'ip'){ |
118 | ($ip,$subnet) = split (/\//,$customhost{$key}[2]); | |
119 | }else{ | |
120 | $ip = $customhost{$key}[2]; | |
121 | } | |
122 | $fwhostsettings{'orgip'} = $ip; | |
e3580608 | 123 | $fwhostsettings{'count'} = $customhost{$key}[4]; |
2a81ab0d | 124 | delete $customhost{$key}; |
5e970723 | 125 | &General::writehasharray("$confighost", \%customhost); |
2a81ab0d AM |
126 | } |
127 | } | |
2a81ab0d | 128 | $fwhostsettings{'actualize'} = 'on'; |
5e970723 | 129 | if($fwhostsettings{'orgip'}){ |
2a81ab0d | 130 | $fwhostsettings{'ACTION'} = 'savehost'; |
5e970723 AM |
131 | }else{ |
132 | $fwhostsettings{'ACTION'} = $Lang::tr{'fwhost newhost'}; | |
133 | } | |
2a81ab0d AM |
134 | } |
135 | if ($fwhostsettings{'ACTION'} eq 'updateservice') | |
136 | { | |
137 | my $count=0; | |
138 | my $needrules=0; | |
139 | $errormessage=&checkports(\%customservice); | |
2a81ab0d AM |
140 | if (!$errormessage){ |
141 | &General::readhasharray("$configsrv", \%customservice); | |
142 | foreach my $key (keys %customservice) | |
143 | { | |
144 | if ($customservice{$key}[0] eq $fwhostsettings{'oldsrvname'}) | |
145 | { | |
146 | $count=$customservice{$key}[4]; | |
147 | delete $customservice{$key}; | |
148 | &General::writehasharray("$configsrv", \%customservice); | |
149 | last; | |
150 | } | |
151 | } | |
152 | if ($fwhostsettings{'PROT'} ne 'ICMP'){ | |
153 | $fwhostsettings{'ICMP_TYPES'}='BLANK'; | |
154 | } | |
155 | my $key1 = &General::findhasharraykey(\%customservice); | |
156 | foreach my $i (0 .. 4) { $customservice{$key1}[$i] = "";} | |
157 | $customservice{$key1}[0] = $fwhostsettings{'SRV_NAME'}; | |
158 | $customservice{$key1}[1] = $fwhostsettings{'SRV_PORT'}; | |
159 | $customservice{$key1}[2] = $fwhostsettings{'PROT'}; | |
160 | $customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'}; | |
161 | $customservice{$key1}[4] = $count; | |
162 | &General::writehasharray("$configsrv", \%customservice); | |
ed73b87e | 163 | #check if we need to update firewallrules |
bfee206c AM |
164 | if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){ |
165 | if ( ! -z $fwconfigfwd ){ | |
166 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
167 | foreach my $key (sort keys %fwfwd){ | |
168 | if ($fwfwd{$key}[15] eq $fwhostsettings{'oldsrvname'}){ | |
169 | $fwfwd{$key}[15] = $fwhostsettings{'SRV_NAME'}; | |
170 | } | |
171 | } | |
172 | &General::writehasharray("$fwconfigfwd", \%fwfwd); | |
bfee206c AM |
173 | } |
174 | if ( ! -z $fwconfiginp ){ | |
175 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
176 | foreach my $line (sort keys %fwinp){ | |
177 | if ($fwfwd{$line}[15] eq $fwhostsettings{'oldsrvname'}){ | |
178 | $fwfwd{$line}[15] = $fwhostsettings{'SRV_NAME'}; | |
179 | } | |
180 | } | |
181 | &General::writehasharray("$fwconfiginp", \%fwinp); | |
182 | } | |
bfac6bd4 AM |
183 | #check if we need to update groups |
184 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
185 | foreach my $key (sort keys %customservicegrp){ | |
186 | if($customservicegrp{$key}[2] eq $fwhostsettings{'oldsrvname'}){ | |
187 | $customservicegrp{$key}[2] = $fwhostsettings{'SRV_NAME'}; | |
188 | } | |
189 | } | |
190 | &General::writehasharray("$configsrvgrp", \%customservicegrp); | |
bfee206c AM |
191 | $needrules='on'; |
192 | } | |
ed73b87e AM |
193 | if($count gt 0 && $fwhostsettings{'oldsrvport'} ne $fwhostsettings{'SRV_PORT'} ){ |
194 | $needrules='on'; | |
2a81ab0d | 195 | } |
ed73b87e AM |
196 | if($count gt 0 && $fwhostsettings{'oldsrvprot'} ne $fwhostsettings{'PROT'} ){ |
197 | $needrules='on'; | |
198 | } | |
2a81ab0d AM |
199 | $fwhostsettings{'SRV_NAME'} = ''; |
200 | $fwhostsettings{'SRV_PORT'} = ''; | |
201 | $fwhostsettings{'PROT'} = ''; | |
2a81ab0d AM |
202 | }else{ |
203 | $fwhostsettings{'SRV_NAME'} = $fwhostsettings{'oldsrvname'}; | |
204 | $fwhostsettings{'SRV_PORT'} = $fwhostsettings{'oldsrvport'}; | |
205 | $fwhostsettings{'PROT'} = $fwhostsettings{'oldsrvprot'}; | |
206 | $fwhostsettings{'updatesrv'}= 'on'; | |
207 | } | |
2a81ab0d | 208 | if($needrules eq 'on'){ |
2a81ab0d AM |
209 | &rules; |
210 | } | |
2a81ab0d AM |
211 | &addservice; |
212 | } | |
213 | # save | |
214 | if ($fwhostsettings{'ACTION'} eq 'savenet' ) | |
215 | { | |
216 | my $count=0; | |
217 | my $needrules=0; | |
218 | if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};} | |
2a81ab0d AM |
219 | #check if all fields are set |
220 | if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '') | |
221 | { | |
222 | $errormessage=$errormessage.$Lang::tr{'fwhost err empty'}; | |
223 | &addnet; | |
224 | &viewtablenet; | |
225 | }else{ | |
226 | #check valid ip | |
227 | if (!&General::validipandmask($fwhostsettings{'IP'}."/".$fwhostsettings{'SUBNET'})) | |
228 | { | |
229 | $errormessage=$errormessage.$Lang::tr{'fwhost err addr'}; | |
230 | $fwhostsettings{'BLK_HOST'} ='readonly'; | |
231 | $fwhostsettings{'NOCHECK'} ='false'; | |
232 | $fwhostsettings{'error'} ='on'; | |
233 | } | |
e5a058c1 AM |
234 | #check remark |
235 | if ($fwhostsettings{'NETREMARK'} ne '' && !&validremark($fwhostsettings{'NETREMARK'})){ | |
236 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
237 | $fwhostsettings{'error'} ='on'; | |
238 | } | |
2a81ab0d AM |
239 | #check if subnet is sigle host |
240 | if(&General::iporsubtocidr($fwhostsettings{'SUBNET'}) eq '32') | |
241 | { | |
242 | $errormessage=$errormessage.$Lang::tr{'fwhost err sub32'}; | |
2a81ab0d AM |
243 | } |
244 | if($fwhostsettings{'error'} ne 'on'){ | |
245 | #check if we use one of ipfire's networks (green,orange,blue) | |
246 | if (($ownnet{'GREEN_NETADDRESS'} ne '' && $ownnet{'GREEN_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'GREEN_NETADDRESS'},$ownnet{'GREEN_NETMASK'})) | |
247 | { | |
248 | $errormessage=$errormessage.$Lang::tr{'ccd err green'}."<br>"; | |
249 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
250 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';} | |
251 | } | |
252 | if (($ownnet{'ORANGE_NETADDRESS'} ne '' && $ownnet{'ORANGE_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'ORANGE_NETADDRESS'},$ownnet{'ORANGE_NETMASK'})) | |
253 | { | |
254 | $errormessage=$errormessage.$Lang::tr{'ccd err orange'}."<br>"; | |
255 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
256 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';} | |
257 | } | |
258 | if (($ownnet{'BLUE_NETADDRESS'} ne '' && $ownnet{'BLUE_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'BLUE_NETADDRESS'},$ownnet{'BLUE_NETMASK'})) | |
259 | { | |
260 | $errormessage=$errormessage.$Lang::tr{'ccd err blue'}."<br>"; | |
261 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
262 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';} | |
263 | } | |
264 | if (($ownnet{'RED_NETADDRESS'} ne '' && $ownnet{'RED_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'RED_NETADDRESS'},$ownnet{'RED_NETMASK'})) | |
265 | { | |
266 | $errormessage=$errormessage.$Lang::tr{'ccd err red'}."<br>"; | |
267 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
268 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';} | |
269 | } | |
270 | } | |
271 | #only check plausi when no error till now | |
272 | if (!$errormessage){ | |
273 | &plausicheck("editnet"); | |
274 | } | |
2a81ab0d AM |
275 | #check if network ip is part of an already used one |
276 | if(&checksubnet(\%customnetwork)) | |
277 | { | |
278 | $errormessage=$errormessage.$Lang::tr{'fwhost err partofnet'}; | |
279 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
280 | } | |
2a81ab0d AM |
281 | if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage) |
282 | { | |
283 | $fwhostsettings{'actualize'} = ''; | |
284 | my $key = &General::findhasharraykey (\%customnetwork); | |
285 | foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";} | |
286 | $customnetwork{$key}[0] = $fwhostsettings{'orgname'} ; | |
287 | $customnetwork{$key}[1] = $fwhostsettings{'orgip'} ; | |
288 | $customnetwork{$key}[2] = $fwhostsettings{'orgsub'}; | |
f80db6a4 | 289 | $customnetwork{$key}[3] = $fwhostsettings{'orgnetremark'}; |
e5a058c1 | 290 | $customnetwork{$key}[4] = $fwhostsettings{'count'}; |
2a81ab0d AM |
291 | &General::writehasharray("$confignet", \%customnetwork); |
292 | undef %customnetwork; | |
293 | } | |
2a81ab0d | 294 | if (!$errormessage){ |
e5a058c1 | 295 | |
2a81ab0d AM |
296 | &General::readhasharray("$confignet", \%customnetwork); |
297 | if ($fwhostsettings{'ACTION'} eq 'updatenet'){ | |
298 | if ($fwhostsettings{'update'} == '0'){ | |
299 | foreach my $key (keys %customnetwork) { | |
300 | if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}){ | |
e5a058c1 | 301 | $count=$customnetwork{$key}[4]; |
2a81ab0d AM |
302 | delete $customnetwork{$key}; |
303 | last; | |
304 | } | |
305 | } | |
306 | } | |
307 | } | |
308 | #get count if actualize is 'on' | |
309 | if($fwhostsettings{'actualize'} eq 'on'){ | |
310 | $fwhostsettings{'actualize'} = ''; | |
311 | $count=$fwhostsettings{'count'}; | |
312 | #check if we need to reload rules | |
313 | if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'} && $count gt '0'){ | |
314 | $needrules='on'; | |
315 | } | |
316 | if ($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){ | |
317 | #check if we need to update groups | |
318 | &General::readhasharray("$configgrp", \%customgrp); | |
319 | foreach my $key (sort keys %customgrp){ | |
320 | if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){ | |
321 | $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'}; | |
322 | last; | |
323 | } | |
324 | } | |
325 | &General::writehasharray("$configgrp", \%customgrp); | |
62fc8511 AM |
326 | #check if we need to update firewallrules |
327 | if ( ! -z $fwconfigfwd ){ | |
328 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
329 | foreach my $line (sort keys %fwfwd){ | |
330 | if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){ | |
331 | $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'}; | |
332 | } | |
333 | if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){ | |
334 | $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'}; | |
335 | } | |
336 | } | |
337 | &General::writehasharray("$fwconfigfwd", \%fwfwd); | |
338 | } | |
339 | if ( ! -z $fwconfiginp ){ | |
340 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
341 | foreach my $line (sort keys %fwinp){ | |
342 | if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){ | |
343 | $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'}; | |
344 | } | |
345 | } | |
346 | &General::writehasharray("$fwconfiginp", \%fwinp); | |
347 | } | |
2a81ab0d AM |
348 | } |
349 | } | |
350 | my $key = &General::findhasharraykey (\%customnetwork); | |
e5a058c1 | 351 | foreach my $i (0 .. 4) { $customnetwork{$key}[$i] = "";} |
2a81ab0d AM |
352 | $fwhostsettings{'SUBNET'} = &General::iporsubtocidr($fwhostsettings{'SUBNET'}); |
353 | $customnetwork{$key}[0] = $fwhostsettings{'HOSTNAME'}; | |
354 | #convert ip when leading '0' in byte | |
e5a058c1 AM |
355 | $fwhostsettings{'IP'} =&General::ip2dec($fwhostsettings{'IP'}); |
356 | $fwhostsettings{'IP'} =&General::dec2ip($fwhostsettings{'IP'}); | |
2a81ab0d AM |
357 | $customnetwork{$key}[1] = &General::getnetworkip($fwhostsettings{'IP'},$fwhostsettings{'SUBNET'}) ; |
358 | $customnetwork{$key}[2] = &General::iporsubtodec($fwhostsettings{'SUBNET'}) ; | |
359 | if($fwhostsettings{'newnet'} eq 'on'){$count=0;} | |
e5a058c1 AM |
360 | $customnetwork{$key}[3] = $fwhostsettings{'NETREMARK'}; |
361 | $customnetwork{$key}[4] = $count; | |
2a81ab0d AM |
362 | &General::writehasharray("$confignet", \%customnetwork); |
363 | $fwhostsettings{'IP'}=$fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'}); | |
364 | undef %customnetwork; | |
365 | $fwhostsettings{'HOSTNAME'}=''; | |
366 | $fwhostsettings{'IP'}=''; | |
367 | $fwhostsettings{'SUBNET'}=''; | |
e5a058c1 | 368 | $fwhostsettings{'NETREMARK'}=''; |
2a81ab0d AM |
369 | #check if an edited net affected groups and need to reload rules |
370 | if ($needrules eq 'on'){ | |
371 | &rules; | |
372 | } | |
373 | &addnet; | |
374 | &viewtablenet; | |
375 | }else | |
376 | { | |
377 | &addnet; | |
378 | &viewtablenet; | |
379 | } | |
380 | } | |
2a81ab0d AM |
381 | } |
382 | if ($fwhostsettings{'ACTION'} eq 'savehost') | |
383 | { | |
384 | my $count=0; | |
385 | my $needrules=0; | |
386 | if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};} | |
2a81ab0d | 387 | $fwhostsettings{'SUBNET'}='32'; |
2a81ab0d AM |
388 | #check if all fields are set |
389 | if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '') | |
390 | { | |
391 | $errormessage=$errormessage.$Lang::tr{'fwhost err empty'}; | |
392 | $fwhostsettings{'ACTION'} = 'edithost'; | |
393 | }else{ | |
2a81ab0d AM |
394 | if($fwhostsettings{'type'} eq 'ip' && $fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){ |
395 | $fwhostsettings{'type'} = 'mac'; | |
396 | }elsif($fwhostsettings{'type'} eq 'mac' && $fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){ | |
397 | $fwhostsettings{'type'} = 'ip'; | |
398 | }elsif($fwhostsettings{'type'} eq 'mac' && $fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){ | |
399 | $fwhostsettings{'type'} = 'mac'; | |
400 | }elsif($fwhostsettings{'type'} eq 'ip' && $fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){ | |
401 | $fwhostsettings{'type'} = 'ip'; | |
402 | }else{ | |
403 | $fwhostsettings{'type'} = ''; | |
404 | $errormessage=$Lang::tr{'fwhost err ipmac'}; | |
405 | } | |
2a81ab0d AM |
406 | if($fwhostsettings{'type'} eq 'mac' ) |
407 | { | |
408 | if ($fwhostsettings{'IP'}!~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/ ) | |
409 | { | |
410 | $errormessage=$Lang::tr{'fwhost err mac'}; | |
2a81ab0d AM |
411 | } |
412 | } | |
e3580608 AM |
413 | #check remark |
414 | if ($fwhostsettings{'HOSTREMARK'} ne '' && !&validremark($fwhostsettings{'HOSTREMARK'})){ | |
415 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
416 | } | |
2a81ab0d AM |
417 | #CHECK IP-PART |
418 | if ($fwhostsettings{'type'} eq 'ip'){ | |
419 | #check for subnet | |
420 | if (rindex($fwhostsettings{'IP'},'/') eq '-1' ){ | |
421 | if($fwhostsettings{'type'} eq 'ip' && !&General::validipandmask($fwhostsettings{'IP'}."/32")) | |
422 | { | |
423 | $errormessage.=$errormessage.$Lang::tr{'fwhost err ip'}; | |
424 | $fwhostsettings{'error'}='on'; | |
425 | } | |
2a81ab0d AM |
426 | }elsif(rindex($fwhostsettings{'IP'},'/') ne '-1' ){ |
427 | $errormessage=$errormessage.$Lang::tr{'fwhost err ipwithsub'}; | |
428 | $fwhostsettings{'error'}='on'; | |
429 | } | |
430 | #check if net or broadcast | |
431 | my @tmp= split (/\./,$fwhostsettings{'IP'}); | |
432 | if (($tmp[3] eq "0") || ($tmp[3] eq "255")){ | |
433 | $errormessage=$Lang::tr{'fwhost err hostip'}; | |
434 | } | |
435 | } | |
2a81ab0d AM |
436 | #only check plausi when no error till now |
437 | if (!$errormessage){ | |
438 | &plausicheck("edithost"); | |
439 | } | |
2a81ab0d AM |
440 | if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){ |
441 | $fwhostsettings{'actualize'} = ''; | |
442 | my $key = &General::findhasharraykey (\%customhost); | |
e3580608 | 443 | foreach my $i (0 .. 4) { $customhost{$key}[$i] = "";} |
2a81ab0d AM |
444 | $customhost{$key}[0] = $fwhostsettings{'orgname'} ; |
445 | $customhost{$key}[1] = $fwhostsettings{'type'} ; | |
446 | if($customhost{$key}[1] eq 'ip'){ | |
447 | $customhost{$key}[2] = $fwhostsettings{'orgip'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'}); | |
448 | }else{ | |
449 | $customhost{$key}[2] = $fwhostsettings{'orgip'}; | |
450 | } | |
f80db6a4 | 451 | $customhost{$key}[3] = $fwhostsettings{'orgremark'}; |
e3580608 | 452 | $customhost{$key}[4] = $fwhostsettings{'count'}; |
2a81ab0d AM |
453 | &General::writehasharray("$confighost", \%customhost); |
454 | undef %customhost; | |
2a81ab0d | 455 | } |
2a81ab0d AM |
456 | if (!$errormessage){ |
457 | #get count if host was edited | |
458 | if($fwhostsettings{'actualize'} eq 'on'){ | |
459 | $count=$fwhostsettings{'count'}; | |
460 | if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'} && $count gt '0' ){ | |
461 | $needrules='on'; | |
462 | } | |
463 | if($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){ | |
464 | #check if we need to update groups | |
465 | &General::readhasharray("$configgrp", \%customgrp); | |
466 | foreach my $key (sort keys %customgrp){ | |
467 | if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){ | |
468 | $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'}; | |
469 | last; | |
470 | } | |
471 | } | |
472 | &General::writehasharray("$configgrp", \%customgrp); | |
62fc8511 AM |
473 | #check if we need to update firewallrules |
474 | if ( ! -z $fwconfigfwd ){ | |
475 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
476 | foreach my $line (sort keys %fwfwd){ | |
477 | if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){ | |
478 | $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'}; | |
479 | } | |
480 | if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){ | |
481 | $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'}; | |
482 | } | |
483 | } | |
484 | &General::writehasharray("$fwconfigfwd", \%fwfwd); | |
485 | } | |
486 | if ( ! -z $fwconfiginp ){ | |
487 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
488 | foreach my $line (sort keys %fwinp){ | |
489 | if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){ | |
490 | $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'}; | |
491 | } | |
492 | } | |
493 | &General::writehasharray("$fwconfiginp", \%fwinp); | |
494 | } | |
2a81ab0d | 495 | } |
2a81ab0d AM |
496 | } |
497 | my $key = &General::findhasharraykey (\%customhost); | |
e3580608 | 498 | foreach my $i (0 .. 4) { $customhost{$key}[$i] = "";} |
2a81ab0d AM |
499 | $customhost{$key}[0] = $fwhostsettings{'HOSTNAME'} ; |
500 | $customhost{$key}[1] = $fwhostsettings{'type'} ; | |
501 | if ($fwhostsettings{'type'} eq 'ip'){ | |
502 | #convert ip when leading '0' in byte | |
503 | $fwhostsettings{'IP'}=&General::ip2dec($fwhostsettings{'IP'}); | |
504 | $fwhostsettings{'IP'}=&General::dec2ip($fwhostsettings{'IP'}); | |
505 | $customhost{$key}[2] = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'}); | |
506 | }else{ | |
507 | $customhost{$key}[2] = $fwhostsettings{'IP'}; | |
508 | } | |
509 | if($fwhostsettings{'newhost'} eq 'on'){$count=0;} | |
e3580608 AM |
510 | $customhost{$key}[3] = $fwhostsettings{'HOSTREMARK'}; |
511 | $customhost{$key}[4] =$count; | |
2a81ab0d | 512 | &General::writehasharray("$confighost", \%customhost); |
2a81ab0d AM |
513 | undef %customhost; |
514 | $fwhostsettings{'HOSTNAME'}=''; | |
515 | $fwhostsettings{'IP'}=''; | |
516 | $fwhostsettings{'type'}=''; | |
e3580608 | 517 | $fwhostsettings{'HOSTREMARK'}=''; |
2a81ab0d AM |
518 | #check if we need to update rules while host was edited |
519 | if($needrules eq 'on'){ | |
520 | &rules; | |
521 | } | |
522 | &addhost; | |
523 | &viewtablehost; | |
524 | }else{ | |
525 | &addhost; | |
526 | &viewtablehost; | |
527 | } | |
2a81ab0d | 528 | } |
2a81ab0d AM |
529 | } |
530 | if ($fwhostsettings{'ACTION'} eq 'savegrp') | |
531 | { | |
6c869961 | 532 | my $grp=$fwhostsettings{'grp_name'};; |
2a81ab0d AM |
533 | my $rem=$fwhostsettings{'remark'}; |
534 | my $count; | |
535 | my $type; | |
536 | my $updcounter='off'; | |
537 | my @target; | |
538 | my @newgrp; | |
539 | &General::readhasharray("$configgrp", \%customgrp); | |
540 | &General::readhasharray("$confignet", \%customnetwork); | |
541 | &General::readhasharray("$confighost", \%customhost); | |
6c869961 AM |
542 | #check name |
543 | if (!&validhostname($grp)){$errormessage.=$Lang::tr{'fwhost err name'};} | |
544 | #check remark | |
545 | if ($rem ne '' && !&validremark($rem) && $fwhostsettings{'update'} ne 'on'){ | |
546 | $errormessage.=$Lang::tr{'fwhost err remark'}; | |
2a81ab0d | 547 | } |
6c869961 AM |
548 | if ($fwhostsettings{'update'} eq 'on'){ |
549 | #check standard networks | |
550 | if ($fwhostsettings{'grp2'} eq 'std_net'){ | |
551 | @target=$fwhostsettings{'DEFAULT_SRC_ADR'}; | |
552 | $type='Standard Network'; | |
553 | } | |
554 | #check custom networks | |
555 | if ($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} ne ''){ | |
556 | @target=$fwhostsettings{'CUST_SRC_NET'}; | |
557 | $updcounter='net'; | |
558 | $type='Custom Network'; | |
559 | }elsif($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} eq ''){ | |
560 | $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>"; | |
561 | $fwhostsettings{'grp_name'}=''; | |
562 | $fwhostsettings{'remark'}=''; | |
563 | } | |
564 | #check custom addresses | |
565 | if ($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} ne ''){ | |
566 | @target=$fwhostsettings{'CUST_SRC_HOST'}; | |
567 | $updcounter='host'; | |
568 | $type='Custom Host'; | |
569 | }elsif($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} eq ''){ | |
570 | $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>"; | |
571 | $fwhostsettings{'grp_name'}=''; | |
572 | $fwhostsettings{'remark'}=''; | |
573 | } | |
574 | #get address from ovpn ccd static net | |
575 | if ($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} ne ''){ | |
576 | @target=$fwhostsettings{'OVPN_CCD_NET'}; | |
577 | $type='OpenVPN static network'; | |
578 | }elsif($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} eq ''){ | |
579 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
580 | $fwhostsettings{'grp_name'}=''; | |
581 | $fwhostsettings{'remark'}=''; | |
582 | } | |
583 | #get address from ovpn ccd static host | |
584 | if ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} ne ''){ | |
585 | @target=$fwhostsettings{'OVPN_CCD_HOST'}; | |
586 | $type='OpenVPN static host'; | |
587 | }elsif ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} eq ''){ | |
588 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
589 | } | |
590 | #get address from ovpn ccd Net-2-Net | |
591 | if ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} ne ''){ | |
592 | @target=$fwhostsettings{'OVPN_N2N'}; | |
593 | $type='OpenVPN N-2-N'; | |
594 | }elsif ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} eq ''){ | |
595 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
596 | $fwhostsettings{'grp_name'}=''; | |
597 | $fwhostsettings{'remark'}=''; | |
598 | } | |
599 | #get address from IPSEC HOST | |
600 | if ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} ne ''){ | |
601 | @target=$fwhostsettings{'IPSEC_HOST'}; | |
602 | $type='IpSec Host'; | |
603 | }elsif ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} eq ''){ | |
604 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
605 | $fwhostsettings{'grp_name'}=''; | |
606 | $fwhostsettings{'remark'}=''; | |
607 | } | |
608 | #get address from IPSEC NETWORK | |
609 | if ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} ne ''){ | |
610 | @target=$fwhostsettings{'IPSEC_NET'}; | |
611 | $type='IpSec Network'; | |
612 | }elsif ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} eq ''){ | |
613 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
614 | $fwhostsettings{'grp_name'}=''; | |
615 | $fwhostsettings{'remark'}=''; | |
616 | } | |
617 | #check if host/net exists in grp | |
618 | ||
619 | my $test="$grp,$fwhostsettings{'oldremark'},@target"; | |
620 | foreach my $key (keys %customgrp) { | |
621 | my $test1="$customgrp{$key}[0],$customgrp{$key}[1],$customgrp{$key}[2]"; | |
622 | if ($test1 eq $test){ | |
623 | $errormessage=$Lang::tr{'fwhost err isingrp'}; | |
624 | $fwhostsettings{'update'} = 'on'; | |
625 | } | |
2a81ab0d AM |
626 | } |
627 | } | |
6c869961 | 628 | |
2a81ab0d AM |
629 | if (!$errormessage){ |
630 | #on first save, we have an empty @target, so fill it with nothing | |
631 | my $targetvalues=@target; | |
632 | if ($targetvalues == '0'){ | |
6c869961 | 633 | @target="none"; |
2a81ab0d AM |
634 | } |
635 | #on update, we have to delete the dummy entry | |
2a81ab0d | 636 | foreach my $key (keys %customgrp){ |
6c869961 | 637 | if ($customgrp{$key}[0] eq $grp && $customgrp{$key}[2] eq "none"){ |
2a81ab0d AM |
638 | delete $customgrp{$key}; |
639 | last; | |
640 | } | |
641 | } | |
642 | &General::writehasharray("$configgrp", \%customgrp); | |
643 | &General::readhasharray("$configgrp", \%customgrp); | |
2a81ab0d AM |
644 | #get count used |
645 | foreach my $key (keys %customgrp) | |
646 | { | |
647 | if($customgrp{$key}[0] eq $grp) | |
648 | { | |
649 | $count=$customgrp{$key}[4]; | |
650 | last; | |
651 | } | |
652 | } | |
653 | if ($count eq '' ){$count='0';} | |
654 | ||
655 | #create array with new lines | |
656 | foreach my $line (@target){ | |
657 | push (@newgrp,"$grp,$rem,$line"); | |
658 | } | |
659 | #append new entries | |
660 | my $key = &General::findhasharraykey (\%customgrp); | |
661 | foreach my $line (@newgrp){ | |
662 | foreach my $i (0 .. 4) { $customgrp{$key}[$i] = "";} | |
663 | my ($a,$b,$c,$d) = split (",",$line); | |
664 | $customgrp{$key}[0] = $a; | |
665 | $customgrp{$key}[1] = $b; | |
666 | $customgrp{$key}[2] = $c; | |
667 | $customgrp{$key}[3] = $type; | |
668 | $customgrp{$key}[4] = $count; | |
669 | } | |
670 | &General::writehasharray("$configgrp", \%customgrp); | |
2a81ab0d AM |
671 | #update counter in Host/Net |
672 | if($updcounter eq 'net'){ | |
673 | foreach my $key (keys %customnetwork) { | |
674 | if($customnetwork{$key}[0] eq $fwhostsettings{'CUST_SRC_NET'}){ | |
e5a058c1 | 675 | $customnetwork{$key}[4] = $customnetwork{$key}[4]+1; |
2a81ab0d AM |
676 | last; |
677 | } | |
678 | } | |
679 | &General::writehasharray("$confignet", \%customnetwork); | |
680 | }elsif($updcounter eq 'host'){ | |
681 | foreach my $key (keys %customhost) { | |
682 | if ($customhost{$key}[0] eq $fwhostsettings{'CUST_SRC_HOST'}){ | |
e3580608 | 683 | $customhost{$key}[4]=$customhost{$key}[3]+1; |
2a81ab0d AM |
684 | } |
685 | } | |
686 | &General::writehasharray("$confighost", \%customhost); | |
687 | } | |
2a81ab0d | 688 | $fwhostsettings{'update'}='on'; |
2a81ab0d | 689 | } |
2a81ab0d AM |
690 | #check if ruleupdate is needed |
691 | if($count > 0 ) | |
692 | { | |
693 | &rules; | |
694 | } | |
695 | &addgrp; | |
696 | &viewtablegrp; | |
2a81ab0d AM |
697 | } |
698 | if ($fwhostsettings{'ACTION'} eq 'saveservice') | |
699 | { | |
700 | my $ICMP; | |
2a81ab0d AM |
701 | &General::readhasharray("$configsrv", \%customservice ); |
702 | $errormessage=&checkports(\%customservice); | |
2a81ab0d AM |
703 | if ($fwhostsettings{'PROT'} eq 'ICMP'){ |
704 | &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); | |
705 | foreach my $key (keys %icmptypes){ | |
706 | if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){ | |
707 | $ICMP=$icmptypes{$key}[0]; | |
708 | } | |
709 | } | |
710 | } | |
711 | if($ICMP eq ''){$ICMP='BLANK';} | |
712 | if (!$errormessage){ | |
2a81ab0d AM |
713 | my $key = &General::findhasharraykey (\%customservice); |
714 | foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";} | |
715 | $customservice{$key}[0] = $fwhostsettings{'SRV_NAME'}; | |
716 | $customservice{$key}[1] = $fwhostsettings{'SRV_PORT'}; | |
717 | $customservice{$key}[2] = $fwhostsettings{'PROT'}; | |
718 | $customservice{$key}[3] = $ICMP; | |
719 | $customservice{$key}[4] = 0; | |
720 | &General::writehasharray("$configsrv", \%customservice ); | |
721 | #reset fields | |
722 | $fwhostsettings{'SRV_NAME'}=''; | |
723 | $fwhostsettings{'SRV_PORT'}=''; | |
724 | $fwhostsettings{'PROT'}=''; | |
725 | $fwhostsettings{'ICMP_TYPES'}=''; | |
2a81ab0d | 726 | } |
2a81ab0d | 727 | &addservice; |
2a81ab0d AM |
728 | } |
729 | if ($fwhostsettings{'ACTION'} eq 'saveservicegrp') | |
730 | { | |
731 | my $prot; | |
732 | my $port; | |
733 | my $count=0; | |
734 | &General::readhasharray("$configsrvgrp", \%customservicegrp ); | |
735 | &General::readhasharray("$configsrv", \%customservice ); | |
2a81ab0d | 736 | $errormessage=&checkservicegroup; |
2a81ab0d AM |
737 | if (!$errormessage){ |
738 | #on first save, we have to enter a dummy value | |
6c869961 AM |
739 | if ($fwhostsettings{'CUST_SRV'} eq ''){ |
740 | $fwhostsettings{'CUST_SRV'}='none'; | |
741 | } | |
2a81ab0d AM |
742 | #on update, we have to delete the dummy entry |
743 | foreach my $key (keys %customservicegrp){ | |
6c869961 | 744 | if ($customservicegrp{$key}[2] eq 'none'){ |
2a81ab0d AM |
745 | delete $customservicegrp{$key}; |
746 | last; | |
747 | } | |
748 | } | |
749 | &General::writehasharray("$configsrvgrp", \%customservicegrp ); | |
750 | #check if remark has also changed | |
751 | if ($fwhostsettings{'SRVGRP_REMARK'} ne $fwhostsettings{'oldsrvgrpremark'} && $fwhostsettings{'updatesrvgrp'} eq 'on') | |
752 | { | |
753 | foreach my $key (keys %customservicegrp) | |
754 | { | |
755 | if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvgrpremark'}) | |
756 | { | |
757 | $customservicegrp{$key}[1]=''; | |
758 | $customservicegrp{$key}[1]=$fwhostsettings{'SRVGRP_REMARK'}; | |
759 | } | |
760 | } | |
761 | } | |
762 | #get count used | |
763 | foreach my $key (keys %customservicegrp) | |
764 | { | |
765 | if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}) | |
766 | { | |
13e5dda4 | 767 | $count=$customservicegrp{$key}[3]; |
2a81ab0d AM |
768 | last; |
769 | } | |
770 | } | |
771 | if ($count eq '' ){$count='0';} | |
772 | ||
773 | foreach my $key (sort keys %customservice){ | |
774 | if($customservice{$key}[0] eq $fwhostsettings{'CUST_SRV'}){ | |
775 | $port=$customservice{$key}[1]; | |
776 | $prot=$customservice{$key}[2]; | |
777 | $customservice{$key}[4]++; | |
778 | } | |
779 | } | |
780 | &General::writehasharray("$configsrv", \%customservice ); | |
2a81ab0d AM |
781 | my $key = &General::findhasharraykey (\%customservicegrp); |
782 | foreach my $i (0 .. 3) { $customservice{$key}[$i] = "";} | |
783 | $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'}; | |
784 | $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'}; | |
785 | $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'}; | |
937d4e08 | 786 | $customservicegrp{$key}[3] = $count; |
2a81ab0d AM |
787 | &General::writehasharray("$configsrvgrp", \%customservicegrp ); |
788 | $fwhostsettings{'updatesrvgrp'}='on'; | |
789 | } | |
2a81ab0d AM |
790 | if ($count gt 0){ |
791 | &rules; | |
792 | } | |
793 | &addservicegrp; | |
794 | &viewtableservicegrp; | |
795 | } | |
796 | # edit | |
797 | if ($fwhostsettings{'ACTION'} eq 'editnet') | |
798 | { | |
799 | &addnet; | |
800 | &viewtablenet; | |
801 | } | |
802 | if ($fwhostsettings{'ACTION'} eq 'edithost') | |
803 | { | |
804 | &addhost; | |
805 | &viewtablehost; | |
806 | } | |
807 | if ($fwhostsettings{'ACTION'} eq 'editgrp') | |
808 | { | |
809 | $fwhostsettings{'update'}='on'; | |
810 | &addgrp; | |
811 | &viewtablegrp; | |
812 | } | |
813 | if ($fwhostsettings{'ACTION'} eq 'editservice') | |
814 | { | |
815 | $fwhostsettings{'updatesrv'}='on'; | |
816 | &addservice; | |
817 | } | |
818 | if ($fwhostsettings{'ACTION'} eq 'editservicegrp') | |
819 | { | |
820 | $fwhostsettings{'updatesrvgrp'} = 'on'; | |
821 | &addservicegrp; | |
822 | &viewtableservicegrp; | |
823 | } | |
824 | # reset | |
825 | if ($fwhostsettings{'ACTION'} eq 'resetnet') | |
826 | { | |
827 | $fwhostsettings{'HOSTNAME'} =""; | |
828 | $fwhostsettings{'IP'} =""; | |
829 | $fwhostsettings{'SUBNET'} =""; | |
830 | &showmenu; | |
831 | } | |
832 | if ($fwhostsettings{'ACTION'} eq 'resethost') | |
833 | { | |
834 | $fwhostsettings{'HOSTNAME'} =""; | |
835 | $fwhostsettings{'IP'} =""; | |
836 | $fwhostsettings{'type'} =""; | |
837 | &showmenu; | |
838 | } | |
839 | # delete | |
840 | if ($fwhostsettings{'ACTION'} eq 'delnet') | |
841 | { | |
842 | &General::readhasharray("$confignet", \%customnetwork); | |
843 | foreach my $key (keys %customnetwork) { | |
844 | if($fwhostsettings{'key'} eq $customnetwork{$key}[0]){ | |
845 | delete $customnetwork{$key}; | |
846 | &General::writehasharray("$confignet", \%customnetwork); | |
847 | last; | |
848 | } | |
849 | } | |
850 | &addnet; | |
851 | &viewtablenet; | |
852 | } | |
853 | if ($fwhostsettings{'ACTION'} eq 'delhost') | |
854 | { | |
855 | &General::readhasharray("$confighost", \%customhost); | |
856 | foreach my $key (keys %customhost) { | |
857 | if($fwhostsettings{'key'} eq $customhost{$key}[0]){ | |
858 | delete $customhost{$key}; | |
859 | &General::writehasharray("$confighost", \%customhost); | |
860 | last; | |
861 | } | |
862 | } | |
863 | &addhost; | |
864 | &viewtablehost; | |
2a81ab0d AM |
865 | } |
866 | if ($fwhostsettings{'ACTION'} eq 'deletegrphost') | |
867 | { | |
3f8fe51e AM |
868 | my $grpremark; |
869 | my $grpname; | |
2a81ab0d AM |
870 | &General::readhasharray("$configgrp", \%customgrp); |
871 | foreach my $key (keys %customgrp){ | |
872 | if($customgrp{$key}[0].",".$customgrp{$key}[1].",".$customgrp{$key}[2].",".$customgrp{$key}[3] eq $fwhostsettings{'delhost'}){ | |
873 | #decrease count from source host/net | |
874 | if ($customgrp{$key}[3] eq 'Custom Network'){ | |
875 | &General::readhasharray("$confignet", \%customnetwork); | |
876 | foreach my $key1 (keys %customnetwork){ | |
877 | if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){ | |
878 | $customnetwork{$key1}[3] = $customnetwork{$key1}[3]-1; | |
879 | last; | |
880 | } | |
881 | } | |
882 | &General::writehasharray("$confignet", \%customnetwork); | |
883 | } | |
884 | if ($customgrp{$key}[3] eq 'Custom Host'){ | |
885 | &General::readhasharray("$confighost", \%customhost); | |
886 | foreach my $key1 (keys %customhost){ | |
887 | if ($customhost{$key1}[0] eq $customgrp{$key}[2]){ | |
e3580608 | 888 | $customhost{$key1}[4] = $customhost{$key1}[4]-1; |
2a81ab0d AM |
889 | last; |
890 | } | |
891 | } | |
892 | &General::writehasharray("$confighost", \%customhost); | |
893 | } | |
3f8fe51e AM |
894 | $grpname=$customgrp{$key}[0]; |
895 | $grpremark=$customgrp{$key}[1]; | |
2a81ab0d AM |
896 | delete $customgrp{$key}; |
897 | } | |
898 | } | |
899 | &General::writehasharray("$configgrp", \%customgrp); | |
e3580608 | 900 | if ($fwhostsettings{'grpcnt'} > 0){&rules;} |
3f8fe51e AM |
901 | if ($fwhostsettings{'update'} eq 'on'){ |
902 | $fwhostsettings{'remark'}= $grpremark; | |
903 | $fwhostsettings{'grp_name'}=$grpname; | |
904 | } | |
2a81ab0d AM |
905 | &addgrp; |
906 | &viewtablegrp; | |
907 | } | |
908 | if ($fwhostsettings{'ACTION'} eq 'delgrp') | |
909 | { | |
910 | &General::readhasharray("$configgrp", \%customgrp); | |
911 | &decrease($fwhostsettings{'grp_name'}); | |
912 | foreach my $key (sort keys %customgrp) | |
913 | { | |
914 | if($customgrp{$key}[0] eq $fwhostsettings{'grp_name'}) | |
915 | { | |
916 | delete $customgrp{$key}; | |
917 | } | |
918 | } | |
919 | &General::writehasharray("$configgrp", \%customgrp); | |
920 | $fwhostsettings{'grp_name'}=''; | |
921 | &addgrp; | |
922 | &viewtablegrp; | |
923 | } | |
924 | if ($fwhostsettings{'ACTION'} eq 'delservice') | |
925 | { | |
926 | &General::readhasharray("$configsrv", \%customservice); | |
927 | foreach my $key (keys %customservice) { | |
928 | if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){ | |
929 | #&deletefromgrp($customhost{$key}[0],$configgrp); | |
930 | delete $customservice{$key}; | |
931 | &General::writehasharray("$configsrv", \%customservice); | |
932 | last; | |
933 | } | |
934 | } | |
935 | $fwhostsettings{'SRV_NAME'}=''; | |
936 | $fwhostsettings{'SRV_PORT'}=''; | |
937 | $fwhostsettings{'PROT'}=''; | |
938 | &addservice; | |
939 | } | |
940 | if ($fwhostsettings{'ACTION'} eq 'delservicegrp') | |
941 | { | |
942 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
943 | &decreaseservice($fwhostsettings{'SRVGRP_NAME'}); | |
944 | foreach my $key (sort keys %customservicegrp) | |
945 | { | |
946 | if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}) | |
947 | { | |
948 | delete $customservicegrp{$key}; | |
949 | } | |
950 | } | |
951 | &General::writehasharray("$configsrvgrp", \%customservicegrp); | |
952 | $fwhostsettings{'SRVGRP_NAME'}=''; | |
953 | &addservicegrp; | |
954 | &viewtableservicegrp; | |
955 | } | |
956 | if ($fwhostsettings{'ACTION'} eq 'delgrpservice') | |
957 | { | |
3f8fe51e AM |
958 | my $grpname; |
959 | my $grpremark; | |
2a81ab0d AM |
960 | &General::readhasharray("$configsrvgrp", \%customservicegrp); |
961 | &General::readhasharray("$configsrv", \%customservice); | |
962 | foreach my $key (keys %customservicegrp){ | |
963 | if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2].",".$customservicegrp{$key}[3] eq $fwhostsettings{'delsrvfromgrp'}) | |
964 | { | |
965 | #decrease count from source service | |
966 | foreach my $key1 (sort keys %customservice){ | |
967 | if($customservice{$key1}[0] eq $customservicegrp{$key}[2]){ | |
968 | $customservice{$key1}[4]--; | |
969 | last; | |
970 | } | |
971 | } | |
972 | &General::writehasharray("$configsrv", \%customservice); | |
3f8fe51e AM |
973 | $grpname=$customservicegrp{$key}[0]; |
974 | $grpremark=$customservicegrp{$key}[1]; | |
975 | delete $customservicegrp{$key}; | |
2a81ab0d AM |
976 | } |
977 | } | |
978 | &General::writehasharray("$configsrvgrp", \%customservicegrp); | |
979 | &rules; | |
3f8fe51e AM |
980 | if ($fwhostsettings{'updatesrvgrp'} eq 'on'){ |
981 | #$fwhostsettings{'updatesrvgrp'}='on'; | |
982 | $fwhostsettings{'SRVGRP_NAME'}=$grpname; | |
983 | $fwhostsettings{'SRVGRP_REMARK'}=$grpremark; | |
984 | } | |
2a81ab0d AM |
985 | &addservicegrp; |
986 | &viewtableservicegrp; | |
987 | ||
988 | } | |
989 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'}) | |
990 | { | |
991 | &addnet; | |
992 | &viewtablenet; | |
993 | } | |
994 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newhost'}) | |
995 | { | |
996 | &addhost; | |
997 | &viewtablehost; | |
998 | } | |
999 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgrp'}) | |
1000 | { | |
1001 | &addgrp; | |
1002 | &viewtablegrp; | |
1003 | } | |
1004 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservice'}) | |
1005 | { | |
1006 | &addservice; | |
1007 | } | |
1008 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservicegrp'}) | |
1009 | { | |
1010 | &addservicegrp; | |
1011 | &viewtableservicegrp; | |
1012 | } | |
6c869961 AM |
1013 | if ($fwhostsettings{'ACTION'} eq 'changegrpremark') |
1014 | { | |
1015 | &General::readhasharray("$configgrp", \%customgrp); | |
d0815ce4 | 1016 | if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){ |
6c869961 AM |
1017 | foreach my $key (sort keys %customgrp) |
1018 | { | |
1019 | #$customgrp{$key}[1]=~ s/\|/,/g; | |
1020 | if($customgrp{$key}[0] eq $fwhostsettings{'grp'} && $customgrp{$key}[1] eq $fwhostsettings{'oldrem'}) | |
1021 | { | |
1022 | #$fwhostsettings{'newrem'}=~ s/,/\|/g; | |
1023 | $customgrp{$key}[1]=''; | |
1024 | $customgrp{$key}[1]=$fwhostsettings{'newrem'}; | |
1025 | } | |
1026 | } | |
1027 | &General::writehasharray("$configgrp", \%customgrp); | |
1028 | $fwhostsettings{'update'}='on'; | |
1029 | #$fwhostsettings{'newrem'}=~ s/\|/,/g; | |
1030 | $fwhostsettings{'remark'}=$fwhostsettings{'newrem'}; | |
1031 | }else{ | |
1032 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
1033 | $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'}; | |
1034 | $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'}; | |
1035 | $fwhostsettings{'update'} = 'on'; | |
1036 | } | |
1037 | $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'}; | |
1038 | &addgrp; | |
1039 | &viewtablegrp; | |
1040 | } | |
1041 | if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark') | |
1042 | { | |
1043 | &General::readhasharray("$configsrvgrp", \%customservicegrp ); | |
d0815ce4 | 1044 | if ($fwhostsettings{'oldsrvrem'} ne $fwhostsettings{'newsrvrem'} && (&validremark($fwhostsettings{'newsrvrem'}) || $fwhostsettings{'newsrvrem'} eq '')){ |
6c869961 AM |
1045 | foreach my $key (sort keys %customservicegrp) |
1046 | { | |
1047 | #$customservicegrp{$key}[1]=~ s/\|/,/g; | |
1048 | if($customservicegrp{$key}[0] eq $fwhostsettings{'srvgrp'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvrem'}) | |
1049 | { | |
1050 | #$fwhostsettings{'newsrvrem'}=~ s/,/|/g; | |
1051 | $customservicegrp{$key}[1]=''; | |
1052 | $customservicegrp{$key}[1]=$fwhostsettings{'newsrvrem'}; | |
1053 | } | |
1054 | } | |
1055 | &General::writehasharray("$configsrvgrp", \%customservicegrp); | |
1056 | $fwhostsettings{'updatesrvgrp'}='on'; | |
1057 | #$fwhostsettings{'newsrvrem'}=~ s/\|/,/g; | |
1058 | $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'newsrvrem'}; | |
1059 | }else{ | |
1060 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
1061 | $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'oldsrvrem'}; | |
1062 | $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'}; | |
1063 | $fwhostsettings{'updatesrvgrp'} = 'on'; | |
1064 | } | |
1065 | $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'}; | |
1066 | &addservicegrp; | |
1067 | &viewtableservicegrp; | |
1068 | } | |
2a81ab0d AM |
1069 | ### VIEW ### |
1070 | if($fwhostsettings{'ACTION'} eq '') | |
1071 | { | |
1072 | &showmenu; | |
1073 | } | |
1074 | ### FUNCTIONS ### | |
1075 | sub showmenu | |
1076 | { | |
7bf83f9d AM |
1077 | if (-f "${General::swroot}/forward/reread"){ |
1078 | print "<table border='0'><form method='post'><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-face: Comic Sans MS; color: red; font-weight: bold;'>$Lang::tr{'fwhost reread'}</td></tr></table></form><hr><br>"; | |
1079 | } | |
2a81ab0d AM |
1080 | &Header::openbox('100%', 'left',$Lang::tr{'fwhost menu'}); |
1081 | print<<END; | |
1082 | <table border='0' width='100%'><form method='post'> | |
1083 | <tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newnet'}' /><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newhost'}' /><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newgrp'}' /></td> | |
1084 | <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newservice'}' /><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newservicegrp'}' /></td></tr> | |
7bf83f9d | 1085 | <tr><td colspan='6'><hr></hr></td></tr></table></form> |
2a81ab0d | 1086 | END |
2a81ab0d AM |
1087 | &Header::closebox(); |
1088 | ||
1089 | } | |
1090 | # Add | |
1091 | sub addnet | |
1092 | { | |
1093 | &error; | |
1094 | &showmenu; | |
1095 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addnet'}); | |
1096 | $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'}; | |
f80db6a4 | 1097 | $fwhostsettings{'orgnetremark'}=$fwhostsettings{'NETREMARK'}; |
2a81ab0d AM |
1098 | print<<END; |
1099 | <table border='0' width='100%'><form method='post' style='display:inline' > | |
be5698ef | 1100 | <tr><td>$Lang::tr{'name'}:</td><td><input type='TEXT' name='HOSTNAME' id='textbox1' value='$fwhostsettings{'HOSTNAME'}' $fwhostsettings{'BLK_HOST'}><script>document.getElementById('textbox1').focus()</script></td><td>$Lang::tr{'fwhost netaddress'}:</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='14'></td><td align='right'>$Lang::tr{'netmask'}:</td><td align='right'><input type='TEXT' name='SUBNET' value='$fwhostsettings{'SUBNET'}' $fwhostsettings{'BLK_IP'} size='14'></td></tr> |
5dd84c25 AM |
1101 | <tr><td>$Lang::tr{'remark'}:</td><td colspan='5'><input type='TEXT' name='NETREMARK' value='$fwhostsettings{'NETREMARK'}' size='110'></td></tr> |
1102 | <tr><td colspan='6'><br><hr></hr></td></tr><tr> | |
2a81ab0d AM |
1103 | END |
1104 | if ($fwhostsettings{'ACTION'} eq 'editnet' || $fwhostsettings{'error'} eq 'on') | |
1105 | { | |
f80db6a4 | 1106 | print "<td colspan='6' align='right' ><input type='submit' value='$Lang::tr{'update'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='updatenet'><input type='hidden' name='orgnetremark' value='$fwhostsettings{'orgnetremark'}' ><input type='hidden' name='orgname' value='$fwhostsettings{'orgname'}' ><input type='hidden' name='update' value='on'><input type='hidden' name='newnet' value='$fwhostsettings{'newnet'}'>"; |
2a81ab0d | 1107 | }else{ |
7f5b2820 | 1108 | print "<td colspan='6' align='right'><input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'/><input type='hidden' name='ACTION' value='savenet'><input type='hidden' name='newnet' value='on'>"; |
2a81ab0d | 1109 | } |
7f5b2820 | 1110 | print "</form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;' ><input type='hidden' name='ACTION' value='resetnet'></td></tr></table></form>"; |
2a81ab0d AM |
1111 | &Header::closebox(); |
1112 | } | |
1113 | sub addhost | |
1114 | { | |
1115 | &error; | |
1116 | &showmenu; | |
1117 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addhost'}); | |
1118 | $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'}; | |
f80db6a4 | 1119 | $fwhostsettings{'orgremark'}=$fwhostsettings{'HOSTREMARK'}; |
2a81ab0d AM |
1120 | print<<END; |
1121 | <table border='0' width='100%'><form method='post' style='display:inline'> | |
1aec05a6 | 1122 | <tr><td>$Lang::tr{'name'}:</td><td width='35%'><input type='TEXT' name='HOSTNAME' id='textbox1' value='$fwhostsettings{'HOSTNAME'}' $fwhostsettings{'BLK_HOST'} ><script>document.getElementById('textbox1').focus()</script></td><td><select name='type'> |
2a81ab0d AM |
1123 | END |
1124 | if ($fwhostsettings{'type'} eq 'ip'){print "<option value='ip' selected >IP</option>";}else{print "<option value='ip' >IP</option>";} | |
1125 | if ($fwhostsettings{'type'} eq 'mac'){print "<option value='mac' selected >MAC</option>";}else{print "<option value='mac' >MAC</option>";} | |
1126 | print<<END; | |
1127 | </option></select></td><td align='right' width='15%'>IP/MAC:</td><td align='right'><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} ></td></tr> | |
5dd84c25 | 1128 | <tr><td>$Lang::tr{'remark'}:</td><td colspan='5'><input type='TEXT' name='HOSTREMARK' value='$fwhostsettings{'HOSTREMARK'}' size='110'></td></tr> |
2a81ab0d AM |
1129 | <tr><td colspan='7'><br><br><b>$Lang::tr{'fwhost attention'}</b><br>$Lang::tr{'fwhost macwarn'}</td></tr> |
1130 | <tr><td colspan='7'><hr></hr></td></tr> | |
1131 | END | |
1132 | ||
1133 | if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on') | |
1134 | { | |
1135 | ||
f80db6a4 | 1136 | print " <td colspan='6' align='right'><input type='submit' value='$Lang::tr{'update'}' style='min-width:100px;'/><input type='hidden' name='ACTION' value='updatehost'><input type='hidden' name='orgremark' value='$fwhostsettings{'orgremark'}' ><input type='hidden' name='orgname' value='$fwhostsettings{'orgname'}' ><input type='hidden' name='update' value='on'><input type='hidden' name='newhost' value='$fwhostsettings{'newhost'}'></form>"; |
2a81ab0d | 1137 | }else{ |
7f5b2820 | 1138 | print " <td colspan='6' align='right'><input type='submit' name='savehost' value='$Lang::tr{'save'}'style='min-width:100px;' /><input type='hidden' name='ACTION' value='savehost' /><input type='hidden' name='newhost' value='on'>"; |
2a81ab0d | 1139 | } |
7f5b2820 | 1140 | print " </form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;' ><input type='hidden' name='ACTION' value='resethost'></td></tr></table></form>"; |
2a81ab0d AM |
1141 | &Header::closebox(); |
1142 | } | |
1143 | sub addgrp | |
1144 | { | |
1145 | &hint; | |
1146 | &error; | |
1147 | &showmenu; | |
1148 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addgrp'}); | |
1149 | &General::setup_default_networks(\%defaultNetworks); | |
1150 | my %checked=(); | |
1151 | $checked{'check1'}{'off'} = ''; | |
1152 | $checked{'check1'}{'on'} = ''; | |
1153 | $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED'; | |
1154 | $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'}; | |
6c869961 AM |
1155 | my $grp=$fwhostsettings{'grp_name'}; |
1156 | my $rem=$fwhostsettings{'remark'}; | |
2a81ab0d AM |
1157 | if ($fwhostsettings{'update'} eq ''){ |
1158 | print<<END; | |
1159 | <table width='100%' border='0'><form method='post'> | |
7f5b2820 | 1160 | <tr><td>$Lang::tr{'fwhost addgrpname'}</td><td><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}'></td><td>$Lang::tr{'remark'}:</td><td width='1%'><input type='TEXT' name='remark' size='35' value='$fwhostsettings{'remark'}'></tr> |
5dd84c25 | 1161 | <tr><td colspan='5'><br><hr></td></tr></table> |
2a81ab0d AM |
1162 | END |
1163 | }else{ | |
1164 | print<<END; | |
6c869961 AM |
1165 | <table width='100%' border='0'><form method='post' style='display:inline'> |
1166 | <tr><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='TEXT' name='grp' value='$fwhostsettings{'grp_name'}' readonly ></td><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='newrem' size='35' value='$fwhostsettings{'remark'}'></td><td><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='ACTION' value='changegrpremark' ></td></tr></table></form> | |
1167 | <hr> | |
2a81ab0d | 1168 | END |
2a81ab0d AM |
1169 | } |
1170 | if ($fwhostsettings{'update'} eq 'on'){ | |
2a81ab0d | 1171 | print<<END; |
6c869961 | 1172 | <form method='post'><input type='hidden' name='remark' value='$rem'><input type='hidden' name='grp_name' value='$grp'><table width='100%' border='0'><tr><td width='1%'><input type='radio' name='grp2' value='std_net' checked></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost stdnet'}</td><td><select name='DEFAULT_SRC_ADR' style='min-width:185px;'> |
2a81ab0d AM |
1173 | END |
1174 | foreach my $network (sort keys %defaultNetworks) | |
1175 | { | |
1176 | next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP"); | |
62fc8511 | 1177 | next if($defaultNetworks{$network}{'NAME'} eq "RED"); |
2a81ab0d AM |
1178 | print "<option value='$defaultNetworks{$network}{'NAME'}'"; |
1179 | print " selected='selected'" if ($fwhostsettings{'DEFAULT_SRC_ADR'} eq $defaultNetworks{$network}{'NAME'}); | |
1180 | print ">$network</option>"; | |
1181 | } | |
2a81ab0d AM |
1182 | print<<END; |
1183 | </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_net' $checked{'grp2'}{'ovpn_net'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='OVPN_CCD_NET' style='min-width:185px;'> | |
1184 | END | |
1185 | &General::readhasharray("$configccdnet", \%ccdnet); | |
1186 | foreach my $key (sort { uc($ccdnet{$a}[0]) cmp uc($ccdnet{$b}[0]) } keys %ccdnet) | |
1187 | { | |
1188 | print"<option value='$ccdnet{$key}[0]'>$ccdnet{$key}[0]</option>"; | |
1189 | } | |
2a81ab0d AM |
1190 | print<<END; |
1191 | </select></td></tr> | |
1192 | <tr><td><input type='radio' name='grp2' value='cust_net' $checked{'grp2'}{'cust_net'}></td><td>$Lang::tr{'fwhost cust net'}</td><td><select name='CUST_SRC_NET' style='min-width:185px;'> | |
1193 | END | |
1194 | &General::readhasharray("$confignet", \%customnetwork); | |
1195 | foreach my $key (sort { uc($customnetwork{$a}[0]) cmp uc($customnetwork{$b}[0]) } keys %customnetwork) { | |
1196 | print"<option>$customnetwork{$key}[0]</option>"; | |
1197 | } | |
2a81ab0d AM |
1198 | print<<END; |
1199 | </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_host' $checked{'grp2'}{'ovpn_host'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='OVPN_CCD_HOST' style='min-width:185px;'> | |
1200 | END | |
1201 | &General::readhasharray("$configccdhost", \%ccdhost); | |
1202 | foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) | |
1203 | { | |
1204 | if ($ccdhost{$key}[33] ne ''){ | |
1205 | print"<option value='$ccdhost{$key}[1]'>$ccdhost{$key}[1]</option>"; | |
1206 | } | |
1207 | } | |
2a81ab0d AM |
1208 | print<<END; |
1209 | </select></td></tr> | |
1210 | <tr><td valign='top'><input type='radio' name='grp2' value='cust_host' $checked{'grp2'}{'cust_host'}></td><td valign='top'>$Lang::tr{'fwhost cust addr'}</td><td><select name='CUST_SRC_HOST' style='min-width:185px;'> | |
1211 | END | |
1212 | &General::readhasharray("$confighost", \%customhost); | |
1213 | foreach my $key (sort { uc($customhost{$a}[0]) cmp uc($customhost{$b}[0]) } keys %customhost) { | |
1214 | print"<option>$customhost{$key}[0]</option>"; | |
1215 | } | |
1216 | print<<END; | |
1217 | </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_n2n' $checked{'grp2'}{'ovpn_n2n'}></td><td valign='top'>$Lang::tr{'fwhost ovpn_n2n'}</td><td colspan='3'><select name='OVPN_N2N' style='min-width:185px;'> | |
1218 | END | |
1219 | &General::readhasharray("$configccdhost", \%ccdhost); | |
1220 | foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) { | |
1221 | if($ccdhost{$key}[3] eq 'net'){ | |
1222 | print"<option>$ccdhost{$key}[1]</option>"; | |
1223 | } | |
1224 | } | |
1225 | print<<END; | |
1226 | </select></td></tr> | |
1227 | <tr><td colspan='3'></td><td valign='top'><input type='radio' name='grp2' value='ipsec_net' $checked{'grp2'}{'ipsec_net'}></td><td valign='top'>$Lang::tr{'fwhost ipsec net'}</td><td><select name='IPSEC_NET' style='min-width:185px;'> | |
1228 | END | |
1229 | &General::readhasharray("$configipsec", \%ipsecconf); | |
1230 | foreach my $key (sort { uc($ipsecconf{$a}[0]) cmp uc($ipsecconf{$b}[0]) } keys %ipsecconf) { | |
1231 | if ($ipsecconf{$key}[3] eq 'net'){ | |
1232 | print"<option value='$ipsecconf{$key}[1]'>$ipsecconf{$key}[1]</option>"; | |
1233 | } | |
1234 | } | |
1235 | print<<END; | |
1236 | </select></td></tr></table> | |
1237 | END | |
1238 | # <td colspan='3'></td><td valign='top'><input type='radio' name='grp2' value='ipsec_host' $checked{'grp2'}{'ipsec_host'}></td><td valign='top'>$Lang::tr{'fwhost ipsec host'}</td><td><select name='IPSEC_HOST' style='min-width:185px;'> | |
1239 | #END | |
1240 | # &General::readhasharray("$configipsec", \%ipsecconf); | |
1241 | # foreach my $key (sort { uc($ipsecconf{$a}[0]) cmp uc($ipsecconf{$b}[0]) } keys %ipsecconf) { | |
1242 | # if ($ipsecconf{$key}[3] eq 'host'){ | |
1243 | # print"<option>$ipsecconf{$key}[1]</option>"; | |
1244 | # } | |
1245 | # } | |
1246 | # print<<END; | |
1247 | # </select></td></tr> | |
1248 | # <tr> | |
6c869961 | 1249 | print"<br><br><b>$Lang::tr{'fwhost attention'}:</b><br> $Lang::tr{'fwhost macwarn'}<br><hr>"; |
2a81ab0d | 1250 | } |
6c869961 AM |
1251 | print"<table border='0' width='100%'>"; |
1252 | print"<tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' /><input type='hidden' name='oldremark' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='update' value=$fwhostsettings{'update'} ><input type='hidden' name='ACTION' value='savegrp' ></form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'><input type='hidden' name='ACTION' value'reset'></td></td></table></form>"; | |
2a81ab0d AM |
1253 | &Header::closebox(); |
1254 | } | |
1255 | sub addservice | |
1256 | { | |
1257 | &error; | |
1258 | &showmenu; | |
1259 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost newservice'}); | |
1260 | if ($fwhostsettings{'updatesrv'} eq 'on') | |
1261 | { | |
1262 | $fwhostsettings{'oldsrvname'} = $fwhostsettings{'SRV_NAME'}; | |
1263 | $fwhostsettings{'oldsrvport'} = $fwhostsettings{'SRV_PORT'}; | |
1264 | $fwhostsettings{'oldsrvprot'} = $fwhostsettings{'PROT'}; | |
1265 | } | |
1266 | print<<END; | |
1267 | <table width='100%' border='0'><form method='post'> | |
62fc8511 | 1268 | <tr><td width='1%' nowrap='nowrap'>$Lang::tr{'fwhost srv_name'}:</td><td width='1%' nowrap='nowrap'><input type='text' name='SRV_NAME' id='textbox1' value='$fwhostsettings{'SRV_NAME'}'><script>document.getElementById('textbox1').focus()</script></td><td width='1%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT'> |
2a81ab0d AM |
1269 | END |
1270 | foreach ("TCP","UDP","ICMP") | |
1271 | { | |
1272 | if ($_ eq $fwhostsettings{'PROT'}) | |
1273 | { | |
1274 | print"<option selected>$_</option>"; | |
1275 | }else{ | |
1276 | print"<option>$_</option>"; | |
1277 | } | |
1278 | } | |
1279 | print<<END; | |
1280 | </select></td><td>$Lang::tr{'fwhost port'}:</td><td><input type='text' name='SRV_PORT' value='$fwhostsettings{'SRV_PORT'}' maxlength='11' size='9'></td></tr> | |
1281 | <tr><td></td><td></td><td nowrap='nowrap'>$Lang::tr{'fwhost icmptype'}</td><td colspan='4'><select name='ICMP_TYPES'> | |
1282 | END | |
1283 | &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); | |
1284 | print"<option>All ICMP-Types</option>"; | |
1285 | foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) }keys %icmptypes){ | |
1286 | print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>"; | |
1287 | } | |
1288 | ||
1289 | print<<END; | |
1290 | </select></td> | |
5dd84c25 | 1291 | <tr><td colspan='6'><br><hr></td></tr> |
2a81ab0d AM |
1292 | <tr><td colspan='6' align='right'> |
1293 | END | |
1294 | if ($fwhostsettings{'updatesrv'} eq 'on') | |
1295 | { | |
1296 | print<<END; | |
7f5b2820 | 1297 | <input type='submit' value='$Lang::tr{'update'}'style='min-width:100px;' > |
2a81ab0d AM |
1298 | <input type='hidden' name='ACTION' value='updateservice'> |
1299 | <input type='hidden' name='oldsrvname' value='$fwhostsettings{'oldsrvname'}'> | |
1300 | <input type='hidden' name='oldsrvport' value='$fwhostsettings{'oldsrvport'}'> | |
1301 | <input type='hidden' name='oldsrvprot' value='$fwhostsettings{'oldsrvprot'}'></form> | |
1302 | END | |
1303 | ||
1304 | }else{ | |
7f5b2820 | 1305 | print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>"; |
2a81ab0d AM |
1306 | } |
1307 | print<<END; | |
7f5b2820 | 1308 | <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr> |
2a81ab0d AM |
1309 | </table></form> |
1310 | ||
1311 | ||
1312 | END | |
1313 | &Header::closebox(); | |
1314 | &viewtableservice; | |
1315 | } | |
1316 | sub addservicegrp | |
1317 | { | |
1318 | &hint; | |
1319 | &error; | |
1320 | &showmenu; | |
1321 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost newservicegrp'}); | |
1322 | $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'}; | |
2a81ab0d AM |
1323 | if ($fwhostsettings{'updatesrvgrp'} eq ''){ |
1324 | print<<END; | |
1325 | <table width='100%' border='0'><form method='post'> | |
1326 | <tr><td>$Lang::tr{'fwhost addgrpname'}</td><td><input type='text' name='SRVGRP_NAME' value='$fwhostsettings{'SRVGRP_NAME'}'></td><td>$Lang::tr{'remark'}:</td><td width='1%'><input type='text' name='SRVGRP_REMARK' size='35' value='$fwhostsettings{'SRVGRP_REMARK'}'></td></tr> | |
5dd84c25 | 1327 | <tr><td colspan='4'><br><hr></td></td></tr> |
2a81ab0d AM |
1328 | </table> |
1329 | END | |
1330 | }else{ | |
1331 | print<<END; | |
6c869961 AM |
1332 | <table width='100%' border='0'><form method='post' style='display:inline'> |
1333 | <tr><td>$Lang::tr{'fwhost addgrpname'}</td><td><input type='text' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}' readonly ></td><td>$Lang::tr{'remark'}:</td><td width='1%'><input type='text' name='newsrvrem' size='35' value='$fwhostsettings{'SRVGRP_REMARK'}'></td><td><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldsrvrem' value='$fwhostsettings{'oldsrvgrpremark'}'><input type='hidden' name='ACTION' value='changesrvgrpremark' ></td></tr> | |
5dd84c25 | 1334 | <tr><td colspan='5'><br><hr></td></td></tr> |
6c869961 | 1335 | </table></form> |
2a81ab0d AM |
1336 | END |
1337 | } | |
1338 | if($fwhostsettings{'updatesrvgrp'} eq 'on'){ | |
2a81ab0d | 1339 | print<<END; |
6c869961 | 1340 | <form method='post'><input type='hidden' name='SRVGRP_REMARK' value='$fwhostsettings{'SRVGRP_REMARK'}'><input type='hidden' name='SRVGRP_NAME' value='$fwhostsettings{'SRVGRP_NAME'}'><table border='0' width='100%'> |
2a81ab0d AM |
1341 | <tr><td width='1%' nowrap='nowrap'>$Lang::tr{'fwhost cust service'}</td><td><select name='CUST_SRV' style='min-width:185px;'> |
1342 | END | |
1343 | &General::readhasharray("$configsrv", \%customservice); | |
0013abb0 | 1344 | foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0])|| $a <=> $b } keys %customservice) |
2a81ab0d AM |
1345 | { |
1346 | print "<option>$customservice{$key}[0]</option>"; | |
1347 | } | |
1348 | print<<END; | |
1349 | </select></td></tr> | |
5dd84c25 | 1350 | <tr><td colspan='4'><br><br></td></tr> |
2a81ab0d AM |
1351 | <tr><td colspan='4'><hr></td></tr> |
1352 | </table> | |
1353 | END | |
1354 | } | |
1355 | print<<END; | |
7f5b2820 AM |
1356 | <table width='100%' border='0'> |
1357 | <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' /><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'><input type='hidden' name='oldsrvgrpremark' value='$fwhostsettings{'oldsrvgrpremark'}'><input type='hidden' name='ACTION' value='saveservicegrp' ></form><form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></td></tr> | |
2a81ab0d AM |
1358 | </table></form> |
1359 | END | |
2a81ab0d AM |
1360 | &Header::closebox(); |
1361 | } | |
1362 | # View | |
1363 | sub viewtablenet | |
1364 | { | |
1365 | if(! -z $confignet){ | |
1366 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'}); | |
1367 | &General::readhasharray("$confignet", \%customnetwork); | |
1368 | if (!keys %customnetwork) | |
1369 | { | |
1370 | print "<center><b>$Lang::tr{'fwhost empty'}</b>"; | |
1371 | }else{ | |
1372 | print<<END; | |
1373 | <table border='0' width='100%'> | |
e5a058c1 | 1374 | <tr><td align='center'><b>$Lang::tr{'name'}</td><td align='center'><b>$Lang::tr{'fwhost netaddress'}</td><td align='center'><b>$Lang::tr{'netmask'}</td><td align='center'><b>$Lang::tr{'remark'}</td><td align='center'><b>$Lang::tr{'used'}</td><td></td><td width='3%'></td></tr> |
2a81ab0d AM |
1375 | END |
1376 | } | |
1377 | my $count=0; | |
ed62bbfb | 1378 | foreach my $key (sort {$a <=> $b} keys %customnetwork) { |
2a81ab0d AM |
1379 | if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) { |
1380 | print" <tr bgcolor='${Header::colouryellow}'>"; | |
1381 | }elsif ($count % 2) | |
1382 | { | |
1383 | print" <tr bgcolor='$color{'color22'}'>"; | |
1384 | }else | |
1385 | { | |
1386 | print" <tr bgcolor='$color{'color20'}'>"; | |
1387 | } | |
1388 | print<<END; | |
e5a058c1 | 1389 | <td width='20%'><form method='post'>$customnetwork{$key}[0]</td><td width=15%'>$customnetwork{$key}[1]</td><td width='15%'>$customnetwork{$key}[2]</td><td width='40%'>$customnetwork{$key}[3]</td><td align='center'>$customnetwork{$key}[4]x</td> |
2a81ab0d AM |
1390 | <td width='1%'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} /> |
1391 | <input type='hidden' name='ACTION' value='editnet'> | |
1392 | <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' /> | |
1393 | <input type='hidden' name='IP' value='$customnetwork{$key}[1]' /> | |
1394 | <input type='hidden' name='SUBNET' value='$customnetwork{$key}[2]' /> | |
e5a058c1 | 1395 | <input type='hidden' name='NETREMARK' value='$customnetwork{$key}[3]' /> |
2a81ab0d AM |
1396 | </td></form> |
1397 | END | |
e5a058c1 | 1398 | if($customnetwork{$key}[4] == '0') |
2a81ab0d AM |
1399 | { |
1400 | print"<td width='1%'><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} /><input type='hidden' name='ACTION' value='delnet' /><input type='hidden' name='key' value='$customnetwork{$key}[0]' /></td></form></tr>"; | |
1401 | }else{ | |
1402 | print"<td></td></form></tr>"; | |
1403 | } | |
1404 | $count++; | |
1405 | } | |
1406 | print"</table>"; | |
1407 | &Header::closebox(); | |
1408 | } | |
1409 | ||
1410 | } | |
1411 | sub viewtablehost | |
1412 | { | |
1413 | if (! -z $confighost){ | |
1414 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust addr'}); | |
1415 | &General::readhasharray("$confighost", \%customhost); | |
1416 | if (!keys %customhost) | |
1417 | { | |
1418 | print "<center><b>$Lang::tr{'fwhost empty'}</b>"; | |
1419 | }else{ | |
1420 | print<<END; | |
1421 | <table border='0' width='100%'> | |
e3580608 | 1422 | <tr><td align='center'><b>$Lang::tr{'name'}</td><td align='center'><b>$Lang::tr{'fwhost ip_mac'}</td><td align='center'><b>$Lang::tr{'remark'}</td><td align='center'><b>$Lang::tr{'used'}</td><td></td><td width='3%'></td></tr> |
2a81ab0d AM |
1423 | END |
1424 | } | |
1425 | my $count=0; | |
fb70d3d5 | 1426 | foreach my $key (sort { uc($customhost{$a}[0]) cmp uc($customhost{$b}[0])|| $a <=> $b } keys %customhost) { |
2a81ab0d AM |
1427 | if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) { |
1428 | print" <tr bgcolor='${Header::colouryellow}'>"; | |
1429 | }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";} | |
1430 | else{ print" <tr bgcolor='$color{'color20'}'>";} | |
1431 | my ($ip,$sub)=split(/\//,$customhost{$key}[2]); | |
e3580608 | 1432 | $customhost{$key}[4]=~s/\s+//g; |
2a81ab0d | 1433 | print<<END; |
e3580608 | 1434 | <td width='20%'><form method='post'>$customhost{$key}[0]</td><td width='20%'>$ip</td><td width='50%'>$customhost{$key}[3]</td><td align='center'>$customhost{$key}[4]x</td> |
2a81ab0d AM |
1435 | <td width='1%'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} /> |
1436 | <input type='hidden' name='ACTION' value='edithost' /> | |
1437 | <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' /> | |
1438 | <input type='hidden' name='IP' value='$ip' /> | |
1439 | <input type='hidden' name='type' value='$customhost{$key}[1]' /> | |
e3580608 | 1440 | <input type='hidden' name='HOSTREMARK' value='$customhost{$key}[3]' /> |
2a81ab0d AM |
1441 | </td></form> |
1442 | END | |
e3580608 | 1443 | if($customhost{$key}[4] == '0') |
2a81ab0d AM |
1444 | { |
1445 | print"<td width='1%'><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} /><input type='hidden' name='ACTION' value='delhost' /><input type='hidden' name='key' value='$customhost{$key}[0]' /></td></form></tr>"; | |
1446 | }else{ | |
1447 | print"<td width='1%'></td></tr>"; | |
1448 | } | |
1449 | $count++; | |
1450 | } | |
1451 | print"</table>"; | |
1452 | &Header::closebox(); | |
1453 | } | |
1454 | } | |
1455 | sub viewtablegrp | |
1456 | { | |
1457 | if(! -z "$configgrp"){ | |
1458 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust grp'}); | |
1459 | &General::readhasharray("$configgrp", \%customgrp); | |
1460 | &General::readhasharray("$configipsec", \%ipsecconf); | |
1461 | &General::readhasharray("$configccdhost", \%ccdhost); | |
1462 | &General::readhasharray("$configccdnet", \%ccdnet); | |
1463 | &General::readhasharray("$confighost", \%customhost); | |
1464 | &General::readhasharray("$confignet", \%customnetwork); | |
1465 | my @grp=(); | |
1466 | my $helper=''; | |
8f204435 | 1467 | my $count=1; |
2a81ab0d AM |
1468 | my $grpname; |
1469 | my $remark; | |
12dcfbbd | 1470 | my $number; |
2cee2462 | 1471 | my $delflag; |
2a81ab0d AM |
1472 | if (!keys %customgrp) |
1473 | { | |
1474 | print "<center><b>$Lang::tr{'fwhost empty'}</b>"; | |
1475 | }else{ | |
20c00d4b | 1476 | foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } sort { uc($customgrp{$a}[2]) cmp uc($customgrp{$b}[2]) } keys %customgrp){ |
2a81ab0d AM |
1477 | $count++; |
1478 | if ($helper ne $customgrp{$key}[0]){ | |
2cee2462 AM |
1479 | $delflag='0'; |
1480 | foreach my $key1 (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } sort { uc($customgrp{$a}[2]) cmp uc($customgrp{$b}[2]) } keys %customgrp){ | |
1481 | if ($customgrp{$key}[0] eq $customgrp{$key1}[0]) | |
1482 | { | |
1483 | $delflag++; | |
1484 | } | |
d0815ce4 | 1485 | if($delflag > 1){ |
d13a9363 AM |
1486 | last; |
1487 | } | |
2cee2462 | 1488 | } |
8f204435 | 1489 | $number=1; |
6c869961 | 1490 | if ($customgrp{$key}[2] eq "none"){$customgrp{$key}[2]=$Lang::tr{'fwhost empty'};} |
2a81ab0d | 1491 | $grpname=$customgrp{$key}[0]; |
6c869961 | 1492 | $remark="$customgrp{$key}[1]"; |
2a81ab0d AM |
1493 | if($count >=2){print"</table>";} |
1494 | print "<br><b><u>$grpname</u></b>    "; | |
1495 | print " <b>$Lang::tr{'remark'}:</b>  $remark   " if ($remark ne ''); | |
937d4e08 | 1496 | print "<b>$Lang::tr{'used'}:</b> $customgrp{$key}[4]x"; |
2a81ab0d AM |
1497 | if($customgrp{$key}[4] == '0') |
1498 | { | |
1499 | print"<form method='post' style='display:inline'><input type='image' src='/images/delete.gif' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} align='right' /><input type='hidden' name='grp_name' value='$grpname' ><input type='hidden' name='ACTION' value='delgrp'></form>"; | |
1500 | } | |
1501 | print"<form method='post' style='display:inline'><input type='image' src='/images/edit.gif' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} align='right' /><input type='hidden' name='grp_name' value='$grpname' ><input type='hidden' name='remark' value='$remark' ><input type='hidden' name='ACTION' value='editgrp'></form>"; | |
e638799b | 1502 | print"<table width='100%' style='border: 1px solid #000000;' rules='none' ><tr><td align='center'><b>Name</b></td><td align='center'><b>$Lang::tr{'ip address'}</b></td><td align='center' width='25%'><b>$Lang::tr{'fwhost type'}</td><td></td></tr>"; |
2a81ab0d | 1503 | } |
2cee2462 | 1504 | |
2a81ab0d AM |
1505 | if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) { |
1506 | print" <tr bgcolor='${Header::colouryellow}'>"; | |
6c869961 AM |
1507 | }elsif ($count %2 == 0){ |
1508 | print"<tr bgcolor='$color{'color22'}'>"; | |
1509 | }else{ | |
1510 | print"<tr bgcolor='$color{'color20'}'>"; | |
1511 | } | |
2a81ab0d AM |
1512 | my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]); |
1513 | if ($ip eq ''){print"<tr bgcolor='${Header::colouryellow}'>";} | |
2a81ab0d AM |
1514 | print "<td width='39%'>"; |
1515 | if($customgrp{$key}[3] eq 'Standard Network'){ | |
1516 | print &get_name($customgrp{$key}[2])."</td>"; | |
1517 | }else{ | |
1518 | print "$customgrp{$key}[2]</td>"; | |
1519 | } | |
1520 | if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost empty'}){ | |
1521 | print "<td align='center'>$Lang::tr{'fwhost deleted'}</td><td>$customgrp{$key}[3]</td><td width='1%'><form method='post'>"; | |
1522 | }else{ | |
1523 | print"<td>$ip</td><td>$customgrp{$key}[3]</td><td width='1%'><form method='post'>"; | |
1524 | } | |
2cee2462 | 1525 | if ($delflag > '1' && $ip ne ''){ |
2a81ab0d AM |
1526 | print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />"; |
1527 | } | |
e3580608 | 1528 | print"<input type='hidden' name='ACTION' value='deletegrphost'><input type='hidden' name='grpcnt' value='$customgrp{$key}[4]'><input type='hidden' name='update' value='$fwhostsettings{'update'}'><input type='hidden' name='delhost' value='$grpname,$remark,$customgrp{$key}[2],$customgrp{$key}[3]'></form></td></tr>"; |
2a81ab0d AM |
1529 | |
1530 | $helper=$customgrp{$key}[0]; | |
12dcfbbd | 1531 | $number++; |
2a81ab0d AM |
1532 | } |
1533 | print"</table>"; | |
1534 | ||
1535 | } | |
1536 | &Header::closebox(); | |
1537 | } | |
1538 | ||
1539 | } | |
1540 | sub viewtableservice | |
1541 | { | |
1542 | my $count=0; | |
1543 | if(! -z "$configsrv") | |
1544 | { | |
1545 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'}); | |
1546 | &General::readhasharray("$configsrv", \%customservice); | |
1547 | print<<END; | |
1548 | <table width='100%' border='0'> | |
1549 | <tr><td align='center'><b>$Lang::tr{'fwhost srv_name'}</td><td align='center'><b>$Lang::tr{'fwhost prot'}</td><td align='center'><b>$Lang::tr{'fwhost port'}</td><td align='center'><b>ICMP</td><td align='center'><b>$Lang::tr{'fwhost used'}</td><td></td><td width='3%'></td></tr> | |
1550 | END | |
937d4e08 | 1551 | foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0])|| $a <=> $b } keys %customservice) |
2a81ab0d AM |
1552 | { |
1553 | $count++; | |
1554 | if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) { | |
1555 | print" <tr bgcolor='${Header::colouryellow}'>"; | |
1556 | }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";}else{ print" <tr bgcolor='$color{'color20'}'>";} | |
1557 | print<<END; | |
1558 | <td>$customservice{$key}[0]</td><td align='center'>$customservice{$key}[2]</td><td align='center'>$customservice{$key}[1]</td><td align='center'> | |
1559 | END | |
1560 | if($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];} | |
1561 | ||
1562 | print<<END; | |
1563 | </td><td align='center'>$customservice{$key}[4]x</td> | |
1564 | <td width='1%'><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} /><input type='hidden' name='ACTION' value='editservice' /> | |
1565 | <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' /> | |
1566 | <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' /> | |
1567 | <input type='hidden' name='PROT' value='$customservice{$key}[2]' /></form></td> | |
1568 | END | |
1569 | if ($customservice{$key}[4] eq '0') | |
1570 | { | |
1571 | print"<td width='1%'><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} /><input type='hidden' name='ACTION' value='delservice' /><input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]'></td></tr></form>"; | |
1572 | }else{ | |
1573 | print"<td></td></tr>"; | |
1574 | } | |
1575 | } | |
1576 | print"</table>"; | |
1577 | &Header::closebox(); | |
1578 | } | |
1579 | } | |
1580 | sub viewtableservicegrp | |
1581 | { | |
1582 | my $count=0; | |
1583 | my $grpname; | |
1584 | my $remark; | |
1585 | my $helper; | |
937d4e08 AM |
1586 | my $port; |
1587 | my $protocol; | |
c7043621 | 1588 | my $delflag; |
2a81ab0d | 1589 | if (! -z $configsrvgrp){ |
2a81ab0d AM |
1590 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'}); |
1591 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
937d4e08 | 1592 | &General::readhasharray("$configsrv", \%customservice); |
2a81ab0d | 1593 | my $number= keys %customservicegrp; |
0f869e32 | 1594 | foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0])|| $a <=> $b } keys %customservicegrp){ |
2a81ab0d AM |
1595 | $count++; |
1596 | if ($helper ne $customservicegrp{$key}[0]){ | |
d13a9363 AM |
1597 | $delflag=0; |
1598 | foreach my $key1 (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } sort { uc($customservicegrp{$a}[2]) cmp uc($customservicegrp{$b}[2]) } keys %customservicegrp){ | |
1599 | if ($customservicegrp{$key}[0] eq $customservicegrp{$key1}[0]) | |
1600 | { | |
1601 | $delflag++; | |
1602 | } | |
1603 | if($delflag > 1){ | |
1604 | last; | |
1605 | } | |
1606 | } | |
2a81ab0d | 1607 | $grpname=$customservicegrp{$key}[0]; |
6c869961 AM |
1608 | if ($customservicegrp{$key}[2] eq "none"){ |
1609 | $customservicegrp{$key}[2]=$Lang::tr{'fwhost empty'}; | |
0b54aaed AM |
1610 | $port=''; |
1611 | $protocol=''; | |
6c869961 AM |
1612 | } |
1613 | $remark="$customservicegrp{$key}[1]"; | |
2a81ab0d AM |
1614 | if($count >=2){print"</table>";} |
1615 | print "<br><b><u>$grpname</u></b>     "; | |
1616 | print "<b>$Lang::tr{'remark'}:</b>  $remark " if ($remark ne ''); | |
937d4e08 AM |
1617 | print "  <b>$Lang::tr{'used'}:</b> $customservicegrp{$key}[3]x"; |
1618 | if($customservicegrp{$key}[3] == '0') | |
2a81ab0d AM |
1619 | { |
1620 | print"<form method='post' style='display:inline'><input type='image' src='/images/delete.gif' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} align='right' /><input type='hidden' name='SRVGRP_NAME' value='$grpname' ><input type='hidden' name='ACTION' value='delservicegrp'></form>"; | |
1621 | } | |
1622 | print"<form method='post' style='display:inline'><input type='image' src='/images/edit.gif' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} align='right' /><input type='hidden' name='SRVGRP_NAME' value='$grpname' ><input type='hidden' name='SRVGRP_REMARK' value='$remark' ><input type='hidden' name='ACTION' value='editservicegrp'></form>"; | |
e638799b | 1623 | print"<table width='100%' style='border: 1px solid #000000;' rules='none' ><tr><td align='center'><b>Name</b></td><td align='center'><b>$Lang::tr{'port'}</b></td><td align='center' width='25%'><b>$Lang::tr{'fwhost prot'}</td><td></td></tr>"; |
2a81ab0d AM |
1624 | } |
1625 | if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) { | |
1626 | print" <tr bgcolor='${Header::colouryellow}'>"; | |
6c869961 | 1627 | }elsif ($count %2 == 0){ |
0f869e32 AM |
1628 | print"<tr bgcolor='$color{'color22'}'>"; |
1629 | }else{ | |
1630 | print"<tr bgcolor='$color{'color20'}'>"; | |
1631 | } | |
1632 | print "<td width='39%'>$customservicegrp{$key}[2]</td>"; | |
937d4e08 AM |
1633 | foreach my $srv (sort keys %customservice){ |
1634 | if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){ | |
1635 | $protocol=$customservice{$srv}[2]; | |
1636 | $port=$customservice{$srv}[1]; | |
1637 | last; | |
1638 | } | |
1639 | } | |
1640 | print"<td align='center'>$port</td><td align='center'>$protocol</td><td width='1%'><form method='post'>"; | |
3f8fe51e | 1641 | if ($number gt '1'){ |
0f869e32 AM |
1642 | print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />"; |
1643 | } | |
3f8fe51e | 1644 | print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'><input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2],$customservicegrp{$key}[3]'></form></td></tr>"; |
0f869e32 | 1645 | $helper=$customservicegrp{$key}[0]; |
2a81ab0d AM |
1646 | } |
1647 | print"</table>"; | |
1648 | &Header::closebox(); | |
1649 | } | |
1650 | } | |
1651 | # Check | |
1652 | sub checkname | |
1653 | { | |
1654 | my %hash=%{(shift)}; | |
1655 | foreach my $key (keys %hash) { | |
1656 | if($hash{$key}[0] eq $fwhostsettings{'HOSTNAME'}){ | |
1657 | return 0; | |
1658 | } | |
1659 | } | |
1660 | return 1; | |
1661 | ||
1662 | } | |
1663 | sub checkip | |
1664 | { | |
1665 | ||
1666 | my %hash=%{(shift)}; | |
1667 | my $a=shift; | |
1668 | foreach my $key (keys %hash) { | |
1669 | if($hash{$key}[$a] eq $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'})){ | |
1670 | return 0; | |
1671 | } | |
1672 | } | |
1673 | return 1; | |
1674 | } | |
1675 | sub checksubnet | |
1676 | { | |
1677 | ||
1678 | my %hash=%{(shift)}; | |
1679 | &General::readhasharray("$confignet", \%hash); | |
1680 | foreach my $key (keys %hash) { | |
1681 | if(&General::IpInSubnet($fwhostsettings{'IP'},$hash{$key}[1],$hash{$key}[2])) | |
1682 | { | |
1683 | return 1; | |
1684 | } | |
1685 | } | |
1686 | return 0; | |
1687 | } | |
1688 | sub checkservicegroup | |
1689 | { | |
1690 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
1691 | ||
1692 | ||
1693 | #check name | |
7772ae73 | 1694 | if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'})) |
2a81ab0d AM |
1695 | { |
1696 | $errormessage.=$Lang::tr{'fwhost err name'}."<br>"; | |
1697 | return $errormessage; | |
1698 | } | |
2a81ab0d AM |
1699 | #check empty selectbox |
1700 | if (keys %customservice lt 1) | |
1701 | { | |
1702 | $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>"; | |
1703 | } | |
2a81ab0d AM |
1704 | #check if name already exists |
1705 | if ($fwhostsettings{'updatesrvgrp'} ne 'on'){ | |
1706 | foreach my $key (keys %customservicegrp) { | |
1707 | if( $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} ){ | |
1708 | $errormessage.=$Lang::tr{'fwhost err grpexist'}."<br>"; | |
1709 | ||
1710 | } | |
1711 | } | |
1712 | } | |
1713 | #check if service already exists in group | |
1714 | foreach my $key (keys %customservicegrp) { | |
13e5dda4 AM |
1715 | if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){ |
1716 | $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>"; | |
2a81ab0d | 1717 | } |
13e5dda4 | 1718 | } |
2a81ab0d AM |
1719 | return $errormessage; |
1720 | } | |
1721 | sub error | |
1722 | { | |
1723 | if ($errormessage) { | |
1724 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
1725 | print "<class name='base'>$errormessage\n"; | |
1726 | print " </class>\n"; | |
1727 | &Header::closebox(); | |
1728 | } | |
1729 | } | |
1730 | sub hint | |
1731 | { | |
1732 | if ($hint) { | |
1733 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'}); | |
1734 | print "<class name='base'>$hint\n"; | |
1735 | print " </class>\n"; | |
1736 | &Header::closebox(); | |
1737 | } | |
1738 | } | |
1739 | sub get_name | |
1740 | { | |
1741 | my $val=shift; | |
1742 | &General::setup_default_networks(\%defaultNetworks); | |
1743 | foreach my $network (sort keys %defaultNetworks) | |
1744 | { | |
1745 | return "$network" if ($val eq $defaultNetworks{$network}{'NAME'}); | |
1746 | } | |
1747 | } | |
1748 | sub deletefromgrp | |
1749 | { | |
1750 | my $target=shift; | |
1751 | my $config=shift; | |
1752 | my %hash=(); | |
1753 | &General::readhasharray("$config",\%hash); | |
1754 | foreach my $key (keys %hash) { | |
1755 | $errormessage.="lese $hash{$key}[2] und $target<br>"; | |
1756 | if($hash{$key}[2] eq $target){ | |
1757 | ||
1758 | delete $hash{$key}; | |
1759 | $errormessage.="Habe $target aus Gruppe gelöscht!<br>"; | |
1760 | } | |
1761 | } | |
1762 | &General::writehasharray("$config",\%hash); | |
1763 | ||
1764 | } | |
1765 | sub plausicheck | |
1766 | { | |
2a81ab0d AM |
1767 | my $edit=shift; |
1768 | #check hostname | |
d0815ce4 | 1769 | if (!&validhostname($fwhostsettings{'HOSTNAME'})) |
2a81ab0d AM |
1770 | { |
1771 | $errormessage=$errormessage.$Lang::tr{'fwhost err name'}; | |
1772 | $fwhostsettings{'BLK_IP'}='readonly'; | |
1773 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
1774 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
1775 | } | |
1776 | #check if name collides with CCD Netname | |
2a81ab0d AM |
1777 | &General::readhasharray("$configccdnet", \%ccdnet); |
1778 | foreach my $key (keys %ccdnet) { | |
1779 | if($ccdnet{$key}[0] eq $fwhostsettings{'HOSTNAME'}){ | |
1780 | $errormessage=$errormessage.$Lang::tr{'fwhost err isccdnet'};; | |
1781 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
1782 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
1783 | last; | |
1784 | } | |
1785 | } | |
2a81ab0d AM |
1786 | #check if IP collides with CCD NetIP |
1787 | if ($fwhostsettings{'type'} ne 'mac'){ | |
1788 | &General::readhasharray("$configccdnet", \%ccdnet); | |
1789 | foreach my $key (keys %ccdnet) { | |
1790 | my $test=(&General::getnetworkip($fwhostsettings{'IP'},&General::iporsubtocidr($fwhostsettings{'SUBNET'})))."/".$fwhostsettings{'SUBNET'}; | |
1791 | if($ccdnet{$key}[1] eq $test){ | |
1792 | $errormessage=$errormessage.$Lang::tr{'fwhost err isccdipnet'}; | |
1793 | $fwhostsettings{'IP'} = $fwhostsettings{'orgip'}; | |
1794 | $fwhostsettings{'SUBNET'} = $fwhostsettings{'orgsubnet'}; | |
1795 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
1796 | last; | |
1797 | } | |
1798 | } | |
1799 | } | |
2a81ab0d AM |
1800 | #check if name collides with CCD Hostname |
1801 | &General::readhasharray("$configccdhost", \%ccdhost); | |
1802 | foreach my $key (keys %ccdhost) { | |
1803 | my ($ip,$sub)=split(/\//,$ccdhost{$key}[33]); | |
1804 | if($ip eq $fwhostsettings{'IP'}){ | |
1805 | $errormessage=$Lang::tr{'fwhost err isccdiphost'}; | |
1806 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
1807 | last; | |
1808 | } | |
1809 | } | |
1810 | #check if IP collides with CCD HostIP (only hosts) | |
1811 | if ($edit eq 'edithost') | |
1812 | { | |
1813 | foreach my $key (keys %ccdhost) { | |
1814 | if($ccdhost{$key}[1] eq $fwhostsettings{'HOSTNAME'}){ | |
1815 | $errormessage=$Lang::tr{'fwhost err isccdhost'}; | |
1816 | $fwhostsettings{'IP'} = $fwhostsettings{'orgname'}; | |
1817 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
1818 | last; | |
1819 | } | |
1820 | } | |
1821 | } | |
1822 | #check if network with this name already exists | |
1823 | &General::readhasharray("$confignet", \%customnetwork); | |
1824 | if (!&checkname(\%customnetwork)) | |
1825 | { | |
1826 | $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err netexist'}; | |
1827 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
1828 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
1829 | } | |
1830 | #check if network ip already exists | |
1831 | if (!&checkip(\%customnetwork,1)) | |
1832 | { | |
1833 | $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err net'}; | |
1834 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
1835 | } | |
1836 | #check if host with this name already exists | |
1837 | &General::readhasharray("$confighost", \%customhost); | |
1838 | if (!&checkname(\%customhost)) | |
1839 | { | |
0013abb0 | 1840 | $errormessage.="<br>".$Lang::tr{'fwhost err hostexist'}; |
2a81ab0d | 1841 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; |
ed73b87e | 1842 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} |
2a81ab0d AM |
1843 | } |
1844 | #check if host with this ip already exists | |
1845 | if (!&checkip(\%customhost,2)) | |
1846 | { | |
1847 | $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'}; | |
2a81ab0d | 1848 | } |
2a81ab0d AM |
1849 | return; |
1850 | } | |
1851 | sub getipforgroup | |
1852 | { | |
1853 | my $name=$_[0], | |
1854 | my $type=$_[1]; | |
1855 | my $value; | |
1856 | ||
1857 | #get address from IPSEC NETWORK | |
1858 | if ($type eq 'IpSec Network'){ | |
1859 | foreach my $key (keys %ipsecconf) { | |
1860 | if ($ipsecconf{$key}[1] eq $name){ | |
1861 | return $ipsecconf{$key}[11]; | |
1862 | } | |
1863 | } | |
1864 | &deletefromgrp($name,$configgrp); | |
1865 | } | |
1866 | ||
1867 | #get address from IPSEC HOST | |
1868 | if ($type eq 'IpSec Host'){ | |
1869 | foreach my $key (keys %ipsecconf) { | |
1870 | if ($ipsecconf{$key}[1] eq $name){ | |
1871 | return $ipsecconf{$key}[10]; | |
1872 | } | |
1873 | } | |
1874 | &deletefromgrp($name,$configgrp); | |
1875 | } | |
1876 | ||
1877 | #get address from ovpn ccd Net-2-Net | |
1878 | if ($type eq 'OpenVPN N-2-N'){ | |
1879 | foreach my $key (keys %ccdhost) { | |
1880 | if($ccdhost{$key}[1] eq $name){ | |
1881 | my ($a,$b) = split ("/",$ccdhost{$key}[11]); | |
1882 | $b=&General::iporsubtodec($b); | |
1883 | return "$a/$b"; | |
1884 | } | |
1885 | } | |
1886 | &deletefromgrp($name,$configgrp); | |
1887 | } | |
1888 | ||
1889 | #get address from ovpn ccd static host | |
1890 | if ($type eq 'OpenVPN static host'){ | |
1891 | foreach my $key (keys %ccdhost) { | |
1892 | if($ccdhost{$key}[1] eq $name){ | |
1893 | my ($a,$b) = split (/\//,$ccdhost{$key}[33]); | |
1894 | $b=&General::iporsubtodec($b); | |
1895 | return "$a/$b"; | |
1896 | } | |
1897 | } | |
1898 | &deletefromgrp($name,$configgrp); | |
1899 | } | |
1900 | ||
1901 | #get address from ovpn ccd static net | |
1902 | if ($type eq 'OpenVPN static network'){ | |
1903 | foreach my $key (keys %ccdnet) { | |
1904 | if ($ccdnet{$key}[0] eq $name){ | |
1905 | my ($a,$b) = split (/\//,$ccdnet{$key}[1]); | |
1906 | $b=&General::iporsubtodec($b); | |
1907 | return "$a/$b"; | |
1908 | } | |
1909 | } | |
1910 | } | |
1911 | ||
1912 | #check custom addresses | |
1913 | if ($type eq 'Custom Host'){ | |
1914 | foreach my $key (keys %customhost) { | |
1915 | if ($customhost{$key}[0] eq $name){ | |
1916 | return $customhost{$key}[2]; | |
1917 | } | |
1918 | } | |
1919 | } | |
1920 | ||
1921 | ##check custom networks | |
1922 | if ($type eq 'Custom Network'){ | |
1923 | foreach my $key (keys %customnetwork) { | |
1924 | if($customnetwork{$key}[0] eq $name){ | |
1925 | return $customnetwork{$key}[1]."/".$customnetwork{$key}[2]; | |
1926 | } | |
1927 | } | |
1928 | } | |
1929 | ||
1930 | #check standard networks | |
1931 | if ($type eq 'Standard Network'){ | |
1932 | if ($name =~ /OpenVPN/i){ | |
1933 | my %ovpn=(); | |
1934 | &General::readhash("${General::swroot}/ovpn/settings",\%ovpn); | |
1935 | return $ovpn{'DOVPN_SUBNET'}; | |
1936 | } | |
1937 | if ($name eq 'GREEN'){ | |
1938 | my %hash=(); | |
1939 | &General::readhash("${General::swroot}/ethernet/settings",\%hash); | |
1940 | return $hash{'GREEN_NETADDRESS'}."/".$hash{'GREEN_NETMASK'}; | |
1941 | } | |
1942 | if ($name eq 'BLUE'){ | |
1943 | my %hash=(); | |
1944 | &General::readhash("${General::swroot}/ethernet/settings",\%hash); | |
1945 | return $hash{'BLUE_NETADDRESS'}."/".$hash{'BLUE_NETMASK'}; | |
1946 | } | |
1947 | if ($name eq 'ORANGE'){ | |
1948 | my %hash=(); | |
1949 | &General::readhash("${General::swroot}/ethernet/settings",\%hash); | |
1950 | return $hash{'ORANGE_NETADDRESS'}."/".$hash{'ORANGE_NETMASK'}; | |
1951 | } | |
1952 | if ($name eq 'ALL'){ | |
1953 | return "0.0.0.0/0.0.0.0"; | |
1954 | } | |
1955 | if ($name =~ /IPsec/i){ | |
1956 | my %hash=(); | |
1957 | &General::readhash("${General::swroot}/vpn/settings",\%hash); | |
1958 | return $hash{'RW_NET'}; | |
1959 | } | |
1960 | } | |
1961 | } | |
1962 | sub rules | |
cd9d9d8a AM |
1963 | { |
1964 | if (!-f "${General::swroot}/fwhosts/reread"){ | |
1965 | system("touch ${General::swroot}/fwhosts/reread"); | |
d0815ce4 | 1966 | system("touch ${General::swroot}/forward/reread"); |
cd9d9d8a AM |
1967 | } |
1968 | } | |
1969 | sub reread_rules | |
2a81ab0d AM |
1970 | { |
1971 | system ("/usr/local/bin/forwardfwctrl"); | |
cd9d9d8a AM |
1972 | if ( -f "${General::swroot}/fwhosts/reread"){ |
1973 | system("rm ${General::swroot}/fwhosts/reread"); | |
d0815ce4 | 1974 | system("rm ${General::swroot}/forward/reread"); |
cd9d9d8a AM |
1975 | } |
1976 | ||
2a81ab0d AM |
1977 | } |
1978 | sub decrease | |
1979 | { | |
1980 | my $grp=$_[0]; | |
1981 | &General::readhasharray("$confignet", \%customnetwork); | |
1982 | &General::readhasharray("$confighost", \%customhost); | |
1983 | foreach my $key (sort keys %customgrp ){ | |
1984 | if ( ($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Network')){ | |
1985 | foreach my $key1 (sort keys %customnetwork){ | |
1986 | if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){ | |
1987 | $customnetwork{$key1}[3]=$customnetwork{$key1}[3]-1; | |
1988 | last; | |
1989 | } | |
1990 | } | |
1991 | } | |
1992 | ||
1993 | if (($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Host')){ | |
1994 | foreach my $key2 (sort keys %customhost){ | |
1995 | if ($customhost{$key2}[0] eq $customgrp{$key}[2]){ | |
1996 | $customhost{$key2}[3]=$customhost{$key2}[3]-1; | |
1997 | last; | |
1998 | } | |
1999 | } | |
2000 | ||
2001 | } | |
2002 | } | |
2003 | &General::writehasharray("$confignet", \%customnetwork); | |
2004 | &General::writehasharray("$confighost", \%customhost); | |
2005 | } | |
2006 | sub decreaseservice | |
2007 | { | |
2008 | my $grp=$_[0]; | |
2009 | &General::readhasharray("$configsrv", \%customservice); | |
2010 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
2011 | ||
2012 | foreach my $key (sort keys %customservicegrp){ | |
2013 | if ($customservicegrp{$key}[0] eq $grp ){ | |
2014 | foreach my $key2 (sort keys %customservice){ | |
2015 | if ($customservice{$key2}[0] eq $customservicegrp{$key}[2]){ | |
2016 | $customservice{$key2}[4]--; | |
2017 | } | |
2018 | } | |
2019 | } | |
2020 | } | |
2021 | &General::writehasharray("$configsrv", \%customservice); | |
2022 | ||
2023 | } | |
2024 | sub checkports | |
2025 | { | |
2026 | ||
2027 | my %hash=%{(shift)}; | |
2028 | #check empty fields | |
2029 | if ($fwhostsettings{'SRV_NAME'} eq '' ){ | |
2030 | $errormessage=$Lang::tr{'fwhost err name1'}; | |
2031 | } | |
2032 | if ($fwhostsettings{'SRV_PORT'} eq '' && $fwhostsettings{'PROT'} ne 'ICMP'){ | |
2033 | $errormessage=$Lang::tr{'fwhost err port'}; | |
2034 | } | |
2035 | #check valid name | |
7772ae73 | 2036 | if (! &validhostname($fwhostsettings{'SRV_NAME'})){ |
2a81ab0d AM |
2037 | $errormessage="<br>".$Lang::tr{'fwhost err name'}; |
2038 | } | |
2039 | #change dashes with : | |
2040 | $fwhostsettings{'SRV_PORT'}=~ tr/-/:/; | |
2041 | ||
2042 | if ($fwhostsettings{'SRV_PORT'} eq "*") { | |
2043 | $fwhostsettings{'SRV_PORT'} = "1:65535"; | |
2044 | } | |
2045 | if ($fwhostsettings{'SRV_PORT'} =~ /^(\D)\:(\d+)$/) { | |
2046 | $fwhostsettings{'SRV_PORT'} = "1:$2"; | |
2047 | } | |
2048 | if ($fwhostsettings{'SRV_PORT'} =~ /^(\d+)\:(\D)$/) { | |
2049 | $fwhostsettings{'SRV_PORT'} = "$1:65535"; | |
2050 | } | |
2051 | if($fwhostsettings{'PROT'} ne 'ICMP'){ | |
2052 | $errormessage = $errormessage.&General::validportrange($fwhostsettings{'SRV_PORT'}, 'src'); | |
2053 | } | |
2054 | # a new service has to have a different name | |
2055 | foreach my $key (keys %hash){ | |
2056 | if ($hash{$key}[0] eq $fwhostsettings{'SRV_NAME'}){ | |
2057 | $errormessage = "<br>".$Lang::tr{'fwhost err srv exists'}; | |
2058 | last; | |
2059 | } | |
2060 | } | |
2061 | return $errormessage; | |
2062 | } | |
2063 | sub validhostname | |
2064 | { | |
2065 | # Checks a hostname against RFC1035 | |
2066 | my $hostname = $_[0]; | |
2067 | ||
2068 | # Each part should be at least two characters in length | |
2069 | # but no more than 63 characters | |
2070 | if (length ($hostname) < 1 || length ($hostname) > 63) { | |
2071 | return 0;} | |
2072 | # Only valid characters are a-z, A-Z, 0-9 and - | |
d0815ce4 | 2073 | if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-_.;()\/\s]*$/) { |
2a81ab0d AM |
2074 | return 0;} |
2075 | # First character can only be a letter or a digit | |
2076 | if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) { | |
2077 | return 0;} | |
2078 | # Last character can only be a letter or a digit | |
7772ae73 | 2079 | if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9()]*$/) { |
2a81ab0d AM |
2080 | return 0;} |
2081 | return 1; | |
2082 | } | |
6c869961 AM |
2083 | sub validremark |
2084 | { | |
2085 | # Checks a hostname against RFC1035 | |
2086 | my $remark = $_[0]; | |
2087 | # Each part should be at least two characters in length | |
2088 | # but no more than 63 characters | |
2089 | if (length ($remark) < 1 || length ($remark) > 255) { | |
2090 | return 0;} | |
2091 | # Only valid characters are a-z, A-Z, 0-9 and - | |
d928d795 | 2092 | if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) { |
6c869961 AM |
2093 | return 0;} |
2094 | # First character can only be a letter or a digit | |
2095 | if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) { | |
2096 | return 0;} | |
2097 | # Last character can only be a letter or a digit | |
d928d795 | 2098 | if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) { |
6c869961 AM |
2099 | return 0;} |
2100 | return 1; | |
2101 | } | |
2a81ab0d AM |
2102 | &Header::closebigbox(); |
2103 | &Header::closepage(); |