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