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