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