wok-6.x view ppp/stuff/ppp.cgi @ rev 20411
ppp/ppp.cgi: add gsm/bluetooth support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Aug 01 09:50:52 2018 +0200 (2018-08-01) |
parents | df2a96b56a0f |
children | 543e0fa614bc |
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
129 hcitool scan | grep : | while read dev name; do
130 set -- $dev "$name" $(sdptool browse $dev | awk '
131 /Service Class ID List/ {n=0}
132 /Dialup Networking/ {n=1}
133 /RFCOMM/ {n++}
134 /Channel/ {if (n==2) { print $2; exit } }')
135 [ -n "$3" ] || continue
136 grep -qs $1 /etc/bluetooth/rfcomm.conf ||
137 cat >> /etc/bluetooth/rfcomm.conf <<EOT
138 rfcomm0 {
139 bind yes;
140 device $1;
141 channel $3;
142 comment "$2 modem";
143 }
144 EOT
145 rfcomm bind all || rfcomm bind 0 $1 $3
146 break
147 done
148 create_gsm_conf "$(GET gsmprovider)"
149 [ -n "$(GET gsmprovider)" ] &&
150 sed -i "s|\"IP\",\".*\"|\"IP\",\"$(GET gsmprovider)\"|" \
151 /etc/ppp/scripts/gsm.chat &&
152 sed -i "s|myGSMprovider|$(GET gsmprovider)|g" \
153 /etc/ppp/chap-secrets /etc/ppp/pap-secrets
154 pppd call gsm
155 host=$(hcitool dev | sed '/hci0/!d;s/.*hci0\t//')
156 pin=$(GET gsmpin)
157 hcitool scan | grep "$1" | while read adrs name ; do
158 echo ${pin:-0000} | bluez-simple-agent $host $adrs
159 done
160 fi ;;
161 *\ stop_pstn\ *|*\ stop_gsm\ *)
162 /etc/ppp/scripts/ppp-off ;;
163 *\ start_pppoe\ *)
164 if [ "$(GET user)" ]; then
165 set_secrets "$(GET user)" "$(GET pass)"
166 grep -qs pppoe /etc/ppp/options || cat > /etc/ppp/options <<EOT
167 plugin rp-pppoe.so
168 noipdefault
169 defaultroute
170 mtu 1492
171 mru 1492
172 lock
173 EOT
174 sed -i 's/^name /d' /etc/ppp/options
175 echo "name $(GET user)" >> /etc/ppp/options
176 ( . /etc/network.conf ; pppd $INTERFACE & )
177 fi ;;
178 *\ stop_pppoe\ *)
179 killall pppd ;;
180 *\ setpppssh\ *)
181 cat > /etc/ppp/pppssh <<EOT
182 PEER="$(GET peer)"
183 SSHARG="$(GET ssharg)"
184 LOCALIP="$(GET localip)"
185 REMOTEIP="$(GET remoteip)"
186 LOCALPPP="$(GET localpppopt)"
187 REMOTEPPP="$(GET remotepppopt)"
188 ROUTES="$(GET routes)"
189 UDP="$(GET udp)"
190 EOT
191 [ "$(GET pass)" ] && export DROPBEAR_PASSWORD="$(GET pass)"
192 case " $(GET) " in
193 *\ send_key\ *)
194 ( dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key ;
195 cat /etc/ssh/ssh_host_rsa_key.pub ) 2> /dev/null | \
196 grep ^ssh | dbclient $(echo $(GET send_key) | sed \
197 's/.*\([A-Za-z0-9_\.-]*\).*/\1/') "mkdir .ssh 2> /dev/null ; \
198 while read key; do for i in authorized_keys authorized_keys2; do \
199 grep -qs '\$key' .ssh/\$i || echo '\$key' >> .ssh/\$i ; done ; done ; \
200 chmod 700 .ssh ; chmod 600 .ssh/authorized_keys*"
201 ;;
202 *\ stop_pppssh\ *)
203 ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)"
204 kill $(busybox ps x | grep "$ppp" | awk '/pty/{next}/dbclient/{print $1}')
205 ;;
206 *\ start_pppssh\ *)
207 EOT
208 pppssh "$(GET ssharg) $(GET peer)" \
209 "$(GET localip):$(GET remoteip) $(GET localpppopt)" \
210 "$(GET remotepppopt)" "$(GET routes)" "$(GET udp)" &
211 ;;
212 esac
213 ;;
214 esac
216 USERNAME="$(sed '/^name/!d;s/^[^ ]* *//' /etc/ppp/options)"
217 PASSWORD="$(awk -v key=$USERNAME "\$1==key{print \$3}" /etc/ppp/pap-secrets)"
218 ACCOUNT="$(sed '/^ACCOUNT=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
219 PASSPSTN="$(sed '/^PASSWORD=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
220 PHONE="$(sed '/^TELEPHONE=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
221 TITLE="$(_ 'TazPanel - Network') - $(_ 'PPP Connections')"
222 header
223 xhtml_header | sed 's/id="content"/id="content-sidebar"/'
224 cat << EOT
225 <div id="sidebar">
226 <section>
227 <header>
228 $(_ 'Documentation')
229 </header>
230 <a data-icon="web" href="http://ppp.samba.org/" target="_blank" rel="noopener">$(_ 'PPP web page')</a><p>
231 <a data-icon="help" href="index.cgi?exec=pppd%20--help" target="_blank" rel="noopener">$(_ 'PPP help')</a><p>
232 <a data-icon="help" href="index.cgi?exec=man%20pppd" target="_blank" rel="noopener">$(_ 'PPP Manual')</a><p>
233 EOT
234 [ "$(which pptp 2>/dev/null)" ] && cat <<EOT
235 <a data-icon="web" href="http://pptpclient.sourceforge.net/" target="_blank" rel="noopener">$(_n 'PPTP web page')</a><p>
236 <a data-icon="help" href="index.cgi?exec=pptp" target="_blank" rel="noopener">$(_ 'PPTP Help')</a><p>
237 EOT
238 [ "$(which pptpd 2>/dev/null)" ] && cat <<EOT
239 <a data-icon="web" href="http://poptop.sourceforge.net/" target="_blank" rel="noopener">$(_n 'PPTPD web page')</a><p>
240 <a data-icon="help" href="index.cgi?exec=pptpd%20--help" target="_blank" rel="noopener">$(_ 'PPTPD Help')</a><p>
241 EOT
242 [ "$(which pppssh 2>/dev/null)" ] && cat <<EOT
243 <a data-icon="web" href="http://doc.slitaz.org/en:guides:vpn" target="_blank" rel="noopener">$(_n 'VPN Wiki')</a><p>
244 <a data-icon="help" href="index.cgi?exec=dbclient" target="_blank" rel="noopener">$(_ 'SSH Help')</a><p>
245 EOT
246 cat << EOT
247 <footer>
248 </footer>
249 </section>
250 <section>
251 <header>
252 $(_ 'Configuration')
253 </header>
254 EOT
255 [ "$(which sdptool 2>/dev/null)" ] && create_gsm_conf && cat <<EOT
256 <a data-icon="conf" href="index.cgi?file=/etc/bluetooth/rfcomm.conf" target="_blank" rel="noopener">$(_ 'GSM device')</a><p>
257 <a data-icon="conf" href="index.cgi?file=/etc/ppp/peers/gsm" target="_blank" rel="noopener">$(_ 'PPP GSM script')</a><p>
258 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/gsm.chat" target="_blank" rel="noopener">$(_ 'PPP GSM chat')</a><p>
259 <a data-icon="conf" href="index.cgi?file=/etc/ppp/options-gsm" target="_blank" rel="noopener">$(_ 'PPP GSM options')</a><p>
260 EOT
261 cat << EOT
262 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on" target="_blank" rel="noopener">$(_ 'PPP PSTN script')</a><p>
263 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on-dialer" target="_blank" rel="noopener">$(_ 'PPP PSTN chat')</a><p>
264 <a data-icon="conf" href="index.cgi?file=/etc/ppp/options" target="_blank" rel="noopener">$(_ 'PPP PSTN options')</a><p>
265 <a data-icon="conf" href="index.cgi?file=/etc/ppp/chap-secrets" target="_blank" rel="noopener">$(_ 'chap users')</a><p>
266 <a data-icon="conf" href="index.cgi?file=/etc/ppp/pap-secrets" target="_blank" rel="noopener">$(_ 'pap users')</a><p>
267 EOT
268 for i in /etc/ppp/peers/* ; do
269 [ -s "$i" ] && [ "$i" != "/etc/ppp/peers/gsm" ] && cat << EOT
270 <a data-icon="conf" href="index.cgi?file=$i" target="_blank" rel="noopener">$(basename $i)</a><p>
271 EOT
272 done
273 [ "$(which pptpd 2>/dev/null)" ] && cat <<EOT
274 <a data-icon="conf" href="index.cgi?file=/etc/pptpd.conf" target="_blank" rel="noopener">$(_ 'pptpd.conf')</a><p>
275 EOT
276 if [ "$(busybox ps x | grep "pppd" | awk '/modem/{print $1}')" ]; then
277 start_disabled='disabled'
278 else
279 stop_disabled='disabled'
280 fi
281 if [ "$(busybox ps x | grep "pppd" | awk '/eth/{print $1}')" ]; then
282 startoe_disabled='disabled'
283 else
284 stopoe_disabled='disabled'
285 fi
286 if [ "$(busybox ps x | grep "pppd" | awk '/gsm/{print $1}')" ]; then
287 startgsm_disabled='disabled'
288 else
289 stopgsm_disabled='disabled'
290 fi
291 head=" <footer>
292 </footer>
293 </section>
294 <section>
295 <header>
296 $(_ 'Install extra')
297 </header>"
298 while read file pkg name ; do
299 [ -z "$(which $file 2>/dev/null)" ] && echo $head && head="" &&
300 echo " <a href='pkgs.cgi?do=Install&pkg=$pkg'>$name</a>"
301 done <<EOT
302 sdptool bluez GSM / Bluetooth
303 pppssh dropbear SSH / VPN
304 EOT
305 #pptp pptpclient PPTP client
306 #pptpd poptop PPTP server
307 cat << EOT
308 <footer>
309 </footer>
310 </section>
311 </div>
313 EOT
314 if [ "$(which sdptool 2>/dev/null)" ]; then
315 cat <<EOT
316 <a name="pppgsm"></a>
317 <section>
318 <header>
319 <span data-icon="modem">$(_ 'GSM modem') -
320 $(_ 'Manage Bluetooth GSM Internet connections')</span>
321 </header>
322 <form method="get">
323 <input type="hidden" name="setpppgsm" />
324 <table>
325 <tr>
326 <td>$(_ 'GSM provider')</td>
327 <td><input type="text" name="gsmprovider" size="40" value="$(sed \
328 '/AT+CGDCONT/!d;s|.*IP","\(.*\)".|\1|' \
329 /etc/ppp/scripts/gsm.chat 2> /dev/null)" /></td>
330 </tr>
331 <tr>
332 <td>$(_ 'Bluetooth PIN')</td>
333 <td><input type="text" name="gsmpin" size="40" value="0000" /></td>
334 </tr>
335 </table>
336 <footer><!--
337 --><button type="submit" name="start_gsm" data-icon="start" $startgsm_disabled>$(_ 'Start' )</button><!--
338 --><button type="submit" name="stop_gsm" data-icon="stop" $stopgsm_disabled>$(_ 'Stop' )</button><!--
339 -->$(phone_names)</footer>
340 </form>
341 </section>
342 EOT
343 fi
344 cat << EOT
345 <a name="ppppstn"></a>
346 <section>
347 <header>
348 <span data-icon="modem">$(_ 'PSTN modem') -
349 $(_ 'Manage PSTN Internet connections')</span>
350 </header>
351 <form action="index.cgi" id="indexform"></form>
352 <form method="get">
353 <input type="hidden" name="setppppstn" />
354 <table>
355 <tr>
356 <td>$(_ 'Username')</td>
357 <td><input type="text" name="user" size="40" value="$ACCOUNT" /></td>
358 </tr>
359 <tr>
360 <td>$(_ 'Password')</td>
361 <td><input type="text" name="pass" size="40" value="$PASSPSTN" /></td>
362 </tr>
363 <tr>
364 <td>$(_ 'Phone number')</td>
365 <td><input type="text" name="phone" size="40" value="$PHONE" /></td>
366 </tr>
367 </table>
368 <footer><!--
369 --><button type="submit" name="start_pstn" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
370 --><button type="submit" name="stop_pstn" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
371 --></footer>
372 </form>
373 </section>
375 <a name="pppoe"></a>
376 <section>
377 <header>
378 <span data-icon="eth">$(_ 'Cable Modem') -
379 $(_ 'Manage PPPoE Internet connections')</span>
380 </header>
381 <form method="get">
382 <input type="hidden" name="setpppoe" />
383 <table>
384 <tr>
385 <td>$(_ 'Username')</td>
386 <td><input type="text" name="user" size="40" value="$USERNAME" /></td>
387 </tr>
388 <tr>
389 <td>$(_ 'Password')</td>
390 <td><input type="text" name="pass" size="40" value="$PASSWORD" /></td>
391 </tr>
392 </table>
393 <footer><!--
394 --><button type="submit" name="start_pppoe" data-icon="start" $startoe_disabled>$(_ 'Start' )</button><!--
395 --><button type="submit" name="stop_pppoe" data-icon="stop" $stopoe_disabled >$(_ 'Stop' )</button><!--
396 --></footer>
397 </form>
398 </section>
399 EOT
400 if [ "$(which pppssh 2>/dev/null)" ]; then
401 [ -s /etc/ppp/pppssh ] && . /etc/ppp/pppssh
402 ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)"
403 if [ "$(busybox ps x | grep "$ppp" | awk '/dbclient/{print $1}')" ]; then
404 startssh_disabled='disabled'
405 else
406 stopssh_disabled='disabled'
407 fi
408 cat <<EOT
409 <a name="pppssh"></a>
410 <section>
411 <header>
412 <span data-icon="vpn">$(_ 'Virtual Private Network') -
413 $(_ 'Manage private TCP/IP connections')</span>
414 </header>
415 <form method="get">
416 <input type="hidden" name="setpppssh" />
417 <table>
418 <tr>
419 <td>$(_ 'Peer')</td>
420 <td><input type="text" name="peer" size="50" value="${PEER:-user@elsewhere}" /></td>
421 </tr>
422 <tr>
423 <td>$(_ 'SSH options')</td>
424 <td><input type="text" name="ssharg" size="50" value="$SSHARG" /></td>
425 </tr>
426 <tr>
427 <td>$(_ 'Password')</td>
428 <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>
429 </tr>
430 <tr>
431 <td>$(_ 'Local IP address')</td>
432 <td><input type="text" name="localip" size="50" value="${LOCALIP:-192.168.254.1}" /></td>
433 </tr>
434 <tr>
435 <td>$(_ 'Remote IP address')</td>
436 <td><input type="text" name="remoteip" size="50" value="${REMOTEIP:-192.168.254.2}" /></td>
437 </tr>
438 <tr>
439 <td>$(_ 'Local PPP options')</td>
440 <td><input type="text" name="localpppopt" size="50" value="$LOCALPPP" /></td>
441 </tr>
442 <tr>
443 <td>$(_ 'Remote PPP options')</td>
444 <td><input type="text" name="remotepppopt" size="50" value="${REMOTEPPP:-proxyarp}" title="$(_ "You may need 'proxyarp' to use the new routes")" /></td>
445 </tr>
446 <tr>
447 <td>$(_ 'Peer routes')</td>
448 <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>
449 </tr>
450 <tr>
451 <td>$(_ 'UDP port')</td>
452 <td><input type="text" name="udp" size="50" value="$UDP" title="$(_ "Optional UDP port for a real-time but unencrypted link")"/></td>
453 </tr>
454 </table>
455 <footer><!--
456 --><button type="submit" name="start_pppssh" data-icon="start" $startssh_disabled>$(_ 'Start' )</button><!--
457 --><button type="submit" name="stop_pppssh" data-icon="stop" $stopssh_disabled>$(_ 'Stop' )</button><!--
458 --><button type="submit" name="send_key" data-icon="sync" >$(_ 'Send SSH key' )</button><!--
459 --></footer>
460 </form>
461 </section>
462 EOT
463 fi
465 xhtml_footer
466 exit 0