]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/pppsetup.cgi
Add additional AT-Commands to ppp settings. (eg. for GPRS/UMTS init)
[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)$/) {
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'} eq 'pptp') {
146 $errormessage = '';
147 if ($pppsettings{'METHOD'} eq 'STATIC') {
148 if (! &General::validip($pppsettings{'ROUTERIP'})) {
149 $errormessage = $Lang::tr{'router ip'}.' '.$Lang::tr{'invalid ip'};
150 }
151 } else {
152 if (($pppsettings{'DHCP_HOSTNAME'} ne '') && (! &General::validfqdn($pppsettings{'DHCP_HOSTNAME'})) ) {
153 $errormessage = $errormessage.' '.$Lang::tr{'hostname'}.' '.$Lang::tr{'invalid hostname'};
154 }
155 }
156 if ($errormessage ne '') {goto ERROR; }
157 }
158 if ($pppsettings{'TYPE'} =~ /^(pppoeatm)$/) {
159 if ( ($pppsettings{'VPI'} eq '') || ($pppsettings{'VCI'} eq '') ) {
160 $errormessage = $Lang::tr{'invalid vpi vpci'};
161 goto ERROR; }
162 if ( (!($pppsettings{'VPI'} =~ /^\d+$/)) || (!($pppsettings{'VCI'} =~ /^\d+$/)) ) {
163 $errormessage = $Lang::tr{'invalid vpi vpci'};
164 goto ERROR; }
165 if (($pppsettings{'VPI'} eq '0') && ($pppsettings{'VCI'} eq '0')) {
166 $errormessage = $Lang::tr{'invalid vpi vpci'};
167 goto ERROR; }
168 if ( $pppsettings{'PROTOCOL'} eq '' ) {
169 $errormessage = $Lang::tr{'invalid input'};
170 goto ERROR; }
171 }
172
173 if ( ($pppsettings{'PROTOCOL'} eq 'RFC1483') && ($pppsettings{'METHOD'} eq '') && \
174 ($pppsettings{'TYPE'} !~ /^(alcatelusb|fritzdsl)$/)) {
175 $errormessage = $Lang::tr{'invalid input'};
176 goto ERROR; }
177
178 if (($pppsettings{'PROTOCOL'} eq 'RFC1483' && $pppsettings{'METHOD'} eq 'DHCP')) {
179 if ($pppsettings{'DHCP_HOSTNAME'} ne '') {
180 if (! &General::validfqdn($pppsettings{'DHCP_HOSTNAME'})) {
181 $errormessage = $errormessage.' '.$Lang::tr{'hostname'}.': '.$Lang::tr{'invalid hostname'}; }
182 }
183 }
184
185 if (($pppsettings{'PROTOCOL'} eq 'RFC1483' && $pppsettings{'METHOD'} eq 'STATIC')) {
186 $errormessage = '';
187 if (! &General::validip($pppsettings{'IP'})) {
188 $errormessage = $Lang::tr{'static ip'}.' '.$Lang::tr{'invalid ip'}; }
189 if (! &General::validip($pppsettings{'GATEWAY'})) {
190 $errormessage = $errormessage.' '.$Lang::tr{'gateway ip'}.' '.$Lang::tr{'invalid ip'}; }
191 if (! &General::validmask($pppsettings{'NETMASK'})) {
192 $errormessage = $errormessage.' '.$Lang::tr{'netmask'}.' '.$Lang::tr{'invalid netmask'}; }
193 if ($pppsettings{'BROADCAST'} ne '') {
194 if (! &General::validip($pppsettings{'BROADCAST'})) {
195 $errormessage = $errormessage.' '.$Lang::tr{'broadcast'}.' '.$Lang::tr{'invalid broadcast ip'}; }
196 }
197 if( $pppsettings{'DNS'} eq 'Automatic') {
198 $errormessage = $Lang::tr{'invalid input'}; }
199 if ($errormessage ne '') {goto ERROR; }
200 }
201
202 if( $pppsettings{'PROTOCOL'} eq 'RFC1483' && $pppsettings{'METHOD'} ne 'PPPOE' && \
203 $pppsettings{'RECONNECTION'} eq 'dialondemand' ) {
204 $errormessage = $Lang::tr{'invalid input'};
205 goto ERROR; }
206
207 if( $pppsettings{'RECONNECTION'} eq 'dialondemand' && `/bin/cat ${General::swroot}/ddns/config` =~ /,on$/m ) {
208 $errormessage = $Lang::tr{'dod not compatible with ddns'};
209 goto ERROR; }
210
211 # if( $pppsettings{'PROTOCOL'} eq 'RFC1483') {
212 # $pppsettings{'ENCAP'} = $pppsettings{'ENCAP_RFC1483'}; }
213 # if( $pppsettings{'PROTOCOL'} eq 'RFC2364') {
214 # $pppsettings{'ENCAP'} = $pppsettings{'ENCAP_RFC2364'}; }
215 delete $pppsettings{'ENCAP_RFC1483'};
216 delete $pppsettings{'ENCAP_RFC2364'};
217
218 ERROR:
219 if ($errormessage) {
220 $pppsettings{'VALID'} = 'no'; }
221 else {
222 $pppsettings{'VALID'} = 'yes'; }
223
224 # write cgi vars to the file.
225 &General::writehash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
226 \%pppsettings);
227
228 # make link and write secret file.
229 &updatesettings();
230 &writesecrets();
231
232 &General::log("$Lang::tr{'profile saved'} $pppsettings{'PROFILENAME'}");
233 }
234 if ($pppsettings{'ACTION'} eq $Lang::tr{'select'})
235 {
236 my $profile = $pppsettings{'PROFILE'};
237 %temppppsettings = ();
238 $temppppsettings{'PROFILE'} = '';
239 &General::readhash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
240 \%temppppsettings);
241
242 # make link.
243 &updatesettings();
244
245 # read in the new params "early" so we can write secrets.
246 %pppsettings = ();
247 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
248 $pppsettings{'PROFILE'} = $profile;
249 &General::writehash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
250 \%pppsettings);
251
252 &writesecrets();
253
254 &General::log("$Lang::tr{'profile made current'} $pppsettings{'PROFILENAME'}");
255 }
256 elsif ($pppsettings{'ACTION'} eq $Lang::tr{'delete'})
257 {
258 &General::log("$Lang::tr{'profile deleted'} $pppsettings{'PROFILENAME'}");
259
260 my $profile = $pppsettings{'PROFILE'};
261 truncate ("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}", 0);
262
263 %temppppsettings = ();
264 $temppppsettings{'PROFILE'} = '';
265 &General::readhash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
266 \%temppppsettings);
267
268 # make link.
269 &updatesettings();
270
271 # read in the new params "early" so we can write secrets.
272 %pppsettings = ();
273 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
274 $pppsettings{'PROFILE'} = $profile;
275 &initprofile;
276 &General::writehash("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
277 \%pppsettings);
278 }
279 elsif ($pppsettings{'ACTION'} eq $Lang::tr{'refresh'})
280 {
281 }
282 else
283 {
284 # read in the current vars
285 %pppsettings = ();
286 $pppsettings{'VALID'} = '';
287 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
288 }
289
290 # read in the profile names into @profilenames.
291 my $c=0;
292 for ($c = 1; $c <= $maxprofiles; $c++)
293 {
294 %temppppsettings = ();
295 $temppppsettings{'PROFILENAME'} = $Lang::tr{'empty profile'};
296 &General::readhash("${General::swroot}/ppp/settings-$c", \%temppppsettings);
297 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
298 }
299
300 if ($pppsettings{'VALID'} eq '')
301 {
302 if ($pppsettings{'PROFILE'} eq '') {
303 $pppsettings{'PROFILE'} = '1';
304 &initprofile();
305 }
306 }
307 for ($c = 1; $c <= $maxprofiles; $c++) {
308 $selected{'PROFILE'}{$c} = ''; }
309 $selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
310 for ($c = 1; $c <= $maxprofiles; $c++) {
311 $selected{'BACKUPPROFILE'}{$c} = ''; }
312 $selected{'BACKUPPROFILE'}{$pppsettings{'BACKUPPROFILE'}} = "selected='selected'";
313
314 $selected{'TYPE'}{'modem'} = '';
315 $selected{'TYPE'}{'serial'} = '';
316 $selected{'TYPE'}{'pppoe'} = '';
317 $selected{'TYPE'}{'pptp'} = '';
318 $selected{'TYPE'}{$pppsettings{'TYPE'}} = "selected='selected'";
319 $checked{'DEBUG'}{'off'} = '';
320 $checked{'DEBUG'}{'on'} = '';
321 $checked{'DEBUG'}{$pppsettings{'DEBUG'}} = "checked='checked'";
322
323 $selected{'COMPORT'}{'ttyS0'} = '';
324 $selected{'COMPORT'}{'ttyS1'} = '';
325 $selected{'COMPORT'}{'ttyS2'} = '';
326 $selected{'COMPORT'}{'ttyS3'} = '';
327 $selected{'COMPORT'}{'ttyS4'} = '';
328 $selected{'COMPORT'}{'ttyACM0'} = '';
329 $selected{'COMPORT'}{'ttyACM1'} = '';
330 $selected{'COMPORT'}{'ttyACM2'} = '';
331 $selected{'COMPORT'}{'ttyACM3'} = '';
332 $selected{'COMPORT'}{'ttyUSB0'} = '';
333 $selected{'COMPORT'}{'ttyUSB1'} = '';
334 $selected{'COMPORT'}{'ttyUSB2'} = '';
335 $selected{'COMPORT'}{'ttyUSB3'} = '';
336 $selected{'COMPORT'}{'rfcomm0'} = '';
337 $selected{'COMPORT'}{'rfcomm1'} = '';
338 $selected{'COMPORT'}{$pppsettings{'COMPORT'}} = "selected='selected'";
339
340 $selected{'DTERATE'}{'9600'} = '';
341 $selected{'DTERATE'}{'19200'} = '';
342 $selected{'DTERATE'}{'38400'} = '';
343 $selected{'DTERATE'}{'57600'} = '';
344 $selected{'DTERATE'}{'115200'} = '';
345 $selected{'DTERATE'}{'230400'} = '';
346 $selected{'DTERATE'}{'460800'} = '';
347 $selected{'DTERATE'}{'921600'} = '';
348 $selected{'DTERATE'}{$pppsettings{'DTERATE'}} = "selected='selected'";
349
350 $checked{'SPEAKER'}{'off'} = '';
351 $checked{'SPEAKER'}{'on'} = '';
352 $checked{'SPEAKER'}{$pppsettings{'SPEAKER'}} = "checked='checked'";
353
354 $selected{'DIALMODE'}{'T'} = '';
355 $selected{'DIALMODE'}{'P'} = '';
356 $selected{'DIALMODE'}{$pppsettings{'DIALMODE'}} = "selected='selected'";
357
358 $checked{'RECONNECTION'}{'persistent'} = '';
359 $checked{'RECONNECTION'}{'dialondemand'} = '';
360 $checked{'RECONNECTION'}{$pppsettings{'RECONNECTION'}} = "checked='checked'";
361
362 $checked{'DIALONDEMANDDNS'}{'off'} = '';
363 $checked{'DIALONDEMANDDNS'}{'on'} = '';
364 $checked{'DIALONDEMANDDNS'}{$pppsettings{'DIALONDEMANDDNS'}} = "checked='checked'";
365
366 $checked{'AUTOCONNECT'}{'off'} = '';
367 $checked{'AUTOCONNECT'}{'on'} = '';
368 $checked{'AUTOCONNECT'}{$pppsettings{'AUTOCONNECT'}} = "checked='checked'";
369
370 $checked{'SENDCR'}{'off'} = '';
371 $checked{'SENDCR'}{'on'} = '';
372 $checked{'SENDCR'}{$pppsettings{'SENDCR'}} = "checked='checked'";
373 $checked{'USEDOV'}{'off'} = '';
374 $checked{'USEDOV'}{'on'} = '';
375 $checked{'USEDOV'}{$pppsettings{'USEDOV'}} = "checked='checked'";
376
377 $checked{'MODEM'}{'PCIST'} = '';
378 $checked{'MODEM'}{'USB'} = '';
379 $checked{'MODEM'}{$pppsettings{'MODEM'}} = "checked='checked'";
380
381 $selected{'LINE'}{'WO'} = '';
382 $selected{'LINE'}{'ES'} = '';
383 $selected{'LINE'}{'ES03'} = '';
384 $selected{'LINE'}{'FR'} = '';
385 $selected{'LINE'}{'FR04'} = '';
386 $selected{'LINE'}{'FR10'} = '';
387 $selected{'LINE'}{'IT'} = '';
388 $selected{'LINE'}{$pppsettings{'LINE'}} = "selected='selected'";
389
390 $checked{'MODULATION'}{'GDMT'} = '';
391 $checked{'MODULATION'}{'ANSI'} = '';
392 $checked{'MODULATION'}{'GLITE'} = '';
393 $checked{'MODULATION'}{'AUTO'} = '';
394 $checked{'MODULATION'}{$pppsettings{'MODULATION'}} = "checked='checked'";
395
396 $checked{'PROTOCOL'}{'RFC1483'} = '';
397 $checked{'PROTOCOL'}{'RFC2364'} = '';
398 $checked{'PROTOCOL'}{$pppsettings{'PROTOCOL'}} = "checked='checked'";
399
400 $selected{'ENCAP'}{'0'} = '';
401 $selected{'ENCAP'}{'1'} = '';
402 #$selected{'ENCAP'}{'2'} = '';
403 #$selected{'ENCAP'}{'3'} = '';
404 #$selected{'ENCAP'}{'4'} = '';
405 $selected{'ENCAP'}{$pppsettings{'ENCAP'}} = "selected='selected'";
406
407 $checked{'METHOD'}{'STATIC'} = '';
408 $checked{'METHOD'}{'PPPOE'} = '';
409 $checked{'METHOD'}{'PPPOE_PLUGIN'} = '';
410 $checked{'METHOD'}{'DHCP'} = '';
411 $checked{'METHOD'}{$pppsettings{'METHOD'}} = "checked='checked'";
412
413 $selected{'AUTH'}{'pap-or-chap'} = '';
414 $selected{'AUTH'}{'pap'} = '';
415 $selected{'AUTH'}{'chap'} = '';
416 $selected{'AUTH'}{'standard-login-script'} = '';
417 $selected{'AUTH'}{'demon-login-script'} = '';
418 $selected{'AUTH'}{'other-login-script'} = '';
419 $selected{'AUTH'}{$pppsettings{'AUTH'}} = "selected='selected'";
420
421 $checked{'DNS'}{'Automatic'} = '';
422 $checked{'DNS'}{'Manual'} = '';
423 $checked{'DNS'}{$pppsettings{'DNS'}} = "checked='checked'";
424
425 &Header::openpage($Lang::tr{'ppp setup'}, 1, '');
426 &Header::openbigbox('100%', 'left', '', $errormessage);
427
428 if ($netsettings{'RED_TYPE'} ne 'PPPOE') {
429 $errormessage = $Lang::tr{'dialup red not ppp'};
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 &Header::closebigbox();
435
436 &Header::closepage();
437 exit(1);
438 }
439
440 if ($errormessage) {
441 &Header::openbox('100%', 'center', $Lang::tr{'error messages'});
442 print "<CLASS name='base'>$errormessage\n";
443 print "&nbsp;</CLASS>\n";
444 &Header::closebox();
445 }
446
447
448 ###
449 ### Box for selecting profile
450 ###
451 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
452 &Header::openbox('100%', 'center', $Lang::tr{'profile'});
453 print <<END
454 <table width='95%' cellspacing='0'>
455 <tr>
456 <td align='left'>$Lang::tr{'profile'}</td>
457 <td align='left'>
458 <select name='PROFILE' style="width: 165px">
459 END
460 ;
461 for ($c = 1; $c <= $maxprofiles; $c++)
462 {
463 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
464 }
465 print <<END
466 </select></td>
467 <td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'select'}' /></td>
468 <td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'delete'}' /></td>
469 <td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'restore'}' /></td>
470 </tr>
471 </table>
472 <br></br>
473 <hr></hr>
474 END
475 ;
476
477 &Header::closebox();
478 &Header::openbox('100%', 'center', $Lang::tr{'connection'});
479
480 print <<END
481 <table width='95%' cellspacing='0'>
482 <tr>
483 <td width='25%'>$Lang::tr{'interface'}:</td>
484 <td width='25%'>
485 <select name='TYPE' style="width: 165px">
486 END
487 ;
488 if ($netsettings{'RED_TYPE'} eq 'PPPOE') {
489 print <<END
490 <option value='modem' $selected{'TYPE'}{'modem'}>$Lang::tr{'modem'}</option>
491 <option value='serial' $selected{'TYPE'}{'serial'}>$Lang::tr{'serial'}</option>
492 <option value='pppoe' $selected{'TYPE'}{'pppoe'}>PPPoE</option>
493 END
494 ;
495
496 my $atmdev=`cat /proc/net/atm/devices | grep 0`;
497 chomp ($atmdev);
498 if ($atmdev ne '') {
499 print <<END
500 <option value='pppoeatm' $selected{'TYPE'}{'pppoeatm'}>PPPoE over ATM-BRIDGE</option>
501 END
502 ;
503 }
504 }
505 #if ($netsettings{'RED_TYPE'} eq 'PPTP') {#
506 # print "\t<option value='pptp' $selected{'TYPE'}{'pptp'}>PPTP</option>\n";
507 #}
508 #
509 #if (0) {
510 # print <<END
511 # <option value='eciadsl' $selected{'TYPE'}{'eciadsl'}>ECI USB ADSL</option>
512 # <option value='eagleusbadsl' $selected{'TYPE'}{'eagleusbadsl'}>Eagle USB ADSL (Acer Allied-Telesyn Comtrend D-Link Sagem USR)</option>
513 # <option value='conexantusbadsl' $selected{'TYPE'}{'conexantusbadsl'}>Conexant USB(Aetra Amigo Draytek Etec Mac Olitec Vitelcom Zoom)</option>
514 # <option value='amedynusbadsl' $selected{'TYPE'}{'amedynusbadsl'}>Zyxel 630-11 / Asus AAM6000UG USB ADSL</option>
515 # <option value='3cp4218usbadsl' $selected{'TYPE'}{'3cp4218usbadsl'}>3Com USB AccessRunner</option>
516 # <option value='alcatelusb' $selected{'TYPE'}{'alcatelusb'}>Speedtouch USB ADSL user mode driver</option>
517 # <option value='alcatelusbk' $selected{'TYPE'}{'alcatelusbk'}>Speedtouch USB ADSL kernel mode driver</option>
518 #END
519 #;
520 #}
521 # print "<option value='fritzdsl' $selected{'TYPE'}{'fritzdsl'}>Fritz!DSL</option>";
522
523 print <<END
524 </select></td>
525 <td colspan='1' width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}'></td>
526 END
527 ;
528 if ($pppsettings{'TYPE'} =~ /^(modem)$/) {
529 print <<END
530 <td colspan='1' width='25%'><A HREF=modem.cgi>$Lang::tr{'modem configuration'}</A></td>
531 END
532 ;
533 }
534
535 print "</tr>";
536
537 #if (-f "/proc/bus/usb/devices") {
538 # <td colspan='2' width='50%'>USB:</td>
539 # my $usb=`lsmod | cut -d ' ' -f1 | grep -E "hci"`;
540 # if ($usb eq '') {
541 # print "\t<td colspan='2' width='50%'>$Lang::tr{'not running'}</td></tr>\n";
542 # } else {
543 # print "\t<td colspan='2' width='50%'>$usb</td></tr>\n";
544 # }
545 #}
546
547 if ($pppsettings{'TYPE'}) {
548 print "<tr><td colspan='4' width='100%'><br></br></td></tr>";
549
550 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/) {
551 print <<END
552
553 <tr>
554 <td colspan='3' width='75%'>$Lang::tr{'interface'}:</td>
555 <td width='25%'><select name='COMPORT' style="width: 165px">
556 END
557 ;
558 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/ ) {
559 print <<END
560 <option value='ttyS0' $selected{'COMPORT'}{'ttyS0'}>COM1</option>
561 <option value='ttyS1' $selected{'COMPORT'}{'ttyS1'}>COM2</option>
562 <option value='ttyS2' $selected{'COMPORT'}{'ttyS2'}>COM3</option>
563 <option value='ttyS3' $selected{'COMPORT'}{'ttyS3'}>COM4</option>
564 <option value='ttyS4' $selected{'COMPORT'}{'ttyS4'}>COM5</option>
565 <option value='ttyUSB0' $selected{'COMPORT'}{'ttyUSB0'}>ttyUSB0</option>
566 <option value='ttyUSB1' $selected{'COMPORT'}{'ttyUSB1'}>ttyUSB1</option>
567 <option value='ttyUSB2' $selected{'COMPORT'}{'ttyUSB2'}>ttyUSB2</option>
568 <option value='ttyUSB3' $selected{'COMPORT'}{'ttyUSB3'}>ttyUSB3</option>
569 <option value='rfcomm0' $selected{'COMPORT'}{'rfcomm0'}>rfcomm0 (bluetooth)</option>
570 <option value='rfcomm1' $selected{'COMPORT'}{'rfcomm1'}>rfcomm1 (bluetooth)</option>
571 END
572 ;
573 if ($pppsettings{'TYPE'} ne 'serial' ) {
574 print <<END
575 <option value='ttyACM0' $selected{'COMPORT'}{'ttyACM0'}>$Lang::tr{'usb modem on acm0'}</option>
576 <option value='ttyACM1' $selected{'COMPORT'}{'ttyACM1'}>$Lang::tr{'usb modem on acm1'}</option>
577 <option value='ttyACM2' $selected{'COMPORT'}{'ttyACM2'}>$Lang::tr{'usb modem on acm2'}</option>
578 <option value='ttyACM3' $selected{'COMPORT'}{'ttyACM3'}>$Lang::tr{'usb modem on acm3'}</option>
579 END
580 ;
581 }
582 print "</select></td> "}
583 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/ ) {
584 print <<END
585 <tr>
586 <td colspan='3' width='75%'>$Lang::tr{'computer to modem rate'}</td>
587 <td width='25%'><select name='DTERATE' style="width: 165px">
588 <option value='9600' $selected{'DTERATE'}{'9600'}>9600</option>
589 <option value='19200' $selected{'DTERATE'}{'19200'}>19200</option>
590 <option value='38400' $selected{'DTERATE'}{'38400'}>38400</option>
591 <option value='57600' $selected{'DTERATE'}{'57600'}>57600</option>
592 <option value='115200' $selected{'DTERATE'}{'115200'}>115200</option>
593 <option value='230400' $selected{'DTERATE'}{'230400'}>230400</option>
594 <option value='460800' $selected{'DTERATE'}{'460800'}>460800</option>
595 <option value='921600' $selected{'DTERATE'}{'921600'}>921600</option>
596 </select></td>
597 </tr>
598 END
599 ;
600 }
601 if ($pppsettings{'TYPE'} =~ /^(modem)$/ ) {
602 print "<tr><td colspan='3' width='75%'>$Lang::tr{'number'}</td>\n";
603 print "<td width='25%'><input type='text' name='TELEPHONE' value='$pppsettings{'TELEPHONE'}'></td><tr>\n";
604 if ($pppsettings{'TYPE'} eq 'modem' ) {
605 print "<tr><td colspan='3' width='75%'>$Lang::tr{'modem speaker on'}</td>\n";
606 print "<td width='25%'><input type='checkbox' name='SPEAKER' $checked{'SPEAKER'}{'on'} /></td></tr>\n";
607 }
608 }
609 }
610 if ($pppsettings{'TYPE'} eq 'modem') {
611 print <<END
612 <tr>
613 <td colspan='3' width='75%'>$Lang::tr{'dialing mode'}</td>
614 <td width='25%'><select name='DIALMODE' style="width: 165px">
615 <option value='T' $selected{'DIALMODE'}{'T'}>$Lang::tr{'tone'}</option>
616 <option value='P' $selected{'DIALMODE'}{'P'}>$Lang::tr{'pulse'}</option>
617 </select></td>
618 </tr>
619 <tr>
620 <td colspan='3' width='75%'>$Lang::tr{'optional at cmd'}&nbsp;1&nbsp;<img src='/blob.gif' alt='*' /></td>
621 <td width='25%'><input type='text' name='ADD_AT1' value='$pppsettings{'ADD_AT1'}'></td>
622 </tr>
623 <tr>
624 <td colspan='3' width='75%'>$Lang::tr{'optional at cmd'}&nbsp;2&nbsp;<img src='/blob.gif' alt='*' /></td>
625 <td width='25%'><input type='text' name='ADD_AT2' value='$pppsettings{'ADD_AT2'}'></td>
626 </tr>
627 <tr>
628 <td colspan='3' width='75%'>$Lang::tr{'optional at cmd'}&nbsp;3&nbsp;<img src='/blob.gif' alt='*' /></td>
629 <td width='25%'><input type='text' name='ADD_AT3' value='$pppsettings{'ADD_AT3'}'></td>
630 </tr>
631 <tr>
632 <td colspan='3' width='75%'>$Lang::tr{'send cr'}</td>
633 <td width='50%'><input type='checkbox' name='SENDCR' $checked{'SENDCR'}{'on'} /></td>
634 </tr>
635 END
636 ;
637 }
638
639 print <<END
640 <tr>
641 <td colspan='3' width='75%'>$Lang::tr{'idle timeout'}</td>
642 <td width='25%'><input type='text' name='TIMEOUT' value='$pppsettings{'TIMEOUT'}' /></td>
643 </tr>
644 <tr>
645 <td colspan='3' width='75%'>$Lang::tr{'connection debugging'}:</td>
646 <td width='25%'><input type='checkbox' name='DEBUG' $checked{'DEBUG'}{'on'} /></td>
647 </tr>
648 <tr>
649 <td colspan='4' width='100%'><br></br></td></tr>
650 <tr>
651 <td colspan='4' width='100%' bgcolor='$color{'color20'}'><b>$Lang::tr{'reconnection'}:</b></td>
652 </tr>
653 <tr>
654 <td colspan='4' width='100%'><input type='radio' name='RECONNECTION' value='dialondemand' $checked{'RECONNECTION'}{'dialondemand'}>$Lang::tr{'dod'}</td>
655 </tr>
656 END
657 ;
658 if ($pppsettings{'TYPE'} ne 'isdn') {
659 print <<END
660 <tr>
661 <td colspan='4' width='100%'><input type='radio' name='RECONNECTION' value='persistent' $checked{'RECONNECTION'}{'persistent'}>$Lang::tr{'persistent'}</td>
662 </tr>
663 <tr>
664 <td colspan='3' width='75%'>$Lang::tr{'backupprofile'}:</td>
665 <td width='25%'><select name='BACKUPPROFILE' style="width: 165px">
666 END
667 ;
668 for ($c = 1; $c <= $maxprofiles; $c++) {
669 print "\t<option value='$c' $selected{'BACKUPPROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
670 }
671 print <<END
672 </select></td>
673 </tr>
674 END
675 ;
676 }
677 print <<END
678 <tr>
679 <td colspan='3' width='75%'>$Lang::tr{'dod for dns'}</td>
680 <td width='25%'><input type='checkbox' name='DIALONDEMANDDNS' $checked{'DIALONDEMANDDNS'}{'on'} /></td>
681 </tr>
682 <tr>
683 <td colspan='3' width='75%'>$Lang::tr{'holdoff'}:</td>
684 <td width='25%'><input type='text' name='HOLDOFF' value='$pppsettings{'HOLDOFF'}' /></td>
685 </tr>
686 <tr>
687 <td colspan='3' width='75%'>$Lang::tr{'maximum retries'}</td>
688 <td width='25%'><input type='text' name='MAXRETRIES' value='$pppsettings{'MAXRETRIES'}' /></td>
689 </tr>
690 END
691 ;
692
693 if ($pppsettings{'TYPE'} eq 'pptp')
694 {
695 print <<END
696 <tr><td colspan='4' width='100%'><br></br></td></tr>
697 <tr>
698 <td colspan='4' width='100%' bgcolor='$color{'color20'}'><b>$Lang::tr{'pptp settings'}</b></td>
699 </tr>
700 <tr>
701 <td width='25%'>$Lang::tr{'phonebook entry'}</td>
702 <td colspan='2' width='50%'></td>
703 <td width='25%'><input type='text' name='PHONEBOOK' value='$pppsettings{'PHONEBOOK'}' /></td>
704 </tr>
705 <tr>
706 <td width='25%'><input type='radio' name='METHOD' value='STATIC' $checked{'METHOD'}{'STATIC'} />$Lang::tr{'static ip'}</td>
707 <td colspan='2' width='50%'>$Lang::tr{'router ip'}</td>
708 <td width='25%'><input type='text' name='ROUTERIP' value='$pppsettings{'ROUTERIP'}' /></td>
709 </tr>
710 <tr>
711 <td width='25%'><input type='radio' name='METHOD' value='DHCP' $checked{'METHOD'}{'DHCP'} />$Lang::tr{'dhcp mode'}</td>
712 <td colspan='2' width='50%'>$Lang::tr{'hostname'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
713 <td width='25%'><input type='text' name='DHCP_HOSTNAME' value='$pppsettings{'DHCP_HOSTNAME'}' /></td>
714 </tr>
715 END
716 ;
717 }
718 if ($pppsettings{'TYPE'} =~ /^(pppoeatm)$/)
719 {
720
721 print <<END
722 <tr>
723 <td colspan='4' width='100%' bgcolor='$color{'color20'}'><b>$Lang::tr{'adsl settings'}:</b></td>
724 <tr>
725
726 <td> $Lang::tr{'encapsulation'}:</td>
727 <td colspan='2' width='30%'>
728 <select name='ENCAP'>
729 <option value='0' $selected{'ENCAP'}{'0'}>LLC</option>
730 <option value='1' $selected{'ENCAP'}{'1'}>VCmux</option>
731 </select>
732 </td>
733 </tr>
734 <tr>
735
736 <td nowrap='nowrap'>$Lang::tr{'vpi number'}</td>
737 <td><input type='text' size='5' name='VPI' value='$pppsettings{'VPI'}' /></td>
738 <td align='right'>$Lang::tr{'vci number'}</td>
739 <td colspan='2'><input type='text' size='5' name='VCI' value='$pppsettings{'VCI'}' /></td>
740 </tr>
741 END
742 ;
743 }
744
745
746 if ($pppsettings{'TYPE'} eq 'pppoe' || $pppsettings{'TYPE'} eq 'pppoeatm')
747 {
748 print <<END
749 <tr><td colspan='4' width='100%'><br></br></td></tr>
750 <tr>
751 <td colspan='4' width='100%' bgcolor='$color{'color20'}'><b>$Lang::tr{'pppoe settings'}</b></td>
752 </tr>
753 <tr>
754 <td width='25%'><input type='radio' name='METHOD' value='PPPOE_PLUGIN' $checked{'METHOD'}{'PPPOE_PLUGIN'} />PPPoE plugin</td>
755 <td colspan='2' width='50%'>$Lang::tr{'service name'}&nbsp;<img src='/blob.gif' alt='*' /></td>
756 <td width='25%'><input type='text' name='SERVICENAME' value='$pppsettings{'SERVICENAME'}' /></td>
757 </tr>
758 <tr>
759 <td width='25%'><input type='radio' name='METHOD' value='PPPOE' $checked{'METHOD'}{'PPPOE'} />$Lang::tr{'pppoe'}</td>
760 <td colspan='2' width='50%'>$Lang::tr{'concentrator name'}&nbsp;<img src='/blob.gif' alt='*' /></td>
761 <td width='25%'><input type='text' name='CONCENTRATORNAME' value='$pppsettings{'CONCENTRATORNAME'}' /></td>
762 </tr>
763 <tr>
764 <td width='25%'>MTU</td>
765 <td colspan='2' width='50%'></td>
766 <td width='25%'><input type='text' name='MTU' value='$pppsettings{'MTU'}' /></td>
767 </tr>
768 END
769 ;
770 }
771
772 print <<END
773 <tr><td colspan='4' width='100%'><br></br></td></tr>
774 <tr>
775 <td bgcolor='$color{'color20'}' colspan='4' width='100%'><b>$Lang::tr{'authentication'}</b></td>
776 </tr>
777 <tr>
778 <td width='25%'>$Lang::tr{'username'}</td>
779 <td width='25%'><input type='text' name='USERNAME' value='$pppsettings{'USERNAME'}' /></td>
780 <td width='25%'>$Lang::tr{'password'}</td>
781 <td width='25%'><input type='password' name='PASSWORD' value='$pppsettings{'PASSWORD'}' /></td>
782 </tr>
783 <tr>
784 <td width='25%'>$Lang::tr{'method'}</td>
785 <td width='25%'><select name='AUTH' style="width: 165px">
786 <option value='pap-or-chap' $selected{'AUTH'}{'pap-or-chap'}>$Lang::tr{'pap or chap'}</option>
787 <option value='pap' $selected{'AUTH'}{'pap'}>PAP</option>
788 <option value='chap' $selected{'AUTH'}{'chap'}>CHAP</option>
789 END
790 ;
791 if ($pppsettings{'TYPE'} eq 'modem') {
792 print <<END
793 <option value='standard-login-script' $selected{'AUTH'}{'standard-login-script'}>$Lang::tr{'standard login script'}</option>
794 <option value='demon-login-script' $selected{'AUTH'}{'demon-login-script'}>$Lang::tr{'demon login script'}</option>
795 <option value='other-login-script' $selected{'AUTH'}{'other-login-script'}>$Lang::tr{'other login script'}</option>
796 END
797 ;
798 }
799 print <<END
800 </select></td>
801 <td width='25%'>$Lang::tr{'script name'}&nbsp;<img src='/blob.gif' alt='*' /></td>
802 <td width='25%'><input type='text' name='LOGINSCRIPT' value='$pppsettings{'LOGINSCRIPT'}' /></td>
803 </tr>
804 <tr><td colspan='4' width='100%'><br></br></td></tr>
805 <tr>
806 <td bgcolor='$color{'color20'}' colspan='4' width='100%'><b>DNS:</b></td>
807 </tr>
808 <tr>
809 <td colspan='4' width='100%'><input type='radio' name='DNS' value='Automatic' $checked{'DNS'}{'Automatic'} />$Lang::tr{'automatic'}</td>
810 </tr>
811 <tr>
812 <td colspan='4' width='100%'><input type='radio' name='DNS' value='Manual' $checked{'DNS'}{'Manual'} />$Lang::tr{'manual'}</td>
813 </tr>
814 <tr>
815 <td width='25%'>$Lang::tr{'primary dns'}</td>
816 <td width='25%'><input type='text' name='DNS1' value='$pppsettings{'DNS1'}'></td>
817 <td width='25%'>$Lang::tr{'secondary dns'}</td>
818 <td width='25%'><input type='text' name='DNS2' value='$pppsettings{'DNS2'}'></td>
819 </tr>
820 <tr><td colspan='4' width='100%'><br></br><hr></hr><br></br></td></tr>
821 <tr>
822 <td width='25%'>$Lang::tr{'profile name'}</td>
823 <td width='25%'><input type='text' name='PROFILENAME' value='$pppsettings{'PROFILENAME'}'>
824 <td colspan='2' width='50%'></td>
825 </tr>
826 <tr>
827 <td align='center' colspan='4' width='100%'><input type='submit' name='ACTION' value='$Lang::tr{'save'}'></td>
828 </tr>
829 <tr>
830 <td colspan='2' width='50%'>$Lang::tr{'legend'}:</td>
831 <td colspan='2' width='50%'><img src='/blob.gif' alt='*' />&nbsp;$Lang::tr{'this field may be blank'}</td>
832 </tr>
833 </table>
834 END
835 ;
836 &Header::closebox();
837 }
838
839 print "</form>\n";
840
841 &Header::closebigbox();
842
843 &Header::closepage();
844
845 sub updatesettings
846 {
847 # make a link from the selected profile to the "default" one.
848 unlink("${General::swroot}/ppp/settings");
849 link("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
850 "${General::swroot}/ppp/settings");
851 system ("/usr/bin/touch", "${General::swroot}/ppp/updatesettings");
852 }
853
854 sub writesecrets
855 {
856 # write secrets file.
857 open(FILE, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file.";
858 flock(FILE, 2);
859 my $username = $pppsettings{'USERNAME'};
860 my $password = $pppsettings{'PASSWORD'};
861 print FILE "'$username' * '$password'\n";
862 chmod 0600, "${General::swroot}/ppp/secrets";
863 close FILE;
864 }
865
866 sub initprofile
867 {
868 $pppsettings{'PROFILENAME'} = $Lang::tr{'unnamed'};
869 $pppsettings{'COMPORT'} = 'ttyS0';
870 $pppsettings{'DTERATE'} = 115200;
871 $pppsettings{'SPEAKER'} = 'off';
872 $pppsettings{'RECONNECTION'} = 'persistent';
873 $pppsettings{'DIALONDEMANDDNS'} = 'off';
874 $pppsettings{'AUTOCONNECT'} = 'on';
875 $pppsettings{'SENDCR'} = 'off';
876 $pppsettings{'USEIBOD'} = 'off';
877 $pppsettings{'USEDOV'} = 'off';
878 $pppsettings{'MODEM'} = 'PCIST';
879 $pppsettings{'LINE'} = 'WO';
880 $pppsettings{'ENCAP'} = '0';
881 $pppsettings{'VPI'} = '1';
882 $pppsettings{'VCI'} = '32';
883 $pppsettings{'PHONEBOOK'} = 'RELAY_PPP1';
884 $pppsettings{'PROTOCOL'} = 'RFC2364';
885 $pppsettings{'METHOD'} = 'PPPOE_PLUGIN';
886 if ( $pppsettings{'METHOD'} eq 'PPPOE_PLUGIN' ) {
887 $pppsettings{'MTU'} = '1492';
888 $pppsettings{'MRU'} = '1492';
889 } else {
890 $pppsettings{'MTU'} = '1452';
891 $pppsettings{'MRU'} = '1452';
892 }
893 $pppsettings{'DIALMODE'} = 'T';
894 $pppsettings{'MAXRETRIES'} = 5;
895 $pppsettings{'HOLDOFF'} = 30;
896 $pppsettings{'TIMEOUT'} = 15;
897 $pppsettings{'MODULATION'} = 'AUTO';
898 $pppsettings{'AUTH'} = 'pap-or-chap';
899 $pppsettings{'DNS'} = 'Automatic';
900 $pppsettings{'DEBUG'} = 'off';
901 $pppsettings{'BACKUPPROFILE'} = $pppsettings{'PROFILE'};
902
903 # Get PPPoE settings so we can see if PPPoE is enabled or not.
904 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
905
906 # empty profile partial pre-initialization
907 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) {
908 $pppsettings{'TYPE'}=lc($netsettings{'RED_TYPE'});
909 } else {
910 $pppsettings{'TYPE'}='modem';
911 }
912 }
913