]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - config/forwardfw/convert-outgoingfw
Forward Firewall: fixed a bug in convert-outgoingfw. THe hosts are created with wrong...
[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);
fccf52cf 254 print "altefirewall hat modus: $outsettings{'POLICY'}\n";
12a43202
AM
255 if ($outsettings{'POLICY'} eq 'MODE1'){
256 $fwdfwsettings{'POLICY'}='MODE1';
27f4a6b1
AM
257 $type='ALLOW';
258 $action='ACCEPT';
259 }elsif($outsettings{'POLICY'} eq 'MODE2'){
fccf52cf 260 $fwdsettings{'POLICY'}='MODE2';
27f4a6b1
AM
261 $type='DENY';
262 $action='DROP';
263 }else{
264 return;
265 }
fccf52cf
AM
266 &General::writehash($fwdfwsettings,\%fwdsettings);
267
6128ded8
AM
268 #open LOG
269 if( -f "/var/log/converters/outgoingfw-convert.log"){unlink ("/var/log/converters/outgoingfw-convert.log");}
270 open (LOG, ">/var/log/converters/outgoingfw-convert.log") or die $!;
27f4a6b1
AM
271 open (DATEI, "<$outgoingrules");
272 my @lines = <DATEI>;
273 foreach my $rule (@lines)
274 {
275 chomp($rule);
99e698d0 276 $port='';
27f4a6b1 277 print LOG "processing: $rule\n";
99e698d0
AM
278 my @configline=();
279 @configline = split( /\;/, $rule );
27f4a6b1
AM
280 my @prot=();
281 if($configline[0] eq $type){
282 #some variables we can use from old config
283 if($configline[1] eq 'on'){ $active='ON';}else{$active='';}
5238a871
AM
284 if($configline[3] eq 'all' && $configline[8] ne ''){
285 push(@prot,"TCP");
286 push(@prot,"UDP");
287 }elsif($configline[3] eq 'all' && $configline[8] eq ''){
5a9fd5db 288 push(@prot,"");
27f4a6b1
AM
289 }else{
290 push(@prot,$configline[3]);
27f4a6b1 291 }
5238a871
AM
292 if($configline[4] ne ''){
293 $configline[4] =~ s/,/;/g;
294 $remark = $configline[4];
295 }else{$remark = '';}
8d1beadc 296 if($configline[9] eq 'Active'){ $log='ON';}else{$log='';}
27f4a6b1
AM
297 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'){
298 if($configline[17] eq '00:00' && $configline[18] eq '00:00'){
299 $time='';
300 }else{
301 $time='ON';
302 }
303 }else{
304 $time='ON';
305 }
306 $time_mon=$configline[10];
307 $time_tue=$configline[11];
308 $time_wed=$configline[12];
309 $time_thu=$configline[13];
310 $time_fri=$configline[14];
311 $time_sat=$configline[15];
312 $time_sun=$configline[16];
313 $time_from=$configline[17];
314 $time_to=$configline[18];
315 ############################################################
316 #sourcepart
317 if ($configline[2] eq 'green') {
318 $grp1='std_net_src';
319 $source='GREEN';
320 }elsif ($configline[2] eq 'orange') {
321 $grp1='std_net_src';
322 $source='ORANGE';
323 }elsif ($configline[2] eq 'red') {
6128ded8
AM
324 $grp1='std_net_src';
325 $source='IPFire';
326 &General::readhash($fwdfwsettings,\%fwdsettings);
327 $fwdsettings{'POLICY1'}=$outsettings{'POLICY'};
fccf52cf 328 $fwdsettings{'POLICY'}=$outsettings{'POLICY'};
6128ded8 329 &General::writehash($fwdfwsettings,\%fwdsettings);
27f4a6b1
AM
330 }elsif ($configline[2] eq 'blue') {
331 $grp1='std_net_src';
332 $source='BLUE';
333 }elsif ($configline[2] eq 'ipsec') {
334 print LOG "-> Rule not converted, ipsec+ interface is obsolet since IPFire 2.7 \n";
335 next;
336 }elsif ($configline[2] eq 'ovpn') {
99e698d0
AM
337 &build_ovpn_grp;
338 $grp1='cust_grp_src';
339 $source='ovpn'
27f4a6b1
AM
340 }elsif ($configline[2] eq 'ip') {
341 my $z=&check_ip($configline[5]);
342 if($z){
3b81fad4
AM
343 my ($ipa,$subn) = split("/",$z);
344 $subn=&General::iporsubtocidr($subn);
27f4a6b1 345 $grp1='src_addr';
3b81fad4 346 $source="$ipa/$subn";
27f4a6b1
AM
347 }else{
348 print LOG "-> Rule not converted, missing/invalid source ip \"$configline[5]\"\n";
349 next;
350 }
351 }elsif ($configline[2] eq 'mac') {
352 if(&General::validmac($configline[6])){
353 $grp1='src_addr';
354 $source=$configline[6];
355 }else{
356 print LOG"-> Rule not converted, invalid MAC \"$configline[6]\" \n";
357 next;
358 }
359 }elsif ($configline[2] eq 'all') {
360 $grp1='std_net_src';
361 $source='ALL';
362 }else{
27f4a6b1
AM
363 foreach my $key (sort keys %groups){
364 if($groups{$key}[0] eq $configline[2]){
365 $grp1='cust_grp_src';
366 $source=$configline[2];
367 }
368 }
369 if ($grp1 eq '' || $source eq ''){
370 print LOG "-> Rule not converted, no valid source recognised\n";
371 }
372 }
373 ############################################################
374 #destinationpart
375 if($configline[7] ne ''){
376 my $address=&check_ip($configline[7]);
377 if($address){
3b81fad4
AM
378 my ($dip,$dsub) = split("/",$address);
379 $dsub=&General::iporsubtocidr($dsub);
27f4a6b1 380 $grp2='tgt_addr';
3b81fad4 381 $target="$dip/$dsub";
27f4a6b1
AM
382 }elsif(!$address){
383 my $getwebsiteip=&get_ip_from_domain($configline[7]);
384 if ($getwebsiteip){
385 $grp2='tgt_addr';
386 $target=$getwebsiteip;
5a9fd5db 387 $remark.=" $configline[7]";
27f4a6b1
AM
388 }else{
389 print LOG "-> Rule not converted, invalid domain \"$configline[7]\"\n";
390 next;
391 }
392 }
393 }else{
394 $grp2='std_net_tgt';
395 $target='ALL';
396 }
87946296 397 if($configline[8] ne '' && $configline[3] ne 'gre' && $configline[3] ne 'esp'){
8f0b047b
AM
398 my @values=();
399 my @parts=split(",",$configline[8]);
400 foreach (@parts){
fccf52cf 401 $_=~ tr/-/:/;
8f0b047b
AM
402 if (!($_ =~ /^(\d+)\:(\d+)$/)) {
403 if(&General::validport($_)){
404 $useport='ON';
8f0b047b
AM
405 push (@values,$_);
406 $grp3='TGT_PORT';
407 }else{
408 print LOG "-> Rule not converted, invalid destination Port \"$configline[8]\"\n";
409 next;
410 }
27f4a6b1 411 }else{
8b3dd791
AM
412 my ($a1,$a2) = split(/\:/,$_);
413 if (&General::validport($a1) && &General::validport($a2) && $a1 < $a2){
8f0b047b 414 $useport='ON';
8f0b047b
AM
415 push (@values,"$a1:$a2");
416 $grp3='TGT_PORT';
8b3dd791 417 }else{
8f0b047b
AM
418 print LOG "-> Rule not converted, invalid destination Port \"$configline[8]\"\n";
419 next;
8b3dd791 420 }
8f0b047b 421 }
27f4a6b1 422 }
8b3dd791
AM
423 $port=join("|",@values);
424 @values=();
99e698d0 425 @parts=();
27f4a6b1
AM
426 }
427 }else{
428 print LOG "-> Rule not converted because not for Firewall mode $outsettings{'POLICY'} (we are only converting for actual mode)\n";
429 }
430 &General::readhasharray($fwdfwconfig,\%fwconfig);
6128ded8 431 &General::readhasharray($outfwconfig,\%fwconfigout);
27f4a6b1 432 my $check;
6128ded8 433 my $chain;
27f4a6b1 434 foreach my $protocol (@prot){
6128ded8
AM
435 if ($source eq 'IPFire'){
436 $chain='OUTGOINGFW';
437 }else{
438 $chain='FORWARDFW';
439 }
27f4a6b1 440 $protocol=uc($protocol);
6128ded8 441 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
442 #Put rules into system....
443 ###########################
27f4a6b1
AM
444 #check for double rules
445 foreach my $key (sort keys %fwconfig){
6128ded8 446 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
447 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]"){
448 $check='on';
449 next;
450 }
451 }
452 if($check ne 'on'){
453 #increase groupcounter
454 my $check1;
455 if($grp1 eq 'cust_grp_src'){
456 foreach my $key (sort keys %groups){
457 if($groups{$key}[0] eq $source){
458 $groups{$key}[4]++;
459 $check1='on';
460 }
461 }
462 if($check1 eq 'on'){
27f4a6b1
AM
463 &General::writehasharray($configgroups,\%groups);
464 }
465 }
6128ded8
AM
466 if ($chain eq 'FORWARDFW'){
467 my $key = &General::findhasharraykey(\%fwconfig);
468 $fwconfig{$key}[0] = $action;
469 $fwconfig{$key}[1] = $chain;
470 $fwconfig{$key}[2] = $active;
471 $fwconfig{$key}[3] = $grp1;
472 $fwconfig{$key}[4] = $source;
473 $fwconfig{$key}[5] = $grp2;
474 $fwconfig{$key}[6] = $target;
475 $fwconfig{$key}[11] = $useport;
476 $fwconfig{$key}[12] = $protocol;
477 $fwconfig{$key}[14] = $grp3;
478 $fwconfig{$key}[15] = $port;
479 $fwconfig{$key}[16] = $remark;
480 $fwconfig{$key}[17] = $log;
481 $fwconfig{$key}[18] = $time;
482 $fwconfig{$key}[19] = $time_mon;
483 $fwconfig{$key}[20] = $time_tue;
484 $fwconfig{$key}[21] = $time_wed;
485 $fwconfig{$key}[22] = $time_thu;
486 $fwconfig{$key}[23] = $time_fri;
487 $fwconfig{$key}[24] = $time_sat;
488 $fwconfig{$key}[25] = $time_sun;
489 $fwconfig{$key}[26] = $time_from;
490 $fwconfig{$key}[27] = $time_to;
491 }else{
492 my $key = &General::findhasharraykey(\%fwconfigout);
493 $fwconfigout{$key}[0] = $action;
494 $fwconfigout{$key}[1] = $chain;
495 $fwconfigout{$key}[2] = $active;
496 $fwconfigout{$key}[3] = $grp1;
497 $fwconfigout{$key}[4] = $source;
498 $fwconfigout{$key}[5] = $grp2;
499 $fwconfigout{$key}[6] = $target;
500 $fwconfigout{$key}[11] = $useport;
501 $fwconfigout{$key}[12] = $protocol;
502 $fwconfigout{$key}[14] = $grp3;
503 $fwconfigout{$key}[15] = $port;
504 $fwconfigout{$key}[16] = $remark;
505 $fwconfigout{$key}[17] = $log;
506 $fwconfigout{$key}[18] = $time;
507 $fwconfigout{$key}[19] = $time_mon;
508 $fwconfigout{$key}[20] = $time_tue;
509 $fwconfigout{$key}[21] = $time_wed;
510 $fwconfigout{$key}[22] = $time_thu;
511 $fwconfigout{$key}[23] = $time_fri;
512 $fwconfigout{$key}[24] = $time_sat;
513 $fwconfigout{$key}[25] = $time_sun;
514 $fwconfigout{$key}[26] = $time_from;
515 $fwconfigout{$key}[27] = $time_to;
516 }
517 &General::writehasharray($fwdfwconfig,\%fwconfig);
518 &General::writehasharray($outfwconfig,\%fwconfigout);
27f4a6b1
AM
519 }
520 }
27f4a6b1
AM
521 @prot=();
522 }
523 close(LOG);
524 @lines=();
525}
526sub get_ip_from_domain
527{
528 $web=shift;
529 my $resolvedip;
530 my $checked;
531 my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($web);
532 if(@addrs){
533 $resolvedip=inet_ntoa($addrs[0]);
534 return $resolvedip;
535 }
536 return;
537}
538sub build_ovpn_grp
539{
540 &General::readhasharray($confighosts,\%hosts);
541 &General::readhasharray($confignets,\%nets);
542 &General::readhasharray($configgroups,\%groups);
543 &General::readhasharray($ovpnconfig,\%configovpn);
544 &General::readhasharray($ccdconfig,\%ccdconf);
545 &General::readhash($ovpnsettings,\%settingsovpn);
546 #get ovpn nets
547 my @ovpnnets=();
548 if($settingsovpn{'DOVPN_SUBNET'}){
549 my ($net,$subnet)=split("/",$settingsovpn{'DOVPN_SUBNET'});
550 push (@ovpnnets,"$net,$subnet,dynamic");
551 }
552 foreach my $key (sort keys %ccdconf){
553 my ($net,$subnet)=split("/",$ccdconf{$key}[1]);
554 $subnet=&General::iporsubtodec($subnet);
555 push (@ovpnnets,"$net,$subnet,$ccdconf{$key}[0]");
556 }
557 foreach my $key (sort keys %configovpn){
558 if ($configovpn{$key}[3] eq 'net'){
559 my ($net,$subnet)=split("/",$configovpn{$key}[27]);
560 push (@ovpnnets,"$net,$subnet,$configovpn{$key}[2]");
561 }
562 }
563 #add ovpn nets to customnetworks/groups
564 foreach my $line (@ovpnnets){
565 my ($net,$subnet,$name) = split(",",$line);
566 if (!&check_net($net,$subnet)){
567 my $netkey = &General::findhasharraykey(\%nets);
568 $name2=$name."(ovpn)".$net;
569 $name3="Custom Network";
570 $nets{$netkey}[0] = $name2;
571 $nets{$netkey}[1] = $net;
572 $nets{$netkey}[2] = $subnet;
573 $nets{$netkey}[3] = 1;
574 }else{
575 print LOG "-> Custom Network with same IP already exist \"$net/$subnet\" (you can ignore this, if this run was manual from shell)\n";
576 }
577 if($name2){
578 my $grpkey = &General::findhasharraykey(\%groups);
579 $groups{$grpkey}[0] = "ovpn";
580 $groups{$grpkey}[1] = '';
581 $groups{$grpkey}[2] = $name2;
582 $groups{$grpkey}[3] = "Custom Network";
583 $groups{$grpkey}[4] = 0;
584 }
585 $name2='';
586 }
587 @ovpnnets=();
588 &General::writehasharray($confighosts,\%hosts);
589 &General::writehasharray($configgroups,\%groups);
590 &General::writehasharray($confignets,\%nets);
591}
5a9fd5db
AM
592sub process_p2p
593{
594 copy("/var/ipfire/outgoing/p2protocols","/var/ipfire/forward/p2protocols");
70d38e50 595 chmod oct('0777'), '/var/ipfire/forward/p2protocols';
5a9fd5db 596}