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