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