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