]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/fwhosts.cgi
vpn-statistic: change title of ovpn RW statistic page
[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
dadffbf7
AM
24#use warnings;
25
eff2dbf8 26use Sort::Naturally;
2a81ab0d
AM
27use CGI::Carp 'fatalsToBrowser';
28no warnings 'uninitialized';
29require '/var/ipfire/general-functions.pl';
30require "${General::swroot}/lang.pl";
31require "${General::swroot}/header.pl";
32
33my %fwhostsettings=();
34my %customnetwork=();
35my %customhost=();
36my %customgrp=();
37my %customservice=();
38my %customservicegrp=();
39my %ccdnet=();
40my %ccdhost=();
41my %ipsecconf=();
42my %icmptypes=();
43my %color=();
44my %defaultNetworks=();
45my %mainsettings=();
46my %ownnet=();
47my %ipsecsettings=();
62fc8511
AM
48my %fwfwd=();
49my %fwinp=();
3a162dc1 50my %fwout=();
b119578f 51my %ovpnsettings=();
f620fa34 52my %netsettings=();
2a81ab0d
AM
53
54my $errormessage;
55my $hint;
56my $update=0;
57my $confignet = "${General::swroot}/fwhosts/customnetworks";
58my $confighost = "${General::swroot}/fwhosts/customhosts";
59my $configgrp = "${General::swroot}/fwhosts/customgroups";
60my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
61my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
62my $configipsec = "${General::swroot}/vpn/config";
63my $configsrv = "${General::swroot}/fwhosts/customservices";
64my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
6d8eb5de
AM
65my $fwconfigfwd = "${General::swroot}/firewall/config";
66my $fwconfiginp = "${General::swroot}/firewall/input";
3a162dc1 67my $fwconfigout = "${General::swroot}/firewall/outgoing";
b119578f 68my $configovpn = "${General::swroot}/ovpn/settings";
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);
f620fa34 83&General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
2a81ab0d
AM
84&Header::getcgihash(\%fwhostsettings);
85
86&Header::showhttpheaders();
4d74a20d 87&Header::openpage($Lang::tr{'fwhost menu'}, 1, '');
2a81ab0d
AM
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'};
49da7d79 242 &checkrulereload($customservicegrp{$key}[0]);
bfac6bd4
AM
243 }
244 }
245 &General::writehasharray("$configsrvgrp", \%customservicegrp);
2aeb4b25 246 }
49da7d79 247 &checkrulereload($fwhostsettings{'SRV_NAME'});
2a81ab0d
AM
248 $fwhostsettings{'SRV_NAME'} = '';
249 $fwhostsettings{'SRV_PORT'} = '';
250 $fwhostsettings{'PROT'} = '';
2aeb4b25
AM
251 $fwhostsettings{'ICMP'} = '';
252 $fwhostsettings{'oldsrvicmp'} = '';
3a162dc1 253 $fwhostsettings{'updatesrv'} = '';
2a81ab0d
AM
254 }else{
255 $fwhostsettings{'SRV_NAME'} = $fwhostsettings{'oldsrvname'};
256 $fwhostsettings{'SRV_PORT'} = $fwhostsettings{'oldsrvport'};
257 $fwhostsettings{'PROT'} = $fwhostsettings{'oldsrvprot'};
2aeb4b25 258 $fwhostsettings{'ICMP'} = $fwhostsettings{'oldsrvicmp'};
2a81ab0d
AM
259 $fwhostsettings{'updatesrv'}= 'on';
260 }
2a81ab0d
AM
261 &addservice;
262}
263# save
264if ($fwhostsettings{'ACTION'} eq 'savenet' )
265{
2a81ab0d
AM
266 my $needrules=0;
267 if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
2a81ab0d
AM
268 #check if all fields are set
269 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
270 {
271 $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
272 &addnet;
273 &viewtablenet;
274 }else{
275 #check valid ip
276 if (!&General::validipandmask($fwhostsettings{'IP'}."/".$fwhostsettings{'SUBNET'}))
277 {
278 $errormessage=$errormessage.$Lang::tr{'fwhost err addr'};
279 $fwhostsettings{'BLK_HOST'} ='readonly';
280 $fwhostsettings{'NOCHECK'} ='false';
281 $fwhostsettings{'error'} ='on';
282 }
e5a058c1
AM
283 #check remark
284 if ($fwhostsettings{'NETREMARK'} ne '' && !&validremark($fwhostsettings{'NETREMARK'})){
285 $errormessage=$Lang::tr{'fwhost err remark'};
286 $fwhostsettings{'error'} ='on';
287 }
2a81ab0d
AM
288 #check if subnet is sigle host
289 if(&General::iporsubtocidr($fwhostsettings{'SUBNET'}) eq '32')
290 {
291 $errormessage=$errormessage.$Lang::tr{'fwhost err sub32'};
2a81ab0d
AM
292 }
293 if($fwhostsettings{'error'} ne 'on'){
3928f52b
AM
294 my $fullip="$fwhostsettings{'IP'}/".&General::iporsubtocidr($fwhostsettings{'SUBNET'});
295 $errormessage=$errormessage.&General::checksubnets($fwhostsettings{'HOSTNAME'},$fullip,"");
2a81ab0d
AM
296 }
297 #only check plausi when no error till now
298 if (!$errormessage){
299 &plausicheck("editnet");
300 }
2a81ab0d
AM
301 if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage)
302 {
303 $fwhostsettings{'actualize'} = '';
304 my $key = &General::findhasharraykey (\%customnetwork);
305 foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
306 $customnetwork{$key}[0] = $fwhostsettings{'orgname'} ;
307 $customnetwork{$key}[1] = $fwhostsettings{'orgip'} ;
308 $customnetwork{$key}[2] = $fwhostsettings{'orgsub'};
f80db6a4 309 $customnetwork{$key}[3] = $fwhostsettings{'orgnetremark'};
2a81ab0d
AM
310 &General::writehasharray("$confignet", \%customnetwork);
311 undef %customnetwork;
d8cc4439 312 }
2a81ab0d
AM
313 if (!$errormessage){
314 &General::readhasharray("$confignet", \%customnetwork);
315 if ($fwhostsettings{'ACTION'} eq 'updatenet'){
316 if ($fwhostsettings{'update'} == '0'){
317 foreach my $key (keys %customnetwork) {
318 if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}){
2a81ab0d
AM
319 delete $customnetwork{$key};
320 last;
321 }
322 }
323 }
324 }
325 #get count if actualize is 'on'
326 if($fwhostsettings{'actualize'} eq 'on'){
327 $fwhostsettings{'actualize'} = '';
2a81ab0d 328 #check if we need to reload rules
484269ce 329 if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){
2a81ab0d
AM
330 $needrules='on';
331 }
332 if ($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
333 #check if we need to update groups
334 &General::readhasharray("$configgrp", \%customgrp);
335 foreach my $key (sort keys %customgrp){
336 if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){
337 $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'};
338 last;
339 }
340 }
341 &General::writehasharray("$configgrp", \%customgrp);
62fc8511
AM
342 #check if we need to update firewallrules
343 if ( ! -z $fwconfigfwd ){
344 &General::readhasharray("$fwconfigfwd", \%fwfwd);
345 foreach my $line (sort keys %fwfwd){
346 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
347 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
348 }
349 if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){
350 $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'};
351 }
352 }
353 &General::writehasharray("$fwconfigfwd", \%fwfwd);
354 }
355 if ( ! -z $fwconfiginp ){
356 &General::readhasharray("$fwconfiginp", \%fwinp);
357 foreach my $line (sort keys %fwinp){
358 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
359 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
360 }
361 }
362 &General::writehasharray("$fwconfiginp", \%fwinp);
363 }
2a81ab0d 364 }
d8cc4439 365 }
2a81ab0d 366 my $key = &General::findhasharraykey (\%customnetwork);
484269ce 367 foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
2a81ab0d
AM
368 $fwhostsettings{'SUBNET'} = &General::iporsubtocidr($fwhostsettings{'SUBNET'});
369 $customnetwork{$key}[0] = $fwhostsettings{'HOSTNAME'};
370 #convert ip when leading '0' in byte
e5a058c1
AM
371 $fwhostsettings{'IP'} =&General::ip2dec($fwhostsettings{'IP'});
372 $fwhostsettings{'IP'} =&General::dec2ip($fwhostsettings{'IP'});
2a81ab0d
AM
373 $customnetwork{$key}[1] = &General::getnetworkip($fwhostsettings{'IP'},$fwhostsettings{'SUBNET'}) ;
374 $customnetwork{$key}[2] = &General::iporsubtodec($fwhostsettings{'SUBNET'}) ;
e5a058c1 375 $customnetwork{$key}[3] = $fwhostsettings{'NETREMARK'};
2a81ab0d
AM
376 &General::writehasharray("$confignet", \%customnetwork);
377 $fwhostsettings{'IP'}=$fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
378 undef %customnetwork;
379 $fwhostsettings{'HOSTNAME'}='';
380 $fwhostsettings{'IP'}='';
381 $fwhostsettings{'SUBNET'}='';
e5a058c1 382 $fwhostsettings{'NETREMARK'}='';
2a81ab0d
AM
383 #check if an edited net affected groups and need to reload rules
384 if ($needrules eq 'on'){
0e430797 385 &General::firewall_config_changed();
2a81ab0d
AM
386 }
387 &addnet;
388 &viewtablenet;
d8cc4439 389 }else{
3928f52b 390 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2a81ab0d
AM
391 &addnet;
392 &viewtablenet;
393 }
394 }
2a81ab0d
AM
395}
396if ($fwhostsettings{'ACTION'} eq 'savehost')
397{
2a81ab0d
AM
398 my $needrules=0;
399 if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
2a81ab0d 400 $fwhostsettings{'SUBNET'}='32';
2a81ab0d
AM
401 #check if all fields are set
402 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
403 {
404 $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
405 $fwhostsettings{'ACTION'} = 'edithost';
406 }else{
92e4ae9d 407 if($fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){
2a81ab0d 408 $fwhostsettings{'type'} = 'mac';
92e4ae9d 409 }elsif($fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
2a81ab0d
AM
410 $fwhostsettings{'type'} = 'ip';
411 }else{
412 $fwhostsettings{'type'} = '';
413 $errormessage=$Lang::tr{'fwhost err ipmac'};
414 }
e3580608
AM
415 #check remark
416 if ($fwhostsettings{'HOSTREMARK'} ne '' && !&validremark($fwhostsettings{'HOSTREMARK'})){
417 $errormessage=$Lang::tr{'fwhost err remark'};
418 }
2a81ab0d
AM
419 #CHECK IP-PART
420 if ($fwhostsettings{'type'} eq 'ip'){
421 #check for subnet
422 if (rindex($fwhostsettings{'IP'},'/') eq '-1' ){
423 if($fwhostsettings{'type'} eq 'ip' && !&General::validipandmask($fwhostsettings{'IP'}."/32"))
424 {
425 $errormessage.=$errormessage.$Lang::tr{'fwhost err ip'};
426 $fwhostsettings{'error'}='on';
427 }
2a81ab0d
AM
428 }elsif(rindex($fwhostsettings{'IP'},'/') ne '-1' ){
429 $errormessage=$errormessage.$Lang::tr{'fwhost err ipwithsub'};
430 $fwhostsettings{'error'}='on';
431 }
432 #check if net or broadcast
433 my @tmp= split (/\./,$fwhostsettings{'IP'});
434 if (($tmp[3] eq "0") || ($tmp[3] eq "255")){
435 $errormessage=$Lang::tr{'fwhost err hostip'};
436 }
437 }
2a81ab0d
AM
438 #only check plausi when no error till now
439 if (!$errormessage){
440 &plausicheck("edithost");
441 }
2a81ab0d
AM
442 if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){
443 $fwhostsettings{'actualize'} = '';
444 my $key = &General::findhasharraykey (\%customhost);
484269ce 445 foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";}
2a81ab0d
AM
446 $customhost{$key}[0] = $fwhostsettings{'orgname'} ;
447 $customhost{$key}[1] = $fwhostsettings{'type'} ;
448 if($customhost{$key}[1] eq 'ip'){
449 $customhost{$key}[2] = $fwhostsettings{'orgip'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
450 }else{
451 $customhost{$key}[2] = $fwhostsettings{'orgip'};
452 }
f80db6a4 453 $customhost{$key}[3] = $fwhostsettings{'orgremark'};
2a81ab0d
AM
454 &General::writehasharray("$confighost", \%customhost);
455 undef %customhost;
2a81ab0d 456 }
2a81ab0d
AM
457 if (!$errormessage){
458 #get count if host was edited
459 if($fwhostsettings{'actualize'} eq 'on'){
484269ce 460 if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){
2a81ab0d
AM
461 $needrules='on';
462 }
463 if($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
464 #check if we need to update groups
465 &General::readhasharray("$configgrp", \%customgrp);
466 foreach my $key (sort keys %customgrp){
467 if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){
468 $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'};
2a81ab0d
AM
469 }
470 }
471 &General::writehasharray("$configgrp", \%customgrp);
62fc8511
AM
472 #check if we need to update firewallrules
473 if ( ! -z $fwconfigfwd ){
474 &General::readhasharray("$fwconfigfwd", \%fwfwd);
475 foreach my $line (sort keys %fwfwd){
476 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
477 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
478 }
479 if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){
480 $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'};
481 }
482 }
483 &General::writehasharray("$fwconfigfwd", \%fwfwd);
484 }
485 if ( ! -z $fwconfiginp ){
486 &General::readhasharray("$fwconfiginp", \%fwinp);
487 foreach my $line (sort keys %fwinp){
488 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
489 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
490 }
491 }
492 &General::writehasharray("$fwconfiginp", \%fwinp);
493 }
2a81ab0d 494 }
2a81ab0d
AM
495 }
496 my $key = &General::findhasharraykey (\%customhost);
484269ce 497 foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";}
2a81ab0d
AM
498 $customhost{$key}[0] = $fwhostsettings{'HOSTNAME'} ;
499 $customhost{$key}[1] = $fwhostsettings{'type'} ;
500 if ($fwhostsettings{'type'} eq 'ip'){
501 #convert ip when leading '0' in byte
502 $fwhostsettings{'IP'}=&General::ip2dec($fwhostsettings{'IP'});
503 $fwhostsettings{'IP'}=&General::dec2ip($fwhostsettings{'IP'});
504 $customhost{$key}[2] = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
505 }else{
506 $customhost{$key}[2] = $fwhostsettings{'IP'};
507 }
e3580608 508 $customhost{$key}[3] = $fwhostsettings{'HOSTREMARK'};
2a81ab0d 509 &General::writehasharray("$confighost", \%customhost);
2a81ab0d
AM
510 undef %customhost;
511 $fwhostsettings{'HOSTNAME'}='';
512 $fwhostsettings{'IP'}='';
513 $fwhostsettings{'type'}='';
e3580608 514 $fwhostsettings{'HOSTREMARK'}='';
2a81ab0d
AM
515 #check if we need to update rules while host was edited
516 if($needrules eq 'on'){
0e430797 517 &General::firewall_config_changed();
2a81ab0d
AM
518 }
519 &addhost;
520 &viewtablehost;
521 }else{
522 &addhost;
523 &viewtablehost;
524 }
2a81ab0d 525 }
2a81ab0d
AM
526}
527if ($fwhostsettings{'ACTION'} eq 'savegrp')
528{
484269ce 529 my $grp=$fwhostsettings{'grp_name'};
2a81ab0d
AM
530 my $rem=$fwhostsettings{'remark'};
531 my $count;
532 my $type;
533 my $updcounter='off';
534 my @target;
535 my @newgrp;
536 &General::readhasharray("$configgrp", \%customgrp);
537 &General::readhasharray("$confignet", \%customnetwork);
538 &General::readhasharray("$confighost", \%customhost);
484269ce
AM
539 &General::readhasharray("$fwconfigfwd", \%fwfwd);
540 &General::readhasharray("$fwconfiginp", \%fwinp);
541 &General::readhasharray("$fwconfigout", \%fwout);
6c869961
AM
542 #check name
543 if (!&validhostname($grp)){$errormessage.=$Lang::tr{'fwhost err name'};}
f195a8d7 544 #check existing name
3a162dc1 545 if (!&checkgroup($grp) && $fwhostsettings{'update'} ne 'on'){$errormessage.=$Lang::tr{'fwhost err grpexist'};}
6c869961
AM
546 #check remark
547 if ($rem ne '' && !&validremark($rem) && $fwhostsettings{'update'} ne 'on'){
548 $errormessage.=$Lang::tr{'fwhost err remark'};
2a81ab0d 549 }
6c869961
AM
550 if ($fwhostsettings{'update'} eq 'on'){
551 #check standard networks
552 if ($fwhostsettings{'grp2'} eq 'std_net'){
553 @target=$fwhostsettings{'DEFAULT_SRC_ADR'};
554 $type='Standard Network';
555 }
556 #check custom networks
557 if ($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} ne ''){
558 @target=$fwhostsettings{'CUST_SRC_NET'};
559 $updcounter='net';
560 $type='Custom Network';
561 }elsif($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} eq ''){
562 $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>";
563 $fwhostsettings{'grp_name'}='';
564 $fwhostsettings{'remark'}='';
565 }
566 #check custom addresses
567 if ($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} ne ''){
568 @target=$fwhostsettings{'CUST_SRC_HOST'};
569 $updcounter='host';
570 $type='Custom Host';
571 }elsif($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} eq ''){
572 $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>";
573 $fwhostsettings{'grp_name'}='';
574 $fwhostsettings{'remark'}='';
575 }
576 #get address from ovpn ccd static net
577 if ($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} ne ''){
578 @target=$fwhostsettings{'OVPN_CCD_NET'};
579 $type='OpenVPN static network';
580 }elsif($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} eq ''){
581 $errormessage=$Lang::tr{'fwhost err groupempty'};
582 $fwhostsettings{'grp_name'}='';
583 $fwhostsettings{'remark'}='';
584 }
585 #get address from ovpn ccd static host
586 if ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} ne ''){
587 @target=$fwhostsettings{'OVPN_CCD_HOST'};
588 $type='OpenVPN static host';
589 }elsif ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} eq ''){
590 $errormessage=$Lang::tr{'fwhost err groupempty'};
591 }
592 #get address from ovpn ccd Net-2-Net
593 if ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} ne ''){
594 @target=$fwhostsettings{'OVPN_N2N'};
595 $type='OpenVPN N-2-N';
596 }elsif ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} eq ''){
597 $errormessage=$Lang::tr{'fwhost err groupempty'};
598 $fwhostsettings{'grp_name'}='';
599 $fwhostsettings{'remark'}='';
600 }
601 #get address from IPSEC HOST
602 if ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} ne ''){
603 @target=$fwhostsettings{'IPSEC_HOST'};
604 $type='IpSec Host';
605 }elsif ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} eq ''){
606 $errormessage=$Lang::tr{'fwhost err groupempty'};
607 $fwhostsettings{'grp_name'}='';
608 $fwhostsettings{'remark'}='';
609 }
610 #get address from IPSEC NETWORK
611 if ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} ne ''){
612 @target=$fwhostsettings{'IPSEC_NET'};
613 $type='IpSec Network';
614 }elsif ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} eq ''){
615 $errormessage=$Lang::tr{'fwhost err groupempty'};
616 $fwhostsettings{'grp_name'}='';
617 $fwhostsettings{'remark'}='';
618 }
619 #check if host/net exists in grp
620
621 my $test="$grp,$fwhostsettings{'oldremark'},@target";
622 foreach my $key (keys %customgrp) {
623 my $test1="$customgrp{$key}[0],$customgrp{$key}[1],$customgrp{$key}[2]";
624 if ($test1 eq $test){
625 $errormessage=$Lang::tr{'fwhost err isingrp'};
626 $fwhostsettings{'update'} = 'on';
627 }
2a81ab0d
AM
628 }
629 }
6c869961 630
2a81ab0d
AM
631 if (!$errormessage){
632 #on first save, we have an empty @target, so fill it with nothing
633 my $targetvalues=@target;
634 if ($targetvalues == '0'){
6c869961 635 @target="none";
2a81ab0d
AM
636 }
637 #on update, we have to delete the dummy entry
2a81ab0d 638 foreach my $key (keys %customgrp){
6c869961 639 if ($customgrp{$key}[0] eq $grp && $customgrp{$key}[2] eq "none"){
2a81ab0d
AM
640 delete $customgrp{$key};
641 last;
642 }
643 }
644 &General::writehasharray("$configgrp", \%customgrp);
645 &General::readhasharray("$configgrp", \%customgrp);
2a81ab0d
AM
646 #create array with new lines
647 foreach my $line (@target){
648 push (@newgrp,"$grp,$rem,$line");
649 }
650 #append new entries
651 my $key = &General::findhasharraykey (\%customgrp);
652 foreach my $line (@newgrp){
484269ce 653 foreach my $i (0 .. 3) { $customgrp{$key}[$i] = "";}
2a81ab0d
AM
654 my ($a,$b,$c,$d) = split (",",$line);
655 $customgrp{$key}[0] = $a;
656 $customgrp{$key}[1] = $b;
657 $customgrp{$key}[2] = $c;
658 $customgrp{$key}[3] = $type;
2a81ab0d
AM
659 }
660 &General::writehasharray("$configgrp", \%customgrp);
2a81ab0d 661 #update counter in Host/Net
2a81ab0d 662 $fwhostsettings{'update'}='on';
2a81ab0d 663 }
2a81ab0d 664 #check if ruleupdate is needed
484269ce
AM
665 my $netgrpcount=0;
666 $netgrpcount=&getnetcount($grp);
667 if($netgrpcount > 0 )
2a81ab0d 668 {
0e430797 669 &General::firewall_config_changed();
2a81ab0d
AM
670 }
671 &addgrp;
672 &viewtablegrp;
2a81ab0d
AM
673}
674if ($fwhostsettings{'ACTION'} eq 'saveservice')
675{
676 my $ICMP;
2a81ab0d 677 &General::readhasharray("$configsrv", \%customservice );
3a162dc1 678 &General::readhasharray("$configgrp", \%customgrp);
2a81ab0d 679 $errormessage=&checkports(\%customservice);
2a81ab0d
AM
680 if ($fwhostsettings{'PROT'} eq 'ICMP'){
681 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
682 foreach my $key (keys %icmptypes){
683 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){
684 $ICMP=$icmptypes{$key}[0];
685 }
686 }
687 }
86a921ee 688 if($ICMP eq ''){$ICMP=$fwhostsettings{'ICMP_TYPES'};}
3a162dc1
AM
689 if ($fwhostsettings{'PROT'} ne 'ICMP'){$ICMP='BLANK';}
690 #Check if a group with the same name already exists
691 if (!&checkgroup($fwhostsettings{'SRV_NAME'})){
692 $errormessage = $Lang::tr{'fwhost err grpexist'};
693 }
2a81ab0d 694 if (!$errormessage){
2a81ab0d
AM
695 my $key = &General::findhasharraykey (\%customservice);
696 foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";}
697 $customservice{$key}[0] = $fwhostsettings{'SRV_NAME'};
698 $customservice{$key}[1] = $fwhostsettings{'SRV_PORT'};
699 $customservice{$key}[2] = $fwhostsettings{'PROT'};
700 $customservice{$key}[3] = $ICMP;
2a81ab0d
AM
701 &General::writehasharray("$configsrv", \%customservice );
702 #reset fields
703 $fwhostsettings{'SRV_NAME'}='';
704 $fwhostsettings{'SRV_PORT'}='';
705 $fwhostsettings{'PROT'}='';
706 $fwhostsettings{'ICMP_TYPES'}='';
2a81ab0d 707 }
2a81ab0d 708 &addservice;
2a81ab0d
AM
709}
710if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
711{
712 my $prot;
713 my $port;
49192c7b
AM
714 my $tcpcounter=0;
715 my $udpcounter=0;
2a81ab0d
AM
716 &General::readhasharray("$configsrvgrp", \%customservicegrp );
717 &General::readhasharray("$configsrv", \%customservice );
2a81ab0d 718 $errormessage=&checkservicegroup;
82b837cf
AM
719 #Check if we have more than 15 services from one Protocol in the group
720 #iptables can only handle 15 ports/portranges via multiport
49192c7b
AM
721 foreach my $key (keys %customservicegrp){
722 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){
723 foreach my $key1 (keys %customservice){
724 $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0];
7db6ad6a 725 $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i;
49192c7b 726 $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0];
7db6ad6a 727 $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i;
49192c7b
AM
728 }
729 }
730 }
85abeb13 731 if ($tcpcounter > 14){
49192c7b
AM
732 $errormessage=$Lang::tr{'fwhost err maxservicetcp'};
733 }
85abeb13 734 if ($udpcounter > 14){
49192c7b
AM
735 $errormessage=$Lang::tr{'fwhost err maxserviceudp'};
736 }
737 $tcpcounter=0;
738 $udpcounter=0;
bc912c6e
AM
739 #check remark
740 if ($fwhostsettings{'SRVGRP_REMARK'} ne '' && !&validremark($fwhostsettings{'SRVGRP_REMARK'})){
49192c7b 741 $errormessage .= $Lang::tr{'fwhost err remark'};
bc912c6e 742 }
3a162dc1
AM
743 #Check if there is already a service with the same name
744 if(!&checkservice($fwhostsettings{'SRVGRP_NAME'})){
745 $errormessage .= $Lang::tr{'fwhost err srv exists'};
746 }
2a81ab0d
AM
747 if (!$errormessage){
748 #on first save, we have to enter a dummy value
6c869961
AM
749 if ($fwhostsettings{'CUST_SRV'} eq ''){
750 $fwhostsettings{'CUST_SRV'}='none';
751 }
2a81ab0d
AM
752 #on update, we have to delete the dummy entry
753 foreach my $key (keys %customservicegrp){
aeefcc9c 754 if ($customservicegrp{$key}[2] eq 'none' && $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){
2a81ab0d
AM
755 delete $customservicegrp{$key};
756 last;
757 }
758 }
759 &General::writehasharray("$configsrvgrp", \%customservicegrp );
760 #check if remark has also changed
761 if ($fwhostsettings{'SRVGRP_REMARK'} ne $fwhostsettings{'oldsrvgrpremark'} && $fwhostsettings{'updatesrvgrp'} eq 'on')
762 {
763 foreach my $key (keys %customservicegrp)
764 {
765 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvgrpremark'})
766 {
767 $customservicegrp{$key}[1]='';
768 $customservicegrp{$key}[1]=$fwhostsettings{'SRVGRP_REMARK'};
3a162dc1 769 }
2a81ab0d
AM
770 }
771 }
2a81ab0d 772 my $key = &General::findhasharraykey (\%customservicegrp);
3a162dc1 773 foreach my $i (0 .. 2) { $customservice{$key}[$i] = "";}
2a81ab0d
AM
774 $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'};
775 $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'};
776 $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'};
2a81ab0d
AM
777 &General::writehasharray("$configsrvgrp", \%customservicegrp );
778 $fwhostsettings{'updatesrvgrp'}='on';
779 }
49da7d79 780 &checkrulereload($fwhostsettings{'SRVGRP_NAME'});
2a81ab0d
AM
781 &addservicegrp;
782 &viewtableservicegrp;
783}
784# edit
785if ($fwhostsettings{'ACTION'} eq 'editnet')
786{
787 &addnet;
788 &viewtablenet;
789}
790if ($fwhostsettings{'ACTION'} eq 'edithost')
791{
792 &addhost;
793 &viewtablehost;
794}
795if ($fwhostsettings{'ACTION'} eq 'editgrp')
796{
797 $fwhostsettings{'update'}='on';
798 &addgrp;
799 &viewtablegrp;
800}
801if ($fwhostsettings{'ACTION'} eq 'editservice')
802{
803 $fwhostsettings{'updatesrv'}='on';
804 &addservice;
805}
806if ($fwhostsettings{'ACTION'} eq 'editservicegrp')
807{
808 $fwhostsettings{'updatesrvgrp'} = 'on';
809 &addservicegrp;
810 &viewtableservicegrp;
811}
812# reset
813if ($fwhostsettings{'ACTION'} eq 'resetnet')
814{
815 $fwhostsettings{'HOSTNAME'} ="";
816 $fwhostsettings{'IP'} ="";
817 $fwhostsettings{'SUBNET'} ="";
818 &showmenu;
819}
820if ($fwhostsettings{'ACTION'} eq 'resethost')
821{
822 $fwhostsettings{'HOSTNAME'} ="";
823 $fwhostsettings{'IP'} ="";
824 $fwhostsettings{'type'} ="";
825 &showmenu;
826}
43215686
AM
827if ($fwhostsettings{'ACTION'} eq 'resetgrp')
828{
829 $fwhostsettings{'grp_name'} ="";
830 $fwhostsettings{'remark'} ="";
831 &showmenu;
832}
2a81ab0d
AM
833# delete
834if ($fwhostsettings{'ACTION'} eq 'delnet')
835{
836 &General::readhasharray("$confignet", \%customnetwork);
837 foreach my $key (keys %customnetwork) {
838 if($fwhostsettings{'key'} eq $customnetwork{$key}[0]){
839 delete $customnetwork{$key};
840 &General::writehasharray("$confignet", \%customnetwork);
841 last;
842 }
843 }
844 &addnet;
845 &viewtablenet;
846}
847if ($fwhostsettings{'ACTION'} eq 'delhost')
848{
849 &General::readhasharray("$confighost", \%customhost);
850 foreach my $key (keys %customhost) {
851 if($fwhostsettings{'key'} eq $customhost{$key}[0]){
852 delete $customhost{$key};
853 &General::writehasharray("$confighost", \%customhost);
854 last;
855 }
856 }
857 &addhost;
858 &viewtablehost;
2a81ab0d
AM
859}
860if ($fwhostsettings{'ACTION'} eq 'deletegrphost')
861{
3f8fe51e
AM
862 my $grpremark;
863 my $grpname;
2a81ab0d
AM
864 &General::readhasharray("$configgrp", \%customgrp);
865 foreach my $key (keys %customgrp){
866 if($customgrp{$key}[0].",".$customgrp{$key}[1].",".$customgrp{$key}[2].",".$customgrp{$key}[3] eq $fwhostsettings{'delhost'}){
3f8fe51e
AM
867 $grpname=$customgrp{$key}[0];
868 $grpremark=$customgrp{$key}[1];
aeefcc9c
AM
869 #check if we delete the last entry, then generate dummy
870 if ($fwhostsettings{'last'} eq 'on'){
871 $customgrp{$key}[1] = '';
872 $customgrp{$key}[2] = 'none';
873 $customgrp{$key}[3] = '';
874 $fwhostsettings{'last'}='';
875 last;
876 }else{
877 delete $customgrp{$key};
878 }
2a81ab0d
AM
879 }
880 }
881 &General::writehasharray("$configgrp", \%customgrp);
aeefcc9c 882 &General::firewall_config_changed();
3f8fe51e
AM
883 if ($fwhostsettings{'update'} eq 'on'){
884 $fwhostsettings{'remark'}= $grpremark;
885 $fwhostsettings{'grp_name'}=$grpname;
886 }
2a81ab0d
AM
887 &addgrp;
888 &viewtablegrp;
889}
890if ($fwhostsettings{'ACTION'} eq 'delgrp')
891{
892 &General::readhasharray("$configgrp", \%customgrp);
893 &decrease($fwhostsettings{'grp_name'});
894 foreach my $key (sort keys %customgrp)
895 {
896 if($customgrp{$key}[0] eq $fwhostsettings{'grp_name'})
897 {
898 delete $customgrp{$key};
899 }
900 }
901 &General::writehasharray("$configgrp", \%customgrp);
902 $fwhostsettings{'grp_name'}='';
903 &addgrp;
904 &viewtablegrp;
905}
906if ($fwhostsettings{'ACTION'} eq 'delservice')
907{
908 &General::readhasharray("$configsrv", \%customservice);
909 foreach my $key (keys %customservice) {
910 if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
2a81ab0d
AM
911 delete $customservice{$key};
912 &General::writehasharray("$configsrv", \%customservice);
913 last;
914 }
915 }
916 $fwhostsettings{'SRV_NAME'}='';
917 $fwhostsettings{'SRV_PORT'}='';
918 $fwhostsettings{'PROT'}='';
919 &addservice;
920}
921if ($fwhostsettings{'ACTION'} eq 'delservicegrp')
922{
923 &General::readhasharray("$configsrvgrp", \%customservicegrp);
924 &decreaseservice($fwhostsettings{'SRVGRP_NAME'});
925 foreach my $key (sort keys %customservicegrp)
926 {
927 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
928 {
929 delete $customservicegrp{$key};
930 }
931 }
932 &General::writehasharray("$configsrvgrp", \%customservicegrp);
933 $fwhostsettings{'SRVGRP_NAME'}='';
934 &addservicegrp;
935 &viewtableservicegrp;
936}
937if ($fwhostsettings{'ACTION'} eq 'delgrpservice')
938{
3f8fe51e
AM
939 my $grpname;
940 my $grpremark;
2a81ab0d 941 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2a81ab0d 942 foreach my $key (keys %customservicegrp){
3a162dc1 943 if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2] eq $fwhostsettings{'delsrvfromgrp'})
2a81ab0d 944 {
3f8fe51e
AM
945 $grpname=$customservicegrp{$key}[0];
946 $grpremark=$customservicegrp{$key}[1];
aeefcc9c
AM
947 if($fwhostsettings{'last'} eq 'on'){
948 $customservicegrp{$key}[2] = 'none';
949 $fwhostsettings{'last'} = '';
950 last;
951 }else{
952 delete $customservicegrp{$key};
953 }
2a81ab0d
AM
954 }
955 }
956 &General::writehasharray("$configsrvgrp", \%customservicegrp);
0e430797 957 &General::firewall_config_changed();
3f8fe51e 958 if ($fwhostsettings{'updatesrvgrp'} eq 'on'){
3f8fe51e
AM
959 $fwhostsettings{'SRVGRP_NAME'}=$grpname;
960 $fwhostsettings{'SRVGRP_REMARK'}=$grpremark;
961 }
2a81ab0d
AM
962 &addservicegrp;
963 &viewtableservicegrp;
2a81ab0d
AM
964}
965if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'})
966{
967 &addnet;
968 &viewtablenet;
969}
970if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newhost'})
971{
972 &addhost;
973 &viewtablehost;
974}
975if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgrp'})
976{
977 &addgrp;
978 &viewtablegrp;
979}
980if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservice'})
981{
982 &addservice;
983}
984if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservicegrp'})
985{
986 &addservicegrp;
987 &viewtableservicegrp;
988}
6c869961
AM
989if ($fwhostsettings{'ACTION'} eq 'changegrpremark')
990{
991 &General::readhasharray("$configgrp", \%customgrp);
d0815ce4 992 if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){
6c869961
AM
993 foreach my $key (sort keys %customgrp)
994 {
6c869961
AM
995 if($customgrp{$key}[0] eq $fwhostsettings{'grp'} && $customgrp{$key}[1] eq $fwhostsettings{'oldrem'})
996 {
6c869961
AM
997 $customgrp{$key}[1]='';
998 $customgrp{$key}[1]=$fwhostsettings{'newrem'};
999 }
1000 }
1001 &General::writehasharray("$configgrp", \%customgrp);
1002 $fwhostsettings{'update'}='on';
6c869961
AM
1003 $fwhostsettings{'remark'}=$fwhostsettings{'newrem'};
1004 }else{
1005 $errormessage=$Lang::tr{'fwhost err remark'};
1006 $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'};
1007 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1008 $fwhostsettings{'update'} = 'on';
1009 }
1010 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1011 &addgrp;
1012 &viewtablegrp;
1013}
1014if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark')
1015{
1016 &General::readhasharray("$configsrvgrp", \%customservicegrp );
d0815ce4 1017 if ($fwhostsettings{'oldsrvrem'} ne $fwhostsettings{'newsrvrem'} && (&validremark($fwhostsettings{'newsrvrem'}) || $fwhostsettings{'newsrvrem'} eq '')){
6c869961
AM
1018 foreach my $key (sort keys %customservicegrp)
1019 {
6c869961
AM
1020 if($customservicegrp{$key}[0] eq $fwhostsettings{'srvgrp'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvrem'})
1021 {
6c869961
AM
1022 $customservicegrp{$key}[1]='';
1023 $customservicegrp{$key}[1]=$fwhostsettings{'newsrvrem'};
1024 }
1025 }
1026 &General::writehasharray("$configsrvgrp", \%customservicegrp);
1027 $fwhostsettings{'updatesrvgrp'}='on';
6c869961 1028 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'newsrvrem'};
82b837cf
AM
1029 }elsif($fwhostsettings{'oldsrvrem'} eq $fwhostsettings{'newsrvrem'}){
1030 &addservicegrp;
1031 &viewtableservicegrp;
6c869961
AM
1032 }else{
1033 $errormessage=$Lang::tr{'fwhost err remark'};
1034 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'oldsrvrem'};
1035 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1036 $fwhostsettings{'updatesrvgrp'} = 'on';
1037 }
1038 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1039 &addservicegrp;
1040 &viewtableservicegrp;
1041}
a8b113e7
AM
1042if ($fwhostsettings{'ACTION'} eq 'changesrvgrpname')
1043{
1044 &General::readhasharray("$configsrvgrp", \%customservicegrp );
1045 if ($fwhostsettings{'oldsrvgrpname'} ne $fwhostsettings{'srvgrp'}){
1046 #Check new groupname
1047 if (!&validhostname($fwhostsettings{'srvgrp'})){
1048 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1049 }
1050 if (!$errormessage){
1051 #Rename group in customservicegroup
1052 foreach my $key (keys %customservicegrp) {
1053 if($customservicegrp{$key}[0] eq $fwhostsettings{'oldsrvgrpname'}){
1054 $customservicegrp{$key}[0]=$fwhostsettings{'srvgrp'};
1055 }
1056 }
1057 &General::writehasharray("$configsrvgrp", \%customservicegrp );
1058 #change name in FW Rules
1059 &changenameinfw($fwhostsettings{'oldsrvgrpname'},$fwhostsettings{'srvgrp'},15);
1060 }
1061 }
1062 &addservicegrp;
1063 &viewtableservicegrp;
1064}
1065if ($fwhostsettings{'ACTION'} eq 'changegrpname')
1066{
1067 &General::readhasharray("$configgrp", \%customgrp );
1068 if ($fwhostsettings{'oldgrpname'} ne $fwhostsettings{'grp'}){
1069 #Check new groupname
1070 if (!&validhostname($fwhostsettings{'grp'})){
1071 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1072 }
1073 if (!$errormessage){
1074 #Rename group in customservicegroup
1075 foreach my $key (keys %customgrp) {
1076 if($customgrp{$key}[0] eq $fwhostsettings{'oldgrpname'}){
1077 $customgrp{$key}[0]=$fwhostsettings{'grp'};
1078 }
1079 }
1080 &General::writehasharray("$configgrp", \%customgrp );
1081 #change name in FW Rules
1082 &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},6);
1083 }
1084 }
1085 &addgrp;
1086 &viewtablegrp;
1087}
2a81ab0d
AM
1088### VIEW ###
1089if($fwhostsettings{'ACTION'} eq '')
1090{
1091 &showmenu;
1092}
1093### FUNCTIONS ###
0e430797 1094sub showmenu {
4d74a20d 1095 &Header::openbox('100%', 'left',);
43d8be09 1096 print "$Lang::tr{'fwhost welcome'}";
2a81ab0d 1097 print<<END;
2e99ab8b
AM
1098 <br><br><table border='0' width='100%'>
1099 <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>
1100 <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>
bc8ecbd6 1101 <tr><td colspan='6'></td></tr></table>
2a81ab0d 1102END
2a81ab0d
AM
1103 &Header::closebox();
1104
1105}
1106# Add
1107sub addnet
1108{
1109 &error;
1110 &showmenu;
1111 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addnet'});
1112 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
f80db6a4 1113 $fwhostsettings{'orgnetremark'}=$fwhostsettings{'NETREMARK'};
2a81ab0d 1114 print<<END;
902a15be 1115 <table border='0' width='100%' >
2e99ab8b 1116 <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
1117 <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>
1118 <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 1119 <tr><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='NETREMARK' value='$fwhostsettings{'NETREMARK'}' style='width: 98.5%;'></td></tr>
bc8ecbd6 1120 <tr><td colspan='6'><br></td></tr><tr>
2a81ab0d
AM
1121END
1122 if ($fwhostsettings{'ACTION'} eq 'editnet' || $fwhostsettings{'error'} eq 'on')
1123 {
902a15be 1124 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'}'>";
2a81ab0d 1125 }else{
902a15be
AM
1126 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'>";
1127 }
2e99ab8b 1128 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
1129 &Header::closebox();
1130}
1131sub addhost
1132{
1133 &error;
1134 &showmenu;
1135 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addhost'});
1136 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
f80db6a4 1137 $fwhostsettings{'orgremark'}=$fwhostsettings{'HOSTREMARK'};
2a81ab0d 1138 print<<END;
bc8ecbd6 1139 <table width='100%'>
2e99ab8b 1140 <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 1141 <tr><td>IP/MAC:</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='17'></td></tr>
8013bd0a 1142 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='HOSTREMARK' value='$fwhostsettings{'HOSTREMARK'}' style='width:98%;'></td></tr>
bc8ecbd6 1143 <tr><td colspan='5'><br></td></tr><tr>
2a81ab0d
AM
1144END
1145
1146 if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on')
1147 {
1148
8013bd0a 1149 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 1150 }else{
2e99ab8b 1151 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 1152 }
2e99ab8b 1153 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
1154 &Header::closebox();
1155}
1156sub addgrp
1157{
1158 &hint;
1159 &error;
1160 &showmenu;
1161 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addgrp'});
1162 &General::setup_default_networks(\%defaultNetworks);
8013bd0a
AM
1163 &General::readhasharray("$configccdnet", \%ccdnet);
1164 &General::readhasharray("$confignet", \%customnetwork);
1165 &General::readhasharray("$configccdhost", \%ccdhost);
1166 &General::readhasharray("$confighost", \%customhost);
1167 &General::readhasharray("$configipsec", \%ipsecconf);
1168
2a81ab0d 1169 my %checked=();
8013bd0a 1170 my $show='';
2a81ab0d
AM
1171 $checked{'check1'}{'off'} = '';
1172 $checked{'check1'}{'on'} = '';
1173 $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED';
1174 $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'};
a8b113e7 1175 $fwhostsettings{'oldgrpname'}=$fwhostsettings{'grp_name'};
6c869961
AM
1176 my $grp=$fwhostsettings{'grp_name'};
1177 my $rem=$fwhostsettings{'remark'};
2a81ab0d
AM
1178 if ($fwhostsettings{'update'} eq ''){
1179 print<<END;
bc8ecbd6
AM
1180 <table width='100%' border='0'>
1181 <tr>
7429ee78
AM
1182 <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td>
1183 <td><form method='post'><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' size='30'></td>
bc8ecbd6
AM
1184 </tr>
1185 <tr>
f620fa34 1186 <td>$Lang::tr{'remark'}:</td>
7429ee78 1187 <td ><input type='TEXT' name='remark' value='$fwhostsettings{'remark'}' style='width: 99%;'></td>
bc8ecbd6
AM
1188 </tr>
1189 <tr>
1190 <td colspan='2'><br></td>
1191 </tr>
1192 </table>
2a81ab0d
AM
1193END
1194 }else{
1195 print<<END;
7429ee78 1196 <table width='100%' border='0'><form method='post'>
bc8ecbd6 1197 <tr>
7429ee78
AM
1198 <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td>
1199 <td style='width:30%;'><input type='TEXT' name='grp' value='$fwhostsettings{'grp_name'}' size='30'></td>
bc8ecbd6
AM
1200 <td><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldgrpname' value='$fwhostsettings{'oldgrpname'}'><input type='hidden' name='ACTION' value='changegrpname'></td>
1201 <td></td></form>
1202 </tr>
1203 <tr><form method='post' style='display:inline'>
1204 <td>$Lang::tr{'remark'}:</td>
7429ee78 1205 <td colspan='2' style='width:98%;'><input type='TEXT' name='newrem' value='$fwhostsettings{'remark'}' style='width:98%;'></td>
a72ae687 1206 <td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='grp' value='$fwhostsettings{'grp_name'}'><input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='ACTION' value='changegrpremark' ></td>
bc8ecbd6
AM
1207 </tr>
1208 </table></form>
1209 <br><br>
2a81ab0d 1210END
2a81ab0d
AM
1211 }
1212 if ($fwhostsettings{'update'} eq 'on'){
2a81ab0d 1213 print<<END;
8013bd0a
AM
1214 <form method='post'><input type='hidden' name='remark' value='$rem'><input type='hidden' name='grp_name' value='$grp'>
1215 <table width='100%' border='0'>
1216 <tr><td width=50% valign='top'>
f620fa34
AM
1217 <table width='90%' border='0'>
1218 <tr>
1219 <td style='width:15em;'>
1220 <label>
1221 <input type='radio' name='grp2' value='std_net' id='DEFAULT_SRC_ADR' checked>
1222 $Lang::tr{'fwhost stdnet'}
1223 </label>
1224 </td>
1225 <td style='text-align:right;'>
a72ae687 1226 <select name='DEFAULT_SRC_ADR' style='width:16em;'>
2a81ab0d
AM
1227END
1228 foreach my $network (sort keys %defaultNetworks)
1229 {
1230 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
7326051e 1231 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
2a81ab0d
AM
1232 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1233 print " selected='selected'" if ($fwhostsettings{'DEFAULT_SRC_ADR'} eq $defaultNetworks{$network}{'NAME'});
7326051e
AM
1234 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
1235 my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK";
1236 my $defsub1=&General::subtocidr($ownnet{$defsub});
1237 $ownnet{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED');
1238 if ($ownnet{$defnet}){
1239 print ">$network ($ownnet{$defnet}/$defsub1)</option>";
1240 }else{
1241 print ">$network</option>";
1242 }
2a81ab0d 1243 }
8013bd0a
AM
1244 print"</select></td></tr>";
1245 if (! -z $confignet){
f620fa34
AM
1246 print<<END;
1247 <tr>
1248 <td>
1249 <label>
1250 <input type='radio' name='grp2' id='CUST_SRC_NET' value='cust_net' $checked{'grp2'}{'cust_net'}>
1251 $Lang::tr{'fwhost cust net'}:
1252 </label>
1253 </td>
1254 <td style='text-align:right;'>
a72ae687 1255 <select name='CUST_SRC_NET' style='width:16em;'>";
f620fa34 1256END
eff2dbf8 1257 foreach my $key (sort { ncmp($customnetwork{$a}[0],$customnetwork{$b}[0]) } keys %customnetwork) {
8013bd0a
AM
1258 print"<option>$customnetwork{$key}[0]</option>";
1259 }
1260 print"</select></td></tr>";
2a81ab0d 1261 }
8013bd0a 1262 if (! -z $confighost){
f620fa34
AM
1263 print<<END;
1264 <tr>
1265 <td valign='top'>
1266 <label>
1267 <input type='radio' name='grp2' id='CUST_SRC_HOST' value='cust_host' $checked{'grp2'}{'cust_host'}>
1268 $Lang::tr{'fwhost cust addr'}:
1269 </label>
1270 </td>
1271 <td style='text-align:right;'>
a72ae687 1272 <select name='CUST_SRC_HOST' style='width:16em;'>";
f620fa34 1273END
eff2dbf8 1274 foreach my $key (sort { ncmp($customhost{$a}[0],$customhost{$b}[0]) } keys %customhost) {
8013bd0a
AM
1275 print"<option>$customhost{$key}[0]</option>";
1276 }
1277 print"</select></td></tr>";
1278 }
1279 print"</table>";
1280 #Inner table right
f620fa34 1281 print"</td><td align='right' style='vertical-align:top;'><table width='90%' border='0'>";
8013bd0a
AM
1282 #OVPN networks
1283 if (! -z $configccdnet){
f620fa34
AM
1284 print<<END;
1285 <td style='width:15em;'>
1286 <label>
1287 <input type='radio' name='grp2' id='OVPN_CCD_NET' value='ovpn_net' $checked{'grp2'}{'ovpn_net'}>
1288 $Lang::tr{'fwhost ccdnet'}
1289 </label>
1290 </td>
1291 <td style='text-align:right;'>
a72ae687 1292 <select name='OVPN_CCD_NET' style='width:16em;'>";
f620fa34 1293END
eff2dbf8 1294 foreach my $key (sort { ncmp($ccdnet{$a}[0],$ccdnet{$b}[0]) } keys %ccdnet)
8013bd0a
AM
1295 {
1296 print"<option value='$ccdnet{$key}[0]'>$ccdnet{$key}[0]</option>";
1297 }
1298 print"</select></td></tr>";
2a81ab0d 1299 }
8013bd0a 1300 #OVPN clients
a72ae687 1301 my @ovpn_clients=();
eff2dbf8 1302 foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost)
2a81ab0d
AM
1303 {
1304 if ($ccdhost{$key}[33] ne ''){
a72ae687
AM
1305 $show='1';
1306 push (@ovpn_clients,$ccdhost{$key}[1]);
1307 }
1308 }
1309 if ($show eq '1'){
1310 $show='';
1311 print<<END;
f620fa34
AM
1312 <td style='width:15em;'>
1313 <label>
1314 <input type='radio' name='grp2' value='ovpn_host' $checked{'grp2'}{'ovpn_host'}>
1315 $Lang::tr{'fwhost ccdhost'}
1316 </label>
1317 </td>
1318 <td style='text-align:right;'>
a72ae687 1319 <select name='OVPN_CCD_HOST' style='width:16em;'>" if ($show eq '');
f620fa34 1320END
a72ae687
AM
1321 foreach(@ovpn_clients){
1322 print"<option value='$_'>$_</option>";
2a81ab0d 1323 }
a72ae687 1324 print"</select></td></tr>";
2a81ab0d 1325 }
8013bd0a 1326 #OVPN n2n networks
a72ae687 1327 my @OVPN_N2N=();
eff2dbf8 1328 foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost) {
2a81ab0d 1329 if($ccdhost{$key}[3] eq 'net'){
a72ae687
AM
1330 $show='1';
1331 push (@OVPN_N2N,$ccdhost{$key}[1]);
1332 }
1333 }
1334 if ($show eq '1'){
1335 $show='';
1336 print<<END;
f620fa34
AM
1337 <td style='width:15em;'>
1338 <label>
1339 <input type='radio' name='grp2' id='OVPN_N2N' value='ovpn_n2n' $checked{'grp2'}{'ovpn_n2n'}>
1340 $Lang::tr{'fwhost ovpn_n2n'}:
1341 </label>
1342 </td>
1343 <td style='text-align:right;'>
a72ae687 1344 <select name='OVPN_N2N' style='width:16em;'>"
f620fa34 1345END
a72ae687
AM
1346 foreach(@OVPN_N2N){
1347 print"<option>$_</option>";
2a81ab0d 1348 }
a72ae687 1349 print"</select></td></tr>";
2a81ab0d 1350 }
8013bd0a 1351 #IPsec networks
a72ae687 1352 my @IPSEC_N2N=();
eff2dbf8 1353 foreach my $key (sort { ncmp($ipsecconf{$a}[0],$ipsecconf{$b}[0]) } keys %ipsecconf) {
2a81ab0d 1354 if ($ipsecconf{$key}[3] eq 'net'){
a72ae687
AM
1355 $show='1';
1356 push (@IPSEC_N2N,$ipsecconf{$key}[1]);
1357 }
1358 }
1359 if ($show eq '1'){
1360 $show='';
1361 print<<END;
f620fa34
AM
1362 <td style='width:15em;'>
1363 <label>
1364 <input type='radio' name='grp2' id='IPSEC_NET' value='ipsec_net' $checked{'grp2'}{'ipsec_net'}>
1365 $Lang::tr{'fwhost ipsec net'}
1366 </label>
1367 </td>
1368 <td style='text-align:right;'>
a72ae687 1369 <select name='IPSEC_NET' style='width:16em;'>"
f620fa34 1370END
a72ae687
AM
1371 foreach(@IPSEC_N2N){
1372 print"<option value='$_'>$_</option>";
2a81ab0d
AM
1373 }
1374 }
a72ae687 1375 print"</select></td></tr>";
8013bd0a
AM
1376 print"</table>";
1377 print"</td></tr></table>";
bc8ecbd6 1378 print"<br><br>";
2a81ab0d 1379 }
bc8ecbd6 1380 print"<table width='100%'>";
f620fa34 1381 print"<tr><td style='text-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
1382 &Header::closebox();
1383}
1384sub addservice
1385{
1386 &error;
1387 &showmenu;
1a8fde0e 1388 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservice'});
2a81ab0d
AM
1389 if ($fwhostsettings{'updatesrv'} eq 'on')
1390 {
1391 $fwhostsettings{'oldsrvname'} = $fwhostsettings{'SRV_NAME'};
1392 $fwhostsettings{'oldsrvport'} = $fwhostsettings{'SRV_PORT'};
1393 $fwhostsettings{'oldsrvprot'} = $fwhostsettings{'PROT'};
2aeb4b25 1394 $fwhostsettings{'oldsrvicmp'} = $fwhostsettings{'ICMP'};
2a81ab0d
AM
1395 }
1396 print<<END;
fda8c915 1397 <table width='100%' border='0'><form method='post'>
1a8fde0e 1398 <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 1399 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT' id='protocol' >
2a81ab0d
AM
1400END
1401 foreach ("TCP","UDP","ICMP")
1402 {
1403 if ($_ eq $fwhostsettings{'PROT'})
1404 {
1405 print"<option selected>$_</option>";
1406 }else{
1407 print"<option>$_</option>";
1408 }
1409 }
1410 print<<END;
fda8c915 1411 </select></td></tr></table>
bfc84eb1 1412 <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
1413END
1414 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
86a921ee 1415 print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>";
eff2dbf8 1416 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
2aeb4b25
AM
1417 if ($icmptypes{$key}[0] eq $fwhostsettings{'oldsrvicmp'}){
1418 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1419 }else{
1420 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1421 }
2a81ab0d 1422 }
2a81ab0d 1423 print<<END;
bfc84eb1
AM
1424 </select></td></tr></table></div>
1425 <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>
bc8ecbd6 1426 <table width='100%' border='0'><tr><td colspan='6'><br></td></tr>
2a81ab0d
AM
1427 <tr><td colspan='6' align='right'>
1428END
1429 if ($fwhostsettings{'updatesrv'} eq 'on')
1430 {
1431 print<<END;
7f5b2820 1432 <input type='submit' value='$Lang::tr{'update'}'style='min-width:100px;' >
2a81ab0d
AM
1433 <input type='hidden' name='ACTION' value='updateservice'>
1434 <input type='hidden' name='oldsrvname' value='$fwhostsettings{'oldsrvname'}'>
1435 <input type='hidden' name='oldsrvport' value='$fwhostsettings{'oldsrvport'}'>
2aeb4b25
AM
1436 <input type='hidden' name='oldsrvprot' value='$fwhostsettings{'oldsrvprot'}'>
1437 <input type='hidden' name='oldsrvicmp' value='$fwhostsettings{'oldsrvicmp'}'>
1438 </form>
2a81ab0d 1439END
fda8c915 1440 }else{
7f5b2820 1441 print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>";
2a81ab0d
AM
1442 }
1443 print<<END;
7f5b2820 1444 <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr>
2a81ab0d 1445 </table></form>
2a81ab0d
AM
1446END
1447 &Header::closebox();
1448 &viewtableservice;
1449}
1450sub addservicegrp
1451{
1452 &hint;
1453 &error;
1454 &showmenu;
1a8fde0e 1455 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservicegrp'});
2a81ab0d 1456 $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'};
a8b113e7 1457 $fwhostsettings{'oldsrvgrpname'}=$fwhostsettings{'SRVGRP_NAME'};
2a81ab0d
AM
1458 if ($fwhostsettings{'updatesrvgrp'} eq ''){
1459 print<<END;
1460 <table width='100%' border='0'><form method='post'>
1a8fde0e 1461 <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 1462 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='text' name='SRVGRP_REMARK' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width: 98%;'></td></tr>
bc8ecbd6 1463 <tr><td colspan='2'><br></tr>
2a81ab0d
AM
1464 </table>
1465END
1466 }else{
1467 print<<END;
bc8ecbd6 1468 <table width='100%'><form method='post' style='display:inline'>
a8b113e7 1469 <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td width='20%'><input type='text' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}' size='14'></td><td align='left'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldsrvgrpname' value='$fwhostsettings{'oldsrvgrpname'}'><input type='hidden' name='ACTION' value='changesrvgrpname'></td><td width='3%'></td></form></tr>
a72ae687
AM
1470 <tr>
1471 <form method='post'>
1472 <td width='10%'>
1473 $Lang::tr{'remark'}:
1474 </td>
1475 <td colspan='2'>
1476 <input type='text' name='newsrvrem' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width:98%;'>
1477 </td>
1478 <td align='right'>
1479 <input type='submit' value='$Lang::tr{'fwhost change'}'>
1480 <input type='hidden' name='oldsrvrem' value='$fwhostsettings{'oldsrvgrpremark'}'>
1481 <input type='hidden' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}'>
1482 <input type='hidden' name='ACTION' value='changesrvgrpremark' >
1483 </td>
1484 </tr>
1485 <tr>
1486 <td colspan='4'>
1487 <br>
1488 </td>
1489 </tr>
1490 </table>
1491 </form>
2a81ab0d
AM
1492END
1493 }
1494 if($fwhostsettings{'updatesrvgrp'} eq 'on'){
2a81ab0d 1495 print<<END;
6c869961 1496 <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%'>
bc8ecbd6 1497 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'add'}: </td><td><select name='CUST_SRV' style='min-width:185px;'>
2a81ab0d
AM
1498END
1499 &General::readhasharray("$configsrv", \%customservice);
82b837cf
AM
1500 #Protocols for use in servicegroups
1501 print "<optgroup label='$Lang::tr{'fwhost cust service'}'>";
eff2dbf8 1502 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice)
2a81ab0d
AM
1503 {
1504 print "<option>$customservice{$key}[0]</option>";
1505 }
82b837cf
AM
1506 print "</optgroup>";
1507 print "<optgroup label='$Lang::tr{'protocol'}'>";
1508 print "<option>GRE</option>";
1509 print "<option>AH</option>";
1510 print "<option>ESP</option>";
1511 print "<option>IGMP</option>";
1512 print "<option>IPIP</option>";
1513 print "<option value='IPV6'>IPv6 encap</option>";
1514 print "</optgroup>";
2a81ab0d
AM
1515 print<<END;
1516 </select></td></tr>
5dd84c25 1517 <tr><td colspan='4'><br><br></td></tr>
bc8ecbd6 1518 <tr><td colspan='4'></td></tr>
2a81ab0d
AM
1519 </table>
1520END
1521 }
1522 print<<END;
bc8ecbd6 1523 <table width='100%'>
7f5b2820 1524 <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
1525 </table></form>
1526END
2a81ab0d
AM
1527 &Header::closebox();
1528}
1529# View
1530sub viewtablenet
1531{
1532 if(! -z $confignet){
1533 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'});
1534 &General::readhasharray("$confignet", \%customnetwork);
484269ce
AM
1535 &General::readhasharray("$configgrp", \%customgrp);
1536 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1537 &General::readhasharray("$fwconfiginp", \%fwinp);
1538 &General::readhasharray("$fwconfigout", \%fwout);
f620fa34 1539
2a81ab0d
AM
1540 if (!keys %customnetwork)
1541 {
1542 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1543 }else{
1544 print<<END;
902a15be
AM
1545 <table width='100%' cellspacing='0' class='tbl'>
1546 <tr><th align='center'><b>$Lang::tr{'name'}</b></th><th align='center'><b>$Lang::tr{'fwhost netaddress'}</b></th><th align='center'><b>$Lang::tr{'remark'}</b></th><th align='center'><b>$Lang::tr{'used'}</b></th><th></th><th width='3%'></th></tr>
2a81ab0d
AM
1547END
1548 }
1549 my $count=0;
902a15be 1550 my $col='';
eff2dbf8 1551 foreach my $key (sort {ncmp($a,$b)} keys %customnetwork) {
2a81ab0d 1552 if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) {
902a15be
AM
1553 print" <tr>";
1554 $col="bgcolor='${Header::colouryellow}'";
2a81ab0d
AM
1555 }elsif ($count % 2)
1556 {
902a15be 1557 $col="bgcolor='$color{'color20'}'";
aeefcc9c 1558 print" <tr>";
2a81ab0d
AM
1559 }else
1560 {
902a15be 1561 $col="bgcolor='$color{'color22'}'";
aeefcc9c 1562 print" <tr>";
2a81ab0d 1563 }
72586f0f 1564 my $colnet="$customnetwork{$key}[1]/".&General::subtocidr($customnetwork{$key}[2]);
484269ce 1565 my $netcount=&getnetcount($customnetwork{$key}[0]);
f620fa34 1566 print"<td width='20%' $col><form method='post'>$customnetwork{$key}[0]</td><td width='15%' align='center' $col>".&getcolor($colnet)."</td><td width='40%' $col>$customnetwork{$key}[3]</td><td align='center' $col>$netcount x</td>";
2a81ab0d 1567 print<<END;
f8aa0679 1568 <td width='1%' $col><input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
2a81ab0d
AM
1569 <input type='hidden' name='ACTION' value='editnet'>
1570 <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' />
1571 <input type='hidden' name='IP' value='$customnetwork{$key}[1]' />
1572 <input type='hidden' name='SUBNET' value='$customnetwork{$key}[2]' />
e5a058c1 1573 <input type='hidden' name='NETREMARK' value='$customnetwork{$key}[3]' />
2a81ab0d
AM
1574 </td></form>
1575END
484269ce 1576 if($netcount == '0')
2a81ab0d 1577 {
f8aa0679 1578 print"<td width='1%' $col><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>";
2a81ab0d 1579 }else{
902a15be 1580 print"<td $col></td></tr>";
2a81ab0d
AM
1581 }
1582 $count++;
1583 }
1584 print"</table>";
1585 &Header::closebox();
1586 }
1587
1588}
b119578f
AM
1589sub getcolor
1590{
1591 my $c=shift;
f620fa34
AM
1592 my $sip;
1593 my $scidr;
1ccfb89e 1594 my $tdcolor='';
f620fa34
AM
1595 #Check if MAC
1596 if (&General::validmac($c)){ return $c;}
1597
1598 #Check if we got a full IP with subnet then split it
1599 if($c =~ /^(.*?)\/(.*?)$/){
1600 ($sip,$scidr) = split ("/",$c);
1601 }else{
1602 $sip=$c;
1603 }
1604
1605 #Now check if IP is part of ORANGE,BLUE or GREEN
7fa1b16e 1606 if ( &Header::orange_used() && &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
f620fa34
AM
1607 $tdcolor="<font style='color: $Header::colourorange;'>$c</font>";
1608 return $tdcolor;
1609 }
1610 if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1611 $tdcolor="<font style='color: $Header::colourgreen;'>$c</font>";
1612 return $tdcolor;
1613 }
7fa1b16e 1614 if ( &Header::blue_used() && &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
f620fa34
AM
1615 $tdcolor="<font style='color: $Header::colourblue;'>$c</font>";
1616 return $tdcolor;
1617 }
48f07c19
AM
1618 if ("$sip/$scidr" eq "0.0.0.0/0"){
1619 $tdcolor="<font style='color: $Header::colourred;'>$c</font>";
1620 return $tdcolor;
1621 }
b119578f
AM
1622 #Check if IP is part of OpenVPN N2N subnet
1623 foreach my $key (sort keys %ccdhost){
1624 if ($ccdhost{$key}[3] eq 'net'){
1625 my ($a,$b) = split("/",$ccdhost{$key}[11]);
f620fa34
AM
1626 if (&General::IpInSubnet($sip,$a,$b)){
1627 $tdcolor="<font style='color:$Header::colourovpn ;'>$c</font>";
b119578f
AM
1628 return $tdcolor;
1629 }
1630 }
1631 }
f620fa34 1632
b119578f
AM
1633 #Check if IP is part of OpenVPN dynamic subnet
1634 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
f620fa34
AM
1635 if (&General::IpInSubnet($sip,$a,$b)){
1636 $tdcolor="<font style='color: $Header::colourovpn;'>$c</font>";
b119578f
AM
1637 return $tdcolor;
1638 }
f620fa34 1639
b119578f
AM
1640 #Check if IP is part of OpenVPN static subnet
1641 foreach my $key (sort keys %ccdnet){
1642 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1643 $b =&General::iporsubtodec($b);
f620fa34
AM
1644 if (&General::IpInSubnet($sip,$a,$b)){
1645 $tdcolor="<font style='color: $Header::colourovpn;'>$c</font>";
b119578f
AM
1646 return $tdcolor;
1647 }
1648 }
f620fa34 1649
b119578f
AM
1650 #Check if IP is part of IPsec RW network
1651 if ($ipsecsettings{'RW_NET'} ne ''){
1652 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1653 $b=&General::iporsubtodec($b);
f620fa34
AM
1654 if (&General::IpInSubnet($sip,$a,$b)){
1655 $tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
b119578f
AM
1656 return $tdcolor;
1657 }
1658 }
f620fa34 1659
b119578f
AM
1660 #Check if IP is part of a IPsec N2N network
1661 foreach my $key (sort keys %ipsecconf){
1ccfb89e
AM
1662 if ($ipsecconf{$key}[11]){
1663 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1664 $b=&General::iporsubtodec($b);
1665 if (&General::IpInSubnet($sip,$a,$b)){
1666 $tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
1667 return $tdcolor;
1668 }
b119578f
AM
1669 }
1670 }
f620fa34 1671 return "$c";
b119578f 1672}
2a81ab0d
AM
1673sub viewtablehost
1674{
1675 if (! -z $confighost){
1676 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust addr'});
1677 &General::readhasharray("$confighost", \%customhost);
b119578f
AM
1678 &General::readhasharray("$configccdnet", \%ccdnet);
1679 &General::readhasharray("$configccdhost", \%ccdhost);
484269ce
AM
1680 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1681 &General::readhasharray("$fwconfiginp", \%fwinp);
1682 &General::readhasharray("$fwconfigout", \%fwout);
1683 &General::readhasharray("$configgrp", \%customgrp);
2a81ab0d
AM
1684 if (!keys %customhost)
1685 {
1686 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1687 }else{
1688 print<<END;
902a15be
AM
1689 <table width='100%' cellspacing='0' class='tbl'>
1690 <tr><th align='center'><b>$Lang::tr{'name'}</b></th><th align='center'><b>$Lang::tr{'fwhost ip_mac'}</b></th><th align='center'><b>$Lang::tr{'remark'}</b></th><th align='center'><b>$Lang::tr{'used'}</b></th><th></th><th width='3%'></th></tr>
2a81ab0d
AM
1691END
1692 }
1693 my $count=0;
902a15be 1694 my $col='';
eff2dbf8 1695 foreach my $key (sort { ncmp ($customhost{$a}[0],$customhost{$b}[0])} keys %customhost) {
2a81ab0d 1696 if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) {
902a15be
AM
1697 print" <tr>";
1698 $col="bgcolor='${Header::colouryellow}'";
1699 }elsif ($count % 2){
1700 print" <tr>";
1701 $col="bgcolor='$color{'color20'}'";
1702 }else{
1703 $col="bgcolor='$color{'color22'}'";
1704 print" <tr>";
1705 }
2a81ab0d 1706 my ($ip,$sub)=split(/\//,$customhost{$key}[2]);
e3580608 1707 $customhost{$key}[4]=~s/\s+//g;
484269ce
AM
1708 my $hostcount=0;
1709 $hostcount=&gethostcount($customhost{$key}[0]);
f620fa34 1710 print"<td width='20%' $col>$customhost{$key}[0]</td><td width='20%' align='center' $col >".&getcolor($ip)."</td><td width='50%' align='left' $col>$customhost{$key}[3]</td><td align='center' $col>$hostcount x</td>";
2a81ab0d 1711 print<<END;
f8aa0679 1712 <td width='1%' $col><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
2a81ab0d
AM
1713 <input type='hidden' name='ACTION' value='edithost' />
1714 <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' />
1715 <input type='hidden' name='IP' value='$ip' />
1716 <input type='hidden' name='type' value='$customhost{$key}[1]' />
e3580608 1717 <input type='hidden' name='HOSTREMARK' value='$customhost{$key}[3]' />
2e99ab8b 1718 </form></td>
2a81ab0d 1719END
484269ce 1720 if($hostcount == '0')
2a81ab0d 1721 {
f8aa0679 1722 print"<td width='1%' $col><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>";
2a81ab0d 1723 }else{
902a15be 1724 print"<td width='1%' $col></td></tr>";
2a81ab0d
AM
1725 }
1726 $count++;
1727 }
1728 print"</table>";
1729 &Header::closebox();
1730 }
1731}
1732sub viewtablegrp
1733{
1734 if(! -z "$configgrp"){
1735 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust grp'});
1736 &General::readhasharray("$configgrp", \%customgrp);
1737 &General::readhasharray("$configipsec", \%ipsecconf);
1738 &General::readhasharray("$configccdhost", \%ccdhost);
1739 &General::readhasharray("$configccdnet", \%ccdnet);
1740 &General::readhasharray("$confighost", \%customhost);
1741 &General::readhasharray("$confignet", \%customnetwork);
484269ce
AM
1742 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1743 &General::readhasharray("$fwconfiginp", \%fwinp);
1744 &General::readhasharray("$fwconfigout", \%fwout);
2a81ab0d
AM
1745 my @grp=();
1746 my $helper='';
8f204435 1747 my $count=1;
2a81ab0d
AM
1748 my $grpname;
1749 my $remark;
12dcfbbd 1750 my $number;
2cee2462 1751 my $delflag;
aeefcc9c
AM
1752 my @counter;
1753 my %hash;
2a81ab0d 1754 if (!keys %customgrp)
484269ce 1755 {
f195a8d7 1756 print "<center><b>$Lang::tr{'fwhost err emptytable'}</b>";
2a81ab0d 1757 }else{
aeefcc9c
AM
1758 #get all groups in a hash
1759 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
1760 push (@counter,$customgrp{$key}[0]);
1761 }
1762 foreach my $key1 (@counter) {
1763 $hash{$key1}++ ;
1764 }
0c2cf9e2 1765 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
2a81ab0d
AM
1766 $count++;
1767 if ($helper ne $customgrp{$key}[0]){
2cee2462 1768 $delflag='0';
eff2dbf8 1769 foreach my $key1 (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
2cee2462
AM
1770 if ($customgrp{$key}[0] eq $customgrp{$key1}[0])
1771 {
1772 $delflag++;
1773 }
d0815ce4 1774 if($delflag > 1){
d13a9363
AM
1775 last;
1776 }
2cee2462 1777 }
8f204435 1778 $number=1;
f195a8d7 1779 if ($customgrp{$key}[2] eq "none"){$customgrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};}
2a81ab0d 1780 $grpname=$customgrp{$key}[0];
6c869961 1781 $remark="$customgrp{$key}[1]";
aeefcc9c 1782 if($count gt 1){ print"</table>";$count=1;}
2e99ab8b 1783 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp;";
2a81ab0d 1784 print " <b>$Lang::tr{'remark'}:</b>&nbsp $remark &nbsp " if ($remark ne '');
484269ce
AM
1785 my $netgrpcount=&getnetcount($grpname);
1786 print "<b>$Lang::tr{'used'}:</b> $netgrpcount x";
1787 if($netgrpcount == '0')
2a81ab0d 1788 {
f8aa0679 1789 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>";
2a81ab0d 1790 }
f8aa0679 1791 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>";
726e6882 1792 print"<table width='100%' cellspacing='0' class='tbl'><tr><th align='center'><b>$Lang::tr{'name'}</b></th><th align='center'><b>$Lang::tr{'fwhost ip_mac'}</b></th><th align='center' width='25%'><b>$Lang::tr{'fwhost type'}</th><th></th></tr>";
2a81ab0d 1793 }
902a15be 1794 my $col='';
2a81ab0d 1795 if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) {
902a15be
AM
1796 print" <tr>";
1797 $col="bgcolor='${Header::colouryellow}'";
6c869961 1798 }elsif ($count %2 == 0){
902a15be 1799 print"<tr>";
aeefcc9c 1800 $col="bgcolor='$color{'color20'}'";
6c869961 1801 }else{
902a15be 1802 print"<tr>";
aeefcc9c 1803 $col="bgcolor='$color{'color22'}'";
6c869961 1804 }
2a81ab0d 1805 my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]);
902a15be
AM
1806 if ($ip eq ''){
1807 print"<tr>";
1808 $col="bgcolor='${Header::colouryellow}'";
1809 }
1810 print "<td width='39%' align='left' $col>";
2a81ab0d
AM
1811 if($customgrp{$key}[3] eq 'Standard Network'){
1812 print &get_name($customgrp{$key}[2])."</td>";
1813 }else{
1814 print "$customgrp{$key}[2]</td>";
1815 }
f195a8d7 1816 if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){
bc595f09 1817 print "<td align='center' $col>$Lang::tr{'fwhost deleted'}</td><td align='center' $col>$Lang::tr{'fwhost '.$customgrp{$key}[3]}</td><td width='1%' $col><form method='post'>";
2a81ab0d 1818 }else{
72586f0f 1819 my ($colip,$colsub) = split("/",$ip);
eae92b2b 1820 $ip="$colip/".&General::iporsubtocidr($colsub) if ($colsub);
bc595f09 1821 print"<td align='center' $col>".&getcolor($ip)."</td><td align='center' $col>$Lang::tr{'fwhost '.$customgrp{$key}[3]}</td><td width='1%' $col><form method='post'>";
2a81ab0d 1822 }
aeefcc9c 1823 if ($delflag > 0 && $ip ne ''){
f8aa0679 1824 print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' />";
aeefcc9c
AM
1825 #check if this group has only one entry
1826 foreach my $key2 (keys %hash) {
1827 if ($hash{$key2}<2 && $key2 eq $customgrp{$key}[0]){
1828 print "<input type='hidden' name='last' value='on'>" ;
1829 }
1830 }
2a81ab0d 1831 }
bc595f09 1832 print"<input type='hidden' name='ACTION' value='deletegrphost'><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 1833 $helper=$customgrp{$key}[0];
12dcfbbd 1834 $number++;
2a81ab0d
AM
1835 }
1836 print"</table>";
2a81ab0d
AM
1837 }
1838 &Header::closebox();
1839}
1840
1841}
1842sub viewtableservice
1843{
1844 my $count=0;
3a162dc1 1845 my $srvcount;
2a81ab0d
AM
1846 if(! -z "$configsrv")
1847 {
1848 &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'});
1849 &General::readhasharray("$configsrv", \%customservice);
3a162dc1
AM
1850 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1851 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1852 &General::readhasharray("$fwconfiginp", \%fwinp);
1853 &General::readhasharray("$fwconfigout", \%fwout);
2a81ab0d 1854 print<<END;
902a15be
AM
1855 <table width='100%' cellspacing='0' class='tbl'>
1856 <tr><th align='center'><b>$Lang::tr{'fwhost srv_name'}</b></th><th align='center'><b>$Lang::tr{'fwhost prot'}</b></th><th align='center'><b>$Lang::tr{'fwhost port'}</b></th><th align='center'><b>ICMP</b></th><th align='center'><b>$Lang::tr{'fwhost used'}</b></th><th></th><th width='3%'></th></tr>
2a81ab0d 1857END
902a15be 1858 my $col='';
eff2dbf8 1859 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0])} keys %customservice)
2a81ab0d
AM
1860 {
1861 $count++;
1862 if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) {
902a15be
AM
1863 print" <tr>";
1864 $col="bgcolor='${Header::colouryellow}'";
1865 }elsif ($count % 2){
1866 print" <tr>";
1867 $col="bgcolor='$color{'color22'}'";
1868 }else{
1869 print" <tr>";
1870 $col="bgcolor='$color{'color20'}'";
1871 }
2a81ab0d 1872 print<<END;
902a15be 1873 <td $col>$customservice{$key}[0]</td><td align='center' $col>$customservice{$key}[2]</td><td align='center' $col>$customservice{$key}[1]</td><td align='center' $col>
2a81ab0d 1874END
3a162dc1
AM
1875 #Neuer count
1876 $srvcount=&getsrvcount($customservice{$key}[0]);
86a921ee
AM
1877 if($customservice{$key}[3] eq 'All ICMP-Types'){print $Lang::tr{'fwdfw all icmp'};}
1878 elsif($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
2a81ab0d 1879 print<<END;
902a15be 1880 </td><td align='center' $col>$srvcount x</td>
f8aa0679 1881 <td width='1%' $col><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' />
2a81ab0d
AM
1882 <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' />
1883 <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' />
2aeb4b25
AM
1884 <input type='hidden' name='PROT' value='$customservice{$key}[2]' />
1885 <input type='hidden' name='ICMP' value='$customservice{$key}[3]' /></form></td>
2a81ab0d 1886END
3a162dc1 1887 if ($srvcount eq '0')
2a81ab0d 1888 {
f8aa0679 1889 print"<td width='1%' $col><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>";
2a81ab0d 1890 }else{
902a15be 1891 print"<td $col></td></tr>";
2a81ab0d
AM
1892 }
1893 }
1894 print"</table>";
1895 &Header::closebox();
1896 }
1897}
1898sub viewtableservicegrp
1899{
1900 my $count=0;
1901 my $grpname;
1902 my $remark;
1903 my $helper;
aeefcc9c 1904 my $helper1;
937d4e08
AM
1905 my $port;
1906 my $protocol;
c7043621 1907 my $delflag;
3a162dc1 1908 my $grpcount=0;
902a15be 1909 my $col='';
aeefcc9c
AM
1910 my $lastentry=0;
1911 my @counter;
1912 my %hash;
2a81ab0d 1913 if (! -z $configsrvgrp){
2a81ab0d
AM
1914 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'});
1915 &General::readhasharray("$configsrvgrp", \%customservicegrp);
937d4e08 1916 &General::readhasharray("$configsrv", \%customservice);
3a162dc1
AM
1917 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1918 &General::readhasharray("$fwconfiginp", \%fwinp);
1919 &General::readhasharray("$fwconfigout", \%fwout);
2a81ab0d 1920 my $number= keys %customservicegrp;
aeefcc9c
AM
1921 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){
1922 push (@counter,$customservicegrp{$key}[0]);
1923 }
1924 foreach my $key1 (@counter) {
1925 $hash{$key1}++ ;
1926 }
fe2bae3b 1927 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){
2a81ab0d
AM
1928 $count++;
1929 if ($helper ne $customservicegrp{$key}[0]){
3a162dc1
AM
1930 #Get used groupcounter
1931 $grpcount=&getsrvcount($customservicegrp{$key}[0]);
d13a9363 1932 $delflag=0;
eff2dbf8 1933 foreach my $key1 (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) } keys %customservicegrp){
d13a9363
AM
1934 if ($customservicegrp{$key}[0] eq $customservicegrp{$key1}[0])
1935 {
1936 $delflag++;
1937 }
1938 if($delflag > 1){
1939 last;
1940 }
1941 }
2a81ab0d 1942 $grpname=$customservicegrp{$key}[0];
6c869961 1943 if ($customservicegrp{$key}[2] eq "none"){
aeefcc9c 1944 $customservicegrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};
0b54aaed
AM
1945 $port='';
1946 $protocol='';
6c869961
AM
1947 }
1948 $remark="$customservicegrp{$key}[1]";
aeefcc9c 1949 if($count >0){print"</table>";$count=1;}
2e99ab8b
AM
1950 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp; ";
1951 print "<b>$Lang::tr{'remark'}:</b>&nbsp; $remark " if ($remark ne '');
3a162dc1
AM
1952 print "&nbsp; <b>$Lang::tr{'used'}:</b> $grpcount x";
1953 if($grpcount == '0')
2a81ab0d 1954 {
f8aa0679 1955 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>";
2a81ab0d 1956 }
f8aa0679 1957 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>";
902a15be 1958 print"<table width='100%' cellspacing='0' class='tbl'><tr><th align='center'><b>Name</b></th><th align='center'><b>$Lang::tr{'port'}</b></th><th align='center' width='25%'><b>$Lang::tr{'fwhost prot'}</th><th></th></tr>";
2a81ab0d
AM
1959 }
1960 if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) {
902a15be
AM
1961 print"<tr>";
1962 $col="bgcolor='${Header::colouryellow}'";
6c869961 1963 }elsif ($count %2 == 0){
902a15be
AM
1964 print"<tr>";
1965 $col="bgcolor='$color{'color20'}'";
0f869e32 1966 }else{
902a15be
AM
1967 print"<tr>";
1968 $col="bgcolor='$color{'color22'}'";
0f869e32 1969 }
aeefcc9c
AM
1970 #make lines yellow if it is a dummy entry
1971 if ($customservicegrp{$key}[2] eq $Lang::tr{'fwhost err emptytable'}){
1972 print"<tr>";
1973 $col="bgcolor='${Header::colouryellow}'";
1974 }
82b837cf
AM
1975 #Set fields if we use protocols in servicegroups
1976 if ($customservicegrp{$key}[2] ne 'TCP' || $customservicegrp{$key}[2] ne 'UDP' || $customservicegrp{$key}[2] ne 'ICMP'){
1977 $port='-';
1978 }
1979 if ($customservicegrp{$key}[2] eq 'GRE'){$protocol='GRE';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} GRE";}
1980 if ($customservicegrp{$key}[2] eq 'ESP'){$protocol='ESP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} ESP";}
1981 if ($customservicegrp{$key}[2] eq 'AH'){$protocol='AH';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} AH";}
1982 if ($customservicegrp{$key}[2] eq 'IGMP'){$protocol='IGMP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IGMP";}
1983 if ($customservicegrp{$key}[2] eq 'IPIP'){$protocol='IPIP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPIP";}
1984 if ($customservicegrp{$key}[2] eq 'IPV6'){$protocol='IPV6';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPv6 encapsulation";}
902a15be 1985 print "<td width='39%' $col>$customservicegrp{$key}[2]</td>";
937d4e08
AM
1986 foreach my $srv (sort keys %customservice){
1987 if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){
1988 $protocol=$customservice{$srv}[2];
1989 $port=$customservice{$srv}[1];
1990 last;
1991 }
1992 }
902a15be 1993 print"<td align='center' $col>$port</td><td align='center' $col>$protocol</td><td width='1%' $col><form method='post'>";
aeefcc9c
AM
1994 if ($delflag gt '0'){
1995 if ($customservicegrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){
f8aa0679 1996 print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title=$Lang::tr{'delete'} />";
aeefcc9c
AM
1997 }
1998 #check if this group has only one entry
1999 foreach my $key2 (keys %hash) {
2000 if ($hash{$key2}<2 && $key2 eq $customservicegrp{$key}[0]){
2001 print "<input type='hidden' name='last' value='on'>" ;
2002 }
2003 }
0f869e32 2004 }
82b837cf 2005 print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'>";
fe2bae3b 2006 if($protocol eq 'TCP' || $protocol eq 'UDP' || $protocol eq 'ICMP'){
3a162dc1 2007 print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2]'></form></td></tr>";
82b837cf 2008 }else{
3a162dc1 2009 print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$protocol'></form></td></tr>";
82b837cf 2010 }
0f869e32 2011 $helper=$customservicegrp{$key}[0];
2a81ab0d
AM
2012 }
2013 print"</table>";
2014 &Header::closebox();
2015 }
2016}
2017# Check
2018sub checkname
2019{
2020 my %hash=%{(shift)};
2021 foreach my $key (keys %hash) {
2022 if($hash{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
2023 return 0;
2024 }
2025 }
2026 return 1;
2027
2028}
f195a8d7
AM
2029sub checkgroup
2030{
40962f97 2031 &General::readhasharray("$configgrp", \%customgrp );
f195a8d7 2032 my $name=shift;
3a162dc1
AM
2033 foreach my $key (keys %customservicegrp) {
2034 if($customservicegrp{$key}[0] eq $name){
2035 return 0;
2036 }
2037 }
2038 return 1;
2039}
2040sub checkservice
2041{
2042 &General::readhasharray("$configsrv", \%customservice );
2043 my $name=shift;
2044 foreach my $key (keys %customservice) {
2045 if($customservice{$key}[0] eq $name){
f195a8d7
AM
2046 return 0;
2047 }
2048 }
2049 return 1;
2050}
2a81ab0d
AM
2051sub checkip
2052{
2053
2054 my %hash=%{(shift)};
2055 my $a=shift;
2056 foreach my $key (keys %hash) {
2057 if($hash{$key}[$a] eq $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'})){
2058 return 0;
2059 }
2060 }
2061 return 1;
2062}
2063sub checksubnet
2064{
2a81ab0d
AM
2065 my %hash=%{(shift)};
2066 &General::readhasharray("$confignet", \%hash);
2067 foreach my $key (keys %hash) {
2068 if(&General::IpInSubnet($fwhostsettings{'IP'},$hash{$key}[1],$hash{$key}[2]))
2069 {
2070 return 1;
2071 }
2072 }
2073 return 0;
2074}
2075sub checkservicegroup
2076{
2077 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2a81ab0d 2078 #check name
7772ae73 2079 if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'}))
2a81ab0d
AM
2080 {
2081 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
2082 return $errormessage;
2083 }
2a81ab0d
AM
2084 #check empty selectbox
2085 if (keys %customservice lt 1)
2086 {
2087 $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>";
2088 }
2a81ab0d
AM
2089 #check if name already exists
2090 if ($fwhostsettings{'updatesrvgrp'} ne 'on'){
2091 foreach my $key (keys %customservicegrp) {
2092 if( $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} ){
2093 $errormessage.=$Lang::tr{'fwhost err grpexist'}."<br>";
2094
2095 }
2096 }
2097 }
2098 #check if service already exists in group
2099 foreach my $key (keys %customservicegrp) {
13e5dda4
AM
2100 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){
2101 $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>";
2a81ab0d 2102 }
13e5dda4 2103 }
2a81ab0d
AM
2104 return $errormessage;
2105}
49da7d79
AM
2106sub checkrulereload
2107{
2108 my $search=shift;
2109 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2110 &General::readhasharray("$fwconfiginp", \%fwinp);
2111 &General::readhasharray("$fwconfigout", \%fwout);
2112
2113 #check if service or servicegroup is used in rules
2114 foreach my $key (keys %fwfwd){
2115 if($search eq $fwfwd{$key}[15]){
2116 &General::firewall_config_changed();
2117 return;
2118 }
2119 }
2120 foreach my $key (keys %fwinp){
2121 if($search eq $fwinp{$key}[15]){
2122 &General::firewall_config_changed();
2123 return;
2124 }
2125 }
2126 foreach my $key (keys %fwout){
2127 if($search eq $fwout{$key}[15]){
2128 &General::firewall_config_changed();
2129 return;
2130 }
2131 }
2132}
2a81ab0d
AM
2133sub error
2134{
2135 if ($errormessage) {
2136 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
2137 print "<class name='base'>$errormessage\n";
2138 print "&nbsp;</class>\n";
2139 &Header::closebox();
2140 }
2141}
2142sub hint
2143{
2144 if ($hint) {
2145 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
2146 print "<class name='base'>$hint\n";
2147 print "&nbsp;</class>\n";
2148 &Header::closebox();
2149 }
2150}
2151sub get_name
2152{
2153 my $val=shift;
2154 &General::setup_default_networks(\%defaultNetworks);
2155 foreach my $network (sort keys %defaultNetworks)
2156 {
2157 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
2158 }
2159}
484269ce
AM
2160sub gethostcount
2161{
2162 my $searchstring=shift;
2163 my $srvcounter=0;
2164 #Count services used in servicegroups
2165 foreach my $key (keys %customgrp) {
2166 if($customgrp{$key}[2] eq $searchstring){
2167 $srvcounter++;
2168 }
2169 }
2170 #Count services used in firewall - config
2171 foreach my $key1 (keys %fwfwd) {
2172 if($fwfwd{$key1}[4] eq $searchstring){
2173 $srvcounter++;
2174 }
2175 if($fwfwd{$key1}[6] eq $searchstring){
2176 $srvcounter++;
2177 }
2178 }
2179 #Count services used in firewall - input
2180 foreach my $key2 (keys %fwinp) {
2181 if($fwinp{$key2}[4] eq $searchstring){
2182 $srvcounter++;
2183 }
2184 if($fwinp{$key2}[6] eq $searchstring){
2185 $srvcounter++;
2186 }
2187 }
2188 #Count services used in firewall - outgoing
2189 foreach my $key3 (keys %fwout) {
2190 if($fwout{$key3}[4] eq $searchstring){
2191 $srvcounter++;
2192 }
2193 if($fwout{$key3}[6] eq $searchstring){
2194 $srvcounter++;
2195 }
2196 }
2197 return $srvcounter;
2198}
2199sub getnetcount
2200{
2201 my $searchstring=shift;
2202 my $srvcounter=0;
2203 #Count services used in servicegroups
2204 foreach my $key (keys %customgrp) {
2205 if($customgrp{$key}[2] eq $searchstring){
2206 $srvcounter++;
2207 }
2208 }
2209 #Count services used in firewall - config
2210 foreach my $key1 (keys %fwfwd) {
2211 if($fwfwd{$key1}[4] eq $searchstring){
2212 $srvcounter++;
2213 }
2214 if($fwfwd{$key1}[6] eq $searchstring){
2215 $srvcounter++;
2216 }
2217 }
2218 #Count services used in firewall - input
2219 foreach my $key2 (keys %fwinp) {
2220 if($fwinp{$key2}[4] eq $searchstring){
2221 $srvcounter++;
2222 }
2223 if($fwinp{$key2}[6] eq $searchstring){
2224 $srvcounter++;
2225 }
2226 }
2227 #Count services used in firewall - outgoing
2228 foreach my $key3 (keys %fwout) {
2229 if($fwout{$key3}[4] eq $searchstring){
2230 $srvcounter++;
2231 }
2232 if($fwout{$key3}[6] eq $searchstring){
2233 $srvcounter++;
2234 }
2235 }
2236 return $srvcounter;
2237}
3a162dc1
AM
2238sub getsrvcount
2239{
2240 my $searchstring=shift;
2241 my $srvcounter=0;
2242 #Count services used in servicegroups
2243 foreach my $key (keys %customservicegrp) {
2244 if($customservicegrp{$key}[2] eq $searchstring){
2245 $srvcounter++;
2246 }
2247 }
2248 #Count services used in firewall - config
2249 foreach my $key1 (keys %fwfwd) {
2250 if($fwfwd{$key1}[15] eq $searchstring){
2251 $srvcounter++;
2252 }
2253 }
2254 #Count services used in firewall - input
2255 foreach my $key2 (keys %fwinp) {
2256 if($fwinp{$key2}[15] eq $searchstring){
2257 $srvcounter++;
2258 }
2259 }
2260 #Count services used in firewall - outgoing
2261 foreach my $key3 (keys %fwout) {
2262 if($fwout{$key3}[15] eq $searchstring){
2263 $srvcounter++;
2264 }
2265 }
2266 return $srvcounter;
2267}
2a81ab0d
AM
2268sub deletefromgrp
2269{
2270 my $target=shift;
2271 my $config=shift;
2272 my %hash=();
2273 &General::readhasharray("$config",\%hash);
2274 foreach my $key (keys %hash) {
2a81ab0d 2275 if($hash{$key}[2] eq $target){
2a81ab0d 2276 delete $hash{$key};
2a81ab0d
AM
2277 }
2278 }
2279 &General::writehasharray("$config",\%hash);
2280
2281}
2282sub plausicheck
2283{
2a81ab0d
AM
2284 my $edit=shift;
2285 #check hostname
d0815ce4 2286 if (!&validhostname($fwhostsettings{'HOSTNAME'}))
2a81ab0d
AM
2287 {
2288 $errormessage=$errormessage.$Lang::tr{'fwhost err name'};
2289 $fwhostsettings{'BLK_IP'}='readonly';
2290 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2291 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2292 }
2293 #check if name collides with CCD Netname
2a81ab0d
AM
2294 &General::readhasharray("$configccdnet", \%ccdnet);
2295 foreach my $key (keys %ccdnet) {
2296 if($ccdnet{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
2297 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdnet'};;
2298 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2299 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2300 last;
2301 }
2302 }
2a81ab0d
AM
2303 #check if IP collides with CCD NetIP
2304 if ($fwhostsettings{'type'} ne 'mac'){
2305 &General::readhasharray("$configccdnet", \%ccdnet);
2306 foreach my $key (keys %ccdnet) {
2307 my $test=(&General::getnetworkip($fwhostsettings{'IP'},&General::iporsubtocidr($fwhostsettings{'SUBNET'})))."/".$fwhostsettings{'SUBNET'};
2308 if($ccdnet{$key}[1] eq $test){
2309 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdipnet'};
2310 $fwhostsettings{'IP'} = $fwhostsettings{'orgip'};
2311 $fwhostsettings{'SUBNET'} = $fwhostsettings{'orgsubnet'};
2312 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2313 last;
2314 }
2315 }
2316 }
2a81ab0d
AM
2317 #check if name collides with CCD Hostname
2318 &General::readhasharray("$configccdhost", \%ccdhost);
2319 foreach my $key (keys %ccdhost) {
2320 my ($ip,$sub)=split(/\//,$ccdhost{$key}[33]);
2321 if($ip eq $fwhostsettings{'IP'}){
2322 $errormessage=$Lang::tr{'fwhost err isccdiphost'};
2323 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2324 last;
2325 }
2326 }
2327 #check if IP collides with CCD HostIP (only hosts)
2328 if ($edit eq 'edithost')
2329 {
2330 foreach my $key (keys %ccdhost) {
2331 if($ccdhost{$key}[1] eq $fwhostsettings{'HOSTNAME'}){
2332 $errormessage=$Lang::tr{'fwhost err isccdhost'};
2333 $fwhostsettings{'IP'} = $fwhostsettings{'orgname'};
2334 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2335 last;
2336 }
2337 }
2338 }
2339 #check if network with this name already exists
2340 &General::readhasharray("$confignet", \%customnetwork);
2341 if (!&checkname(\%customnetwork))
2342 {
2343 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err netexist'};
2344 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2345 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2346 }
2347 #check if network ip already exists
2348 if (!&checkip(\%customnetwork,1))
2349 {
2350 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err net'};
2351 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2352 }
2353 #check if host with this name already exists
2354 &General::readhasharray("$confighost", \%customhost);
2355 if (!&checkname(\%customhost))
2356 {
0013abb0 2357 $errormessage.="<br>".$Lang::tr{'fwhost err hostexist'};
2a81ab0d 2358 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
ed73b87e 2359 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2a81ab0d
AM
2360 }
2361 #check if host with this ip already exists
2362 if (!&checkip(\%customhost,2))
2363 {
2364 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'};
2a81ab0d 2365 }
2a81ab0d
AM
2366 return;
2367}
2368sub getipforgroup
2369{
2370 my $name=$_[0],
2371 my $type=$_[1];
2372 my $value;
2373
2374 #get address from IPSEC NETWORK
2375 if ($type eq 'IpSec Network'){
2376 foreach my $key (keys %ipsecconf) {
2377 if ($ipsecconf{$key}[1] eq $name){
2378 return $ipsecconf{$key}[11];
2379 }
2380 }
2381 &deletefromgrp($name,$configgrp);
2382 }
2383
2384 #get address from IPSEC HOST
2385 if ($type eq 'IpSec Host'){
2386 foreach my $key (keys %ipsecconf) {
2387 if ($ipsecconf{$key}[1] eq $name){
2388 return $ipsecconf{$key}[10];
2389 }
2390 }
2391 &deletefromgrp($name,$configgrp);
2392 }
2393
2394 #get address from ovpn ccd Net-2-Net
2395 if ($type eq 'OpenVPN N-2-N'){
2396 foreach my $key (keys %ccdhost) {
2397 if($ccdhost{$key}[1] eq $name){
2398 my ($a,$b) = split ("/",$ccdhost{$key}[11]);
2399 $b=&General::iporsubtodec($b);
2400 return "$a/$b";
2401 }
2402 }
2403 &deletefromgrp($name,$configgrp);
2404 }
2405
2406 #get address from ovpn ccd static host
2407 if ($type eq 'OpenVPN static host'){
2408 foreach my $key (keys %ccdhost) {
2409 if($ccdhost{$key}[1] eq $name){
2410 my ($a,$b) = split (/\//,$ccdhost{$key}[33]);
2411 $b=&General::iporsubtodec($b);
2412 return "$a/$b";
2413 }
2414 }
2415 &deletefromgrp($name,$configgrp);
2416 }
2417
2418 #get address from ovpn ccd static net
2419 if ($type eq 'OpenVPN static network'){
2420 foreach my $key (keys %ccdnet) {
2421 if ($ccdnet{$key}[0] eq $name){
2422 my ($a,$b) = split (/\//,$ccdnet{$key}[1]);
2423 $b=&General::iporsubtodec($b);
2424 return "$a/$b";
2425 }
2426 }
2427 }
2428
2429 #check custom addresses
2430 if ($type eq 'Custom Host'){
2431 foreach my $key (keys %customhost) {
2432 if ($customhost{$key}[0] eq $name){
f1934a05
AM
2433 my ($ip,$sub) = split("/",$customhost{$key}[2]);
2434 return $ip;
2a81ab0d
AM
2435 }
2436 }
2437 }
2438
2439 ##check custom networks
2440 if ($type eq 'Custom Network'){
2441 foreach my $key (keys %customnetwork) {
2442 if($customnetwork{$key}[0] eq $name){
2443 return $customnetwork{$key}[1]."/".$customnetwork{$key}[2];
2444 }
2445 }
2446 }
2447
2448 #check standard networks
2449 if ($type eq 'Standard Network'){
2450 if ($name =~ /OpenVPN/i){
2451 my %ovpn=();
2452 &General::readhash("${General::swroot}/ovpn/settings",\%ovpn);
2453 return $ovpn{'DOVPN_SUBNET'};
2454 }
2455 if ($name eq 'GREEN'){
2456 my %hash=();
2457 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2458 return $hash{'GREEN_NETADDRESS'}."/".$hash{'GREEN_NETMASK'};
2459 }
2460 if ($name eq 'BLUE'){
2461 my %hash=();
2462 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2463 return $hash{'BLUE_NETADDRESS'}."/".$hash{'BLUE_NETMASK'};
2464 }
2465 if ($name eq 'ORANGE'){
2466 my %hash=();
2467 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2468 return $hash{'ORANGE_NETADDRESS'}."/".$hash{'ORANGE_NETMASK'};
2469 }
2470 if ($name eq 'ALL'){
2471 return "0.0.0.0/0.0.0.0";
2472 }
2473 if ($name =~ /IPsec/i){
2474 my %hash=();
2475 &General::readhash("${General::swroot}/vpn/settings",\%hash);
2476 return $hash{'RW_NET'};
2477 }
48f07c19
AM
2478 if ($name eq 'RED'){
2479 return "0.0.0.0/0";
2480 }
2a81ab0d
AM
2481 }
2482}
fe2bae3b
AM
2483sub decrease
2484{
2a81ab0d
AM
2485 my $grp=$_[0];
2486 &General::readhasharray("$confignet", \%customnetwork);
2487 &General::readhasharray("$confighost", \%customhost);
2488 foreach my $key (sort keys %customgrp ){
2489 if ( ($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Network')){
2490 foreach my $key1 (sort keys %customnetwork){
2491 if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){
8013bd0a 2492 $customnetwork{$key1}[4]=$customnetwork{$key1}[4]-1;
2a81ab0d
AM
2493 last;
2494 }
2495 }
2496 }
2497
2498 if (($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Host')){
2499 foreach my $key2 (sort keys %customhost){
2500 if ($customhost{$key2}[0] eq $customgrp{$key}[2]){
8013bd0a 2501 $customhost{$key2}[4]=$customhost{$key2}[4]-1;
2a81ab0d
AM
2502 last;
2503 }
2504 }
2505
2506 }
2507 }
2508 &General::writehasharray("$confignet", \%customnetwork);
2509 &General::writehasharray("$confighost", \%customhost);
2510}
2511sub decreaseservice
2512{
2513 my $grp=$_[0];
2514 &General::readhasharray("$configsrv", \%customservice);
2515 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2516
2517 foreach my $key (sort keys %customservicegrp){
2518 if ($customservicegrp{$key}[0] eq $grp ){
2519 foreach my $key2 (sort keys %customservice){
2520 if ($customservice{$key2}[0] eq $customservicegrp{$key}[2]){
2521 $customservice{$key2}[4]--;
2522 }
2523 }
2524 }
2525 }
2526 &General::writehasharray("$configsrv", \%customservice);
2527
2528}
a8b113e7
AM
2529sub changenameinfw
2530{
2531 my $old=shift;
2532 my $new=shift;
2533 my $fld=shift;
2534 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2535 &General::readhasharray("$fwconfiginp", \%fwinp);
2536 &General::readhasharray("$fwconfigout", \%fwout);
2537 #Rename group in Firewall-CONFIG
2538 foreach my $key1 (keys %fwfwd) {
2539 if($fwfwd{$key1}[$fld] eq $old){
2540 $fwfwd{$key1}[$fld]=$new;
2541 }
2542 }
2543 &General::writehasharray("$fwconfigfwd", \%fwfwd );
2544 #Rename group in Firewall-INPUT
2545 foreach my $key2 (keys %fwinp) {
2546 if($fwinp{$key2}[$fld] eq $old){
2547 $fwinp{$key2}[$fld]=$new;
2548 }
2549 }
2550 &General::writehasharray("$fwconfiginp", \%fwinp );
2551 #Rename group in Firewall-OUTGOING
2552 foreach my $key3 (keys %fwout) {
2553 if($fwout{$key3}[$fld] eq $old){
2554 $fwout{$key3}[$fld]=$new;
2555 }
2556 }
2557 &General::writehasharray("$fwconfigout", \%fwout );
2558}
2a81ab0d
AM
2559sub checkports
2560{
2561
2562 my %hash=%{(shift)};
2563 #check empty fields
2564 if ($fwhostsettings{'SRV_NAME'} eq '' ){
2565 $errormessage=$Lang::tr{'fwhost err name1'};
2566 }
2567 if ($fwhostsettings{'SRV_PORT'} eq '' && $fwhostsettings{'PROT'} ne 'ICMP'){
2568 $errormessage=$Lang::tr{'fwhost err port'};
2569 }
2570 #check valid name
7772ae73 2571 if (! &validhostname($fwhostsettings{'SRV_NAME'})){
2a81ab0d
AM
2572 $errormessage="<br>".$Lang::tr{'fwhost err name'};
2573 }
2574 #change dashes with :
2575 $fwhostsettings{'SRV_PORT'}=~ tr/-/:/;
2576
2577 if ($fwhostsettings{'SRV_PORT'} eq "*") {
2578 $fwhostsettings{'SRV_PORT'} = "1:65535";
2579 }
2580 if ($fwhostsettings{'SRV_PORT'} =~ /^(\D)\:(\d+)$/) {
2581 $fwhostsettings{'SRV_PORT'} = "1:$2";
2582 }
2583 if ($fwhostsettings{'SRV_PORT'} =~ /^(\d+)\:(\D)$/) {
2584 $fwhostsettings{'SRV_PORT'} = "$1:65535";
2585 }
2586 if($fwhostsettings{'PROT'} ne 'ICMP'){
2587 $errormessage = $errormessage.&General::validportrange($fwhostsettings{'SRV_PORT'}, 'src');
2588 }
2589 # a new service has to have a different name
2590 foreach my $key (keys %hash){
2591 if ($hash{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
2592 $errormessage = "<br>".$Lang::tr{'fwhost err srv exists'};
2593 last;
2594 }
2595 }
2596 return $errormessage;
2597}
2598sub validhostname
2599{
2600 # Checks a hostname against RFC1035
2601 my $hostname = $_[0];
2602
2603 # Each part should be at least two characters in length
2604 # but no more than 63 characters
2605 if (length ($hostname) < 1 || length ($hostname) > 63) {
2606 return 0;}
2607 # Only valid characters are a-z, A-Z, 0-9 and -
d0815ce4 2608 if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-_.;()\/\s]*$/) {
2a81ab0d
AM
2609 return 0;}
2610 # First character can only be a letter or a digit
2611 if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
2612 return 0;}
2613 # Last character can only be a letter or a digit
7772ae73 2614 if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9()]*$/) {
2a81ab0d
AM
2615 return 0;}
2616 return 1;
2617}
6c869961
AM
2618sub validremark
2619{
2620 # Checks a hostname against RFC1035
2621 my $remark = $_[0];
2622 # Each part should be at least two characters in length
2623 # but no more than 63 characters
2624 if (length ($remark) < 1 || length ($remark) > 255) {
2625 return 0;}
2626 # Only valid characters are a-z, A-Z, 0-9 and -
d928d795 2627 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
6c869961
AM
2628 return 0;}
2629 # First character can only be a letter or a digit
2630 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
2631 return 0;}
2632 # Last character can only be a letter or a digit
d928d795 2633 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
6c869961
AM
2634 return 0;}
2635 return 1;
2636}
2a81ab0d
AM
2637&Header::closebigbox();
2638&Header::closepage();