]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - html/cgi-bin/pppsetup.cgi
Zwei kleine Fixes, an den Installations-Skripten.
[people/teissler/ipfire-2.x.git] / html / cgi-bin / pppsetup.cgi
CommitLineData
ac1cfefa 1#!/usr/bin/perl
70df8302
MT
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###############################################################################
ac1cfefa
MT
21
22use strict;
23
24# enable only the following on debugging purpose
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
27
986e08d9 28require '/var/ipfire/general-functions.pl';
ac1cfefa
MT
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
31
32our %pppsettings=();
33my %temppppsettings=();
34our %modemsettings=();
35our %isdnsettings=();
36our %netsettings=();
37my %selected=();
38my %checked=();
39my @profilenames=();
40my $errormessage = '';
41my $maxprofiles = 5;
42my $kernel=`/bin/uname -r | /usr/bin/tr -d '\012'`;
43
f2fdd0c1
CS
44my %color = ();
45my %mainsettings = ();
46&General::readhash("${General::swroot}/main/settings", \%mainsettings);
47&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
48
ac1cfefa
MT
49&Header::showhttpheaders();
50
51$pppsettings{'ACTION'} = '';
52&initprofile();
53&Header::getcgihash(\%pppsettings);
54
55if ($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}
64elsif ($pppsettings{'ACTION'} eq $Lang::tr{'refresh'})
65{
a89770fa 66 unless ($pppsettings{'TYPE'} =~ /^(modem|serial|isdn|pppoe|pptp|pppoeatm)$/) {
ac1cfefa
MT
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}
73elsif ($pppsettings{'ACTION'} eq $Lang::tr{'save'})
74{
3e615c37 75 if ($pppsettings{'TYPE'} =~ /^(modem|serial|isdn)$/ && $pppsettings{'COMPORT'} !~ /^(ttyS0|ttyS1|ttyS2|ttyS3|ttyS4|ttyACM0|ttyACM1|ttyACM2|ttyACM3|isdn1|isdn2)$/) {
ac1cfefa
MT
76 $errormessage = $Lang::tr{'invalid input'};
77 goto ERROR; }
a89770fa 78 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/ && $pppsettings{'DTERATE'} !~ /^(9600|19200|38400|57600|115200|230400|460800|921600)$/) {
ac1cfefa
MT
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
ac1cfefa
MT
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 }
a89770fa
MT
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
ac1cfefa
MT
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
a89770fa
MT
211# if( $pppsettings{'PROTOCOL'} eq 'RFC1483') {
212# $pppsettings{'ENCAP'} = $pppsettings{'ENCAP_RFC1483'}; }
213# if( $pppsettings{'PROTOCOL'} eq 'RFC2364') {
214# $pppsettings{'ENCAP'} = $pppsettings{'ENCAP_RFC2364'}; }
ac1cfefa
MT
215 delete $pppsettings{'ENCAP_RFC1483'};
216 delete $pppsettings{'ENCAP_RFC2364'};
217
218ERROR:
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'}");
ac1cfefa 233}
cb5e9c6c 234if ($pppsettings{'ACTION'} eq $Lang::tr{'select'})
ac1cfefa
MT
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}
256elsif ($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}
279else
280{
281 # read in the current vars
282 %pppsettings = ();
283 $pppsettings{'VALID'} = '';
284 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
285}
286
287# read in the profile names into @profilenames.
288my $c=0;
289for ($c = 1; $c <= $maxprofiles; $c++)
290{
291 %temppppsettings = ();
6c666a3b 292 $temppppsettings{'PROFILENAME'} = $Lang::tr{'empty profile'};
ac1cfefa
MT
293 &General::readhash("${General::swroot}/ppp/settings-$c", \%temppppsettings);
294 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
295}
296
297if ($pppsettings{'VALID'} eq '')
298{
299 if ($pppsettings{'PROFILE'} eq '') {
300 $pppsettings{'PROFILE'} = '1';
301 &initprofile();
302 }
303}
304for ($c = 1; $c <= $maxprofiles; $c++) {
305 $selected{'PROFILE'}{$c} = ''; }
306$selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
307for ($c = 1; $c <= $maxprofiles; $c++) {
308 $selected{'BACKUPPROFILE'}{$c} = ''; }
309$selected{'BACKUPPROFILE'}{$pppsettings{'BACKUPPROFILE'}} = "selected='selected'";
310
311$selected{'TYPE'}{'modem'} = '';
312$selected{'TYPE'}{'serial'} = '';
ac1cfefa
MT
313$selected{'TYPE'}{'pppoe'} = '';
314$selected{'TYPE'}{'pptp'} = '';
ac1cfefa
MT
315$selected{'TYPE'}{$pppsettings{'TYPE'}} = "selected='selected'";
316
317$checked{'DEBUG'}{'off'} = '';
318$checked{'DEBUG'}{'on'} = '';
319$checked{'DEBUG'}{$pppsettings{'DEBUG'}} = "checked='checked'";
320
321$selected{'COMPORT'}{'ttyS0'} = '';
322$selected{'COMPORT'}{'ttyS1'} = '';
323$selected{'COMPORT'}{'ttyS2'} = '';
324$selected{'COMPORT'}{'ttyS3'} = '';
325$selected{'COMPORT'}{'ttyS4'} = '';
3e615c37
MT
326$selected{'COMPORT'}{'ttyACM0'} = '';
327$selected{'COMPORT'}{'ttyACM1'} = '';
328$selected{'COMPORT'}{'ttyACM2'} = '';
329$selected{'COMPORT'}{'ttyACM3'} = '';
ac1cfefa
MT
330$selected{'COMPORT'}{$pppsettings{'COMPORT'}} = "selected='selected'";
331
332$selected{'DTERATE'}{'9600'} = '';
333$selected{'DTERATE'}{'19200'} = '';
334$selected{'DTERATE'}{'38400'} = '';
335$selected{'DTERATE'}{'57600'} = '';
336$selected{'DTERATE'}{'115200'} = '';
337$selected{'DTERATE'}{'230400'} = '';
6c666a3b 338$selected{'DTERATE'}{'460800'} = '';
a89770fa 339$selected{'DTERATE'}{'921600'} = '';
ac1cfefa
MT
340$selected{'DTERATE'}{$pppsettings{'DTERATE'}} = "selected='selected'";
341
342$checked{'SPEAKER'}{'off'} = '';
343$checked{'SPEAKER'}{'on'} = '';
344$checked{'SPEAKER'}{$pppsettings{'SPEAKER'}} = "checked='checked'";
345
346$selected{'DIALMODE'}{'T'} = '';
347$selected{'DIALMODE'}{'P'} = '';
348$selected{'DIALMODE'}{$pppsettings{'DIALMODE'}} = "selected='selected'";
349
350$checked{'RECONNECTION'}{'manual'} = '';
351$checked{'RECONNECTION'}{'persistent'} = '';
352$checked{'RECONNECTION'}{'dialondemand'} = '';
353$checked{'RECONNECTION'}{$pppsettings{'RECONNECTION'}} = "checked='checked'";
354
355$checked{'DIALONDEMANDDNS'}{'off'} = '';
356$checked{'DIALONDEMANDDNS'}{'on'} = '';
357$checked{'DIALONDEMANDDNS'}{$pppsettings{'DIALONDEMANDDNS'}} = "checked='checked'";
358
359$checked{'AUTOCONNECT'}{'off'} = '';
360$checked{'AUTOCONNECT'}{'on'} = '';
361$checked{'AUTOCONNECT'}{$pppsettings{'AUTOCONNECT'}} = "checked='checked'";
362
363$checked{'SENDCR'}{'off'} = '';
364$checked{'SENDCR'}{'on'} = '';
365$checked{'SENDCR'}{$pppsettings{'SENDCR'}} = "checked='checked'";
366$checked{'USEDOV'}{'off'} = '';
367$checked{'USEDOV'}{'on'} = '';
368$checked{'USEDOV'}{$pppsettings{'USEDOV'}} = "checked='checked'";
ac1cfefa
MT
369
370$checked{'MODEM'}{'PCIST'} = '';
371$checked{'MODEM'}{'USB'} = '';
372$checked{'MODEM'}{$pppsettings{'MODEM'}} = "checked='checked'";
373
374$selected{'LINE'}{'WO'} = '';
375$selected{'LINE'}{'ES'} = '';
376$selected{'LINE'}{'ES03'} = '';
377$selected{'LINE'}{'FR'} = '';
378$selected{'LINE'}{'FR04'} = '';
379$selected{'LINE'}{'FR10'} = '';
380$selected{'LINE'}{'IT'} = '';
381$selected{'LINE'}{$pppsettings{'LINE'}} = "selected='selected'";
382
383$checked{'MODULATION'}{'GDMT'} = '';
384$checked{'MODULATION'}{'ANSI'} = '';
385$checked{'MODULATION'}{'GLITE'} = '';
386$checked{'MODULATION'}{'AUTO'} = '';
387$checked{'MODULATION'}{$pppsettings{'MODULATION'}} = "checked='checked'";
388
389$checked{'PROTOCOL'}{'RFC1483'} = '';
390$checked{'PROTOCOL'}{'RFC2364'} = '';
391$checked{'PROTOCOL'}{$pppsettings{'PROTOCOL'}} = "checked='checked'";
392
393$selected{'ENCAP'}{'0'} = '';
394$selected{'ENCAP'}{'1'} = '';
a89770fa
MT
395#$selected{'ENCAP'}{'2'} = '';
396#$selected{'ENCAP'}{'3'} = '';
397#$selected{'ENCAP'}{'4'} = '';
ac1cfefa 398$selected{'ENCAP'}{$pppsettings{'ENCAP'}} = "selected='selected'";
a89770fa 399
ac1cfefa
MT
400$checked{'METHOD'}{'STATIC'} = '';
401$checked{'METHOD'}{'PPPOE'} = '';
402$checked{'METHOD'}{'PPPOE_PLUGIN'} = '';
403$checked{'METHOD'}{'DHCP'} = '';
404$checked{'METHOD'}{$pppsettings{'METHOD'}} = "checked='checked'";
405
406$selected{'AUTH'}{'pap-or-chap'} = '';
407$selected{'AUTH'}{'pap'} = '';
408$selected{'AUTH'}{'chap'} = '';
409$selected{'AUTH'}{'standard-login-script'} = '';
410$selected{'AUTH'}{'demon-login-script'} = '';
411$selected{'AUTH'}{'other-login-script'} = '';
412$selected{'AUTH'}{$pppsettings{'AUTH'}} = "selected='selected'";
413
414$checked{'DNS'}{'Automatic'} = '';
415$checked{'DNS'}{'Manual'} = '';
416$checked{'DNS'}{$pppsettings{'DNS'}} = "checked='checked'";
417
418&Header::openpage($Lang::tr{'ppp setup'}, 1, '');
ac1cfefa
MT
419&Header::openbigbox('100%', 'left', '', $errormessage);
420
421if ($errormessage) {
330345c2 422 &Header::openbox('100%', 'center', $Lang::tr{'error messages'});
ac1cfefa
MT
423 print "<CLASS name='base'>$errormessage\n";
424 print "&nbsp;</CLASS>\n";
425 &Header::closebox();
426}
427
428
429###
430### Box for selecting profile
431###
432print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
330345c2 433&Header::openbox('100%', 'center', $Lang::tr{'profile'});
ac1cfefa 434print <<END
330345c2 435<table width='95%' cellspacing='0'>
ac1cfefa 436<tr>
a89770fa 437 <td align='left'>$Lang::tr{'profile'}</td>
330345c2
MT
438 <td align='left'>
439 <select name='PROFILE' style="width: 165px">
ac1cfefa
MT
440END
441;
442for ($c = 1; $c <= $maxprofiles; $c++)
443{
444 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
445}
446print <<END
447 </select></td>
330345c2
MT
448 <td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'select'}' /></td>
449 <td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'delete'}' /></td>
450 <td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'restore'}' /></td>
ac1cfefa
MT
451</tr>
452</table>
330345c2
MT
453<br></br>
454<hr></hr>
ac1cfefa
MT
455END
456;
330345c2 457
ac1cfefa 458&Header::closebox();
330345c2
MT
459&Header::openbox('100%', 'center', $Lang::tr{'connection'});
460
ac1cfefa 461print <<END
330345c2 462<table width='95%' cellspacing='0'>
ac1cfefa 463<tr>
330345c2
MT
464 <td width='25%'>$Lang::tr{'interface'}:</td>
465 <td width='25%'>
466 <select name='TYPE' style="width: 165px">
ac1cfefa
MT
467 <option value='modem' $selected{'TYPE'}{'modem'}>$Lang::tr{'modem'}</option>
468 <option value='serial' $selected{'TYPE'}{'serial'}>$Lang::tr{'serial'}</option>
469END
470;
ac1cfefa
MT
471if ($netsettings{'RED_TYPE'} eq 'PPPOE') {
472 print "\t<option value='pppoe' $selected{'TYPE'}{'pppoe'}>PPPoE</option>\n";
473}
474if ($netsettings{'RED_TYPE'} eq 'PPTP') {
475 print "\t<option value='pptp' $selected{'TYPE'}{'pptp'}>PPTP</option>\n";
476}
a89770fa
MT
477my $atmdev=`cat /proc/net/atm/devices | grep 0`;
478chomp ($atmdev);
479if ($atmdev ne '') {
ac1cfefa 480 print <<END
a89770fa 481 <option value='pppoeatm' $selected{'TYPE'}{'pppoeatm'}>PPPoE over ATM-BRIDGE</option>
ac1cfefa
MT
482END
483;
484}
8cc01c83 485
a89770fa
MT
486#if (0) {
487# print <<END
488# <option value='eciadsl' $selected{'TYPE'}{'eciadsl'}>ECI USB ADSL</option>
489# <option value='eagleusbadsl' $selected{'TYPE'}{'eagleusbadsl'}>Eagle USB ADSL (Acer Allied-Telesyn Comtrend D-Link Sagem USR)</option>
490# <option value='conexantusbadsl' $selected{'TYPE'}{'conexantusbadsl'}>Conexant USB(Aetra Amigo Draytek Etec Mac Olitec Vitelcom Zoom)</option>
491# <option value='amedynusbadsl' $selected{'TYPE'}{'amedynusbadsl'}>Zyxel 630-11 / Asus AAM6000UG USB ADSL</option>
492# <option value='3cp4218usbadsl' $selected{'TYPE'}{'3cp4218usbadsl'}>3Com USB AccessRunner</option>
493# <option value='alcatelusb' $selected{'TYPE'}{'alcatelusb'}>Speedtouch USB ADSL user mode driver</option>
494# <option value='alcatelusbk' $selected{'TYPE'}{'alcatelusbk'}>Speedtouch USB ADSL kernel mode driver</option>
495#END
496#;
497#}
8cc01c83 498# print "<option value='fritzdsl' $selected{'TYPE'}{'fritzdsl'}>Fritz!DSL</option>";
a89770fa 499
ac1cfefa 500 print <<END
a89770fa
MT
501 </select></td>
502 <td colspan='1' width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}'></td>
503END
504;
505 if ($pppsettings{'TYPE'} =~ /^(modem)$/) {
506 print <<END
507 <td colspan='1' width='25%'><A HREF=modem.cgi>$Lang::tr{'modem configuration'}</A></td>
ac1cfefa
MT
508END
509;
ac1cfefa
MT
510}
511
a89770fa
MT
512 print "</tr>";
513
514#if (-f "/proc/bus/usb/devices") {
515# <td colspan='2' width='50%'>USB:</td>
516# my $usb=`lsmod | cut -d ' ' -f1 | grep -E "hci"`;
517# if ($usb eq '') {
518# print "\t<td colspan='2' width='50%'>$Lang::tr{'not running'}</td></tr>\n";
519# } else {
520# print "\t<td colspan='2' width='50%'>$usb</td></tr>\n";
521# }
522#}
523
ac1cfefa 524if ($pppsettings{'TYPE'}) {
330345c2 525 print "<tr><td colspan='4' width='100%'><br></br></td></tr>";
a89770fa 526
285c5bbd 527 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/) {
ac1cfefa 528 print <<END
a89770fa 529
ac1cfefa 530<tr>
330345c2
MT
531 <td colspan='3' width='75%'>$Lang::tr{'interface'}:</td>
532 <td width='25%'><select name='COMPORT' style="width: 165px">
ac1cfefa
MT
533END
534;
535 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/ ) {
536 print <<END
537 <option value='ttyS0' $selected{'COMPORT'}{'ttyS0'}>$Lang::tr{'modem on com1'}</option>
538 <option value='ttyS1' $selected{'COMPORT'}{'ttyS1'}>$Lang::tr{'modem on com2'}</option>
539 <option value='ttyS2' $selected{'COMPORT'}{'ttyS2'}>$Lang::tr{'modem on com3'}</option>
540 <option value='ttyS3' $selected{'COMPORT'}{'ttyS3'}>$Lang::tr{'modem on com4'}</option>
541 <option value='ttyS4' $selected{'COMPORT'}{'ttyS4'}>$Lang::tr{'modem on com5'}</option>
a29b2d7b
MT
542 <option value='ttyACM0' $selected{'COMPORT'}{'ttyACM0'}>$Lang::tr{'usb modem on acm0'}</option>
543 <option value='ttyACM1' $selected{'COMPORT'}{'ttyACM1'}>$Lang::tr{'usb modem on acm1'}</option>
544 <option value='ttyACM2' $selected{'COMPORT'}{'ttyACM2'}>$Lang::tr{'usb modem on acm2'}</option>
545 <option value='ttyACM3' $selected{'COMPORT'}{'ttyACM3'}>$Lang::tr{'usb modem on acm3'}</option>
a89770fa 546 </select></td>
ac1cfefa 547END
ac1cfefa
MT
548;
549 }
550 if ($pppsettings{'TYPE'} =~ /^(modem|serial)$/ ) {
551 print <<END
330345c2
MT
552 <tr>
553 <td colspan='3' width='75%'>$Lang::tr{'computer to modem rate'}</td>
554 <td width='25%'><select name='DTERATE' style="width: 165px">
ac1cfefa
MT
555 <option value='9600' $selected{'DTERATE'}{'9600'}>9600</option>
556 <option value='19200' $selected{'DTERATE'}{'19200'}>19200</option>
557 <option value='38400' $selected{'DTERATE'}{'38400'}>38400</option>
558 <option value='57600' $selected{'DTERATE'}{'57600'}>57600</option>
559 <option value='115200' $selected{'DTERATE'}{'115200'}>115200</option>
560 <option value='230400' $selected{'DTERATE'}{'230400'}>230400</option>
6c666a3b 561 <option value='460800' $selected{'DTERATE'}{'460800'}>460800</option>
a89770fa 562 <option value='921600' $selected{'DTERATE'}{'921600'}>921600</option>
ac1cfefa
MT
563 </select></td>
564</tr>
565END
566;
330345c2 567 }
285c5bbd 568 if ($pppsettings{'TYPE'} =~ /^(modem)$/ ) {
330345c2
MT
569 print "<tr><td colspan='3' width='75%'>$Lang::tr{'number'}</td>\n";
570 print "<td width='25%'><input type='text' name='TELEPHONE' value='$pppsettings{'TELEPHONE'}'></td><tr>\n";
ac1cfefa 571 if ($pppsettings{'TYPE'} eq 'modem' ) {
330345c2
MT
572 print "<tr><td colspan='3' width='75%'>$Lang::tr{'modem speaker on'}</td>\n";
573 print "<td width='25%'><input type='checkbox' name='SPEAKER' $checked{'SPEAKER'}{'on'} /></td></tr>\n";
574 }
ac1cfefa
MT
575 }
576 }
577 if ($pppsettings{'TYPE'} eq 'modem') {
578 print <<END
579<tr>
330345c2
MT
580 <td colspan='3' width='75%'>$Lang::tr{'dialing mode'}</td>
581 <td width='25%'><select name='DIALMODE' style="width: 165px">
ac1cfefa
MT
582 <option value='T' $selected{'DIALMODE'}{'T'}>$Lang::tr{'tone'}</option>
583 <option value='P' $selected{'DIALMODE'}{'P'}>$Lang::tr{'pulse'}</option>
584 </select></td>
330345c2
MT
585</tr>
586<tr>
587 <td colspan='3' width='75%'>$Lang::tr{'send cr'}</td>
588 <td width='50%'><input type='checkbox' name='SENDCR' $checked{'SENDCR'}{'on'} /></td>
ac1cfefa
MT
589</tr>
590END
591;
592}
593
594print <<END
595<tr>
330345c2
MT
596 <td colspan='3' width='75%'>$Lang::tr{'idle timeout'}</td>
597 <td width='25%'><input type='text' name='TIMEOUT' value='$pppsettings{'TIMEOUT'}' /></td>
ac1cfefa
MT
598</tr>
599END
600;
cb5e9c6c 601 if ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && ( $netsettings{'RED_TYPE'} eq "DHCP" || $netsettings{'RED_TYPE'} eq "STATIC") ) {
ac1cfefa 602 $pppsettings{'AUTOCONNECT'} = 'on';
330345c2
MT
603 print "<tr><td colspan='3' width='75%'>$Lang::tr{'connect on ipfire restart'}</td>\n";
604 print "<td width='25%'><input type='checkbox' disabled='disabled' name='AUTOCONNECT' value='on' $checked{'AUTOCONNECT'}{'on'}></td>\n";
ac1cfefa 605 } else {
330345c2
MT
606 print "<tr><td colspan='3' width='75%'>$Lang::tr{'connect on ipfire restart'}</td>\n";
607 print "<td width='25%'><input type='checkbox' name='AUTOCONNECT' value='on' $checked{'AUTOCONNECT'}{'on'}></td>\n";
ac1cfefa
MT
608 }
609print <<END
330345c2
MT
610 </tr>
611 <tr>
612 <td colspan='3' width='75%'>$Lang::tr{'connection debugging'}:</td>
613 <td width='25%'><input type='checkbox' name='DEBUG' $checked{'DEBUG'}{'on'} /></td>
614 </tr>
615 <tr>
616 <td colspan='4' width='100%'><br></br></td></tr>
ac1cfefa 617<tr>
f2fdd0c1 618 <td colspan='4' width='100%' bgcolor='$color{'color20'}'><b>$Lang::tr{'reconnection'}:</b></td>
ac1cfefa
MT
619</tr>
620<tr>
330345c2 621 <td colspan='4' width='100%'><input type='radio' name='RECONNECTION' value='manual' $checked{'RECONNECTION'}{'manual'}>$Lang::tr{'manual'}</td>
ac1cfefa 622</tr>
330345c2
MT
623<tr>
624 <td colspan='4' width='100%'><input type='radio' name='RECONNECTION' value='dialondemand' $checked{'RECONNECTION'}{'dialondemand'}>$Lang::tr{'dod'}</td>
625 </tr>
ac1cfefa
MT
626END
627;
628if ($pppsettings{'TYPE'} ne 'isdn') {
629print <<END
330345c2
MT
630 <tr>
631 <td colspan='4' width='100%'><input type='radio' name='RECONNECTION' value='persistent' $checked{'RECONNECTION'}{'persistent'}>$Lang::tr{'persistent'}</td>
632 </tr>
633 <tr>
634 <td colspan='3' width='75%'>$Lang::tr{'backupprofile'}:</td>
635 <td width='25%'><select name='BACKUPPROFILE' style="width: 165px">
ac1cfefa
MT
636END
637;
638 for ($c = 1; $c <= $maxprofiles; $c++) {
639 print "\t<option value='$c' $selected{'BACKUPPROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
640 }
641 print <<END
642 </select></td>
643</tr>
644END
645;
646}
647print <<END
330345c2
MT
648 <tr>
649 <td colspan='3' width='75%'>$Lang::tr{'dod for dns'}</td>
650 <td width='25%'><input type='checkbox' name='DIALONDEMANDDNS' $checked{'DIALONDEMANDDNS'}{'on'} /></td>
651</tr>
ac1cfefa 652<tr>
330345c2
MT
653 <td colspan='3' width='75%'>$Lang::tr{'holdoff'}:</td>
654 <td width='25%'><input type='text' name='HOLDOFF' value='$pppsettings{'HOLDOFF'}' /></td>
ac1cfefa
MT
655</tr>
656<tr>
330345c2
MT
657 <td colspan='3' width='75%'>$Lang::tr{'maximum retries'}</td>
658 <td width='25%'><input type='text' name='MAXRETRIES' value='$pppsettings{'MAXRETRIES'}' /></td>
ac1cfefa
MT
659</tr>
660END
661;
662
ac1cfefa
MT
663if ($pppsettings{'TYPE'} eq 'pptp')
664{
665print <<END
330345c2 666<tr><td colspan='4' width='100%'><br></br></td></tr>
ac1cfefa 667<tr>
f2fdd0c1 668 <td colspan='4' width='100%' bgcolor='$color{'color20'}'><b>$Lang::tr{'pptp settings'}</b></td>
ac1cfefa
MT
669</tr>
670<tr>
330345c2
MT
671 <td width='25%'>$Lang::tr{'phonebook entry'}</td>
672 <td colspan='2' width='50%'></td>
673 <td width='25%'><input type='text' name='PHONEBOOK' value='$pppsettings{'PHONEBOOK'}' /></td>
ac1cfefa
MT
674</tr>
675<tr>
330345c2
MT
676 <td width='25%'><input type='radio' name='METHOD' value='STATIC' $checked{'METHOD'}{'STATIC'} />$Lang::tr{'static ip'}</td>
677 <td colspan='2' width='50%'>$Lang::tr{'router ip'}</td>
678 <td width='25%'><input type='text' name='ROUTERIP' value='$pppsettings{'ROUTERIP'}' /></td>
ac1cfefa
MT
679</tr>
680<tr>
330345c2
MT
681 <td width='25%'><input type='radio' name='METHOD' value='DHCP' $checked{'METHOD'}{'DHCP'} />$Lang::tr{'dhcp mode'}</td>
682 <td colspan='2' width='50%'>$Lang::tr{'hostname'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
683 <td width='25%'><input type='text' name='DHCP_HOSTNAME' value='$pppsettings{'DHCP_HOSTNAME'}' /></td>
ac1cfefa
MT
684</tr>
685END
686;
687}
a89770fa
MT
688if ($pppsettings{'TYPE'} =~ /^(pppoeatm)$/)
689{
690
691print <<END
692</table>
693<table width='100%'>
694<tr>
695 <td colspan='4' width='100%' bgcolor='$color{'color20'}'><b>$Lang::tr{'adsl settings'}:</b></td>
696</tr>
697<tr>
698
699 <td> $Lang::tr{'encapsulation'}:</td>
700 <td colspan='2' width='30%'>
701 <select name='ENCAP'>
702 <option value='0' $selected{'ENCAP'}{'0'}>LLC</option>
703 <option value='1' $selected{'ENCAP'}{'1'}>VCmux</option>
704 </select>
705 </td>
706</tr>
707<tr>
708
709 <td nowrap='nowrap'>$Lang::tr{'vpi number'}</td>
710 <td><input type='text' size='5' name='VPI' value='$pppsettings{'VPI'}' /></td>
711 <td align='right'>$Lang::tr{'vci number'}</td>
712 <td colspan='2'><input type='text' size='5' name='VCI' value='$pppsettings{'VCI'}' /></td>
713</tr>
714END
715;
716}
717
718
719if ($pppsettings{'TYPE'} eq 'pppoe' || $pppsettings{'TYPE'} eq 'pppoeatm')
ac1cfefa
MT
720{
721print <<END
330345c2 722<tr><td colspan='4' width='100%'><br></br></td></tr>
ac1cfefa 723<tr>
f2fdd0c1 724 <td colspan='4' width='100%' bgcolor='$color{'color20'}'><b>$Lang::tr{'pppoe settings'}</b></td>
ac1cfefa
MT
725</tr>
726<tr>
330345c2
MT
727 <td width='25%'><input type='radio' name='METHOD' value='PPPOE_PLUGIN' $checked{'METHOD'}{'PPPOE_PLUGIN'} />PPPoE plugin</td>
728 <td colspan='2' width='50%'>$Lang::tr{'service name'}&nbsp;<img src='/blob.gif' alt='*' /></td>
729 <td width='25%'><input type='text' name='SERVICENAME' value='$pppsettings{'SERVICENAME'}' /></td>
ac1cfefa
MT
730</tr>
731<tr>
330345c2
MT
732 <td width='25%'><input type='radio' name='METHOD' value='PPPOE' $checked{'METHOD'}{'PPPOE'} />$Lang::tr{'pppoe'}</td>
733 <td colspan='2' width='50%'>$Lang::tr{'concentrator name'}&nbsp;<img src='/blob.gif' alt='*' /></td>
734 <td width='25%'><input type='text' name='CONCENTRATORNAME' value='$pppsettings{'CONCENTRATORNAME'}' /></td>
ac1cfefa 735</tr>
2ed35f39
CS
736<tr>
737 <td width='25%'>MTU</td>
738 <td colspan='2' width='50%'></td>
739 <td width='25%'><input type='text' name='MTU' value='$pppsettings{'MTU'}' /></td>
740</tr>
ac1cfefa
MT
741END
742;
743}
744
ac1cfefa 745print <<END
330345c2 746<tr><td colspan='4' width='100%'><br></br></td></tr>
ac1cfefa 747<tr>
f2fdd0c1 748 <td bgcolor='$color{'color20'}' colspan='4' width='100%'><b>$Lang::tr{'authentication'}</b></td>
ac1cfefa
MT
749</tr>
750<tr>
330345c2
MT
751 <td width='25%'>$Lang::tr{'username'}</td>
752 <td width='25%'><input type='text' name='USERNAME' value='$pppsettings{'USERNAME'}' /></td>
753 <td width='25%'>$Lang::tr{'password'}</td>
754 <td width='25%'><input type='password' name='PASSWORD' value='$pppsettings{'PASSWORD'}' /></td>
ac1cfefa
MT
755</tr>
756<tr>
330345c2
MT
757 <td width='25%'>$Lang::tr{'method'}</td>
758 <td width='25%'><select name='AUTH' style="width: 165px">
ac1cfefa
MT
759 <option value='pap-or-chap' $selected{'AUTH'}{'pap-or-chap'}>$Lang::tr{'pap or chap'}</option>
760 <option value='pap' $selected{'AUTH'}{'pap'}>PAP</option>
761 <option value='chap' $selected{'AUTH'}{'chap'}>CHAP</option>
762END
763;
764if ($pppsettings{'TYPE'} eq 'modem') {
765print <<END
766 <option value='standard-login-script' $selected{'AUTH'}{'standard-login-script'}>$Lang::tr{'standard login script'}</option>
767 <option value='demon-login-script' $selected{'AUTH'}{'demon-login-script'}>$Lang::tr{'demon login script'}</option>
768 <option value='other-login-script' $selected{'AUTH'}{'other-login-script'}>$Lang::tr{'other login script'}</option>
769END
770;
771}
772print <<END
773 </select></td>
330345c2
MT
774 <td width='25%'>$Lang::tr{'script name'}&nbsp;<img src='/blob.gif' alt='*' /></td>
775 <td width='25%'><input type='text' name='LOGINSCRIPT' value='$pppsettings{'LOGINSCRIPT'}' /></td>
ac1cfefa 776</tr>
330345c2 777<tr><td colspan='4' width='100%'><br></br></td></tr>
ac1cfefa 778<tr>
f2fdd0c1 779 <td bgcolor='$color{'color20'}' colspan='4' width='100%'><b>DNS:</b></td>
ac1cfefa
MT
780</tr>
781<tr>
330345c2 782 <td colspan='4' width='100%'><input type='radio' name='DNS' value='Automatic' $checked{'DNS'}{'Automatic'} />$Lang::tr{'automatic'}</td>
ac1cfefa
MT
783</tr>
784<tr>
330345c2 785 <td colspan='4' width='100%'><input type='radio' name='DNS' value='Manual' $checked{'DNS'}{'Manual'} />$Lang::tr{'manual'}</td>
ac1cfefa
MT
786</tr>
787<tr>
330345c2
MT
788 <td width='25%'>$Lang::tr{'primary dns'}</td>
789 <td width='25%'><input type='text' name='DNS1' value='$pppsettings{'DNS1'}'></td>
790 <td width='25%'>$Lang::tr{'secondary dns'}</td>
791 <td width='25%'><input type='text' name='DNS2' value='$pppsettings{'DNS2'}'></td>
ac1cfefa 792</tr>
330345c2 793<tr><td colspan='4' width='100%'><br></br><hr></hr><br></br></td></tr>
ac1cfefa 794<tr>
330345c2
MT
795 <td width='25%'>$Lang::tr{'profile name'}</td>
796 <td width='25%'><input type='text' name='PROFILENAME' value='$pppsettings{'PROFILENAME'}'>
797 <td colspan='2' width='50%'></td>
ac1cfefa
MT
798</tr>
799<tr>
330345c2 800 <td align='center' colspan='4' width='100%'><input type='submit' name='ACTION' value='$Lang::tr{'save'}'></td>
ac1cfefa
MT
801</tr>
802<tr>
330345c2
MT
803 <td colspan='2' width='50%'>$Lang::tr{'legend'}:</td>
804 <td colspan='2' width='50%'><img src='/blob.gif' alt='*' />&nbsp;$Lang::tr{'this field may be blank'}</td>
ac1cfefa
MT
805</tr>
806</table>
807END
808;
809&Header::closebox();
810}
811
812print "</form>\n";
813
814&Header::closebigbox();
815
816&Header::closepage();
817
818sub updatesettings
819{
820 # make a link from the selected profile to the "default" one.
821 unlink("${General::swroot}/ppp/settings");
822 link("${General::swroot}/ppp/settings-$pppsettings{'PROFILE'}",
823 "${General::swroot}/ppp/settings");
9833e7d8 824 system ("/usr/bin/touch", "${General::swroot}/ppp/updatesettings");
ac1cfefa
MT
825}
826
827sub writesecrets
828{
829 # write secrets file.
830 open(FILE, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file.";
831 flock(FILE, 2);
832 my $username = $pppsettings{'USERNAME'};
833 my $password = $pppsettings{'PASSWORD'};
834 print FILE "'$username' * '$password'\n";
835 chmod 0600, "${General::swroot}/ppp/secrets";
836 close FILE;
837}
838
839sub initprofile
840{
841 $pppsettings{'PROFILENAME'} = $Lang::tr{'unnamed'};
842 $pppsettings{'COMPORT'} = 'ttyS0';
843 $pppsettings{'DTERATE'} = 115200;
844 $pppsettings{'SPEAKER'} = 'off';
845 $pppsettings{'RECONNECTION'} = 'manual';
846 $pppsettings{'DIALONDEMANDDNS'} = 'off';
847 $pppsettings{'AUTOCONNECT'} = 'off';
848 $pppsettings{'SENDCR'} = 'off';
849 $pppsettings{'USEIBOD'} = 'off';
850 $pppsettings{'USEDOV'} = 'off';
851 $pppsettings{'MODEM'} = 'PCIST';
852 $pppsettings{'LINE'} = 'WO';
853 $pppsettings{'ENCAP'} = '0';
a89770fa
MT
854 $pppsettings{'VPI'} = '1';
855 $pppsettings{'VCI'} = '32';
ac1cfefa
MT
856 $pppsettings{'PHONEBOOK'} = 'RELAY_PPP1';
857 $pppsettings{'PROTOCOL'} = 'RFC2364';
858 $pppsettings{'METHOD'} = 'PPPOE_PLUGIN';
285c5bbd
MT
859 if ( $pppsettings{'METHOD'} eq 'PPPOE_PLUGIN' ) {
860 $pppsettings{'MTU'} = '1492';
861 $pppsettings{'MRU'} = '1492';
862 } else {
863 $pppsettings{'MTU'} = '1452';
864 $pppsettings{'MRU'} = '1452';
f515baeb 865 }
ac1cfefa
MT
866 $pppsettings{'DIALMODE'} = 'T';
867 $pppsettings{'MAXRETRIES'} = 5;
868 $pppsettings{'HOLDOFF'} = 30;
869 $pppsettings{'TIMEOUT'} = 15;
870 $pppsettings{'MODULATION'} = 'AUTO';
871 $pppsettings{'AUTH'} = 'pap-or-chap';
872 $pppsettings{'DNS'} = 'Automatic';
873 $pppsettings{'DEBUG'} = 'off';
874 $pppsettings{'BACKUPPROFILE'} = $pppsettings{'PROFILE'};
ac1cfefa
MT
875
876 # Get PPPoE settings so we can see if PPPoE is enabled or not.
877 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
878
879 # empty profile partial pre-initialization
cb5e9c6c 880 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) {
ac1cfefa 881 $pppsettings{'TYPE'}=lc($netsettings{'RED_TYPE'});
ac1cfefa
MT
882 } else {
883 $pppsettings{'TYPE'}='modem';
884 }
885}
886