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