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