]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/firewall/convert-outgoingfw
convert-outgoingfw: Fix permissions of p2protocols configuration file.
[people/teissler/ipfire-2.x.git] / config / firewall / convert-outgoingfw
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 Alexander Marx <amarx@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 # #
22 # This script converts old groups and firewallrules #
23 # to the new one. This is a 3-step process. #
24 # STEP1: convert groups ->LOG /var/log/converters #
25 # STEP2: convert rules ->LOG /var/log/converters #
26 # STEP3: convert P2P rules #
27 # #
28 ###############################################################################
29
30 require '/var/ipfire/general-functions.pl';
31 require "${General::swroot}/lang.pl";
32
33 use Socket;
34 use File::Path;
35 use File::Copy;
36
37 my $ipgrouppath = "${General::swroot}/outgoing/groups/ipgroups/";
38 my $macgrouppath = "${General::swroot}/outgoing/groups/macgroups/";
39 my $outgoingrules = "${General::swroot}/outgoing/rules";
40 my $outfwsettings = "${General::swroot}/outgoing/settings";
41 my $host = "Converted ";
42 my $confighosts = "${General::swroot}/fwhosts/customhosts";
43 my $confignets = "${General::swroot}/fwhosts/customnetworks";
44 my $configgroups = "${General::swroot}/fwhosts/customgroups";
45 my $ovpnsettings = "${General::swroot}/ovpn/settings";
46 my $ovpnconfig = "${General::swroot}/ovpn/ovpnconfig";
47 my $ccdconfig = "${General::swroot}/ovpn/ccd.conf";
48 my $fwdfwconfig = "${General::swroot}/firewall/config";
49 my $outfwconfig = "${General::swroot}/firewall/outgoing";
50 my $fwdfwsettings = "${General::swroot}/firewall/settings";
51 my @ipgroups = qx(ls $ipgrouppath);
52 my @macgroups = qx(ls $macgrouppath);
53 my @hostarray=();
54 my %outsettings=();
55 my %hosts=();
56 my %nets=();
57 my %groups=();
58 my %settingsovpn=();
59 my %configovpn=();
60 my %ccdconf=();
61 my %fwconfig=();
62 my %fwconfigout=();
63 my %fwdsettings=();
64 my %ownnet=();
65 my %ovpnSettings = ();
66 my @active= ('Aktiv', 'aktiv', 'Active', 'Activo', 'Actif', 'Actief', 'Aktywne', 'Активен', 'Aktif');
67 &General::readhash("${General::swroot}/ovpn/settings", \%ovpnSettings);
68 &General::readhash($outfwsettings,\%outsettings);
69 &General::readhash("${General::swroot}/ethernet/settings", \%ownnet);
70
71 #ONLY RUN if /var/ipfire/outgoing exists
72 if ( -d "/var/ipfire/outgoing"){
73 &process_groups;
74 &process_rules;
75 &process_p2p;
76 }
77 system("/usr/local/bin/firewallctrl");
78 sub process_groups
79 {
80 if(! -d "/var/log/converters"){ mkdir("/var/log/converters");}
81 if( -f "/var/log/converters/groups-convert.log"){rmtree("var/log/converters");}
82 open (LOG, ">/var/log/converters/groups-convert.log") or die $!;
83 #IP Group processing
84 foreach my $group (@ipgroups){
85 my $now=localtime;
86 chomp $group;
87 print LOG "\n$now Processing IP-GROUP: $group...\n";
88 open (DATEI, "<$ipgrouppath/$group");
89 my @zeilen = <DATEI>;
90 foreach my $ip (@zeilen){
91 chomp($ip);
92 $ip =~ s/\s//gi;
93 print LOG "$now Check IP $ip from Group $group ";
94 my $val=&check_ip($ip);
95 if($val){
96 push(@hostarray,$val.",ip");
97 print LOG "$now -> OK\n";
98 }
99 else{
100 print LOG "$now -> IP \"$ip\" from group $group not converted (invalid IP) \n";
101 }
102 $val='';
103 }
104 &new_hostgrp($group,'ip');
105 @hostarray=();
106 }
107 $group='';
108 @zeilen=();
109 @hostarray=();
110 #MAC Group processing
111 foreach my $group (@macgroups){
112 chomp $group;
113 print LOG "\nProcessing MAC-GROUP: $group...\n";
114 open (DATEI, "<$macgrouppath/$group");
115 my @zeilen = <DATEI>;
116 foreach my $mac (@zeilen){
117 chomp($mac);
118 $mac =~ s/\s//gi;
119 print LOG "$now Checking MAC $mac from group $group ";
120 #MAC checking
121 if(&General::validmac($mac)){
122 $val=$mac;
123 }
124 if($val){
125 push(@hostarray,$val.",mac");
126 print LOG "$now -> OK\n";
127 }
128 else{
129 print LOG "$now -> Mac $mac from group $group not converted (invalid MAC)\n";
130 }
131 $val='';
132 }
133 &new_hostgrp($group,'mac');
134 @hostarray=();
135 @zeilen=();
136 }
137 close (LOG);
138 }
139 sub check_ip
140 {
141 my $adr=shift;
142 my $a;
143 #ip with subnet in decimal
144 if($adr =~ m/^(\d\d?\d?).(\d\d?\d?).(\d\d?\d?).(\d\d?\d?)\/(\d{1,2})$/){
145 $adr=int($1).".".int($2).".".int($3).".".int($4);
146 my $b = &General::iporsubtodec($5);
147 $a=$adr."/".$b;
148 }elsif($adr =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
149 $adr=int($1).".".int($2).".".int($3).".".int($4);
150 if(&General::validip($adr)){
151 $a=$adr."/255.255.255.255";
152 }
153 }
154 if(&General::validipandmask($adr)){
155 $a=&General::iporsubtodec($adr);
156 }
157 return $a;
158 }
159 sub new_hostgrp
160 {
161 &General::readhasharray($confighosts,\%hosts);
162 &General::readhasharray($confignets,\%nets);
163 &General::readhasharray($configgroups,\%groups);
164 my $grp=shift;
165 my $run=shift;
166 my $name; #"converted"
167 my $name2;
168 my $name3; #custom host/custom net
169 my $mac2;
170 foreach my $adr (@hostarray){
171 if($run eq 'ip'){
172 my ($ip,$type) = split(",",$adr);
173 my ($ippart,$subnet) = split("/",$ip);
174 my ($byte1,$byte2,$byte3,$byte4) = split(/\./,$subnet);
175 if($byte4 eq '255'){
176 print LOG "Processing SINGLE HOST $ippart/$subnet from group $grp\n";
177 if(!&check_host($ip)){
178 my $key = &General::findhasharraykey(\%hosts);
179 $name="host ";
180 $name2=$name.$ippart;
181 $name3="Custom Host";
182 $hosts{$key}[0] = $name2;
183 $hosts{$key}[1] = $type;
184 $hosts{$key}[2] = $ip;
185 $hosts{$key}[3] = '';
186 print LOG "->Host (IP) $ip added to custom hosts\n"
187 }else{
188 print LOG "->Host (IP) $ip already exists in custom hosts\n";
189 $name="host ";
190 $name2=$name.$ippart;
191 $name="host ";
192 $name2=$name.$ippart;
193 $name3="Custom Host";
194 }
195 }elsif($byte4 < '255'){
196 print LOG "Processing NETWORK $ippart/$subnet from Group $grp\n";
197 if(!&check_net($ippart,$subnet)){
198 #Check if this network is one one of IPFire internal networks
199 if (($ownnet{'GREEN_NETADDRESS'} ne '' && $ownnet{'GREEN_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($ippart,$ownnet{'GREEN_NETADDRESS'},$ownnet{'GREEN_NETMASK'}))
200 {
201 $name2='GREEN';
202 $name3='Standard Network';
203 }elsif (($ownnet{'ORANGE_NETADDRESS'} ne '' && $ownnet{'ORANGE_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($ippart,$ownnet{'ORANGE_NETADDRESS'},$ownnet{'ORANGE_NETMASK'}))
204 {
205 $name2='ORANGE';
206 $name3='Standard Network';
207 }elsif (($ownnet{'BLUE_NETADDRESS'} ne '' && $ownnet{'BLUE_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($ippart,$ownnet{'BLUE_NETADDRESS'},$ownnet{'BLUE_NETMASK'}))
208 {
209 $name2='BLUE';
210 $name3='Standard Network';
211 }elsif ($ippart eq '0.0.0.0')
212 {
213 $name2='ALL';
214 $name3='Standard Network';
215 }elsif(defined($ovpnSettings{'DOVPN_SUBNET'}) && "$ippart/".&General::iporsubtodec($subnet) eq $ovpnSettings{'DOVPN_SUBNET'})
216 {
217 $name2='OpenVPN-Dyn';
218 $name3='Standard Network';
219 }else{
220 my $netkey = &General::findhasharraykey(\%nets);
221 $name="net ";
222 $name2=$name.$ippart;
223 $name3="Custom Network";
224 $nets{$netkey}[0] = $name2;
225 $nets{$netkey}[1] = $ippart;
226 $nets{$netkey}[2] = $subnet;
227 $nets{$netkey}[3] = '';
228 print LOG "->Network $ippart/$subnet added to custom networks\n";
229 }
230 }else{
231 print LOG "Network $ippart already exists in custom networks\n";
232 $name="net ";
233 $name2=$name.$ippart;
234 $name="net ";
235 $name2=$name.$ippart;
236 $name3="Custom Network";
237 }
238 }
239 if($name2 && !&check_grp($grp,$name2)){
240 my $grpkey = &General::findhasharraykey(\%groups);
241 $groups{$grpkey}[0] = $grp;
242 $groups{$grpkey}[1] = '';
243 $groups{$grpkey}[2] = $name2;
244 $groups{$grpkey}[3] = $name3;
245 print LOG "->$name2 added to group $grp\n";
246 }
247 }elsif($run eq 'mac'){
248 #MACRUN
249 my ($mac,$type) = split(",",$adr);
250 print LOG "Processing HOST (MAC) $mac\n";
251 if(!&check_host($mac)){
252 my $key = &General::findhasharraykey(\%hosts);
253 $name="host ";
254 $mac2=$mac;
255 $mac2 =~ s/:/-/g;
256 $name2=$name.$mac2;
257 $name3="Custom Host";
258 $hosts{$key}[0] = $name2;
259 $hosts{$key}[1] = $type;
260 $hosts{$key}[2] = $mac;
261 print LOG "->Host (MAC) $mac added to custom hosts\n";
262 }else{
263 $mac2=mac;
264 $mac2 =~ s/:/-/g;
265 print LOG "->Host (MAC) $mac already exists in custom hosts \n";
266 $name="host ";
267 $name2=$name.$mac2;
268 $name3="Custom Host";
269 }
270 if($name2 && !&check_grp($grp,$name2)){
271 my $grpkey = &General::findhasharraykey(\%groups);
272 $groups{$grpkey}[0] = $grp;
273 $groups{$grpkey}[1] = '';
274 $groups{$grpkey}[2] = $name2;
275 $groups{$grpkey}[3] = $name3;
276 print LOG "->$name2 added to group $grp\n";
277 }
278 }
279 }
280 @hostarray=();
281 &General::writehasharray($confighosts,\%hosts);
282 &General::writehasharray($configgroups,\%groups);
283 &General::writehasharray($confignets,\%nets);
284
285 }
286 sub check_host
287 {
288 my $ip=shift;
289 foreach my $key (sort keys %hosts)
290 {
291 if($hosts{$key}[2] eq $ip)
292 {
293 return 1;
294 }
295 }
296 return 0;
297 }
298 sub check_net
299 {
300 my $ip=shift;
301 my $sub=shift;
302 foreach my $key (sort keys %nets)
303 {
304 if($nets{$key}[1] eq $ip && $nets{$key}[2] eq $sub)
305 {
306 return 1;
307 }
308 }
309 return 0;
310 }
311 sub check_grp
312 {
313 my $grp=shift;
314 my $value=shift;
315 foreach my $key (sort keys %groups)
316 {
317 if($groups{$key}[0] eq $grp && $groups{$key}[2] eq $value)
318 {
319 return 1;
320 }
321 }
322 return 0;
323 }
324 sub process_rules
325 {
326 my ($type,$action,$active,$grp1,$source,$grp2,$useport,$port,$prot,$grp3,$target,$remark,$log,$time,$time_mon,$time_tue,$time_wed,$time_thu,$time_fri,$time_sat,$time_sun,$time_from,$time_to);
327 #open LOG
328 if( -f "/var/log/converters/outgoingfw-convert.log"){unlink ("/var/log/converters/outgoingfw-convert.log");}
329 open (LOG, ">/var/log/converters/outgoingfw-convert.log") or die $!;
330
331 &General::readhash($fwdfwsettings,\%fwdsettings);
332 if ($outsettings{'POLICY'} eq 'MODE1'){
333 $fwdsettings{'POLICY'}='MODE1';
334 $fwdsettings{'POLICY1'}='MODE2';
335 $type='ALLOW';
336 $action='ACCEPT';
337 }else{
338 $fwdsettings{'POLICY'}='MODE2';
339 $fwdsettings{'POLICY1'}='MODE2';
340 $type='DENY';
341 $action='DROP';
342 }
343 &General::writehash($fwdfwsettings,\%fwdsettings);
344 open (DATEI, "<$outgoingrules");
345 my @lines = <DATEI>;
346 foreach my $rule (@lines)
347 {
348 &General::readhasharray($fwdfwconfig,\%fwconfig);
349 &General::readhasharray($outfwconfig,\%fwconfigout);
350 my $now=localtime;
351 chomp($rule);
352 $port='';
353 print LOG "$now processing: $rule\n";
354 my @configline=();
355 @configline = split( /\;/, $rule );
356 my @prot=();
357 if($configline[0] eq $type){
358 #some variables we can use from old config
359 if($configline[1] eq 'on'){ $active='ON';}else{$active='';}
360 if($configline[3] eq 'all' && $configline[8] ne ''){
361 push(@prot,"TCP");
362 push(@prot,"UDP");
363 }elsif($configline[3] eq 'all' && $configline[8] eq ''){
364 push(@prot,"");
365 }else{
366 push(@prot,$configline[3]);
367 }
368 if($configline[4] ne ''){
369 $configline[4] =~ s/,/;/g;
370 $remark = $configline[4];
371 }else{$remark = '';}
372 #find all "active" tags in all language files and check them against the old config
373 my $logging='0';
374 foreach (@active){
375 $logging='1' if ($_ eq $configline[9]);
376 }
377 if($logging eq '1' ){ $log='ON';}else{$log='';}
378 if($configline[10] eq 'on' && $configline[11] eq 'on' && $configline[12] eq 'on' && $configline[13] eq 'on' && $configline[14] eq 'on' && $configline[15] eq 'on' && $configline[16] eq 'on'){
379 if($configline[17] eq '00:00' && $configline[18] eq '00:00'){
380 $time='';
381 }else{
382 $time='ON';
383 }
384 }else{
385 $time='ON';
386 }
387 $time_mon=$configline[10];
388 $time_tue=$configline[11];
389 $time_wed=$configline[12];
390 $time_thu=$configline[13];
391 $time_fri=$configline[14];
392 $time_sat=$configline[15];
393 $time_sun=$configline[16];
394 $time_from=$configline[17];
395 $time_to=$configline[18];
396 ############################################################
397 #sourcepart
398 if ($configline[2] eq 'green') {
399 $grp1='std_net_src';
400 $source='GREEN';
401 }elsif ($configline[2] eq 'orange') {
402 $grp1='std_net_src';
403 $source='ORANGE';
404 }elsif ($configline[2] eq 'red') {
405 $grp1='std_net_src';
406 $source='IPFire';
407 &General::readhash($fwdfwsettings,\%fwdsettings);
408 $fwdsettings{'POLICY1'}=$outsettings{'POLICY'};
409 $fwdsettings{'POLICY'}=$outsettings{'POLICY'};
410 &General::writehash($fwdfwsettings,\%fwdsettings);
411 }elsif ($configline[2] eq 'blue') {
412 $grp1='std_net_src';
413 $source='BLUE';
414 }elsif ($configline[2] eq 'ipsec') {
415 print LOG "$now -> Rule not converted, ipsec+ interface is obsolet since IPFire 2.7 \n";
416 next;
417 }elsif ($configline[2] eq 'ovpn') {
418 print LOG "$now ->Creating networks/groups for OpenVPN...\n";
419 &build_ovpn_grp;
420 $grp1='cust_grp_src';
421 $source='ovpn'
422 }elsif ($configline[2] eq 'ip') {
423 my $z=&check_ip($configline[5]);
424 if($z){
425 my ($ipa,$subn) = split("/",$z);
426 $subn=&General::iporsubtocidr($subn);
427 $grp1='src_addr';
428 $source="$ipa/$subn";
429 }else{
430 print LOG "$now -> Rule not converted, missing/invalid source ip \"$configline[5]\"\n";
431 next;
432 }
433 }elsif ($configline[2] eq 'mac') {
434 if(&General::validmac($configline[6])){
435 $grp1='src_addr';
436 $source=$configline[6];
437 }else{
438 print LOG"$now -> Rule not converted, invalid MAC \"$configline[6]\" \n";
439 next;
440 }
441 }elsif ($configline[2] eq 'all') {
442 $grp1='std_net_src';
443 $source='ALL';
444 }else{
445 foreach my $key (sort keys %groups){
446 if($groups{$key}[0] eq $configline[2]){
447 $grp1='cust_grp_src';
448 $source=$configline[2];
449 }
450 }
451 if ($grp1 eq '' || $source eq ''){
452 print LOG "$now -> Rule not converted, no valid source recognised\n";
453 }
454 }
455 ############################################################
456 #destinationpart
457 if($configline[7] ne '' && $configline[7] ne '0.0.0.0'){
458 my $address=&check_ip($configline[7]);
459 if($address){
460 my ($dip,$dsub) = split("/",$address);
461 $dsub=&General::iporsubtocidr($dsub);
462 $grp2='tgt_addr';
463 $target="$dip/$dsub";
464 }elsif(!$address){
465 my $getwebsiteip=&get_ip_from_domain($configline[7]);
466 if ($getwebsiteip){
467 $grp2='tgt_addr';
468 $target=$getwebsiteip;
469 $remark.=" $configline[7]";
470 }else{
471 print LOG "$now -> Rule not converted, invalid domain \"$configline[7]\"\n";
472 next;
473 }
474 }
475 }else{
476 $grp2='std_net_tgt';
477 $target='ALL';
478 }
479 if($configline[8] ne '' && $configline[3] ne 'gre' && $configline[3] ne 'esp'){
480 my @values=();
481 my @parts=split(",",$configline[8]);
482 foreach (@parts){
483 $_=~ tr/-/:/;
484 if (!($_ =~ /^(\d+)\:(\d+)$/)) {
485 if(&General::validport($_)){
486 $useport='ON';
487 push (@values,$_);
488 $grp3='TGT_PORT';
489 }else{
490 print LOG "$now -> Rule not converted, invalid destination Port \"$configline[8]\"\n";
491 next;
492 }
493 }else{
494 my ($a1,$a2) = split(/\:/,$_);
495 if (&General::validport($a1) && &General::validport($a2) && $a1 < $a2){
496 $useport='ON';
497 push (@values,"$a1:$a2");
498 $grp3='TGT_PORT';
499 }else{
500 print LOG "$now -> Rule not converted, invalid destination Port \"$configline[8]\"\n";
501 next;
502 }
503 }
504 }
505 $port=join("|",@values);
506 @values=();
507 @parts=();
508 }
509 }else{
510 print LOG "-> Rule not converted because not for Firewall mode $outsettings{'POLICY'} (we are only converting for actual mode)\n";
511 }
512 my $check;
513 my $chain;
514 foreach my $protocol (@prot){
515 my $now=localtime;
516 if ($source eq 'IPFire'){
517 $chain='OUTGOINGFW';
518 }else{
519 $chain='FORWARDFW';
520 }
521 $protocol=uc($protocol);
522 print LOG "$now -> Converted: $action,$chain,$active,$grp1,$source,$grp2,$target,,$protocol,,,$useport,,,$grp3,$port,$remark,$log,$time,$time_mon,$time_tue,$time_wed,$time_thu,$time_fri,$time_sat,$time_sun,$time_from,$time_to\n";
523 #Put rules into system....
524 ###########################
525 #check for double rules
526 foreach my $key (sort keys %fwconfig){
527 if("$action,$chain,$active,$grp1,$source,$grp2,$target,$protocol,$useport,$grp3,$port,$remark,$log,$time,$time_mon,$time_tue,$time_wed,$time_thu,$time_fri,$time_sat,$time_sun,$time_from,$time_to"
528 eq "$fwconfig{$key}[0],$fwconfig{$key}[1],$fwconfig{$key}[2],$fwconfig{$key}[3],$fwconfig{$key}[4],$fwconfig{$key}[5],$fwconfig{$key}[6],$fwconfig{$key}[8],$fwconfig{$key}[11],$fwconfig{$key}[14],$fwconfig{$key}[15],$fwconfig{$key}[16],$fwconfig{$key}[17],$fwconfig{$key}[18],$fwconfig{$key}[19],$fwconfig{$key}[20],$fwconfig{$key}[21],$fwconfig{$key}[22],$fwconfig{$key}[23],$fwconfig{$key}[24],$fwconfig{$key}[25],$fwconfig{$key}[26],$fwconfig{$key}[27]"){
529 $check='on';
530 next;
531 }
532 }
533 if($check ne 'on'){
534 if ($chain eq 'FORWARDFW'){
535 my $key = &General::findhasharraykey(\%fwconfig);
536 $fwconfig{$key}[0] = $action;
537 $fwconfig{$key}[1] = $chain;
538 $fwconfig{$key}[2] = $active;
539 $fwconfig{$key}[3] = $grp1;
540 $fwconfig{$key}[4] = $source;
541 $fwconfig{$key}[5] = $grp2;
542 $fwconfig{$key}[6] = $target;
543 $fwconfig{$key}[8] = $protocol;
544 $fwconfig{$key}[11] = $useport;
545 $fwconfig{$key}[14] = $grp3;
546 $fwconfig{$key}[15] = $port;
547 $fwconfig{$key}[16] = $remark;
548 $fwconfig{$key}[17] = $log;
549 $fwconfig{$key}[18] = $time;
550 $fwconfig{$key}[19] = $time_mon;
551 $fwconfig{$key}[20] = $time_tue;
552 $fwconfig{$key}[21] = $time_wed;
553 $fwconfig{$key}[22] = $time_thu;
554 $fwconfig{$key}[23] = $time_fri;
555 $fwconfig{$key}[24] = $time_sat;
556 $fwconfig{$key}[25] = $time_sun;
557 $fwconfig{$key}[26] = $time_from;
558 $fwconfig{$key}[27] = $time_to;
559 $fwconfig{$key}[28] = '';
560 $fwconfig{$key}[29] = 'ALL';
561 $fwconfig{$key}[30] = '';
562 $fwconfig{$key}[31] = 'dnat';
563 &General::writehasharray($fwdfwconfig,\%fwconfig);
564 }else{
565 my $key = &General::findhasharraykey(\%fwconfigout);
566 $fwconfigout{$key}[0] = $action;
567 $fwconfigout{$key}[1] = $chain;
568 $fwconfigout{$key}[2] = $active;
569 $fwconfigout{$key}[3] = $grp1;
570 $fwconfigout{$key}[4] = $source;
571 $fwconfigout{$key}[5] = $grp2;
572 $fwconfigout{$key}[6] = $target;
573 $fwconfigout{$key}[8] = $protocol;
574 $fwconfigout{$key}[11] = $useport;
575 $fwconfigout{$key}[14] = $grp3;
576 $fwconfigout{$key}[15] = $port;
577 $fwconfigout{$key}[16] = $remark;
578 $fwconfigout{$key}[17] = $log;
579 $fwconfigout{$key}[18] = $time;
580 $fwconfigout{$key}[19] = $time_mon;
581 $fwconfigout{$key}[20] = $time_tue;
582 $fwconfigout{$key}[21] = $time_wed;
583 $fwconfigout{$key}[22] = $time_thu;
584 $fwconfigout{$key}[23] = $time_fri;
585 $fwconfigout{$key}[24] = $time_sat;
586 $fwconfigout{$key}[25] = $time_sun;
587 $fwconfigout{$key}[26] = $time_from;
588 $fwconfigout{$key}[27] = $time_to;
589 $fwconfigout{$key}[28] = '';
590 $fwconfigout{$key}[29] = 'ALL';
591 $fwconfigout{$key}[30] = '';
592 $fwconfigout{$key}[31] = 'dnat';
593 &General::writehasharray($outfwconfig,\%fwconfigout);
594 }
595 }
596 }
597 @prot=();
598 }
599 close(LOG);
600 @lines=();
601 }
602 sub get_ip_from_domain
603 {
604 $web=shift;
605 my $resolvedip;
606 my $checked;
607 my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($web);
608 if(@addrs){
609 $resolvedip=inet_ntoa($addrs[0]);
610 return $resolvedip;
611 }
612 return;
613 }
614 sub build_ovpn_grp
615 {
616 my $now=localtime;
617 &General::readhasharray($confighosts,\%hosts);
618 &General::readhasharray($confignets,\%nets);
619 &General::readhasharray($configgroups,\%groups);
620 &General::readhasharray($ovpnconfig,\%configovpn);
621 &General::readhasharray($ccdconfig,\%ccdconf);
622 &General::readhash($ovpnsettings,\%settingsovpn);
623 #get ovpn nets
624 my @ovpnnets=();
625 if($settingsovpn{'DOVPN_SUBNET'}){
626 my ($net,$subnet)=split("/",$settingsovpn{'DOVPN_SUBNET'});
627 push (@ovpnnets,"$net,$subnet,dynamic");
628 print LOG "$now ->found dynamic OpenVPN net\n";
629 }
630 foreach my $key (sort keys %ccdconf){
631 my ($net,$subnet)=split("/",$ccdconf{$key}[1]);
632 $subnet=&General::iporsubtodec($subnet);
633 push (@ovpnnets,"$net,$subnet,$ccdconf{$key}[0]");
634 print LOG "$now ->found OpenVPN static net $net/$subnet\n";
635 }
636 foreach my $key (sort keys %configovpn){
637 if ($configovpn{$key}[3] eq 'net'){
638 my ($net,$subnet)=split("/",$configovpn{$key}[27]);
639 push (@ovpnnets,"$net,$subnet,$configovpn{$key}[2]");
640 print LOG "$now ->found OpenVPN $net/$subnet $configovpn{$key}[2]\n";
641 }
642 }
643 #add ovpn nets to customnetworks/groups
644 foreach my $line (@ovpnnets){
645 my $now=localtime;
646 my ($net,$subnet,$name) = split(",",$line);
647 if (!&check_net($net,$subnet)){
648 my $netkey = &General::findhasharraykey(\%nets);
649 $name2=$name."(ovpn)".$net;
650 $name3="Custom Network";
651 $nets{$netkey}[0] = $name2;
652 $nets{$netkey}[1] = $net;
653 $nets{$netkey}[2] = $subnet;
654 $nets{$netkey}[3] = '';
655 print LOG "$now ->added $name2 $net/$subnet to customnetworks\n";
656 }else{
657 print LOG "-> Custom Network with same IP already exist \"$net/$subnet\" (you can ignore this, if this run was manual from shell)\n";
658 }
659 if($name2){
660 my $grpkey = &General::findhasharraykey(\%groups);
661 $groups{$grpkey}[0] = "ovpn";
662 $groups{$grpkey}[1] = '';
663 $groups{$grpkey}[2] = $name2;
664 $groups{$grpkey}[3] = "Custom Network";
665 print LOG "$now ->added $name2 to customgroup ovpn\n";
666 }
667 $name2='';
668 }
669 @ovpnnets=();
670 &General::writehasharray($confighosts,\%hosts);
671 &General::writehasharray($configgroups,\%groups);
672 &General::writehasharray($confignets,\%nets);
673 print LOG "$now ->finished OVPN\n";
674 }
675 sub process_p2p
676 {
677 copy("/var/ipfire/outgoing/p2protocols","/var/ipfire/firewall/p2protocols");
678 chown 99, 99, '/var/ipfire/firewall/p2protocols';
679 }