]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - html/cgi-bin/fwhosts.cgi
Forward Firewall: Design changes
[people/teissler/ipfire-2.x.git] / html / cgi-bin / fwhosts.cgi
CommitLineData
2a81ab0d
AM
1#!/usr/bin/perl
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2011 IPFire Team <info@ipfire.org> #
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###############################################################################
21# New function for forwarding firewall. To make it comfortable to create #
22# rules, we need "spelling names" for single Hosts. If you have any questions #
23# <amarx@ipfire.org> #
24###############################################################################
25use strict;
26
27# enable only the following on debugging purpose
28use warnings;
eff2dbf8 29use Sort::Naturally;
2a81ab0d
AM
30use CGI::Carp 'fatalsToBrowser';
31no warnings 'uninitialized';
32require '/var/ipfire/general-functions.pl';
33require "${General::swroot}/lang.pl";
34require "${General::swroot}/header.pl";
35
36my %fwhostsettings=();
37my %customnetwork=();
38my %customhost=();
39my %customgrp=();
40my %customservice=();
41my %customservicegrp=();
42my %ccdnet=();
43my %ccdhost=();
44my %ipsecconf=();
45my %icmptypes=();
46my %color=();
47my %defaultNetworks=();
48my %mainsettings=();
49my %ownnet=();
50my %ipsecsettings=();
62fc8511
AM
51my %fwfwd=();
52my %fwinp=();
2a81ab0d
AM
53
54my $errormessage;
55my $hint;
56my $update=0;
57my $confignet = "${General::swroot}/fwhosts/customnetworks";
58my $confighost = "${General::swroot}/fwhosts/customhosts";
59my $configgrp = "${General::swroot}/fwhosts/customgroups";
60my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
61my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
62my $configipsec = "${General::swroot}/vpn/config";
63my $configsrv = "${General::swroot}/fwhosts/customservices";
64my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
62fc8511
AM
65my $fwconfigfwd = "${General::swroot}/forward/config";
66my $fwconfiginp = "${General::swroot}/forward/input";
2a81ab0d
AM
67
68unless (-e $confignet) { system("touch $confignet"); }
69unless (-e $confighost) { system("touch $confighost"); }
70unless (-e $configgrp) { system("touch $configgrp"); }
71unless (-e $configsrv) { system("touch $configsrv"); }
72unless (-e $configsrvgrp) { system("touch $configsrvgrp"); }
73
74&General::readhash("${General::swroot}/main/settings", \%mainsettings);
75&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
76&General::readhash("${General::swroot}/ethernet/settings", \%ownnet);
77&Header::getcgihash(\%fwhostsettings);
78
79&Header::showhttpheaders();
80&Header::openpage($Lang::tr{'fwhost hosts'}, 1, '');
81&Header::openbigbox('100%', 'center');
82
83## ACTION ####
cd9d9d8a
AM
84if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
85{
86 &reread_rules;
87 &showmenu;
88}
2a81ab0d
AM
89# Update
90if ($fwhostsettings{'ACTION'} eq 'updatenet' )
91{
92 &General::readhasharray("$confignet", \%customnetwork);
93 foreach my $key (keys %customnetwork)
94 {
95 if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'})
96 {
97 $fwhostsettings{'orgname'} = $customnetwork{$key}[0];
98 $fwhostsettings{'orgip'} = $customnetwork{$key}[1];
99 $fwhostsettings{'orgsub'} = $customnetwork{$key}[2];
e5a058c1
AM
100 $fwhostsettings{'netremark'} = $customnetwork{$key}[3];
101 $fwhostsettings{'count'} = $customnetwork{$key}[4];
2a81ab0d
AM
102 delete $customnetwork{$key};
103
104 }
105 }
106 &General::writehasharray("$confignet", \%customnetwork);
107 $fwhostsettings{'actualize'} = 'on';
108 $fwhostsettings{'ACTION'} = 'savenet';
109}
110if ($fwhostsettings{'ACTION'} eq 'updatehost')
111{
112 my ($ip,$subnet);
113 &General::readhasharray("$confighost", \%customhost);
114 foreach my $key (keys %customhost)
115 {
116 if($customhost{$key}[0] eq $fwhostsettings{'orgname'})
117 {
2a81ab0d
AM
118 if ($customhost{$key}[1] eq 'ip'){
119 ($ip,$subnet) = split (/\//,$customhost{$key}[2]);
120 }else{
121 $ip = $customhost{$key}[2];
122 }
123 $fwhostsettings{'orgip'} = $ip;
e3580608 124 $fwhostsettings{'count'} = $customhost{$key}[4];
2a81ab0d 125 delete $customhost{$key};
5e970723 126 &General::writehasharray("$confighost", \%customhost);
2a81ab0d
AM
127 }
128 }
2a81ab0d 129 $fwhostsettings{'actualize'} = 'on';
5e970723 130 if($fwhostsettings{'orgip'}){
2a81ab0d 131 $fwhostsettings{'ACTION'} = 'savehost';
5e970723
AM
132 }else{
133 $fwhostsettings{'ACTION'} = $Lang::tr{'fwhost newhost'};
134 }
2a81ab0d
AM
135}
136if ($fwhostsettings{'ACTION'} eq 'updateservice')
137{
138 my $count=0;
139 my $needrules=0;
140 $errormessage=&checkports(\%customservice);
2a81ab0d
AM
141 if (!$errormessage){
142 &General::readhasharray("$configsrv", \%customservice);
143 foreach my $key (keys %customservice)
144 {
145 if ($customservice{$key}[0] eq $fwhostsettings{'oldsrvname'})
146 {
147 $count=$customservice{$key}[4];
148 delete $customservice{$key};
149 &General::writehasharray("$configsrv", \%customservice);
150 last;
151 }
152 }
153 if ($fwhostsettings{'PROT'} ne 'ICMP'){
154 $fwhostsettings{'ICMP_TYPES'}='BLANK';
155 }
156 my $key1 = &General::findhasharraykey(\%customservice);
157 foreach my $i (0 .. 4) { $customservice{$key1}[$i] = "";}
158 $customservice{$key1}[0] = $fwhostsettings{'SRV_NAME'};
159 $customservice{$key1}[1] = $fwhostsettings{'SRV_PORT'};
160 $customservice{$key1}[2] = $fwhostsettings{'PROT'};
161 $customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'};
162 $customservice{$key1}[4] = $count;
163 &General::writehasharray("$configsrv", \%customservice);
ed73b87e 164 #check if we need to update firewallrules
bfee206c
AM
165 if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){
166 if ( ! -z $fwconfigfwd ){
167 &General::readhasharray("$fwconfigfwd", \%fwfwd);
168 foreach my $key (sort keys %fwfwd){
169 if ($fwfwd{$key}[15] eq $fwhostsettings{'oldsrvname'}){
170 $fwfwd{$key}[15] = $fwhostsettings{'SRV_NAME'};
171 }
172 }
173 &General::writehasharray("$fwconfigfwd", \%fwfwd);
bfee206c
AM
174 }
175 if ( ! -z $fwconfiginp ){
176 &General::readhasharray("$fwconfiginp", \%fwinp);
177 foreach my $line (sort keys %fwinp){
178 if ($fwfwd{$line}[15] eq $fwhostsettings{'oldsrvname'}){
179 $fwfwd{$line}[15] = $fwhostsettings{'SRV_NAME'};
180 }
181 }
182 &General::writehasharray("$fwconfiginp", \%fwinp);
183 }
bfac6bd4
AM
184 #check if we need to update groups
185 &General::readhasharray("$configsrvgrp", \%customservicegrp);
186 foreach my $key (sort keys %customservicegrp){
187 if($customservicegrp{$key}[2] eq $fwhostsettings{'oldsrvname'}){
188 $customservicegrp{$key}[2] = $fwhostsettings{'SRV_NAME'};
189 }
190 }
191 &General::writehasharray("$configsrvgrp", \%customservicegrp);
bfee206c
AM
192 $needrules='on';
193 }
ed73b87e
AM
194 if($count gt 0 && $fwhostsettings{'oldsrvport'} ne $fwhostsettings{'SRV_PORT'} ){
195 $needrules='on';
2a81ab0d 196 }
ed73b87e
AM
197 if($count gt 0 && $fwhostsettings{'oldsrvprot'} ne $fwhostsettings{'PROT'} ){
198 $needrules='on';
199 }
2a81ab0d
AM
200 $fwhostsettings{'SRV_NAME'} = '';
201 $fwhostsettings{'SRV_PORT'} = '';
202 $fwhostsettings{'PROT'} = '';
2a81ab0d
AM
203 }else{
204 $fwhostsettings{'SRV_NAME'} = $fwhostsettings{'oldsrvname'};
205 $fwhostsettings{'SRV_PORT'} = $fwhostsettings{'oldsrvport'};
206 $fwhostsettings{'PROT'} = $fwhostsettings{'oldsrvprot'};
207 $fwhostsettings{'updatesrv'}= 'on';
208 }
2a81ab0d 209 if($needrules eq 'on'){
2a81ab0d
AM
210 &rules;
211 }
2a81ab0d
AM
212 &addservice;
213}
214# save
215if ($fwhostsettings{'ACTION'} eq 'savenet' )
216{
217 my $count=0;
218 my $needrules=0;
219 if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
2a81ab0d
AM
220 #check if all fields are set
221 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
222 {
223 $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
224 &addnet;
225 &viewtablenet;
226 }else{
227 #check valid ip
228 if (!&General::validipandmask($fwhostsettings{'IP'}."/".$fwhostsettings{'SUBNET'}))
229 {
230 $errormessage=$errormessage.$Lang::tr{'fwhost err addr'};
231 $fwhostsettings{'BLK_HOST'} ='readonly';
232 $fwhostsettings{'NOCHECK'} ='false';
233 $fwhostsettings{'error'} ='on';
234 }
e5a058c1
AM
235 #check remark
236 if ($fwhostsettings{'NETREMARK'} ne '' && !&validremark($fwhostsettings{'NETREMARK'})){
237 $errormessage=$Lang::tr{'fwhost err remark'};
238 $fwhostsettings{'error'} ='on';
239 }
2a81ab0d
AM
240 #check if subnet is sigle host
241 if(&General::iporsubtocidr($fwhostsettings{'SUBNET'}) eq '32')
242 {
243 $errormessage=$errormessage.$Lang::tr{'fwhost err sub32'};
2a81ab0d
AM
244 }
245 if($fwhostsettings{'error'} ne 'on'){
246 #check if we use one of ipfire's networks (green,orange,blue)
247 if (($ownnet{'GREEN_NETADDRESS'} ne '' && $ownnet{'GREEN_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'GREEN_NETADDRESS'},$ownnet{'GREEN_NETMASK'}))
248 {
249 $errormessage=$errormessage.$Lang::tr{'ccd err green'}."<br>";
250 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
251 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';}
252 }
253 if (($ownnet{'ORANGE_NETADDRESS'} ne '' && $ownnet{'ORANGE_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'ORANGE_NETADDRESS'},$ownnet{'ORANGE_NETMASK'}))
254 {
255 $errormessage=$errormessage.$Lang::tr{'ccd err orange'}."<br>";
256 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
257 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';}
258 }
259 if (($ownnet{'BLUE_NETADDRESS'} ne '' && $ownnet{'BLUE_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'BLUE_NETADDRESS'},$ownnet{'BLUE_NETMASK'}))
260 {
261 $errormessage=$errormessage.$Lang::tr{'ccd err blue'}."<br>";
262 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
263 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';}
264 }
265 if (($ownnet{'RED_NETADDRESS'} ne '' && $ownnet{'RED_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'RED_NETADDRESS'},$ownnet{'RED_NETMASK'}))
266 {
267 $errormessage=$errormessage.$Lang::tr{'ccd err red'}."<br>";
268 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
269 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';}
270 }
271 }
272 #only check plausi when no error till now
273 if (!$errormessage){
274 &plausicheck("editnet");
275 }
2a81ab0d
AM
276 #check if network ip is part of an already used one
277 if(&checksubnet(\%customnetwork))
278 {
279 $errormessage=$errormessage.$Lang::tr{'fwhost err partofnet'};
280 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
281 }
2a81ab0d
AM
282 if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage)
283 {
284 $fwhostsettings{'actualize'} = '';
285 my $key = &General::findhasharraykey (\%customnetwork);
286 foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
287 $customnetwork{$key}[0] = $fwhostsettings{'orgname'} ;
288 $customnetwork{$key}[1] = $fwhostsettings{'orgip'} ;
289 $customnetwork{$key}[2] = $fwhostsettings{'orgsub'};
f80db6a4 290 $customnetwork{$key}[3] = $fwhostsettings{'orgnetremark'};
e5a058c1 291 $customnetwork{$key}[4] = $fwhostsettings{'count'};
2a81ab0d
AM
292 &General::writehasharray("$confignet", \%customnetwork);
293 undef %customnetwork;
294 }
2a81ab0d 295 if (!$errormessage){
e5a058c1 296
2a81ab0d
AM
297 &General::readhasharray("$confignet", \%customnetwork);
298 if ($fwhostsettings{'ACTION'} eq 'updatenet'){
299 if ($fwhostsettings{'update'} == '0'){
300 foreach my $key (keys %customnetwork) {
301 if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}){
e5a058c1 302 $count=$customnetwork{$key}[4];
2a81ab0d
AM
303 delete $customnetwork{$key};
304 last;
305 }
306 }
307 }
308 }
309 #get count if actualize is 'on'
310 if($fwhostsettings{'actualize'} eq 'on'){
311 $fwhostsettings{'actualize'} = '';
312 $count=$fwhostsettings{'count'};
313 #check if we need to reload rules
314 if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'} && $count gt '0'){
315 $needrules='on';
316 }
317 if ($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
318 #check if we need to update groups
319 &General::readhasharray("$configgrp", \%customgrp);
320 foreach my $key (sort keys %customgrp){
321 if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){
322 $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'};
323 last;
324 }
325 }
326 &General::writehasharray("$configgrp", \%customgrp);
62fc8511
AM
327 #check if we need to update firewallrules
328 if ( ! -z $fwconfigfwd ){
329 &General::readhasharray("$fwconfigfwd", \%fwfwd);
330 foreach my $line (sort keys %fwfwd){
331 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
332 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
333 }
334 if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){
335 $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'};
336 }
337 }
338 &General::writehasharray("$fwconfigfwd", \%fwfwd);
339 }
340 if ( ! -z $fwconfiginp ){
341 &General::readhasharray("$fwconfiginp", \%fwinp);
342 foreach my $line (sort keys %fwinp){
343 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
344 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
345 }
346 }
347 &General::writehasharray("$fwconfiginp", \%fwinp);
348 }
2a81ab0d
AM
349 }
350 }
351 my $key = &General::findhasharraykey (\%customnetwork);
e5a058c1 352 foreach my $i (0 .. 4) { $customnetwork{$key}[$i] = "";}
2a81ab0d
AM
353 $fwhostsettings{'SUBNET'} = &General::iporsubtocidr($fwhostsettings{'SUBNET'});
354 $customnetwork{$key}[0] = $fwhostsettings{'HOSTNAME'};
355 #convert ip when leading '0' in byte
e5a058c1
AM
356 $fwhostsettings{'IP'} =&General::ip2dec($fwhostsettings{'IP'});
357 $fwhostsettings{'IP'} =&General::dec2ip($fwhostsettings{'IP'});
2a81ab0d
AM
358 $customnetwork{$key}[1] = &General::getnetworkip($fwhostsettings{'IP'},$fwhostsettings{'SUBNET'}) ;
359 $customnetwork{$key}[2] = &General::iporsubtodec($fwhostsettings{'SUBNET'}) ;
360 if($fwhostsettings{'newnet'} eq 'on'){$count=0;}
e5a058c1
AM
361 $customnetwork{$key}[3] = $fwhostsettings{'NETREMARK'};
362 $customnetwork{$key}[4] = $count;
2a81ab0d
AM
363 &General::writehasharray("$confignet", \%customnetwork);
364 $fwhostsettings{'IP'}=$fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
365 undef %customnetwork;
366 $fwhostsettings{'HOSTNAME'}='';
367 $fwhostsettings{'IP'}='';
368 $fwhostsettings{'SUBNET'}='';
e5a058c1 369 $fwhostsettings{'NETREMARK'}='';
2a81ab0d
AM
370 #check if an edited net affected groups and need to reload rules
371 if ($needrules eq 'on'){
372 &rules;
373 }
374 &addnet;
375 &viewtablenet;
376 }else
377 {
378 &addnet;
379 &viewtablenet;
380 }
381 }
2a81ab0d
AM
382}
383if ($fwhostsettings{'ACTION'} eq 'savehost')
384{
385 my $count=0;
386 my $needrules=0;
387 if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
2a81ab0d 388 $fwhostsettings{'SUBNET'}='32';
2a81ab0d
AM
389 #check if all fields are set
390 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
391 {
392 $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
393 $fwhostsettings{'ACTION'} = 'edithost';
394 }else{
92e4ae9d 395 if($fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){
2a81ab0d 396 $fwhostsettings{'type'} = 'mac';
92e4ae9d 397 }elsif($fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
2a81ab0d
AM
398 $fwhostsettings{'type'} = 'ip';
399 }else{
400 $fwhostsettings{'type'} = '';
401 $errormessage=$Lang::tr{'fwhost err ipmac'};
402 }
e3580608
AM
403 #check remark
404 if ($fwhostsettings{'HOSTREMARK'} ne '' && !&validremark($fwhostsettings{'HOSTREMARK'})){
405 $errormessage=$Lang::tr{'fwhost err remark'};
406 }
2a81ab0d
AM
407 #CHECK IP-PART
408 if ($fwhostsettings{'type'} eq 'ip'){
409 #check for subnet
410 if (rindex($fwhostsettings{'IP'},'/') eq '-1' ){
411 if($fwhostsettings{'type'} eq 'ip' && !&General::validipandmask($fwhostsettings{'IP'}."/32"))
412 {
413 $errormessage.=$errormessage.$Lang::tr{'fwhost err ip'};
414 $fwhostsettings{'error'}='on';
415 }
2a81ab0d
AM
416 }elsif(rindex($fwhostsettings{'IP'},'/') ne '-1' ){
417 $errormessage=$errormessage.$Lang::tr{'fwhost err ipwithsub'};
418 $fwhostsettings{'error'}='on';
419 }
420 #check if net or broadcast
421 my @tmp= split (/\./,$fwhostsettings{'IP'});
422 if (($tmp[3] eq "0") || ($tmp[3] eq "255")){
423 $errormessage=$Lang::tr{'fwhost err hostip'};
424 }
425 }
2a81ab0d
AM
426 #only check plausi when no error till now
427 if (!$errormessage){
428 &plausicheck("edithost");
429 }
2a81ab0d
AM
430 if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){
431 $fwhostsettings{'actualize'} = '';
432 my $key = &General::findhasharraykey (\%customhost);
e3580608 433 foreach my $i (0 .. 4) { $customhost{$key}[$i] = "";}
2a81ab0d
AM
434 $customhost{$key}[0] = $fwhostsettings{'orgname'} ;
435 $customhost{$key}[1] = $fwhostsettings{'type'} ;
436 if($customhost{$key}[1] eq 'ip'){
437 $customhost{$key}[2] = $fwhostsettings{'orgip'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
438 }else{
439 $customhost{$key}[2] = $fwhostsettings{'orgip'};
440 }
f80db6a4 441 $customhost{$key}[3] = $fwhostsettings{'orgremark'};
e3580608 442 $customhost{$key}[4] = $fwhostsettings{'count'};
2a81ab0d
AM
443 &General::writehasharray("$confighost", \%customhost);
444 undef %customhost;
2a81ab0d 445 }
2a81ab0d
AM
446 if (!$errormessage){
447 #get count if host was edited
448 if($fwhostsettings{'actualize'} eq 'on'){
449 $count=$fwhostsettings{'count'};
450 if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'} && $count gt '0' ){
451 $needrules='on';
452 }
453 if($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
454 #check if we need to update groups
455 &General::readhasharray("$configgrp", \%customgrp);
456 foreach my $key (sort keys %customgrp){
457 if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){
458 $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'};
2a81ab0d
AM
459 }
460 }
461 &General::writehasharray("$configgrp", \%customgrp);
62fc8511
AM
462 #check if we need to update firewallrules
463 if ( ! -z $fwconfigfwd ){
464 &General::readhasharray("$fwconfigfwd", \%fwfwd);
465 foreach my $line (sort keys %fwfwd){
466 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
467 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
468 }
469 if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){
470 $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'};
471 }
472 }
473 &General::writehasharray("$fwconfigfwd", \%fwfwd);
474 }
475 if ( ! -z $fwconfiginp ){
476 &General::readhasharray("$fwconfiginp", \%fwinp);
477 foreach my $line (sort keys %fwinp){
478 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
479 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
480 }
481 }
482 &General::writehasharray("$fwconfiginp", \%fwinp);
483 }
2a81ab0d 484 }
2a81ab0d
AM
485 }
486 my $key = &General::findhasharraykey (\%customhost);
e3580608 487 foreach my $i (0 .. 4) { $customhost{$key}[$i] = "";}
2a81ab0d
AM
488 $customhost{$key}[0] = $fwhostsettings{'HOSTNAME'} ;
489 $customhost{$key}[1] = $fwhostsettings{'type'} ;
490 if ($fwhostsettings{'type'} eq 'ip'){
491 #convert ip when leading '0' in byte
492 $fwhostsettings{'IP'}=&General::ip2dec($fwhostsettings{'IP'});
493 $fwhostsettings{'IP'}=&General::dec2ip($fwhostsettings{'IP'});
494 $customhost{$key}[2] = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
495 }else{
496 $customhost{$key}[2] = $fwhostsettings{'IP'};
497 }
498 if($fwhostsettings{'newhost'} eq 'on'){$count=0;}
e3580608
AM
499 $customhost{$key}[3] = $fwhostsettings{'HOSTREMARK'};
500 $customhost{$key}[4] =$count;
2a81ab0d 501 &General::writehasharray("$confighost", \%customhost);
2a81ab0d
AM
502 undef %customhost;
503 $fwhostsettings{'HOSTNAME'}='';
504 $fwhostsettings{'IP'}='';
505 $fwhostsettings{'type'}='';
e3580608 506 $fwhostsettings{'HOSTREMARK'}='';
2a81ab0d
AM
507 #check if we need to update rules while host was edited
508 if($needrules eq 'on'){
509 &rules;
510 }
511 &addhost;
512 &viewtablehost;
513 }else{
514 &addhost;
515 &viewtablehost;
516 }
2a81ab0d 517 }
2a81ab0d
AM
518}
519if ($fwhostsettings{'ACTION'} eq 'savegrp')
520{
6c869961 521 my $grp=$fwhostsettings{'grp_name'};;
2a81ab0d
AM
522 my $rem=$fwhostsettings{'remark'};
523 my $count;
524 my $type;
525 my $updcounter='off';
526 my @target;
527 my @newgrp;
528 &General::readhasharray("$configgrp", \%customgrp);
529 &General::readhasharray("$confignet", \%customnetwork);
530 &General::readhasharray("$confighost", \%customhost);
6c869961
AM
531 #check name
532 if (!&validhostname($grp)){$errormessage.=$Lang::tr{'fwhost err name'};}
533 #check remark
534 if ($rem ne '' && !&validremark($rem) && $fwhostsettings{'update'} ne 'on'){
535 $errormessage.=$Lang::tr{'fwhost err remark'};
2a81ab0d 536 }
6c869961
AM
537 if ($fwhostsettings{'update'} eq 'on'){
538 #check standard networks
539 if ($fwhostsettings{'grp2'} eq 'std_net'){
540 @target=$fwhostsettings{'DEFAULT_SRC_ADR'};
541 $type='Standard Network';
542 }
543 #check custom networks
544 if ($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} ne ''){
545 @target=$fwhostsettings{'CUST_SRC_NET'};
546 $updcounter='net';
547 $type='Custom Network';
548 }elsif($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} eq ''){
549 $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>";
550 $fwhostsettings{'grp_name'}='';
551 $fwhostsettings{'remark'}='';
552 }
553 #check custom addresses
554 if ($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} ne ''){
555 @target=$fwhostsettings{'CUST_SRC_HOST'};
556 $updcounter='host';
557 $type='Custom Host';
558 }elsif($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} eq ''){
559 $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>";
560 $fwhostsettings{'grp_name'}='';
561 $fwhostsettings{'remark'}='';
562 }
563 #get address from ovpn ccd static net
564 if ($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} ne ''){
565 @target=$fwhostsettings{'OVPN_CCD_NET'};
566 $type='OpenVPN static network';
567 }elsif($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} eq ''){
568 $errormessage=$Lang::tr{'fwhost err groupempty'};
569 $fwhostsettings{'grp_name'}='';
570 $fwhostsettings{'remark'}='';
571 }
572 #get address from ovpn ccd static host
573 if ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} ne ''){
574 @target=$fwhostsettings{'OVPN_CCD_HOST'};
575 $type='OpenVPN static host';
576 }elsif ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} eq ''){
577 $errormessage=$Lang::tr{'fwhost err groupempty'};
578 }
579 #get address from ovpn ccd Net-2-Net
580 if ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} ne ''){
581 @target=$fwhostsettings{'OVPN_N2N'};
582 $type='OpenVPN N-2-N';
583 }elsif ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} eq ''){
584 $errormessage=$Lang::tr{'fwhost err groupempty'};
585 $fwhostsettings{'grp_name'}='';
586 $fwhostsettings{'remark'}='';
587 }
588 #get address from IPSEC HOST
589 if ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} ne ''){
590 @target=$fwhostsettings{'IPSEC_HOST'};
591 $type='IpSec Host';
592 }elsif ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} eq ''){
593 $errormessage=$Lang::tr{'fwhost err groupempty'};
594 $fwhostsettings{'grp_name'}='';
595 $fwhostsettings{'remark'}='';
596 }
597 #get address from IPSEC NETWORK
598 if ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} ne ''){
599 @target=$fwhostsettings{'IPSEC_NET'};
600 $type='IpSec Network';
601 }elsif ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} eq ''){
602 $errormessage=$Lang::tr{'fwhost err groupempty'};
603 $fwhostsettings{'grp_name'}='';
604 $fwhostsettings{'remark'}='';
605 }
606 #check if host/net exists in grp
607
608 my $test="$grp,$fwhostsettings{'oldremark'},@target";
609 foreach my $key (keys %customgrp) {
610 my $test1="$customgrp{$key}[0],$customgrp{$key}[1],$customgrp{$key}[2]";
611 if ($test1 eq $test){
612 $errormessage=$Lang::tr{'fwhost err isingrp'};
613 $fwhostsettings{'update'} = 'on';
614 }
2a81ab0d
AM
615 }
616 }
6c869961 617
2a81ab0d
AM
618 if (!$errormessage){
619 #on first save, we have an empty @target, so fill it with nothing
620 my $targetvalues=@target;
621 if ($targetvalues == '0'){
6c869961 622 @target="none";
2a81ab0d
AM
623 }
624 #on update, we have to delete the dummy entry
2a81ab0d 625 foreach my $key (keys %customgrp){
6c869961 626 if ($customgrp{$key}[0] eq $grp && $customgrp{$key}[2] eq "none"){
2a81ab0d
AM
627 delete $customgrp{$key};
628 last;
629 }
630 }
631 &General::writehasharray("$configgrp", \%customgrp);
632 &General::readhasharray("$configgrp", \%customgrp);
2a81ab0d
AM
633 #get count used
634 foreach my $key (keys %customgrp)
635 {
636 if($customgrp{$key}[0] eq $grp)
637 {
638 $count=$customgrp{$key}[4];
639 last;
640 }
641 }
642 if ($count eq '' ){$count='0';}
643
644 #create array with new lines
645 foreach my $line (@target){
646 push (@newgrp,"$grp,$rem,$line");
647 }
648 #append new entries
649 my $key = &General::findhasharraykey (\%customgrp);
650 foreach my $line (@newgrp){
651 foreach my $i (0 .. 4) { $customgrp{$key}[$i] = "";}
652 my ($a,$b,$c,$d) = split (",",$line);
653 $customgrp{$key}[0] = $a;
654 $customgrp{$key}[1] = $b;
655 $customgrp{$key}[2] = $c;
656 $customgrp{$key}[3] = $type;
657 $customgrp{$key}[4] = $count;
658 }
659 &General::writehasharray("$configgrp", \%customgrp);
2a81ab0d
AM
660 #update counter in Host/Net
661 if($updcounter eq 'net'){
662 foreach my $key (keys %customnetwork) {
663 if($customnetwork{$key}[0] eq $fwhostsettings{'CUST_SRC_NET'}){
e5a058c1 664 $customnetwork{$key}[4] = $customnetwork{$key}[4]+1;
2a81ab0d
AM
665 last;
666 }
667 }
668 &General::writehasharray("$confignet", \%customnetwork);
669 }elsif($updcounter eq 'host'){
670 foreach my $key (keys %customhost) {
671 if ($customhost{$key}[0] eq $fwhostsettings{'CUST_SRC_HOST'}){
04abd8d9 672 $customhost{$key}[4]=$customhost{$key}[4]+1;
2a81ab0d
AM
673 }
674 }
675 &General::writehasharray("$confighost", \%customhost);
676 }
2a81ab0d 677 $fwhostsettings{'update'}='on';
2a81ab0d 678 }
2a81ab0d
AM
679 #check if ruleupdate is needed
680 if($count > 0 )
681 {
682 &rules;
683 }
684 &addgrp;
685 &viewtablegrp;
2a81ab0d
AM
686}
687if ($fwhostsettings{'ACTION'} eq 'saveservice')
688{
689 my $ICMP;
2a81ab0d
AM
690 &General::readhasharray("$configsrv", \%customservice );
691 $errormessage=&checkports(\%customservice);
2a81ab0d
AM
692 if ($fwhostsettings{'PROT'} eq 'ICMP'){
693 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
694 foreach my $key (keys %icmptypes){
695 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){
696 $ICMP=$icmptypes{$key}[0];
697 }
698 }
699 }
700 if($ICMP eq ''){$ICMP='BLANK';}
701 if (!$errormessage){
2a81ab0d
AM
702 my $key = &General::findhasharraykey (\%customservice);
703 foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";}
704 $customservice{$key}[0] = $fwhostsettings{'SRV_NAME'};
705 $customservice{$key}[1] = $fwhostsettings{'SRV_PORT'};
706 $customservice{$key}[2] = $fwhostsettings{'PROT'};
707 $customservice{$key}[3] = $ICMP;
708 $customservice{$key}[4] = 0;
709 &General::writehasharray("$configsrv", \%customservice );
710 #reset fields
711 $fwhostsettings{'SRV_NAME'}='';
712 $fwhostsettings{'SRV_PORT'}='';
713 $fwhostsettings{'PROT'}='';
714 $fwhostsettings{'ICMP_TYPES'}='';
2a81ab0d 715 }
2a81ab0d 716 &addservice;
2a81ab0d
AM
717}
718if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
719{
720 my $prot;
721 my $port;
722 my $count=0;
723 &General::readhasharray("$configsrvgrp", \%customservicegrp );
724 &General::readhasharray("$configsrv", \%customservice );
2a81ab0d 725 $errormessage=&checkservicegroup;
bc912c6e
AM
726 #check remark
727 if ($fwhostsettings{'SRVGRP_REMARK'} ne '' && !&validremark($fwhostsettings{'SRVGRP_REMARK'})){
728 $errormessage=$Lang::tr{'fwhost err remark'};
729 }
2a81ab0d
AM
730 if (!$errormessage){
731 #on first save, we have to enter a dummy value
6c869961
AM
732 if ($fwhostsettings{'CUST_SRV'} eq ''){
733 $fwhostsettings{'CUST_SRV'}='none';
734 }
2a81ab0d
AM
735 #on update, we have to delete the dummy entry
736 foreach my $key (keys %customservicegrp){
6c869961 737 if ($customservicegrp{$key}[2] eq 'none'){
2a81ab0d
AM
738 delete $customservicegrp{$key};
739 last;
740 }
741 }
742 &General::writehasharray("$configsrvgrp", \%customservicegrp );
743 #check if remark has also changed
744 if ($fwhostsettings{'SRVGRP_REMARK'} ne $fwhostsettings{'oldsrvgrpremark'} && $fwhostsettings{'updatesrvgrp'} eq 'on')
745 {
746 foreach my $key (keys %customservicegrp)
747 {
748 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvgrpremark'})
749 {
750 $customservicegrp{$key}[1]='';
751 $customservicegrp{$key}[1]=$fwhostsettings{'SRVGRP_REMARK'};
752 }
753 }
754 }
755 #get count used
756 foreach my $key (keys %customservicegrp)
757 {
758 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
759 {
13e5dda4 760 $count=$customservicegrp{$key}[3];
2a81ab0d
AM
761 last;
762 }
763 }
764 if ($count eq '' ){$count='0';}
765
766 foreach my $key (sort keys %customservice){
767 if($customservice{$key}[0] eq $fwhostsettings{'CUST_SRV'}){
768 $port=$customservice{$key}[1];
769 $prot=$customservice{$key}[2];
770 $customservice{$key}[4]++;
771 }
772 }
773 &General::writehasharray("$configsrv", \%customservice );
2a81ab0d
AM
774 my $key = &General::findhasharraykey (\%customservicegrp);
775 foreach my $i (0 .. 3) { $customservice{$key}[$i] = "";}
776 $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'};
777 $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'};
778 $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'};
937d4e08 779 $customservicegrp{$key}[3] = $count;
2a81ab0d
AM
780 &General::writehasharray("$configsrvgrp", \%customservicegrp );
781 $fwhostsettings{'updatesrvgrp'}='on';
782 }
2a81ab0d
AM
783 if ($count gt 0){
784 &rules;
785 }
786 &addservicegrp;
787 &viewtableservicegrp;
788}
789# edit
790if ($fwhostsettings{'ACTION'} eq 'editnet')
791{
792 &addnet;
793 &viewtablenet;
794}
795if ($fwhostsettings{'ACTION'} eq 'edithost')
796{
797 &addhost;
798 &viewtablehost;
799}
800if ($fwhostsettings{'ACTION'} eq 'editgrp')
801{
802 $fwhostsettings{'update'}='on';
803 &addgrp;
804 &viewtablegrp;
805}
806if ($fwhostsettings{'ACTION'} eq 'editservice')
807{
808 $fwhostsettings{'updatesrv'}='on';
809 &addservice;
810}
811if ($fwhostsettings{'ACTION'} eq 'editservicegrp')
812{
813 $fwhostsettings{'updatesrvgrp'} = 'on';
814 &addservicegrp;
815 &viewtableservicegrp;
816}
817# reset
818if ($fwhostsettings{'ACTION'} eq 'resetnet')
819{
820 $fwhostsettings{'HOSTNAME'} ="";
821 $fwhostsettings{'IP'} ="";
822 $fwhostsettings{'SUBNET'} ="";
823 &showmenu;
824}
825if ($fwhostsettings{'ACTION'} eq 'resethost')
826{
827 $fwhostsettings{'HOSTNAME'} ="";
828 $fwhostsettings{'IP'} ="";
829 $fwhostsettings{'type'} ="";
830 &showmenu;
831}
832# delete
833if ($fwhostsettings{'ACTION'} eq 'delnet')
834{
835 &General::readhasharray("$confignet", \%customnetwork);
836 foreach my $key (keys %customnetwork) {
837 if($fwhostsettings{'key'} eq $customnetwork{$key}[0]){
838 delete $customnetwork{$key};
839 &General::writehasharray("$confignet", \%customnetwork);
840 last;
841 }
842 }
843 &addnet;
844 &viewtablenet;
845}
846if ($fwhostsettings{'ACTION'} eq 'delhost')
847{
848 &General::readhasharray("$confighost", \%customhost);
849 foreach my $key (keys %customhost) {
850 if($fwhostsettings{'key'} eq $customhost{$key}[0]){
851 delete $customhost{$key};
852 &General::writehasharray("$confighost", \%customhost);
853 last;
854 }
855 }
856 &addhost;
857 &viewtablehost;
2a81ab0d
AM
858}
859if ($fwhostsettings{'ACTION'} eq 'deletegrphost')
860{
3f8fe51e
AM
861 my $grpremark;
862 my $grpname;
2a81ab0d
AM
863 &General::readhasharray("$configgrp", \%customgrp);
864 foreach my $key (keys %customgrp){
865 if($customgrp{$key}[0].",".$customgrp{$key}[1].",".$customgrp{$key}[2].",".$customgrp{$key}[3] eq $fwhostsettings{'delhost'}){
866 #decrease count from source host/net
867 if ($customgrp{$key}[3] eq 'Custom Network'){
868 &General::readhasharray("$confignet", \%customnetwork);
869 foreach my $key1 (keys %customnetwork){
870 if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){
e09884e0 871 $customnetwork{$key1}[4] = $customnetwork{$key1}[4]-1;
2a81ab0d
AM
872 last;
873 }
874 }
875 &General::writehasharray("$confignet", \%customnetwork);
876 }
877 if ($customgrp{$key}[3] eq 'Custom Host'){
878 &General::readhasharray("$confighost", \%customhost);
879 foreach my $key1 (keys %customhost){
880 if ($customhost{$key1}[0] eq $customgrp{$key}[2]){
e3580608 881 $customhost{$key1}[4] = $customhost{$key1}[4]-1;
2a81ab0d
AM
882 last;
883 }
884 }
885 &General::writehasharray("$confighost", \%customhost);
886 }
3f8fe51e
AM
887 $grpname=$customgrp{$key}[0];
888 $grpremark=$customgrp{$key}[1];
2a81ab0d
AM
889 delete $customgrp{$key};
890 }
891 }
892 &General::writehasharray("$configgrp", \%customgrp);
e3580608 893 if ($fwhostsettings{'grpcnt'} > 0){&rules;}
3f8fe51e
AM
894 if ($fwhostsettings{'update'} eq 'on'){
895 $fwhostsettings{'remark'}= $grpremark;
896 $fwhostsettings{'grp_name'}=$grpname;
897 }
2a81ab0d
AM
898 &addgrp;
899 &viewtablegrp;
900}
901if ($fwhostsettings{'ACTION'} eq 'delgrp')
902{
903 &General::readhasharray("$configgrp", \%customgrp);
904 &decrease($fwhostsettings{'grp_name'});
905 foreach my $key (sort keys %customgrp)
906 {
907 if($customgrp{$key}[0] eq $fwhostsettings{'grp_name'})
908 {
909 delete $customgrp{$key};
910 }
911 }
912 &General::writehasharray("$configgrp", \%customgrp);
913 $fwhostsettings{'grp_name'}='';
914 &addgrp;
915 &viewtablegrp;
916}
917if ($fwhostsettings{'ACTION'} eq 'delservice')
918{
919 &General::readhasharray("$configsrv", \%customservice);
920 foreach my $key (keys %customservice) {
921 if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
922 #&deletefromgrp($customhost{$key}[0],$configgrp);
923 delete $customservice{$key};
924 &General::writehasharray("$configsrv", \%customservice);
925 last;
926 }
927 }
928 $fwhostsettings{'SRV_NAME'}='';
929 $fwhostsettings{'SRV_PORT'}='';
930 $fwhostsettings{'PROT'}='';
931 &addservice;
932}
933if ($fwhostsettings{'ACTION'} eq 'delservicegrp')
934{
935 &General::readhasharray("$configsrvgrp", \%customservicegrp);
936 &decreaseservice($fwhostsettings{'SRVGRP_NAME'});
937 foreach my $key (sort keys %customservicegrp)
938 {
939 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
940 {
941 delete $customservicegrp{$key};
942 }
943 }
944 &General::writehasharray("$configsrvgrp", \%customservicegrp);
945 $fwhostsettings{'SRVGRP_NAME'}='';
946 &addservicegrp;
947 &viewtableservicegrp;
948}
949if ($fwhostsettings{'ACTION'} eq 'delgrpservice')
950{
3f8fe51e
AM
951 my $grpname;
952 my $grpremark;
2a81ab0d
AM
953 &General::readhasharray("$configsrvgrp", \%customservicegrp);
954 &General::readhasharray("$configsrv", \%customservice);
955 foreach my $key (keys %customservicegrp){
956 if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2].",".$customservicegrp{$key}[3] eq $fwhostsettings{'delsrvfromgrp'})
957 {
958 #decrease count from source service
959 foreach my $key1 (sort keys %customservice){
960 if($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
961 $customservice{$key1}[4]--;
962 last;
963 }
964 }
965 &General::writehasharray("$configsrv", \%customservice);
3f8fe51e
AM
966 $grpname=$customservicegrp{$key}[0];
967 $grpremark=$customservicegrp{$key}[1];
968 delete $customservicegrp{$key};
2a81ab0d
AM
969 }
970 }
971 &General::writehasharray("$configsrvgrp", \%customservicegrp);
972 &rules;
3f8fe51e 973 if ($fwhostsettings{'updatesrvgrp'} eq 'on'){
3f8fe51e
AM
974 $fwhostsettings{'SRVGRP_NAME'}=$grpname;
975 $fwhostsettings{'SRVGRP_REMARK'}=$grpremark;
976 }
2a81ab0d
AM
977 &addservicegrp;
978 &viewtableservicegrp;
979
980}
981if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'})
982{
983 &addnet;
984 &viewtablenet;
985}
986if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newhost'})
987{
988 &addhost;
989 &viewtablehost;
990}
991if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgrp'})
992{
993 &addgrp;
994 &viewtablegrp;
995}
996if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservice'})
997{
998 &addservice;
999}
1000if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservicegrp'})
1001{
1002 &addservicegrp;
1003 &viewtableservicegrp;
1004}
6c869961
AM
1005if ($fwhostsettings{'ACTION'} eq 'changegrpremark')
1006{
1007 &General::readhasharray("$configgrp", \%customgrp);
d0815ce4 1008 if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){
6c869961
AM
1009 foreach my $key (sort keys %customgrp)
1010 {
6c869961
AM
1011 if($customgrp{$key}[0] eq $fwhostsettings{'grp'} && $customgrp{$key}[1] eq $fwhostsettings{'oldrem'})
1012 {
6c869961
AM
1013 $customgrp{$key}[1]='';
1014 $customgrp{$key}[1]=$fwhostsettings{'newrem'};
1015 }
1016 }
1017 &General::writehasharray("$configgrp", \%customgrp);
1018 $fwhostsettings{'update'}='on';
6c869961
AM
1019 $fwhostsettings{'remark'}=$fwhostsettings{'newrem'};
1020 }else{
1021 $errormessage=$Lang::tr{'fwhost err remark'};
1022 $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'};
1023 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1024 $fwhostsettings{'update'} = 'on';
1025 }
1026 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1027 &addgrp;
1028 &viewtablegrp;
1029}
1030if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark')
1031{
1032 &General::readhasharray("$configsrvgrp", \%customservicegrp );
d0815ce4 1033 if ($fwhostsettings{'oldsrvrem'} ne $fwhostsettings{'newsrvrem'} && (&validremark($fwhostsettings{'newsrvrem'}) || $fwhostsettings{'newsrvrem'} eq '')){
6c869961
AM
1034 foreach my $key (sort keys %customservicegrp)
1035 {
6c869961
AM
1036 if($customservicegrp{$key}[0] eq $fwhostsettings{'srvgrp'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvrem'})
1037 {
6c869961
AM
1038 $customservicegrp{$key}[1]='';
1039 $customservicegrp{$key}[1]=$fwhostsettings{'newsrvrem'};
1040 }
1041 }
1042 &General::writehasharray("$configsrvgrp", \%customservicegrp);
1043 $fwhostsettings{'updatesrvgrp'}='on';
6c869961
AM
1044 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'newsrvrem'};
1045 }else{
1046 $errormessage=$Lang::tr{'fwhost err remark'};
1047 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'oldsrvrem'};
1048 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1049 $fwhostsettings{'updatesrvgrp'} = 'on';
1050 }
1051 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1052 &addservicegrp;
1053 &viewtableservicegrp;
1054}
2a81ab0d
AM
1055### VIEW ###
1056if($fwhostsettings{'ACTION'} eq '')
1057{
1058 &showmenu;
1059}
1060### FUNCTIONS ###
1061sub showmenu
1062{
7bf83f9d 1063 if (-f "${General::swroot}/forward/reread"){
a0fb1099 1064 print "<table border='1' rules='groups' bgcolor='lightgreen' width='100%'><form method='post'><td><div style='font-size:11pt; font-weight: bold;vertical-align: middle; '><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-face: Comic Sans MS; color: green; font-weight: bold; font-size: 14pt;'>&nbsp &nbsp $Lang::tr{'fwhost reread'}</td></tr></table></form><br>";
7bf83f9d 1065 }
2a81ab0d
AM
1066 &Header::openbox('100%', 'left',$Lang::tr{'fwhost menu'});
1067 print<<END;
1068 <table border='0' width='100%'><form method='post'>
1069 <tr><td><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'}' /></td>
1070 <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newservice'}' /><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newservicegrp'}' /></td></tr>
7bf83f9d 1071 <tr><td colspan='6'><hr></hr></td></tr></table></form>
2a81ab0d 1072END
2a81ab0d
AM
1073 &Header::closebox();
1074
1075}
1076# Add
1077sub addnet
1078{
1079 &error;
1080 &showmenu;
1081 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addnet'});
1082 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
f80db6a4 1083 $fwhostsettings{'orgnetremark'}=$fwhostsettings{'NETREMARK'};
2a81ab0d
AM
1084 print<<END;
1085 <table border='0' width='100%'><form method='post' style='display:inline' >
8013bd0a
AM
1086 <tr><td width='15%'>$Lang::tr{'name'}:</td><td><input type='TEXT' name='HOSTNAME' id='textbox1' value='$fwhostsettings{'HOSTNAME'}' $fwhostsettings{'BLK_HOST'} size='14'><script>document.getElementById('textbox1').focus()</script></td></tr>
1087 <tr><td>$Lang::tr{'fwhost netaddress'}:</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='14' maxlength='15'></td></tr>
1088 <tr><td>$Lang::tr{'netmask'}:</td><td><input type='TEXT' name='SUBNET' value='$fwhostsettings{'SUBNET'}' $fwhostsettings{'BLK_IP'} size='14' maxlength='15'></td></tr>
1089 <tr><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='NETREMARK' value='$fwhostsettings{'NETREMARK'}' style='width: 98.5%;'></td></tr>
5dd84c25 1090 <tr><td colspan='6'><br><hr></hr></td></tr><tr>
2a81ab0d
AM
1091END
1092 if ($fwhostsettings{'ACTION'} eq 'editnet' || $fwhostsettings{'error'} eq 'on')
1093 {
f80db6a4 1094 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 1095 }else{
7f5b2820 1096 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'>";
2a81ab0d 1097 }
7f5b2820 1098 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'></td></tr></table></form>";
2a81ab0d
AM
1099 &Header::closebox();
1100}
1101sub addhost
1102{
1103 &error;
1104 &showmenu;
1105 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addhost'});
1106 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
f80db6a4 1107 $fwhostsettings{'orgremark'}=$fwhostsettings{'HOSTREMARK'};
2a81ab0d
AM
1108 print<<END;
1109 <table border='0' width='100%'><form method='post' style='display:inline'>
8013bd0a 1110 <tr><td>$Lang::tr{'name'}:</td><td><input type='TEXT' name='HOSTNAME' id='textbox1' value='$fwhostsettings{'HOSTNAME'}' $fwhostsettings{'BLK_HOST'} size='14'><script>document.getElementById('textbox1').focus()</script></td></tr>
f2ab6fba 1111 <tr><td>IP/MAC:</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='14' maxlength='17'></td></tr>
8013bd0a 1112 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='HOSTREMARK' value='$fwhostsettings{'HOSTREMARK'}' style='width:98%;'></td></tr>
92e4ae9d 1113 <tr><td colspan='5'><hr></hr></td></tr>
2a81ab0d
AM
1114END
1115
1116 if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on')
1117 {
1118
8013bd0a 1119 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 1120 }else{
8013bd0a 1121 print " <td colspan='4' align='right'><input type='submit' name='savehost' value='$Lang::tr{'save'}'style='min-width:100px;' /><input type='hidden' name='ACTION' value='savehost' /><input type='hidden' name='newhost' value='on'>";
2a81ab0d 1122 }
7f5b2820 1123 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'></td></tr></table></form>";
2a81ab0d
AM
1124 &Header::closebox();
1125}
1126sub addgrp
1127{
1128 &hint;
1129 &error;
1130 &showmenu;
1131 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addgrp'});
1132 &General::setup_default_networks(\%defaultNetworks);
8013bd0a
AM
1133 &General::readhasharray("$configccdnet", \%ccdnet);
1134 &General::readhasharray("$confignet", \%customnetwork);
1135 &General::readhasharray("$configccdhost", \%ccdhost);
1136 &General::readhasharray("$confighost", \%customhost);
1137 &General::readhasharray("$configipsec", \%ipsecconf);
1138
2a81ab0d 1139 my %checked=();
8013bd0a 1140 my $show='';
2a81ab0d
AM
1141 $checked{'check1'}{'off'} = '';
1142 $checked{'check1'}{'on'} = '';
1143 $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED';
1144 $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'};
6c869961
AM
1145 my $grp=$fwhostsettings{'grp_name'};
1146 my $rem=$fwhostsettings{'remark'};
2a81ab0d
AM
1147 if ($fwhostsettings{'update'} eq ''){
1148 print<<END;
1149 <table width='100%' border='0'><form method='post'>
8013bd0a
AM
1150 <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' size='14'></td></tr>
1151 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td ><input type='TEXT' name='remark' value='$fwhostsettings{'remark'}' style='width: 98%;'></td></tr>
1152 <tr><td colspan='2'><br><hr></td></tr></table>
2a81ab0d
AM
1153END
1154 }else{
1155 print<<END;
6c869961 1156 <table width='100%' border='0'><form method='post' style='display:inline'>
8013bd0a
AM
1157 <tr><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='TEXT' name='grp' value='$fwhostsettings{'grp_name'}' readonly ></td><td></td></tr>
1158 <tr><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='newrem' size='45' value='$fwhostsettings{'remark'}' style='width:98%'></td><td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='ACTION' value='changegrpremark' ></td></tr></table></form>
6c869961 1159 <hr>
2a81ab0d 1160END
2a81ab0d
AM
1161 }
1162 if ($fwhostsettings{'update'} eq 'on'){
2a81ab0d 1163 print<<END;
8013bd0a
AM
1164 <form method='post'><input type='hidden' name='remark' value='$rem'><input type='hidden' name='grp_name' value='$grp'>
1165 <table width='100%' border='0'>
1166 <tr><td width=50% valign='top'>
1167 <table width='100%' border='0'>
1168 <tr><td width='1%'><input type='radio' name='grp2' value='std_net' checked></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost stdnet'}</td><td><select name='DEFAULT_SRC_ADR' style='min-width:185px;'>
2a81ab0d
AM
1169END
1170 foreach my $network (sort keys %defaultNetworks)
1171 {
1172 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
62fc8511 1173 next if($defaultNetworks{$network}{'NAME'} eq "RED");
2a81ab0d
AM
1174 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1175 print " selected='selected'" if ($fwhostsettings{'DEFAULT_SRC_ADR'} eq $defaultNetworks{$network}{'NAME'});
1176 print ">$network</option>";
1177 }
8013bd0a
AM
1178 print"</select></td></tr>";
1179 if (! -z $confignet){
1180 print"<tr><td><input type='radio' name='grp2' value='cust_net' $checked{'grp2'}{'cust_net'}></td><td>$Lang::tr{'fwhost cust net'}</td><td><select name='CUST_SRC_NET' style='min-width:185px;'>";
eff2dbf8 1181 foreach my $key (sort { ncmp($customnetwork{$a}[0],$customnetwork{$b}[0]) } keys %customnetwork) {
8013bd0a
AM
1182 print"<option>$customnetwork{$key}[0]</option>";
1183 }
1184 print"</select></td></tr>";
2a81ab0d 1185 }
8013bd0a
AM
1186 if (! -z $confighost){
1187 print"<tr><td valign='top'><input type='radio' name='grp2' value='cust_host' $checked{'grp2'}{'cust_host'}></td><td valign='top'>$Lang::tr{'fwhost cust addr'}</td><td><select name='CUST_SRC_HOST' style='min-width:185px;'>";
eff2dbf8 1188 foreach my $key (sort { ncmp($customhost{$a}[0],$customhost{$b}[0]) } keys %customhost) {
8013bd0a
AM
1189 print"<option>$customhost{$key}[0]</option>";
1190 }
1191 print"</select></td></tr>";
1192 }
1193 print"</table>";
1194 #Inner table right
1195 print"</td><td valign='top'><table width='100%' border='0'>";
1196 #OVPN networks
1197 if (! -z $configccdnet){
1198 print"<td width='1%'><input type='radio' name='grp2' value='ovpn_net' $checked{'grp2'}{'ovpn_net'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='OVPN_CCD_NET' style='min-width:185px;'>";
eff2dbf8 1199 foreach my $key (sort { ncmp($ccdnet{$a}[0],$ccdnet{$b}[0]) } keys %ccdnet)
8013bd0a
AM
1200 {
1201 print"<option value='$ccdnet{$key}[0]'>$ccdnet{$key}[0]</option>";
1202 }
1203 print"</select></td></tr>";
2a81ab0d 1204 }
8013bd0a 1205 #OVPN clients
eff2dbf8 1206 foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost)
2a81ab0d
AM
1207 {
1208 if ($ccdhost{$key}[33] ne ''){
8013bd0a
AM
1209 print"<td width='1%'><input type='radio' name='grp2' value='ovpn_host' $checked{'grp2'}{'ovpn_host'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='OVPN_CCD_HOST' style='min-width:185px;'>" if ($show eq '');
1210 $show='1';
2a81ab0d
AM
1211 print"<option value='$ccdhost{$key}[1]'>$ccdhost{$key}[1]</option>";
1212 }
1213 }
8013bd0a
AM
1214 if ($show eq '1'){$show='';print"</select></td></tr>";}
1215 #OVPN n2n networks
eff2dbf8 1216 foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost) {
2a81ab0d 1217 if($ccdhost{$key}[3] eq 'net'){
8013bd0a
AM
1218 print"<td width='1%'><input type='radio' name='grp2' value='ovpn_n2n' $checked{'grp2'}{'ovpn_n2n'}></td><td valign='top'>$Lang::tr{'fwhost ovpn_n2n'}</td><td colspan='3'><select name='OVPN_N2N' style='min-width:185px;'>" if ($show eq '');
1219 $show='1';
2a81ab0d
AM
1220 print"<option>$ccdhost{$key}[1]</option>";
1221 }
1222 }
8013bd0a
AM
1223 if ($show eq '1'){$show='';print"</select></td></tr>";}
1224 #IPsec networks
eff2dbf8 1225 foreach my $key (sort { ncmp($ipsecconf{$a}[0],$ipsecconf{$b}[0]) } keys %ipsecconf) {
2a81ab0d 1226 if ($ipsecconf{$key}[3] eq 'net'){
8013bd0a
AM
1227 print"<td valign='top'><input type='radio' name='grp2' value='ipsec_net' $checked{'grp2'}{'ipsec_net'}></td><td valign='top'>$Lang::tr{'fwhost ipsec net'}</td><td><select name='IPSEC_NET' style='min-width:185px;'>" if ($show eq '');
1228 $show='1';
2a81ab0d
AM
1229 print"<option value='$ipsecconf{$key}[1]'>$ipsecconf{$key}[1]</option>";
1230 }
1231 }
8013bd0a
AM
1232 if ($show eq '1'){$show='';print"</select></td></tr>";}
1233 print"</table>";
1234 print"</td></tr></table>";
6c869961 1235 print"<br><br><b>$Lang::tr{'fwhost attention'}:</b><br> $Lang::tr{'fwhost macwarn'}<br><hr>";
2a81ab0d 1236 }
8013bd0a
AM
1237 print"<table border='0' width='100%'>";
1238 print"<tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' /><input type='hidden' name='oldremark' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='update' value=$fwhostsettings{'update'} ><input type='hidden' name='ACTION' value='savegrp' ></form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'><input type='hidden' name='ACTION' value'reset'></td></td></table></form>";
2a81ab0d
AM
1239 &Header::closebox();
1240}
1241sub addservice
1242{
1243 &error;
1244 &showmenu;
1245 &Header::openbox('100%', 'left', $Lang::tr{'fwhost newservice'});
1246 if ($fwhostsettings{'updatesrv'} eq 'on')
1247 {
1248 $fwhostsettings{'oldsrvname'} = $fwhostsettings{'SRV_NAME'};
1249 $fwhostsettings{'oldsrvport'} = $fwhostsettings{'SRV_PORT'};
1250 $fwhostsettings{'oldsrvprot'} = $fwhostsettings{'PROT'};
1251 }
1252 print<<END;
1253 <table width='100%' border='0'><form method='post'>
8013bd0a
AM
1254 <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='14'><script>document.getElementById('textbox1').focus()</script></td></tr>
1255 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT'>
2a81ab0d
AM
1256END
1257 foreach ("TCP","UDP","ICMP")
1258 {
1259 if ($_ eq $fwhostsettings{'PROT'})
1260 {
1261 print"<option selected>$_</option>";
1262 }else{
1263 print"<option>$_</option>";
1264 }
1265 }
1266 print<<END;
8013bd0a
AM
1267 </select></td></tr>
1268 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost icmptype'}</td><td><select name='ICMP_TYPES'>
2a81ab0d
AM
1269END
1270 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1271 print"<option>All ICMP-Types</option>";
eff2dbf8 1272 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
2a81ab0d
AM
1273 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1274 }
1275
1276 print<<END;
8013bd0a
AM
1277 </select></td></tr>
1278 <tr><td width='10%'>$Lang::tr{'fwhost port'}:</td><td><input type='text' name='SRV_PORT' value='$fwhostsettings{'SRV_PORT'}' maxlength='11' size='14'></td></tr>
5dd84c25 1279 <tr><td colspan='6'><br><hr></td></tr>
2a81ab0d
AM
1280 <tr><td colspan='6' align='right'>
1281END
1282 if ($fwhostsettings{'updatesrv'} eq 'on')
1283 {
1284 print<<END;
7f5b2820 1285 <input type='submit' value='$Lang::tr{'update'}'style='min-width:100px;' >
2a81ab0d
AM
1286 <input type='hidden' name='ACTION' value='updateservice'>
1287 <input type='hidden' name='oldsrvname' value='$fwhostsettings{'oldsrvname'}'>
1288 <input type='hidden' name='oldsrvport' value='$fwhostsettings{'oldsrvport'}'>
1289 <input type='hidden' name='oldsrvprot' value='$fwhostsettings{'oldsrvprot'}'></form>
1290END
1291
1292 }else{
7f5b2820 1293 print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>";
2a81ab0d
AM
1294 }
1295 print<<END;
7f5b2820 1296 <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr>
2a81ab0d
AM
1297 </table></form>
1298
1299
1300END
1301 &Header::closebox();
1302 &viewtableservice;
1303}
1304sub addservicegrp
1305{
1306 &hint;
1307 &error;
1308 &showmenu;
1309 &Header::openbox('100%', 'left', $Lang::tr{'fwhost newservicegrp'});
1310 $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'};
2a81ab0d
AM
1311 if ($fwhostsettings{'updatesrvgrp'} eq ''){
1312 print<<END;
1313 <table width='100%' border='0'><form method='post'>
8013bd0a
AM
1314 <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='text' name='SRVGRP_NAME' value='$fwhostsettings{'SRVGRP_NAME'}' size='14'></td></tr>
1315 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='text' name='SRVGRP_REMARK' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width: 98%;'></td></tr>
1316 <tr><td colspan='2'><br><hr></tr>
2a81ab0d
AM
1317 </table>
1318END
1319 }else{
1320 print<<END;
6c869961 1321 <table width='100%' border='0'><form method='post' style='display:inline'>
8013bd0a
AM
1322 <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='text' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}' readonly size='14'></td><td width='3%'></td></tr>
1323 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='text' name='newsrvrem' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width:98%;'></td><td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldsrvrem' value='$fwhostsettings{'oldsrvgrpremark'}'><input type='hidden' name='ACTION' value='changesrvgrpremark' ></td></tr>
1324 <tr><td colspan='3'><br><hr></td></td></tr>
6c869961 1325 </table></form>
2a81ab0d
AM
1326END
1327 }
1328 if($fwhostsettings{'updatesrvgrp'} eq 'on'){
2a81ab0d 1329 print<<END;
6c869961 1330 <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%'>
2a81ab0d
AM
1331 <tr><td width='1%' nowrap='nowrap'>$Lang::tr{'fwhost cust service'}</td><td><select name='CUST_SRV' style='min-width:185px;'>
1332END
1333 &General::readhasharray("$configsrv", \%customservice);
eff2dbf8 1334 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice)
2a81ab0d
AM
1335 {
1336 print "<option>$customservice{$key}[0]</option>";
1337 }
1338 print<<END;
1339 </select></td></tr>
5dd84c25 1340 <tr><td colspan='4'><br><br></td></tr>
2a81ab0d
AM
1341 <tr><td colspan='4'><hr></td></tr>
1342 </table>
1343END
1344 }
1345 print<<END;
7f5b2820
AM
1346 <table width='100%' border='0'>
1347 <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
1348 </table></form>
1349END
2a81ab0d
AM
1350 &Header::closebox();
1351}
1352# View
1353sub viewtablenet
1354{
1355 if(! -z $confignet){
1356 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'});
1357 &General::readhasharray("$confignet", \%customnetwork);
1358 if (!keys %customnetwork)
1359 {
1360 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1361 }else{
1362 print<<END;
05612a54 1363 <table border='0' width='100%' cellspacing='0'>
e5a058c1 1364 <tr><td align='center'><b>$Lang::tr{'name'}</td><td align='center'><b>$Lang::tr{'fwhost netaddress'}</td><td align='center'><b>$Lang::tr{'netmask'}</td><td align='center'><b>$Lang::tr{'remark'}</td><td align='center'><b>$Lang::tr{'used'}</td><td></td><td width='3%'></td></tr>
2a81ab0d
AM
1365END
1366 }
1367 my $count=0;
eff2dbf8 1368 foreach my $key (sort {ncmp($a,$b)} keys %customnetwork) {
2a81ab0d
AM
1369 if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) {
1370 print" <tr bgcolor='${Header::colouryellow}'>";
1371 }elsif ($count % 2)
1372 {
1373 print" <tr bgcolor='$color{'color22'}'>";
1374 }else
1375 {
1376 print" <tr bgcolor='$color{'color20'}'>";
1377 }
1378 print<<END;
05612a54 1379 <td width='20%'><form method='post'>$customnetwork{$key}[0]</td><td width=15%' align='center'>$customnetwork{$key}[1]</td><td width='15%' align='center'>$customnetwork{$key}[2]</td><td width='40%'>$customnetwork{$key}[3]</td><td align='center'>$customnetwork{$key}[4]x</td>
2a81ab0d
AM
1380 <td width='1%'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} />
1381 <input type='hidden' name='ACTION' value='editnet'>
1382 <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' />
1383 <input type='hidden' name='IP' value='$customnetwork{$key}[1]' />
1384 <input type='hidden' name='SUBNET' value='$customnetwork{$key}[2]' />
e5a058c1 1385 <input type='hidden' name='NETREMARK' value='$customnetwork{$key}[3]' />
2a81ab0d
AM
1386 </td></form>
1387END
e5a058c1 1388 if($customnetwork{$key}[4] == '0')
2a81ab0d
AM
1389 {
1390 print"<td width='1%'><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>";
1391 }else{
1392 print"<td></td></form></tr>";
1393 }
1394 $count++;
1395 }
1396 print"</table>";
1397 &Header::closebox();
1398 }
1399
1400}
1401sub viewtablehost
1402{
1403 if (! -z $confighost){
1404 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust addr'});
1405 &General::readhasharray("$confighost", \%customhost);
1406 if (!keys %customhost)
1407 {
1408 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1409 }else{
1410 print<<END;
05612a54 1411 <table border='0' width='100%' cellspacing='0'>
e3580608 1412 <tr><td align='center'><b>$Lang::tr{'name'}</td><td align='center'><b>$Lang::tr{'fwhost ip_mac'}</td><td align='center'><b>$Lang::tr{'remark'}</td><td align='center'><b>$Lang::tr{'used'}</td><td></td><td width='3%'></td></tr>
2a81ab0d
AM
1413END
1414 }
1415 my $count=0;
eff2dbf8 1416 foreach my $key (sort { ncmp ($customhost{$a}[0],$customhost{$b}[0])} keys %customhost) {
2a81ab0d
AM
1417 if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) {
1418 print" <tr bgcolor='${Header::colouryellow}'>";
1419 }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";}
1420 else{ print" <tr bgcolor='$color{'color20'}'>";}
1421 my ($ip,$sub)=split(/\//,$customhost{$key}[2]);
e3580608 1422 $customhost{$key}[4]=~s/\s+//g;
2a81ab0d 1423 print<<END;
05612a54 1424 <td width='20%'><form method='post'>$customhost{$key}[0]</td><td width='20%' align='center'>$ip</td><td width='50%' align='left'>$customhost{$key}[3]</td><td align='center'>$customhost{$key}[4]x</td>
2a81ab0d
AM
1425 <td width='1%'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} />
1426 <input type='hidden' name='ACTION' value='edithost' />
1427 <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' />
1428 <input type='hidden' name='IP' value='$ip' />
1429 <input type='hidden' name='type' value='$customhost{$key}[1]' />
e3580608 1430 <input type='hidden' name='HOSTREMARK' value='$customhost{$key}[3]' />
2a81ab0d
AM
1431 </td></form>
1432END
e3580608 1433 if($customhost{$key}[4] == '0')
2a81ab0d
AM
1434 {
1435 print"<td width='1%'><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>";
1436 }else{
1437 print"<td width='1%'></td></tr>";
1438 }
1439 $count++;
1440 }
1441 print"</table>";
1442 &Header::closebox();
1443 }
1444}
1445sub viewtablegrp
1446{
1447 if(! -z "$configgrp"){
1448 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust grp'});
1449 &General::readhasharray("$configgrp", \%customgrp);
1450 &General::readhasharray("$configipsec", \%ipsecconf);
1451 &General::readhasharray("$configccdhost", \%ccdhost);
1452 &General::readhasharray("$configccdnet", \%ccdnet);
1453 &General::readhasharray("$confighost", \%customhost);
1454 &General::readhasharray("$confignet", \%customnetwork);
1455 my @grp=();
1456 my $helper='';
8f204435 1457 my $count=1;
2a81ab0d
AM
1458 my $grpname;
1459 my $remark;
12dcfbbd 1460 my $number;
2cee2462 1461 my $delflag;
2a81ab0d
AM
1462 if (!keys %customgrp)
1463 {
1464 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1465 }else{
eff2dbf8 1466 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp ($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
2a81ab0d
AM
1467 $count++;
1468 if ($helper ne $customgrp{$key}[0]){
2cee2462 1469 $delflag='0';
eff2dbf8 1470 foreach my $key1 (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
2cee2462
AM
1471 if ($customgrp{$key}[0] eq $customgrp{$key1}[0])
1472 {
1473 $delflag++;
1474 }
d0815ce4 1475 if($delflag > 1){
d13a9363
AM
1476 last;
1477 }
2cee2462 1478 }
8f204435 1479 $number=1;
6c869961 1480 if ($customgrp{$key}[2] eq "none"){$customgrp{$key}[2]=$Lang::tr{'fwhost empty'};}
2a81ab0d 1481 $grpname=$customgrp{$key}[0];
6c869961 1482 $remark="$customgrp{$key}[1]";
2a81ab0d
AM
1483 if($count >=2){print"</table>";}
1484 print "<br><b><u>$grpname</u></b> &nbsp &nbsp";
1485 print " <b>$Lang::tr{'remark'}:</b>&nbsp $remark &nbsp " if ($remark ne '');
937d4e08 1486 print "<b>$Lang::tr{'used'}:</b> $customgrp{$key}[4]x";
2a81ab0d
AM
1487 if($customgrp{$key}[4] == '0')
1488 {
1489 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>";
1490 }
1491 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>";
05612a54 1492 print"<table width='100%' style='border: 1px solid #CCCCCC;' rules='none' cellspacing='0'><tr><td align='center'><b>Name</b></td><td align='center'><b>$Lang::tr{'ip address'}</b></td><td align='center' width='25%'><b>$Lang::tr{'fwhost type'}</td><td></td></tr>";
2a81ab0d 1493 }
2cee2462 1494
2a81ab0d
AM
1495 if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) {
1496 print" <tr bgcolor='${Header::colouryellow}'>";
6c869961
AM
1497 }elsif ($count %2 == 0){
1498 print"<tr bgcolor='$color{'color22'}'>";
1499 }else{
1500 print"<tr bgcolor='$color{'color20'}'>";
1501 }
2a81ab0d
AM
1502 my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]);
1503 if ($ip eq ''){print"<tr bgcolor='${Header::colouryellow}'>";}
05612a54 1504 print "<td width='39%' align='left'>";
2a81ab0d
AM
1505 if($customgrp{$key}[3] eq 'Standard Network'){
1506 print &get_name($customgrp{$key}[2])."</td>";
1507 }else{
1508 print "$customgrp{$key}[2]</td>";
1509 }
1510 if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost empty'}){
f833ef46 1511 print "<td align='center'>$Lang::tr{'fwhost deleted'}</td><td align='center'>$customgrp{$key}[3]</td><td width='1%'><form method='post'>";
2a81ab0d 1512 }else{
05612a54 1513 print"<td align='center'>$ip</td><td align='center'>$customgrp{$key}[3]</td><td width='1%'><form method='post'>";
2a81ab0d 1514 }
2cee2462 1515 if ($delflag > '1' && $ip ne ''){
2a81ab0d
AM
1516 print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
1517 }
e3580608 1518 print"<input type='hidden' name='ACTION' value='deletegrphost'><input type='hidden' name='grpcnt' value='$customgrp{$key}[4]'><input type='hidden' name='update' value='$fwhostsettings{'update'}'><input type='hidden' name='delhost' value='$grpname,$remark,$customgrp{$key}[2],$customgrp{$key}[3]'></form></td></tr>";
2a81ab0d
AM
1519
1520 $helper=$customgrp{$key}[0];
12dcfbbd 1521 $number++;
2a81ab0d
AM
1522 }
1523 print"</table>";
1524
1525 }
1526 &Header::closebox();
1527}
1528
1529}
1530sub viewtableservice
1531{
1532 my $count=0;
1533 if(! -z "$configsrv")
1534 {
1535 &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'});
1536 &General::readhasharray("$configsrv", \%customservice);
1537 print<<END;
05612a54 1538 <table width='100%' border='0' cellspacing='0'>
2a81ab0d
AM
1539 <tr><td align='center'><b>$Lang::tr{'fwhost srv_name'}</td><td align='center'><b>$Lang::tr{'fwhost prot'}</td><td align='center'><b>$Lang::tr{'fwhost port'}</td><td align='center'><b>ICMP</td><td align='center'><b>$Lang::tr{'fwhost used'}</td><td></td><td width='3%'></td></tr>
1540END
eff2dbf8 1541 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0])} keys %customservice)
2a81ab0d
AM
1542 {
1543 $count++;
1544 if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) {
1545 print" <tr bgcolor='${Header::colouryellow}'>";
1546 }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";}else{ print" <tr bgcolor='$color{'color20'}'>";}
1547 print<<END;
1548 <td>$customservice{$key}[0]</td><td align='center'>$customservice{$key}[2]</td><td align='center'>$customservice{$key}[1]</td><td align='center'>
1549END
1550 if($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
1551
1552 print<<END;
1553 </td><td align='center'>$customservice{$key}[4]x</td>
1554 <td width='1%'><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' />
1555 <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' />
1556 <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' />
1557 <input type='hidden' name='PROT' value='$customservice{$key}[2]' /></form></td>
1558END
1559 if ($customservice{$key}[4] eq '0')
1560 {
1561 print"<td width='1%'><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>";
1562 }else{
1563 print"<td></td></tr>";
1564 }
1565 }
1566 print"</table>";
1567 &Header::closebox();
1568 }
1569}
1570sub viewtableservicegrp
1571{
1572 my $count=0;
1573 my $grpname;
1574 my $remark;
1575 my $helper;
937d4e08
AM
1576 my $port;
1577 my $protocol;
c7043621 1578 my $delflag;
2a81ab0d 1579 if (! -z $configsrvgrp){
2a81ab0d
AM
1580 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'});
1581 &General::readhasharray("$configsrvgrp", \%customservicegrp);
937d4e08 1582 &General::readhasharray("$configsrv", \%customservice);
2a81ab0d 1583 my $number= keys %customservicegrp;
eff2dbf8 1584 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
2a81ab0d
AM
1585 $count++;
1586 if ($helper ne $customservicegrp{$key}[0]){
d13a9363 1587 $delflag=0;
eff2dbf8 1588 foreach my $key1 (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) } keys %customservicegrp){
d13a9363
AM
1589 if ($customservicegrp{$key}[0] eq $customservicegrp{$key1}[0])
1590 {
1591 $delflag++;
1592 }
1593 if($delflag > 1){
1594 last;
1595 }
1596 }
2a81ab0d 1597 $grpname=$customservicegrp{$key}[0];
6c869961
AM
1598 if ($customservicegrp{$key}[2] eq "none"){
1599 $customservicegrp{$key}[2]=$Lang::tr{'fwhost empty'};
0b54aaed
AM
1600 $port='';
1601 $protocol='';
6c869961
AM
1602 }
1603 $remark="$customservicegrp{$key}[1]";
2a81ab0d
AM
1604 if($count >=2){print"</table>";}
1605 print "<br><b><u>$grpname</u></b> &nbsp &nbsp ";
1606 print "<b>$Lang::tr{'remark'}:</b>&nbsp $remark " if ($remark ne '');
937d4e08
AM
1607 print "&nbsp <b>$Lang::tr{'used'}:</b> $customservicegrp{$key}[3]x";
1608 if($customservicegrp{$key}[3] == '0')
2a81ab0d
AM
1609 {
1610 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>";
1611 }
1612 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>";
05612a54 1613 print"<table width='100%' style='border: 1px solid #CCCCCC;' rules='none' cellspacing='0'><tr><td align='center'><b>Name</b></td><td align='center'><b>$Lang::tr{'port'}</b></td><td align='center' width='25%'><b>$Lang::tr{'fwhost prot'}</td><td></td></tr>";
2a81ab0d
AM
1614 }
1615 if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) {
1616 print" <tr bgcolor='${Header::colouryellow}'>";
6c869961 1617 }elsif ($count %2 == 0){
0f869e32
AM
1618 print"<tr bgcolor='$color{'color22'}'>";
1619 }else{
1620 print"<tr bgcolor='$color{'color20'}'>";
1621 }
1622 print "<td width='39%'>$customservicegrp{$key}[2]</td>";
937d4e08
AM
1623 foreach my $srv (sort keys %customservice){
1624 if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){
1625 $protocol=$customservice{$srv}[2];
1626 $port=$customservice{$srv}[1];
1627 last;
1628 }
1629 }
1630 print"<td align='center'>$port</td><td align='center'>$protocol</td><td width='1%'><form method='post'>";
3f8fe51e 1631 if ($number gt '1'){
0f869e32
AM
1632 print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
1633 }
3f8fe51e 1634 print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'><input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2],$customservicegrp{$key}[3]'></form></td></tr>";
0f869e32 1635 $helper=$customservicegrp{$key}[0];
2a81ab0d
AM
1636 }
1637 print"</table>";
1638 &Header::closebox();
1639 }
1640}
1641# Check
1642sub checkname
1643{
1644 my %hash=%{(shift)};
1645 foreach my $key (keys %hash) {
1646 if($hash{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
1647 return 0;
1648 }
1649 }
1650 return 1;
1651
1652}
1653sub checkip
1654{
1655
1656 my %hash=%{(shift)};
1657 my $a=shift;
1658 foreach my $key (keys %hash) {
1659 if($hash{$key}[$a] eq $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'})){
1660 return 0;
1661 }
1662 }
1663 return 1;
1664}
1665sub checksubnet
1666{
1667
1668 my %hash=%{(shift)};
1669 &General::readhasharray("$confignet", \%hash);
1670 foreach my $key (keys %hash) {
1671 if(&General::IpInSubnet($fwhostsettings{'IP'},$hash{$key}[1],$hash{$key}[2]))
1672 {
1673 return 1;
1674 }
1675 }
1676 return 0;
1677}
1678sub checkservicegroup
1679{
1680 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1681
1682
1683 #check name
7772ae73 1684 if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'}))
2a81ab0d
AM
1685 {
1686 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1687 return $errormessage;
1688 }
2a81ab0d
AM
1689 #check empty selectbox
1690 if (keys %customservice lt 1)
1691 {
1692 $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>";
1693 }
2a81ab0d
AM
1694 #check if name already exists
1695 if ($fwhostsettings{'updatesrvgrp'} ne 'on'){
1696 foreach my $key (keys %customservicegrp) {
1697 if( $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} ){
1698 $errormessage.=$Lang::tr{'fwhost err grpexist'}."<br>";
1699
1700 }
1701 }
1702 }
1703 #check if service already exists in group
1704 foreach my $key (keys %customservicegrp) {
13e5dda4
AM
1705 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){
1706 $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>";
2a81ab0d 1707 }
13e5dda4 1708 }
2a81ab0d
AM
1709 return $errormessage;
1710}
1711sub error
1712{
1713 if ($errormessage) {
1714 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1715 print "<class name='base'>$errormessage\n";
1716 print "&nbsp;</class>\n";
1717 &Header::closebox();
1718 }
1719}
1720sub hint
1721{
1722 if ($hint) {
1723 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1724 print "<class name='base'>$hint\n";
1725 print "&nbsp;</class>\n";
1726 &Header::closebox();
1727 }
1728}
1729sub get_name
1730{
1731 my $val=shift;
1732 &General::setup_default_networks(\%defaultNetworks);
1733 foreach my $network (sort keys %defaultNetworks)
1734 {
1735 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1736 }
1737}
1738sub deletefromgrp
1739{
1740 my $target=shift;
1741 my $config=shift;
1742 my %hash=();
1743 &General::readhasharray("$config",\%hash);
1744 foreach my $key (keys %hash) {
1745 $errormessage.="lese $hash{$key}[2] und $target<br>";
1746 if($hash{$key}[2] eq $target){
1747
1748 delete $hash{$key};
1749 $errormessage.="Habe $target aus Gruppe gelöscht!<br>";
1750 }
1751 }
1752 &General::writehasharray("$config",\%hash);
1753
1754}
1755sub plausicheck
1756{
2a81ab0d
AM
1757 my $edit=shift;
1758 #check hostname
d0815ce4 1759 if (!&validhostname($fwhostsettings{'HOSTNAME'}))
2a81ab0d
AM
1760 {
1761 $errormessage=$errormessage.$Lang::tr{'fwhost err name'};
1762 $fwhostsettings{'BLK_IP'}='readonly';
1763 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1764 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1765 }
1766 #check if name collides with CCD Netname
2a81ab0d
AM
1767 &General::readhasharray("$configccdnet", \%ccdnet);
1768 foreach my $key (keys %ccdnet) {
1769 if($ccdnet{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
1770 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdnet'};;
1771 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1772 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1773 last;
1774 }
1775 }
2a81ab0d
AM
1776 #check if IP collides with CCD NetIP
1777 if ($fwhostsettings{'type'} ne 'mac'){
1778 &General::readhasharray("$configccdnet", \%ccdnet);
1779 foreach my $key (keys %ccdnet) {
1780 my $test=(&General::getnetworkip($fwhostsettings{'IP'},&General::iporsubtocidr($fwhostsettings{'SUBNET'})))."/".$fwhostsettings{'SUBNET'};
1781 if($ccdnet{$key}[1] eq $test){
1782 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdipnet'};
1783 $fwhostsettings{'IP'} = $fwhostsettings{'orgip'};
1784 $fwhostsettings{'SUBNET'} = $fwhostsettings{'orgsubnet'};
1785 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1786 last;
1787 }
1788 }
1789 }
2a81ab0d
AM
1790 #check if name collides with CCD Hostname
1791 &General::readhasharray("$configccdhost", \%ccdhost);
1792 foreach my $key (keys %ccdhost) {
1793 my ($ip,$sub)=split(/\//,$ccdhost{$key}[33]);
1794 if($ip eq $fwhostsettings{'IP'}){
1795 $errormessage=$Lang::tr{'fwhost err isccdiphost'};
1796 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1797 last;
1798 }
1799 }
1800 #check if IP collides with CCD HostIP (only hosts)
1801 if ($edit eq 'edithost')
1802 {
1803 foreach my $key (keys %ccdhost) {
1804 if($ccdhost{$key}[1] eq $fwhostsettings{'HOSTNAME'}){
1805 $errormessage=$Lang::tr{'fwhost err isccdhost'};
1806 $fwhostsettings{'IP'} = $fwhostsettings{'orgname'};
1807 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1808 last;
1809 }
1810 }
1811 }
1812 #check if network with this name already exists
1813 &General::readhasharray("$confignet", \%customnetwork);
1814 if (!&checkname(\%customnetwork))
1815 {
1816 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err netexist'};
1817 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1818 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1819 }
1820 #check if network ip already exists
1821 if (!&checkip(\%customnetwork,1))
1822 {
1823 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err net'};
1824 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1825 }
1826 #check if host with this name already exists
1827 &General::readhasharray("$confighost", \%customhost);
1828 if (!&checkname(\%customhost))
1829 {
0013abb0 1830 $errormessage.="<br>".$Lang::tr{'fwhost err hostexist'};
2a81ab0d 1831 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
ed73b87e 1832 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2a81ab0d
AM
1833 }
1834 #check if host with this ip already exists
1835 if (!&checkip(\%customhost,2))
1836 {
1837 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'};
2a81ab0d 1838 }
2a81ab0d
AM
1839 return;
1840}
1841sub getipforgroup
1842{
1843 my $name=$_[0],
1844 my $type=$_[1];
1845 my $value;
1846
1847 #get address from IPSEC NETWORK
1848 if ($type eq 'IpSec Network'){
1849 foreach my $key (keys %ipsecconf) {
1850 if ($ipsecconf{$key}[1] eq $name){
1851 return $ipsecconf{$key}[11];
1852 }
1853 }
1854 &deletefromgrp($name,$configgrp);
1855 }
1856
1857 #get address from IPSEC HOST
1858 if ($type eq 'IpSec Host'){
1859 foreach my $key (keys %ipsecconf) {
1860 if ($ipsecconf{$key}[1] eq $name){
1861 return $ipsecconf{$key}[10];
1862 }
1863 }
1864 &deletefromgrp($name,$configgrp);
1865 }
1866
1867 #get address from ovpn ccd Net-2-Net
1868 if ($type eq 'OpenVPN N-2-N'){
1869 foreach my $key (keys %ccdhost) {
1870 if($ccdhost{$key}[1] eq $name){
1871 my ($a,$b) = split ("/",$ccdhost{$key}[11]);
1872 $b=&General::iporsubtodec($b);
1873 return "$a/$b";
1874 }
1875 }
1876 &deletefromgrp($name,$configgrp);
1877 }
1878
1879 #get address from ovpn ccd static host
1880 if ($type eq 'OpenVPN static host'){
1881 foreach my $key (keys %ccdhost) {
1882 if($ccdhost{$key}[1] eq $name){
1883 my ($a,$b) = split (/\//,$ccdhost{$key}[33]);
1884 $b=&General::iporsubtodec($b);
1885 return "$a/$b";
1886 }
1887 }
1888 &deletefromgrp($name,$configgrp);
1889 }
1890
1891 #get address from ovpn ccd static net
1892 if ($type eq 'OpenVPN static network'){
1893 foreach my $key (keys %ccdnet) {
1894 if ($ccdnet{$key}[0] eq $name){
1895 my ($a,$b) = split (/\//,$ccdnet{$key}[1]);
1896 $b=&General::iporsubtodec($b);
1897 return "$a/$b";
1898 }
1899 }
1900 }
1901
1902 #check custom addresses
1903 if ($type eq 'Custom Host'){
1904 foreach my $key (keys %customhost) {
1905 if ($customhost{$key}[0] eq $name){
1906 return $customhost{$key}[2];
1907 }
1908 }
1909 }
1910
1911 ##check custom networks
1912 if ($type eq 'Custom Network'){
1913 foreach my $key (keys %customnetwork) {
1914 if($customnetwork{$key}[0] eq $name){
1915 return $customnetwork{$key}[1]."/".$customnetwork{$key}[2];
1916 }
1917 }
1918 }
1919
1920 #check standard networks
1921 if ($type eq 'Standard Network'){
1922 if ($name =~ /OpenVPN/i){
1923 my %ovpn=();
1924 &General::readhash("${General::swroot}/ovpn/settings",\%ovpn);
1925 return $ovpn{'DOVPN_SUBNET'};
1926 }
1927 if ($name eq 'GREEN'){
1928 my %hash=();
1929 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
1930 return $hash{'GREEN_NETADDRESS'}."/".$hash{'GREEN_NETMASK'};
1931 }
1932 if ($name eq 'BLUE'){
1933 my %hash=();
1934 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
1935 return $hash{'BLUE_NETADDRESS'}."/".$hash{'BLUE_NETMASK'};
1936 }
1937 if ($name eq 'ORANGE'){
1938 my %hash=();
1939 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
1940 return $hash{'ORANGE_NETADDRESS'}."/".$hash{'ORANGE_NETMASK'};
1941 }
1942 if ($name eq 'ALL'){
1943 return "0.0.0.0/0.0.0.0";
1944 }
1945 if ($name =~ /IPsec/i){
1946 my %hash=();
1947 &General::readhash("${General::swroot}/vpn/settings",\%hash);
1948 return $hash{'RW_NET'};
1949 }
1950 }
1951}
1952sub rules
cd9d9d8a
AM
1953{
1954 if (!-f "${General::swroot}/fwhosts/reread"){
1955 system("touch ${General::swroot}/fwhosts/reread");
d0815ce4 1956 system("touch ${General::swroot}/forward/reread");
cd9d9d8a
AM
1957 }
1958}
1959sub reread_rules
2a81ab0d
AM
1960{
1961 system ("/usr/local/bin/forwardfwctrl");
cd9d9d8a
AM
1962 if ( -f "${General::swroot}/fwhosts/reread"){
1963 system("rm ${General::swroot}/fwhosts/reread");
d0815ce4 1964 system("rm ${General::swroot}/forward/reread");
cd9d9d8a
AM
1965 }
1966
2a81ab0d
AM
1967}
1968sub decrease
1969{
1970 my $grp=$_[0];
1971 &General::readhasharray("$confignet", \%customnetwork);
1972 &General::readhasharray("$confighost", \%customhost);
1973 foreach my $key (sort keys %customgrp ){
1974 if ( ($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Network')){
1975 foreach my $key1 (sort keys %customnetwork){
1976 if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){
8013bd0a 1977 $customnetwork{$key1}[4]=$customnetwork{$key1}[4]-1;
2a81ab0d
AM
1978 last;
1979 }
1980 }
1981 }
1982
1983 if (($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Host')){
1984 foreach my $key2 (sort keys %customhost){
1985 if ($customhost{$key2}[0] eq $customgrp{$key}[2]){
8013bd0a 1986 $customhost{$key2}[4]=$customhost{$key2}[4]-1;
2a81ab0d
AM
1987 last;
1988 }
1989 }
1990
1991 }
1992 }
1993 &General::writehasharray("$confignet", \%customnetwork);
1994 &General::writehasharray("$confighost", \%customhost);
1995}
1996sub decreaseservice
1997{
1998 my $grp=$_[0];
1999 &General::readhasharray("$configsrv", \%customservice);
2000 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2001
2002 foreach my $key (sort keys %customservicegrp){
2003 if ($customservicegrp{$key}[0] eq $grp ){
2004 foreach my $key2 (sort keys %customservice){
2005 if ($customservice{$key2}[0] eq $customservicegrp{$key}[2]){
2006 $customservice{$key2}[4]--;
2007 }
2008 }
2009 }
2010 }
2011 &General::writehasharray("$configsrv", \%customservice);
2012
2013}
2014sub checkports
2015{
2016
2017 my %hash=%{(shift)};
2018 #check empty fields
2019 if ($fwhostsettings{'SRV_NAME'} eq '' ){
2020 $errormessage=$Lang::tr{'fwhost err name1'};
2021 }
2022 if ($fwhostsettings{'SRV_PORT'} eq '' && $fwhostsettings{'PROT'} ne 'ICMP'){
2023 $errormessage=$Lang::tr{'fwhost err port'};
2024 }
2025 #check valid name
7772ae73 2026 if (! &validhostname($fwhostsettings{'SRV_NAME'})){
2a81ab0d
AM
2027 $errormessage="<br>".$Lang::tr{'fwhost err name'};
2028 }
2029 #change dashes with :
2030 $fwhostsettings{'SRV_PORT'}=~ tr/-/:/;
2031
2032 if ($fwhostsettings{'SRV_PORT'} eq "*") {
2033 $fwhostsettings{'SRV_PORT'} = "1:65535";
2034 }
2035 if ($fwhostsettings{'SRV_PORT'} =~ /^(\D)\:(\d+)$/) {
2036 $fwhostsettings{'SRV_PORT'} = "1:$2";
2037 }
2038 if ($fwhostsettings{'SRV_PORT'} =~ /^(\d+)\:(\D)$/) {
2039 $fwhostsettings{'SRV_PORT'} = "$1:65535";
2040 }
2041 if($fwhostsettings{'PROT'} ne 'ICMP'){
2042 $errormessage = $errormessage.&General::validportrange($fwhostsettings{'SRV_PORT'}, 'src');
2043 }
2044 # a new service has to have a different name
2045 foreach my $key (keys %hash){
2046 if ($hash{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
2047 $errormessage = "<br>".$Lang::tr{'fwhost err srv exists'};
2048 last;
2049 }
2050 }
2051 return $errormessage;
2052}
2053sub validhostname
2054{
2055 # Checks a hostname against RFC1035
2056 my $hostname = $_[0];
2057
2058 # Each part should be at least two characters in length
2059 # but no more than 63 characters
2060 if (length ($hostname) < 1 || length ($hostname) > 63) {
2061 return 0;}
2062 # Only valid characters are a-z, A-Z, 0-9 and -
d0815ce4 2063 if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-_.;()\/\s]*$/) {
2a81ab0d
AM
2064 return 0;}
2065 # First character can only be a letter or a digit
2066 if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
2067 return 0;}
2068 # Last character can only be a letter or a digit
7772ae73 2069 if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9()]*$/) {
2a81ab0d
AM
2070 return 0;}
2071 return 1;
2072}
6c869961
AM
2073sub validremark
2074{
2075 # Checks a hostname against RFC1035
2076 my $remark = $_[0];
2077 # Each part should be at least two characters in length
2078 # but no more than 63 characters
2079 if (length ($remark) < 1 || length ($remark) > 255) {
2080 return 0;}
2081 # Only valid characters are a-z, A-Z, 0-9 and -
d928d795 2082 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
6c869961
AM
2083 return 0;}
2084 # First character can only be a letter or a digit
2085 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
2086 return 0;}
2087 # Last character can only be a letter or a digit
d928d795 2088 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
6c869961
AM
2089 return 0;}
2090 return 1;
2091}
2a81ab0d
AM
2092&Header::closebigbox();
2093&Header::closepage();