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