wok-current view ppp/stuff/ppp.cgi @ rev 23684
updated svgcleaner (0.7.1 -> 0.9.5)
author | Hans-G?nter Theisgen |
---|---|
date | Sun Apr 26 17:15:20 2020 +0100 (2020-04-26) |
parents | fa8eccc0015a |
children |
line source
1 #!/bin/sh
2 #
3 # Network/PPP configuration CGI interface
4 #
5 # Copyright (C) 2015 SliTaz GNU/Linux - BSD License
6 #
8 # Common functions from libtazpanel
9 . lib/libtazpanel
10 get_config
13 set_secrets()
14 {
15 grep -qs "^$1 " /etc/ppp/pap-secrets ||
16 echo "$1 * $2" >> /etc/ppp/pap-secrets
17 grep -qs "^$1 " /etc/ppp/chap-secrets ||
18 echo "$1 * $2" >> /etc/ppp/chap-secrets
19 }
22 create_gsm_conf()
23 {
24 local provider="${1:-myGSMprovider}"
25 set_secrets "$provider" "$provider"
26 [ -s /etc/ppp/scripts/gsm.chat ] ||
27 cat > /etc/ppp/scripts/gsm.chat <<EOT
28 ABORT 'BUSY'
29 ABORT 'NO CARRIER'
30 ABORT 'VOICE'
31 ABORT 'NO DIALTONE'
32 ABORT 'NO DIAL TONE'
33 ABORT 'NO ANSWER'
34 ABORT 'DELAYED'
35 REPORT CONNECT
36 TIMEOUT 6
37 '' 'ATQ0'
38 'OK-AT-OK' 'ATZ'
39 TIMEOUT 3
40 'OK' 'ATI'
41 'OK' 'ATZ'
42 'OK' 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0'
43 'OK' 'AT+CGDCONT=1,"IP","$provider"'
44 'OK' 'ATDT*99#'
45 TIMEOUT 30
46 CONNECT ''
47 EOT
48 [ -s /etc/ppp/options-gsm ] ||
49 cat > /etc/ppp/options-gsm << EOT
50 rfcomm0
51 460800
52 lock
53 crtscts
54 modem
55 passive
56 novj
57 defaultroute
58 noipdefault
59 usepeerdns
60 noauth
61 hide-password
62 persist
63 holdoff 10
64 maxfail 0
65 debug
66 EOT
67 [ -s /etc/ppp/peers/gsm ] ||
68 cat > /etc/ppp/peers/gsm << EOT
69 file /etc/ppp/options-gsm
70 user "$provider"
71 password "$provider"
72 connect "/usr/sbin/chat -v -t15 -f /etc/ppp/scripts/gsm.chat"
73 EOT
74 }
77 phone_names()
78 {
79 rfcomm | awk '/connected/{print $2}' | while read mac; do
80 grep -A2 $mac /etc/bluetooth/rfcomm.conf | \
81 sed '/comment/!d;s/.* "\(.*\) modem";/ \1/'
82 done
83 }
86 case "$1" in
87 menu)
88 TEXTDOMAIN_original=$TEXTDOMAIN
89 export TEXTDOMAIN='ppp'
91 groups | grep -q dialout && dialout="" || dialout=" data-root"
92 case "$2" in
93 *VPN*)
94 [ "$(which pptp 2>/dev/null)$(which pptpd 2>/dev/null)" ] && cat <<EOT
95 <li><a data-icon="vpn" href="ppp.cgi#pptp"$dialout>$(_ 'PPTP')</a></li>
96 EOT
97 [ "$(which pppssh 2>/dev/null)" ] && cat <<EOT
98 <li><a data-icon="vpn" href="ppp.cgi#pppssh"$dialout>$(_ 'PPP/SSH')</a></li>
99 EOT
100 ;;
101 *)
102 cat <<EOT
103 <li><a data-icon="modem" href="ppp.cgi"$dialout>$(_ 'PPP Modem')</a></li>
104 EOT
105 esac
106 export TEXTDOMAIN=$TEXTDOMAIN_original
107 exit
108 esac
111 #
112 # Commands
113 #
115 case " $(GET) " in
116 *\ start_pstn\ *)
117 if [ "$(GET user)" ]; then
118 set_secrets "$(GET user)" "$(GET pass)"
119 sed -i 's/^name /d' /etc/ppp/options
120 echo "name $(GET user)" >> /etc/ppp/options
121 /etc/ppp/scripts/ppp-off
122 /etc/ppp/scripts/ppp-on &
123 fi ;;
124 *\ start_gsm\ *)
125 if [ "$(GET gsmprovider)" ]; then
126 [ -n "$(pidof dbus-daemon)" ] || /etc/init.d/dbus start
127 [ -n "$(pidof bluetoothd)" ] || bluetoothd
128 grep -qs btusb /proc/modules || !modprobe btusb || sleep 1
129 if [ -n "$(which bluetoothctl)" ]; then
130 bluetoothctl power on
131 bluetoothctl pairable on
132 bluetoothctl scan on
133 fi
134 hcitool scan | grep : | while read dev name; do
135 set -- $dev "$name" $(sdptool browse $dev | awk '
136 /Service Class ID List/ {n=0}
137 /Dialup Networking/ {n=1}
138 /RFCOMM/ {n++}
139 /Channel/ {if (n==2) { print $2; exit } }')
140 [ -n "$3" ] || continue
141 grep -qs $1 /etc/bluetooth/rfcomm.conf ||
142 cat >> /etc/bluetooth/rfcomm.conf <<EOT
143 rfcomm0 {
144 bind yes;
145 device $1;
146 channel $3;
147 comment "$2 modem";
148 }
149 EOT
150 rfcomm bind all || rfcomm bind 0 $1 $3
151 break
152 done
153 create_gsm_conf "$(GET gsmprovider)"
154 [ -n "$(GET gsmprovider)" ] &&
155 sed -i "s|\"IP\",\".*\"|\"IP\",\"$(GET gsmprovider)\"|" \
156 /etc/ppp/scripts/gsm.chat &&
157 sed -i "s|myGSMprovider|$(GET gsmprovider)|g" \
158 /etc/ppp/chap-secrets /etc/ppp/pap-secrets
159 pppd call gsm
160 host=$(hcitool dev | sed '/hci0/!d;s/.*hci0\t//')
161 pin=$(GET gsmpin)
162 hcitool scan | grep "$1" | while read adrs name ; do
163 echo ${pin:-0000} | bluez-simple-agent $host $adrs
164 done
165 fi ;;
166 *\ stop_pstn\ *|*\ stop_gsm\ *)
167 /etc/ppp/scripts/ppp-off ;;
168 *\ start_pppoe\ *)
169 if [ "$(GET user)" ]; then
170 set_secrets "$(GET user)" "$(GET pass)"
171 grep -qs pppoe /etc/ppp/options || cat > /etc/ppp/options <<EOT
172 plugin rp-pppoe.so
173 noipdefault
174 defaultroute
175 mtu 1492
176 mru 1492
177 lock
178 EOT
179 sed -i 's/^name /d' /etc/ppp/options
180 echo "name $(GET user)" >> /etc/ppp/options
181 ( . /etc/network.conf ; pppd $INTERFACE & )
182 fi ;;
183 *\ stop_pppoe\ *)
184 killall pppd ;;
185 *\ setpppssh\ *)
186 cat > /etc/ppp/pppssh <<EOT
187 PEER="$(GET peer)"
188 SSHARG="$(GET ssharg)"
189 LOCALIP="$(GET localip)"
190 REMOTEIP="$(GET remoteip)"
191 LOCALPPP="$(GET localpppopt)"
192 REMOTEPPP="$(GET remotepppopt)"
193 ROUTES="$(GET routes)"
194 UDP="$(GET udp)"
195 EOT
196 [ "$(GET pass)" ] && export DROPBEAR_PASSWORD="$(GET pass)"
197 case " $(GET) " in
198 *\ send_key\ *)
199 ( dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key ;
200 cat /etc/ssh/ssh_host_rsa_key.pub ) 2> /dev/null | \
201 grep ^ssh | dbclient $(echo $(GET send_key) | sed \
202 's/.*\([A-Za-z0-9_\.-]*\).*/\1/') "mkdir .ssh 2> /dev/null ; \
203 while read key; do for i in authorized_keys authorized_keys2; do \
204 grep -qs '\$key' .ssh/\$i || echo '\$key' >> .ssh/\$i ; done ; done ; \
205 chmod 700 .ssh ; chmod 600 .ssh/authorized_keys*"
206 ;;
207 *\ stop_pppssh\ *)
208 ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)"
209 kill $(busybox ps x | grep "$ppp" | awk '/pty/{next}/dbclient/{print $1}')
210 ;;
211 *\ start_pppssh\ *)
212 pppssh "$(GET ssharg) $(GET peer)" \
213 "$(GET localip):$(GET remoteip) $(GET localpppopt)" \
214 "$(GET remotepppopt)" "$(GET routes)" \
215 "$(GET udp)" > /dev/null &
216 sleep 1
217 ;;
218 esac
219 ;;
220 esac
222 USERNAME="$(sed '/^name/!d;s/^[^ ]* *//' /etc/ppp/options)"
223 PASSWORD="$(awk -v key=$USERNAME "\$1==key{print \$3}" /etc/ppp/pap-secrets)"
224 ACCOUNT="$(sed '/^ACCOUNT=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
225 PASSPSTN="$(sed '/^PASSWORD=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
226 PHONE="$(sed '/^TELEPHONE=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
227 TITLE="$(_ 'TazPanel - Network') - $(_ 'PPP Connections')"
228 header
229 xhtml_header | sed 's/id="content"/id="content-sidebar"/'
230 cat << EOT
231 <div id="sidebar">
232 <section>
233 <header>
234 $(_ 'Documentation')
235 </header>
236 <a data-icon="web" href="http://ppp.samba.org/" target="_blank" rel="noopener">$(_ 'PPP web page')</a><p>
237 <a data-icon="help" href="index.cgi?exec=pppd%20--help" target="_blank" rel="noopener">$(_ 'PPP help')</a><p>
238 <a data-icon="help" href="index.cgi?exec=man%20pppd" target="_blank" rel="noopener">$(_ 'PPP Manual')</a><p>
239 <a data-icon="web" href="https://en.wikipedia.org/wiki/Hayes_command_set" target="_blank" rel="noopener">$(_ 'Hayes codes')</a><p>
240 EOT
241 [ "$(which pptp 2>/dev/null)" ] && cat <<EOT
242 <a data-icon="web" href="http://pptpclient.sourceforge.net/" target="_blank" rel="noopener">$(_n 'PPTP web page')</a><p>
243 <a data-icon="help" href="index.cgi?exec=pptp" target="_blank" rel="noopener">$(_ 'PPTP Help')</a><p>
244 EOT
245 [ "$(which pptpd 2>/dev/null)" ] && cat <<EOT
246 <a data-icon="web" href="http://poptop.sourceforge.net/" target="_blank" rel="noopener">$(_n 'PPTPD web page')</a><p>
247 <a data-icon="help" href="index.cgi?exec=pptpd%20--help" target="_blank" rel="noopener">$(_ 'PPTPD Help')</a><p>
248 EOT
249 [ "$(which pppssh 2>/dev/null)" ] && cat <<EOT
250 <a data-icon="web" href="http://doc.slitaz.org/en:guides:vpn" target="_blank" rel="noopener">$(_n 'VPN Wiki')</a><p>
251 <a data-icon="help" href="index.cgi?exec=dbclient" target="_blank" rel="noopener">$(_ 'SSH Help')</a><p>
252 EOT
253 cat << EOT
254 <footer>
255 </footer>
256 </section>
257 <section>
258 <header>
259 $(_ 'Configuration')
260 </header>
261 EOT
262 [ "$(which sdptool 2>/dev/null)" ] && create_gsm_conf && cat <<EOT
263 <a data-icon="conf" href="index.cgi?file=/etc/bluetooth/rfcomm.conf" target="_blank" rel="noopener">$(_ 'GSM device')</a><p>
264 <a data-icon="conf" href="index.cgi?file=/etc/ppp/peers/gsm" target="_blank" rel="noopener">$(_ 'PPP GSM script')</a><p>
265 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/gsm.chat" target="_blank" rel="noopener">$(_ 'PPP GSM chat')</a><p>
266 <a data-icon="conf" href="index.cgi?file=/etc/ppp/options-gsm" target="_blank" rel="noopener">$(_ 'PPP GSM options')</a><p>
267 EOT
268 cat << EOT
269 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on" target="_blank" rel="noopener">$(_ 'PPP PSTN script')</a><p>
270 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on-dialer" target="_blank" rel="noopener">$(_ 'PPP PSTN chat')</a><p>
271 <a data-icon="conf" href="index.cgi?file=/etc/ppp/options" target="_blank" rel="noopener">$(_ 'PPP PSTN options')</a><p>
272 <a data-icon="conf" href="index.cgi?file=/etc/ppp/chap-secrets" target="_blank" rel="noopener">$(_ 'chap users')</a><p>
273 <a data-icon="conf" href="index.cgi?file=/etc/ppp/pap-secrets" target="_blank" rel="noopener">$(_ 'pap users')</a><p>
274 EOT
275 for i in /etc/ppp/peers/* ; do
276 [ -s "$i" ] && [ "$i" != "/etc/ppp/peers/gsm" ] && cat << EOT
277 <a data-icon="conf" href="index.cgi?file=$i" target="_blank" rel="noopener">$(basename $i)</a><p>
278 EOT
279 done
280 [ "$(which pptpd 2>/dev/null)" ] && cat <<EOT
281 <a data-icon="conf" href="index.cgi?file=/etc/pptpd.conf" target="_blank" rel="noopener">$(_ 'pptpd.conf')</a><p>
282 EOT
283 if [ "$(busybox ps x | grep "pppd" | awk '/modem/{print $1}')" ]; then
284 start_disabled='disabled'
285 else
286 stop_disabled='disabled'
287 fi
288 if [ "$(busybox ps x | grep "pppd" | awk '/eth/{print $1}')" ]; then
289 startoe_disabled='disabled'
290 else
291 stopoe_disabled='disabled'
292 fi
293 if [ "$(busybox ps x | grep "pppd" | awk '/gsm/{print $1}')" ]; then
294 startgsm_disabled='disabled'
295 else
296 stopgsm_disabled='disabled'
297 fi
298 head=" <footer>
299 </footer>
300 </section>
301 <section>
302 <header>
303 $(_ 'Install extra')
304 </header>"
305 while read file pkg name ; do
306 [ -z "$(which $file 2>/dev/null)" ] && echo $head && head="" &&
307 echo " <a href='pkgs.cgi?do=Install&pkg=$pkg'>$name</a>"
308 done <<EOT
309 sdptool bluez GSM / Bluetooth
310 pppssh dropbear SSH / VPN
311 EOT
312 #pptp pptpclient PPTP client
313 #pptpd poptop PPTP server
314 cat << EOT
315 <footer>
316 </footer>
317 </section>
318 </div>
320 EOT
321 if [ "$(which sdptool 2>/dev/null)" ]; then
322 cat <<EOT
323 <a name="pppgsm"></a>
324 <section>
325 <header>
326 <span data-icon="modem">$(_ 'GSM modem') -
327 $(_ 'Manage Bluetooth GSM Internet connections')</span>
328 </header>
329 <form method="get">
330 <input type="hidden" name="setpppgsm" />
331 <table>
332 <tr>
333 <td>$(_ 'GSM provider')</td>
334 <td><input type="text" name="gsmprovider" size="40" value="$(sed \
335 '/AT+CGDCONT/!d;s|.*IP","\(.*\)".|\1|' \
336 /etc/ppp/scripts/gsm.chat 2> /dev/null)" /></td>
337 </tr>
338 <tr>
339 <td>$(_ 'Bluetooth PIN')</td>
340 <td><input type="text" name="gsmpin" size="40" value="0000" /></td>
341 </tr>
342 </table>
343 <footer><!--
344 --><button type="submit" name="start_gsm" data-icon="start" $startgsm_disabled>$(_ 'Start' )</button><!--
345 --><button type="submit" name="stop_gsm" data-icon="stop" $stopgsm_disabled>$(_ 'Stop' )</button><!--
346 -->$(phone_names)</footer>
347 </form>
348 </section>
349 EOT
350 fi
351 cat << EOT
352 <a name="ppppstn"></a>
353 <section>
354 <header>
355 <span data-icon="modem">$(_ 'PSTN modem') -
356 $(_ 'Manage PSTN Internet connections')</span>
357 </header>
358 <form action="index.cgi" id="indexform"></form>
359 <form method="get">
360 <input type="hidden" name="setppppstn" />
361 <table>
362 <tr>
363 <td>$(_ 'Username')</td>
364 <td><input type="text" name="user" size="40" value="$ACCOUNT" /></td>
365 </tr>
366 <tr>
367 <td>$(_ 'Password')</td>
368 <td><input type="text" name="pass" size="40" value="$PASSPSTN" /></td>
369 </tr>
370 <tr>
371 <td>$(_ 'Phone number')</td>
372 <td><input type="text" name="phone" size="40" value="$PHONE" /></td>
373 </tr>
374 </table>
375 <footer><!--
376 --><button type="submit" name="start_pstn" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
377 --><button type="submit" name="stop_pstn" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
378 --></footer>
379 </form>
380 </section>
382 <a name="pppoe"></a>
383 <section>
384 <header>
385 <span data-icon="eth">$(_ 'Cable Modem') -
386 $(_ 'Manage PPPoE Internet connections')</span>
387 </header>
388 <form method="get">
389 <input type="hidden" name="setpppoe" />
390 <table>
391 <tr>
392 <td>$(_ 'Username')</td>
393 <td><input type="text" name="user" size="40" value="$USERNAME" /></td>
394 </tr>
395 <tr>
396 <td>$(_ 'Password')</td>
397 <td><input type="text" name="pass" size="40" value="$PASSWORD" /></td>
398 </tr>
399 </table>
400 <footer><!--
401 --><button type="submit" name="start_pppoe" data-icon="start" $startoe_disabled>$(_ 'Start' )</button><!--
402 --><button type="submit" name="stop_pppoe" data-icon="stop" $stopoe_disabled >$(_ 'Stop' )</button><!--
403 --></footer>
404 </form>
405 </section>
406 EOT
407 if [ "$(which pppssh 2>/dev/null)" ]; then
408 [ -s /etc/ppp/pppssh ] && . /etc/ppp/pppssh
409 ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)"
410 if [ "$(busybox ps x | grep "$ppp" | awk '/dbclient/{print $1}')" ]; then
411 startssh_disabled='disabled'
412 else
413 stopssh_disabled='disabled'
414 fi
415 cat <<EOT
416 <a name="pppssh"></a>
417 <section>
418 <header>
419 <span data-icon="vpn">$(_ 'Virtual Private Network') -
420 $(_ 'Manage private TCP/IP connections')</span>
421 </header>
422 <form method="get">
423 <input type="hidden" name="setpppssh" />
424 <table>
425 <tr>
426 <td>$(_ 'Peer')</td>
427 <td><input type="text" name="peer" size="50" value="${PEER:-user@elsewhere}" /></td>
428 </tr>
429 <tr>
430 <td>$(_ 'SSH options')</td>
431 <td><input type="text" name="ssharg" size="50" value="$SSHARG" /></td>
432 </tr>
433 <tr>
434 <td>$(_ 'Password')</td>
435 <td><input type="password" name="pass" size="50" title="Should be empty to use the SSH key; useful to send the SSH key only" /></td>
436 </tr>
437 <tr>
438 <td>$(_ 'Local IP address')</td>
439 <td><input type="text" name="localip" size="50" value="${LOCALIP:-192.168.254.1}" /></td>
440 </tr>
441 <tr>
442 <td>$(_ 'Remote IP address')</td>
443 <td><input type="text" name="remoteip" size="50" value="${REMOTEIP:-192.168.254.2}" /></td>
444 </tr>
445 <tr>
446 <td>$(_ 'Local PPP options')</td>
447 <td><input type="text" name="localpppopt" size="50" value="${LOCALPPP:-usepeerdns}" /></td>
448 </tr>
449 <tr>
450 <td>$(_ 'Remote PPP options')</td>
451 <td><input type="text" name="remotepppopt" size="50" value="${REMOTEPPP:-proxyarp}" title="$(_ "You may need 'proxyarp' to use the new routes")" /></td>
452 </tr>
453 <tr>
454 <td>$(_ 'Peer routes')</td>
455 <td><input type="text" name="routes" size="50" value="${ROUTES:-192.168.10.0/24 192.168.20.0/28}" title="$(_ "Routes on peer network to import or 'default' to redirect the default route")"/></td>
456 </tr>
457 <tr>
458 <td>$(_ 'UDP port')</td>
459 <td><input type="text" name="udp" size="50" value="$UDP" title="$(_ "Optional UDP port for real-time (with a very reliable link only)")"/></td>
460 </tr>
461 </table>
462 <footer><!--
463 --><button type="submit" name="start_pppssh" data-icon="start" $startssh_disabled>$(_ 'Start' )</button><!--
464 --><button type="submit" name="stop_pppssh" data-icon="stop" $stopssh_disabled>$(_ 'Stop' )</button><!--
465 --><button type="submit" name="send_key" data-icon="sync" >$(_ 'Send SSH key' )</button><!--
466 --></footer>
467 </form>
468 </section>
469 EOT
470 fi
472 xhtml_footer
473 exit 0