Merge branch 'master' of ssh://arne_f@git.ipfire.org/pub/git/ipfire-2.x
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / pppsetup.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 use strict;
23
24 # enable only the following on debugging purpose
25 #use warnings;
26 #use CGI::Carp 'fatalsToBrowser';
27
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31
32 our %pppsettings=();
33 my %temppppsettings=();
34 our %modemsettings=();
35 our %isdnsettings=();
36 our %netsettings=();
37 my %selected=();
38 my %checked=();
39 my @profilenames=();
40 my $errormessage = '';
41 my $maxprofiles = 5;
42 my $kernel=`/bin/uname -r | /usr/bin/tr -d '\012'`;
43
44 my %color = ();
45 my %mainsettings = ();
46 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
47 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
48
49 &Header::showhttpheaders();
50
51 $pppsettings{'ACTION'} = '';
52 &initprofile();
53 &Header::getcgihash(\%pppsettings);
54
55 if ($pppsettings{'ACTION'} ne '' &&
56 (-e '/var/run/ppp-ipcop.pid' || -e "${General::swroot}/red/active"))
57 {
58 $errormessage = $Lang::tr{'unable to alter profiles while red is active'};
59 # read in the current vars
60 %pppsettings = ();
61 $pppsettings{'VALID'} = '';
62 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
63 }
64 elsif ($pppsettings{'ACTION'} eq $Lang::tr{'refresh'})
65 {
66 unless ($pppsettings{'TYPE'} =~ /^(modem|serial|isdn|pppoe|pptp|pppoeatm|pptpatm)$/) {
67 $errormessage = $Lang::tr{'invalid input'};
68 goto ERROR; }
69 my $type = $pppsettings{'TYPE'};
70 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
71 $pppsettings{'TYPE'} = $type;
72 }
73 elsif ($pppsettings{'ACTION'} eq $Lang::tr{'save'})
74 {
75 if ($pppsettings{'TYPE'} =~ /^(modem|serial|isdn)$/ && $pppsettings{'COMPORT'} !~ /^(ttyS0|ttyS1|ttyS2|ttyS3|ttyS4|ttyACM0|ttyACM1|ttyACM2|ttyACM3|ttyUSB0|ttyUSB1|ttyUSB2|ttyUSB3|rfcomm0|rfcomm1|isdn1|isdn2)$/) {
76 $errormessage = $Lang::tr{'invalid input'};
77 goto ERROR; }
78 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/ && $pppsettings{'DTERATE'} !~ /^(9600|19200|38400|57600|115200|230400|460800|921600)$/) {
79 $errormessage = $Lang::tr{'invalid input'};
80 goto ERROR; }
81 if ($pppsettings{'TYPE'} eq 'modem' && $pppsettings{'DIALMODE'} !~ /^(T|P)$/) {
82 $errormessage = $Lang::tr{'invalid input'};
83 goto ERROR; }
84 if ($pppsettings{'AUTH'} !~ /^(pap-or-chap|pap|chap|standard-login-script|demon-login-script|other-login-script)$/) {
85 $errormessage = $Lang::tr{'invalid input'};
86 goto ERROR;
87 }
88
89 if ($pppsettings{'PROFILENAME'} eq '') {
90 $errormessage = $Lang::tr{'profile name not given'};
91 $pppsettings{'PROFILENAME'} = '';
92 goto ERROR; }
93 if ($pppsettings{'TYPE'} =~ /^(modem|isdn)$/) {
94 if ($pppsettings{'TELEPHONE'} eq '') {
95 $errormessage = $Lang::tr{'telephone not set'};
96 goto ERROR; }
97 if (!($pppsettings{'TELEPHONE'} =~ /^[\d\*\#\,]+$/)) {
98 $errormessage = $Lang::tr{'bad characters in the telephone number field'};
99 goto ERROR; }
100 }
101 unless (($pppsettings{'PROTOCOL'} eq 'RFC1483' && $pppsettings{'METHOD'} =~ /^(STATIC|DHCP)$/)) {
102 if ($pppsettings{'USERNAME'} eq '') {
103 $errormessage = $Lang::tr{'username not set'};
104 goto ERROR; }
105 if ($pppsettings{'PASSWORD'} eq '') {
106 $errormessage = $Lang::tr{'password not set'};
107 goto ERROR; }
108 }
109
110 if ($pppsettings{'TIMEOUT'} eq '') {
111 $errormessage = $Lang::tr{'idle timeout not set'};
112 goto ERROR; }
113 if (!($pppsettings{'TIMEOUT'} =~ /^\d+$/)) {
114 $errormessage = $Lang::tr{'only digits allowed in the idle timeout'};
115 goto ERROR; }
116
117 if ($pppsettings{'LOGINSCRIPT'} =~ /[.\/ ]/ ) {
118 $errormessage = $Lang::tr{'bad characters in script field'};
119 goto ERROR; }
120
121 if ($pppsettings{'DNS1'})
122 {
123 if (!(&General::validip($pppsettings{'DNS1'}))) {
124 $errormessage = $Lang::tr{'invalid primary dns'};
125 goto ERROR; }
126 }
127 if ($pppsettings{'DNS2'})
128 {
129 if (!(&General::validip($pppsettings{'DNS2'}))) {
130 $errormessage = $Lang::tr{'invalid secondary dns'};
131 goto ERROR; }
132 }
133
134 if ($pppsettings{'MAXRETRIES'} eq '') {
135 $errormessage = $Lang::tr{'max retries not set'};
136 goto ERROR; }
137 if (!($pppsettings{'MAXRETRIES'} =~ /^\d+$/)) {
138 $errormessage = $Lang::tr{'only digits allowed in max retries field'};
139 goto ERROR; }
140
141 if (!($pppsettings{'HOLDOFF'} =~ /^\d+$/)) {
142 $errormessage = $Lang::tr{'only digits allowed in holdoff field'};
143 goto ERROR; }
144
145 if ($pppsettings{'TYPE'} =~ /^(pppoeatm|pptpatm)$/) {
146 if ( ($pppsettings{'VPI'} eq '') || ($pppsettings{'VCI'} eq '') ) {
147 $errormessage = $Lang::tr{'invalid vpi vpci'};
148 goto ERROR; }
149 if ( (!($pppsettings{'VPI'} =~ /^\d+$/)) || (!($pppsettings{'VCI'} =~ /^\d+$/)) ) {
150 $errormessage = $Lang::tr{'invalid vpi vpci'};
151 goto ERROR; }
152 if (($pppsettings{'VPI'} eq '0') && ($pppsettings{'VCI'} eq '0')) {
153 $errormessage = $Lang::tr{'invalid vpi vpci'};
154 goto ERROR; }
155 if ( $pppsettings{'PROTOCOL'} eq '' ) {
156 $errormessage = $Lang::tr{'invalid input'};
157 goto ERROR; }
158 }
159
160 if ( ($pppsettings{'PROTOCOL'} eq 'RFC1483') && ($pppsettings{'METHOD'} eq '') && \
161 ($pppsettings{'TYPE'} !~ /^(alcatelusb|fritzdsl)$/)) {
162 $errormessage = $Lang::tr{'invalid input'};
163 goto ERROR; }
164
165 if (($pppsettings{'PROTOCOL'} eq 'RFC1483' && $pppsettings{'METHOD'} eq 'DHCP')) {
166 if ($pppsettings{'DHCP_HOSTNAME'} ne '') {
167 if (! &General::validfqdn($pppsettings{'DHCP_HOSTNAME'})) {
168 $errormessage = $errormessage.' '.$Lang::tr{'hostname'}.': '.$Lang::tr{'invalid hostname'}; }
169 }
170 }
171
172 if (($pppsettings{'PROTOCOL'} eq 'RFC1483' && $pppsettings{'METHOD'} eq 'STATIC')) {
173 $errormessage = '';
174 if (! &General::validip($pppsettings{'IP'})) {
175 $errormessage = $Lang::tr{'static ip'}.' '.$Lang::tr{'invalid ip'}; }
176 if (! &General::validip($pppsettings{'GATEWAY'})) {
177 $errormessage = $errormessage.' '.$Lang::tr{'gateway ip'}.' '.$Lang::tr{'invalid ip'}; }
178 if (! &General::validmask($pppsettings{'NETMASK'})) {
179 $errormessage = $errormessage.' '.$Lang::tr{'netmask'}.' '.$Lang::tr{'invalid netmask'}; }
180 if ($pppsettings{'BROADCAST'} ne '') {
181 if (! &General::validip($pppsettings{'BROADCAST'})) {
182 $errormessage = $errormessage.' '.$Lang::tr{'broadcast'}.' '.$Lang::tr{'invalid broadcast ip'}; }
183 }
184 if( $pppsettings{'DNS'} eq 'Automatic') {
185 $errormessage = $Lang::tr{'invalid input'}; }
186 if ($errormessage ne '') {goto ERROR; }
187 }
188
189 if( $pppsettings{'PROTOCOL'} eq 'RFC1483' && $pppsettings{'METHOD'} ne 'PPPOE' && \
190 $pppsettings{'RECONNECTION'} eq 'dialondemand' ) {
191 $errormessage = $Lang::tr{'invalid input'};
192 goto ERROR; }
193
194 if( $pppsettings{'RECONNECTION'} eq 'dialondemand' && `/bin/cat ${General::swroot}/ddns/config` =~ /,on$/m ) {
195 $errormessage = $Lang::tr{'dod not compatible with ddns'};
196 goto ERROR; }
197
198 # if( $pppsettings{'PROTOCOL'} eq 'RFC1483') {
199 # $pppsettings{'ENCAP'} = $pppsettings{'ENCAP_RFC1483'}; }
200 # if( $pppsettings{'PROTOCOL'} eq 'RFC2364') {
201 # $pppsettings{'ENCAP'} = $pppsettings{'ENCAP_RFC2364'}; }
202 delete $pppsettings{'ENCAP_RFC1483'};
203 delete $pppsettings{'ENCAP_RFC2364'};
204
205 ERROR:
206 if ($errormessage) {
207 $pppsettings{'VALID'} = 'no'; }
208 else {
209 $pppsettings{'VALID'} = 'yes'; }
210
211 # write cgi vars to the file.
212 &General::writehash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
213 \%pppsettings);
214
215 # make link and write secret file.
216 &updatesettings();
217 &writesecrets();
218
219 &General::log("$Lang::tr{'profile saved'} $pppsettings{'PROFILENAME'}");
220 }
221 if ($pppsettings{'ACTION'} eq $Lang::tr{'select'})
222 {
223 my $profile = $pppsettings{'PROFILE'};
224 %temppppsettings = ();
225 $temppppsettings{'PROFILE'} = '';
226 &General::readhash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
227 \%temppppsettings);
228
229 # make link.
230 &updatesettings();
231
232 # read in the new params "early" so we can write secrets.
233 %pppsettings = ();
234 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
235 $pppsettings{'PROFILE'} = $profile;
236 &General::writehash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
237 \%pppsettings);
238
239 &writesecrets();
240
241 &General::log("$Lang::tr{'profile made current'} $pppsettings{'PROFILENAME'}");
242 }
243 elsif ($pppsettings{'ACTION'} eq $Lang::tr{'delete'})
244 {
245 &General::log("$Lang::tr{'profile deleted'} $pppsettings{'PROFILENAME'}");
246
247 my $profile = $pppsettings{'PROFILE'};
248 truncate ("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}", 0);
249
250 %temppppsettings = ();
251 $temppppsettings{'PROFILE'} = '';
252 &General::readhash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
253 \%temppppsettings);
254
255 # make link.
256 &updatesettings();
257
258 # read in the new params "early" so we can write secrets.
259 %pppsettings = ();
260 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
261 $pppsettings{'PROFILE'} = $profile;
262 &initprofile;
263 &General::writehash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
264 \%pppsettings);
265 }
266 elsif ($pppsettings{'ACTION'} eq $Lang::tr{'refresh'})
267 {
268 }
269 else
270 {
271 # read in the current vars
272 %pppsettings = ();
273 $pppsettings{'VALID'} = '';
274 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
275 }
276
277 # read in the profile names into @profilenames.
278 my $c=0;
279 for ($c = 1; $c <= $maxprofiles; $c++)
280 {
281 %temppppsettings = ();
282 $temppppsettings{'PROFILENAME'} = $Lang::tr{'empty profile'};
283 &General::readhash("${General::swroot}/ppp/settings-$c", \%temppppsettings);
284 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
285 }
286
287 if ($pppsettings{'VALID'} eq '')
288 {
289 if ($pppsettings{'PROFILE'} eq '') {
290 $pppsettings{'PROFILE'} = '1';
291 &initprofile();
292 }
293 }
294 for ($c = 1; $c <= $maxprofiles; $c++) {
295 $selected{'PROFILE'}{$c} = ''; }
296 $selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
297 for ($c = 1; $c <= $maxprofiles; $c++) {
298 $selected{'BACKUPPROFILE'}{$c} = ''; }
299 $selected{'BACKUPPROFILE'}{$pppsettings{'BACKUPPROFILE'}} = "selected='selected'";
300
301 $selected{'TYPE'}{'modem'} = '';
302 $selected{'TYPE'}{'serial'} = '';
303 $selected{'TYPE'}{'pppoe'} = '';
304 $selected{'TYPE'}{'pptp'} = '';
305 $selected{'TYPE'}{'pppoeatm'} = '';
306 $selected{'TYPE'}{'pptpatm'} = '';
307 $selected{'TYPE'}{$pppsettings{'TYPE'}} = "selected='selected'";
308 $checked{'DEBUG'}{'off'} = '';
309 $checked{'DEBUG'}{'on'} = '';
310 $checked{'DEBUG'}{$pppsettings{'DEBUG'}} = "checked='checked'";
311
312 $selected{'COMPORT'}{'ttyS0'} = '';
313 $selected{'COMPORT'}{'ttyS1'} = '';
314 $selected{'COMPORT'}{'ttyS2'} = '';
315 $selected{'COMPORT'}{'ttyS3'} = '';
316 $selected{'COMPORT'}{'ttyS4'} = '';
317 $selected{'COMPORT'}{'ttyACM0'} = '';
318 $selected{'COMPORT'}{'ttyACM1'} = '';
319 $selected{'COMPORT'}{'ttyACM2'} = '';
320 $selected{'COMPORT'}{'ttyACM3'} = '';
321 $selected{'COMPORT'}{'ttyUSB0'} = '';
322 $selected{'COMPORT'}{'ttyUSB1'} = '';
323 $selected{'COMPORT'}{'ttyUSB2'} = '';
324 $selected{'COMPORT'}{'ttyUSB3'} = '';
325 $selected{'COMPORT'}{'rfcomm0'} = '';
326 $selected{'COMPORT'}{'rfcomm1'} = '';
327 $selected{'COMPORT'}{$pppsettings{'COMPORT'}} = "selected='selected'";
328
329 $selected{'DTERATE'}{'9600'} = '';
330 $selected{'DTERATE'}{'19200'} = '';
331 $selected{'DTERATE'}{'38400'} = '';
332 $selected{'DTERATE'}{'57600'} = '';
333 $selected{'DTERATE'}{'115200'} = '';
334 $selected{'DTERATE'}{'230400'} = '';
335 $selected{'DTERATE'}{'460800'} = '';
336 $selected{'DTERATE'}{'921600'} = '';
337 $selected{'DTERATE'}{$pppsettings{'DTERATE'}} = "selected='selected'";
338
339 $checked{'SPEAKER'}{'off'} = '';
340 $checked{'SPEAKER'}{'on'} = '';
341 $checked{'SPEAKER'}{$pppsettings{'SPEAKER'}} = "checked='checked'";
342
343 $selected{'DIALMODE'}{'T'} = '';
344 $selected{'DIALMODE'}{'P'} = '';
345 $selected{'DIALMODE'}{$pppsettings{'DIALMODE'}} = "selected='selected'";
346
347 $checked{'RECONNECTION'}{'persistent'} = '';
348 $checked{'RECONNECTION'}{'dialondemand'} = '';
349 $checked{'RECONNECTION'}{$pppsettings{'RECONNECTION'}} = "checked='checked'";
350
351 $checked{'DIALONDEMANDDNS'}{'off'} = '';
352 $checked{'DIALONDEMANDDNS'}{'on'} = '';
353 $checked{'DIALONDEMANDDNS'}{$pppsettings{'DIALONDEMANDDNS'}} = "checked='checked'";
354
355 $checked{'AUTOCONNECT'}{'off'} = '';
356 $checked{'AUTOCONNECT'}{'on'} = '';
357 $checked{'AUTOCONNECT'}{$pppsettings{'AUTOCONNECT'}} = "checked='checked'";
358
359 $checked{'SENDCR'}{'off'} = '';
360 $checked{'SENDCR'}{'on'} = '';
361 $checked{'SENDCR'}{$pppsettings{'SENDCR'}} = "checked='checked'";
362 $checked{'USEDOV'}{'off'} = '';
363 $checked{'USEDOV'}{'on'} = '';
364 $checked{'USEDOV'}{$pppsettings{'USEDOV'}} = "checked='checked'";
365
366 $checked{'MODEM'}{'PCIST'} = '';
367 $checked{'MODEM'}{'USB'} = '';
368 $checked{'MODEM'}{$pppsettings{'MODEM'}} = "checked='checked'";
369
370 $selected{'LINE'}{'WO'} = '';
371 $selected{'LINE'}{'ES'} = '';
372 $selected{'LINE'}{'ES03'} = '';
373 $selected{'LINE'}{'FR'} = '';
374 $selected{'LINE'}{'FR04'} = '';
375 $selected{'LINE'}{'FR10'} = '';
376 $selected{'LINE'}{'IT'} = '';
377 $selected{'LINE'}{$pppsettings{'LINE'}} = "selected='selected'";
378
379 $checked{'MODULATION'}{'GDMT'} = '';
380 $checked{'MODULATION'}{'ANSI'} = '';
381 $checked{'MODULATION'}{'GLITE'} = '';
382 $checked{'MODULATION'}{'AUTO'} = '';
383 $checked{'MODULATION'}{$pppsettings{'MODULATION'}} = "checked='checked'";
384
385 $checked{'PROTOCOL'}{'RFC1483'} = '';
386 $checked{'PROTOCOL'}{'RFC2364'} = '';
387 $checked{'PROTOCOL'}{$pppsettings{'PROTOCOL'}} = "checked='checked'";
388
389 $selected{'ENCAP'}{'0'} = '';
390 $selected{'ENCAP'}{'1'} = '';
391 #$selected{'ENCAP'}{'2'} = '';
392 #$selected{'ENCAP'}{'3'} = '';
393 #$selected{'ENCAP'}{'4'} = '';
394 $selected{'ENCAP'}{$pppsettings{'ENCAP'}} = "selected='selected'";
395
396 $checked{'METHOD'}{'STATIC'} = '';
397 $checked{'METHOD'}{'PPPOE'} = '';
398 $checked{'METHOD'}{'PPPOE_PLUGIN'} = '';
399 $checked{'METHOD'}{'DHCP'} = '';
400 $checked{'METHOD'}{$pppsettings{'METHOD'}} = "checked='checked'";
401
402 $selected{'AUTH'}{'pap-or-chap'} = '';
403 $selected{'AUTH'}{'pap'} = '';
404 $selected{'AUTH'}{'chap'} = '';
405 $selected{'AUTH'}{'standard-login-script'} = '';
406 $selected{'AUTH'}{'demon-login-script'} = '';
407 $selected{'AUTH'}{'other-login-script'} = '';
408 $selected{'AUTH'}{$pppsettings{'AUTH'}} = "selected='selected'";
409
410 $checked{'DNS'}{'Automatic'} = '';
411 $checked{'DNS'}{'Manual'} = '';
412 $checked{'DNS'}{$pppsettings{'DNS'}} = "checked='checked'";
413
414 &Header::openpage($Lang::tr{'ppp setup'}, 1, '');
415 &Header::openbigbox('100%', 'left', '', $errormessage);
416
417 if ($netsettings{'RED_TYPE'} ne 'PPPOE') {
418 $errormessage = $Lang::tr{'dialup red not ppp'};
419 &Header::openbox('100%', 'center', $Lang::tr{'error messages'});
420 print "<CLASS name='base'>$errormessage\n";
421 print "&nbsp;</CLASS>\n";
422 &Header::closebox();
423 &Header::closebigbox();
424
425 &Header::closepage();
426 exit(1);
427 }
428
429 if ($errormessage) {
430 &Header::openbox('100%', 'center', $Lang::tr{'error messages'});
431 print "<CLASS name='base'>$errormessage\n";
432 print "&nbsp;</CLASS>\n";
433 &Header::closebox();
434 }
435
436
437 ###
438 ### Box for selecting profile
439 ###
440 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
441 &Header::openbox('100%', 'center', $Lang::tr{'profile'});
442 print <<END
443 <table width='95%' cellspacing='0'>
444 <tr>
445 <td align='left'>$Lang::tr{'profile'}</td>
446 <td align='left'>
447 <select name='PROFILE' style="width: 165px">
448 END
449 ;
450 for ($c = 1; $c <= $maxprofiles; $c++)
451 {
452 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
453 }
454 print <<END
455 </select></td>
456 <td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'select'}' /></td>
457 <td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'delete'}' /></td>
458 <td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'restore'}' /></td>
459 </tr>
460 </table>
461 <br></br>
462 <hr></hr>
463 END
464 ;
465
466 &Header::closebox();
467 &Header::openbox('100%', 'center', $Lang::tr{'connection'});
468
469 print <<END
470 <table width='95%' cellspacing='0'>
471 <tr>
472 <td width='25%'>$Lang::tr{'interface'}:</td>
473 <td width='25%'>
474 <select name='TYPE' style="width: 165px">
475 END
476 ;
477 if ($netsettings{'RED_TYPE'} eq 'PPPOE') {
478 print <<END
479 <option value='modem' $selected{'TYPE'}{'modem'}>$Lang::tr{'modem'}</option>
480 <option value='serial' $selected{'TYPE'}{'serial'}>$Lang::tr{'serial'}</option>
481 <option value='pppoe' $selected{'TYPE'}{'pppoe'}>PPPoE</option>
482 <option value='pptp' $selected{'TYPE'}{'pptp'}>PPTP</option>
483 END
484 ;
485
486 my $atmdev=`cat /proc/net/atm/devices | grep 0`;
487 chomp ($atmdev);
488 if ($atmdev ne '') {
489 print <<END
490 <option value='pppoeatm' $selected{'TYPE'}{'pppoeatm'}>PPPoE over ATM-BRIDGE</option>
491 <option value='pptpatm' $selected{'TYPE'}{'pptpatm'}>PPTP over ATM-BRIDGE</option>
492 END
493 ;
494 }
495 }
496 #if (0) {
497 # print <<END
498 # <option value='eciadsl' $selected{'TYPE'}{'eciadsl'}>ECI USB ADSL</option>
499 # <option value='eagleusbadsl' $selected{'TYPE'}{'eagleusbadsl'}>Eagle USB ADSL (Acer Allied-Telesyn Comtrend D-Link Sagem USR)</option>
500 # <option value='conexantusbadsl' $selected{'TYPE'}{'conexantusbadsl'}>Conexant USB(Aetra Amigo Draytek Etec Mac Olitec Vitelcom Zoom)</option>
501 # <option value='amedynusbadsl' $selected{'TYPE'}{'amedynusbadsl'}>Zyxel 630-11 / Asus AAM6000UG USB ADSL</option>
502 # <option value='3cp4218usbadsl' $selected{'TYPE'}{'3cp4218usbadsl'}>3Com USB AccessRunner</option>
503 # <option value='alcatelusb' $selected{'TYPE'}{'alcatelusb'}>Speedtouch USB ADSL user mode driver</option>
504 # <option value='alcatelusbk' $selected{'TYPE'}{'alcatelusbk'}>Speedtouch USB ADSL kernel mode driver</option>
505 #END
506 #;
507 #}
508 # print "<option value='fritzdsl' $selected{'TYPE'}{'fritzdsl'}>Fritz!DSL</option>";
509
510 print <<END
511 </select></td>
512 <td colspan='1' width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}'></td>
513 END
514 ;
515 if ($pppsettings{'TYPE'} =~ /^(modem)$/) {
516 print <<END
517 <td colspan='1' width='25%'><A HREF=modem.cgi>$Lang::tr{'modem configuration'}</A></td>
518 END
519 ;
520 }
521
522 print "</tr>";
523
524 #if (-f "/proc/bus/usb/devices") {
525 # <td colspan='2' width='50%'>USB:</td>
526 # my $usb=`lsmod | cut -d ' ' -f1 | grep -E "hci"`;
527 # if ($usb eq '') {
528 # print "\t<td colspan='2' width='50%'>$Lang::tr{'not running'}</td></tr>\n";
529 # } else {
530 # print "\t<td colspan='2' width='50%'>$usb</td></tr>\n";
531 # }
532 #}
533
534 if ($pppsettings{'TYPE'}) {
535 print "<tr><td colspan='4' width='100%'><br></br></td></tr>";
536
537 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/) {
538 print <<END
539
540 <tr>
541 <td colspan='3' width='75%'>$Lang::tr{'interface'}:</td>
542 <td width='25%'><select name='COMPORT' style="width: 165px">
543 END
544 ;
545 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/ ) {
546 print <<END
547 <option value='ttyS0' $selected{'COMPORT'}{'ttyS0'}>COM1</option>
548 <option value='ttyS1' $selected{'COMPORT'}{'ttyS1'}>COM2</option>
549 <option value='ttyS2' $selected{'COMPORT'}{'ttyS2'}>COM3</option>
550 <option value='ttyS3' $selected{'COMPORT'}{'ttyS3'}>COM4</option>
551 <option value='ttyS4' $selected{'COMPORT'}{'ttyS4'}>COM5</option>
552 <option value='ttyUSB0' $selected{'COMPORT'}{'ttyUSB0'}>ttyUSB0</option>
553 <option value='ttyUSB1' $selected{'COMPORT'}{'ttyUSB1'}>ttyUSB1</option>
554 <option value='ttyUSB2' $selected{'COMPORT'}{'ttyUSB2'}>ttyUSB2</option>
555 <option value='ttyUSB3' $selected{'COMPORT'}{'ttyUSB3'}>ttyUSB3</option>
556 <option value='rfcomm0' $selected{'COMPORT'}{'rfcomm0'}>rfcomm0 (bluetooth)</option>
557 <option value='rfcomm1' $selected{'COMPORT'}{'rfcomm1'}>rfcomm1 (bluetooth)</option>
558 END
559 ;
560 if ($pppsettings{'TYPE'} ne 'serial' ) {
561 print <<END
562 <option value='ttyACM0' $selected{'COMPORT'}{'ttyACM0'}>$Lang::tr{'usb modem on acm0'}</option>
563 <option value='ttyACM1' $selected{'COMPORT'}{'ttyACM1'}>$Lang::tr{'usb modem on acm1'}</option>
564 <option value='ttyACM2' $selected{'COMPORT'}{'ttyACM2'}>$Lang::tr{'usb modem on acm2'}</option>
565 <option value='ttyACM3' $selected{'COMPORT'}{'ttyACM3'}>$Lang::tr{'usb modem on acm3'}</option>
566 END
567 ;
568 }
569 print "</select></td> "}
570 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/ ) {
571 print <<END
572 <tr>
573 <td colspan='3' width='75%'>$Lang::tr{'computer to modem rate'}</td>
574 <td width='25%'><select name='DTERATE' style="width: 165px">
575 <option value='9600' $selected{'DTERATE'}{'9600'}>9600</option>
576 <option value='19200' $selected{'DTERATE'}{'19200'}>19200</option>
577 <option value='38400' $selected{'DTERATE'}{'38400'}>38400</option>
578 <option value='57600' $selected{'DTERATE'}{'57600'}>57600</option>
579 <option value='115200' $selected{'DTERATE'}{'115200'}>115200</option>
580 <option value='230400' $selected{'DTERATE'}{'230400'}>230400</option>
581 <option value='460800' $selected{'DTERATE'}{'460800'}>460800</option>
582 <option value='921600' $selected{'DTERATE'}{'921600'}>921600</option>
583 </select></td>
584 </tr>
585 END
586 ;
587 }
588 if ($pppsettings{'TYPE'} =~ /^(modem)$/ ) {
589 print "<tr><td colspan='3' width='75%'>$Lang::tr{'number'}</td>\n";
590 print "<td width='25%'><input type='text' name='TELEPHONE' value='$pppsettings{'TELEPHONE'}'></td><tr>\n";
591 if ($pppsettings{'TYPE'} eq 'modem' ) {
592 print "<tr><td colspan='3' width='75%'>$Lang::tr{'modem speaker on'}</td>\n";
593 print "<td width='25%'><input type='checkbox' name='SPEAKER' $checked{'SPEAKER'}{'on'} /></td></tr>\n";
594 }
595 }
596 }
597 if ($pppsettings{'TYPE'} eq 'modem') {
598 print <<END
599 <tr>
600 <td colspan='3' width='75%'>$Lang::tr{'dialing mode'}</td>
601 <td width='25%'><select name='DIALMODE' style="width: 165px">
602 <option value='T' $selected{'DIALMODE'}{'T'}>$Lang::tr{'tone'}</option>
603 <option value='P' $selected{'DIALMODE'}{'P'}>$Lang::tr{'pulse'}</option>
604 </select></td>
605 </tr>
606 <tr>
607 <td colspan='3' width='75%'>$Lang::tr{'optional at cmd'}&nbsp;1&nbsp;<img src='/blob.gif' alt='*' /></td>
608 <td width='25%'><input type='text' name='ADD_AT1' value='$pppsettings{'ADD_AT1'}'></td>
609 </tr>
610 <tr>
611 <td colspan='3' width='75%'>$Lang::tr{'optional at cmd'}&nbsp;2&nbsp;<img src='/blob.gif' alt='*' /></td>
612 <td width='25%'><input type='text' name='ADD_AT2' value='$pppsettings{'ADD_AT2'}'></td>
613 </tr>
614 <tr>
615 <td colspan='3' width='75%'>$Lang::tr{'optional at cmd'}&nbsp;3&nbsp;<img src='/blob.gif' alt='*' /></td>
616 <td width='25%'><input type='text' name='ADD_AT3' value='$pppsettings{'ADD_AT3'}'></td>
617 </tr>
618 <tr>
619 <td colspan='3' width='75%'>$Lang::tr{'send cr'}</td>
620 <td width='50%'><input type='checkbox' name='SENDCR' $checked{'SENDCR'}{'on'} /></td>
621 </tr>
622 END
623 ;
624 }
625
626 print <<END
627 <tr>
628 <td colspan='3' width='75%'>$Lang::tr{'idle timeout'}</td>
629 <td width='25%'><input type='text' name='TIMEOUT' value='$pppsettings{'TIMEOUT'}' /></td>
630 </tr>
631 <tr>
632 <td colspan='3' width='75%'>$Lang::tr{'connection debugging'}:</td>
633 <td width='25%'><input type='checkbox' name='DEBUG' $checked{'DEBUG'}{'on'} /></td>
634 </tr>
635 <tr>
636 <td colspan='4' width='100%'><br></br></td></tr>
637 <tr>
638 <td colspan='4' width='100%' bgcolor='$color{'color20'}'><b>$Lang::tr{'reconnection'}:</b></td>
639 </tr>
640 <tr>
641 <td colspan='4' width='100%'><input type='radio' name='RECONNECTION' value='dialondemand' $checked{'RECONNECTION'}{'dialondemand'}>$Lang::tr{'dod'}</td>
642 </tr>
643 END
644 ;
645 if ($pppsettings{'TYPE'} ne 'isdn') {
646 print <<END
647 <tr>
648 <td colspan='4' width='100%'><input type='radio' name='RECONNECTION' value='persistent' $checked{'RECONNECTION'}{'persistent'}>$Lang::tr{'persistent'}</td>
649 </tr>
650 <tr>
651 <td colspan='3' width='75%'>$Lang::tr{'backupprofile'}:</td>
652 <td width='25%'><select name='BACKUPPROFILE' style="width: 165px">
653 END
654 ;
655 for ($c = 1; $c <= $maxprofiles; $c++) {
656 print "\t<option value='$c' $selected{'BACKUPPROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
657 }
658 print <<END
659 </select></td>
660 </tr>
661 END
662 ;
663 }
664 print <<END
665 <tr>
666 <td colspan='3' width='75%'>$Lang::tr{'dod for dns'}</td>
667 <td width='25%'><input type='checkbox' name='DIALONDEMANDDNS' $checked{'DIALONDEMANDDNS'}{'on'} /></td>
668 </tr>
669 <tr>
670 <td colspan='3' width='75%'>$Lang::tr{'holdoff'}:</td>
671 <td width='25%'><input type='text' name='HOLDOFF' value='$pppsettings{'HOLDOFF'}' /></td>
672 </tr>
673 <tr>
674 <td colspan='3' width='75%'>$Lang::tr{'maximum retries'}</td>
675 <td width='25%'><input type='text' name='MAXRETRIES' value='$pppsettings{'MAXRETRIES'}' /></td>
676 </tr>
677 END
678 ;
679
680 if ($pppsettings{'TYPE'} eq 'pptp')
681 {
682
683 print <<END
684 <tr><td colspan='4' width='100%'><br></br></td></tr>
685 <tr>
686 <td colspan='4' width='100%' bgcolor='$color{'color20'}'><b>$Lang::tr{'pptp settings'}</b></td>
687 </tr>
688 <tr>
689 <td width='25%'>Peer</td>
690 <td colspan='3'><input size=50 type='text' name='PPTP_PEER' value='$pppsettings{'PPTP_PEER'}' /></td>
691 </tr>
692 <tr>
693 <td width='25%'>My Netconfig</td>
694 <td colspan='3'><input size=50 type='text' name='PPTP_NICCFG' value='$pppsettings{'PPTP_NICCFG'}' /></td>
695 </tr>
696 END
697 ;
698 }
699
700 if ($pppsettings{'TYPE'} =~ /^(pppoeatm|pptpatm)$/)
701 {
702
703 print <<END
704 <tr>
705 <td colspan='4' width='100%' bgcolor='$color{'color20'}'><b>$Lang::tr{'adsl settings'}:</b></td>
706 <tr>
707
708 <td> $Lang::tr{'encapsulation'}:</td>
709 <td colspan='2' width='30%'>
710 <select name='ENCAP'>
711 <option value='0' $selected{'ENCAP'}{'0'}>LLC</option>
712 <option value='1' $selected{'ENCAP'}{'1'}>VCmux</option>
713 </select>
714 </td>
715 </tr>
716 <tr>
717
718 <td nowrap='nowrap'>$Lang::tr{'vpi number'}</td>
719 <td><input type='text' size='5' name='VPI' value='$pppsettings{'VPI'}' /></td>
720 <td align='right'>$Lang::tr{'vci number'}</td>
721 <td colspan='2'><input type='text' size='5' name='VCI' value='$pppsettings{'VCI'}' /></td>
722 </tr>
723 END
724 ;
725 }
726
727
728 if ($pppsettings{'TYPE'} eq 'pppoe' || $pppsettings{'TYPE'} eq 'pppoeatm')
729 {
730 print <<END
731 <tr><td colspan='4' width='100%'><br></br></td></tr>
732 <tr>
733 <td colspan='4' width='100%' bgcolor='$color{'color20'}'><b>$Lang::tr{'pppoe settings'}</b></td>
734 </tr>
735 <tr>
736 <td width='25%'><input type='radio' name='METHOD' value='PPPOE_PLUGIN' $checked{'METHOD'}{'PPPOE_PLUGIN'} />PPPoE plugin</td>
737 <td colspan='2' width='50%'>$Lang::tr{'service name'}&nbsp;<img src='/blob.gif' alt='*' /></td>
738 <td width='25%'><input type='text' name='SERVICENAME' value='$pppsettings{'SERVICENAME'}' /></td>
739 </tr>
740 <tr>
741 <td width='25%'><input type='radio' name='METHOD' value='PPPOE' $checked{'METHOD'}{'PPPOE'} />$Lang::tr{'pppoe'}</td>
742 <td colspan='2' width='50%'>$Lang::tr{'concentrator name'}&nbsp;<img src='/blob.gif' alt='*' /></td>
743 <td width='25%'><input type='text' name='CONCENTRATORNAME' value='$pppsettings{'CONCENTRATORNAME'}' /></td>
744 </tr>
745 <tr>
746 <td width='25%'>MTU</td>
747 <td colspan='2' width='50%'></td>
748 <td width='25%'><input type='text' name='MTU' value='$pppsettings{'MTU'}' /></td>
749 </tr>
750 END
751 ;
752 }
753
754 print <<END
755 <tr><td colspan='4' width='100%'><br></br></td></tr>
756 <tr>
757 <td bgcolor='$color{'color20'}' colspan='4' width='100%'><b>$Lang::tr{'authentication'}</b></td>
758 </tr>
759 <tr>
760 <td width='25%'>$Lang::tr{'username'}</td>
761 <td width='25%'><input type='text' name='USERNAME' value='$pppsettings{'USERNAME'}' /></td>
762 <td width='25%'>$Lang::tr{'password'}</td>
763 <td width='25%'><input type='password' name='PASSWORD' value='$pppsettings{'PASSWORD'}' /></td>
764 </tr>
765 <tr>
766 <td width='25%'>$Lang::tr{'method'}</td>
767 <td width='25%'><select name='AUTH' style="width: 165px">
768 <option value='pap-or-chap' $selected{'AUTH'}{'pap-or-chap'}>$Lang::tr{'pap or chap'}</option>
769 <option value='pap' $selected{'AUTH'}{'pap'}>PAP</option>
770 <option value='chap' $selected{'AUTH'}{'chap'}>CHAP</option>
771 END
772 ;
773 if ($pppsettings{'TYPE'} eq 'modem') {
774 print <<END
775 <option value='standard-login-script' $selected{'AUTH'}{'standard-login-script'}>$Lang::tr{'standard login script'}</option>
776 <option value='demon-login-script' $selected{'AUTH'}{'demon-login-script'}>$Lang::tr{'demon login script'}</option>
777 <option value='other-login-script' $selected{'AUTH'}{'other-login-script'}>$Lang::tr{'other login script'}</option>
778 END
779 ;
780 }
781 print <<END
782 </select></td>
783 <td width='25%'>$Lang::tr{'script name'}&nbsp;<img src='/blob.gif' alt='*' /></td>
784 <td width='25%'><input type='text' name='LOGINSCRIPT' value='$pppsettings{'LOGINSCRIPT'}' /></td>
785 </tr>
786 <tr><td colspan='4' width='100%'><br></br></td></tr>
787 <tr>
788 <td bgcolor='$color{'color20'}' colspan='4' width='100%'><b>DNS:</b></td>
789 </tr>
790 <tr>
791 <td colspan='4' width='100%'><input type='radio' name='DNS' value='Automatic' $checked{'DNS'}{'Automatic'} />$Lang::tr{'automatic'}</td>
792 </tr>
793 <tr>
794 <td colspan='4' width='100%'><input type='radio' name='DNS' value='Manual' $checked{'DNS'}{'Manual'} />$Lang::tr{'manual'}</td>
795 </tr>
796 <tr>
797 <td width='25%'>$Lang::tr{'primary dns'}</td>
798 <td width='25%'><input type='text' name='DNS1' value='$pppsettings{'DNS1'}'></td>
799 <td width='25%'>$Lang::tr{'secondary dns'}</td>
800 <td width='25%'><input type='text' name='DNS2' value='$pppsettings{'DNS2'}'></td>
801 </tr>
802 <tr><td colspan='4' width='100%'><br></br><hr></hr><br></br></td></tr>
803 <tr>
804 <td width='25%'>$Lang::tr{'profile name'}</td>
805 <td width='25%'><input type='text' name='PROFILENAME' value='$pppsettings{'PROFILENAME'}'>
806 <td colspan='2' width='50%'></td>
807 </tr>
808 <tr>
809 <td align='center' colspan='4' width='100%'><input type='submit' name='ACTION' value='$Lang::tr{'save'}'></td>
810 </tr>
811 <tr>
812 <td colspan='2' width='50%'>$Lang::tr{'legend'}:</td>
813 <td colspan='2' width='50%'><img src='/blob.gif' alt='*' />&nbsp;$Lang::tr{'this field may be blank'}</td>
814 </tr>
815 </table>
816 END
817 ;
818 &Header::closebox();
819 }
820
821 print "</form>\n";
822
823 &Header::closebigbox();
824
825 &Header::closepage();
826
827 sub updatesettings
828 {
829 # make a link from the selected profile to the "default" one.
830 unlink("${General::swroot}/ppp/settings");
831 link("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
832 "${General::swroot}/ppp/settings");
833 system ("/usr/bin/touch", "${General::swroot}/ppp/updatesettings");
834 }
835
836 sub writesecrets
837 {
838 # write secrets file.
839 open(FILE, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file.";
840 flock(FILE, 2);
841 my $username = $pppsettings{'USERNAME'};
842 my $password = $pppsettings{'PASSWORD'};
843 print FILE "'$username' * '$password'\n";
844 chmod 0600, "${General::swroot}/ppp/secrets";
845 close FILE;
846 }
847
848 sub initprofile
849 {
850 $pppsettings{'PROFILENAME'} = $Lang::tr{'unnamed'};
851 $pppsettings{'COMPORT'} = 'ttyS0';
852 $pppsettings{'DTERATE'} = 115200;
853 $pppsettings{'SPEAKER'} = 'off';
854 $pppsettings{'RECONNECTION'} = 'persistent';
855 $pppsettings{'DIALONDEMANDDNS'} = 'off';
856 $pppsettings{'AUTOCONNECT'} = 'on';
857 $pppsettings{'SENDCR'} = 'off';
858 $pppsettings{'USEIBOD'} = 'off';
859 $pppsettings{'USEDOV'} = 'off';
860 $pppsettings{'MODEM'} = 'PCIST';
861 $pppsettings{'LINE'} = 'WO';
862 $pppsettings{'ENCAP'} = '0';
863 $pppsettings{'VPI'} = '1';
864 $pppsettings{'VCI'} = '32';
865 $pppsettings{'PPTP_PEER'} = '10.0.0.138';
866 $pppsettings{'PPTP_NICCFG'} = '10.0.0.140/24 broadcast 10.0.0.255';
867 $pppsettings{'PROTOCOL'} = 'RFC2364';
868 $pppsettings{'METHOD'} = 'PPPOE_PLUGIN';
869 if ( $pppsettings{'METHOD'} eq 'PPPOE_PLUGIN' ) {
870 $pppsettings{'MTU'} = '1492';
871 $pppsettings{'MRU'} = '1492';
872 } else {
873 $pppsettings{'MTU'} = '1452';
874 $pppsettings{'MRU'} = '1452';
875 }
876 $pppsettings{'DIALMODE'} = 'T';
877 $pppsettings{'MAXRETRIES'} = 5;
878 $pppsettings{'HOLDOFF'} = 30;
879 $pppsettings{'TIMEOUT'} = 15;
880 $pppsettings{'MODULATION'} = 'AUTO';
881 $pppsettings{'AUTH'} = 'pap-or-chap';
882 $pppsettings{'DNS'} = 'Automatic';
883 $pppsettings{'DEBUG'} = 'off';
884 $pppsettings{'BACKUPPROFILE'} = $pppsettings{'PROFILE'};
885
886 # Get PPPoE settings so we can see if PPPoE is enabled or not.
887 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
888
889 # empty profile partial pre-initialization
890 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) {
891 $pppsettings{'TYPE'}=lc($netsettings{'RED_TYPE'});
892 } else {
893 $pppsettings{'TYPE'}='modem';
894 }
895 }
896