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