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