]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - html/cgi-bin/fwhosts.cgi
Layout changes fwhosts.cgi
[people/teissler/ipfire-2.x.git] / html / cgi-bin / fwhosts.cgi
CommitLineData
2a81ab0d
AM
1#!/usr/bin/perl
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5bee9a9d 5# Copyright (C) 2013 Alexander Marx <amarx@ipfire.org> #
2a81ab0d
AM
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
2a81ab0d
AM
21use strict;
22
23# enable only the following on debugging purpose
24use warnings;
eff2dbf8 25use Sort::Naturally;
2a81ab0d
AM
26use CGI::Carp 'fatalsToBrowser';
27no warnings 'uninitialized';
28require '/var/ipfire/general-functions.pl';
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
31
32my %fwhostsettings=();
33my %customnetwork=();
34my %customhost=();
35my %customgrp=();
36my %customservice=();
37my %customservicegrp=();
38my %ccdnet=();
39my %ccdhost=();
40my %ipsecconf=();
41my %icmptypes=();
42my %color=();
43my %defaultNetworks=();
44my %mainsettings=();
45my %ownnet=();
46my %ipsecsettings=();
62fc8511
AM
47my %fwfwd=();
48my %fwinp=();
3a162dc1 49my %fwout=();
b119578f 50my %ovpnsettings=();
2aeb4b25 51
2a81ab0d
AM
52
53my $errormessage;
54my $hint;
55my $update=0;
56my $confignet = "${General::swroot}/fwhosts/customnetworks";
57my $confighost = "${General::swroot}/fwhosts/customhosts";
58my $configgrp = "${General::swroot}/fwhosts/customgroups";
59my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
60my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
61my $configipsec = "${General::swroot}/vpn/config";
62my $configsrv = "${General::swroot}/fwhosts/customservices";
63my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
6d8eb5de
AM
64my $fwconfigfwd = "${General::swroot}/firewall/config";
65my $fwconfiginp = "${General::swroot}/firewall/input";
3a162dc1 66my $fwconfigout = "${General::swroot}/firewall/outgoing";
b119578f
AM
67my $configovpn = "${General::swroot}/ovpn/settings";
68my $tdcolor='';
b119578f 69my $configipsecrw = "${General::swroot}/vpn/settings";
2a81ab0d
AM
70
71unless (-e $confignet) { system("touch $confignet"); }
72unless (-e $confighost) { system("touch $confighost"); }
73unless (-e $configgrp) { system("touch $configgrp"); }
74unless (-e $configsrv) { system("touch $configsrv"); }
75unless (-e $configsrvgrp) { system("touch $configsrvgrp"); }
76
77&General::readhash("${General::swroot}/main/settings", \%mainsettings);
78&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
79&General::readhash("${General::swroot}/ethernet/settings", \%ownnet);
b119578f
AM
80&General::readhash("$configovpn", \%ovpnsettings);
81&General::readhasharray("$configipsec", \%ipsecconf);
82&General::readhash("$configipsecrw", \%ipsecsettings);
83
2a81ab0d
AM
84&Header::getcgihash(\%fwhostsettings);
85
86&Header::showhttpheaders();
87&Header::openpage($Lang::tr{'fwhost hosts'}, 1, '');
88&Header::openbigbox('100%', 'center');
89
2e99ab8b
AM
90#### JAVA SCRIPT ####
91print<<END;
92<script>
fda8c915
AM
93 var PROTOCOLS_WITH_PORTS = ["TCP", "UDP"];
94 var update_protocol = function() {
95 var protocol = \$("#protocol").val();
96
97 if (protocol === undefined)
98 return;
99
100 // Check if we are dealing with a protocol, that knows ports.
101 if (\$.inArray(protocol, PROTOCOLS_WITH_PORTS) >= 0) {
102 \$("#PORT").show();
c9493d6c 103 \$("#PROTOKOLL").hide();
fda8c915
AM
104 } else {
105 \$("#PORT").hide();
fda8c915 106 \$("#PROTOKOLL").show();
fda8c915
AM
107 }
108 };
109
2e99ab8b 110 \$(document).ready(function() {
fda8c915 111 var protocol = \$("#protocol").val();
fda8c915
AM
112 \$("#protocol").change(update_protocol);
113 update_protocol();
5f037986
AM
114 // Automatically select radio buttons when corresponding
115 // dropdown menu changes.
116 \$("select").change(function() {
117 var id = \$(this).attr("name");
118 \$('#' + id).prop("checked", true);
119 });
2e99ab8b
AM
120 });
121</script>
122END
123
2a81ab0d
AM
124## ACTION ####
125# Update
126if ($fwhostsettings{'ACTION'} eq 'updatenet' )
127{
128 &General::readhasharray("$confignet", \%customnetwork);
129 foreach my $key (keys %customnetwork)
130 {
131 if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'})
132 {
133 $fwhostsettings{'orgname'} = $customnetwork{$key}[0];
134 $fwhostsettings{'orgip'} = $customnetwork{$key}[1];
135 $fwhostsettings{'orgsub'} = $customnetwork{$key}[2];
e5a058c1
AM
136 $fwhostsettings{'netremark'} = $customnetwork{$key}[3];
137 $fwhostsettings{'count'} = $customnetwork{$key}[4];
2a81ab0d
AM
138 delete $customnetwork{$key};
139
140 }
141 }
142 &General::writehasharray("$confignet", \%customnetwork);
143 $fwhostsettings{'actualize'} = 'on';
144 $fwhostsettings{'ACTION'} = 'savenet';
145}
146if ($fwhostsettings{'ACTION'} eq 'updatehost')
147{
148 my ($ip,$subnet);
149 &General::readhasharray("$confighost", \%customhost);
150 foreach my $key (keys %customhost)
151 {
152 if($customhost{$key}[0] eq $fwhostsettings{'orgname'})
153 {
2a81ab0d
AM
154 if ($customhost{$key}[1] eq 'ip'){
155 ($ip,$subnet) = split (/\//,$customhost{$key}[2]);
156 }else{
157 $ip = $customhost{$key}[2];
158 }
159 $fwhostsettings{'orgip'} = $ip;
e3580608 160 $fwhostsettings{'count'} = $customhost{$key}[4];
2a81ab0d 161 delete $customhost{$key};
5e970723 162 &General::writehasharray("$confighost", \%customhost);
2a81ab0d
AM
163 }
164 }
2a81ab0d 165 $fwhostsettings{'actualize'} = 'on';
5e970723 166 if($fwhostsettings{'orgip'}){
2a81ab0d 167 $fwhostsettings{'ACTION'} = 'savehost';
5e970723
AM
168 }else{
169 $fwhostsettings{'ACTION'} = $Lang::tr{'fwhost newhost'};
170 }
2a81ab0d
AM
171}
172if ($fwhostsettings{'ACTION'} eq 'updateservice')
173{
174 my $count=0;
175 my $needrules=0;
176 $errormessage=&checkports(\%customservice);
3a162dc1
AM
177 if ($fwhostsettings{'oldsrvname'} ne $fwhostsettings{'SRV_NAME'} && !&checkgroup($fwhostsettings{'SRV_NAME'})){
178 $errormessage=$Lang::tr{'fwhost err grpexist'};
179 }
2a81ab0d
AM
180 if (!$errormessage){
181 &General::readhasharray("$configsrv", \%customservice);
182 foreach my $key (keys %customservice)
183 {
184 if ($customservice{$key}[0] eq $fwhostsettings{'oldsrvname'})
185 {
2a81ab0d
AM
186 delete $customservice{$key};
187 &General::writehasharray("$configsrv", \%customservice);
188 last;
189 }
190 }
191 if ($fwhostsettings{'PROT'} ne 'ICMP'){
192 $fwhostsettings{'ICMP_TYPES'}='BLANK';
193 }
194 my $key1 = &General::findhasharraykey(\%customservice);
2aeb4b25
AM
195 #find out short ICMP-TYPE
196 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
197 foreach my $key (keys %icmptypes){
198 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){
199 $fwhostsettings{'ICMP_TYPES'}=$icmptypes{$key}[0];
200 }
201 }
2a81ab0d
AM
202 foreach my $i (0 .. 4) { $customservice{$key1}[$i] = "";}
203 $customservice{$key1}[0] = $fwhostsettings{'SRV_NAME'};
204 $customservice{$key1}[1] = $fwhostsettings{'SRV_PORT'};
205 $customservice{$key1}[2] = $fwhostsettings{'PROT'};
206 $customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'};
2a81ab0d 207 &General::writehasharray("$configsrv", \%customservice);
ed73b87e 208 #check if we need to update firewallrules
bfee206c
AM
209 if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){
210 if ( ! -z $fwconfigfwd ){
211 &General::readhasharray("$fwconfigfwd", \%fwfwd);
212 foreach my $key (sort keys %fwfwd){
213 if ($fwfwd{$key}[15] eq $fwhostsettings{'oldsrvname'}){
214 $fwfwd{$key}[15] = $fwhostsettings{'SRV_NAME'};
215 }
216 }
217 &General::writehasharray("$fwconfigfwd", \%fwfwd);
bfee206c
AM
218 }
219 if ( ! -z $fwconfiginp ){
220 &General::readhasharray("$fwconfiginp", \%fwinp);
221 foreach my $line (sort keys %fwinp){
222 if ($fwfwd{$line}[15] eq $fwhostsettings{'oldsrvname'}){
223 $fwfwd{$line}[15] = $fwhostsettings{'SRV_NAME'};
224 }
225 }
226 &General::writehasharray("$fwconfiginp", \%fwinp);
227 }
3a162dc1
AM
228 if ( ! -z $fwconfigout ){
229 &General::readhasharray("$fwconfigout", \%fwout);
230 foreach my $line (sort keys %fwout){
231 if ($fwout{$line}[15] eq $fwhostsettings{'oldsrvname'}){
232 $fwout{$line}[15] = $fwhostsettings{'SRV_NAME'};
233 }
234 }
235 &General::writehasharray("$fwconfigout", \%fwout);
236 }
bfac6bd4
AM
237 #check if we need to update groups
238 &General::readhasharray("$configsrvgrp", \%customservicegrp);
239 foreach my $key (sort keys %customservicegrp){
240 if($customservicegrp{$key}[2] eq $fwhostsettings{'oldsrvname'}){
241 $customservicegrp{$key}[2] = $fwhostsettings{'SRV_NAME'};
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){
6c869961 783 if ($customservicegrp{$key}[2] eq 'none'){
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'}){
896 #decrease count from source host/net
897 if ($customgrp{$key}[3] eq 'Custom Network'){
898 &General::readhasharray("$confignet", \%customnetwork);
899 foreach my $key1 (keys %customnetwork){
900 if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){
e09884e0 901 $customnetwork{$key1}[4] = $customnetwork{$key1}[4]-1;
2a81ab0d
AM
902 last;
903 }
904 }
905 &General::writehasharray("$confignet", \%customnetwork);
906 }
907 if ($customgrp{$key}[3] eq 'Custom Host'){
908 &General::readhasharray("$confighost", \%customhost);
909 foreach my $key1 (keys %customhost){
910 if ($customhost{$key1}[0] eq $customgrp{$key}[2]){
e3580608 911 $customhost{$key1}[4] = $customhost{$key1}[4]-1;
2a81ab0d
AM
912 last;
913 }
914 }
915 &General::writehasharray("$confighost", \%customhost);
916 }
3f8fe51e
AM
917 $grpname=$customgrp{$key}[0];
918 $grpremark=$customgrp{$key}[1];
2a81ab0d
AM
919 delete $customgrp{$key};
920 }
921 }
922 &General::writehasharray("$configgrp", \%customgrp);
0e430797
MT
923 if ($fwhostsettings{'grpcnt'} > 0){
924 &General::firewall_config_changed();
925 }
3f8fe51e
AM
926 if ($fwhostsettings{'update'} eq 'on'){
927 $fwhostsettings{'remark'}= $grpremark;
928 $fwhostsettings{'grp_name'}=$grpname;
929 }
2a81ab0d
AM
930 &addgrp;
931 &viewtablegrp;
932}
933if ($fwhostsettings{'ACTION'} eq 'delgrp')
934{
935 &General::readhasharray("$configgrp", \%customgrp);
936 &decrease($fwhostsettings{'grp_name'});
937 foreach my $key (sort keys %customgrp)
938 {
939 if($customgrp{$key}[0] eq $fwhostsettings{'grp_name'})
940 {
941 delete $customgrp{$key};
942 }
943 }
944 &General::writehasharray("$configgrp", \%customgrp);
945 $fwhostsettings{'grp_name'}='';
946 &addgrp;
947 &viewtablegrp;
948}
949if ($fwhostsettings{'ACTION'} eq 'delservice')
950{
951 &General::readhasharray("$configsrv", \%customservice);
952 foreach my $key (keys %customservice) {
953 if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
2a81ab0d
AM
954 delete $customservice{$key};
955 &General::writehasharray("$configsrv", \%customservice);
956 last;
957 }
958 }
959 $fwhostsettings{'SRV_NAME'}='';
960 $fwhostsettings{'SRV_PORT'}='';
961 $fwhostsettings{'PROT'}='';
962 &addservice;
963}
964if ($fwhostsettings{'ACTION'} eq 'delservicegrp')
965{
966 &General::readhasharray("$configsrvgrp", \%customservicegrp);
967 &decreaseservice($fwhostsettings{'SRVGRP_NAME'});
968 foreach my $key (sort keys %customservicegrp)
969 {
970 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
971 {
972 delete $customservicegrp{$key};
973 }
974 }
975 &General::writehasharray("$configsrvgrp", \%customservicegrp);
976 $fwhostsettings{'SRVGRP_NAME'}='';
977 &addservicegrp;
978 &viewtableservicegrp;
979}
980if ($fwhostsettings{'ACTION'} eq 'delgrpservice')
981{
3f8fe51e
AM
982 my $grpname;
983 my $grpremark;
2a81ab0d
AM
984 &General::readhasharray("$configsrvgrp", \%customservicegrp);
985 &General::readhasharray("$configsrv", \%customservice);
986 foreach my $key (keys %customservicegrp){
3a162dc1 987 if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2] eq $fwhostsettings{'delsrvfromgrp'})
2a81ab0d
AM
988 {
989 #decrease count from source service
fe2bae3b
AM
990 foreach my $key1 (sort keys %customservice){
991 if($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
992 $customservice{$key1}[4]--;
993 last;
2a81ab0d
AM
994 }
995 }
3f8fe51e
AM
996 $grpname=$customservicegrp{$key}[0];
997 $grpremark=$customservicegrp{$key}[1];
998 delete $customservicegrp{$key};
2a81ab0d
AM
999 }
1000 }
fe2bae3b 1001 &General::writehasharray("$configsrv", \%customservice);
2a81ab0d 1002 &General::writehasharray("$configsrvgrp", \%customservicegrp);
0e430797 1003 &General::firewall_config_changed();
3f8fe51e 1004 if ($fwhostsettings{'updatesrvgrp'} eq 'on'){
3f8fe51e
AM
1005 $fwhostsettings{'SRVGRP_NAME'}=$grpname;
1006 $fwhostsettings{'SRVGRP_REMARK'}=$grpremark;
1007 }
2a81ab0d
AM
1008 &addservicegrp;
1009 &viewtableservicegrp;
1010
1011}
1012if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'})
1013{
1014 &addnet;
1015 &viewtablenet;
1016}
1017if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newhost'})
1018{
1019 &addhost;
1020 &viewtablehost;
1021}
1022if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgrp'})
1023{
1024 &addgrp;
1025 &viewtablegrp;
1026}
1027if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservice'})
1028{
1029 &addservice;
1030}
1031if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservicegrp'})
1032{
1033 &addservicegrp;
1034 &viewtableservicegrp;
1035}
6c869961
AM
1036if ($fwhostsettings{'ACTION'} eq 'changegrpremark')
1037{
1038 &General::readhasharray("$configgrp", \%customgrp);
d0815ce4 1039 if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){
6c869961
AM
1040 foreach my $key (sort keys %customgrp)
1041 {
6c869961
AM
1042 if($customgrp{$key}[0] eq $fwhostsettings{'grp'} && $customgrp{$key}[1] eq $fwhostsettings{'oldrem'})
1043 {
6c869961
AM
1044 $customgrp{$key}[1]='';
1045 $customgrp{$key}[1]=$fwhostsettings{'newrem'};
1046 }
1047 }
1048 &General::writehasharray("$configgrp", \%customgrp);
1049 $fwhostsettings{'update'}='on';
6c869961
AM
1050 $fwhostsettings{'remark'}=$fwhostsettings{'newrem'};
1051 }else{
1052 $errormessage=$Lang::tr{'fwhost err remark'};
1053 $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'};
1054 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1055 $fwhostsettings{'update'} = 'on';
1056 }
1057 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1058 &addgrp;
1059 &viewtablegrp;
1060}
1061if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark')
1062{
1063 &General::readhasharray("$configsrvgrp", \%customservicegrp );
d0815ce4 1064 if ($fwhostsettings{'oldsrvrem'} ne $fwhostsettings{'newsrvrem'} && (&validremark($fwhostsettings{'newsrvrem'}) || $fwhostsettings{'newsrvrem'} eq '')){
6c869961
AM
1065 foreach my $key (sort keys %customservicegrp)
1066 {
6c869961
AM
1067 if($customservicegrp{$key}[0] eq $fwhostsettings{'srvgrp'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvrem'})
1068 {
6c869961
AM
1069 $customservicegrp{$key}[1]='';
1070 $customservicegrp{$key}[1]=$fwhostsettings{'newsrvrem'};
1071 }
1072 }
1073 &General::writehasharray("$configsrvgrp", \%customservicegrp);
1074 $fwhostsettings{'updatesrvgrp'}='on';
6c869961 1075 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'newsrvrem'};
82b837cf
AM
1076 }elsif($fwhostsettings{'oldsrvrem'} eq $fwhostsettings{'newsrvrem'}){
1077 &addservicegrp;
1078 &viewtableservicegrp;
6c869961
AM
1079 }else{
1080 $errormessage=$Lang::tr{'fwhost err remark'};
1081 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'oldsrvrem'};
1082 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1083 $fwhostsettings{'updatesrvgrp'} = 'on';
1084 }
1085 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1086 &addservicegrp;
1087 &viewtableservicegrp;
1088}
a8b113e7
AM
1089if ($fwhostsettings{'ACTION'} eq 'changesrvgrpname')
1090{
1091 &General::readhasharray("$configsrvgrp", \%customservicegrp );
1092 if ($fwhostsettings{'oldsrvgrpname'} ne $fwhostsettings{'srvgrp'}){
1093 #Check new groupname
1094 if (!&validhostname($fwhostsettings{'srvgrp'})){
1095 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1096 }
1097 if (!$errormessage){
1098 #Rename group in customservicegroup
1099 foreach my $key (keys %customservicegrp) {
1100 if($customservicegrp{$key}[0] eq $fwhostsettings{'oldsrvgrpname'}){
1101 $customservicegrp{$key}[0]=$fwhostsettings{'srvgrp'};
1102 }
1103 }
1104 &General::writehasharray("$configsrvgrp", \%customservicegrp );
1105 #change name in FW Rules
1106 &changenameinfw($fwhostsettings{'oldsrvgrpname'},$fwhostsettings{'srvgrp'},15);
1107 }
1108 }
1109 &addservicegrp;
1110 &viewtableservicegrp;
1111}
1112if ($fwhostsettings{'ACTION'} eq 'changegrpname')
1113{
1114 &General::readhasharray("$configgrp", \%customgrp );
1115 if ($fwhostsettings{'oldgrpname'} ne $fwhostsettings{'grp'}){
1116 #Check new groupname
1117 if (!&validhostname($fwhostsettings{'grp'})){
1118 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1119 }
1120 if (!$errormessage){
1121 #Rename group in customservicegroup
1122 foreach my $key (keys %customgrp) {
1123 if($customgrp{$key}[0] eq $fwhostsettings{'oldgrpname'}){
1124 $customgrp{$key}[0]=$fwhostsettings{'grp'};
1125 }
1126 }
1127 &General::writehasharray("$configgrp", \%customgrp );
1128 #change name in FW Rules
1129 &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},6);
1130 }
1131 }
1132 &addgrp;
1133 &viewtablegrp;
1134}
2a81ab0d
AM
1135### VIEW ###
1136if($fwhostsettings{'ACTION'} eq '')
1137{
1138 &showmenu;
1139}
1140### FUNCTIONS ###
0e430797 1141sub showmenu {
2a81ab0d 1142 &Header::openbox('100%', 'left',$Lang::tr{'fwhost menu'});
43d8be09 1143 print "$Lang::tr{'fwhost welcome'}";
2a81ab0d 1144 print<<END;
2e99ab8b
AM
1145 <br><br><table border='0' width='100%'>
1146 <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>
1147 <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 1148 <tr><td colspan='6'></td></tr></table>
2a81ab0d 1149END
2a81ab0d
AM
1150 &Header::closebox();
1151
1152}
1153# Add
1154sub addnet
1155{
1156 &error;
1157 &showmenu;
1158 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addnet'});
1159 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
f80db6a4 1160 $fwhostsettings{'orgnetremark'}=$fwhostsettings{'NETREMARK'};
2a81ab0d 1161 print<<END;
902a15be 1162 <table border='0' width='100%' >
2e99ab8b 1163 <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
1164 <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>
1165 <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 1166 <tr><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='NETREMARK' value='$fwhostsettings{'NETREMARK'}' style='width: 98.5%;'></td></tr>
bc8ecbd6 1167 <tr><td colspan='6'><br></td></tr><tr>
2a81ab0d
AM
1168END
1169 if ($fwhostsettings{'ACTION'} eq 'editnet' || $fwhostsettings{'error'} eq 'on')
1170 {
902a15be 1171 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 1172 }else{
902a15be
AM
1173 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'>";
1174 }
2e99ab8b 1175 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
1176 &Header::closebox();
1177}
1178sub addhost
1179{
1180 &error;
1181 &showmenu;
1182 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addhost'});
1183 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
f80db6a4 1184 $fwhostsettings{'orgremark'}=$fwhostsettings{'HOSTREMARK'};
2a81ab0d 1185 print<<END;
bc8ecbd6 1186 <table width='100%'>
2e99ab8b 1187 <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 1188 <tr><td>IP/MAC:</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='17'></td></tr>
8013bd0a 1189 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='HOSTREMARK' value='$fwhostsettings{'HOSTREMARK'}' style='width:98%;'></td></tr>
bc8ecbd6 1190 <tr><td colspan='5'><br></td></tr><tr>
2a81ab0d
AM
1191END
1192
1193 if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on')
1194 {
1195
8013bd0a 1196 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 1197 }else{
2e99ab8b 1198 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 1199 }
2e99ab8b 1200 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
1201 &Header::closebox();
1202}
1203sub addgrp
1204{
1205 &hint;
1206 &error;
1207 &showmenu;
1208 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addgrp'});
1209 &General::setup_default_networks(\%defaultNetworks);
8013bd0a
AM
1210 &General::readhasharray("$configccdnet", \%ccdnet);
1211 &General::readhasharray("$confignet", \%customnetwork);
1212 &General::readhasharray("$configccdhost", \%ccdhost);
1213 &General::readhasharray("$confighost", \%customhost);
1214 &General::readhasharray("$configipsec", \%ipsecconf);
1215
2a81ab0d 1216 my %checked=();
8013bd0a 1217 my $show='';
2a81ab0d
AM
1218 $checked{'check1'}{'off'} = '';
1219 $checked{'check1'}{'on'} = '';
1220 $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED';
1221 $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'};
a8b113e7 1222 $fwhostsettings{'oldgrpname'}=$fwhostsettings{'grp_name'};
6c869961
AM
1223 my $grp=$fwhostsettings{'grp_name'};
1224 my $rem=$fwhostsettings{'remark'};
2a81ab0d
AM
1225 if ($fwhostsettings{'update'} eq ''){
1226 print<<END;
bc8ecbd6
AM
1227 <table width='100%' border='0'>
1228 <tr>
1229 <td width='10%'>$Lang::tr{'fwhost addgrpname'}</td>
1230 <td><form method='post'><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' size='20'></td>
1231 </tr>
1232 <tr>
1233 <td width='10%'>$Lang::tr{'remark'}:</td>
1234 <td ><input type='TEXT' name='remark' value='$fwhostsettings{'remark'}' style='width: 98%;'></td>
1235 </tr>
1236 <tr>
1237 <td colspan='2'><br></td>
1238 </tr>
1239 </table>
2a81ab0d
AM
1240END
1241 }else{
1242 print<<END;
6c869961 1243 <table width='100%' border='0'><form method='post' style='display:inline'>
bc8ecbd6
AM
1244 <tr>
1245 <td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost addgrpname'}</td>
1246 <td width='20%'><input type='TEXT' name='grp' value='$fwhostsettings{'grp_name'}' ></td>
1247 <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>
1248 <td></td></form>
1249 </tr>
1250 <tr><form method='post' style='display:inline'>
1251 <td>$Lang::tr{'remark'}:</td>
1252 <td colspan='2'><input type='TEXT' name='newrem' size='45' value='$fwhostsettings{'remark'}' style='width:98%'></td>
1253 <td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='ACTION' value='changegrpremark' ></td>
1254 </tr>
1255 </table></form>
1256 <br><br>
2a81ab0d 1257END
2a81ab0d
AM
1258 }
1259 if ($fwhostsettings{'update'} eq 'on'){
2a81ab0d 1260 print<<END;
8013bd0a
AM
1261 <form method='post'><input type='hidden' name='remark' value='$rem'><input type='hidden' name='grp_name' value='$grp'>
1262 <table width='100%' border='0'>
1263 <tr><td width=50% valign='top'>
1264 <table width='100%' border='0'>
2e99ab8b 1265 <tr><td width='1%'><input type='radio' name='grp2' value='std_net' id='DEFAULT_SRC_ADR' checked></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost stdnet'}</td><td><select name='DEFAULT_SRC_ADR' style='min-width:185px;'>
2a81ab0d
AM
1266END
1267 foreach my $network (sort keys %defaultNetworks)
1268 {
1269 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
7326051e 1270 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
2a81ab0d
AM
1271 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1272 print " selected='selected'" if ($fwhostsettings{'DEFAULT_SRC_ADR'} eq $defaultNetworks{$network}{'NAME'});
7326051e
AM
1273 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
1274 my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK";
1275 my $defsub1=&General::subtocidr($ownnet{$defsub});
1276 $ownnet{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED');
1277 if ($ownnet{$defnet}){
1278 print ">$network ($ownnet{$defnet}/$defsub1)</option>";
1279 }else{
1280 print ">$network</option>";
1281 }
2a81ab0d 1282 }
8013bd0a
AM
1283 print"</select></td></tr>";
1284 if (! -z $confignet){
bc8ecbd6 1285 print"<tr><td><input type='radio' name='grp2' id='CUST_SRC_NET' value='cust_net' $checked{'grp2'}{'cust_net'}></td><td>$Lang::tr{'fwhost cust net'}:</td><td><select name='CUST_SRC_NET' style='min-width:185px;'>";
eff2dbf8 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){
bc8ecbd6 1292 print"<tr><td valign='top'><input type='radio' name='grp2' id='CUST_SRC_HOST' value='cust_host' $checked{'grp2'}{'cust_host'}></td><td valign='top'>$Lang::tr{'fwhost cust addr'}:</td><td><select name='CUST_SRC_HOST' style='min-width:185px;'>";
eff2dbf8 1293 foreach my $key (sort { ncmp($customhost{$a}[0],$customhost{$b}[0]) } keys %customhost) {
8013bd0a
AM
1294 print"<option>$customhost{$key}[0]</option>";
1295 }
1296 print"</select></td></tr>";
1297 }
1298 print"</table>";
1299 #Inner table right
1300 print"</td><td valign='top'><table width='100%' border='0'>";
1301 #OVPN networks
1302 if (! -z $configccdnet){
2e99ab8b 1303 print"<td width='1%'><input type='radio' name='grp2' id='OVPN_CCD_NET' value='ovpn_net' $checked{'grp2'}{'ovpn_net'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='OVPN_CCD_NET' style='min-width:185px;'>";
eff2dbf8 1304 foreach my $key (sort { ncmp($ccdnet{$a}[0],$ccdnet{$b}[0]) } keys %ccdnet)
8013bd0a
AM
1305 {
1306 print"<option value='$ccdnet{$key}[0]'>$ccdnet{$key}[0]</option>";
1307 }
1308 print"</select></td></tr>";
2a81ab0d 1309 }
8013bd0a 1310 #OVPN clients
eff2dbf8 1311 foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost)
2a81ab0d
AM
1312 {
1313 if ($ccdhost{$key}[33] ne ''){
8013bd0a
AM
1314 print"<td width='1%'><input type='radio' name='grp2' value='ovpn_host' $checked{'grp2'}{'ovpn_host'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='OVPN_CCD_HOST' style='min-width:185px;'>" if ($show eq '');
1315 $show='1';
2a81ab0d
AM
1316 print"<option value='$ccdhost{$key}[1]'>$ccdhost{$key}[1]</option>";
1317 }
1318 }
8013bd0a
AM
1319 if ($show eq '1'){$show='';print"</select></td></tr>";}
1320 #OVPN n2n networks
eff2dbf8 1321 foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost) {
2a81ab0d 1322 if($ccdhost{$key}[3] eq 'net'){
bc8ecbd6 1323 print"<td width='1%'><input type='radio' name='grp2' id='OVPN_N2N' value='ovpn_n2n' $checked{'grp2'}{'ovpn_n2n'}></td><td valign='top'>$Lang::tr{'fwhost ovpn_n2n'}:</td><td colspan='3'><select name='OVPN_N2N' style='min-width:185px;'>" if ($show eq '');
8013bd0a 1324 $show='1';
2a81ab0d
AM
1325 print"<option>$ccdhost{$key}[1]</option>";
1326 }
1327 }
8013bd0a
AM
1328 if ($show eq '1'){$show='';print"</select></td></tr>";}
1329 #IPsec networks
eff2dbf8 1330 foreach my $key (sort { ncmp($ipsecconf{$a}[0],$ipsecconf{$b}[0]) } keys %ipsecconf) {
2a81ab0d 1331 if ($ipsecconf{$key}[3] eq 'net'){
2e99ab8b 1332 print"<td valign='top'><input type='radio' name='grp2' id='IPSEC_NET' value='ipsec_net' $checked{'grp2'}{'ipsec_net'}></td><td valign='top'>$Lang::tr{'fwhost ipsec net'}</td><td><select name='IPSEC_NET' style='min-width:185px;'>" if ($show eq '');
8013bd0a 1333 $show='1';
2a81ab0d
AM
1334 print"<option value='$ipsecconf{$key}[1]'>$ipsecconf{$key}[1]</option>";
1335 }
1336 }
8013bd0a
AM
1337 if ($show eq '1'){$show='';print"</select></td></tr>";}
1338 print"</table>";
1339 print"</td></tr></table>";
bc8ecbd6 1340 print"<br><br>";
2a81ab0d 1341 }
bc8ecbd6 1342 print"<table width='100%'>";
43215686 1343 print"<tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' /><input type='hidden' name='oldremark' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='update' value=\"$fwhostsettings{'update'}\"><input type='hidden' name='ACTION' value='savegrp' ></form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='resetgrp'></form></td></table>";
2a81ab0d
AM
1344 &Header::closebox();
1345}
1346sub addservice
1347{
1348 &error;
1349 &showmenu;
1a8fde0e 1350 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservice'});
2a81ab0d
AM
1351 if ($fwhostsettings{'updatesrv'} eq 'on')
1352 {
1353 $fwhostsettings{'oldsrvname'} = $fwhostsettings{'SRV_NAME'};
1354 $fwhostsettings{'oldsrvport'} = $fwhostsettings{'SRV_PORT'};
1355 $fwhostsettings{'oldsrvprot'} = $fwhostsettings{'PROT'};
2aeb4b25 1356 $fwhostsettings{'oldsrvicmp'} = $fwhostsettings{'ICMP'};
2a81ab0d
AM
1357 }
1358 print<<END;
fda8c915 1359 <table width='100%' border='0'><form method='post'>
1a8fde0e 1360 <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 1361 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT' id='protocol' >
2a81ab0d
AM
1362END
1363 foreach ("TCP","UDP","ICMP")
1364 {
1365 if ($_ eq $fwhostsettings{'PROT'})
1366 {
1367 print"<option selected>$_</option>";
1368 }else{
1369 print"<option>$_</option>";
1370 }
1371 }
1372 print<<END;
fda8c915 1373 </select></td></tr></table>
bfc84eb1 1374 <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
1375END
1376 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
86a921ee 1377 print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>";
eff2dbf8 1378 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
2aeb4b25
AM
1379 if ($icmptypes{$key}[0] eq $fwhostsettings{'oldsrvicmp'}){
1380 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1381 }else{
1382 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1383 }
2a81ab0d 1384 }
2a81ab0d 1385 print<<END;
bfc84eb1
AM
1386 </select></td></tr></table></div>
1387 <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 1388 <table width='100%' border='0'><tr><td colspan='6'><br></td></tr>
2a81ab0d
AM
1389 <tr><td colspan='6' align='right'>
1390END
1391 if ($fwhostsettings{'updatesrv'} eq 'on')
1392 {
1393 print<<END;
7f5b2820 1394 <input type='submit' value='$Lang::tr{'update'}'style='min-width:100px;' >
2a81ab0d
AM
1395 <input type='hidden' name='ACTION' value='updateservice'>
1396 <input type='hidden' name='oldsrvname' value='$fwhostsettings{'oldsrvname'}'>
1397 <input type='hidden' name='oldsrvport' value='$fwhostsettings{'oldsrvport'}'>
2aeb4b25
AM
1398 <input type='hidden' name='oldsrvprot' value='$fwhostsettings{'oldsrvprot'}'>
1399 <input type='hidden' name='oldsrvicmp' value='$fwhostsettings{'oldsrvicmp'}'>
1400 </form>
2a81ab0d 1401END
fda8c915 1402 }else{
7f5b2820 1403 print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>";
2a81ab0d
AM
1404 }
1405 print<<END;
7f5b2820 1406 <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr>
2a81ab0d 1407 </table></form>
2a81ab0d
AM
1408END
1409 &Header::closebox();
1410 &viewtableservice;
1411}
1412sub addservicegrp
1413{
1414 &hint;
1415 &error;
1416 &showmenu;
1a8fde0e 1417 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservicegrp'});
2a81ab0d 1418 $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'};
a8b113e7 1419 $fwhostsettings{'oldsrvgrpname'}=$fwhostsettings{'SRVGRP_NAME'};
2a81ab0d
AM
1420 if ($fwhostsettings{'updatesrvgrp'} eq ''){
1421 print<<END;
1422 <table width='100%' border='0'><form method='post'>
1a8fde0e 1423 <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 1424 <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 1425 <tr><td colspan='2'><br></tr>
2a81ab0d
AM
1426 </table>
1427END
1428 }else{
1429 print<<END;
bc8ecbd6 1430 <table width='100%'><form method='post' style='display:inline'>
a8b113e7
AM
1431 <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>
1432 <tr><form method='post'><td width='10%'>$Lang::tr{'remark'}:</td><td colspan='2'><input type='text' name='newsrvrem' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width:98%;'></td><td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldsrvrem' value='$fwhostsettings{'oldsrvgrpremark'}'><input type='hidden' name='ACTION' value='changesrvgrpremark' ></td></tr>
bc8ecbd6 1433 <tr><td colspan='4'><br></td></td></tr>
6c869961 1434 </table></form>
2a81ab0d
AM
1435END
1436 }
1437 if($fwhostsettings{'updatesrvgrp'} eq 'on'){
2a81ab0d 1438 print<<END;
6c869961 1439 <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 1440 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'add'}: </td><td><select name='CUST_SRV' style='min-width:185px;'>
2a81ab0d
AM
1441END
1442 &General::readhasharray("$configsrv", \%customservice);
82b837cf
AM
1443 #Protocols for use in servicegroups
1444 print "<optgroup label='$Lang::tr{'fwhost cust service'}'>";
eff2dbf8 1445 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice)
2a81ab0d
AM
1446 {
1447 print "<option>$customservice{$key}[0]</option>";
1448 }
82b837cf
AM
1449 print "</optgroup>";
1450 print "<optgroup label='$Lang::tr{'protocol'}'>";
1451 print "<option>GRE</option>";
1452 print "<option>AH</option>";
1453 print "<option>ESP</option>";
1454 print "<option>IGMP</option>";
1455 print "<option>IPIP</option>";
1456 print "<option value='IPV6'>IPv6 encap</option>";
1457 print "</optgroup>";
2a81ab0d
AM
1458 print<<END;
1459 </select></td></tr>
5dd84c25 1460 <tr><td colspan='4'><br><br></td></tr>
bc8ecbd6 1461 <tr><td colspan='4'></td></tr>
2a81ab0d
AM
1462 </table>
1463END
1464 }
1465 print<<END;
bc8ecbd6 1466 <table width='100%'>
7f5b2820 1467 <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
1468 </table></form>
1469END
2a81ab0d
AM
1470 &Header::closebox();
1471}
1472# View
1473sub viewtablenet
1474{
1475 if(! -z $confignet){
1476 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'});
1477 &General::readhasharray("$confignet", \%customnetwork);
484269ce
AM
1478 &General::readhasharray("$configgrp", \%customgrp);
1479 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1480 &General::readhasharray("$fwconfiginp", \%fwinp);
1481 &General::readhasharray("$fwconfigout", \%fwout);
2a81ab0d
AM
1482 if (!keys %customnetwork)
1483 {
1484 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1485 }else{
1486 print<<END;
902a15be
AM
1487 <table width='100%' cellspacing='0' class='tbl'>
1488 <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
1489END
1490 }
1491 my $count=0;
902a15be 1492 my $col='';
eff2dbf8 1493 foreach my $key (sort {ncmp($a,$b)} keys %customnetwork) {
2a81ab0d 1494 if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) {
902a15be
AM
1495 print" <tr>";
1496 $col="bgcolor='${Header::colouryellow}'";
2a81ab0d
AM
1497 }elsif ($count % 2)
1498 {
902a15be
AM
1499 $col="bgcolor='$color{'color20'}'";
1500 print" <tr>";# bgcolor='$color{'color20'}'>";
2a81ab0d
AM
1501 }else
1502 {
902a15be
AM
1503 $col="bgcolor='$color{'color22'}'";
1504 print" <tr>";# bgcolor='$color{'color22'}'>";
2a81ab0d 1505 }
72586f0f 1506 my $colnet="$customnetwork{$key}[1]/".&General::subtocidr($customnetwork{$key}[2]);
484269ce 1507 my $netcount=&getnetcount($customnetwork{$key}[0]);
902a15be 1508 print"<td width='20%' $col><form method='post'>$customnetwork{$key}[0]</td><td width='15%' align='center' $col>".&Header::colorize($colnet)."</td><td width='40%' $col>$customnetwork{$key}[3]</td><td align='center' $col>$netcount x</td>";
2a81ab0d 1509 print<<END;
902a15be 1510 <td width='1%' $col><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} />
2a81ab0d
AM
1511 <input type='hidden' name='ACTION' value='editnet'>
1512 <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' />
1513 <input type='hidden' name='IP' value='$customnetwork{$key}[1]' />
1514 <input type='hidden' name='SUBNET' value='$customnetwork{$key}[2]' />
e5a058c1 1515 <input type='hidden' name='NETREMARK' value='$customnetwork{$key}[3]' />
2a81ab0d
AM
1516 </td></form>
1517END
484269ce 1518 if($netcount == '0')
2a81ab0d 1519 {
902a15be 1520 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 1521 }else{
902a15be 1522 print"<td $col></td></tr>";
2a81ab0d
AM
1523 }
1524 $count++;
1525 }
1526 print"</table>";
1527 &Header::closebox();
1528 }
1529
1530}
b119578f
AM
1531sub getcolor
1532{
1533 my $c=shift;
1534 #Check if IP is part of OpenVPN N2N subnet
1535 foreach my $key (sort keys %ccdhost){
1536 if ($ccdhost{$key}[3] eq 'net'){
1537 my ($a,$b) = split("/",$ccdhost{$key}[11]);
1538 if (&General::IpInSubnet($c,$a,$b)){
1539 $tdcolor="style='color:$Header::colourovpn ;'";
1540 return $tdcolor;
1541 }
1542 }
1543 }
1544 #Check if IP is part of OpenVPN dynamic subnet
1545 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
1546 if (&General::IpInSubnet($c,$a,$b)){
1547 $tdcolor="style='color: $Header::colourovpn;'";
1548 return $tdcolor;
1549 }
1550 #Check if IP is part of OpenVPN static subnet
1551 foreach my $key (sort keys %ccdnet){
1552 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1553 $b =&General::iporsubtodec($b);
1554 if (&General::IpInSubnet($c,$a,$b)){
1555 $tdcolor="style='color: $Header::colourovpn;'";
1556 return $tdcolor;
1557 }
1558 }
1559 #Check if IP is part of IPsec RW network
1560 if ($ipsecsettings{'RW_NET'} ne ''){
1561 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1562 $b=&General::iporsubtodec($b);
1563 if (&General::IpInSubnet($c,$a,$b)){
1564 $tdcolor="style='color: $Header::colourvpn;'";
1565 return $tdcolor;
1566 }
1567 }
1568 #Check if IP is part of a IPsec N2N network
1569 foreach my $key (sort keys %ipsecconf){
1570 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1571 if (&General::IpInSubnet($c,$a,$b)){
1572 $tdcolor="style='color: $Header::colourvpn;'";
1573 return $tdcolor;
1574 }
1575 }
1576 $tdcolor='';
1577 return $tdcolor;
1578}
2a81ab0d
AM
1579sub viewtablehost
1580{
1581 if (! -z $confighost){
1582 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust addr'});
1583 &General::readhasharray("$confighost", \%customhost);
b119578f
AM
1584 &General::readhasharray("$configccdnet", \%ccdnet);
1585 &General::readhasharray("$configccdhost", \%ccdhost);
484269ce
AM
1586 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1587 &General::readhasharray("$fwconfiginp", \%fwinp);
1588 &General::readhasharray("$fwconfigout", \%fwout);
1589 &General::readhasharray("$configgrp", \%customgrp);
2a81ab0d
AM
1590 if (!keys %customhost)
1591 {
1592 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1593 }else{
1594 print<<END;
902a15be
AM
1595 <table width='100%' cellspacing='0' class='tbl'>
1596 <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
1597END
1598 }
1599 my $count=0;
902a15be 1600 my $col='';
eff2dbf8 1601 foreach my $key (sort { ncmp ($customhost{$a}[0],$customhost{$b}[0])} keys %customhost) {
2a81ab0d 1602 if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) {
902a15be
AM
1603 print" <tr>";
1604 $col="bgcolor='${Header::colouryellow}'";
1605 }elsif ($count % 2){
1606 print" <tr>";
1607 $col="bgcolor='$color{'color20'}'";
1608 }else{
1609 $col="bgcolor='$color{'color22'}'";
1610 print" <tr>";
1611 }
2a81ab0d 1612 my ($ip,$sub)=split(/\//,$customhost{$key}[2]);
e3580608 1613 $customhost{$key}[4]=~s/\s+//g;
484269ce
AM
1614 my $hostcount=0;
1615 $hostcount=&gethostcount($customhost{$key}[0]);
902a15be 1616 print"<td width='20%' $col>$customhost{$key}[0]</td><td width='20%' align='center' $col ".&getcolor($ip).">".&Header::colorize($ip)."</td><td width='50%' align='left' $col>$customhost{$key}[3]</td><td align='center' $col>$hostcount x</td>";
2a81ab0d 1617 print<<END;
902a15be 1618 <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
1619 <input type='hidden' name='ACTION' value='edithost' />
1620 <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' />
1621 <input type='hidden' name='IP' value='$ip' />
1622 <input type='hidden' name='type' value='$customhost{$key}[1]' />
e3580608 1623 <input type='hidden' name='HOSTREMARK' value='$customhost{$key}[3]' />
2e99ab8b 1624 </form></td>
2a81ab0d 1625END
484269ce 1626 if($hostcount == '0')
2a81ab0d 1627 {
902a15be 1628 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 1629 }else{
902a15be 1630 print"<td width='1%' $col></td></tr>";
2a81ab0d
AM
1631 }
1632 $count++;
1633 }
1634 print"</table>";
1635 &Header::closebox();
1636 }
1637}
1638sub viewtablegrp
1639{
1640 if(! -z "$configgrp"){
1641 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust grp'});
1642 &General::readhasharray("$configgrp", \%customgrp);
1643 &General::readhasharray("$configipsec", \%ipsecconf);
1644 &General::readhasharray("$configccdhost", \%ccdhost);
1645 &General::readhasharray("$configccdnet", \%ccdnet);
1646 &General::readhasharray("$confighost", \%customhost);
1647 &General::readhasharray("$confignet", \%customnetwork);
484269ce
AM
1648 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1649 &General::readhasharray("$fwconfiginp", \%fwinp);
1650 &General::readhasharray("$fwconfigout", \%fwout);
2a81ab0d
AM
1651 my @grp=();
1652 my $helper='';
8f204435 1653 my $count=1;
2a81ab0d
AM
1654 my $grpname;
1655 my $remark;
12dcfbbd 1656 my $number;
2cee2462 1657 my $delflag;
2a81ab0d 1658 if (!keys %customgrp)
484269ce 1659 {
f195a8d7 1660 print "<center><b>$Lang::tr{'fwhost err emptytable'}</b>";
2a81ab0d 1661 }else{
0c2cf9e2 1662 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
2a81ab0d
AM
1663 $count++;
1664 if ($helper ne $customgrp{$key}[0]){
2cee2462 1665 $delflag='0';
eff2dbf8 1666 foreach my $key1 (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
2cee2462
AM
1667 if ($customgrp{$key}[0] eq $customgrp{$key1}[0])
1668 {
1669 $delflag++;
1670 }
d0815ce4 1671 if($delflag > 1){
d13a9363
AM
1672 last;
1673 }
2cee2462 1674 }
8f204435 1675 $number=1;
f195a8d7 1676 if ($customgrp{$key}[2] eq "none"){$customgrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};}
2a81ab0d 1677 $grpname=$customgrp{$key}[0];
6c869961 1678 $remark="$customgrp{$key}[1]";
0c2cf9e2 1679 if($count gt 1){ print"</table>";}
2e99ab8b 1680 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp;";
2a81ab0d 1681 print " <b>$Lang::tr{'remark'}:</b>&nbsp $remark &nbsp " if ($remark ne '');
484269ce
AM
1682 my $netgrpcount=&getnetcount($grpname);
1683 print "<b>$Lang::tr{'used'}:</b> $netgrpcount x";
1684 if($netgrpcount == '0')
2a81ab0d
AM
1685 {
1686 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>";
1687 }
1688 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>";
902a15be 1689 print"<table width='100%' cellspacing='0' class='tbl'><tr><th align='center'><b>Name</b></th><th align='center'><b>$Lang::tr{'ip address'}</b></th><th align='center' width='25%'><b>$Lang::tr{'fwhost type'}</th><th></th></tr>";
2a81ab0d 1690 }
902a15be 1691 my $col='';
2a81ab0d 1692 if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) {
902a15be
AM
1693 print" <tr>";
1694 $col="bgcolor='${Header::colouryellow}'";
6c869961 1695 }elsif ($count %2 == 0){
902a15be
AM
1696 print"<tr>";
1697 $col="bgcolor='$color{'color22'}'";
6c869961 1698 }else{
902a15be
AM
1699 print"<tr>";
1700 $col="bgcolor='$color{'color20'}'";
6c869961 1701 }
2a81ab0d 1702 my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]);
902a15be
AM
1703 if ($ip eq ''){
1704 print"<tr>";
1705 $col="bgcolor='${Header::colouryellow}'";
1706 }
1707 print "<td width='39%' align='left' $col>";
2a81ab0d
AM
1708 if($customgrp{$key}[3] eq 'Standard Network'){
1709 print &get_name($customgrp{$key}[2])."</td>";
1710 }else{
1711 print "$customgrp{$key}[2]</td>";
1712 }
f195a8d7 1713 if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){
902a15be 1714 print "<td align='center' $col>$Lang::tr{'fwhost deleted'}</td><td align='center' $col>$customgrp{$key}[3]</td><td width='1%' $col><form method='post'>";
2a81ab0d 1715 }else{
72586f0f
AM
1716 my ($colip,$colsub) = split("/",$ip);
1717 $ip="$colip/".&General::subtocidr($colsub) if ($colsub);
902a15be 1718 print"<td align='center' $col ".&getcolor($colip).">".&Header::colorize($ip)."</td><td align='center' $col>$customgrp{$key}[3]</td><td width='1%' $col><form method='post'>";
2a81ab0d 1719 }
484269ce 1720 if ($delflag > 1 && $ip ne ''){
2a81ab0d
AM
1721 print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
1722 }
e3580608 1723 print"<input type='hidden' name='ACTION' value='deletegrphost'><input type='hidden' name='grpcnt' value='$customgrp{$key}[4]'><input type='hidden' name='update' value='$fwhostsettings{'update'}'><input type='hidden' name='delhost' value='$grpname,$remark,$customgrp{$key}[2],$customgrp{$key}[3]'></form></td></tr>";
2a81ab0d
AM
1724
1725 $helper=$customgrp{$key}[0];
12dcfbbd 1726 $number++;
2a81ab0d
AM
1727 }
1728 print"</table>";
2a81ab0d
AM
1729 }
1730 &Header::closebox();
1731}
1732
1733}
1734sub viewtableservice
1735{
1736 my $count=0;
3a162dc1 1737 my $srvcount;
2a81ab0d
AM
1738 if(! -z "$configsrv")
1739 {
1740 &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'});
1741 &General::readhasharray("$configsrv", \%customservice);
3a162dc1
AM
1742 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1743 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1744 &General::readhasharray("$fwconfiginp", \%fwinp);
1745 &General::readhasharray("$fwconfigout", \%fwout);
2a81ab0d 1746 print<<END;
902a15be
AM
1747 <table width='100%' cellspacing='0' class='tbl'>
1748 <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 1749END
902a15be 1750 my $col='';
eff2dbf8 1751 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0])} keys %customservice)
2a81ab0d
AM
1752 {
1753 $count++;
1754 if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) {
902a15be
AM
1755 print" <tr>";
1756 $col="bgcolor='${Header::colouryellow}'";
1757 }elsif ($count % 2){
1758 print" <tr>";
1759 $col="bgcolor='$color{'color22'}'";
1760 }else{
1761 print" <tr>";
1762 $col="bgcolor='$color{'color20'}'";
1763 }
2a81ab0d 1764 print<<END;
902a15be 1765 <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 1766END
3a162dc1
AM
1767 #Neuer count
1768 $srvcount=&getsrvcount($customservice{$key}[0]);
86a921ee
AM
1769 if($customservice{$key}[3] eq 'All ICMP-Types'){print $Lang::tr{'fwdfw all icmp'};}
1770 elsif($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
2a81ab0d 1771 print<<END;
902a15be
AM
1772 </td><td align='center' $col>$srvcount x</td>
1773 <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
1774 <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' />
1775 <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' />
2aeb4b25
AM
1776 <input type='hidden' name='PROT' value='$customservice{$key}[2]' />
1777 <input type='hidden' name='ICMP' value='$customservice{$key}[3]' /></form></td>
2a81ab0d 1778END
3a162dc1 1779 if ($srvcount eq '0')
2a81ab0d 1780 {
902a15be 1781 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 1782 }else{
902a15be 1783 print"<td $col></td></tr>";
2a81ab0d
AM
1784 }
1785 }
1786 print"</table>";
1787 &Header::closebox();
1788 }
1789}
1790sub viewtableservicegrp
1791{
1792 my $count=0;
1793 my $grpname;
1794 my $remark;
1795 my $helper;
937d4e08
AM
1796 my $port;
1797 my $protocol;
c7043621 1798 my $delflag;
3a162dc1 1799 my $grpcount=0;
902a15be 1800 my $col='';
2a81ab0d 1801 if (! -z $configsrvgrp){
2a81ab0d
AM
1802 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'});
1803 &General::readhasharray("$configsrvgrp", \%customservicegrp);
937d4e08 1804 &General::readhasharray("$configsrv", \%customservice);
3a162dc1
AM
1805 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1806 &General::readhasharray("$fwconfiginp", \%fwinp);
1807 &General::readhasharray("$fwconfigout", \%fwout);
2a81ab0d 1808 my $number= keys %customservicegrp;
fe2bae3b 1809 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){
2a81ab0d
AM
1810 $count++;
1811 if ($helper ne $customservicegrp{$key}[0]){
3a162dc1
AM
1812 #Get used groupcounter
1813 $grpcount=&getsrvcount($customservicegrp{$key}[0]);
d13a9363 1814 $delflag=0;
eff2dbf8 1815 foreach my $key1 (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) } keys %customservicegrp){
d13a9363
AM
1816 if ($customservicegrp{$key}[0] eq $customservicegrp{$key1}[0])
1817 {
1818 $delflag++;
1819 }
1820 if($delflag > 1){
1821 last;
1822 }
1823 }
2a81ab0d 1824 $grpname=$customservicegrp{$key}[0];
6c869961
AM
1825 if ($customservicegrp{$key}[2] eq "none"){
1826 $customservicegrp{$key}[2]=$Lang::tr{'fwhost empty'};
0b54aaed
AM
1827 $port='';
1828 $protocol='';
6c869961
AM
1829 }
1830 $remark="$customservicegrp{$key}[1]";
2a81ab0d 1831 if($count >=2){print"</table>";}
2e99ab8b
AM
1832 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp; ";
1833 print "<b>$Lang::tr{'remark'}:</b>&nbsp; $remark " if ($remark ne '');
3a162dc1
AM
1834 print "&nbsp; <b>$Lang::tr{'used'}:</b> $grpcount x";
1835 if($grpcount == '0')
2a81ab0d
AM
1836 {
1837 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>";
1838 }
1839 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 1840 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
1841 }
1842 if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) {
902a15be
AM
1843 print"<tr>";
1844 $col="bgcolor='${Header::colouryellow}'";
6c869961 1845 }elsif ($count %2 == 0){
902a15be
AM
1846 print"<tr>";
1847 $col="bgcolor='$color{'color20'}'";
0f869e32 1848 }else{
902a15be
AM
1849 print"<tr>";
1850 $col="bgcolor='$color{'color22'}'";
0f869e32 1851 }
82b837cf
AM
1852 #Set fields if we use protocols in servicegroups
1853 if ($customservicegrp{$key}[2] ne 'TCP' || $customservicegrp{$key}[2] ne 'UDP' || $customservicegrp{$key}[2] ne 'ICMP'){
1854 $port='-';
1855 }
1856 if ($customservicegrp{$key}[2] eq 'GRE'){$protocol='GRE';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} GRE";}
1857 if ($customservicegrp{$key}[2] eq 'ESP'){$protocol='ESP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} ESP";}
1858 if ($customservicegrp{$key}[2] eq 'AH'){$protocol='AH';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} AH";}
1859 if ($customservicegrp{$key}[2] eq 'IGMP'){$protocol='IGMP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IGMP";}
1860 if ($customservicegrp{$key}[2] eq 'IPIP'){$protocol='IPIP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPIP";}
1861 if ($customservicegrp{$key}[2] eq 'IPV6'){$protocol='IPV6';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPv6 encapsulation";}
902a15be 1862 print "<td width='39%' $col>$customservicegrp{$key}[2]</td>";
937d4e08
AM
1863 foreach my $srv (sort keys %customservice){
1864 if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){
1865 $protocol=$customservice{$srv}[2];
1866 $port=$customservice{$srv}[1];
1867 last;
1868 }
1869 }
902a15be 1870 print"<td align='center' $col>$port</td><td align='center' $col>$protocol</td><td width='1%' $col><form method='post'>";
64e822fb 1871 if ($delflag gt '1'){
0f869e32
AM
1872 print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
1873 }
82b837cf 1874 print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'>";
fe2bae3b 1875 if($protocol eq 'TCP' || $protocol eq 'UDP' || $protocol eq 'ICMP'){
3a162dc1 1876 print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2]'></form></td></tr>";
82b837cf 1877 }else{
3a162dc1 1878 print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$protocol'></form></td></tr>";
82b837cf 1879 }
0f869e32 1880 $helper=$customservicegrp{$key}[0];
2a81ab0d
AM
1881 }
1882 print"</table>";
1883 &Header::closebox();
1884 }
1885}
1886# Check
1887sub checkname
1888{
1889 my %hash=%{(shift)};
1890 foreach my $key (keys %hash) {
1891 if($hash{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
1892 return 0;
1893 }
1894 }
1895 return 1;
1896
1897}
f195a8d7
AM
1898sub checkgroup
1899{
3a162dc1 1900 &General::readhasharray("$configsrvgrp", \%customservicegrp );
f195a8d7 1901 my $name=shift;
3a162dc1
AM
1902 foreach my $key (keys %customservicegrp) {
1903 if($customservicegrp{$key}[0] eq $name){
1904 return 0;
1905 }
1906 }
1907 return 1;
1908}
1909sub checkservice
1910{
1911 &General::readhasharray("$configsrv", \%customservice );
1912 my $name=shift;
1913 foreach my $key (keys %customservice) {
1914 if($customservice{$key}[0] eq $name){
f195a8d7
AM
1915 return 0;
1916 }
1917 }
1918 return 1;
1919}
2a81ab0d
AM
1920sub checkip
1921{
1922
1923 my %hash=%{(shift)};
1924 my $a=shift;
1925 foreach my $key (keys %hash) {
1926 if($hash{$key}[$a] eq $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'})){
1927 return 0;
1928 }
1929 }
1930 return 1;
1931}
1932sub checksubnet
1933{
2a81ab0d
AM
1934 my %hash=%{(shift)};
1935 &General::readhasharray("$confignet", \%hash);
1936 foreach my $key (keys %hash) {
1937 if(&General::IpInSubnet($fwhostsettings{'IP'},$hash{$key}[1],$hash{$key}[2]))
1938 {
1939 return 1;
1940 }
1941 }
1942 return 0;
1943}
1944sub checkservicegroup
1945{
1946 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2a81ab0d 1947 #check name
7772ae73 1948 if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'}))
2a81ab0d
AM
1949 {
1950 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1951 return $errormessage;
1952 }
2a81ab0d
AM
1953 #check empty selectbox
1954 if (keys %customservice lt 1)
1955 {
1956 $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>";
1957 }
2a81ab0d
AM
1958 #check if name already exists
1959 if ($fwhostsettings{'updatesrvgrp'} ne 'on'){
1960 foreach my $key (keys %customservicegrp) {
1961 if( $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} ){
1962 $errormessage.=$Lang::tr{'fwhost err grpexist'}."<br>";
1963
1964 }
1965 }
1966 }
1967 #check if service already exists in group
1968 foreach my $key (keys %customservicegrp) {
13e5dda4
AM
1969 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){
1970 $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>";
2a81ab0d 1971 }
13e5dda4 1972 }
2a81ab0d
AM
1973 return $errormessage;
1974}
49da7d79
AM
1975sub checkrulereload
1976{
1977 my $search=shift;
1978 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1979 &General::readhasharray("$fwconfiginp", \%fwinp);
1980 &General::readhasharray("$fwconfigout", \%fwout);
1981
1982 #check if service or servicegroup is used in rules
1983 foreach my $key (keys %fwfwd){
1984 if($search eq $fwfwd{$key}[15]){
1985 &General::firewall_config_changed();
1986 return;
1987 }
1988 }
1989 foreach my $key (keys %fwinp){
1990 if($search eq $fwinp{$key}[15]){
1991 &General::firewall_config_changed();
1992 return;
1993 }
1994 }
1995 foreach my $key (keys %fwout){
1996 if($search eq $fwout{$key}[15]){
1997 &General::firewall_config_changed();
1998 return;
1999 }
2000 }
2001}
2a81ab0d
AM
2002sub error
2003{
2004 if ($errormessage) {
2005 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
2006 print "<class name='base'>$errormessage\n";
2007 print "&nbsp;</class>\n";
2008 &Header::closebox();
2009 }
2010}
2011sub hint
2012{
2013 if ($hint) {
2014 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
2015 print "<class name='base'>$hint\n";
2016 print "&nbsp;</class>\n";
2017 &Header::closebox();
2018 }
2019}
2020sub get_name
2021{
2022 my $val=shift;
2023 &General::setup_default_networks(\%defaultNetworks);
2024 foreach my $network (sort keys %defaultNetworks)
2025 {
2026 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
2027 }
2028}
484269ce
AM
2029sub gethostcount
2030{
2031 my $searchstring=shift;
2032 my $srvcounter=0;
2033 #Count services used in servicegroups
2034 foreach my $key (keys %customgrp) {
2035 if($customgrp{$key}[2] eq $searchstring){
2036 $srvcounter++;
2037 }
2038 }
2039 #Count services used in firewall - config
2040 foreach my $key1 (keys %fwfwd) {
2041 if($fwfwd{$key1}[4] eq $searchstring){
2042 $srvcounter++;
2043 }
2044 if($fwfwd{$key1}[6] eq $searchstring){
2045 $srvcounter++;
2046 }
2047 }
2048 #Count services used in firewall - input
2049 foreach my $key2 (keys %fwinp) {
2050 if($fwinp{$key2}[4] eq $searchstring){
2051 $srvcounter++;
2052 }
2053 if($fwinp{$key2}[6] eq $searchstring){
2054 $srvcounter++;
2055 }
2056 }
2057 #Count services used in firewall - outgoing
2058 foreach my $key3 (keys %fwout) {
2059 if($fwout{$key3}[4] eq $searchstring){
2060 $srvcounter++;
2061 }
2062 if($fwout{$key3}[6] eq $searchstring){
2063 $srvcounter++;
2064 }
2065 }
2066 return $srvcounter;
2067}
2068sub getnetcount
2069{
2070 my $searchstring=shift;
2071 my $srvcounter=0;
2072 #Count services used in servicegroups
2073 foreach my $key (keys %customgrp) {
2074 if($customgrp{$key}[2] eq $searchstring){
2075 $srvcounter++;
2076 }
2077 }
2078 #Count services used in firewall - config
2079 foreach my $key1 (keys %fwfwd) {
2080 if($fwfwd{$key1}[4] eq $searchstring){
2081 $srvcounter++;
2082 }
2083 if($fwfwd{$key1}[6] eq $searchstring){
2084 $srvcounter++;
2085 }
2086 }
2087 #Count services used in firewall - input
2088 foreach my $key2 (keys %fwinp) {
2089 if($fwinp{$key2}[4] eq $searchstring){
2090 $srvcounter++;
2091 }
2092 if($fwinp{$key2}[6] eq $searchstring){
2093 $srvcounter++;
2094 }
2095 }
2096 #Count services used in firewall - outgoing
2097 foreach my $key3 (keys %fwout) {
2098 if($fwout{$key3}[4] eq $searchstring){
2099 $srvcounter++;
2100 }
2101 if($fwout{$key3}[6] eq $searchstring){
2102 $srvcounter++;
2103 }
2104 }
2105 return $srvcounter;
2106}
3a162dc1
AM
2107sub getsrvcount
2108{
2109 my $searchstring=shift;
2110 my $srvcounter=0;
2111 #Count services used in servicegroups
2112 foreach my $key (keys %customservicegrp) {
2113 if($customservicegrp{$key}[2] eq $searchstring){
2114 $srvcounter++;
2115 }
2116 }
2117 #Count services used in firewall - config
2118 foreach my $key1 (keys %fwfwd) {
2119 if($fwfwd{$key1}[15] eq $searchstring){
2120 $srvcounter++;
2121 }
2122 }
2123 #Count services used in firewall - input
2124 foreach my $key2 (keys %fwinp) {
2125 if($fwinp{$key2}[15] eq $searchstring){
2126 $srvcounter++;
2127 }
2128 }
2129 #Count services used in firewall - outgoing
2130 foreach my $key3 (keys %fwout) {
2131 if($fwout{$key3}[15] eq $searchstring){
2132 $srvcounter++;
2133 }
2134 }
2135 return $srvcounter;
2136}
2a81ab0d
AM
2137sub deletefromgrp
2138{
2139 my $target=shift;
2140 my $config=shift;
2141 my %hash=();
2142 &General::readhasharray("$config",\%hash);
2143 foreach my $key (keys %hash) {
2a81ab0d 2144 if($hash{$key}[2] eq $target){
2a81ab0d 2145 delete $hash{$key};
2a81ab0d
AM
2146 }
2147 }
2148 &General::writehasharray("$config",\%hash);
2149
2150}
2151sub plausicheck
2152{
2a81ab0d
AM
2153 my $edit=shift;
2154 #check hostname
d0815ce4 2155 if (!&validhostname($fwhostsettings{'HOSTNAME'}))
2a81ab0d
AM
2156 {
2157 $errormessage=$errormessage.$Lang::tr{'fwhost err name'};
2158 $fwhostsettings{'BLK_IP'}='readonly';
2159 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2160 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2161 }
2162 #check if name collides with CCD Netname
2a81ab0d
AM
2163 &General::readhasharray("$configccdnet", \%ccdnet);
2164 foreach my $key (keys %ccdnet) {
2165 if($ccdnet{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
2166 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdnet'};;
2167 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2168 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2169 last;
2170 }
2171 }
2a81ab0d
AM
2172 #check if IP collides with CCD NetIP
2173 if ($fwhostsettings{'type'} ne 'mac'){
2174 &General::readhasharray("$configccdnet", \%ccdnet);
2175 foreach my $key (keys %ccdnet) {
2176 my $test=(&General::getnetworkip($fwhostsettings{'IP'},&General::iporsubtocidr($fwhostsettings{'SUBNET'})))."/".$fwhostsettings{'SUBNET'};
2177 if($ccdnet{$key}[1] eq $test){
2178 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdipnet'};
2179 $fwhostsettings{'IP'} = $fwhostsettings{'orgip'};
2180 $fwhostsettings{'SUBNET'} = $fwhostsettings{'orgsubnet'};
2181 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2182 last;
2183 }
2184 }
2185 }
2a81ab0d
AM
2186 #check if name collides with CCD Hostname
2187 &General::readhasharray("$configccdhost", \%ccdhost);
2188 foreach my $key (keys %ccdhost) {
2189 my ($ip,$sub)=split(/\//,$ccdhost{$key}[33]);
2190 if($ip eq $fwhostsettings{'IP'}){
2191 $errormessage=$Lang::tr{'fwhost err isccdiphost'};
2192 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2193 last;
2194 }
2195 }
2196 #check if IP collides with CCD HostIP (only hosts)
2197 if ($edit eq 'edithost')
2198 {
2199 foreach my $key (keys %ccdhost) {
2200 if($ccdhost{$key}[1] eq $fwhostsettings{'HOSTNAME'}){
2201 $errormessage=$Lang::tr{'fwhost err isccdhost'};
2202 $fwhostsettings{'IP'} = $fwhostsettings{'orgname'};
2203 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2204 last;
2205 }
2206 }
2207 }
2208 #check if network with this name already exists
2209 &General::readhasharray("$confignet", \%customnetwork);
2210 if (!&checkname(\%customnetwork))
2211 {
2212 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err netexist'};
2213 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2214 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2215 }
2216 #check if network ip already exists
2217 if (!&checkip(\%customnetwork,1))
2218 {
2219 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err net'};
2220 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2221 }
2222 #check if host with this name already exists
2223 &General::readhasharray("$confighost", \%customhost);
2224 if (!&checkname(\%customhost))
2225 {
0013abb0 2226 $errormessage.="<br>".$Lang::tr{'fwhost err hostexist'};
2a81ab0d 2227 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
ed73b87e 2228 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2a81ab0d
AM
2229 }
2230 #check if host with this ip already exists
2231 if (!&checkip(\%customhost,2))
2232 {
2233 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'};
2a81ab0d 2234 }
2a81ab0d
AM
2235 return;
2236}
2237sub getipforgroup
2238{
2239 my $name=$_[0],
2240 my $type=$_[1];
2241 my $value;
2242
2243 #get address from IPSEC NETWORK
2244 if ($type eq 'IpSec Network'){
2245 foreach my $key (keys %ipsecconf) {
2246 if ($ipsecconf{$key}[1] eq $name){
2247 return $ipsecconf{$key}[11];
2248 }
2249 }
2250 &deletefromgrp($name,$configgrp);
2251 }
2252
2253 #get address from IPSEC HOST
2254 if ($type eq 'IpSec Host'){
2255 foreach my $key (keys %ipsecconf) {
2256 if ($ipsecconf{$key}[1] eq $name){
2257 return $ipsecconf{$key}[10];
2258 }
2259 }
2260 &deletefromgrp($name,$configgrp);
2261 }
2262
2263 #get address from ovpn ccd Net-2-Net
2264 if ($type eq 'OpenVPN N-2-N'){
2265 foreach my $key (keys %ccdhost) {
2266 if($ccdhost{$key}[1] eq $name){
2267 my ($a,$b) = split ("/",$ccdhost{$key}[11]);
2268 $b=&General::iporsubtodec($b);
2269 return "$a/$b";
2270 }
2271 }
2272 &deletefromgrp($name,$configgrp);
2273 }
2274
2275 #get address from ovpn ccd static host
2276 if ($type eq 'OpenVPN static host'){
2277 foreach my $key (keys %ccdhost) {
2278 if($ccdhost{$key}[1] eq $name){
2279 my ($a,$b) = split (/\//,$ccdhost{$key}[33]);
2280 $b=&General::iporsubtodec($b);
2281 return "$a/$b";
2282 }
2283 }
2284 &deletefromgrp($name,$configgrp);
2285 }
2286
2287 #get address from ovpn ccd static net
2288 if ($type eq 'OpenVPN static network'){
2289 foreach my $key (keys %ccdnet) {
2290 if ($ccdnet{$key}[0] eq $name){
2291 my ($a,$b) = split (/\//,$ccdnet{$key}[1]);
2292 $b=&General::iporsubtodec($b);
2293 return "$a/$b";
2294 }
2295 }
2296 }
2297
2298 #check custom addresses
2299 if ($type eq 'Custom Host'){
2300 foreach my $key (keys %customhost) {
2301 if ($customhost{$key}[0] eq $name){
f1934a05
AM
2302 my ($ip,$sub) = split("/",$customhost{$key}[2]);
2303 return $ip;
2a81ab0d
AM
2304 }
2305 }
2306 }
2307
2308 ##check custom networks
2309 if ($type eq 'Custom Network'){
2310 foreach my $key (keys %customnetwork) {
2311 if($customnetwork{$key}[0] eq $name){
2312 return $customnetwork{$key}[1]."/".$customnetwork{$key}[2];
2313 }
2314 }
2315 }
2316
2317 #check standard networks
2318 if ($type eq 'Standard Network'){
2319 if ($name =~ /OpenVPN/i){
2320 my %ovpn=();
2321 &General::readhash("${General::swroot}/ovpn/settings",\%ovpn);
2322 return $ovpn{'DOVPN_SUBNET'};
2323 }
2324 if ($name eq 'GREEN'){
2325 my %hash=();
2326 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2327 return $hash{'GREEN_NETADDRESS'}."/".$hash{'GREEN_NETMASK'};
2328 }
2329 if ($name eq 'BLUE'){
2330 my %hash=();
2331 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2332 return $hash{'BLUE_NETADDRESS'}."/".$hash{'BLUE_NETMASK'};
2333 }
2334 if ($name eq 'ORANGE'){
2335 my %hash=();
2336 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2337 return $hash{'ORANGE_NETADDRESS'}."/".$hash{'ORANGE_NETMASK'};
2338 }
2339 if ($name eq 'ALL'){
2340 return "0.0.0.0/0.0.0.0";
2341 }
2342 if ($name =~ /IPsec/i){
2343 my %hash=();
2344 &General::readhash("${General::swroot}/vpn/settings",\%hash);
2345 return $hash{'RW_NET'};
2346 }
2347 }
2348}
fe2bae3b
AM
2349sub decrease
2350{
2a81ab0d
AM
2351 my $grp=$_[0];
2352 &General::readhasharray("$confignet", \%customnetwork);
2353 &General::readhasharray("$confighost", \%customhost);
2354 foreach my $key (sort keys %customgrp ){
2355 if ( ($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Network')){
2356 foreach my $key1 (sort keys %customnetwork){
2357 if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){
8013bd0a 2358 $customnetwork{$key1}[4]=$customnetwork{$key1}[4]-1;
2a81ab0d
AM
2359 last;
2360 }
2361 }
2362 }
2363
2364 if (($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Host')){
2365 foreach my $key2 (sort keys %customhost){
2366 if ($customhost{$key2}[0] eq $customgrp{$key}[2]){
8013bd0a 2367 $customhost{$key2}[4]=$customhost{$key2}[4]-1;
2a81ab0d
AM
2368 last;
2369 }
2370 }
2371
2372 }
2373 }
2374 &General::writehasharray("$confignet", \%customnetwork);
2375 &General::writehasharray("$confighost", \%customhost);
2376}
2377sub decreaseservice
2378{
2379 my $grp=$_[0];
2380 &General::readhasharray("$configsrv", \%customservice);
2381 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2382
2383 foreach my $key (sort keys %customservicegrp){
2384 if ($customservicegrp{$key}[0] eq $grp ){
2385 foreach my $key2 (sort keys %customservice){
2386 if ($customservice{$key2}[0] eq $customservicegrp{$key}[2]){
2387 $customservice{$key2}[4]--;
2388 }
2389 }
2390 }
2391 }
2392 &General::writehasharray("$configsrv", \%customservice);
2393
2394}
a8b113e7
AM
2395sub changenameinfw
2396{
2397 my $old=shift;
2398 my $new=shift;
2399 my $fld=shift;
2400 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2401 &General::readhasharray("$fwconfiginp", \%fwinp);
2402 &General::readhasharray("$fwconfigout", \%fwout);
2403 #Rename group in Firewall-CONFIG
2404 foreach my $key1 (keys %fwfwd) {
2405 if($fwfwd{$key1}[$fld] eq $old){
2406 $fwfwd{$key1}[$fld]=$new;
2407 }
2408 }
2409 &General::writehasharray("$fwconfigfwd", \%fwfwd );
2410 #Rename group in Firewall-INPUT
2411 foreach my $key2 (keys %fwinp) {
2412 if($fwinp{$key2}[$fld] eq $old){
2413 $fwinp{$key2}[$fld]=$new;
2414 }
2415 }
2416 &General::writehasharray("$fwconfiginp", \%fwinp );
2417 #Rename group in Firewall-OUTGOING
2418 foreach my $key3 (keys %fwout) {
2419 if($fwout{$key3}[$fld] eq $old){
2420 $fwout{$key3}[$fld]=$new;
2421 }
2422 }
2423 &General::writehasharray("$fwconfigout", \%fwout );
2424}
2a81ab0d
AM
2425sub checkports
2426{
2427
2428 my %hash=%{(shift)};
2429 #check empty fields
2430 if ($fwhostsettings{'SRV_NAME'} eq '' ){
2431 $errormessage=$Lang::tr{'fwhost err name1'};
2432 }
2433 if ($fwhostsettings{'SRV_PORT'} eq '' && $fwhostsettings{'PROT'} ne 'ICMP'){
2434 $errormessage=$Lang::tr{'fwhost err port'};
2435 }
2436 #check valid name
7772ae73 2437 if (! &validhostname($fwhostsettings{'SRV_NAME'})){
2a81ab0d
AM
2438 $errormessage="<br>".$Lang::tr{'fwhost err name'};
2439 }
2440 #change dashes with :
2441 $fwhostsettings{'SRV_PORT'}=~ tr/-/:/;
2442
2443 if ($fwhostsettings{'SRV_PORT'} eq "*") {
2444 $fwhostsettings{'SRV_PORT'} = "1:65535";
2445 }
2446 if ($fwhostsettings{'SRV_PORT'} =~ /^(\D)\:(\d+)$/) {
2447 $fwhostsettings{'SRV_PORT'} = "1:$2";
2448 }
2449 if ($fwhostsettings{'SRV_PORT'} =~ /^(\d+)\:(\D)$/) {
2450 $fwhostsettings{'SRV_PORT'} = "$1:65535";
2451 }
2452 if($fwhostsettings{'PROT'} ne 'ICMP'){
2453 $errormessage = $errormessage.&General::validportrange($fwhostsettings{'SRV_PORT'}, 'src');
2454 }
2455 # a new service has to have a different name
2456 foreach my $key (keys %hash){
2457 if ($hash{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
2458 $errormessage = "<br>".$Lang::tr{'fwhost err srv exists'};
2459 last;
2460 }
2461 }
2462 return $errormessage;
2463}
2464sub validhostname
2465{
2466 # Checks a hostname against RFC1035
2467 my $hostname = $_[0];
2468
2469 # Each part should be at least two characters in length
2470 # but no more than 63 characters
2471 if (length ($hostname) < 1 || length ($hostname) > 63) {
2472 return 0;}
2473 # Only valid characters are a-z, A-Z, 0-9 and -
d0815ce4 2474 if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-_.;()\/\s]*$/) {
2a81ab0d
AM
2475 return 0;}
2476 # First character can only be a letter or a digit
2477 if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
2478 return 0;}
2479 # Last character can only be a letter or a digit
7772ae73 2480 if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9()]*$/) {
2a81ab0d
AM
2481 return 0;}
2482 return 1;
2483}
6c869961
AM
2484sub validremark
2485{
2486 # Checks a hostname against RFC1035
2487 my $remark = $_[0];
2488 # Each part should be at least two characters in length
2489 # but no more than 63 characters
2490 if (length ($remark) < 1 || length ($remark) > 255) {
2491 return 0;}
2492 # Only valid characters are a-z, A-Z, 0-9 and -
d928d795 2493 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
6c869961
AM
2494 return 0;}
2495 # First character can only be a letter or a digit
2496 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
2497 return 0;}
2498 # Last character can only be a letter or a digit
d928d795 2499 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
6c869961
AM
2500 return 0;}
2501 return 1;
2502}
2a81ab0d
AM
2503&Header::closebigbox();
2504&Header::closepage();