]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/fwhosts.cgi
rules.pl: Flush GEOIPBLOCK chain when the feature will be switched off.
[ipfire-2.x.git] / html / cgi-bin / fwhosts.cgi
CommitLineData
2a81ab0d
AM
1#!/usr/bin/perl
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5bee9a9d 5# Copyright (C) 2013 Alexander Marx <amarx@ipfire.org> #
2a81ab0d
AM
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
2a81ab0d
AM
21use strict;
22
23# enable only the following on debugging purpose
dadffbf7
AM
24#use warnings;
25
eff2dbf8 26use Sort::Naturally;
2a81ab0d
AM
27use CGI::Carp 'fatalsToBrowser';
28no warnings 'uninitialized';
29require '/var/ipfire/general-functions.pl';
4313aa18
SS
30require "/var/ipfire/geoip-functions.pl";
31require "/usr/lib/firewall/firewall-lib.pl";
2a81ab0d
AM
32require "${General::swroot}/lang.pl";
33require "${General::swroot}/header.pl";
34
35my %fwhostsettings=();
36my %customnetwork=();
37my %customhost=();
38my %customgrp=();
39my %customservice=();
40my %customservicegrp=();
4313aa18 41my %customgeoipgrp=();
2a81ab0d
AM
42my %ccdnet=();
43my %ccdhost=();
44my %ipsecconf=();
45my %icmptypes=();
46my %color=();
47my %defaultNetworks=();
48my %mainsettings=();
49my %ownnet=();
50my %ipsecsettings=();
62fc8511
AM
51my %fwfwd=();
52my %fwinp=();
3a162dc1 53my %fwout=();
b119578f 54my %ovpnsettings=();
f620fa34 55my %netsettings=();
2a81ab0d
AM
56
57my $errormessage;
58my $hint;
59my $update=0;
60my $confignet = "${General::swroot}/fwhosts/customnetworks";
61my $confighost = "${General::swroot}/fwhosts/customhosts";
62my $configgrp = "${General::swroot}/fwhosts/customgroups";
63my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
64my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
65my $configipsec = "${General::swroot}/vpn/config";
66my $configsrv = "${General::swroot}/fwhosts/customservices";
67my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
4313aa18 68my $configgeoipgrp = "${General::swroot}/fwhosts/customgeoipgrp";
6d8eb5de
AM
69my $fwconfigfwd = "${General::swroot}/firewall/config";
70my $fwconfiginp = "${General::swroot}/firewall/input";
3a162dc1 71my $fwconfigout = "${General::swroot}/firewall/outgoing";
b119578f 72my $configovpn = "${General::swroot}/ovpn/settings";
b119578f 73my $configipsecrw = "${General::swroot}/vpn/settings";
2a81ab0d
AM
74
75unless (-e $confignet) { system("touch $confignet"); }
76unless (-e $confighost) { system("touch $confighost"); }
77unless (-e $configgrp) { system("touch $configgrp"); }
78unless (-e $configsrv) { system("touch $configsrv"); }
79unless (-e $configsrvgrp) { system("touch $configsrvgrp"); }
4313aa18 80unless (-e $configgeoipgrp) { system("touch $configgeoipgrp"); }
2a81ab0d
AM
81
82&General::readhash("${General::swroot}/main/settings", \%mainsettings);
83&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
84&General::readhash("${General::swroot}/ethernet/settings", \%ownnet);
b119578f
AM
85&General::readhash("$configovpn", \%ovpnsettings);
86&General::readhasharray("$configipsec", \%ipsecconf);
87&General::readhash("$configipsecrw", \%ipsecsettings);
f620fa34 88&General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
2a81ab0d
AM
89&Header::getcgihash(\%fwhostsettings);
90
91&Header::showhttpheaders();
4d74a20d 92&Header::openpage($Lang::tr{'fwhost menu'}, 1, '');
2a81ab0d
AM
93&Header::openbigbox('100%', 'center');
94
2e99ab8b
AM
95#### JAVA SCRIPT ####
96print<<END;
97<script>
fda8c915
AM
98 var PROTOCOLS_WITH_PORTS = ["TCP", "UDP"];
99 var update_protocol = function() {
100 var protocol = \$("#protocol").val();
101
102 if (protocol === undefined)
103 return;
104
105 // Check if we are dealing with a protocol, that knows ports.
106 if (\$.inArray(protocol, PROTOCOLS_WITH_PORTS) >= 0) {
107 \$("#PORT").show();
c9493d6c 108 \$("#PROTOKOLL").hide();
fda8c915
AM
109 } else {
110 \$("#PORT").hide();
fda8c915 111 \$("#PROTOKOLL").show();
fda8c915
AM
112 }
113 };
114
2e99ab8b 115 \$(document).ready(function() {
fda8c915 116 var protocol = \$("#protocol").val();
fda8c915
AM
117 \$("#protocol").change(update_protocol);
118 update_protocol();
5f037986
AM
119 // Automatically select radio buttons when corresponding
120 // dropdown menu changes.
121 \$("select").change(function() {
122 var id = \$(this).attr("name");
123 \$('#' + id).prop("checked", true);
124 });
2e99ab8b
AM
125 });
126</script>
127END
128
2a81ab0d
AM
129## ACTION ####
130# Update
131if ($fwhostsettings{'ACTION'} eq 'updatenet' )
132{
133 &General::readhasharray("$confignet", \%customnetwork);
134 foreach my $key (keys %customnetwork)
135 {
136 if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'})
137 {
138 $fwhostsettings{'orgname'} = $customnetwork{$key}[0];
139 $fwhostsettings{'orgip'} = $customnetwork{$key}[1];
140 $fwhostsettings{'orgsub'} = $customnetwork{$key}[2];
e5a058c1
AM
141 $fwhostsettings{'netremark'} = $customnetwork{$key}[3];
142 $fwhostsettings{'count'} = $customnetwork{$key}[4];
2a81ab0d
AM
143 delete $customnetwork{$key};
144
145 }
146 }
147 &General::writehasharray("$confignet", \%customnetwork);
148 $fwhostsettings{'actualize'} = 'on';
149 $fwhostsettings{'ACTION'} = 'savenet';
150}
151if ($fwhostsettings{'ACTION'} eq 'updatehost')
152{
153 my ($ip,$subnet);
154 &General::readhasharray("$confighost", \%customhost);
155 foreach my $key (keys %customhost)
156 {
157 if($customhost{$key}[0] eq $fwhostsettings{'orgname'})
158 {
2a81ab0d
AM
159 if ($customhost{$key}[1] eq 'ip'){
160 ($ip,$subnet) = split (/\//,$customhost{$key}[2]);
161 }else{
162 $ip = $customhost{$key}[2];
163 }
164 $fwhostsettings{'orgip'} = $ip;
e3580608 165 $fwhostsettings{'count'} = $customhost{$key}[4];
2a81ab0d 166 delete $customhost{$key};
5e970723 167 &General::writehasharray("$confighost", \%customhost);
2a81ab0d
AM
168 }
169 }
2a81ab0d 170 $fwhostsettings{'actualize'} = 'on';
5e970723 171 if($fwhostsettings{'orgip'}){
2a81ab0d 172 $fwhostsettings{'ACTION'} = 'savehost';
5e970723
AM
173 }else{
174 $fwhostsettings{'ACTION'} = $Lang::tr{'fwhost newhost'};
175 }
2a81ab0d
AM
176}
177if ($fwhostsettings{'ACTION'} eq 'updateservice')
178{
179 my $count=0;
180 my $needrules=0;
181 $errormessage=&checkports(\%customservice);
3a162dc1
AM
182 if ($fwhostsettings{'oldsrvname'} ne $fwhostsettings{'SRV_NAME'} && !&checkgroup($fwhostsettings{'SRV_NAME'})){
183 $errormessage=$Lang::tr{'fwhost err grpexist'};
184 }
2a81ab0d
AM
185 if (!$errormessage){
186 &General::readhasharray("$configsrv", \%customservice);
187 foreach my $key (keys %customservice)
188 {
189 if ($customservice{$key}[0] eq $fwhostsettings{'oldsrvname'})
190 {
2a81ab0d
AM
191 delete $customservice{$key};
192 &General::writehasharray("$configsrv", \%customservice);
193 last;
194 }
195 }
196 if ($fwhostsettings{'PROT'} ne 'ICMP'){
197 $fwhostsettings{'ICMP_TYPES'}='BLANK';
198 }
199 my $key1 = &General::findhasharraykey(\%customservice);
2aeb4b25
AM
200 #find out short ICMP-TYPE
201 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
202 foreach my $key (keys %icmptypes){
203 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){
204 $fwhostsettings{'ICMP_TYPES'}=$icmptypes{$key}[0];
205 }
206 }
2a81ab0d
AM
207 foreach my $i (0 .. 4) { $customservice{$key1}[$i] = "";}
208 $customservice{$key1}[0] = $fwhostsettings{'SRV_NAME'};
209 $customservice{$key1}[1] = $fwhostsettings{'SRV_PORT'};
210 $customservice{$key1}[2] = $fwhostsettings{'PROT'};
211 $customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'};
2a81ab0d 212 &General::writehasharray("$configsrv", \%customservice);
ed73b87e 213 #check if we need to update firewallrules
bfee206c
AM
214 if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){
215 if ( ! -z $fwconfigfwd ){
216 &General::readhasharray("$fwconfigfwd", \%fwfwd);
217 foreach my $key (sort keys %fwfwd){
218 if ($fwfwd{$key}[15] eq $fwhostsettings{'oldsrvname'}){
219 $fwfwd{$key}[15] = $fwhostsettings{'SRV_NAME'};
220 }
221 }
222 &General::writehasharray("$fwconfigfwd", \%fwfwd);
bfee206c
AM
223 }
224 if ( ! -z $fwconfiginp ){
225 &General::readhasharray("$fwconfiginp", \%fwinp);
226 foreach my $line (sort keys %fwinp){
227 if ($fwfwd{$line}[15] eq $fwhostsettings{'oldsrvname'}){
228 $fwfwd{$line}[15] = $fwhostsettings{'SRV_NAME'};
229 }
230 }
231 &General::writehasharray("$fwconfiginp", \%fwinp);
232 }
3a162dc1
AM
233 if ( ! -z $fwconfigout ){
234 &General::readhasharray("$fwconfigout", \%fwout);
235 foreach my $line (sort keys %fwout){
236 if ($fwout{$line}[15] eq $fwhostsettings{'oldsrvname'}){
237 $fwout{$line}[15] = $fwhostsettings{'SRV_NAME'};
238 }
239 }
240 &General::writehasharray("$fwconfigout", \%fwout);
241 }
bfac6bd4
AM
242 #check if we need to update groups
243 &General::readhasharray("$configsrvgrp", \%customservicegrp);
244 foreach my $key (sort keys %customservicegrp){
245 if($customservicegrp{$key}[2] eq $fwhostsettings{'oldsrvname'}){
246 $customservicegrp{$key}[2] = $fwhostsettings{'SRV_NAME'};
49da7d79 247 &checkrulereload($customservicegrp{$key}[0]);
bfac6bd4
AM
248 }
249 }
250 &General::writehasharray("$configsrvgrp", \%customservicegrp);
2aeb4b25 251 }
49da7d79 252 &checkrulereload($fwhostsettings{'SRV_NAME'});
2a81ab0d
AM
253 $fwhostsettings{'SRV_NAME'} = '';
254 $fwhostsettings{'SRV_PORT'} = '';
255 $fwhostsettings{'PROT'} = '';
2aeb4b25
AM
256 $fwhostsettings{'ICMP'} = '';
257 $fwhostsettings{'oldsrvicmp'} = '';
3a162dc1 258 $fwhostsettings{'updatesrv'} = '';
2a81ab0d
AM
259 }else{
260 $fwhostsettings{'SRV_NAME'} = $fwhostsettings{'oldsrvname'};
261 $fwhostsettings{'SRV_PORT'} = $fwhostsettings{'oldsrvport'};
262 $fwhostsettings{'PROT'} = $fwhostsettings{'oldsrvprot'};
2aeb4b25 263 $fwhostsettings{'ICMP'} = $fwhostsettings{'oldsrvicmp'};
2a81ab0d
AM
264 $fwhostsettings{'updatesrv'}= 'on';
265 }
2a81ab0d
AM
266 &addservice;
267}
268# save
269if ($fwhostsettings{'ACTION'} eq 'savenet' )
270{
2a81ab0d
AM
271 my $needrules=0;
272 if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
2a81ab0d
AM
273 #check if all fields are set
274 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
275 {
276 $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
277 &addnet;
278 &viewtablenet;
279 }else{
280 #check valid ip
281 if (!&General::validipandmask($fwhostsettings{'IP'}."/".$fwhostsettings{'SUBNET'}))
282 {
283 $errormessage=$errormessage.$Lang::tr{'fwhost err addr'};
284 $fwhostsettings{'BLK_HOST'} ='readonly';
285 $fwhostsettings{'NOCHECK'} ='false';
286 $fwhostsettings{'error'} ='on';
287 }
e5a058c1
AM
288 #check remark
289 if ($fwhostsettings{'NETREMARK'} ne '' && !&validremark($fwhostsettings{'NETREMARK'})){
290 $errormessage=$Lang::tr{'fwhost err remark'};
291 $fwhostsettings{'error'} ='on';
292 }
2a81ab0d
AM
293 #check if subnet is sigle host
294 if(&General::iporsubtocidr($fwhostsettings{'SUBNET'}) eq '32')
295 {
296 $errormessage=$errormessage.$Lang::tr{'fwhost err sub32'};
2a81ab0d
AM
297 }
298 if($fwhostsettings{'error'} ne 'on'){
3928f52b
AM
299 my $fullip="$fwhostsettings{'IP'}/".&General::iporsubtocidr($fwhostsettings{'SUBNET'});
300 $errormessage=$errormessage.&General::checksubnets($fwhostsettings{'HOSTNAME'},$fullip,"");
2a81ab0d
AM
301 }
302 #only check plausi when no error till now
303 if (!$errormessage){
304 &plausicheck("editnet");
305 }
2a81ab0d
AM
306 if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage)
307 {
308 $fwhostsettings{'actualize'} = '';
309 my $key = &General::findhasharraykey (\%customnetwork);
310 foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
311 $customnetwork{$key}[0] = $fwhostsettings{'orgname'} ;
312 $customnetwork{$key}[1] = $fwhostsettings{'orgip'} ;
313 $customnetwork{$key}[2] = $fwhostsettings{'orgsub'};
f80db6a4 314 $customnetwork{$key}[3] = $fwhostsettings{'orgnetremark'};
2a81ab0d
AM
315 &General::writehasharray("$confignet", \%customnetwork);
316 undef %customnetwork;
d8cc4439 317 }
2a81ab0d
AM
318 if (!$errormessage){
319 &General::readhasharray("$confignet", \%customnetwork);
320 if ($fwhostsettings{'ACTION'} eq 'updatenet'){
321 if ($fwhostsettings{'update'} == '0'){
322 foreach my $key (keys %customnetwork) {
323 if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}){
2a81ab0d
AM
324 delete $customnetwork{$key};
325 last;
326 }
327 }
328 }
329 }
330 #get count if actualize is 'on'
331 if($fwhostsettings{'actualize'} eq 'on'){
332 $fwhostsettings{'actualize'} = '';
2a81ab0d 333 #check if we need to reload rules
484269ce 334 if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){
2a81ab0d
AM
335 $needrules='on';
336 }
337 if ($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
338 #check if we need to update groups
339 &General::readhasharray("$configgrp", \%customgrp);
340 foreach my $key (sort keys %customgrp){
341 if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){
342 $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'};
343 last;
344 }
345 }
346 &General::writehasharray("$configgrp", \%customgrp);
62fc8511
AM
347 #check if we need to update firewallrules
348 if ( ! -z $fwconfigfwd ){
349 &General::readhasharray("$fwconfigfwd", \%fwfwd);
350 foreach my $line (sort keys %fwfwd){
351 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
352 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
353 }
354 if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){
355 $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'};
356 }
357 }
358 &General::writehasharray("$fwconfigfwd", \%fwfwd);
359 }
360 if ( ! -z $fwconfiginp ){
361 &General::readhasharray("$fwconfiginp", \%fwinp);
362 foreach my $line (sort keys %fwinp){
363 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
364 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
365 }
366 }
367 &General::writehasharray("$fwconfiginp", \%fwinp);
368 }
2a81ab0d 369 }
d8cc4439 370 }
2a81ab0d 371 my $key = &General::findhasharraykey (\%customnetwork);
484269ce 372 foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
2a81ab0d
AM
373 $fwhostsettings{'SUBNET'} = &General::iporsubtocidr($fwhostsettings{'SUBNET'});
374 $customnetwork{$key}[0] = $fwhostsettings{'HOSTNAME'};
375 #convert ip when leading '0' in byte
e5a058c1
AM
376 $fwhostsettings{'IP'} =&General::ip2dec($fwhostsettings{'IP'});
377 $fwhostsettings{'IP'} =&General::dec2ip($fwhostsettings{'IP'});
2a81ab0d
AM
378 $customnetwork{$key}[1] = &General::getnetworkip($fwhostsettings{'IP'},$fwhostsettings{'SUBNET'}) ;
379 $customnetwork{$key}[2] = &General::iporsubtodec($fwhostsettings{'SUBNET'}) ;
e5a058c1 380 $customnetwork{$key}[3] = $fwhostsettings{'NETREMARK'};
2a81ab0d
AM
381 &General::writehasharray("$confignet", \%customnetwork);
382 $fwhostsettings{'IP'}=$fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
383 undef %customnetwork;
384 $fwhostsettings{'HOSTNAME'}='';
385 $fwhostsettings{'IP'}='';
386 $fwhostsettings{'SUBNET'}='';
e5a058c1 387 $fwhostsettings{'NETREMARK'}='';
2a81ab0d
AM
388 #check if an edited net affected groups and need to reload rules
389 if ($needrules eq 'on'){
0e430797 390 &General::firewall_config_changed();
2a81ab0d
AM
391 }
392 &addnet;
393 &viewtablenet;
d8cc4439 394 }else{
3928f52b 395 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2a81ab0d
AM
396 &addnet;
397 &viewtablenet;
398 }
399 }
2a81ab0d
AM
400}
401if ($fwhostsettings{'ACTION'} eq 'savehost')
402{
2a81ab0d
AM
403 my $needrules=0;
404 if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
2a81ab0d 405 $fwhostsettings{'SUBNET'}='32';
2a81ab0d
AM
406 #check if all fields are set
407 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
408 {
409 $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
410 $fwhostsettings{'ACTION'} = 'edithost';
411 }else{
92e4ae9d 412 if($fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){
2a81ab0d 413 $fwhostsettings{'type'} = 'mac';
92e4ae9d 414 }elsif($fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
2a81ab0d
AM
415 $fwhostsettings{'type'} = 'ip';
416 }else{
417 $fwhostsettings{'type'} = '';
418 $errormessage=$Lang::tr{'fwhost err ipmac'};
419 }
e3580608
AM
420 #check remark
421 if ($fwhostsettings{'HOSTREMARK'} ne '' && !&validremark($fwhostsettings{'HOSTREMARK'})){
422 $errormessage=$Lang::tr{'fwhost err remark'};
423 }
2a81ab0d
AM
424 #CHECK IP-PART
425 if ($fwhostsettings{'type'} eq 'ip'){
426 #check for subnet
427 if (rindex($fwhostsettings{'IP'},'/') eq '-1' ){
428 if($fwhostsettings{'type'} eq 'ip' && !&General::validipandmask($fwhostsettings{'IP'}."/32"))
429 {
430 $errormessage.=$errormessage.$Lang::tr{'fwhost err ip'};
431 $fwhostsettings{'error'}='on';
432 }
2a81ab0d
AM
433 }elsif(rindex($fwhostsettings{'IP'},'/') ne '-1' ){
434 $errormessage=$errormessage.$Lang::tr{'fwhost err ipwithsub'};
435 $fwhostsettings{'error'}='on';
436 }
437 #check if net or broadcast
438 my @tmp= split (/\./,$fwhostsettings{'IP'});
439 if (($tmp[3] eq "0") || ($tmp[3] eq "255")){
440 $errormessage=$Lang::tr{'fwhost err hostip'};
441 }
442 }
2a81ab0d
AM
443 #only check plausi when no error till now
444 if (!$errormessage){
445 &plausicheck("edithost");
446 }
2a81ab0d
AM
447 if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){
448 $fwhostsettings{'actualize'} = '';
449 my $key = &General::findhasharraykey (\%customhost);
484269ce 450 foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";}
2a81ab0d
AM
451 $customhost{$key}[0] = $fwhostsettings{'orgname'} ;
452 $customhost{$key}[1] = $fwhostsettings{'type'} ;
453 if($customhost{$key}[1] eq 'ip'){
454 $customhost{$key}[2] = $fwhostsettings{'orgip'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
455 }else{
456 $customhost{$key}[2] = $fwhostsettings{'orgip'};
457 }
f80db6a4 458 $customhost{$key}[3] = $fwhostsettings{'orgremark'};
2a81ab0d
AM
459 &General::writehasharray("$confighost", \%customhost);
460 undef %customhost;
2a81ab0d 461 }
2a81ab0d
AM
462 if (!$errormessage){
463 #get count if host was edited
464 if($fwhostsettings{'actualize'} eq 'on'){
484269ce 465 if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){
2a81ab0d
AM
466 $needrules='on';
467 }
468 if($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
469 #check if we need to update groups
470 &General::readhasharray("$configgrp", \%customgrp);
471 foreach my $key (sort keys %customgrp){
472 if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){
473 $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'};
2a81ab0d
AM
474 }
475 }
476 &General::writehasharray("$configgrp", \%customgrp);
62fc8511
AM
477 #check if we need to update firewallrules
478 if ( ! -z $fwconfigfwd ){
479 &General::readhasharray("$fwconfigfwd", \%fwfwd);
480 foreach my $line (sort keys %fwfwd){
481 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
482 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
483 }
484 if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){
485 $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'};
486 }
487 }
488 &General::writehasharray("$fwconfigfwd", \%fwfwd);
489 }
490 if ( ! -z $fwconfiginp ){
491 &General::readhasharray("$fwconfiginp", \%fwinp);
492 foreach my $line (sort keys %fwinp){
493 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
494 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
495 }
496 }
497 &General::writehasharray("$fwconfiginp", \%fwinp);
498 }
2a81ab0d 499 }
2a81ab0d
AM
500 }
501 my $key = &General::findhasharraykey (\%customhost);
484269ce 502 foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";}
2a81ab0d
AM
503 $customhost{$key}[0] = $fwhostsettings{'HOSTNAME'} ;
504 $customhost{$key}[1] = $fwhostsettings{'type'} ;
505 if ($fwhostsettings{'type'} eq 'ip'){
506 #convert ip when leading '0' in byte
507 $fwhostsettings{'IP'}=&General::ip2dec($fwhostsettings{'IP'});
508 $fwhostsettings{'IP'}=&General::dec2ip($fwhostsettings{'IP'});
509 $customhost{$key}[2] = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
510 }else{
511 $customhost{$key}[2] = $fwhostsettings{'IP'};
512 }
e3580608 513 $customhost{$key}[3] = $fwhostsettings{'HOSTREMARK'};
2a81ab0d 514 &General::writehasharray("$confighost", \%customhost);
2a81ab0d
AM
515 undef %customhost;
516 $fwhostsettings{'HOSTNAME'}='';
517 $fwhostsettings{'IP'}='';
518 $fwhostsettings{'type'}='';
e3580608 519 $fwhostsettings{'HOSTREMARK'}='';
2a81ab0d
AM
520 #check if we need to update rules while host was edited
521 if($needrules eq 'on'){
0e430797 522 &General::firewall_config_changed();
2a81ab0d
AM
523 }
524 &addhost;
525 &viewtablehost;
526 }else{
527 &addhost;
528 &viewtablehost;
529 }
2a81ab0d 530 }
2a81ab0d
AM
531}
532if ($fwhostsettings{'ACTION'} eq 'savegrp')
533{
484269ce 534 my $grp=$fwhostsettings{'grp_name'};
2a81ab0d
AM
535 my $rem=$fwhostsettings{'remark'};
536 my $count;
537 my $type;
538 my $updcounter='off';
539 my @target;
540 my @newgrp;
541 &General::readhasharray("$configgrp", \%customgrp);
542 &General::readhasharray("$confignet", \%customnetwork);
543 &General::readhasharray("$confighost", \%customhost);
484269ce
AM
544 &General::readhasharray("$fwconfigfwd", \%fwfwd);
545 &General::readhasharray("$fwconfiginp", \%fwinp);
546 &General::readhasharray("$fwconfigout", \%fwout);
6c869961
AM
547 #check name
548 if (!&validhostname($grp)){$errormessage.=$Lang::tr{'fwhost err name'};}
f195a8d7 549 #check existing name
3a162dc1 550 if (!&checkgroup($grp) && $fwhostsettings{'update'} ne 'on'){$errormessage.=$Lang::tr{'fwhost err grpexist'};}
6c869961
AM
551 #check remark
552 if ($rem ne '' && !&validremark($rem) && $fwhostsettings{'update'} ne 'on'){
553 $errormessage.=$Lang::tr{'fwhost err remark'};
2a81ab0d 554 }
6c869961
AM
555 if ($fwhostsettings{'update'} eq 'on'){
556 #check standard networks
557 if ($fwhostsettings{'grp2'} eq 'std_net'){
558 @target=$fwhostsettings{'DEFAULT_SRC_ADR'};
559 $type='Standard Network';
560 }
561 #check custom networks
562 if ($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} ne ''){
563 @target=$fwhostsettings{'CUST_SRC_NET'};
564 $updcounter='net';
565 $type='Custom Network';
566 }elsif($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} eq ''){
567 $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>";
568 $fwhostsettings{'grp_name'}='';
569 $fwhostsettings{'remark'}='';
570 }
571 #check custom addresses
572 if ($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} ne ''){
573 @target=$fwhostsettings{'CUST_SRC_HOST'};
574 $updcounter='host';
575 $type='Custom Host';
576 }elsif($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} eq ''){
577 $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>";
578 $fwhostsettings{'grp_name'}='';
579 $fwhostsettings{'remark'}='';
580 }
581 #get address from ovpn ccd static net
582 if ($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} ne ''){
583 @target=$fwhostsettings{'OVPN_CCD_NET'};
584 $type='OpenVPN static network';
585 }elsif($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} eq ''){
586 $errormessage=$Lang::tr{'fwhost err groupempty'};
587 $fwhostsettings{'grp_name'}='';
588 $fwhostsettings{'remark'}='';
589 }
590 #get address from ovpn ccd static host
591 if ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} ne ''){
592 @target=$fwhostsettings{'OVPN_CCD_HOST'};
593 $type='OpenVPN static host';
594 }elsif ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} eq ''){
595 $errormessage=$Lang::tr{'fwhost err groupempty'};
596 }
597 #get address from ovpn ccd Net-2-Net
598 if ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} ne ''){
599 @target=$fwhostsettings{'OVPN_N2N'};
600 $type='OpenVPN N-2-N';
601 }elsif ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} eq ''){
602 $errormessage=$Lang::tr{'fwhost err groupempty'};
603 $fwhostsettings{'grp_name'}='';
604 $fwhostsettings{'remark'}='';
605 }
606 #get address from IPSEC HOST
607 if ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} ne ''){
608 @target=$fwhostsettings{'IPSEC_HOST'};
609 $type='IpSec Host';
610 }elsif ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} eq ''){
611 $errormessage=$Lang::tr{'fwhost err groupempty'};
612 $fwhostsettings{'grp_name'}='';
613 $fwhostsettings{'remark'}='';
614 }
615 #get address from IPSEC NETWORK
616 if ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} ne ''){
617 @target=$fwhostsettings{'IPSEC_NET'};
618 $type='IpSec Network';
619 }elsif ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} eq ''){
620 $errormessage=$Lang::tr{'fwhost err groupempty'};
621 $fwhostsettings{'grp_name'}='';
622 $fwhostsettings{'remark'}='';
623 }
624 #check if host/net exists in grp
625
626 my $test="$grp,$fwhostsettings{'oldremark'},@target";
627 foreach my $key (keys %customgrp) {
628 my $test1="$customgrp{$key}[0],$customgrp{$key}[1],$customgrp{$key}[2]";
629 if ($test1 eq $test){
630 $errormessage=$Lang::tr{'fwhost err isingrp'};
631 $fwhostsettings{'update'} = 'on';
632 }
2a81ab0d
AM
633 }
634 }
6c869961 635
2a81ab0d
AM
636 if (!$errormessage){
637 #on first save, we have an empty @target, so fill it with nothing
638 my $targetvalues=@target;
639 if ($targetvalues == '0'){
6c869961 640 @target="none";
2a81ab0d
AM
641 }
642 #on update, we have to delete the dummy entry
2a81ab0d 643 foreach my $key (keys %customgrp){
6c869961 644 if ($customgrp{$key}[0] eq $grp && $customgrp{$key}[2] eq "none"){
2a81ab0d
AM
645 delete $customgrp{$key};
646 last;
647 }
648 }
649 &General::writehasharray("$configgrp", \%customgrp);
650 &General::readhasharray("$configgrp", \%customgrp);
2a81ab0d
AM
651 #create array with new lines
652 foreach my $line (@target){
653 push (@newgrp,"$grp,$rem,$line");
654 }
655 #append new entries
656 my $key = &General::findhasharraykey (\%customgrp);
657 foreach my $line (@newgrp){
484269ce 658 foreach my $i (0 .. 3) { $customgrp{$key}[$i] = "";}
2a81ab0d
AM
659 my ($a,$b,$c,$d) = split (",",$line);
660 $customgrp{$key}[0] = $a;
661 $customgrp{$key}[1] = $b;
662 $customgrp{$key}[2] = $c;
663 $customgrp{$key}[3] = $type;
2a81ab0d
AM
664 }
665 &General::writehasharray("$configgrp", \%customgrp);
2a81ab0d 666 #update counter in Host/Net
2a81ab0d 667 $fwhostsettings{'update'}='on';
2a81ab0d 668 }
2a81ab0d 669 #check if ruleupdate is needed
484269ce
AM
670 my $netgrpcount=0;
671 $netgrpcount=&getnetcount($grp);
672 if($netgrpcount > 0 )
2a81ab0d 673 {
0e430797 674 &General::firewall_config_changed();
2a81ab0d
AM
675 }
676 &addgrp;
677 &viewtablegrp;
2a81ab0d 678}
4313aa18
SS
679if ($fwhostsettings{'ACTION'} eq 'savegeoipgrp')
680{
681 my $grp=$fwhostsettings{'grp_name'};
682 my $rem=$fwhostsettings{'remark'};
683 my $count;
684 my $type;
685 my @target;
686 my @newgrp;
687 &General::readhasharray("$configgeoipgrp", \%customgeoipgrp);
688
689 # Check for existing group name.
690 if (!&checkgroup($grp) && $fwhostsettings{'update'} ne 'on'){
691 $errormessage = $Lang::tr{'fwhost err grpexist'};
692 }
693
694 # Check remark.
695 if ($rem ne '' && !&validremark($rem) && $fwhostsettings{'update'} ne 'on'){
696 $errormessage = $Lang::tr{'fwhost err remark'};
697 }
698
699 if ($fwhostsettings{'update'} eq 'on'){
700 @target=$fwhostsettings{'COUNTRY_CODE'};
701 $type='GeoIP Group';
702
703 #check if host/net exists in grp
704 my $test="$grp,$fwhostsettings{'oldremark'},@target";
705 foreach my $key (keys %customgeoipgrp) {
706 my $test1="$customgeoipgrp{$key}[0],$customgeoipgrp{$key}[1],$customgeoipgrp{$key}[2]";
707 if ($test1 eq $test){
708 $errormessage=$Lang::tr{'fwhost err isingrp'};
709 $fwhostsettings{'update'} = 'on';
710 }
711 }
712 }
713
714 if (!$errormessage){
715 #on first save, we have an empty @target, so fill it with nothing
716 my $targetvalues=@target;
717 if ($targetvalues == '0'){
718 @target="none";
719 }
720 #on update, we have to delete the dummy entry
721 foreach my $key (keys %customgeoipgrp){
722 if ($customgeoipgrp{$key}[0] eq $grp && $customgeoipgrp{$key}[2] eq "none"){
723 delete $customgeoipgrp{$key};
724 last;
725 }
726 }
727 &General::writehasharray("$configgeoipgrp", \%customgeoipgrp);
728 &General::readhasharray("$configgeoipgrp", \%customgeoipgrp);
729 #create array with new lines
730 foreach my $line (@target){
731 push (@newgrp,"$grp,$rem,$line");
732 }
733 #append new entries
734 my $key = &General::findhasharraykey (\%customgeoipgrp);
735 foreach my $line (@newgrp){
736 foreach my $i (0 .. 3) { $customgeoipgrp{$key}[$i] = "";}
737 my ($a,$b,$c,$d) = split (",",$line);
738 $customgeoipgrp{$key}[0] = $a;
739 $customgeoipgrp{$key}[1] = $b;
740 $customgeoipgrp{$key}[2] = $c;
741 $customgeoipgrp{$key}[3] = $type;
742 }
743 &General::writehasharray("$configgeoipgrp", \%customgeoipgrp);
744 #update counter in Host/Net
745 $fwhostsettings{'update'}='on';
746 }
747 #check if ruleupdate is needed
748 my $geoipgrpcount=0;
749 $geoipgrpcount=&getgeoipcount($grp);
750 if($geoipgrpcount > 0 )
751 {
752 &General::firewall_config_changed();
753 }
754 &addgeoipgrp;
755 &viewtablegeoipgrp;
756}
2a81ab0d
AM
757if ($fwhostsettings{'ACTION'} eq 'saveservice')
758{
759 my $ICMP;
2a81ab0d 760 &General::readhasharray("$configsrv", \%customservice );
3a162dc1 761 &General::readhasharray("$configgrp", \%customgrp);
2a81ab0d 762 $errormessage=&checkports(\%customservice);
2a81ab0d
AM
763 if ($fwhostsettings{'PROT'} eq 'ICMP'){
764 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
765 foreach my $key (keys %icmptypes){
766 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){
767 $ICMP=$icmptypes{$key}[0];
768 }
769 }
770 }
86a921ee 771 if($ICMP eq ''){$ICMP=$fwhostsettings{'ICMP_TYPES'};}
3a162dc1
AM
772 if ($fwhostsettings{'PROT'} ne 'ICMP'){$ICMP='BLANK';}
773 #Check if a group with the same name already exists
774 if (!&checkgroup($fwhostsettings{'SRV_NAME'})){
775 $errormessage = $Lang::tr{'fwhost err grpexist'};
776 }
2a81ab0d 777 if (!$errormessage){
2a81ab0d
AM
778 my $key = &General::findhasharraykey (\%customservice);
779 foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";}
780 $customservice{$key}[0] = $fwhostsettings{'SRV_NAME'};
781 $customservice{$key}[1] = $fwhostsettings{'SRV_PORT'};
782 $customservice{$key}[2] = $fwhostsettings{'PROT'};
783 $customservice{$key}[3] = $ICMP;
2a81ab0d
AM
784 &General::writehasharray("$configsrv", \%customservice );
785 #reset fields
786 $fwhostsettings{'SRV_NAME'}='';
787 $fwhostsettings{'SRV_PORT'}='';
788 $fwhostsettings{'PROT'}='';
789 $fwhostsettings{'ICMP_TYPES'}='';
2a81ab0d 790 }
2a81ab0d 791 &addservice;
2a81ab0d
AM
792}
793if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
794{
795 my $prot;
796 my $port;
49192c7b
AM
797 my $tcpcounter=0;
798 my $udpcounter=0;
2a81ab0d
AM
799 &General::readhasharray("$configsrvgrp", \%customservicegrp );
800 &General::readhasharray("$configsrv", \%customservice );
2a81ab0d 801 $errormessage=&checkservicegroup;
82b837cf
AM
802 #Check if we have more than 15 services from one Protocol in the group
803 #iptables can only handle 15 ports/portranges via multiport
49192c7b
AM
804 foreach my $key (keys %customservicegrp){
805 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){
806 foreach my $key1 (keys %customservice){
807 $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0];
7db6ad6a 808 $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i;
49192c7b 809 $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0];
7db6ad6a 810 $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i;
49192c7b
AM
811 }
812 }
813 }
85abeb13 814 if ($tcpcounter > 14){
49192c7b
AM
815 $errormessage=$Lang::tr{'fwhost err maxservicetcp'};
816 }
85abeb13 817 if ($udpcounter > 14){
49192c7b
AM
818 $errormessage=$Lang::tr{'fwhost err maxserviceudp'};
819 }
820 $tcpcounter=0;
821 $udpcounter=0;
bc912c6e
AM
822 #check remark
823 if ($fwhostsettings{'SRVGRP_REMARK'} ne '' && !&validremark($fwhostsettings{'SRVGRP_REMARK'})){
49192c7b 824 $errormessage .= $Lang::tr{'fwhost err remark'};
bc912c6e 825 }
3a162dc1
AM
826 #Check if there is already a service with the same name
827 if(!&checkservice($fwhostsettings{'SRVGRP_NAME'})){
828 $errormessage .= $Lang::tr{'fwhost err srv exists'};
829 }
2a81ab0d
AM
830 if (!$errormessage){
831 #on first save, we have to enter a dummy value
6c869961
AM
832 if ($fwhostsettings{'CUST_SRV'} eq ''){
833 $fwhostsettings{'CUST_SRV'}='none';
834 }
2a81ab0d
AM
835 #on update, we have to delete the dummy entry
836 foreach my $key (keys %customservicegrp){
aeefcc9c 837 if ($customservicegrp{$key}[2] eq 'none' && $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){
2a81ab0d
AM
838 delete $customservicegrp{$key};
839 last;
840 }
841 }
842 &General::writehasharray("$configsrvgrp", \%customservicegrp );
843 #check if remark has also changed
844 if ($fwhostsettings{'SRVGRP_REMARK'} ne $fwhostsettings{'oldsrvgrpremark'} && $fwhostsettings{'updatesrvgrp'} eq 'on')
845 {
846 foreach my $key (keys %customservicegrp)
847 {
848 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvgrpremark'})
849 {
850 $customservicegrp{$key}[1]='';
851 $customservicegrp{$key}[1]=$fwhostsettings{'SRVGRP_REMARK'};
3a162dc1 852 }
2a81ab0d
AM
853 }
854 }
2a81ab0d 855 my $key = &General::findhasharraykey (\%customservicegrp);
3a162dc1 856 foreach my $i (0 .. 2) { $customservice{$key}[$i] = "";}
2a81ab0d
AM
857 $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'};
858 $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'};
859 $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'};
2a81ab0d
AM
860 &General::writehasharray("$configsrvgrp", \%customservicegrp );
861 $fwhostsettings{'updatesrvgrp'}='on';
862 }
49da7d79 863 &checkrulereload($fwhostsettings{'SRVGRP_NAME'});
2a81ab0d
AM
864 &addservicegrp;
865 &viewtableservicegrp;
866}
867# edit
868if ($fwhostsettings{'ACTION'} eq 'editnet')
869{
870 &addnet;
871 &viewtablenet;
872}
873if ($fwhostsettings{'ACTION'} eq 'edithost')
874{
875 &addhost;
876 &viewtablehost;
877}
878if ($fwhostsettings{'ACTION'} eq 'editgrp')
879{
880 $fwhostsettings{'update'}='on';
881 &addgrp;
882 &viewtablegrp;
883}
4313aa18
SS
884if ($fwhostsettings{'ACTION'} eq 'editgeoipgrp')
885{
886 $fwhostsettings{'update'}='on';
887 &addgeoipgrp;
888 &viewtablegeoipgrp;
889}
2a81ab0d
AM
890if ($fwhostsettings{'ACTION'} eq 'editservice')
891{
892 $fwhostsettings{'updatesrv'}='on';
893 &addservice;
894}
895if ($fwhostsettings{'ACTION'} eq 'editservicegrp')
896{
897 $fwhostsettings{'updatesrvgrp'} = 'on';
898 &addservicegrp;
899 &viewtableservicegrp;
900}
901# reset
902if ($fwhostsettings{'ACTION'} eq 'resetnet')
903{
904 $fwhostsettings{'HOSTNAME'} ="";
905 $fwhostsettings{'IP'} ="";
906 $fwhostsettings{'SUBNET'} ="";
907 &showmenu;
908}
909if ($fwhostsettings{'ACTION'} eq 'resethost')
910{
911 $fwhostsettings{'HOSTNAME'} ="";
912 $fwhostsettings{'IP'} ="";
913 $fwhostsettings{'type'} ="";
914 &showmenu;
915}
43215686
AM
916if ($fwhostsettings{'ACTION'} eq 'resetgrp')
917{
918 $fwhostsettings{'grp_name'} ="";
919 $fwhostsettings{'remark'} ="";
920 &showmenu;
921}
4313aa18
SS
922if ($fwhostsettings{'ACTION'} eq 'resetgeoipgrp')
923{
924 $fwhostsettings{'grp_name'} ="";
925 $fwhostsettings{'remark'} ="";
926 &showmenu;
927}
2a81ab0d
AM
928# delete
929if ($fwhostsettings{'ACTION'} eq 'delnet')
930{
931 &General::readhasharray("$confignet", \%customnetwork);
932 foreach my $key (keys %customnetwork) {
933 if($fwhostsettings{'key'} eq $customnetwork{$key}[0]){
934 delete $customnetwork{$key};
935 &General::writehasharray("$confignet", \%customnetwork);
936 last;
937 }
938 }
939 &addnet;
940 &viewtablenet;
941}
942if ($fwhostsettings{'ACTION'} eq 'delhost')
943{
944 &General::readhasharray("$confighost", \%customhost);
945 foreach my $key (keys %customhost) {
946 if($fwhostsettings{'key'} eq $customhost{$key}[0]){
947 delete $customhost{$key};
948 &General::writehasharray("$confighost", \%customhost);
949 last;
950 }
951 }
952 &addhost;
953 &viewtablehost;
2a81ab0d
AM
954}
955if ($fwhostsettings{'ACTION'} eq 'deletegrphost')
956{
3f8fe51e
AM
957 my $grpremark;
958 my $grpname;
2a81ab0d
AM
959 &General::readhasharray("$configgrp", \%customgrp);
960 foreach my $key (keys %customgrp){
961 if($customgrp{$key}[0].",".$customgrp{$key}[1].",".$customgrp{$key}[2].",".$customgrp{$key}[3] eq $fwhostsettings{'delhost'}){
3f8fe51e
AM
962 $grpname=$customgrp{$key}[0];
963 $grpremark=$customgrp{$key}[1];
aeefcc9c
AM
964 #check if we delete the last entry, then generate dummy
965 if ($fwhostsettings{'last'} eq 'on'){
966 $customgrp{$key}[1] = '';
967 $customgrp{$key}[2] = 'none';
968 $customgrp{$key}[3] = '';
969 $fwhostsettings{'last'}='';
970 last;
971 }else{
972 delete $customgrp{$key};
973 }
2a81ab0d
AM
974 }
975 }
976 &General::writehasharray("$configgrp", \%customgrp);
aeefcc9c 977 &General::firewall_config_changed();
3f8fe51e
AM
978 if ($fwhostsettings{'update'} eq 'on'){
979 $fwhostsettings{'remark'}= $grpremark;
980 $fwhostsettings{'grp_name'}=$grpname;
981 }
2a81ab0d
AM
982 &addgrp;
983 &viewtablegrp;
984}
4313aa18
SS
985if ($fwhostsettings{'ACTION'} eq 'deletegeoipgrpentry')
986{
987 my $grpremark;
988 my $grpname;
989 &General::readhasharray("$configgeoipgrp", \%customgeoipgrp);
990 foreach my $key (keys %customgeoipgrp){
991 if($customgeoipgrp{$key}[0].",".$customgeoipgrp{$key}[1].",".$customgeoipgrp{$key}[2].",".$customgeoipgrp{$key}[3] eq $fwhostsettings{'delentry'}){
992 $grpname=$customgeoipgrp{$key}[0];
993 $grpremark=$customgeoipgrp{$key}[1];
994 #check if we delete the last entry, then generate dummy
995 if ($fwhostsettings{'last'} eq 'on'){
996 $customgeoipgrp{$key}[1] = '';
997 $customgeoipgrp{$key}[2] = 'none';
998 $customgeoipgrp{$key}[3] = '';
999 $fwhostsettings{'last'}='';
1000 last;
1001 }else{
1002 delete $customgeoipgrp{$key};
1003 }
1004 }
1005 }
1006 &General::writehasharray("$configgeoipgrp", \%customgeoipgrp);
1007 &General::firewall_config_changed();
1008 if ($fwhostsettings{'update'} eq 'on'){
1009 $fwhostsettings{'remark'}= $grpremark;
1010 $fwhostsettings{'grp_name'}=$grpname;
1011 }
1012 &addgeoipgrp;
1013 &viewtablegeoipgrp;
1014}
1015
2a81ab0d
AM
1016if ($fwhostsettings{'ACTION'} eq 'delgrp')
1017{
1018 &General::readhasharray("$configgrp", \%customgrp);
1019 &decrease($fwhostsettings{'grp_name'});
1020 foreach my $key (sort keys %customgrp)
1021 {
1022 if($customgrp{$key}[0] eq $fwhostsettings{'grp_name'})
1023 {
1024 delete $customgrp{$key};
1025 }
1026 }
1027 &General::writehasharray("$configgrp", \%customgrp);
1028 $fwhostsettings{'grp_name'}='';
1029 &addgrp;
1030 &viewtablegrp;
1031}
4313aa18
SS
1032if ($fwhostsettings{'ACTION'} eq 'delgeoipgrp')
1033{
1034 &General::readhasharray("$configgeoipgrp", \%customgeoipgrp);
1035 &decrease($fwhostsettings{'grp_name'});
1036 foreach my $key (sort keys %customgeoipgrp)
1037 {
1038 if($customgeoipgrp{$key}[0] eq $fwhostsettings{'grp_name'})
1039 {
1040 delete $customgeoipgrp{$key};
1041 }
1042 }
1043 &General::writehasharray("$configgeoipgrp", \%customgeoipgrp);
1044 $fwhostsettings{'grp_name'}='';
1045 &addgeoipgrp;
1046 &viewtablegeoipgrp;
1047}
2a81ab0d
AM
1048if ($fwhostsettings{'ACTION'} eq 'delservice')
1049{
1050 &General::readhasharray("$configsrv", \%customservice);
1051 foreach my $key (keys %customservice) {
1052 if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
2a81ab0d
AM
1053 delete $customservice{$key};
1054 &General::writehasharray("$configsrv", \%customservice);
1055 last;
1056 }
1057 }
1058 $fwhostsettings{'SRV_NAME'}='';
1059 $fwhostsettings{'SRV_PORT'}='';
1060 $fwhostsettings{'PROT'}='';
1061 &addservice;
1062}
1063if ($fwhostsettings{'ACTION'} eq 'delservicegrp')
1064{
1065 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1066 &decreaseservice($fwhostsettings{'SRVGRP_NAME'});
1067 foreach my $key (sort keys %customservicegrp)
1068 {
1069 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
1070 {
1071 delete $customservicegrp{$key};
1072 }
1073 }
1074 &General::writehasharray("$configsrvgrp", \%customservicegrp);
1075 $fwhostsettings{'SRVGRP_NAME'}='';
1076 &addservicegrp;
1077 &viewtableservicegrp;
1078}
1079if ($fwhostsettings{'ACTION'} eq 'delgrpservice')
1080{
3f8fe51e
AM
1081 my $grpname;
1082 my $grpremark;
2a81ab0d 1083 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2a81ab0d 1084 foreach my $key (keys %customservicegrp){
3a162dc1 1085 if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2] eq $fwhostsettings{'delsrvfromgrp'})
2a81ab0d 1086 {
3f8fe51e
AM
1087 $grpname=$customservicegrp{$key}[0];
1088 $grpremark=$customservicegrp{$key}[1];
aeefcc9c
AM
1089 if($fwhostsettings{'last'} eq 'on'){
1090 $customservicegrp{$key}[2] = 'none';
1091 $fwhostsettings{'last'} = '';
1092 last;
1093 }else{
1094 delete $customservicegrp{$key};
1095 }
2a81ab0d
AM
1096 }
1097 }
1098 &General::writehasharray("$configsrvgrp", \%customservicegrp);
0e430797 1099 &General::firewall_config_changed();
3f8fe51e 1100 if ($fwhostsettings{'updatesrvgrp'} eq 'on'){
3f8fe51e
AM
1101 $fwhostsettings{'SRVGRP_NAME'}=$grpname;
1102 $fwhostsettings{'SRVGRP_REMARK'}=$grpremark;
1103 }
2a81ab0d
AM
1104 &addservicegrp;
1105 &viewtableservicegrp;
2a81ab0d
AM
1106}
1107if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'})
1108{
1109 &addnet;
1110 &viewtablenet;
1111}
1112if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newhost'})
1113{
1114 &addhost;
1115 &viewtablehost;
1116}
1117if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgrp'})
1118{
1119 &addgrp;
1120 &viewtablegrp;
1121}
4313aa18
SS
1122if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgeoipgrp'})
1123{
1124 &addgeoipgrp;
1125 &viewtablegeoipgrp;
1126}
2a81ab0d
AM
1127if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservice'})
1128{
1129 &addservice;
1130}
1131if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservicegrp'})
1132{
1133 &addservicegrp;
1134 &viewtableservicegrp;
1135}
6c869961
AM
1136if ($fwhostsettings{'ACTION'} eq 'changegrpremark')
1137{
1138 &General::readhasharray("$configgrp", \%customgrp);
d0815ce4 1139 if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){
6c869961
AM
1140 foreach my $key (sort keys %customgrp)
1141 {
6c869961
AM
1142 if($customgrp{$key}[0] eq $fwhostsettings{'grp'} && $customgrp{$key}[1] eq $fwhostsettings{'oldrem'})
1143 {
6c869961
AM
1144 $customgrp{$key}[1]='';
1145 $customgrp{$key}[1]=$fwhostsettings{'newrem'};
1146 }
1147 }
1148 &General::writehasharray("$configgrp", \%customgrp);
1149 $fwhostsettings{'update'}='on';
6c869961
AM
1150 $fwhostsettings{'remark'}=$fwhostsettings{'newrem'};
1151 }else{
1152 $errormessage=$Lang::tr{'fwhost err remark'};
1153 $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'};
1154 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1155 $fwhostsettings{'update'} = 'on';
1156 }
1157 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1158 &addgrp;
1159 &viewtablegrp;
1160}
4313aa18
SS
1161if ($fwhostsettings{'ACTION'} eq 'changegeoipgrpremark')
1162{
1163 &General::readhasharray("$configgeoipgrp", \%customgeoipgrp);
1164 if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){
1165 foreach my $key (sort keys %customgeoipgrp)
1166 {
1167 if($customgeoipgrp{$key}[0] eq $fwhostsettings{'grp'} && $customgeoipgrp{$key}[1] eq $fwhostsettings{'oldrem'})
1168 {
1169 $customgeoipgrp{$key}[1]='';
1170 $customgeoipgrp{$key}[1]=$fwhostsettings{'newrem'};
1171 }
1172 }
1173 &General::writehasharray("$configgeoipgrp", \%customgeoipgrp);
1174 $fwhostsettings{'update'}='on';
1175 $fwhostsettings{'remark'}=$fwhostsettings{'newrem'};
1176 }else{
1177 $errormessage=$Lang::tr{'fwhost err remark'};
1178 $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'};
1179 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1180 $fwhostsettings{'update'} = 'on';
1181 }
1182 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1183 &addgeoipgrp;
1184 &viewtablegeoipgrp;
1185}
6c869961
AM
1186if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark')
1187{
1188 &General::readhasharray("$configsrvgrp", \%customservicegrp );
d0815ce4 1189 if ($fwhostsettings{'oldsrvrem'} ne $fwhostsettings{'newsrvrem'} && (&validremark($fwhostsettings{'newsrvrem'}) || $fwhostsettings{'newsrvrem'} eq '')){
6c869961
AM
1190 foreach my $key (sort keys %customservicegrp)
1191 {
6c869961
AM
1192 if($customservicegrp{$key}[0] eq $fwhostsettings{'srvgrp'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvrem'})
1193 {
6c869961
AM
1194 $customservicegrp{$key}[1]='';
1195 $customservicegrp{$key}[1]=$fwhostsettings{'newsrvrem'};
1196 }
1197 }
1198 &General::writehasharray("$configsrvgrp", \%customservicegrp);
1199 $fwhostsettings{'updatesrvgrp'}='on';
6c869961 1200 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'newsrvrem'};
82b837cf
AM
1201 }elsif($fwhostsettings{'oldsrvrem'} eq $fwhostsettings{'newsrvrem'}){
1202 &addservicegrp;
1203 &viewtableservicegrp;
6c869961
AM
1204 }else{
1205 $errormessage=$Lang::tr{'fwhost err remark'};
1206 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'oldsrvrem'};
1207 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1208 $fwhostsettings{'updatesrvgrp'} = 'on';
1209 }
1210 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1211 &addservicegrp;
1212 &viewtableservicegrp;
1213}
a8b113e7
AM
1214if ($fwhostsettings{'ACTION'} eq 'changesrvgrpname')
1215{
1216 &General::readhasharray("$configsrvgrp", \%customservicegrp );
1217 if ($fwhostsettings{'oldsrvgrpname'} ne $fwhostsettings{'srvgrp'}){
1218 #Check new groupname
1219 if (!&validhostname($fwhostsettings{'srvgrp'})){
1220 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1221 }
1222 if (!$errormessage){
1223 #Rename group in customservicegroup
1224 foreach my $key (keys %customservicegrp) {
1225 if($customservicegrp{$key}[0] eq $fwhostsettings{'oldsrvgrpname'}){
1226 $customservicegrp{$key}[0]=$fwhostsettings{'srvgrp'};
1227 }
1228 }
1229 &General::writehasharray("$configsrvgrp", \%customservicegrp );
1230 #change name in FW Rules
1231 &changenameinfw($fwhostsettings{'oldsrvgrpname'},$fwhostsettings{'srvgrp'},15);
1232 }
1233 }
1234 &addservicegrp;
1235 &viewtableservicegrp;
1236}
1237if ($fwhostsettings{'ACTION'} eq 'changegrpname')
1238{
1239 &General::readhasharray("$configgrp", \%customgrp );
1240 if ($fwhostsettings{'oldgrpname'} ne $fwhostsettings{'grp'}){
1241 #Check new groupname
1242 if (!&validhostname($fwhostsettings{'grp'})){
1243 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1244 }
1245 if (!$errormessage){
1246 #Rename group in customservicegroup
1247 foreach my $key (keys %customgrp) {
1248 if($customgrp{$key}[0] eq $fwhostsettings{'oldgrpname'}){
1249 $customgrp{$key}[0]=$fwhostsettings{'grp'};
1250 }
1251 }
1252 &General::writehasharray("$configgrp", \%customgrp );
1253 #change name in FW Rules
1254 &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},6);
1255 }
1256 }
1257 &addgrp;
1258 &viewtablegrp;
1259}
4313aa18
SS
1260if ($fwhostsettings{'ACTION'} eq 'changegeoipgrpname')
1261{
1262 &General::readhasharray("$configgeoipgrp", \%customgeoipgrp );
1263 if ($fwhostsettings{'oldgrpname'} ne $fwhostsettings{'grp'}){
1264 #Check new groupname
1265 if (!&validhostname($fwhostsettings{'grp'})){
1266 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1267 }
1268 if (!$errormessage){
1269 # Rename group.
1270 foreach my $key (keys %customgeoipgrp) {
1271 if($customgeoipgrp{$key}[0] eq $fwhostsettings{'oldgrpname'}){
1272 $customgeoipgrp{$key}[0]=$fwhostsettings{'grp'};
1273 }
1274 }
1275 &General::writehasharray("$configgeoipgrp", \%customgeoipgrp );
1276 #change name in FW Rules
1277 &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},6);
1278 }
1279 }
1280 &addgeoipgrp;
1281 &viewtablegeoipgrp;
1282}
2a81ab0d
AM
1283### VIEW ###
1284if($fwhostsettings{'ACTION'} eq '')
1285{
1286 &showmenu;
1287}
1288### FUNCTIONS ###
0e430797 1289sub showmenu {
4d74a20d 1290 &Header::openbox('100%', 'left',);
43d8be09 1291 print "$Lang::tr{'fwhost welcome'}";
2a81ab0d 1292 print<<END;
2e99ab8b 1293 <br><br><table border='0' width='100%'>
4313aa18 1294 <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'}' ><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newgeoipgrp'}' ></form></td>
2e99ab8b 1295 <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 1296 <tr><td colspan='6'></td></tr></table>
2a81ab0d 1297END
2a81ab0d
AM
1298 &Header::closebox();
1299
1300}
1301# Add
1302sub addnet
1303{
1304 &error;
1305 &showmenu;
1306 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addnet'});
1307 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
f80db6a4 1308 $fwhostsettings{'orgnetremark'}=$fwhostsettings{'NETREMARK'};
2a81ab0d 1309 print<<END;
902a15be 1310 <table border='0' width='100%' >
2e99ab8b 1311 <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
1312 <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>
1313 <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 1314 <tr><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='NETREMARK' value='$fwhostsettings{'NETREMARK'}' style='width: 98.5%;'></td></tr>
bc8ecbd6 1315 <tr><td colspan='6'><br></td></tr><tr>
2a81ab0d
AM
1316END
1317 if ($fwhostsettings{'ACTION'} eq 'editnet' || $fwhostsettings{'error'} eq 'on')
1318 {
902a15be 1319 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 1320 }else{
902a15be
AM
1321 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'>";
1322 }
2e99ab8b 1323 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
1324 &Header::closebox();
1325}
1326sub addhost
1327{
1328 &error;
1329 &showmenu;
1330 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addhost'});
1331 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
f80db6a4 1332 $fwhostsettings{'orgremark'}=$fwhostsettings{'HOSTREMARK'};
2a81ab0d 1333 print<<END;
bc8ecbd6 1334 <table width='100%'>
2e99ab8b 1335 <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 1336 <tr><td>IP/MAC:</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='17'></td></tr>
8013bd0a 1337 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='HOSTREMARK' value='$fwhostsettings{'HOSTREMARK'}' style='width:98%;'></td></tr>
bc8ecbd6 1338 <tr><td colspan='5'><br></td></tr><tr>
2a81ab0d
AM
1339END
1340
1341 if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on')
1342 {
1343
8013bd0a 1344 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 1345 }else{
2e99ab8b 1346 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 1347 }
2e99ab8b 1348 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
1349 &Header::closebox();
1350}
1351sub addgrp
1352{
1353 &hint;
1354 &error;
1355 &showmenu;
1356 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addgrp'});
1357 &General::setup_default_networks(\%defaultNetworks);
8013bd0a
AM
1358 &General::readhasharray("$configccdnet", \%ccdnet);
1359 &General::readhasharray("$confignet", \%customnetwork);
1360 &General::readhasharray("$configccdhost", \%ccdhost);
1361 &General::readhasharray("$confighost", \%customhost);
1362 &General::readhasharray("$configipsec", \%ipsecconf);
1363
2a81ab0d 1364 my %checked=();
8013bd0a 1365 my $show='';
2a81ab0d
AM
1366 $checked{'check1'}{'off'} = '';
1367 $checked{'check1'}{'on'} = '';
1368 $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED';
1369 $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'};
a8b113e7 1370 $fwhostsettings{'oldgrpname'}=$fwhostsettings{'grp_name'};
6c869961
AM
1371 my $grp=$fwhostsettings{'grp_name'};
1372 my $rem=$fwhostsettings{'remark'};
2a81ab0d
AM
1373 if ($fwhostsettings{'update'} eq ''){
1374 print<<END;
bc8ecbd6
AM
1375 <table width='100%' border='0'>
1376 <tr>
7429ee78
AM
1377 <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td>
1378 <td><form method='post'><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' size='30'></td>
bc8ecbd6
AM
1379 </tr>
1380 <tr>
f620fa34 1381 <td>$Lang::tr{'remark'}:</td>
7429ee78 1382 <td ><input type='TEXT' name='remark' value='$fwhostsettings{'remark'}' style='width: 99%;'></td>
bc8ecbd6
AM
1383 </tr>
1384 <tr>
1385 <td colspan='2'><br></td>
1386 </tr>
1387 </table>
2a81ab0d
AM
1388END
1389 }else{
1390 print<<END;
7429ee78 1391 <table width='100%' border='0'><form method='post'>
bc8ecbd6 1392 <tr>
7429ee78
AM
1393 <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td>
1394 <td style='width:30%;'><input type='TEXT' name='grp' value='$fwhostsettings{'grp_name'}' size='30'></td>
bc8ecbd6
AM
1395 <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>
1396 <td></td></form>
1397 </tr>
1398 <tr><form method='post' style='display:inline'>
1399 <td>$Lang::tr{'remark'}:</td>
7429ee78 1400 <td colspan='2' style='width:98%;'><input type='TEXT' name='newrem' value='$fwhostsettings{'remark'}' style='width:98%;'></td>
a72ae687 1401 <td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='grp' value='$fwhostsettings{'grp_name'}'><input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='ACTION' value='changegrpremark' ></td>
bc8ecbd6
AM
1402 </tr>
1403 </table></form>
1404 <br><br>
2a81ab0d 1405END
2a81ab0d
AM
1406 }
1407 if ($fwhostsettings{'update'} eq 'on'){
2a81ab0d 1408 print<<END;
8013bd0a
AM
1409 <form method='post'><input type='hidden' name='remark' value='$rem'><input type='hidden' name='grp_name' value='$grp'>
1410 <table width='100%' border='0'>
1411 <tr><td width=50% valign='top'>
f620fa34
AM
1412 <table width='90%' border='0'>
1413 <tr>
1414 <td style='width:15em;'>
1415 <label>
1416 <input type='radio' name='grp2' value='std_net' id='DEFAULT_SRC_ADR' checked>
1417 $Lang::tr{'fwhost stdnet'}
1418 </label>
1419 </td>
1420 <td style='text-align:right;'>
a72ae687 1421 <select name='DEFAULT_SRC_ADR' style='width:16em;'>
2a81ab0d
AM
1422END
1423 foreach my $network (sort keys %defaultNetworks)
1424 {
1425 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
7326051e 1426 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
2a81ab0d
AM
1427 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1428 print " selected='selected'" if ($fwhostsettings{'DEFAULT_SRC_ADR'} eq $defaultNetworks{$network}{'NAME'});
7326051e
AM
1429 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
1430 my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK";
1431 my $defsub1=&General::subtocidr($ownnet{$defsub});
1432 $ownnet{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED');
1433 if ($ownnet{$defnet}){
1434 print ">$network ($ownnet{$defnet}/$defsub1)</option>";
1435 }else{
1436 print ">$network</option>";
1437 }
2a81ab0d 1438 }
8013bd0a
AM
1439 print"</select></td></tr>";
1440 if (! -z $confignet){
f620fa34
AM
1441 print<<END;
1442 <tr>
1443 <td>
1444 <label>
1445 <input type='radio' name='grp2' id='CUST_SRC_NET' value='cust_net' $checked{'grp2'}{'cust_net'}>
1446 $Lang::tr{'fwhost cust net'}:
1447 </label>
1448 </td>
1449 <td style='text-align:right;'>
a72ae687 1450 <select name='CUST_SRC_NET' style='width:16em;'>";
f620fa34 1451END
eff2dbf8 1452 foreach my $key (sort { ncmp($customnetwork{$a}[0],$customnetwork{$b}[0]) } keys %customnetwork) {
8013bd0a
AM
1453 print"<option>$customnetwork{$key}[0]</option>";
1454 }
1455 print"</select></td></tr>";
2a81ab0d 1456 }
8013bd0a 1457 if (! -z $confighost){
f620fa34
AM
1458 print<<END;
1459 <tr>
1460 <td valign='top'>
1461 <label>
1462 <input type='radio' name='grp2' id='CUST_SRC_HOST' value='cust_host' $checked{'grp2'}{'cust_host'}>
1463 $Lang::tr{'fwhost cust addr'}:
1464 </label>
1465 </td>
1466 <td style='text-align:right;'>
a72ae687 1467 <select name='CUST_SRC_HOST' style='width:16em;'>";
f620fa34 1468END
eff2dbf8 1469 foreach my $key (sort { ncmp($customhost{$a}[0],$customhost{$b}[0]) } keys %customhost) {
8013bd0a
AM
1470 print"<option>$customhost{$key}[0]</option>";
1471 }
1472 print"</select></td></tr>";
1473 }
1474 print"</table>";
1475 #Inner table right
f620fa34 1476 print"</td><td align='right' style='vertical-align:top;'><table width='90%' border='0'>";
8013bd0a
AM
1477 #OVPN networks
1478 if (! -z $configccdnet){
f620fa34
AM
1479 print<<END;
1480 <td style='width:15em;'>
1481 <label>
1482 <input type='radio' name='grp2' id='OVPN_CCD_NET' value='ovpn_net' $checked{'grp2'}{'ovpn_net'}>
1483 $Lang::tr{'fwhost ccdnet'}
1484 </label>
1485 </td>
1486 <td style='text-align:right;'>
a72ae687 1487 <select name='OVPN_CCD_NET' style='width:16em;'>";
f620fa34 1488END
eff2dbf8 1489 foreach my $key (sort { ncmp($ccdnet{$a}[0],$ccdnet{$b}[0]) } keys %ccdnet)
8013bd0a
AM
1490 {
1491 print"<option value='$ccdnet{$key}[0]'>$ccdnet{$key}[0]</option>";
1492 }
1493 print"</select></td></tr>";
2a81ab0d 1494 }
8013bd0a 1495 #OVPN clients
a72ae687 1496 my @ovpn_clients=();
eff2dbf8 1497 foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost)
2a81ab0d
AM
1498 {
1499 if ($ccdhost{$key}[33] ne ''){
a72ae687
AM
1500 $show='1';
1501 push (@ovpn_clients,$ccdhost{$key}[1]);
1502 }
1503 }
1504 if ($show eq '1'){
1505 $show='';
1506 print<<END;
f620fa34
AM
1507 <td style='width:15em;'>
1508 <label>
1509 <input type='radio' name='grp2' value='ovpn_host' $checked{'grp2'}{'ovpn_host'}>
1510 $Lang::tr{'fwhost ccdhost'}
1511 </label>
1512 </td>
1513 <td style='text-align:right;'>
a72ae687 1514 <select name='OVPN_CCD_HOST' style='width:16em;'>" if ($show eq '');
f620fa34 1515END
a72ae687
AM
1516 foreach(@ovpn_clients){
1517 print"<option value='$_'>$_</option>";
2a81ab0d 1518 }
a72ae687 1519 print"</select></td></tr>";
2a81ab0d 1520 }
8013bd0a 1521 #OVPN n2n networks
a72ae687 1522 my @OVPN_N2N=();
eff2dbf8 1523 foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost) {
2a81ab0d 1524 if($ccdhost{$key}[3] eq 'net'){
a72ae687
AM
1525 $show='1';
1526 push (@OVPN_N2N,$ccdhost{$key}[1]);
1527 }
1528 }
1529 if ($show eq '1'){
1530 $show='';
1531 print<<END;
f620fa34
AM
1532 <td style='width:15em;'>
1533 <label>
1534 <input type='radio' name='grp2' id='OVPN_N2N' value='ovpn_n2n' $checked{'grp2'}{'ovpn_n2n'}>
1535 $Lang::tr{'fwhost ovpn_n2n'}:
1536 </label>
1537 </td>
1538 <td style='text-align:right;'>
a72ae687 1539 <select name='OVPN_N2N' style='width:16em;'>"
f620fa34 1540END
a72ae687
AM
1541 foreach(@OVPN_N2N){
1542 print"<option>$_</option>";
2a81ab0d 1543 }
a72ae687 1544 print"</select></td></tr>";
2a81ab0d 1545 }
8013bd0a 1546 #IPsec networks
a72ae687 1547 my @IPSEC_N2N=();
eff2dbf8 1548 foreach my $key (sort { ncmp($ipsecconf{$a}[0],$ipsecconf{$b}[0]) } keys %ipsecconf) {
2a81ab0d 1549 if ($ipsecconf{$key}[3] eq 'net'){
a72ae687
AM
1550 $show='1';
1551 push (@IPSEC_N2N,$ipsecconf{$key}[1]);
1552 }
1553 }
1554 if ($show eq '1'){
1555 $show='';
1556 print<<END;
f620fa34
AM
1557 <td style='width:15em;'>
1558 <label>
1559 <input type='radio' name='grp2' id='IPSEC_NET' value='ipsec_net' $checked{'grp2'}{'ipsec_net'}>
1560 $Lang::tr{'fwhost ipsec net'}
1561 </label>
1562 </td>
1563 <td style='text-align:right;'>
a72ae687 1564 <select name='IPSEC_NET' style='width:16em;'>"
f620fa34 1565END
a72ae687
AM
1566 foreach(@IPSEC_N2N){
1567 print"<option value='$_'>$_</option>";
2a81ab0d
AM
1568 }
1569 }
a72ae687 1570 print"</select></td></tr>";
8013bd0a
AM
1571 print"</table>";
1572 print"</td></tr></table>";
bc8ecbd6 1573 print"<br><br>";
2a81ab0d 1574 }
bc8ecbd6 1575 print"<table width='100%'>";
f620fa34 1576 print"<tr><td style='text-align:right;'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' /><input type='hidden' name='oldremark' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='update' value=\"$fwhostsettings{'update'}\"><input type='hidden' name='ACTION' value='savegrp' ></form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='resetgrp'></form></td></table>";
2a81ab0d
AM
1577 &Header::closebox();
1578}
4313aa18
SS
1579sub addgeoipgrp
1580{
1581 &hint;
1582 &error;
1583 &showmenu;
1584 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addgeoipgrp'});
1585
1586 my %checked=();
1587 my $show='';
1588 $checked{'check1'}{'off'} = '';
1589 $checked{'check1'}{'on'} = '';
1590 $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED';
1591 $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'};
1592 $fwhostsettings{'oldgrpname'}=$fwhostsettings{'grp_name'};
1593 my $grp=$fwhostsettings{'grp_name'};
1594 my $rem=$fwhostsettings{'remark'};
1595 if ($fwhostsettings{'update'} eq ''){
1596 print<<END;
1597 <table width='100%' border='0'>
1598 <tr>
1599 <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td>
1600 <td><form method='post'><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' size='30'></td>
1601 </tr>
1602 <tr>
1603 <td>$Lang::tr{'remark'}:</td>
1604 <td ><input type='TEXT' name='remark' value='$fwhostsettings{'remark'}' style='width: 99%;'></td>
1605 </tr>
1606 <tr>
1607 <td colspan='2'><br></td>
1608 </tr>
1609 </table>
1610END
1611 } else {
1612 print<<END;
1613 <table width='100%' border='0'>
1614 <form method='post'><tr>
1615 <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td>
1616 <td style='width:30%;'><input type='TEXT' name='grp' value='$fwhostsettings{'grp_name'}' size='30'></td>
1617 <td>
1618 <input type='submit' value='$Lang::tr{'fwhost change'}'>
1619 <input type='hidden' name='oldgrpname' value='$fwhostsettings{'oldgrpname'}'>
1620 <input type='hidden' name='ACTION' value='changegeoipgrpname'>
1621 </td>
1622 <td></td>
1623 </tr></form>
1624 <tr><form method='post' style='display:inline'>
1625 <td>$Lang::tr{'remark'}:</td>
1626 <td colspan='2' style='width:98%;'>
1627 <input type='TEXT' name='newrem' value='$fwhostsettings{'remark'}' style='width:98%;'>
1628 </td>
1629 <td align='right'>
1630 <input type='submit' value='$Lang::tr{'fwhost change'}'>
1631 <input type='hidden' name='grp' value='$fwhostsettings{'grp_name'}'>
1632 <input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'>
1633 <input type='hidden' name='ACTION' value='changegeoipgrpremark'>
1634 </td>
1635 </tr></form>
1636 </table>
1637 <br><br>
1638END
1639 }
1640 if ($fwhostsettings{'update'} eq 'on') {
1641 my @geoip_locations = &fwlib::get_geoip_locations();
1642
1643 print<<END;
1644 <form method='post'>
1645 <input type='hidden' name='remark' value='$rem'>
1646 <input type='hidden' name='grp_name' value='$grp'>
1647
1648 <table width='100%' border='0'>
1649 <tr>
1650 <td style='text-align:left;'>
1651 <select name='COUNTRY_CODE' style='width:16em;'>";
1652END
1653 foreach my $location (@geoip_locations) {
1654 # Get full country name.
1655 my $fullname = &GeoIP::get_full_country_name($location);
1656
1657 print"<option value='$location'>$location - $fullname</option>\n";
1658 }
1659 print <<END;
1660 </select>
1661 </td>
1662 </tr>
1663 </table>
1664 <br><br>
1665END
1666 }
1667 print <<END;
1668 <table width='100%'>
1669 <tr><td style='text-align:right;'>
1670 <input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
1671 <input type='hidden' name='oldremark' value='$fwhostsettings{'oldremark'}'>
1672 <input type='hidden' name='update' value=\"$fwhostsettings{'update'}\">
1673 <input type='hidden' name='ACTION' value='savegeoipgrp' >
1674 </form>
1675
1676 <form method='post' style='display:inline'>
1677
1678 <input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'>
1679 <input type='hidden' name='ACTION' value='resetgeoipgrp'>
1680
1681 </form>
1682 </td></tr></table>
1683END
1684 &Header::closebox();
1685}
2a81ab0d
AM
1686sub addservice
1687{
1688 &error;
1689 &showmenu;
1a8fde0e 1690 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservice'});
2a81ab0d
AM
1691 if ($fwhostsettings{'updatesrv'} eq 'on')
1692 {
1693 $fwhostsettings{'oldsrvname'} = $fwhostsettings{'SRV_NAME'};
1694 $fwhostsettings{'oldsrvport'} = $fwhostsettings{'SRV_PORT'};
1695 $fwhostsettings{'oldsrvprot'} = $fwhostsettings{'PROT'};
2aeb4b25 1696 $fwhostsettings{'oldsrvicmp'} = $fwhostsettings{'ICMP'};
2a81ab0d
AM
1697 }
1698 print<<END;
fda8c915 1699 <table width='100%' border='0'><form method='post'>
1a8fde0e 1700 <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 1701 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT' id='protocol' >
2a81ab0d
AM
1702END
1703 foreach ("TCP","UDP","ICMP")
1704 {
1705 if ($_ eq $fwhostsettings{'PROT'})
1706 {
1707 print"<option selected>$_</option>";
1708 }else{
1709 print"<option>$_</option>";
1710 }
1711 }
1712 print<<END;
fda8c915 1713 </select></td></tr></table>
bfc84eb1 1714 <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
1715END
1716 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
86a921ee 1717 print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>";
eff2dbf8 1718 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
2aeb4b25
AM
1719 if ($icmptypes{$key}[0] eq $fwhostsettings{'oldsrvicmp'}){
1720 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1721 }else{
1722 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1723 }
2a81ab0d 1724 }
2a81ab0d 1725 print<<END;
bfc84eb1
AM
1726 </select></td></tr></table></div>
1727 <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 1728 <table width='100%' border='0'><tr><td colspan='6'><br></td></tr>
2a81ab0d
AM
1729 <tr><td colspan='6' align='right'>
1730END
1731 if ($fwhostsettings{'updatesrv'} eq 'on')
1732 {
1733 print<<END;
7f5b2820 1734 <input type='submit' value='$Lang::tr{'update'}'style='min-width:100px;' >
2a81ab0d
AM
1735 <input type='hidden' name='ACTION' value='updateservice'>
1736 <input type='hidden' name='oldsrvname' value='$fwhostsettings{'oldsrvname'}'>
1737 <input type='hidden' name='oldsrvport' value='$fwhostsettings{'oldsrvport'}'>
2aeb4b25
AM
1738 <input type='hidden' name='oldsrvprot' value='$fwhostsettings{'oldsrvprot'}'>
1739 <input type='hidden' name='oldsrvicmp' value='$fwhostsettings{'oldsrvicmp'}'>
1740 </form>
2a81ab0d 1741END
fda8c915 1742 }else{
7f5b2820 1743 print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>";
2a81ab0d
AM
1744 }
1745 print<<END;
7f5b2820 1746 <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr>
2a81ab0d 1747 </table></form>
2a81ab0d
AM
1748END
1749 &Header::closebox();
1750 &viewtableservice;
1751}
1752sub addservicegrp
1753{
1754 &hint;
1755 &error;
1756 &showmenu;
1a8fde0e 1757 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservicegrp'});
2a81ab0d 1758 $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'};
a8b113e7 1759 $fwhostsettings{'oldsrvgrpname'}=$fwhostsettings{'SRVGRP_NAME'};
2a81ab0d
AM
1760 if ($fwhostsettings{'updatesrvgrp'} eq ''){
1761 print<<END;
1762 <table width='100%' border='0'><form method='post'>
1a8fde0e 1763 <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 1764 <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 1765 <tr><td colspan='2'><br></tr>
2a81ab0d
AM
1766 </table>
1767END
1768 }else{
1769 print<<END;
bc8ecbd6 1770 <table width='100%'><form method='post' style='display:inline'>
a8b113e7 1771 <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td width='20%'><input type='text' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}' size='14'></td><td align='left'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldsrvgrpname' value='$fwhostsettings{'oldsrvgrpname'}'><input type='hidden' name='ACTION' value='changesrvgrpname'></td><td width='3%'></td></form></tr>
a72ae687
AM
1772 <tr>
1773 <form method='post'>
1774 <td width='10%'>
1775 $Lang::tr{'remark'}:
1776 </td>
1777 <td colspan='2'>
1778 <input type='text' name='newsrvrem' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width:98%;'>
1779 </td>
1780 <td align='right'>
1781 <input type='submit' value='$Lang::tr{'fwhost change'}'>
1782 <input type='hidden' name='oldsrvrem' value='$fwhostsettings{'oldsrvgrpremark'}'>
1783 <input type='hidden' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}'>
1784 <input type='hidden' name='ACTION' value='changesrvgrpremark' >
1785 </td>
1786 </tr>
1787 <tr>
1788 <td colspan='4'>
1789 <br>
1790 </td>
1791 </tr>
1792 </table>
1793 </form>
2a81ab0d
AM
1794END
1795 }
1796 if($fwhostsettings{'updatesrvgrp'} eq 'on'){
2a81ab0d 1797 print<<END;
6c869961 1798 <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 1799 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'add'}: </td><td><select name='CUST_SRV' style='min-width:185px;'>
2a81ab0d
AM
1800END
1801 &General::readhasharray("$configsrv", \%customservice);
82b837cf
AM
1802 #Protocols for use in servicegroups
1803 print "<optgroup label='$Lang::tr{'fwhost cust service'}'>";
eff2dbf8 1804 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice)
2a81ab0d
AM
1805 {
1806 print "<option>$customservice{$key}[0]</option>";
1807 }
82b837cf
AM
1808 print "</optgroup>";
1809 print "<optgroup label='$Lang::tr{'protocol'}'>";
1810 print "<option>GRE</option>";
1811 print "<option>AH</option>";
1812 print "<option>ESP</option>";
1813 print "<option>IGMP</option>";
1814 print "<option>IPIP</option>";
1815 print "<option value='IPV6'>IPv6 encap</option>";
1816 print "</optgroup>";
2a81ab0d
AM
1817 print<<END;
1818 </select></td></tr>
5dd84c25 1819 <tr><td colspan='4'><br><br></td></tr>
bc8ecbd6 1820 <tr><td colspan='4'></td></tr>
2a81ab0d
AM
1821 </table>
1822END
1823 }
1824 print<<END;
bc8ecbd6 1825 <table width='100%'>
7f5b2820 1826 <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
1827 </table></form>
1828END
2a81ab0d
AM
1829 &Header::closebox();
1830}
1831# View
1832sub viewtablenet
1833{
1834 if(! -z $confignet){
1835 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'});
1836 &General::readhasharray("$confignet", \%customnetwork);
484269ce
AM
1837 &General::readhasharray("$configgrp", \%customgrp);
1838 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1839 &General::readhasharray("$fwconfiginp", \%fwinp);
1840 &General::readhasharray("$fwconfigout", \%fwout);
f620fa34 1841
2a81ab0d
AM
1842 if (!keys %customnetwork)
1843 {
1844 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1845 }else{
1846 print<<END;
902a15be
AM
1847 <table width='100%' cellspacing='0' class='tbl'>
1848 <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
1849END
1850 }
1851 my $count=0;
902a15be 1852 my $col='';
eff2dbf8 1853 foreach my $key (sort {ncmp($a,$b)} keys %customnetwork) {
2a81ab0d 1854 if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) {
902a15be
AM
1855 print" <tr>";
1856 $col="bgcolor='${Header::colouryellow}'";
2a81ab0d
AM
1857 }elsif ($count % 2)
1858 {
902a15be 1859 $col="bgcolor='$color{'color20'}'";
aeefcc9c 1860 print" <tr>";
2a81ab0d
AM
1861 }else
1862 {
902a15be 1863 $col="bgcolor='$color{'color22'}'";
aeefcc9c 1864 print" <tr>";
2a81ab0d 1865 }
72586f0f 1866 my $colnet="$customnetwork{$key}[1]/".&General::subtocidr($customnetwork{$key}[2]);
484269ce 1867 my $netcount=&getnetcount($customnetwork{$key}[0]);
f620fa34 1868 print"<td width='20%' $col><form method='post'>$customnetwork{$key}[0]</td><td width='15%' align='center' $col>".&getcolor($colnet)."</td><td width='40%' $col>$customnetwork{$key}[3]</td><td align='center' $col>$netcount x</td>";
2a81ab0d 1869 print<<END;
f8aa0679 1870 <td width='1%' $col><input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
2a81ab0d
AM
1871 <input type='hidden' name='ACTION' value='editnet'>
1872 <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' />
1873 <input type='hidden' name='IP' value='$customnetwork{$key}[1]' />
1874 <input type='hidden' name='SUBNET' value='$customnetwork{$key}[2]' />
e5a058c1 1875 <input type='hidden' name='NETREMARK' value='$customnetwork{$key}[3]' />
2a81ab0d
AM
1876 </td></form>
1877END
484269ce 1878 if($netcount == '0')
2a81ab0d 1879 {
f8aa0679 1880 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 1881 }else{
902a15be 1882 print"<td $col></td></tr>";
2a81ab0d
AM
1883 }
1884 $count++;
1885 }
1886 print"</table>";
1887 &Header::closebox();
1888 }
1889
1890}
b119578f
AM
1891sub getcolor
1892{
1893 my $c=shift;
f620fa34
AM
1894 my $sip;
1895 my $scidr;
1ccfb89e 1896 my $tdcolor='';
f620fa34
AM
1897 #Check if MAC
1898 if (&General::validmac($c)){ return $c;}
1899
1900 #Check if we got a full IP with subnet then split it
1901 if($c =~ /^(.*?)\/(.*?)$/){
1902 ($sip,$scidr) = split ("/",$c);
1903 }else{
1904 $sip=$c;
1905 }
1906
1907 #Now check if IP is part of ORANGE,BLUE or GREEN
7fa1b16e 1908 if ( &Header::orange_used() && &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
f620fa34
AM
1909 $tdcolor="<font style='color: $Header::colourorange;'>$c</font>";
1910 return $tdcolor;
1911 }
1912 if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1913 $tdcolor="<font style='color: $Header::colourgreen;'>$c</font>";
1914 return $tdcolor;
1915 }
7fa1b16e 1916 if ( &Header::blue_used() && &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
f620fa34
AM
1917 $tdcolor="<font style='color: $Header::colourblue;'>$c</font>";
1918 return $tdcolor;
1919 }
48f07c19
AM
1920 if ("$sip/$scidr" eq "0.0.0.0/0"){
1921 $tdcolor="<font style='color: $Header::colourred;'>$c</font>";
1922 return $tdcolor;
1923 }
b119578f
AM
1924 #Check if IP is part of OpenVPN N2N subnet
1925 foreach my $key (sort keys %ccdhost){
1926 if ($ccdhost{$key}[3] eq 'net'){
1927 my ($a,$b) = split("/",$ccdhost{$key}[11]);
f620fa34
AM
1928 if (&General::IpInSubnet($sip,$a,$b)){
1929 $tdcolor="<font style='color:$Header::colourovpn ;'>$c</font>";
b119578f
AM
1930 return $tdcolor;
1931 }
1932 }
1933 }
f620fa34 1934
b119578f
AM
1935 #Check if IP is part of OpenVPN dynamic subnet
1936 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
f620fa34
AM
1937 if (&General::IpInSubnet($sip,$a,$b)){
1938 $tdcolor="<font style='color: $Header::colourovpn;'>$c</font>";
b119578f
AM
1939 return $tdcolor;
1940 }
f620fa34 1941
b119578f
AM
1942 #Check if IP is part of OpenVPN static subnet
1943 foreach my $key (sort keys %ccdnet){
1944 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1945 $b =&General::iporsubtodec($b);
f620fa34
AM
1946 if (&General::IpInSubnet($sip,$a,$b)){
1947 $tdcolor="<font style='color: $Header::colourovpn;'>$c</font>";
b119578f
AM
1948 return $tdcolor;
1949 }
1950 }
f620fa34 1951
b119578f
AM
1952 #Check if IP is part of IPsec RW network
1953 if ($ipsecsettings{'RW_NET'} ne ''){
1954 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1955 $b=&General::iporsubtodec($b);
f620fa34
AM
1956 if (&General::IpInSubnet($sip,$a,$b)){
1957 $tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
b119578f
AM
1958 return $tdcolor;
1959 }
1960 }
f620fa34 1961
b119578f
AM
1962 #Check if IP is part of a IPsec N2N network
1963 foreach my $key (sort keys %ipsecconf){
1ccfb89e
AM
1964 if ($ipsecconf{$key}[11]){
1965 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1966 $b=&General::iporsubtodec($b);
1967 if (&General::IpInSubnet($sip,$a,$b)){
1968 $tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
1969 return $tdcolor;
1970 }
b119578f
AM
1971 }
1972 }
f620fa34 1973 return "$c";
b119578f 1974}
2a81ab0d
AM
1975sub viewtablehost
1976{
1977 if (! -z $confighost){
1978 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust addr'});
1979 &General::readhasharray("$confighost", \%customhost);
b119578f
AM
1980 &General::readhasharray("$configccdnet", \%ccdnet);
1981 &General::readhasharray("$configccdhost", \%ccdhost);
484269ce
AM
1982 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1983 &General::readhasharray("$fwconfiginp", \%fwinp);
1984 &General::readhasharray("$fwconfigout", \%fwout);
1985 &General::readhasharray("$configgrp", \%customgrp);
2a81ab0d
AM
1986 if (!keys %customhost)
1987 {
1988 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1989 }else{
1990 print<<END;
902a15be
AM
1991 <table width='100%' cellspacing='0' class='tbl'>
1992 <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
1993END
1994 }
1995 my $count=0;
902a15be 1996 my $col='';
eff2dbf8 1997 foreach my $key (sort { ncmp ($customhost{$a}[0],$customhost{$b}[0])} keys %customhost) {
2a81ab0d 1998 if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) {
902a15be
AM
1999 print" <tr>";
2000 $col="bgcolor='${Header::colouryellow}'";
2001 }elsif ($count % 2){
2002 print" <tr>";
2003 $col="bgcolor='$color{'color20'}'";
2004 }else{
2005 $col="bgcolor='$color{'color22'}'";
2006 print" <tr>";
2007 }
2a81ab0d 2008 my ($ip,$sub)=split(/\//,$customhost{$key}[2]);
e3580608 2009 $customhost{$key}[4]=~s/\s+//g;
484269ce
AM
2010 my $hostcount=0;
2011 $hostcount=&gethostcount($customhost{$key}[0]);
f620fa34 2012 print"<td width='20%' $col>$customhost{$key}[0]</td><td width='20%' align='center' $col >".&getcolor($ip)."</td><td width='50%' align='left' $col>$customhost{$key}[3]</td><td align='center' $col>$hostcount x</td>";
2a81ab0d 2013 print<<END;
f8aa0679 2014 <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
2015 <input type='hidden' name='ACTION' value='edithost' />
2016 <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' />
2017 <input type='hidden' name='IP' value='$ip' />
2018 <input type='hidden' name='type' value='$customhost{$key}[1]' />
e3580608 2019 <input type='hidden' name='HOSTREMARK' value='$customhost{$key}[3]' />
2e99ab8b 2020 </form></td>
2a81ab0d 2021END
484269ce 2022 if($hostcount == '0')
2a81ab0d 2023 {
f8aa0679 2024 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 2025 }else{
902a15be 2026 print"<td width='1%' $col></td></tr>";
2a81ab0d
AM
2027 }
2028 $count++;
2029 }
2030 print"</table>";
2031 &Header::closebox();
2032 }
2033}
2034sub viewtablegrp
2035{
2036 if(! -z "$configgrp"){
2037 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust grp'});
2038 &General::readhasharray("$configgrp", \%customgrp);
2039 &General::readhasharray("$configipsec", \%ipsecconf);
2040 &General::readhasharray("$configccdhost", \%ccdhost);
2041 &General::readhasharray("$configccdnet", \%ccdnet);
2042 &General::readhasharray("$confighost", \%customhost);
2043 &General::readhasharray("$confignet", \%customnetwork);
484269ce
AM
2044 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2045 &General::readhasharray("$fwconfiginp", \%fwinp);
2046 &General::readhasharray("$fwconfigout", \%fwout);
2a81ab0d
AM
2047 my @grp=();
2048 my $helper='';
8f204435 2049 my $count=1;
2a81ab0d
AM
2050 my $grpname;
2051 my $remark;
12dcfbbd 2052 my $number;
2cee2462 2053 my $delflag;
aeefcc9c
AM
2054 my @counter;
2055 my %hash;
2a81ab0d 2056 if (!keys %customgrp)
484269ce 2057 {
f195a8d7 2058 print "<center><b>$Lang::tr{'fwhost err emptytable'}</b>";
2a81ab0d 2059 }else{
aeefcc9c
AM
2060 #get all groups in a hash
2061 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
2062 push (@counter,$customgrp{$key}[0]);
2063 }
2064 foreach my $key1 (@counter) {
2065 $hash{$key1}++ ;
2066 }
0c2cf9e2 2067 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
2a81ab0d
AM
2068 $count++;
2069 if ($helper ne $customgrp{$key}[0]){
2cee2462 2070 $delflag='0';
eff2dbf8 2071 foreach my $key1 (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
2cee2462
AM
2072 if ($customgrp{$key}[0] eq $customgrp{$key1}[0])
2073 {
2074 $delflag++;
2075 }
d0815ce4 2076 if($delflag > 1){
d13a9363
AM
2077 last;
2078 }
2cee2462 2079 }
8f204435 2080 $number=1;
f195a8d7 2081 if ($customgrp{$key}[2] eq "none"){$customgrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};}
2a81ab0d 2082 $grpname=$customgrp{$key}[0];
6c869961 2083 $remark="$customgrp{$key}[1]";
aeefcc9c 2084 if($count gt 1){ print"</table>";$count=1;}
2e99ab8b 2085 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp;";
2a81ab0d 2086 print " <b>$Lang::tr{'remark'}:</b>&nbsp $remark &nbsp " if ($remark ne '');
484269ce
AM
2087 my $netgrpcount=&getnetcount($grpname);
2088 print "<b>$Lang::tr{'used'}:</b> $netgrpcount x";
2089 if($netgrpcount == '0')
2a81ab0d 2090 {
f8aa0679 2091 print"<form method='post' style='display:inline'><input type='image' src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' align='right' /><input type='hidden' name='grp_name' value='$grpname' ><input type='hidden' name='ACTION' value='delgrp'></form>";
2a81ab0d 2092 }
f8aa0679 2093 print"<form method='post' style='display:inline'><input type='image' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' align='right' /><input type='hidden' name='grp_name' value='$grpname' ><input type='hidden' name='remark' value='$remark' ><input type='hidden' name='ACTION' value='editgrp'></form>";
726e6882 2094 print"<table width='100%' cellspacing='0' class='tbl'><tr><th align='center'><b>$Lang::tr{'name'}</b></th><th align='center'><b>$Lang::tr{'fwhost ip_mac'}</b></th><th align='center' width='25%'><b>$Lang::tr{'fwhost type'}</th><th></th></tr>";
2a81ab0d 2095 }
902a15be 2096 my $col='';
2a81ab0d 2097 if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) {
902a15be
AM
2098 print" <tr>";
2099 $col="bgcolor='${Header::colouryellow}'";
6c869961 2100 }elsif ($count %2 == 0){
902a15be 2101 print"<tr>";
aeefcc9c 2102 $col="bgcolor='$color{'color20'}'";
6c869961 2103 }else{
902a15be 2104 print"<tr>";
aeefcc9c 2105 $col="bgcolor='$color{'color22'}'";
6c869961 2106 }
2a81ab0d 2107 my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]);
902a15be
AM
2108 if ($ip eq ''){
2109 print"<tr>";
2110 $col="bgcolor='${Header::colouryellow}'";
2111 }
2112 print "<td width='39%' align='left' $col>";
2a81ab0d
AM
2113 if($customgrp{$key}[3] eq 'Standard Network'){
2114 print &get_name($customgrp{$key}[2])."</td>";
2115 }else{
2116 print "$customgrp{$key}[2]</td>";
2117 }
f195a8d7 2118 if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){
bc595f09 2119 print "<td align='center' $col>$Lang::tr{'fwhost deleted'}</td><td align='center' $col>$Lang::tr{'fwhost '.$customgrp{$key}[3]}</td><td width='1%' $col><form method='post'>";
2a81ab0d 2120 }else{
72586f0f 2121 my ($colip,$colsub) = split("/",$ip);
eae92b2b 2122 $ip="$colip/".&General::iporsubtocidr($colsub) if ($colsub);
bc595f09 2123 print"<td align='center' $col>".&getcolor($ip)."</td><td align='center' $col>$Lang::tr{'fwhost '.$customgrp{$key}[3]}</td><td width='1%' $col><form method='post'>";
2a81ab0d 2124 }
aeefcc9c 2125 if ($delflag > 0 && $ip ne ''){
f8aa0679 2126 print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' />";
aeefcc9c
AM
2127 #check if this group has only one entry
2128 foreach my $key2 (keys %hash) {
2129 if ($hash{$key2}<2 && $key2 eq $customgrp{$key}[0]){
2130 print "<input type='hidden' name='last' value='on'>" ;
2131 }
2132 }
2a81ab0d 2133 }
bc595f09 2134 print"<input type='hidden' name='ACTION' value='deletegrphost'><input type='hidden' name='update' value='$fwhostsettings{'update'}'><input type='hidden' name='delhost' value='$grpname,$remark,$customgrp{$key}[2],$customgrp{$key}[3]'></form></td></tr>";
2a81ab0d 2135 $helper=$customgrp{$key}[0];
12dcfbbd 2136 $number++;
2a81ab0d
AM
2137 }
2138 print"</table>";
2a81ab0d
AM
2139 }
2140 &Header::closebox();
2141}
2142
4313aa18
SS
2143}
2144sub viewtablegeoipgrp
2145{
2146 # If our filesize is "zero" there is nothing to read-in.
2147 if (-z "$configgeoipgrp") {
2148 return;
2149 }
2150
2151 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust geoipgrp'});
2152 &General::readhasharray("$configgeoipgrp", \%customgeoipgrp);
2153 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2154 &General::readhasharray("$fwconfiginp", \%fwinp);
2155 &General::readhasharray("$fwconfigout", \%fwout);
2156 my @grp=();
2157 my $helper='';
2158 my $count=1;
2159 my $country_code;
2160 my $grpname;
2161 my $remark;
2162 my $number;
2163 my $delflag;
2164 my @counter;
2165 my %hash;
2166
2167 # If there are no groups we are finished here.
2168 if (!keys %customgeoipgrp) {
2169 print "<center><b>$Lang::tr{'fwhost err emptytable'}</b>";
2170 return;
2171 }
2172
2173 # Put all groups in a hash.
2174 foreach my $key (sort { ncmp($customgeoipgrp{$a}[0],$customgeoipgrp{$b}[0]) }
2175 sort { ncmp($customgeoipgrp{$a}[2],$customgeoipgrp{$b}[2]) } keys %customgeoipgrp) {
2176 push (@counter,$customgeoipgrp{$key}[0]);
2177 }
2178
2179 # Increase current used key.
2180 foreach my $key1 (@counter) {
2181 $hash{$key1}++ ;
2182 }
2183
2184 # Sort hash.
2185 foreach my $key (sort { ncmp($customgeoipgrp{$a}[0],$customgeoipgrp{$b}[0]) }
2186 sort { ncmp($customgeoipgrp{$a}[2],$customgeoipgrp{$b}[2]) } keys %customgeoipgrp) {
2187 $count++;
2188 if ($helper ne $customgeoipgrp{$key}[0]) {
2189 $delflag='0';
2190
2191 foreach my $key1 (sort { ncmp($customgeoipgrp{$a}[0],$customgeoipgrp{$b}[0]) }
2192 sort { ncmp($customgeoipgrp{$a}[2],$customgeoipgrp{$b}[2]) } keys %customgeoipgrp) {
2193
2194 if ($customgeoipgrp{$key}[0] eq $customgeoipgrp{$key1}[0])
2195 {
2196 $delflag++;
2197 }
2198 if($delflag > 1){
2199 last;
2200 }
2201 }
2202
2203 $number=1;
2204
2205 # Groupname.
2206 $grpname=$customgeoipgrp{$key}[0];
2207
2208 # Group remark.
2209 $remark="$customgeoipgrp{$key}[1]";
2210
2211 # Country code.
2212 $country_code="$customgeoipgrp{$key}[2]";
2213
2214 if ($count gt 1){
2215 print"</table>";
2216 $count=1;
2217 }
2218
2219 # Display groups header.
2220 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp;\n";
2221 print "<b>$Lang::tr{'remark'}:</b>&nbsp $remark &nbsp\n" if ($remark ne '');
2222
2223 # Get group count.
2224 my $geoipgrpcount=&getgeoipcount($grpname);
2225 print "<b>$Lang::tr{'used'}:</b> $geoipgrpcount x";
2226
2227 # Only display delete icon, if the group is not used by a firewall rule.
2228 if($geoipgrpcount == '0') {
2229 print"<form method='post' style='display:inline'>\n";
2230 print"<input type='image' src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' align='right' />\n";
2231 print"<input type='hidden' name='grp_name' value='$grpname' >\n";
2232 print"<input type='hidden' name='ACTION' value='delgeoipgrp'>\n";
2233 print"</form>";
2234 }
2235
2236 # Icon for group editing.
2237print <<END;
2238 <form method='post' style='display:inline'>
2239 <input type='image' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' align='right'/>
2240 <input type='hidden' name='grp_name' value='$grpname' >
2241 <input type='hidden' name='remark' value='$remark' >
2242 <input type='hidden' name='ACTION' value='editgeoipgrp'>
2243 </form>
2244
2245 <table width='100%' cellspacing='0' class='tbl'>
2246END
2247 # Display headlines if the group contains any entries.
2248 if ($country_code ne "none") {
2249print <<END;
2250 <tr>
2251 <td width='10%' align='center'>
2252 <b>$Lang::tr{'flag'}</b>
2253 </td>
2254
2255 <td width='10%'align='center'>
2256 <b>$Lang::tr{'countrycode'}</b>
2257 </td>
2258
2259 <td width='70%'align='left'>
2260 <b>$Lang::tr{'country'}</b>
2261 </td>
2262
2263 <td width='10%' align='right'></td>
2264 </tr>
2265END
2266 }
2267 }
2268
2269 # Check if our group contains any entries.
2270 if ($country_code eq "none") {
2271 print "<tr><td>$Lang::tr{'fwhost err emptytable'}</td></tr>\n";
2272 } else {
2273 # Check if we are currently editing a group and assign column backgound colors.
2274 my $col='';
2275 if ( ($fwhostsettings{'ACTION'} eq 'editgeoipgrp' || $fwhostsettings{'update'} ne '')
2276 && $fwhostsettings{'grp_name'} eq $customgeoipgrp{$key}[0]) {
2277 $col="bgcolor='${Header::colouryellow}'";
2278 } elsif ($count %2 == 0){
2279 $col="bgcolor='$color{'color20'}'";
2280 } else {
2281 $col="bgcolor='$color{'color22'}'";
2282 }
2283
2284 # Get country flag.
2285 my $icon = &GeoIP::get_flag_icon($customgeoipgrp{$key}[2]);
2286
2287 # Print column with flag icon.
2288 my $col_content;
2289 if ($icon) {
2290 $col_content = "<img src='$icon' alt='$customgeoipgrp{$key}[2]' title='$customgeoipgrp{$key}[2]'>";
2291 } else {
2292 $col_content = "<b>N/A</b>";
2293 }
2294
2295 print "<td align='center' $col>$col_content</td>\n";
2296
2297 # Print column with country code.
2298 print "<td align='center' $col>$customgeoipgrp{$key}[2]</td>\n";
2299
2300 # Print column with full country name.
2301 my $country_name = &GeoIP::get_full_country_name($customgeoipgrp{$key}[2]);
2302 print "<td align='left' $col>$country_name</td>\n";
2303
2304 # Generate from for removing entries from a group.
2305 print "<td align='right' width='1%' $col><form method='post'>\n";
2306
2307 if ($delflag > 0){
2308 print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}'/>\n";
2309
2310 # Check if this group only has a single entry.
2311 foreach my $key2 (keys %hash) {
2312 if ($hash{$key2}<2 && $key2 eq $customgeoipgrp{$key}[0]){
2313 print "<input type='hidden' name='last' value='on'>" ;
2314 }
2315 }
2316 }
2317
2318 print "<input type='hidden' name='ACTION' value='deletegeoipgrpentry'>\n";
2319 print "<input type='hidden' name='update' value='$fwhostsettings{'update'}'>\n";
2320 print "<input type='hidden' name='delentry' value='$grpname,$remark,$customgeoipgrp{$key}[2],$customgeoipgrp{$key}[3]'>\n";
2321 print "</form>\n";
2322 print "</td>\n";
2323 print "</tr>\n";
2324 }
2325
2326 $helper=$customgeoipgrp{$key}[0];
2327 $number++;
2328 }
2329
2330 print"</table>\n";
2331 &Header::closebox();
2a81ab0d
AM
2332}
2333sub viewtableservice
2334{
2335 my $count=0;
3a162dc1 2336 my $srvcount;
2a81ab0d
AM
2337 if(! -z "$configsrv")
2338 {
2339 &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'});
2340 &General::readhasharray("$configsrv", \%customservice);
3a162dc1
AM
2341 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2342 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2343 &General::readhasharray("$fwconfiginp", \%fwinp);
2344 &General::readhasharray("$fwconfigout", \%fwout);
2a81ab0d 2345 print<<END;
902a15be
AM
2346 <table width='100%' cellspacing='0' class='tbl'>
2347 <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 2348END
902a15be 2349 my $col='';
eff2dbf8 2350 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0])} keys %customservice)
2a81ab0d
AM
2351 {
2352 $count++;
2353 if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) {
902a15be
AM
2354 print" <tr>";
2355 $col="bgcolor='${Header::colouryellow}'";
2356 }elsif ($count % 2){
2357 print" <tr>";
2358 $col="bgcolor='$color{'color22'}'";
2359 }else{
2360 print" <tr>";
2361 $col="bgcolor='$color{'color20'}'";
2362 }
2a81ab0d 2363 print<<END;
902a15be 2364 <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 2365END
3a162dc1
AM
2366 #Neuer count
2367 $srvcount=&getsrvcount($customservice{$key}[0]);
86a921ee
AM
2368 if($customservice{$key}[3] eq 'All ICMP-Types'){print $Lang::tr{'fwdfw all icmp'};}
2369 elsif($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
2a81ab0d 2370 print<<END;
902a15be 2371 </td><td align='center' $col>$srvcount x</td>
f8aa0679 2372 <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
2373 <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' />
2374 <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' />
2aeb4b25
AM
2375 <input type='hidden' name='PROT' value='$customservice{$key}[2]' />
2376 <input type='hidden' name='ICMP' value='$customservice{$key}[3]' /></form></td>
2a81ab0d 2377END
3a162dc1 2378 if ($srvcount eq '0')
2a81ab0d 2379 {
f8aa0679 2380 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 2381 }else{
902a15be 2382 print"<td $col></td></tr>";
2a81ab0d
AM
2383 }
2384 }
2385 print"</table>";
2386 &Header::closebox();
2387 }
2388}
2389sub viewtableservicegrp
2390{
2391 my $count=0;
2392 my $grpname;
2393 my $remark;
2394 my $helper;
aeefcc9c 2395 my $helper1;
937d4e08
AM
2396 my $port;
2397 my $protocol;
c7043621 2398 my $delflag;
3a162dc1 2399 my $grpcount=0;
902a15be 2400 my $col='';
aeefcc9c
AM
2401 my $lastentry=0;
2402 my @counter;
2403 my %hash;
2a81ab0d 2404 if (! -z $configsrvgrp){
2a81ab0d
AM
2405 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'});
2406 &General::readhasharray("$configsrvgrp", \%customservicegrp);
937d4e08 2407 &General::readhasharray("$configsrv", \%customservice);
3a162dc1
AM
2408 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2409 &General::readhasharray("$fwconfiginp", \%fwinp);
2410 &General::readhasharray("$fwconfigout", \%fwout);
2a81ab0d 2411 my $number= keys %customservicegrp;
aeefcc9c
AM
2412 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){
2413 push (@counter,$customservicegrp{$key}[0]);
2414 }
2415 foreach my $key1 (@counter) {
2416 $hash{$key1}++ ;
2417 }
fe2bae3b 2418 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){
2a81ab0d
AM
2419 $count++;
2420 if ($helper ne $customservicegrp{$key}[0]){
3a162dc1
AM
2421 #Get used groupcounter
2422 $grpcount=&getsrvcount($customservicegrp{$key}[0]);
d13a9363 2423 $delflag=0;
eff2dbf8 2424 foreach my $key1 (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) } keys %customservicegrp){
d13a9363
AM
2425 if ($customservicegrp{$key}[0] eq $customservicegrp{$key1}[0])
2426 {
2427 $delflag++;
2428 }
2429 if($delflag > 1){
2430 last;
2431 }
2432 }
2a81ab0d 2433 $grpname=$customservicegrp{$key}[0];
6c869961 2434 if ($customservicegrp{$key}[2] eq "none"){
aeefcc9c 2435 $customservicegrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};
0b54aaed
AM
2436 $port='';
2437 $protocol='';
6c869961
AM
2438 }
2439 $remark="$customservicegrp{$key}[1]";
aeefcc9c 2440 if($count >0){print"</table>";$count=1;}
2e99ab8b
AM
2441 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp; ";
2442 print "<b>$Lang::tr{'remark'}:</b>&nbsp; $remark " if ($remark ne '');
3a162dc1
AM
2443 print "&nbsp; <b>$Lang::tr{'used'}:</b> $grpcount x";
2444 if($grpcount == '0')
2a81ab0d 2445 {
f8aa0679 2446 print"<form method='post' style='display:inline'><input type='image' src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' align='right' /><input type='hidden' name='SRVGRP_NAME' value='$grpname' ><input type='hidden' name='ACTION' value='delservicegrp'></form>";
2a81ab0d 2447 }
f8aa0679 2448 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 2449 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
2450 }
2451 if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) {
902a15be
AM
2452 print"<tr>";
2453 $col="bgcolor='${Header::colouryellow}'";
6c869961 2454 }elsif ($count %2 == 0){
902a15be
AM
2455 print"<tr>";
2456 $col="bgcolor='$color{'color20'}'";
0f869e32 2457 }else{
902a15be
AM
2458 print"<tr>";
2459 $col="bgcolor='$color{'color22'}'";
0f869e32 2460 }
aeefcc9c
AM
2461 #make lines yellow if it is a dummy entry
2462 if ($customservicegrp{$key}[2] eq $Lang::tr{'fwhost err emptytable'}){
2463 print"<tr>";
2464 $col="bgcolor='${Header::colouryellow}'";
2465 }
82b837cf
AM
2466 #Set fields if we use protocols in servicegroups
2467 if ($customservicegrp{$key}[2] ne 'TCP' || $customservicegrp{$key}[2] ne 'UDP' || $customservicegrp{$key}[2] ne 'ICMP'){
2468 $port='-';
2469 }
2470 if ($customservicegrp{$key}[2] eq 'GRE'){$protocol='GRE';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} GRE";}
2471 if ($customservicegrp{$key}[2] eq 'ESP'){$protocol='ESP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} ESP";}
2472 if ($customservicegrp{$key}[2] eq 'AH'){$protocol='AH';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} AH";}
2473 if ($customservicegrp{$key}[2] eq 'IGMP'){$protocol='IGMP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IGMP";}
2474 if ($customservicegrp{$key}[2] eq 'IPIP'){$protocol='IPIP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPIP";}
2475 if ($customservicegrp{$key}[2] eq 'IPV6'){$protocol='IPV6';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPv6 encapsulation";}
902a15be 2476 print "<td width='39%' $col>$customservicegrp{$key}[2]</td>";
937d4e08
AM
2477 foreach my $srv (sort keys %customservice){
2478 if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){
2479 $protocol=$customservice{$srv}[2];
2480 $port=$customservice{$srv}[1];
2481 last;
2482 }
2483 }
902a15be 2484 print"<td align='center' $col>$port</td><td align='center' $col>$protocol</td><td width='1%' $col><form method='post'>";
aeefcc9c
AM
2485 if ($delflag gt '0'){
2486 if ($customservicegrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){
f8aa0679 2487 print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title=$Lang::tr{'delete'} />";
aeefcc9c
AM
2488 }
2489 #check if this group has only one entry
2490 foreach my $key2 (keys %hash) {
2491 if ($hash{$key2}<2 && $key2 eq $customservicegrp{$key}[0]){
2492 print "<input type='hidden' name='last' value='on'>" ;
2493 }
2494 }
0f869e32 2495 }
82b837cf 2496 print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'>";
fe2bae3b 2497 if($protocol eq 'TCP' || $protocol eq 'UDP' || $protocol eq 'ICMP'){
3a162dc1 2498 print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2]'></form></td></tr>";
82b837cf 2499 }else{
3a162dc1 2500 print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$protocol'></form></td></tr>";
82b837cf 2501 }
0f869e32 2502 $helper=$customservicegrp{$key}[0];
2a81ab0d
AM
2503 }
2504 print"</table>";
2505 &Header::closebox();
2506 }
2507}
2508# Check
2509sub checkname
2510{
2511 my %hash=%{(shift)};
2512 foreach my $key (keys %hash) {
2513 if($hash{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
2514 return 0;
2515 }
2516 }
2517 return 1;
2518
2519}
f195a8d7
AM
2520sub checkgroup
2521{
40962f97 2522 &General::readhasharray("$configgrp", \%customgrp );
f195a8d7 2523 my $name=shift;
3a162dc1
AM
2524 foreach my $key (keys %customservicegrp) {
2525 if($customservicegrp{$key}[0] eq $name){
2526 return 0;
2527 }
2528 }
2529 return 1;
2530}
2531sub checkservice
2532{
2533 &General::readhasharray("$configsrv", \%customservice );
2534 my $name=shift;
2535 foreach my $key (keys %customservice) {
2536 if($customservice{$key}[0] eq $name){
f195a8d7
AM
2537 return 0;
2538 }
2539 }
2540 return 1;
2541}
2a81ab0d
AM
2542sub checkip
2543{
2544
2545 my %hash=%{(shift)};
2546 my $a=shift;
2547 foreach my $key (keys %hash) {
2548 if($hash{$key}[$a] eq $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'})){
2549 return 0;
2550 }
2551 }
2552 return 1;
2553}
2554sub checksubnet
2555{
2a81ab0d
AM
2556 my %hash=%{(shift)};
2557 &General::readhasharray("$confignet", \%hash);
2558 foreach my $key (keys %hash) {
2559 if(&General::IpInSubnet($fwhostsettings{'IP'},$hash{$key}[1],$hash{$key}[2]))
2560 {
2561 return 1;
2562 }
2563 }
2564 return 0;
2565}
2566sub checkservicegroup
2567{
2568 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2a81ab0d 2569 #check name
7772ae73 2570 if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'}))
2a81ab0d
AM
2571 {
2572 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
2573 return $errormessage;
2574 }
2a81ab0d
AM
2575 #check empty selectbox
2576 if (keys %customservice lt 1)
2577 {
2578 $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>";
2579 }
2a81ab0d
AM
2580 #check if name already exists
2581 if ($fwhostsettings{'updatesrvgrp'} ne 'on'){
2582 foreach my $key (keys %customservicegrp) {
2583 if( $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} ){
2584 $errormessage.=$Lang::tr{'fwhost err grpexist'}."<br>";
2585
2586 }
2587 }
2588 }
2589 #check if service already exists in group
2590 foreach my $key (keys %customservicegrp) {
13e5dda4
AM
2591 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){
2592 $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>";
2a81ab0d 2593 }
13e5dda4 2594 }
2a81ab0d
AM
2595 return $errormessage;
2596}
49da7d79
AM
2597sub checkrulereload
2598{
2599 my $search=shift;
2600 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2601 &General::readhasharray("$fwconfiginp", \%fwinp);
2602 &General::readhasharray("$fwconfigout", \%fwout);
2603
2604 #check if service or servicegroup is used in rules
2605 foreach my $key (keys %fwfwd){
2606 if($search eq $fwfwd{$key}[15]){
2607 &General::firewall_config_changed();
2608 return;
2609 }
2610 }
2611 foreach my $key (keys %fwinp){
2612 if($search eq $fwinp{$key}[15]){
2613 &General::firewall_config_changed();
2614 return;
2615 }
2616 }
2617 foreach my $key (keys %fwout){
2618 if($search eq $fwout{$key}[15]){
2619 &General::firewall_config_changed();
2620 return;
2621 }
2622 }
2623}
2a81ab0d
AM
2624sub error
2625{
2626 if ($errormessage) {
2627 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
2628 print "<class name='base'>$errormessage\n";
2629 print "&nbsp;</class>\n";
2630 &Header::closebox();
2631 }
2632}
2633sub hint
2634{
2635 if ($hint) {
2636 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
2637 print "<class name='base'>$hint\n";
2638 print "&nbsp;</class>\n";
2639 &Header::closebox();
2640 }
2641}
2642sub get_name
2643{
2644 my $val=shift;
2645 &General::setup_default_networks(\%defaultNetworks);
2646 foreach my $network (sort keys %defaultNetworks)
2647 {
2648 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
2649 }
2650}
484269ce
AM
2651sub gethostcount
2652{
2653 my $searchstring=shift;
2654 my $srvcounter=0;
2655 #Count services used in servicegroups
2656 foreach my $key (keys %customgrp) {
2657 if($customgrp{$key}[2] eq $searchstring){
2658 $srvcounter++;
2659 }
2660 }
2661 #Count services used in firewall - config
2662 foreach my $key1 (keys %fwfwd) {
2663 if($fwfwd{$key1}[4] eq $searchstring){
2664 $srvcounter++;
2665 }
2666 if($fwfwd{$key1}[6] eq $searchstring){
2667 $srvcounter++;
2668 }
2669 }
2670 #Count services used in firewall - input
2671 foreach my $key2 (keys %fwinp) {
2672 if($fwinp{$key2}[4] eq $searchstring){
2673 $srvcounter++;
2674 }
2675 if($fwinp{$key2}[6] eq $searchstring){
2676 $srvcounter++;
2677 }
2678 }
2679 #Count services used in firewall - outgoing
2680 foreach my $key3 (keys %fwout) {
2681 if($fwout{$key3}[4] eq $searchstring){
2682 $srvcounter++;
2683 }
2684 if($fwout{$key3}[6] eq $searchstring){
2685 $srvcounter++;
2686 }
2687 }
2688 return $srvcounter;
2689}
4313aa18
SS
2690sub getgeoipcount
2691{
2692 my $groupname=shift;
2693 my $counter=0;
2694
2695 # GeoIP groups are stored as "group:groupname" in the
2696 # firewall settings files.
2697 my $searchstring = join(':', "group",$groupname);
2698
2699 # Count services used in firewall - forward
2700 foreach my $key1 (keys %fwfwd) {
2701 if($fwfwd{$key1}[4] eq $searchstring){
2702 $counter++;
2703 }
2704 if($fwfwd{$key1}[6] eq $searchstring){
2705 $counter++;
2706 }
2707 }
2708 #Count services used in firewall - input
2709 foreach my $key2 (keys %fwinp) {
2710 if($fwinp{$key2}[4] eq $searchstring){
2711 $counter++;
2712 }
2713 if($fwinp{$key2}[6] eq $searchstring){
2714 $counter++;
2715 }
2716 }
2717 #Count services used in firewall - outgoing
2718 foreach my $key3 (keys %fwout) {
2719 if($fwout{$key3}[4] eq $searchstring){
2720 $counter++;
2721 }
2722 if($fwout{$key3}[6] eq $searchstring){
2723 $counter++;
2724 }
2725 }
2726 return $counter;
2727}
484269ce
AM
2728sub getnetcount
2729{
2730 my $searchstring=shift;
2731 my $srvcounter=0;
2732 #Count services used in servicegroups
2733 foreach my $key (keys %customgrp) {
2734 if($customgrp{$key}[2] eq $searchstring){
2735 $srvcounter++;
2736 }
2737 }
2738 #Count services used in firewall - config
2739 foreach my $key1 (keys %fwfwd) {
2740 if($fwfwd{$key1}[4] eq $searchstring){
2741 $srvcounter++;
2742 }
2743 if($fwfwd{$key1}[6] eq $searchstring){
2744 $srvcounter++;
2745 }
2746 }
2747 #Count services used in firewall - input
2748 foreach my $key2 (keys %fwinp) {
2749 if($fwinp{$key2}[4] eq $searchstring){
2750 $srvcounter++;
2751 }
2752 if($fwinp{$key2}[6] eq $searchstring){
2753 $srvcounter++;
2754 }
2755 }
2756 #Count services used in firewall - outgoing
2757 foreach my $key3 (keys %fwout) {
2758 if($fwout{$key3}[4] eq $searchstring){
2759 $srvcounter++;
2760 }
2761 if($fwout{$key3}[6] eq $searchstring){
2762 $srvcounter++;
2763 }
2764 }
2765 return $srvcounter;
2766}
3a162dc1
AM
2767sub getsrvcount
2768{
2769 my $searchstring=shift;
2770 my $srvcounter=0;
2771 #Count services used in servicegroups
2772 foreach my $key (keys %customservicegrp) {
2773 if($customservicegrp{$key}[2] eq $searchstring){
2774 $srvcounter++;
2775 }
2776 }
2777 #Count services used in firewall - config
2778 foreach my $key1 (keys %fwfwd) {
2779 if($fwfwd{$key1}[15] eq $searchstring){
2780 $srvcounter++;
2781 }
2782 }
2783 #Count services used in firewall - input
2784 foreach my $key2 (keys %fwinp) {
2785 if($fwinp{$key2}[15] eq $searchstring){
2786 $srvcounter++;
2787 }
2788 }
2789 #Count services used in firewall - outgoing
2790 foreach my $key3 (keys %fwout) {
2791 if($fwout{$key3}[15] eq $searchstring){
2792 $srvcounter++;
2793 }
2794 }
2795 return $srvcounter;
2796}
2a81ab0d
AM
2797sub deletefromgrp
2798{
2799 my $target=shift;
2800 my $config=shift;
2801 my %hash=();
2802 &General::readhasharray("$config",\%hash);
2803 foreach my $key (keys %hash) {
2a81ab0d 2804 if($hash{$key}[2] eq $target){
2a81ab0d 2805 delete $hash{$key};
2a81ab0d
AM
2806 }
2807 }
2808 &General::writehasharray("$config",\%hash);
2809
2810}
2811sub plausicheck
2812{
2a81ab0d
AM
2813 my $edit=shift;
2814 #check hostname
d0815ce4 2815 if (!&validhostname($fwhostsettings{'HOSTNAME'}))
2a81ab0d
AM
2816 {
2817 $errormessage=$errormessage.$Lang::tr{'fwhost err name'};
2818 $fwhostsettings{'BLK_IP'}='readonly';
2819 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2820 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2821 }
2822 #check if name collides with CCD Netname
2a81ab0d
AM
2823 &General::readhasharray("$configccdnet", \%ccdnet);
2824 foreach my $key (keys %ccdnet) {
2825 if($ccdnet{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
2826 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdnet'};;
2827 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2828 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2829 last;
2830 }
2831 }
2a81ab0d
AM
2832 #check if IP collides with CCD NetIP
2833 if ($fwhostsettings{'type'} ne 'mac'){
2834 &General::readhasharray("$configccdnet", \%ccdnet);
2835 foreach my $key (keys %ccdnet) {
2836 my $test=(&General::getnetworkip($fwhostsettings{'IP'},&General::iporsubtocidr($fwhostsettings{'SUBNET'})))."/".$fwhostsettings{'SUBNET'};
2837 if($ccdnet{$key}[1] eq $test){
2838 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdipnet'};
2839 $fwhostsettings{'IP'} = $fwhostsettings{'orgip'};
2840 $fwhostsettings{'SUBNET'} = $fwhostsettings{'orgsubnet'};
2841 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2842 last;
2843 }
2844 }
2845 }
2a81ab0d
AM
2846 #check if name collides with CCD Hostname
2847 &General::readhasharray("$configccdhost", \%ccdhost);
2848 foreach my $key (keys %ccdhost) {
2849 my ($ip,$sub)=split(/\//,$ccdhost{$key}[33]);
2850 if($ip eq $fwhostsettings{'IP'}){
2851 $errormessage=$Lang::tr{'fwhost err isccdiphost'};
2852 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2853 last;
2854 }
2855 }
2856 #check if IP collides with CCD HostIP (only hosts)
2857 if ($edit eq 'edithost')
2858 {
2859 foreach my $key (keys %ccdhost) {
2860 if($ccdhost{$key}[1] eq $fwhostsettings{'HOSTNAME'}){
2861 $errormessage=$Lang::tr{'fwhost err isccdhost'};
2862 $fwhostsettings{'IP'} = $fwhostsettings{'orgname'};
2863 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2864 last;
2865 }
2866 }
2867 }
2868 #check if network with this name already exists
2869 &General::readhasharray("$confignet", \%customnetwork);
2870 if (!&checkname(\%customnetwork))
2871 {
2872 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err netexist'};
2873 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2874 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2875 }
2876 #check if network ip already exists
2877 if (!&checkip(\%customnetwork,1))
2878 {
2879 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err net'};
2880 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2881 }
2882 #check if host with this name already exists
2883 &General::readhasharray("$confighost", \%customhost);
2884 if (!&checkname(\%customhost))
2885 {
0013abb0 2886 $errormessage.="<br>".$Lang::tr{'fwhost err hostexist'};
2a81ab0d 2887 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
ed73b87e 2888 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2a81ab0d
AM
2889 }
2890 #check if host with this ip already exists
2891 if (!&checkip(\%customhost,2))
2892 {
2893 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'};
2a81ab0d 2894 }
2a81ab0d
AM
2895 return;
2896}
2897sub getipforgroup
2898{
2899 my $name=$_[0],
2900 my $type=$_[1];
2901 my $value;
2902
2903 #get address from IPSEC NETWORK
2904 if ($type eq 'IpSec Network'){
2905 foreach my $key (keys %ipsecconf) {
2906 if ($ipsecconf{$key}[1] eq $name){
2907 return $ipsecconf{$key}[11];
2908 }
2909 }
2910 &deletefromgrp($name,$configgrp);
2911 }
2912
2913 #get address from IPSEC HOST
2914 if ($type eq 'IpSec Host'){
2915 foreach my $key (keys %ipsecconf) {
2916 if ($ipsecconf{$key}[1] eq $name){
2917 return $ipsecconf{$key}[10];
2918 }
2919 }
2920 &deletefromgrp($name,$configgrp);
2921 }
2922
2923 #get address from ovpn ccd Net-2-Net
2924 if ($type eq 'OpenVPN N-2-N'){
2925 foreach my $key (keys %ccdhost) {
2926 if($ccdhost{$key}[1] eq $name){
2927 my ($a,$b) = split ("/",$ccdhost{$key}[11]);
2928 $b=&General::iporsubtodec($b);
2929 return "$a/$b";
2930 }
2931 }
2932 &deletefromgrp($name,$configgrp);
2933 }
2934
2935 #get address from ovpn ccd static host
2936 if ($type eq 'OpenVPN static host'){
2937 foreach my $key (keys %ccdhost) {
2938 if($ccdhost{$key}[1] eq $name){
2939 my ($a,$b) = split (/\//,$ccdhost{$key}[33]);
2940 $b=&General::iporsubtodec($b);
2941 return "$a/$b";
2942 }
2943 }
2944 &deletefromgrp($name,$configgrp);
2945 }
2946
2947 #get address from ovpn ccd static net
2948 if ($type eq 'OpenVPN static network'){
2949 foreach my $key (keys %ccdnet) {
2950 if ($ccdnet{$key}[0] eq $name){
2951 my ($a,$b) = split (/\//,$ccdnet{$key}[1]);
2952 $b=&General::iporsubtodec($b);
2953 return "$a/$b";
2954 }
2955 }
2956 }
2957
2958 #check custom addresses
2959 if ($type eq 'Custom Host'){
2960 foreach my $key (keys %customhost) {
2961 if ($customhost{$key}[0] eq $name){
f1934a05
AM
2962 my ($ip,$sub) = split("/",$customhost{$key}[2]);
2963 return $ip;
2a81ab0d
AM
2964 }
2965 }
2966 }
2967
2968 ##check custom networks
2969 if ($type eq 'Custom Network'){
2970 foreach my $key (keys %customnetwork) {
2971 if($customnetwork{$key}[0] eq $name){
2972 return $customnetwork{$key}[1]."/".$customnetwork{$key}[2];
2973 }
2974 }
2975 }
2976
2977 #check standard networks
2978 if ($type eq 'Standard Network'){
2979 if ($name =~ /OpenVPN/i){
2980 my %ovpn=();
2981 &General::readhash("${General::swroot}/ovpn/settings",\%ovpn);
2982 return $ovpn{'DOVPN_SUBNET'};
2983 }
2984 if ($name eq 'GREEN'){
2985 my %hash=();
2986 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2987 return $hash{'GREEN_NETADDRESS'}."/".$hash{'GREEN_NETMASK'};
2988 }
2989 if ($name eq 'BLUE'){
2990 my %hash=();
2991 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2992 return $hash{'BLUE_NETADDRESS'}."/".$hash{'BLUE_NETMASK'};
2993 }
2994 if ($name eq 'ORANGE'){
2995 my %hash=();
2996 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2997 return $hash{'ORANGE_NETADDRESS'}."/".$hash{'ORANGE_NETMASK'};
2998 }
2999 if ($name eq 'ALL'){
3000 return "0.0.0.0/0.0.0.0";
3001 }
3002 if ($name =~ /IPsec/i){
3003 my %hash=();
3004 &General::readhash("${General::swroot}/vpn/settings",\%hash);
3005 return $hash{'RW_NET'};
3006 }
48f07c19
AM
3007 if ($name eq 'RED'){
3008 return "0.0.0.0/0";
3009 }
2a81ab0d
AM
3010 }
3011}
fe2bae3b
AM
3012sub decrease
3013{
2a81ab0d
AM
3014 my $grp=$_[0];
3015 &General::readhasharray("$confignet", \%customnetwork);
3016 &General::readhasharray("$confighost", \%customhost);
3017 foreach my $key (sort keys %customgrp ){
3018 if ( ($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Network')){
3019 foreach my $key1 (sort keys %customnetwork){
3020 if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){
8013bd0a 3021 $customnetwork{$key1}[4]=$customnetwork{$key1}[4]-1;
2a81ab0d
AM
3022 last;
3023 }
3024 }
3025 }
3026
3027 if (($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Host')){
3028 foreach my $key2 (sort keys %customhost){
3029 if ($customhost{$key2}[0] eq $customgrp{$key}[2]){
8013bd0a 3030 $customhost{$key2}[4]=$customhost{$key2}[4]-1;
2a81ab0d
AM
3031 last;
3032 }
3033 }
3034
3035 }
3036 }
3037 &General::writehasharray("$confignet", \%customnetwork);
3038 &General::writehasharray("$confighost", \%customhost);
3039}
3040sub decreaseservice
3041{
3042 my $grp=$_[0];
3043 &General::readhasharray("$configsrv", \%customservice);
3044 &General::readhasharray("$configsrvgrp", \%customservicegrp);
3045
3046 foreach my $key (sort keys %customservicegrp){
3047 if ($customservicegrp{$key}[0] eq $grp ){
3048 foreach my $key2 (sort keys %customservice){
3049 if ($customservice{$key2}[0] eq $customservicegrp{$key}[2]){
3050 $customservice{$key2}[4]--;
3051 }
3052 }
3053 }
3054 }
3055 &General::writehasharray("$configsrv", \%customservice);
3056
3057}
a8b113e7
AM
3058sub changenameinfw
3059{
3060 my $old=shift;
3061 my $new=shift;
3062 my $fld=shift;
3063 &General::readhasharray("$fwconfigfwd", \%fwfwd);
3064 &General::readhasharray("$fwconfiginp", \%fwinp);
3065 &General::readhasharray("$fwconfigout", \%fwout);
3066 #Rename group in Firewall-CONFIG
3067 foreach my $key1 (keys %fwfwd) {
3068 if($fwfwd{$key1}[$fld] eq $old){
3069 $fwfwd{$key1}[$fld]=$new;
3070 }
3071 }
3072 &General::writehasharray("$fwconfigfwd", \%fwfwd );
3073 #Rename group in Firewall-INPUT
3074 foreach my $key2 (keys %fwinp) {
3075 if($fwinp{$key2}[$fld] eq $old){
3076 $fwinp{$key2}[$fld]=$new;
3077 }
3078 }
3079 &General::writehasharray("$fwconfiginp", \%fwinp );
3080 #Rename group in Firewall-OUTGOING
3081 foreach my $key3 (keys %fwout) {
3082 if($fwout{$key3}[$fld] eq $old){
3083 $fwout{$key3}[$fld]=$new;
3084 }
3085 }
3086 &General::writehasharray("$fwconfigout", \%fwout );
3087}
2a81ab0d
AM
3088sub checkports
3089{
3090
3091 my %hash=%{(shift)};
3092 #check empty fields
3093 if ($fwhostsettings{'SRV_NAME'} eq '' ){
3094 $errormessage=$Lang::tr{'fwhost err name1'};
3095 }
3096 if ($fwhostsettings{'SRV_PORT'} eq '' && $fwhostsettings{'PROT'} ne 'ICMP'){
3097 $errormessage=$Lang::tr{'fwhost err port'};
3098 }
3099 #check valid name
7772ae73 3100 if (! &validhostname($fwhostsettings{'SRV_NAME'})){
2a81ab0d
AM
3101 $errormessage="<br>".$Lang::tr{'fwhost err name'};
3102 }
3103 #change dashes with :
3104 $fwhostsettings{'SRV_PORT'}=~ tr/-/:/;
3105
3106 if ($fwhostsettings{'SRV_PORT'} eq "*") {
3107 $fwhostsettings{'SRV_PORT'} = "1:65535";
3108 }
3109 if ($fwhostsettings{'SRV_PORT'} =~ /^(\D)\:(\d+)$/) {
3110 $fwhostsettings{'SRV_PORT'} = "1:$2";
3111 }
3112 if ($fwhostsettings{'SRV_PORT'} =~ /^(\d+)\:(\D)$/) {
3113 $fwhostsettings{'SRV_PORT'} = "$1:65535";
3114 }
3115 if($fwhostsettings{'PROT'} ne 'ICMP'){
3116 $errormessage = $errormessage.&General::validportrange($fwhostsettings{'SRV_PORT'}, 'src');
3117 }
3118 # a new service has to have a different name
3119 foreach my $key (keys %hash){
3120 if ($hash{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
3121 $errormessage = "<br>".$Lang::tr{'fwhost err srv exists'};
3122 last;
3123 }
3124 }
3125 return $errormessage;
3126}
3127sub validhostname
3128{
3129 # Checks a hostname against RFC1035
3130 my $hostname = $_[0];
3131
3132 # Each part should be at least two characters in length
3133 # but no more than 63 characters
3134 if (length ($hostname) < 1 || length ($hostname) > 63) {
3135 return 0;}
3136 # Only valid characters are a-z, A-Z, 0-9 and -
d0815ce4 3137 if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-_.;()\/\s]*$/) {
2a81ab0d
AM
3138 return 0;}
3139 # First character can only be a letter or a digit
3140 if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
3141 return 0;}
3142 # Last character can only be a letter or a digit
7772ae73 3143 if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9()]*$/) {
2a81ab0d
AM
3144 return 0;}
3145 return 1;
3146}
6c869961
AM
3147sub validremark
3148{
3149 # Checks a hostname against RFC1035
3150 my $remark = $_[0];
3151 # Each part should be at least two characters in length
3152 # but no more than 63 characters
3153 if (length ($remark) < 1 || length ($remark) > 255) {
3154 return 0;}
3155 # Only valid characters are a-z, A-Z, 0-9 and -
d928d795 3156 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
6c869961
AM
3157 return 0;}
3158 # First character can only be a letter or a digit
3159 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
3160 return 0;}
3161 # Last character can only be a letter or a digit
d928d795 3162 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
6c869961
AM
3163 return 0;}
3164 return 1;
3165}
2a81ab0d
AM
3166&Header::closebigbox();
3167&Header::closepage();