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