]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/init.d/red
FritzCard-Module installiert.
[people/pmueller/ipfire-2.x.git] / src / initscripts / init.d / red
1 #!/usr/bin/perl
2 #
3 # This file is part of the IPCop Firewall.
4 #
5 # IPCop is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # IPCop is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with IPCop; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #
19 # (c) The SmoothWall Team
20 #
21
22 # Clean up our environment (we're running SUID!)
23 delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)};
24 $< = $>;
25
26 use strict;
27 require '/var/ipfire/general-functions.pl';
28
29 my %pppsettings;
30 my %isdnsettings;
31 my %netsettings;
32 my %dhcpsettings;
33 my $iface;
34
35 # read vars back from file.
36 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
37 &General::readhash("${General::swroot}/isdn/settings", \%isdnsettings);
38 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
39 &General::readhash("${General::swroot}/dhcp/settings", \%dhcpsettings);
40
41 sub dodhcpdial($;$) {
42 my ($iface,$dhcp_name)=@_;
43
44 system ('/sbin/iptables', '-A', 'REDINPUT', '-p', 'tcp', '--source-port', '67',
45 '--destination-port', '68', '-i', $iface, '-j', 'ACCEPT');
46 system ('/sbin/iptables', '-A', 'REDINPUT', '-p', 'udp', '--source-port', '67',
47 '--destination-port', '68', '-i', $iface, '-j', 'ACCEPT');
48
49 foreach ("<${General::swroot}/dhcpc/*.info>") { unlink $1 if ( $_ =~ /^([\/\w.-]+)$/ ); }
50 my @dhcpcommand = ('/sbin/dhcpcd');
51 push(@dhcpcommand, ('-N', '-R', "$iface",'-L', "${General::swroot}/dhcpc"));
52
53 #FIXME the only way actually to set debug use is in pppsetup.cgi and 'RED is modem/isdn' interface
54 if ($pppsettings{'DEBUG'} eq 'on') {
55 push(@dhcpcommand, ('-d'));
56 }
57
58 if ($dhcp_name ne '') { push(@dhcpcommand, ('-h', "$dhcp_name")); }
59 if ($netsettings{'RED_TYPE'} eq 'PPTP') { push(@dhcpcommand, '-G'); }
60
61 if (system (@dhcpcommand)) {
62 &General::log('dhcpcd fail');
63 exit 1;
64 } else {
65 &General::log('dhcpcd success');
66 }
67 }
68
69 sub doupdatesettings {
70 # complete cleanup only if settings were changed or clear is ordered
71 system('/sbin/modprobe', '-r', 'pppoatm');
72 system('/sbin/modprobe', '-r', 'pppoe');
73 system('/bin/killall /usr/bin/br2684ctl 2>/dev/null');
74 system('/sbin/modprobe', '-r', 'br2684');
75 system('/sbin/modprobe', '-r', 'clip');
76
77 if ($pppsettings{'TYPE'} ne 'fritzdsl') {
78 system('/sbin/modprobe', '-r', 'fcdsl', 'fcdsl2', 'fcdslsl', 'fcdslusb', 'fcdslslusb');}
79 sleep 1;
80
81 # remove existing default route (for static address) if it was been changed from setup or web interface SF1175052
82 system ('/sbin/route del default 2>/dev/null');
83
84 # erase in case it was created once with 'persistent' selected but rc.red stop never used : SF1171610
85 unlink ("${General::swroot}/red/iface");
86 }
87 }
88
89 # No output should be sent to the webclient
90 open STDIN, '</dev/zero' or die "Can't read from /dev/zero";
91 open STDOUT, '>/dev/null' or die "Can't write to /dev/null";
92
93 if ($ARGV[0] eq 'start') {
94 if (-e "${General::swroot}/red/active" ||
95 -e '/var/run/ppp-ipfire.pid')
96 {
97 &General::log ("ERROR: Can't start RED when it's still active");
98 exit 1;
99 }
100
101 if ( ( ( ($netsettings{'RED_TYPE'} =~ /^(PPPOE|PPTP)$/) && ($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) ) ||
102 ( ( ($pppsettings{'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) || ($pppsettings{'PROTOCOL'} eq 'RFC2364') ) &&
103 ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/) ) ) && ($pppsettings{'RECONNECTION'} ne 'manual') ) {
104 system ('/etc/rc.d/rc.connectioncheck start &');
105 }
106
107 ###
108 ### Red device is ethernet
109 ###
110 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/)
111 {
112 if ($netsettings{'RED_DEV'} ne '')
113 {
114 &General::log("Starting RED device $netsettings{'RED_DEV'}.");
115
116 if ( $netsettings{'RED_TYPE'} eq 'DHCP')
117 {
118 if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $netsettings{'RED_DEV'}; close FILE; }
119 dodhcpdial($netsettings{'RED_DEV'},$netsettings{'RED_DHCP_HOSTNAME'});
120 exit 0;
121 }
122 elsif ( ( $netsettings{'RED_TYPE'} eq 'PPTP') && ( $pppsettings{'METHOD'} eq 'DHCP') )
123 {
124 if (open(FILE, ">${General::swroot}/red/device")) { print FILE $netsettings{'RED_DEV'}; close FILE; }
125 unlink ("${General::swroot}/red/iface");
126 dodhcpdial($netsettings{'RED_DEV'},$netsettings{'RED_DHCP_HOSTNAME'});
127 }
128 elsif ( ( $netsettings{'RED_TYPE'} eq 'STATIC') ||
129 ( $netsettings{'RED_TYPE'} eq 'PPTP') && ( $pppsettings{'METHOD'} ne 'DHCP') )
130 {
131 system ("/sbin/ifconfig",
132 $netsettings{'RED_DEV'}, $netsettings{'RED_ADDRESS'},
133 "netmask", $netsettings{'RED_NETMASK'},
134 "broadcast", $netsettings{'RED_BROADCAST'},"up");
135 if ( $netsettings{'RED_TYPE'} eq 'STATIC')
136 {
137 system("/usr/local/bin/setaliases");
138 system("echo $netsettings{'DNS1'} > ${General::swroot}/red/dns1");
139 system("echo $netsettings{'DNS2'} > ${General::swroot}/red/dns2");
140 system("echo $netsettings{'RED_ADDRESS'} > ${General::swroot}/red/local-ipaddress");
141 system("echo $netsettings{'DEFAULT_GATEWAY'} > ${General::swroot}/red/remote-ipaddress");
142 } elsif ( $netsettings{'RED_TYPE'} eq 'PPTP' ) {
143 if (open(FILE, ">${General::swroot}/red/device")) { print FILE $netsettings{'RED_DEV'}; close FILE; }
144 unlink ("${General::swroot}/red/iface");
145 }
146 if ( $netsettings{'DEFAULT_GATEWAY'} ne '' )
147 {
148 system ("/sbin/route","add","default","gw",
149 $netsettings{'DEFAULT_GATEWAY'});
150 }
151 }
152 else
153 {
154 # PPPoE
155 system ("/sbin/ifconfig", $netsettings{'RED_DEV'}, "1.1.1.1",
156 "netmask", "255.255.255.0", "broadcast", "1.1.1.255", "up");
157 }
158
159 if ( $netsettings{'RED_TYPE'} eq 'STATIC')
160 {
161 if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $netsettings{'RED_DEV'}; close FILE; }
162 system ("/bin/touch", "${General::swroot}/red/active");
163 system ("/etc/rc.d/init.d/network red update");
164 exit 0;
165 }
166 }
167 else
168 {
169 &General::log ("ERROR: Can't start RED when RED device not set!");
170 exit 1;
171 }
172 }
173
174
175 if ($pppsettings{'RECONNECTION'} eq 'dialondemand')
176 {
177 system ('/bin/touch', "${General::swroot}/red/dial-on-demand");
178 }
179
180 if ($pppsettings{'VALID'} ne 'yes') {
181 &General::log("Profile has errors.");
182 exit 1;
183 }
184
185 if (-e "${General::swroot}/ppp/updatesettings") {
186 &doupdatesettings;
187 }
188
189 if (( $pppsettings{'METHOD'} eq 'STATIC') && ( $pppsettings{'DNS'} eq 'Manual')) {
190 system("/usr/local/bin/setaliases");
191 if (open(FILE, ">${General::swroot}/red/dns1")) { print FILE $pppsettings{'DNS1'}; close FILE; }
192 if (open(FILE, ">${General::swroot}/red/dns2")) { print FILE $pppsettings{'DNS2'}; close FILE; }
193 if (open(FILE, ">${General::swroot}/red/local-ipaddress")) { print FILE $pppsettings{'IP'}; close FILE; }
194 if (open(FILE, ">${General::swroot}/red/remote-ipaddress")) { print FILE $pppsettings{'GATEWAY'}; close FILE; }
195 }
196 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
197 &General::log("Dial-on-Demand waiting to dial $pppsettings{'PROFILENAME'}.");
198 } else {
199 &General::log("Dialling $pppsettings{'PROFILENAME'}.");
200 }
201
202 if ($pppsettings{'TYPE'} eq 'modem') { &domodemdial(); }
203 elsif ($pppsettings{'TYPE'} eq 'serial') { &doserialdial(); }
204 elsif ($pppsettings{'TYPE'} eq 'isdn') { &doisdndial(); }
205 elsif ($pppsettings{'TYPE'} eq 'pppoe') { &dopppoedial(); }
206 elsif ($pppsettings{'TYPE'} eq 'pptp') { &dopptpdial(); }
207 elsif ($pppsettings{'TYPE'} eq 'fritzdsl') { &dofritzdsldial(); }
208
209 if (-e "${General::swroot}/ppp/updatesettings") {
210 # erase update mark only after specific script had run, allowing specific script to treat the update
211 unlink ("${General::swroot}/ppp/updatesettings");
212 }
213 if ( ($pppsettings{'RECONNECTION'} eq 'dialondemand') || ($pppsettings{'METHOD'} eq 'STATIC') ){
214 system ("/etc/rc.d/init.d/network red update");
215 }
216 }
217 elsif ($ARGV[0] eq 'stop')
218 {
219 if (open(IFACE, "${General::swroot}/red/iface")) {
220 $iface = <IFACE>;
221 close IFACE;
222 chomp ($iface);
223 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
224 }
225
226 my $device;
227 if (open(FILE, "${General::swroot}/red/device")) {
228 $device = <FILE>;
229 close FILE;
230 chomp ($device);
231 $device =~ /([a-zA-Z0-9]*)/; $device = $1;
232 }
233
234 unlink "${General::swroot}/red/dial-on-demand";
235 unlink "${General::swroot}/red/active";
236 unlink "${General::swroot}/red/local-ipaddress";
237 unlink "${General::swroot}/red/remote-ipaddress";
238 unlink "${General::swroot}/red/dns1";
239 unlink "${General::swroot}/red/dns2";
240 unlink "${General::swroot}/red/resolv.conf";
241 unlink "${General::swroot}/red/device";
242
243 # stay with keepconnected during transitional rc.red stop ordered by rc.connectioncheck
244 if ( ! -e "${General::swroot}/red/redial") {
245 unlink "${General::swroot}/red/keepconnected";
246 }
247 unlink "${General::swroot}/red/redial";
248
249 # Kill PPPD
250 if (open(FILE, "/var/run/ppp-ipfire.pid")) {
251 my $pid = <FILE>;
252 close FILE;
253 chomp ($pid);
254 $pid =~ /(\d*)/; $pid = $1;
255 system ('/bin/kill', $pid);
256 }
257
258 # Bring down Ethernet interfaces & Kill DHCPC daemons
259 if (($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) && ( $netsettings{'RED_TYPE'} eq 'PPPOE') && $iface ) {
260 system ("/sbin/ifconfig", $iface, "down");
261 }
262 if ($device) {
263 system ("/sbin/ifconfig", $device, "down");
264 }
265
266 my $file;
267 while (($file = glob("${General::swroot}/dhcpc/dhcpcd-*.pid") )) {
268 if (open(FILE, $file)) {
269 my $pid = <FILE>;
270 close FILE;
271 chomp ($pid);
272 $pid =~ /(\d*)/; $pid = $1;
273 system ('/bin/kill', $pid);
274 }
275 }
276
277 if (!system ('/bin/ps -ef | /bin/grep -q [a]tmarpd')) {
278 if ($pppsettings{'GATEWAY'} ne '') {
279 system("/usr/sbin/atmarp -d $pppsettings{'GATEWAY'} 2>/dev/null"); }
280 system('/bin/killall /usr/sbin/atmarpd 2>/dev/null');
281 system ('/sbin/ifconfig', 'atm0', 'down');
282 }
283
284 if ($pppsettings{'TYPE'} eq 'isdn') { system('/etc/rc.d/rc.isdn','stop'); }
285 if ($pppsettings{'TYPE'} eq 'fritzdsl') { system ('/etc/rc.d/rc.fritzdsl','stop'); }
286
287 if ( ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} eq 'STATIC') ||
288 ( $netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'PROTOCOL'} eq 'RFC1483' &&
289 $pppsettings{'METHOD'} eq 'STATIC' ) ) {
290 system ("/etc/rc.d/init.d/network red update");
291 }
292 }
293 elsif ($ARGV[0] eq 'clear')
294 {
295 &doupdatesettings();
296 &docleanup();
297 }
298
299 exit 0;
300
301 sub docleanup
302 {
303 if ($pppsettings{'TYPE'} eq 'fritzdsl') { system ('/etc/rc.d/rc.fritzdsl','cleanup'); }
304 }
305
306 sub domodemdial
307 {
308 my @pppcommand = ('/usr/sbin/pppd');
309 my $loginscript = '';
310
311 if ($pppsettings{'COMPORT'} =~ /ttyACM/) {
312 system ('/sbin/rmmod acm');
313 sleep 1;
314 system ('/sbin/modprobe acm');
315 }
316
317 my $device = "/dev/${pppsettings{'COMPORT'}}";
318
319 if ($pppsettings{'DNS'} eq 'Automatic') {
320 push(@pppcommand, ('usepeerdns')); }
321
322 if ($pppsettings{'AUTH'} eq 'pap') {
323 push(@pppcommand, ('-chap'));
324 } elsif ($pppsettings{'AUTH'} eq 'chap') {
325 push(@pppcommand, ('-pap'));
326 } elsif ($pppsettings{'AUTH'} eq 'standard-login-script') {
327 $loginscript = 'standardloginscript';
328 } elsif ($pppsettings{'AUTH'} eq 'demon-login-script') {
329 $loginscript = 'demonloginscript';
330 } else {
331 $loginscript = $pppsettings{'LOGINSCRIPT'};
332 }
333
334 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
335 if ($pppsettings{'TIMEOUT'} != 0)
336 {
337 my $seconds = $pppsettings{'TIMEOUT'} * 60;
338 push (@pppcommand, ('idle', $seconds));
339 }
340 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
341 push (@pppcommand, ('demand', 'nopersist'));
342 }
343 push (@pppcommand,
344 ('active-filter',
345 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
346 }
347
348 push (@pppcommand, ('novj', 'novjccomp'));
349
350 push (@pppcommand, ('lock', 'modem', 'crtscts', $device,
351 $pppsettings{'DTERATE'}, 'noipdefault',
352 'defaultroute', 'user', $pppsettings{'USERNAME'},
353 'maxfail', $pppsettings{'MAXRETRIES'}, 'connect',
354 '/etc/ppp/dialer'));
355 if ($pppsettings{'DEBUG'} eq 'on') {
356 push(@pppcommand, ('debug'));
357 }
358
359 system @pppcommand;
360 }
361
362 sub doserialdial
363 {
364 my @pppcommand = ('/usr/sbin/pppd');
365 my $loginscript = '';
366
367 if ($pppsettings{'COMPORT'} =~ /ttyACM/) {
368 system ('/sbin/rmmod acm');
369 sleep 1;
370 system ('/sbin/modprobe acm');
371 }
372
373 my $device = "/dev/${pppsettings{'COMPORT'}}";
374
375 if ($pppsettings{'DNS'} eq 'Automatic') {
376 push(@pppcommand, ('usepeerdns')); }
377
378 if ($pppsettings{'AUTH'} eq 'pap') {
379 push(@pppcommand, ('-chap'));
380 } elsif ($pppsettings{'AUTH'} eq 'chap') {
381 push(@pppcommand, ('-pap'));
382 }
383
384 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
385 if ($pppsettings{'TIMEOUT'} != 0)
386 {
387 my $seconds = $pppsettings{'TIMEOUT'} * 60;
388 push (@pppcommand, ('idle', $seconds));
389 }
390 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
391 push (@pppcommand, ('demand', 'nopersist'));
392 }
393 push (@pppcommand,
394 ('active-filter',
395 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
396 }
397
398 push (@pppcommand, ('novj', 'novjccomp'));
399
400 push (@pppcommand, ('lock', 'modem', 'crtscts', $device,
401 $pppsettings{'DTERATE'}, 'noipdefault',
402 'defaultroute', 'user', $pppsettings{'USERNAME'},
403 'maxfail', $pppsettings{'MAXRETRIES'}, 'connect',
404 '/bin/true'));
405 if ($pppsettings{'DEBUG'} eq 'on') {
406 push(@pppcommand, ('debug'));
407 }
408
409 system @pppcommand;
410 }
411
412 sub doisdndial
413 {
414 my $pppoptions;
415 my $seconds;
416 my $phone;
417
418 if (system ('/etc/rc.d/rc.isdn', 'start')) {
419 &General::log ("ERROR: ISDN module failed to load");
420 exit 1;
421 }
422
423 $seconds = $pppsettings{'TIMEOUT'} * 60;
424 if ($pppsettings{'USEDOV'} eq 'on')
425 {
426 $phone = 'v' . $pppsettings{'TELEPHONE'};
427 }
428 else
429 {
430 $phone = $pppsettings{'TELEPHONE'};
431 };
432
433 if ($pppsettings{'COMPORT'} eq 'isdn2')
434 {
435 system('/usr/sbin/isdnctrl','addif','ippp0');
436 system('/usr/sbin/isdnctrl','addslave','ippp0','ippp1');
437 system('/usr/sbin/isdnctrl','l2_prot','ippp0','hdlc');
438 system('/usr/sbin/isdnctrl','l3_prot','ippp0','trans');
439 system('/usr/sbin/isdnctrl','encap','ippp0','syncppp');
440 system('/usr/sbin/isdnctrl','dialmax','ippp0',$pppsettings{'MAXRETRIES'});
441 system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'});
442 system('/usr/sbin/isdnctrl','addphone','ippp0','out',$phone);
443 system('/usr/sbin/isdnctrl','huptimeout','ippp0',$seconds);
444 system('/usr/sbin/isdnctrl','l2_prot','ippp1','hdlc');
445 system('/usr/sbin/isdnctrl','l3_prot','ippp1','trans');
446 system('/usr/sbin/isdnctrl','encap','ippp1','syncppp');
447 system('/usr/sbin/isdnctrl','dialmax','ippp1',$pppsettings{'MAXRETRIES'});
448 system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'});
449 system('/usr/sbin/isdnctrl','addphone','ippp1','out',$phone);
450 system('/usr/sbin/isdnctrl','huptimeout','ippp1',$seconds);
451 system('/usr/sbin/isdnctrl','dialmode','ippp1','auto');
452
453 my @pppcommand = ('/usr/sbin/ipppd','ms-get-dns','noipdefault','+mp',
454 'defaultroute','user',$pppsettings{'USERNAME'},
455 'name',$pppsettings{'USERNAME'},
456 'active-filter','outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0',
457 'pidfile','/var/run/ppp-ipfire.pid','/dev/ippp0','/dev/ippp1');
458 if ($pppsettings{'DEBUG'} eq 'on') {
459 push(@pppcommand, ('debug'));
460 }
461 if ($pppsettings{'AUTH'} eq 'pap') {
462 push(@pppcommand, ('-chap'));
463 } elsif ($pppsettings{'AUTH'} eq 'chap') {
464 push(@pppcommand, ('-pap'));
465 }
466 system (@pppcommand);
467 }
468 else
469 {
470 system('/usr/sbin/isdnctrl','addif','ippp0');
471 system('/usr/sbin/isdnctrl','l2_prot','ippp0','hdlc');
472 system('/usr/sbin/isdnctrl','l3_prot','ippp0','trans');
473 system('/usr/sbin/isdnctrl','encap','ippp0','syncppp');
474 system('/usr/sbin/isdnctrl','dialmax','ippp0',$pppsettings{'MAXRETRIES'});
475 system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'});
476 system('/usr/sbin/isdnctrl','addphone','ippp0','out',$phone);
477 system('/usr/sbin/isdnctrl','huptimeout','ippp0',$seconds);
478
479 my @pppcommand = ('/usr/sbin/ipppd','ms-get-dns','noipdefault',
480 'defaultroute','user',$pppsettings{'USERNAME'},
481 'name',$pppsettings{'USERNAME'},
482 'active-filter','outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0',
483 'pidfile','/var/run/ppp-ipfire.pid','/dev/ippp0');
484 if ($pppsettings{'DEBUG'} eq 'on') {
485 push(@pppcommand, ('debug'));
486 }
487 if ($pppsettings{'AUTH'} eq 'pap') {
488 push(@pppcommand, ('-chap'));
489 } elsif ($pppsettings{'AUTH'} eq 'chap') {
490 push(@pppcommand, ('-pap'));
491 }
492 system (@pppcommand);
493 }
494
495 sleep 1;
496
497 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
498 system('/usr/sbin/isdnctrl','dialmode','ippp0','auto');
499 system('/sbin/ifconfig','ippp0','10.112.112.112','pointopoint','10.112.112.113');
500 system('/sbin/ifconfig','ippp0','-arp','-broadcast');
501 system('/sbin/route','add','default','dev','ippp0');
502 } else {
503 system('/usr/sbin/isdnctrl', 'dial', 'ippp0');
504
505 }
506
507 system('/bin/killall', 'ibod');
508 if ($pppsettings{'COMPORT'} eq 'isdn2') {
509 if ($pppsettings{'USEIBOD'} eq 'on') {
510 system("/usr/sbin/ibod &");
511 } else {
512 system('/usr/sbin/isdnctrl', 'addlink', 'ippp0');
513 }
514 }
515 }
516
517 sub dopppoedial
518 {
519 if ($pppsettings{'METHOD'} ne 'PPPOE_PLUGIN') {
520 my @pppcommand = ('/usr/sbin/pppd', 'pty');
521 my @pppoecommand = ('/usr/sbin/pppoe', '-p','/var/run/pppoe.pid','-I',
522 $netsettings{'RED_DEV'}, '-T', '80', '-U', '-m', '1412');
523
524 if ($pppsettings{'SERVICENAME'}) {
525 push(@pppoecommand, ('-S', $pppsettings{'SERVICENAME'})); }
526 if ($pppsettings{'CONCENTRATORNAME'}) {
527 push(@pppoecommand, ('-C', $pppsettings{'CONCENTRATORNAME'})); }
528
529 push(@pppcommand, "@pppoecommand");
530
531 if ($pppsettings{'DNS'} eq 'Automatic') {
532 push(@pppcommand, ('usepeerdns'));
533 }
534
535 if ($pppsettings{'AUTH'} eq 'pap') {
536 push(@pppcommand, ('-chap'));
537 } elsif ($pppsettings{'AUTH'} eq 'chap') {
538 push(@pppcommand, ('-pap'));
539 }
540
541 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
542 if ($pppsettings{'TIMEOUT'} != 0) {
543 my $seconds = $pppsettings{'TIMEOUT'} * 60;
544 push(@pppcommand, ('idle', "$seconds"));
545 }
546 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
547 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
548 }
549 push (@pppcommand,
550 ('active-filter',
551 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
552 }
553
554 push(@pppcommand, ('noipdefault', 'default-asyncmap',
555 'defaultroute', 'hide-password', 'local',
556 'mtu', '1492', 'mru', '1492', 'noaccomp', 'noccp',
557 'nobsdcomp', 'nodeflate', 'nopcomp', 'novj', 'novjccomp',
558 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
559 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
560 'maxfail',$pppsettings{'MAXRETRIES'}));
561 if ($pppsettings{'DEBUG'} eq 'on') {
562 push(@pppcommand, ('debug'));
563 }
564
565 system (@pppcommand);
566 } else {
567 # PPPoE plugin
568 system ('/sbin/modprobe pppoe');
569 my @pppcommand = ('/usr/sbin/pppd');
570 push(@pppcommand,'plugin','rp-pppoe.so',"$netsettings{'RED_DEV'}");
571 if ($pppsettings{'DNS'} eq 'Automatic') {
572 push(@pppcommand, ('usepeerdns'));
573 }
574 if ($pppsettings{'AUTH'} eq 'pap') {
575 push(@pppcommand, ('-chap'));
576 } elsif ($pppsettings{'AUTH'} eq 'chap') {
577 push(@pppcommand, ('-pap'));
578 }
579 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
580 if ($pppsettings{'TIMEOUT'} != 0) {
581 my $seconds = $pppsettings{'TIMEOUT'} * 60;
582 push(@pppcommand, ('idle', "$seconds"));
583 }
584 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
585 push (@pppcommand, ('demand','nopersist'));
586 }
587 push (@pppcommand,
588 ('active-filter',
589 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
590 }
591 push(@pppcommand, ('noipdefault', 'defaultroute', 'hide-password', 'ipcp-accept-local',
592 'ipcp-accept-remote', 'passive', 'noccp','nopcomp', 'novjccomp',
593 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
594 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
595 'maxfail',$pppsettings{'MAXRETRIES'}));
596 if ($pppsettings{'DEBUG'} eq 'on') {
597 push(@pppcommand, ('debug'));
598 }
599
600 system (@pppcommand);
601 }
602 }
603
604 sub dopptpdial
605 {
606 my %pptpdhcpc;
607 my $routerip = $pppsettings{'ROUTERIP'} ? $pppsettings{'ROUTERIP'} : "10.0.0.138";
608 if ( $pppsettings{'METHOD'} eq 'DHCP' && open(FILE, "${General::swroot}/red/device")) {
609 my $device = <FILE>;
610 close FILE;
611 chomp ($device);
612 $device =~ /([a-zA-Z0-9]*)/; $device = $1;
613 if (&General::readhash("${General::swroot}/dhcpc/dhcpcd-$device.info", \%pptpdhcpc)) {
614 system("/sbin/route add -host $routerip gw $pptpdhcpc{'GATEWAY'}");
615 } else {
616 system("/sbin/route add -host $routerip dev $device");
617 }
618 }
619
620 my @pppcommand = ('/usr/sbin/pppd', 'pty');
621 my @pptpcommand = ('/usr/sbin/pptp', $routerip, '--nobuffer', '--nolaunchpppd', '--sync');
622 if ($pppsettings{'PHONEBOOK'}) {
623 push (@pptpcommand, ('--phone ', $pppsettings{'PHONEBOOK'}));
624 }
625
626 push(@pppcommand, "@pptpcommand");
627
628 if ($pppsettings{'DNS'} eq 'Automatic') {
629 push(@pppcommand, ('usepeerdns'));
630 }
631 if ($pppsettings{'AUTH'} eq 'pap') {
632 push(@pppcommand, ('-chap'));
633 } elsif ($pppsettings{'AUTH'} eq 'chap') {
634 push(@pppcommand, ('-pap'));
635 }
636
637 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
638 if ($pppsettings{'TIMEOUT'} != 0) {
639 my $seconds = $pppsettings{'TIMEOUT'} * 60;
640 push(@pppcommand, ('idle', "$seconds"));
641 }
642 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
643 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
644 }
645 push (@pppcommand,
646 ('active-filter',
647 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
648 }
649
650 push(@pppcommand, ('noipdefault', 'default-asyncmap',
651 'defaultroute', 'hide-password', 'local','noaccomp', 'noccp',
652 'nobsdcomp', 'nodeflate', 'nopcomp', 'novj', 'novjccomp',
653 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
654 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
655 'maxfail',$pppsettings{'MAXRETRIES'},'sync'));
656 if ($pppsettings{'DEBUG'} eq 'on') {
657 push(@pppcommand, ('debug'));
658 }
659
660 system (@pppcommand);
661 }
662
663 sub dofritzdsldial
664 {
665 my $controller;
666
667 if (system ('/etc/rc.d/rc.fritzdsl','start')) {
668 &General::log ("ERROR: Fritz DSL module failed to load");
669 exit 1;
670 }
671
672 # controller number
673 if ($pppsettings{'TYPE'} eq 'fritzdsl') {
674 if ( ! system ('/bin/grep', '1244:2700', '/proc/pci')) {
675 $controller=1; # fcdslsl
676 } elsif (! system('/bin/grep', '1244:2900', '/proc/pci')) {
677 $controller=2; # fcdsl2
678 } elsif (! system('/bin/grep', '1131:5402', '/proc/pci')) {
679 $controller=2; # fdsl
680 } elsif (! system('/bin/grep', 'Vendor=057c ProdID=2300', '/proc/bus/usb/devices')) {
681 $controller=1; # fcdslusb
682 } elsif (! system('/bin/grep', 'Vendor=057c ProdID=3500', '/proc/bus/usb/devices')) {
683 $controller=1; # fcdslslusb
684 }
685 }
686 my @pppcommand = ('/usr/sbin/pppd');
687 my @capiplugin;
688
689 if ($pppsettings{'DNS'} eq 'Automatic') {
690 push(@pppcommand, ('usepeerdns'));
691 }
692
693 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
694 if ($pppsettings{'TIMEOUT'} != 0) {
695 my $seconds = $pppsettings{'TIMEOUT'} * 60;
696 push(@pppcommand, ('idle', "$seconds"));
697 }
698 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
699 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
700 }
701 push (@pppcommand,
702 ('active-filter',
703 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
704 }
705
706 push(@pppcommand, ('noipdefault', 'defaultroute', 'sync', 'user',
707 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
708 'noaccomp', 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
709 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
710 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
711
712 if ($pppsettings{'DEBUG'} eq 'on') {
713 push(@pppcommand, ('debug'));
714 }
715
716 if ($pppsettings {'PROTOCOL'} eq 'RFC1483') {
717 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoe',
718 'controller', $controller, 'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
719 } else {
720 if ($pppsettings {'ENCAP'} eq '1') {
721 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoallc',
722 'controller', $controller, 'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
723 } else {
724 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoa',
725 'controller', $controller,'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
726 }
727 }
728 push(@pppcommand, @capiplugin);
729 push(@pppcommand, '/dev/null');
730
731 system (@pppcommand);
732 }
733
734 sub doatmdial
735 {
736 my $ENCAP;
737 if ($pppsettings {'PROTOCOL'} eq 'RFC2364') {
738 system ('/sbin/modprobe pppoatm');
739 my @pppcommand = ('/usr/sbin/pppd');
740 if ($pppsettings{'ENCAP'} eq '0') { $ENCAP='vc-encaps'; } else { $ENCAP='llc-encaps'; }
741 push(@pppcommand,'plugin', 'pppoatm.so',$pppsettings{'VPI'}.".".$pppsettings{'VCI'},"$ENCAP");
742 if ($pppsettings{'DNS'} eq 'Automatic') { push(@pppcommand, ('usepeerdns'));}
743 if ($pppsettings{'AUTH'} eq 'pap') {
744 push(@pppcommand, ('-chap'));
745 } elsif ($pppsettings{'AUTH'} eq 'chap') {
746 push(@pppcommand, ('-pap'));
747 }
748 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
749 if ($pppsettings{'TIMEOUT'} != 0) {
750 my $seconds = $pppsettings{'TIMEOUT'} * 60;
751 push(@pppcommand, ('idle', "$seconds"));
752 }
753 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
754 push (@pppcommand, ('demand','nopersist'));
755 }
756 push (@pppcommand,
757 ('active-filter',
758 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
759 }
760 push(@pppcommand, ('noipdefault', 'defaultroute', 'user',
761 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
762 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
763 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
764 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
765
766 if ($pppsettings{'DEBUG'} eq 'on') {
767 push(@pppcommand, ('debug'));
768 }
769
770 system (@pppcommand);
771 } elsif ($pppsettings {'PROTOCOL'} eq 'RFC1483') {
772 if ($pppsettings {'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) {
773 my $itf='0';
774 my $device = "nas$itf";
775 if (open(FILE, ">${General::swroot}/red/device")) { print FILE $device; close FILE; }
776 $netsettings{'RED_DEV'} = $device;
777 if (system ('/bin/ps -ef | /bin/grep -q [b]r2684ctl')) {
778 system ('/sbin/modprobe br2684');
779 system ('/usr/bin/br2684ctl', '-b', '-c', "$itf", '-e', $pppsettings{'ENCAP'}, '-a', "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
780 sleep 3;
781 }
782 system ('/sbin/ifconfig',"$device",'up');
783 &dopppoedial();
784 } elsif ($pppsettings{'ENCAP'} =~ /^(0|1)$/) {
785 my $itf='0';
786 $iface = "nas$itf";
787 if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $iface; close FILE; }
788 if (system ('/bin/ps -ef | /bin/grep -q [b]r2684ctl')) {
789 system ('/sbin/modprobe br2684');
790 system ('/usr/bin/br2684ctl', '-b', '-c', "$itf", '-e', $pppsettings{'ENCAP'}, '-a', "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
791 sleep 3;
792 }
793 system ('/sbin/ifconfig',"$iface",'up');
794
795 if ($pppsettings{'METHOD'} eq 'STATIC') {
796 my @staticcommand = ('/sbin/ifconfig');
797 push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}));
798 if ($pppsettings{'BROADCAST'} ne '') {
799 push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'}));
800 }
801 system (@staticcommand);
802 system ("/sbin/route","add","default","gw",$pppsettings{'GATEWAY'});
803 system ("/bin/touch", "${General::swroot}/red/active");
804 system ("/etc/rc.d/init.d/network red update");
805 } elsif ($pppsettings {'METHOD'} eq 'DHCP') {
806 dodhcpdial($iface,$pppsettings{'DHCP_HOSTNAME'});
807 }
808 } elsif ($pppsettings{'ENCAP'} =~ /^(2|3)$/) {
809 my $itf='0';
810 $iface = "atm$itf";
811 if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $iface; close FILE; }
812 if (system ('/bin/ps -ef | /bin/grep -q [a]tmarpd')) {
813 if (system ('/usr/sbin/atmarpd -b -l syslog')) {
814 &General::log('atmarpd fail');
815 exit 1;
816 }
817 # it will fail on all attempt after the first because interface still exist
818 system ("/usr/sbin/atmarp -c $iface 2>/dev/null");
819
820 if ($pppsettings{'METHOD'} eq 'STATIC') {
821 my @staticcommand = ('/sbin/ifconfig');
822 push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}, 'up'));
823 if ($pppsettings{'BROADCAST'} ne '') {
824 push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'}));
825 }
826 system (@staticcommand);
827 # we have to wait a bit before launching atmarp -s
828 sleep 2;
829 my @atmarp = ('/usr/sbin/atmarp', '-s', $pppsettings{'GATEWAY'}, "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
830 if ($pppsettings{'ENCAP'} eq '3') {
831 push(@atmarp, 'null' ); # routed ip vc encap
832 }
833 system (@atmarp);
834 system ("/sbin/route", "add", "default", "gw", $pppsettings{'GATEWAY'});
835 system ("/bin/touch", "${General::swroot}/red/active");
836 }
837 }
838 }
839 }
840 }