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