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