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