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