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