Gro├čes Update:
[ipfire-2.x.git] / html / cgi-bin / pppsetup.cgi
1 #!/usr/bin/perl
2 #
3 # SmoothWall CGIs
4 #
5 # This code is distributed under the terms of the GPL
6 #
7 # (c) The SmoothWall Team
8 #
9 # Copyright (C) 03-Apr-2002 Guy Ellis <guy@traverse.com.au>
10 #              - ISDN DOV support
11 #              - ibod now an option
12 #              - PCI ADSL support added
13 #
14 # $Id: pppsetup.cgi,v 1.17.2.49 2005/12/01 16:20:35 franck78 Exp $
15
16 use strict;
17
18 # enable only the following on debugging purpose
19 #use warnings;
20 #use CGI::Carp 'fatalsToBrowser';
21
22 require 'CONFIG_ROOT/general-functions.pl';
23 require "${General::swroot}/lang.pl";
24 require "${General::swroot}/header.pl";
25
26 our %pppsettings=();
27 my %temppppsettings=();
28 our %modemsettings=();
29 our %isdnsettings=();
30 our %netsettings=();
31 my %selected=();
32 my %checked=();
33 my @profilenames=();
34 my $errormessage = '';
35 my $maxprofiles = 5;
36 my $kernel=`/bin/uname -r | /usr/bin/tr -d '\012'`;
37
38 &Header::showhttpheaders();
39
40 $pppsettings{'ACTION'} = '';
41 &initprofile();
42 &Header::getcgihash(\%pppsettings);
43
44 if ($pppsettings{'ACTION'} ne '' &&
45         (-e '/var/run/ppp-ipcop.pid' || -e "${General::swroot}/red/active"))
46 {
47         $errormessage = $Lang::tr{'unable to alter profiles while red is active'};
48         # read in the current vars
49         %pppsettings = ();
50         $pppsettings{'VALID'} = '';
51         &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
52 }
53 elsif ($pppsettings{'ACTION'} eq $Lang::tr{'refresh'})
54 {
55         unless ($pppsettings{'TYPE'} =~ /^(modem|serial|isdn|pppoe|pptp|alcatelusb|alcatelusbk|amedynusbadsl|conexantusbadsl|conexantpciadsl|3cp4218usbadsl|pulsardsl|eciadsl|fritzdsl|bewanadsl|eagleusbadsl)$/) {
56                 $errormessage = $Lang::tr{'invalid input'};
57                 goto ERROR; }
58         my $type = $pppsettings{'TYPE'};
59         &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
60         $pppsettings{'TYPE'} = $type;
61 }
62 elsif ($pppsettings{'ACTION'} eq $Lang::tr{'save'})
63 {
64         if ($pppsettings{'TYPE'} =~ /^(modem|serial|isdn)$/ && $pppsettings{'COMPORT'} !~ /^(ttyS0|ttyS1|ttyS2|ttyS3|ttyS4|usb\/ttyACM0|usb\/ttyACM1|usb\/ttyACM2|usb\/ttyACM3|isdn1|isdn2)$/) {
65                 $errormessage = $Lang::tr{'invalid input'};
66                 goto ERROR; }
67         if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/ && $pppsettings{'DTERATE'} !~ /^(9600|19200|38400|57600|115200|230400)$/) {
68                 $errormessage = $Lang::tr{'invalid input'};
69                 goto ERROR; }
70         if ($pppsettings{'TYPE'} eq 'modem' && $pppsettings{'DIALMODE'} !~ /^(T|P)$/) {
71                 $errormessage = $Lang::tr{'invalid input'};
72                 goto ERROR; }
73         if ($pppsettings{'AUTH'} !~ /^(pap-or-chap|pap|chap|standard-login-script|demon-login-script|other-login-script)$/) {
74                 $errormessage = $Lang::tr{'invalid input'};
75                 goto ERROR;
76         }
77
78         if ($pppsettings{'PROFILENAME'} eq '') {
79                 $errormessage = $Lang::tr{'profile name not given'};
80                 $pppsettings{'PROFILENAME'} = '';
81                 goto ERROR; }
82         if ($pppsettings{'TYPE'} =~ /^(modem|isdn)$/) {
83                 if ($pppsettings{'TELEPHONE'} eq '') {
84                         $errormessage = $Lang::tr{'telephone not set'}; 
85                         goto ERROR; }
86                 if (!($pppsettings{'TELEPHONE'} =~ /^[\d\*\#\,]+$/)) {
87                         $errormessage = $Lang::tr{'bad characters in the telephone number field'};
88                         goto ERROR; }
89         }
90         unless (($pppsettings{'PROTOCOL'} eq 'RFC1483' && $pppsettings{'METHOD'} =~ /^(STATIC|DHCP)$/)) {
91                 if ($pppsettings{'USERNAME'} eq '') {
92                         $errormessage = $Lang::tr{'username not set'}; 
93                         goto ERROR; }
94                 if ($pppsettings{'PASSWORD'} eq '') {
95                         $errormessage = $Lang::tr{'password not set'};
96                         goto ERROR; }
97         }
98
99         if ($pppsettings{'TIMEOUT'} eq '') {
100                 $errormessage = $Lang::tr{'idle timeout not set'};
101                 goto ERROR; }
102         if (!($pppsettings{'TIMEOUT'} =~ /^\d+$/)) {
103                 $errormessage = $Lang::tr{'only digits allowed in the idle timeout'};
104                 goto ERROR; }
105
106         if ($pppsettings{'LOGINSCRIPT'} =~ /[.\/ ]/ ) {
107                 $errormessage = $Lang::tr{'bad characters in script field'}; 
108                 goto ERROR; }
109
110         if ($pppsettings{'DNS1'})
111         {
112                 if (!(&General::validip($pppsettings{'DNS1'}))) {
113                         $errormessage = $Lang::tr{'invalid primary dns'};
114                         goto ERROR;  }
115         }
116         if ($pppsettings{'DNS2'})
117         {
118                 if (!(&General::validip($pppsettings{'DNS2'}))) {
119                         $errormessage = $Lang::tr{'invalid secondary dns'};
120                         goto ERROR; }
121         }
122
123         if ($pppsettings{'MAXRETRIES'} eq '') {
124                 $errormessage = $Lang::tr{'max retries not set'};
125                 goto ERROR; }
126         if (!($pppsettings{'MAXRETRIES'} =~ /^\d+$/)) {
127                 $errormessage = $Lang::tr{'only digits allowed in max retries field'};
128                 goto ERROR; }
129
130         if (!($pppsettings{'HOLDOFF'} =~ /^\d+$/)) {
131                 $errormessage = $Lang::tr{'only digits allowed in holdoff field'};
132                 goto ERROR; }
133
134         my $drivererror = 0;
135         if ($pppsettings{'TYPE'} =~ /^(alcatelusb|alcatelusbk)$/) {
136                 my $modem = '';
137                 my $speedtouch = &Header::speedtouchversion;
138                 if ($speedtouch >=0 && $speedtouch <=4) {
139                         if ($speedtouch ==4) { $modem='v4_b'; } else { $modem='v0123'; }
140                         $pppsettings{'MODEM'} = $modem;
141                 } else {
142                         $modem='v0123';
143                         $errormessage ="$Lang::tr{'unknown'} Rev $speedtouch";
144                         goto ERROR;
145                 }
146                 if (! -e "${General::swroot}/alcatelusb/firmware.$modem.bin") {
147                         $errormessage = $Lang::tr{'no alcatelusb firmware'};
148                         $drivererror = 1;
149                         goto ERROR;
150                 }
151         }
152
153         if($pppsettings{'TYPE'} eq 'eciadsl' && (!(-e "${General::swroot}/eciadsl/synch.bin"))) {
154                 $errormessage = $Lang::tr{'no eciadsl synch.bin file'};
155                 $drivererror = 1;
156                 goto ERROR; }
157
158         if($pppsettings{'TYPE'} eq 'fritzdsl' && (!(-e "/lib/modules/$kernel/misc/fcdslusb.o.gz"))) {
159                 $errormessage = $Lang::tr{'no fritzdsl driver'};
160                 $drivererror = 1;
161                 goto ERROR; }
162
163         if( $pppsettings{'USEIBOD'} eq 'on' && $pppsettings{'COMPORT'} eq 'isdn1') {
164                 $errormessage = $Lang::tr{'ibod for dual isdn only'};
165                 goto ERROR; }
166
167         if ($pppsettings{'TYPE'} eq 'pptp') {
168                 $errormessage = '';
169                 if ($pppsettings{'METHOD'} eq 'STATIC') {
170                         if (! &General::validip($pppsettings{'ROUTERIP'})) {
171                                 $errormessage = $Lang::tr{'router ip'}.' '.$Lang::tr{'invalid ip'};
172                         }
173                 } else {
174                         if (($pppsettings{'DHCP_HOSTNAME'} ne '') && (! &General::validfqdn($pppsettings{'DHCP_HOSTNAME'})) ) {
175                                 $errormessage = $errormessage.' '.$Lang::tr{'hostname'}.' '.$Lang::tr{'invalid hostname'};
176                         }
177                 }
178                 if ($errormessage ne '') {goto ERROR; }
179         }
180
181         if ($pppsettings{'TYPE'} =~ /^(alcatelusb|alcatelusbk|amedynusbadsl|conexantusbadsl|conexantpciadsl|3cp4218usbadsl|pulsardsl|eciadsl|fritzdsl|bewanadsl|eagleusbadsl)$/) {
182                 if ( ($pppsettings{'VPI'} eq '') || ($pppsettings{'VCI'} eq '') ) {
183                         $errormessage = $Lang::tr{'invalid vpi vpci'};
184                         goto ERROR; }
185                 if ( (!($pppsettings{'VPI'} =~ /^\d+$/)) || (!($pppsettings{'VCI'} =~ /^\d+$/)) ) {
186                         $errormessage = $Lang::tr{'invalid vpi vpci'};
187                         goto ERROR; }
188                 if (($pppsettings{'VPI'} eq '0') && ($pppsettings{'VCI'} eq '0')) {
189                         $errormessage = $Lang::tr{'invalid vpi vpci'};
190                         goto ERROR; }
191                 if ( $pppsettings{'PROTOCOL'} eq '' ) {
192                         $errormessage = $Lang::tr{'invalid input'};
193                         goto ERROR; }
194         }
195
196         if ( ($pppsettings{'PROTOCOL'} eq 'RFC1483') && ($pppsettings{'METHOD'} eq '') && \
197                 ($pppsettings{'TYPE'} !~ /^(alcatelusb|fritzdsl)$/)) {
198                         $errormessage = $Lang::tr{'invalid input'};
199                         goto ERROR; }
200
201         if (($pppsettings{'PROTOCOL'} eq 'RFC1483' && $pppsettings{'METHOD'} eq 'DHCP')) {
202                 if ($pppsettings{'DHCP_HOSTNAME'} ne '') {
203                         if (! &General::validfqdn($pppsettings{'DHCP_HOSTNAME'})) {
204                                 $errormessage = $errormessage.' '.$Lang::tr{'hostname'}.': '.$Lang::tr{'invalid hostname'}; }
205                 }
206         }
207
208         if (($pppsettings{'PROTOCOL'} eq 'RFC1483' && $pppsettings{'METHOD'} eq 'STATIC')) {
209                 $errormessage = '';
210                 if (! &General::validip($pppsettings{'IP'})) {
211                         $errormessage = $Lang::tr{'static ip'}.' '.$Lang::tr{'invalid ip'}; }
212                 if (! &General::validip($pppsettings{'GATEWAY'})) {
213                         $errormessage = $errormessage.' '.$Lang::tr{'gateway ip'}.' '.$Lang::tr{'invalid ip'}; }
214                 if (! &General::validmask($pppsettings{'NETMASK'})) {
215                         $errormessage = $errormessage.' '.$Lang::tr{'netmask'}.' '.$Lang::tr{'invalid netmask'}; }
216                 if ($pppsettings{'BROADCAST'} ne '') {
217                         if (! &General::validip($pppsettings{'BROADCAST'})) {
218                                  $errormessage = $errormessage.' '.$Lang::tr{'broadcast'}.' '.$Lang::tr{'invalid broadcast ip'}; }
219                 }
220                 if( $pppsettings{'DNS'} eq 'Automatic') {
221                         $errormessage = $Lang::tr{'invalid input'}; }
222                 if ($errormessage ne '') {goto ERROR; }
223         }
224
225         if( $pppsettings{'PROTOCOL'} eq 'RFC1483' && $pppsettings{'METHOD'} ne 'PPPOE'  && \
226                 $pppsettings{'RECONNECTION'} eq 'dialondemand' ) {
227                 $errormessage = $Lang::tr{'invalid input'};
228                 goto ERROR; }
229
230         if( $pppsettings{'RECONNECTION'} eq 'dialondemand' && `/bin/cat ${General::swroot}/ddns/config` =~ /,on$/m ) {
231                 $errormessage = $Lang::tr{'dod not compatible with ddns'};
232                 goto ERROR; }
233
234         if ( ($pppsettings{'TYPE'} =~ /^(bewanadsl)$/) && $pppsettings{'MODEM'} eq '') {
235                 $errormessage = $Lang::tr{'no modem selected'};
236                 goto ERROR; }
237
238         if( $pppsettings{'PROTOCOL'} eq 'RFC1483') {
239                 $pppsettings{'ENCAP'} = $pppsettings{'ENCAP_RFC1483'}; }
240         if( $pppsettings{'PROTOCOL'} eq 'RFC2364') {
241                 $pppsettings{'ENCAP'} = $pppsettings{'ENCAP_RFC2364'}; }
242         delete $pppsettings{'ENCAP_RFC1483'};
243         delete $pppsettings{'ENCAP_RFC2364'};
244
245 ERROR:
246         if ($errormessage) {
247                 $pppsettings{'VALID'} = 'no'; }
248         else {
249                 $pppsettings{'VALID'} = 'yes'; }
250
251         # write cgi vars to the file.
252         &General::writehash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
253                 \%pppsettings);
254
255         # make link and write secret file.
256         &updatesettings();
257         &writesecrets();
258
259         &General::log("$Lang::tr{'profile saved'} $pppsettings{'PROFILENAME'}");
260         if ($drivererror) {
261         my $refresh = "<META HTTP-EQUIV='refresh' CONTENT='1; URL=/cgi-bin/upload.cgi'>";
262                 my $title = $Lang::tr{'upload'};
263                 &Header::openpage($title, 0, $refresh);
264         }
265 }
266 elsif ($pppsettings{'ACTION'} eq $Lang::tr{'select'})
267 {
268         my $profile = $pppsettings{'PROFILE'};
269         %temppppsettings = ();
270         $temppppsettings{'PROFILE'} = '';
271         &General::readhash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
272                 \%temppppsettings);
273
274         # make link.
275         &updatesettings(); 
276
277         # read in the new params "early" so we can write secrets.
278         %pppsettings = ();
279         &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
280         $pppsettings{'PROFILE'} = $profile;
281         &General::writehash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
282                 \%pppsettings);
283
284         &writesecrets();
285
286         &General::log("$Lang::tr{'profile made current'} $pppsettings{'PROFILENAME'}"); 
287 }
288 elsif ($pppsettings{'ACTION'} eq $Lang::tr{'delete'})
289 {
290         &General::log("$Lang::tr{'profile deleted'} $pppsettings{'PROFILENAME'}");
291
292         my $profile = $pppsettings{'PROFILE'};
293         truncate ("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}", 0);
294         
295         %temppppsettings = ();
296         $temppppsettings{'PROFILE'} = '';
297         &General::readhash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
298                 \%temppppsettings);
299
300         # make link.
301         &updatesettings(); 
302
303         # read in the new params "early" so we can write secrets.
304         %pppsettings = ();
305         &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
306         $pppsettings{'PROFILE'} = $profile;
307         &initprofile;
308         &General::writehash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
309                 \%pppsettings);
310 }
311 else
312 {
313         # read in the current vars
314         %pppsettings = ();
315         $pppsettings{'VALID'} = '';
316         &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
317 }
318
319 # read in the profile names into @profilenames.
320 my $c=0;
321 for ($c = 1; $c <= $maxprofiles; $c++)
322 {
323         %temppppsettings = ();
324         $temppppsettings{'PROFILENAME'} = $Lang::tr{'empty'};
325         &General::readhash("${General::swroot}/ppp/settings-$c", \%temppppsettings);
326         $profilenames[$c] = $temppppsettings{'PROFILENAME'};
327 }
328
329 if ($pppsettings{'VALID'} eq '')
330 {
331         if ($pppsettings{'PROFILE'} eq '') {
332                 $pppsettings{'PROFILE'} = '1';
333                 &initprofile();
334         }
335 }
336 for ($c = 1; $c <= $maxprofiles; $c++) {
337         $selected{'PROFILE'}{$c} = ''; }
338 $selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
339 for ($c = 1; $c <= $maxprofiles; $c++) {
340         $selected{'BACKUPPROFILE'}{$c} = ''; }
341 $selected{'BACKUPPROFILE'}{$pppsettings{'BACKUPPROFILE'}} = "selected='selected'";
342
343 $selected{'TYPE'}{'modem'} = '';
344 $selected{'TYPE'}{'serial'} = '';
345 $selected{'TYPE'}{'isdn'} = '';
346 $selected{'TYPE'}{'pppoe'} = '';
347 $selected{'TYPE'}{'pptp'} = '';
348 $selected{'TYPE'}{'alcatelusb'} = '';
349 $selected{'TYPE'}{'alcatelusbk'} = '';
350 $selected{'TYPE'}{'pulsardsl'} = '';
351 $selected{'TYPE'}{'eciadsl'} = '';
352 $selected{'TYPE'}{'fritzdsl'} = '';
353 $selected{'TYPE'}{'bewanadsl'} = '';
354 $selected{'TYPE'}{'eagleusbadsl'} = '';
355 $selected{'TYPE'}{'conexantusbadsl'} = '';
356 $selected{'TYPE'}{'conexantpciadsl'} = '';
357 $selected{'TYPE'}{'amedynusbadsl'} = '';
358 $selected{'TYPE'}{'3cp4218usbadsl'} = '';
359 $selected{'TYPE'}{$pppsettings{'TYPE'}} = "selected='selected'";
360
361 $checked{'DEBUG'}{'off'} = '';
362 $checked{'DEBUG'}{'on'} = '';
363 $checked{'DEBUG'}{$pppsettings{'DEBUG'}} = "checked='checked'";
364
365 $selected{'COMPORT'}{'ttyS0'} = '';
366 $selected{'COMPORT'}{'ttyS1'} = '';
367 $selected{'COMPORT'}{'ttyS2'} = '';
368 $selected{'COMPORT'}{'ttyS3'} = '';
369 $selected{'COMPORT'}{'ttyS4'} = '';
370 $selected{'COMPORT'}{'usb/ttyACM0'} = '';
371 $selected{'COMPORT'}{'usb/ttyACM1'} = '';
372 $selected{'COMPORT'}{'usb/ttyACM2'} = '';
373 $selected{'COMPORT'}{'usb/ttyACM3'} = '';
374 $selected{'COMPORT'}{'isdn1'} = '';
375 $selected{'COMPORT'}{'isdn2'} = '';
376 $selected{'COMPORT'}{$pppsettings{'COMPORT'}} = "selected='selected'";
377
378 $selected{'DTERATE'}{'9600'} = '';
379 $selected{'DTERATE'}{'19200'} = '';
380 $selected{'DTERATE'}{'38400'} = '';
381 $selected{'DTERATE'}{'57600'} = '';
382 $selected{'DTERATE'}{'115200'} = '';
383 $selected{'DTERATE'}{'230400'} = '';
384 $selected{'DTERATE'}{$pppsettings{'DTERATE'}} = "selected='selected'";
385
386 $checked{'SPEAKER'}{'off'} = '';
387 $checked{'SPEAKER'}{'on'} = '';
388 $checked{'SPEAKER'}{$pppsettings{'SPEAKER'}} = "checked='checked'";
389
390 $selected{'DIALMODE'}{'T'} = '';
391 $selected{'DIALMODE'}{'P'} = '';
392 $selected{'DIALMODE'}{$pppsettings{'DIALMODE'}} = "selected='selected'";
393
394 $checked{'RECONNECTION'}{'manual'} = '';
395 $checked{'RECONNECTION'}{'persistent'} = '';
396 $checked{'RECONNECTION'}{'dialondemand'} = '';
397 $checked{'RECONNECTION'}{$pppsettings{'RECONNECTION'}} = "checked='checked'";
398
399 $checked{'DIALONDEMANDDNS'}{'off'} = '';
400 $checked{'DIALONDEMANDDNS'}{'on'} = '';
401 $checked{'DIALONDEMANDDNS'}{$pppsettings{'DIALONDEMANDDNS'}} = "checked='checked'";
402
403 $checked{'AUTOCONNECT'}{'off'} = '';
404 $checked{'AUTOCONNECT'}{'on'} = ''; 
405 $checked{'AUTOCONNECT'}{$pppsettings{'AUTOCONNECT'}} = "checked='checked'";
406
407 $checked{'SENDCR'}{'off'} = '';
408 $checked{'SENDCR'}{'on'} = '';
409 $checked{'SENDCR'}{$pppsettings{'SENDCR'}} = "checked='checked'";
410 $checked{'USEDOV'}{'off'} = '';
411 $checked{'USEDOV'}{'on'} = '';
412 $checked{'USEDOV'}{$pppsettings{'USEDOV'}} = "checked='checked'";
413 $checked{'USEIBOD'}{'off'} = '';
414 $checked{'USEIBOD'}{'on'} = '';
415 $checked{'USEIBOD'}{$pppsettings{'USEIBOD'}} = "checked='checked'";
416
417 $checked{'MODEM'}{'PCIST'} = '';
418 $checked{'MODEM'}{'USB'} = '';
419 $checked{'MODEM'}{$pppsettings{'MODEM'}} = "checked='checked'";
420
421 $selected{'LINE'}{'WO'} = '';
422 $selected{'LINE'}{'ES'} = '';
423 $selected{'LINE'}{'ES03'} = '';
424 $selected{'LINE'}{'FR'} = '';
425 $selected{'LINE'}{'FR04'} = '';
426 $selected{'LINE'}{'FR10'} = '';
427 $selected{'LINE'}{'IT'} = '';
428 $selected{'LINE'}{$pppsettings{'LINE'}} = "selected='selected'";
429
430 $checked{'MODULATION'}{'GDMT'} = '';
431 $checked{'MODULATION'}{'ANSI'} = '';
432 $checked{'MODULATION'}{'GLITE'} = '';
433 $checked{'MODULATION'}{'AUTO'} = '';
434 $checked{'MODULATION'}{$pppsettings{'MODULATION'}} = "checked='checked'";
435
436 $checked{'PROTOCOL'}{'RFC1483'} = '';
437 $checked{'PROTOCOL'}{'RFC2364'} = '';
438 $checked{'PROTOCOL'}{$pppsettings{'PROTOCOL'}} = "checked='checked'";
439
440 $selected{'ENCAP'}{'0'} = '';
441 $selected{'ENCAP'}{'1'} = '';
442 $selected{'ENCAP'}{'2'} = '';
443 $selected{'ENCAP'}{'3'} = '';
444 $selected{'ENCAP'}{'4'} = '';
445 $selected{'ENCAP'}{$pppsettings{'ENCAP'}} = "selected='selected'";
446 $checked{'METHOD'}{'STATIC'} = '';
447 $checked{'METHOD'}{'PPPOE'} = '';
448 $checked{'METHOD'}{'PPPOE_PLUGIN'} = '';
449 $checked{'METHOD'}{'DHCP'} = '';
450 $checked{'METHOD'}{$pppsettings{'METHOD'}} = "checked='checked'";
451
452 $selected{'AUTH'}{'pap-or-chap'} = '';
453 $selected{'AUTH'}{'pap'} = '';
454 $selected{'AUTH'}{'chap'} = '';
455 $selected{'AUTH'}{'standard-login-script'} = '';
456 $selected{'AUTH'}{'demon-login-script'} = '';
457 $selected{'AUTH'}{'other-login-script'} = '';
458 $selected{'AUTH'}{$pppsettings{'AUTH'}} = "selected='selected'";
459
460 $checked{'DNS'}{'Automatic'} = '';
461 $checked{'DNS'}{'Manual'} = '';
462 $checked{'DNS'}{$pppsettings{'DNS'}} = "checked='checked'";
463
464 &Header::openpage($Lang::tr{'ppp setup'}, 1, '');
465
466 &Header::openbigbox('100%', 'left', '', $errormessage);
467
468 if ($errormessage) {
469         &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
470         print "<CLASS name='base'>$errormessage\n";
471         print "&nbsp;</CLASS>\n";
472         &Header::closebox();
473 }
474
475
476 ###
477 ### Box for selecting profile
478 ###
479 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
480 &Header::openbox('100%', 'left', $Lang::tr{'profiles'});
481 print <<END
482 <table width='100%'>
483 <tr>
484         <td align='right'>$Lang::tr{'profile'}:</td>
485         <td>
486         <select name='PROFILE'>
487 END
488 ;
489 for ($c = 1; $c <= $maxprofiles; $c++)
490 {
491         print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
492 }
493 print <<END
494         </select></td>
495         <td><input type='submit' name='ACTION' value='$Lang::tr{'select'}' /></td>
496         <td><input type='submit' name='ACTION' value='$Lang::tr{'delete'}' /></td>
497         <td width='30%'><input type='submit' name='ACTION' value='$Lang::tr{'restore'}' /></td>
498 </tr>
499 </table>
500 END
501 ;
502 &Header::closebox();
503 &Header::openbox('100%', 'left', $Lang::tr{'connection'}.':');
504 print <<END
505 <table width='100%'>
506 <tr>
507         <td align='right'>$Lang::tr{'interface'}:</td>
508         <td>
509         <select name='TYPE'>
510         <option value='modem' $selected{'TYPE'}{'modem'}>$Lang::tr{'modem'}</option>
511         <option value='serial' $selected{'TYPE'}{'serial'}>$Lang::tr{'serial'}</option>
512 END
513 ;
514 if ($isdnsettings{'ENABLED'} eq 'on') {
515         print "\t<option value='isdn' $selected{'TYPE'}{'isdn'}>$Lang::tr{'isdn'}</option>\n";
516 }
517 if ($netsettings{'RED_TYPE'} eq 'PPPOE') {
518         print "\t<option value='pppoe' $selected{'TYPE'}{'pppoe'}>PPPoE</option>\n";
519 }
520 if ($netsettings{'RED_TYPE'} eq 'PPTP') {
521         print "\t<option value='pptp' $selected{'TYPE'}{'pptp'}>PPTP</option>\n";
522 }
523 if (-f "/proc/bus/usb/devices") {
524         print <<END
525         <option value='eciadsl' $selected{'TYPE'}{'eciadsl'}>ECI USB ADSL</option>
526         <option value='eagleusbadsl' $selected{'TYPE'}{'eagleusbadsl'}>Eagle USB ADSL (Acer Allied-Telesyn Comtrend D-Link Sagem USR)</option>
527         <option value='conexantusbadsl' $selected{'TYPE'}{'conexantusbadsl'}>Conexant USB(Aetra Amigo Draytek Etec Mac Olitec Vitelcom Zoom)</option>
528         <option value='amedynusbadsl' $selected{'TYPE'}{'amedynusbadsl'}>Zyxel 630-11 / Asus AAM6000UG USB ADSL</option>
529         <option value='3cp4218usbadsl' $selected{'TYPE'}{'3cp4218usbadsl'}>3Com USB AccessRunner</option>
530         <option value='alcatelusb' $selected{'TYPE'}{'alcatelusb'}>Speedtouch USB ADSL user mode driver</option>
531         <option value='alcatelusbk' $selected{'TYPE'}{'alcatelusbk'}>Speedtouch USB ADSL kernel mode driver</option>
532 END
533 ;
534 }
535         print <<END
536         <option value='fritzdsl' $selected{'TYPE'}{'fritzdsl'}>Fritz!DSL</option>
537         <option value='pulsardsl' $selected{'TYPE'}{'pulsardsl'}>Pulsar ADSL</option>
538         <option value='bewanadsl' $selected{'TYPE'}{'bewanadsl'}>Bewan ADSL PCI st/USB st</option>
539         <option value='conexantpciadsl' $selected{'TYPE'}{'conexantpciadsl'}>Conexant PCI ADSL</option>
540         </select></td>
541         <td width='50%'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /></td>
542         </tr>
543         <tr>
544         <td align='right'>USB:</td>
545 END
546 ;
547 if (-f "/proc/bus/usb/devices") {
548         my $usb=`lsmod | cut -d ' ' -f1 | grep -E "hci"`;
549         if ($usb eq '') {
550                 print "\t<td>$Lang::tr{'not running'}</td></tr>\n";
551         } else {
552                 print "\t<td>$usb</td></tr>\n";
553         }
554 }
555
556 if ($pppsettings{'TYPE'}) {
557         print "</table><table width='100%'>";
558         if ($pppsettings{'TYPE'} =~ /^(modem|serial|isdn)$/) {
559                 print <<END
560 <tr>
561         <td align='right'>$Lang::tr{'interface'}:</td>
562         <td><select name='COMPORT'>
563 END
564 ;
565                 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/ ) {
566                         print <<END
567                 <option value='ttyS0' $selected{'COMPORT'}{'ttyS0'}>$Lang::tr{'modem on com1'}</option>
568                 <option value='ttyS1' $selected{'COMPORT'}{'ttyS1'}>$Lang::tr{'modem on com2'}</option>
569                 <option value='ttyS2' $selected{'COMPORT'}{'ttyS2'}>$Lang::tr{'modem on com3'}</option>
570                 <option value='ttyS3' $selected{'COMPORT'}{'ttyS3'}>$Lang::tr{'modem on com4'}</option>
571                 <option value='ttyS4' $selected{'COMPORT'}{'ttyS4'}>$Lang::tr{'modem on com5'}</option>
572                 <option value='usb/ttyACM0' $selected{'COMPORT'}{'usb/ttyACM0'}>$Lang::tr{'usb modem on acm0'}</option>
573                 <option value='usb/ttyACM1' $selected{'COMPORT'}{'usb/ttyACM1'}>$Lang::tr{'usb modem on acm1'}</option>
574                 <option value='usb/ttyACM2' $selected{'COMPORT'}{'usb/ttyACM2'}>$Lang::tr{'usb modem on acm2'}</option>
575                 <option value='usb/ttyACM3' $selected{'COMPORT'}{'usb/ttyACM3'}>$Lang::tr{'usb modem on acm3'}</option>
576         </select></td>
577 END
578 ;
579                 } elsif ($pppsettings{'TYPE'} eq 'isdn') {
580                         print <<END
581                 <option value='isdn1' $selected{'COMPORT'}{'isdn1'}>$Lang::tr{'isdn1'}</option>
582                 <option value='isdn2' $selected{'COMPORT'}{'isdn2'}>$Lang::tr{'isdn2'}</option>
583         </select></td>
584 END
585 ;
586                 }
587                 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/ ) {
588                         print <<END
589         <td align='right'>$Lang::tr{'computer to modem rate'}</td>
590         <td><select name='DTERATE'>
591                 <option value='9600' $selected{'DTERATE'}{'9600'}>9600</option>
592                 <option value='19200' $selected{'DTERATE'}{'19200'}>19200</option>
593                 <option value='38400' $selected{'DTERATE'}{'38400'}>38400</option>
594                 <option value='57600' $selected{'DTERATE'}{'57600'}>57600</option>
595                 <option value='115200' $selected{'DTERATE'}{'115200'}>115200</option>
596                 <option value='230400' $selected{'DTERATE'}{'230400'}>230400</option>
597         </select></td>
598 </tr>
599 END
600 ;
601                 } else {
602                         print "<td colspan='2'>&nbsp;</td></tr>\n";
603                 }
604                 if ($pppsettings{'TYPE'} =~ /^(modem|isdn)$/ ) {
605                         print "<tr><td align='right'>$Lang::tr{'number'}</td>\n";
606                         print "<td><input type='text' name='TELEPHONE' value='$pppsettings{'TELEPHONE'}' /></td>\n";
607                         if ($pppsettings{'TYPE'} eq 'modem' ) {
608                                 print "<td align='right'>$Lang::tr{'modem speaker on'}</td>\n";
609                                 print "<td><input type='checkbox' name='SPEAKER' $checked{'SPEAKER'}{'on'} /></td></tr>\n";
610                         } else {
611                                 print "<td colspan='2'>&nbsp;</td></tr>\n";
612                         }
613                 }
614         }
615         if ($pppsettings{'TYPE'} eq 'modem') {
616                 print <<END
617 <tr>
618         <td align='right'>$Lang::tr{'dialing mode'}</td>
619         <td><select name='DIALMODE'>
620                 <option value='T' $selected{'DIALMODE'}{'T'}>$Lang::tr{'tone'}</option>
621                 <option value='P' $selected{'DIALMODE'}{'P'}>$Lang::tr{'pulse'}</option>
622         </select></td>
623         <td align='right'>$Lang::tr{'send cr'}</td>
624         <td><input type='checkbox' name='SENDCR' $checked{'SENDCR'}{'on'} /></td>
625 </tr>
626 END
627
628 }
629
630 print <<END
631 <tr>
632         <td align='right'>$Lang::tr{'idle timeout'}</td>
633         <td><input type='text' size='5' name='TIMEOUT' value='$pppsettings{'TIMEOUT'}' /></td>
634         <td colspan='2'>&nbsp;</td>
635 </tr>
636 END
637 ;
638         if ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && ( $netsettings{'RED_TYPE'} eq "DHCP" || $netsettings{'RED_TYPE'} eq "STATIC") ) {
639                 $pppsettings{'AUTOCONNECT'} = 'on';
640                 print "<tr><td align='right'>$Lang::tr{'connect on ipfire restart'}</td>\n";
641                 print "<td><input type='checkbox' disabled='disabled' name='AUTOCONNECT' value='on' $checked{'AUTOCONNECT'}{'on'} /></td>\n";
642         } else {
643                 print "<tr><td align='right'>$Lang::tr{'connect on ipfire restart'}</td>\n";
644                 print "<td><input type='checkbox' name='AUTOCONNECT' value='on' $checked{'AUTOCONNECT'}{'on'} /></td>\n";
645         }
646 print <<END
647         <td align='right'>$Lang::tr{'connection debugging'}:</td>
648         <td><input type='checkbox' name='DEBUG' $checked{'DEBUG'}{'on'} /></td>
649 </tr>
650 <tr>
651         <td colspan='5'><br /><hr /><b>$Lang::tr{'reconnection'}:</b></td>
652 </tr>
653 <tr>
654         <td colspan='4'>
655                 <input type='radio' name='RECONNECTION' value='manual' $checked{'RECONNECTION'}{'manual'} />$Lang::tr{'manual'}</td>
656 </tr>
657 END
658 ;
659 if ($pppsettings{'TYPE'} ne 'isdn') {
660 print <<END
661 <tr>
662         <td>
663                 <input type='radio' name='RECONNECTION' value='persistent' $checked{'RECONNECTION'}{'persistent'} />$Lang::tr{'persistent'}</td>
664         <td colspan='2' align='right'>$Lang::tr{'backupprofile'}:</td>
665         <td>
666         <select name='BACKUPPROFILE'>
667 END
668 ;
669         for ($c = 1; $c <= $maxprofiles; $c++) {
670                 print "\t<option value='$c' $selected{'BACKUPPROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
671         }
672         print <<END
673         </select></td>
674 </tr>
675 END
676 ;
677 }
678 print <<END
679 <tr>
680         <td>
681                 <input type='radio' name='RECONNECTION' value='dialondemand' $checked{'RECONNECTION'}{'dialondemand'} />$Lang::tr{'dod'}</td>
682         <td colspan='2' align='right'>$Lang::tr{'dod for dns'}</td>
683         <td><input type='checkbox' name='DIALONDEMANDDNS' $checked{'DIALONDEMANDDNS'}{'on'} /></td>
684
685 </tr>
686 <tr>
687         <td align='right'>$Lang::tr{'holdoff'}:</td>
688         <td><input type='text' size='5' name='HOLDOFF' value='$pppsettings{'HOLDOFF'}' /></td>
689         <td align='right'>$Lang::tr{'maximum retries'}</td>
690         <td><input type='text' size='5' name='MAXRETRIES' value='$pppsettings{'MAXRETRIES'}' /></td>
691 </tr>
692 END
693 ;
694
695 if ($pppsettings{'TYPE'} eq 'isdn') {
696         print <<END
697 </table>
698 <table width='100%'>
699 <tr>
700         <td colspan='5'><br /><hr /><b>$Lang::tr{'isdn settings'}</b></td>
701 </tr>
702 <tr>
703         <td align='right'>$Lang::tr{'use ibod'}</td>
704         <td><input type='checkbox' name='USEIBOD' $checked{'USEIBOD'}{'on'} /></td>
705         <td align='right'>$Lang::tr{'use dov'}</td>
706         <td><input type='checkbox' name='USEDOV' $checked{'USEDOV'}{'on'} /></td>
707 </tr>
708 END
709 ;
710 }
711
712 if ($pppsettings{'TYPE'} eq 'pptp')
713 {
714 print <<END
715 </table>
716
717 <table width='100%'>
718 <tr>
719         <td colspan='5'><br /><hr /><b>$Lang::tr{'pptp settings'}</b></td>
720 </tr>
721 <tr>
722         <td colspan='2' align='right'>$Lang::tr{'phonebook entry'}</td>
723         <td><input type='text' name='PHONEBOOK' value='$pppsettings{'PHONEBOOK'}' /></td>
724 </tr>
725 <tr>
726         <td><input type='radio' name='METHOD' value='STATIC' $checked{'METHOD'}{'STATIC'} />$Lang::tr{'static ip'}</td>
727         <td align='right'>$Lang::tr{'router ip'}</td>
728         <td><input type='text' name='ROUTERIP' value='$pppsettings{'ROUTERIP'}' /></td>
729 </tr>
730 <tr>
731         <td>&nbsp;</td>
732         <td colspan='3'><hr /></td>
733 </tr>
734 <tr>
735         <td><input type='radio' name='METHOD' value='DHCP' $checked{'METHOD'}{'DHCP'} />$Lang::tr{'dhcp mode'}</td>
736         <td align='right'>$Lang::tr{'hostname'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
737         <td><input type='text' name='DHCP_HOSTNAME' value='$pppsettings{'DHCP_HOSTNAME'}' /></td>
738 </tr>
739 END
740 ;
741 }
742 if ($pppsettings{'TYPE'} eq 'pppoe')
743 {
744 print <<END
745 </table>
746 <table width='100%'>
747 <tr>
748         <td colspan='5'><br /><hr /><b>$Lang::tr{'pppoe settings'}</b></td>
749 </tr>
750 END
751 ;
752 }
753 if ($pppsettings{'TYPE'} =~ /^(alcatelusb|alcatelusbk|amedynusbadsl|conexantusbadsl|conexantpciadsl|3cp4218usbadsl|pulsardsl|eciadsl|fritzdsl|bewanadsl|eagleusbadsl)$/)
754 {
755
756 print <<END
757 </table>
758 <table width='100%'>
759 <tr>
760         <td colspan='5'><br /><hr /><b>$Lang::tr{'adsl settings'}:</b></td>
761 </tr>
762 <tr>
763         <td nowrap='nowrap' align='right'>$Lang::tr{'vpi number'}</td>
764         <td><input type='text' size='5' name='VPI' value='$pppsettings{'VPI'}' /></td>
765         <td align='right'>$Lang::tr{'vci number'}</td>
766         <td colspan='2'><input type='text' size='5' name='VCI' value='$pppsettings{'VCI'}' /></td>
767 </tr>
768 <tr>
769         <td>&nbsp;</td>
770         <td colspan='4'><hr /></td>
771 </tr>
772 END
773 ;
774 }
775 if ($pppsettings{'TYPE'} eq 'bewanadsl')
776 {
777 print <<END
778 <tr>
779         <td align='right'>$Lang::tr{'modem'}:</td>
780         <td colspan='2' nowrap='nowrap'>
781                 <input type='radio' name='MODEM' value='PCIST' $checked{'MODEM'}{'PCIST'} />Bewan ADSL PCI st</td>
782         <td colspan='2'><input type='radio' name='MODEM' value='USB' $checked{'MODEM'}{'USB'} />Bewan ADSL USB st</td>
783 </tr>
784 <tr>
785         <td>&nbsp;</td>
786         <td colspan='4'><hr /></td>
787 </tr>
788 END
789 ;
790 }
791 if ($pppsettings{'TYPE'} =~ /^(3cp4218usbadsl|bewanadsl)$/)
792 {
793 print <<END
794 <tr>
795         <td align='right'>$Lang::tr{'modulation'}:</td>
796         <td><input type='radio' name='MODULATION' value='AUTO' $checked{'MODULATION'}{'AUTO'} />$Lang::tr{'automatic'}</td>
797         <td><input type='radio' name='MODULATION' value='ANSI' $checked{'MODULATION'}{'ANSI'} />ANSI T1.483</td>
798         <td><input type='radio' name='MODULATION' value='GDMT' $checked{'MODULATION'}{'GDMT'} />G.DMT</td>
799         <td><input type='radio' name='MODULATION' value='GLITE' $checked{'MODULATION'}{'GLITE'} />G.Lite</td>
800 </tr>
801 <tr>
802         <td>&nbsp;</td>
803         <td colspan='4'><hr /></td>
804 </tr>
805 END
806 ;
807 }
808
809 if ($pppsettings{'TYPE'} eq 'eagleusbadsl')
810 {
811 print <<END
812 <tr>
813         <td align='right'>$Lang::tr{'country'}:</td>
814         <td>
815         <select name='LINE'>
816         <option value='WO' $selected{'LINE'}{'WO'}>$Lang::tr{'other countries'}</option>
817         <option value='ES' $selected{'LINE'}{'ES'}>ESPANA</option>
818         <option value='ES03' $selected{'LINE'}{'ES03'}>ESPANA03</option>
819         <option value='FR' $selected{'LINE'}{'FR'}>FRANCE</option>
820         <option value='FR04' $selected{'LINE'}{'FR04'}>FRANCE04</option>
821         <option value='FR10' $selected{'LINE'}{'FR04'}>FRANCE10</option>
822         <option value='IT' $selected{'LINE'}{'IT'}>ITALIA</option>
823         </select></td>
824 </tr>
825 <tr>
826         <td>&nbsp;</td>
827         <td colspan='4'><hr /></td>
828 </tr>
829 END
830 ;
831 }
832 if ($pppsettings{'TYPE'} eq 'eciadsl')
833 {
834 print <<END
835 <tr>
836         <td align='right'>$Lang::tr{'modem'}:</td>
837         <td colspan='5'>
838                 <select name='MODEM'>
839 END
840 ;
841                 open (MODEMS, "/etc/eciadsl/modems.db") or die 'Unable to open modems database.';
842                 while (my $line = <MODEMS>) {
843                         $line =~ /^([\S\ ]+).*$/;
844                         my $modem = $1;
845                         $modem =~ s/^\s*(.*?)\s*$/$1/;
846                         print "<option value='$modem'";
847                         if ($pppsettings{'MODEM'} =~ /$modem/) { print " selected";}
848                         print ">$modem</option>\n";
849                 }
850                 close (MODEMS);
851
852 print <<END
853                 </select>
854         </td>
855 </tr>
856 <tr>
857         <td>&nbsp;</td>
858         <td colspan='4'><hr /></td>
859 </tr>
860 END
861 ;
862 }
863 if ($pppsettings{'TYPE'} =~ /^(alcatelusb|alcatelusbk|amedynusbadsl|conexantusbadsl|conexantpciadsl|3cp4218usbadsl|pulsardsl|eciadsl|fritzdsl|bewanadsl|eagleusbadsl)$/)
864 {
865 print <<END
866 <tr>
867         <td valign='top' align='right'>$Lang::tr{'protocol'}:</td>
868         <td nowrap='nowrap'>
869                 <input type='radio' name='PROTOCOL' value='RFC2364' $checked{'PROTOCOL'}{'RFC2364'} />RFC2364 PPPoA</td>
870 END
871 ;
872 }
873 if ($pppsettings{'TYPE'} eq 'alcatelusb')
874 {
875         print "<td colspan=3>&nbsp;</td></tr>";
876 }
877
878 if ($pppsettings{'TYPE'} =~ /^(alcatelusbk|amedynusbadsl|conexantusbadsl|conexantpciadsl|3cp4218usbadsl|pulsardsl|eciadsl|bewanadsl|eagleusbadsl|fritzdsl)$/)
879 {
880 print <<END
881         <td align='right'>$Lang::tr{'encapsulation'}:</td>
882         <td colspan='2' width='30%'>
883                 <select name='ENCAP_RFC2364'>
884                 <option value='0' $selected{'ENCAP'}{'0'}>VCmux</option>
885                 <option value='1' $selected{'ENCAP'}{'1'}>LLC</option>
886                 </select>
887         </td>
888 </tr>
889 END
890 ;
891 }
892 if ($pppsettings{'TYPE'} =~ /^(alcatelusb|alcatelusbk|amedynusbadsl|conexantusbadsl|conexantpciadsl|3cp4218usbadsl|pulsardsl|eciadsl|fritzdsl|bewanadsl|eagleusbadsl)$/)
893 {
894 print <<END
895 <tr>
896         <td>&nbsp;</td>
897         <td colspan='4'><hr /></td>
898 </tr>
899 <tr>
900         <td>&nbsp;</td>
901         <td valign='top'>
902                 <input type='radio' name='PROTOCOL' value='RFC1483' $checked{'PROTOCOL'}{'RFC1483'} />RFC 1483 / 2684</td>
903 END
904 ;
905 }
906 if ($pppsettings{'TYPE'} eq 'alcatelusb')
907 {
908         print "<td colspan='3'>&nbsp;</td></tr>";
909 }
910
911 if ($pppsettings{'TYPE'} =~ /^(alcatelusbk|amedynusbadsl|conexantusbadsl|conexantpciadsl|3cp4218usbadsl|pulsardsl|eciadsl|bewanadsl|eagleusbadsl|fritzdsl)$/)
912 {
913         if ($pppsettings{'TYPE'} ne 'fritzdsl')
914         {
915 print <<END
916         <td align='right'>$Lang::tr{'encapsulation'}:</td>
917         <td colspan='2'>
918                 <select name='ENCAP_RFC1483'>
919                 <option value='0' $selected{'ENCAP'}{'0'}>BRIDGED_ETH_LLC</option>
920                 <option value='1' $selected{'ENCAP'}{'1'}>BRIDGED_ETH_VC</option>
921                 <option value='2' $selected{'ENCAP'}{'2'}>ROUTED_IP_LLC</option>
922                 <option value='3' $selected{'ENCAP'}{'3'}>ROUTED_IP_VC</option>
923                 </select>
924         </td>
925 </tr>
926 <tr>
927         <td colspan='2'>&nbsp;</td>
928         <td colspan='3'><hr /></td>
929 </tr>
930 END
931 ;
932         } else {
933 print <<END
934         <td colspan='4'>PPPoE</td>
935 </tr>
936 END
937 ;
938         }
939 }
940 if ($pppsettings{'TYPE'} =~ /^(pppoe|alcatelusb|alcatelusbk|amedynusbadsl|conexantusbadsl|conexantpciadsl|3cp4218usbadsl|pulsardsl|eciadsl|bewanadsl|eagleusbadsl)$/)
941 {
942 print <<END
943 <tr>
944         <td>&nbsp;</td>
945         <td>&nbsp;</td>
946         <td><input type='radio' name='METHOD' value='PPPOE_PLUGIN' $checked{'METHOD'}{'PPPOE_PLUGIN'} />PPPoE plugin</td>
947         <td align='right'>$Lang::tr{'service name'}&nbsp;<img src='/blob.gif' alt='*' /></td>
948         <td><input type='text' name='SERVICENAME' value='$pppsettings{'SERVICENAME'}' /></td>
949 </tr>
950 <tr>
951         <td>&nbsp;</td>
952         <td>&nbsp;</td>
953         <td><input type='radio' name='METHOD' value='PPPOE' $checked{'METHOD'}{'PPPOE'} />$Lang::tr{'pppoe'}</td>
954         <td align='right'>$Lang::tr{'concentrator name'}&nbsp;<img src='/blob.gif' alt='*' /></td>
955         <td><input type='text' name='CONCENTRATORNAME' value='$pppsettings{'CONCENTRATORNAME'}' /></td>
956 </tr>
957
958 END
959 ;
960 }
961 if ($pppsettings{'TYPE'} =~ /^(alcatelusbk|amedynusbadsl|conexantusbadsl|conexantpciadsl|3cp4218usbadsl|pulsardsl|eciadsl|bewanadsl|eagleusbadsl)$/)
962 {
963 print <<END
964 <tr>
965         <td colspan='2'>&nbsp;</td>
966         <td colspan='3'><hr /></td>
967 </tr>
968 <tr>
969         <td>&nbsp;</td>
970         <td>&nbsp;</td>
971         <td rowspan='4'><input type='radio' name='METHOD' value='STATIC' $checked{'METHOD'}{'STATIC'} />$Lang::tr{'static ip'}</td>
972         <td align='right'>$Lang::tr{'static ip'}:</td>
973         <td><input type='text' size='16' name='IP' value='$pppsettings{'IP'}' /></td>
974 </tr>
975 <tr>
976         <td>&nbsp;</td>
977         <td>&nbsp;</td>
978         <td align='right'>$Lang::tr{'gateway ip'}:</td>
979         <td><input type='text' size='16' name='GATEWAY' value='$pppsettings{'GATEWAY'}' /></td>
980 </tr>
981 <tr>
982         <td>&nbsp;</td>
983         <td>&nbsp;</td>
984         <td align='right'>$Lang::tr{'netmask'}:</td>
985         <td><input type='text' size='16' name='NETMASK' value='$pppsettings{'NETMASK'}' /></td>
986 </tr>
987 <tr>
988         <td>&nbsp;</td>
989         <td>&nbsp;</td>
990         <td align='right' nowrap='nowrap'>$Lang::tr{'broadcast'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
991         <td><input type='text' size='16' name='BROADCAST' value='$pppsettings{'BROADCAST'}' /></td>
992 </tr>
993 END
994 ;
995         if ($pppsettings{'TYPE'} =~ /^(eciadsl|eagleusbadsl)$/)
996         {
997 print <<END
998 <tr>
999         <td colspan='2'>&nbsp;</td>
1000         <td colspan='3'><hr /></td>
1001 </tr>
1002 <tr>
1003         <td>&nbsp;</td>
1004         <td>&nbsp;</td>
1005         <td><input type='radio' name='METHOD' value='DHCP' $checked{'METHOD'}{'DHCP'} />$Lang::tr{'dhcp mode'}</td>
1006         <td align='right'>$Lang::tr{'hostname'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1007         <td><input type='text' name='DHCP_HOSTNAME' value='$pppsettings{'DHCP_HOSTNAME'}' /></td>
1008 </tr>
1009 END
1010 ;
1011         }
1012 }
1013 if ($pppsettings{'TYPE'} =~ /^(alcatelusb|alcatelusbk|eciadsl|fritzdsl)$/) {
1014         print "<tr><td>&nbsp;</td><td colspan='4'><hr /></td></tr>";
1015 }
1016 if ($pppsettings{'TYPE'} =~ /^(alcatelusb|alcatelusbk)$/) {
1017         my $speedtouch = &Header::speedtouchversion;
1018         if (($speedtouch >= 0) && ($speedtouch <=4)) {
1019                 my $modem;
1020                 if ($speedtouch ==4) { $modem='v4_b'; } else { $modem='v0123'; }
1021                 print "<tr><td align='right'>$Lang::tr{'firmware'}:</td>";
1022                 if (-e "${General::swroot}/alcatelusb/firmware.$modem.bin") {
1023                         print "<td>$Lang::tr{'present'}</td><td colspan='3'>&nbsp;</td></tr>\n";
1024                 } else {
1025                         print "<td>$Lang::tr{'not present'}</td><td colspan='3'>&nbsp;</td></tr>\n";
1026                 }
1027         } else {
1028                 print "<tr><td colspan='5'>$Lang::tr{'unknown'} Rev $speedtouch</td></tr>";
1029         }
1030 } elsif ($pppsettings{'TYPE'} eq 'eciadsl') {
1031         print "<tr><td align='right'>$Lang::tr{'driver'}:</td>";
1032         if (-e "${General::swroot}/eciadsl/synch.bin") {
1033                 print "<td>$Lang::tr{'present'}</td><td colspan='3'>&nbsp;</td></tr>\n";
1034         } else {
1035                 print "<td>$Lang::tr{'not present'}</td><td colspan='3'>&nbsp;</td></tr>\n"; }
1036 } elsif ($pppsettings{'TYPE'} eq 'fritzdsl') {
1037         print "<tr><td align='right'>$Lang::tr{'driver'}:</td>";
1038         if (-e "/lib/modules/$kernel/misc/fcdslusb.o.gz") {
1039                 print "<td>$Lang::tr{'present'}</td><td colspan='3'>&nbsp;</td></tr>\n";
1040         } else {
1041                 print "<td>$Lang::tr{'not present'}</td><td colspan='3'>&nbsp;</td></tr>\n"; }
1042 }
1043 print <<END
1044 </table>
1045 <table width='100%'>
1046 <tr>
1047         <td colspan='5'><br /><hr /><b>$Lang::tr{'authentication'}</b></td>
1048 </tr>
1049 <tr>
1050         <td align='right'>$Lang::tr{'username'}</td>
1051         <td><input type='text' name='USERNAME' value='$pppsettings{'USERNAME'}' /></td>
1052         <td align='right'>$Lang::tr{'password'}</td>
1053         <td><input type='password' name='PASSWORD' value='$pppsettings{'PASSWORD'}' /></td>
1054 </tr>
1055 <tr>
1056         <td align='right'>$Lang::tr{'method'}</td>
1057         <td><select name='AUTH'>
1058                 <option value='pap-or-chap' $selected{'AUTH'}{'pap-or-chap'}>$Lang::tr{'pap or chap'}</option>
1059                 <option value='pap' $selected{'AUTH'}{'pap'}>PAP</option>
1060                 <option value='chap' $selected{'AUTH'}{'chap'}>CHAP</option>
1061 END
1062 ;
1063 if ($pppsettings{'TYPE'} eq 'modem') {
1064 print <<END
1065                 <option value='standard-login-script' $selected{'AUTH'}{'standard-login-script'}>$Lang::tr{'standard login script'}</option>
1066                 <option value='demon-login-script' $selected{'AUTH'}{'demon-login-script'}>$Lang::tr{'demon login script'}</option>
1067                 <option value='other-login-script' $selected{'AUTH'}{'other-login-script'}>$Lang::tr{'other login script'}</option>
1068 END
1069 ;
1070 }
1071 print <<END
1072         </select></td>
1073         <td align='right'>$Lang::tr{'script name'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1074         <td nowrap='nowrap'><input type='text' name='LOGINSCRIPT' value='$pppsettings{'LOGINSCRIPT'}' /></td>
1075 </tr>
1076 </table>
1077 <table width='100%'>
1078 <tr>
1079         <td colspan='5'><br /><hr /><b>DNS:</b></td>
1080 </tr>
1081 <tr>
1082         <td colspan='5'><input type='radio' name='DNS' value='Automatic' $checked{'DNS'}{'Automatic'} />$Lang::tr{'automatic'}</td>
1083 </tr>
1084 <tr>
1085         <td><input type='radio' name='DNS' value='Manual' $checked{'DNS'}{'Manual'} />$Lang::tr{'manual'}</td>
1086         <td align='right'>$Lang::tr{'primary dns'}</td>
1087         <td><input type='text' size='16' name='DNS1' value='$pppsettings{'DNS1'}' /></td>
1088         <td align='right'>$Lang::tr{'secondary dns'}</td>
1089         <td><input type='text' size='16' name='DNS2' value='$pppsettings{'DNS2'}' /></td>
1090 </tr>
1091 <tr>
1092         <td colspan='5'><br /><hr /></td>
1093 </tr>
1094 <tr>
1095         <td>&nbsp;</td>
1096         <td align='right'>$Lang::tr{'profile name'}</td>
1097         <td><input type='text' name='PROFILENAME' value='$pppsettings{'PROFILENAME'}' /></td>
1098         <td><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
1099 </tr>
1100 <tr>
1101         <td colspan='5'><br /><hr /></td>
1102 </tr>
1103 <tr>
1104         <td align='right'>$Lang::tr{'legend'}:</td>
1105         <td><img src='/blob.gif' alt='*' />&nbsp;$Lang::tr{'this field may be blank'}</td>
1106 </tr>
1107 </table>
1108 END
1109 ;
1110 &Header::closebox();
1111 }
1112
1113 print "</form>\n";
1114
1115 &Header::closebigbox();
1116
1117 &Header::closepage();
1118
1119 sub updatesettings
1120 {
1121         # make a link from the selected profile to the "default" one.
1122         unlink("${General::swroot}/ppp/settings");
1123         link("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
1124                 "${General::swroot}/ppp/settings");
1125         system ("/bin/touch", "${General::swroot}/ppp/updatesettings");
1126         if ($pppsettings{'TYPE'} eq 'eagleusbadsl') {
1127                 # eagle-usb.conf is in backup but link DSPcode.bin can't, so the link is created in rc.eagleusbadsl
1128                 open(FILE, ">/${General::swroot}/eagle-usb/eagle-usb.conf") or die "Unable to write eagle-usb.conf file";
1129                 flock(FILE, 2);
1130                 # decimal to hexa
1131                 $modemsettings{'VPI'} = uc(sprintf('%X', $pppsettings{'VPI'}));
1132                 $modemsettings{'VCI'} = uc(sprintf('%X', $pppsettings{'VCI'}));
1133                 if( $pppsettings{'PROTOCOL'} eq 'RFC1483') {
1134                         $modemsettings{'Encapsulation'} =1+$pppsettings{'ENCAP'}
1135                 } elsif ( $pppsettings{'PROTOCOL'} eq 'RFC2364') {
1136                         $modemsettings{'Encapsulation'} =6-$pppsettings{'ENCAP'}
1137                 }
1138                 print FILE "<eaglectrl>\n";
1139                 print FILE "VPI=$modemsettings{'VPI'}\n";
1140                 print FILE "VCI=$modemsettings{'VCI'}\n";
1141                 print FILE "Encapsulation=$modemsettings{'Encapsulation'}\n";
1142                 print FILE "Linetype=0A\n";
1143                 print FILE "RatePollFreq=00000009\n";
1144                 print FILE "</eaglectrl>\n";
1145                 close FILE;
1146         }
1147 }
1148
1149 sub writesecrets
1150 {
1151         # write secrets file.
1152         open(FILE, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file.";
1153         flock(FILE, 2);
1154         my $username = $pppsettings{'USERNAME'};
1155         my $password = $pppsettings{'PASSWORD'};
1156         print FILE "'$username' * '$password'\n";
1157         chmod 0600, "${General::swroot}/ppp/secrets";
1158         close FILE;
1159 }
1160
1161 sub initprofile
1162 {
1163         $pppsettings{'PROFILENAME'} = $Lang::tr{'unnamed'};
1164         $pppsettings{'COMPORT'} = 'ttyS0';
1165         $pppsettings{'DTERATE'} = 115200;
1166         $pppsettings{'SPEAKER'} = 'off';
1167         $pppsettings{'RECONNECTION'} = 'manual';
1168         $pppsettings{'DIALONDEMANDDNS'} = 'off';
1169         $pppsettings{'AUTOCONNECT'} = 'off';
1170         $pppsettings{'SENDCR'} = 'off';
1171         $pppsettings{'USEIBOD'} = 'off';
1172         $pppsettings{'USEDOV'} = 'off';
1173         $pppsettings{'MODEM'} = 'PCIST';
1174         $pppsettings{'LINE'} = 'WO';
1175         $pppsettings{'ENCAP'} = '0';
1176         $pppsettings{'PHONEBOOK'} = 'RELAY_PPP1';
1177         $pppsettings{'PROTOCOL'} = 'RFC2364';
1178         $pppsettings{'METHOD'} = 'PPPOE_PLUGIN';
1179         $pppsettings{'DIALMODE'} = 'T';
1180         $pppsettings{'MAXRETRIES'} = 5;
1181         $pppsettings{'HOLDOFF'} = 30;
1182         $pppsettings{'TIMEOUT'} = 15;
1183         $pppsettings{'MODULATION'} = 'AUTO';
1184         $pppsettings{'AUTH'} = 'pap-or-chap';
1185         $pppsettings{'DNS'} = 'Automatic';
1186         $pppsettings{'DEBUG'} = 'off';
1187         $pppsettings{'BACKUPPROFILE'} = $pppsettings{'PROFILE'};
1188
1189         # Get ISDN settings so we can see if ISDN is enabled or not.
1190         $isdnsettings{'ENABLED'} = 'off';
1191         &General::readhash("${General::swroot}/isdn/settings", \%isdnsettings);
1192         
1193         # Get PPPoE settings so we can see if PPPoE is enabled or not.
1194         &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
1195
1196         # empty profile partial pre-initialization
1197         if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) {
1198                 $pppsettings{'TYPE'}=lc($netsettings{'RED_TYPE'});
1199         } elsif ($isdnsettings{'ENABLED'} eq 'on') {
1200                 $pppsettings{'TYPE'}='isdn';
1201         } else {
1202                 $pppsettings{'TYPE'}='modem';
1203         }
1204 }
1205