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