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