wok view ppp/stuff/ppp.cgi @ rev 21718
updated protobuf-python again (2.4.1 -> 3.8.0)
author | Hans-G?nter Theisgen |
---|---|
date | Wed Jun 12 13:51:36 2019 +0100 (2019-06-12) |
parents | e0d366200e99 |
children | c34ef09acb7c |
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 <a data-icon="web" href="https://en.wikipedia.org/wiki/Hayes_command_set" target="_blank" rel="noopener">$(_ 'Hayes codes')</a><p>
234 EOT
235 [ "$(which pptp 2>/dev/null)" ] && cat <<EOT
236 <a data-icon="web" href="http://pptpclient.sourceforge.net/" target="_blank" rel="noopener">$(_n 'PPTP web page')</a><p>
237 <a data-icon="help" href="index.cgi?exec=pptp" target="_blank" rel="noopener">$(_ 'PPTP Help')</a><p>
238 EOT
239 [ "$(which pptpd 2>/dev/null)" ] && cat <<EOT
240 <a data-icon="web" href="http://poptop.sourceforge.net/" target="_blank" rel="noopener">$(_n 'PPTPD web page')</a><p>
241 <a data-icon="help" href="index.cgi?exec=pptpd%20--help" target="_blank" rel="noopener">$(_ 'PPTPD Help')</a><p>
242 EOT
243 [ "$(which pppssh 2>/dev/null)" ] && cat <<EOT
244 <a data-icon="web" href="http://doc.slitaz.org/en:guides:vpn" target="_blank" rel="noopener">$(_n 'VPN Wiki')</a><p>
245 <a data-icon="help" href="index.cgi?exec=dbclient" target="_blank" rel="noopener">$(_ 'SSH Help')</a><p>
246 EOT
247 cat << EOT
248 <footer>
249 </footer>
250 </section>
251 <section>
252 <header>
253 $(_ 'Configuration')
254 </header>
255 EOT
256 [ "$(which sdptool 2>/dev/null)" ] && create_gsm_conf && cat <<EOT
257 <a data-icon="conf" href="index.cgi?file=/etc/bluetooth/rfcomm.conf" target="_blank" rel="noopener">$(_ 'GSM device')</a><p>
258 <a data-icon="conf" href="index.cgi?file=/etc/ppp/peers/gsm" target="_blank" rel="noopener">$(_ 'PPP GSM script')</a><p>
259 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/gsm.chat" target="_blank" rel="noopener">$(_ 'PPP GSM chat')</a><p>
260 <a data-icon="conf" href="index.cgi?file=/etc/ppp/options-gsm" target="_blank" rel="noopener">$(_ 'PPP GSM options')</a><p>
261 EOT
262 cat << EOT
263 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on" target="_blank" rel="noopener">$(_ 'PPP PSTN script')</a><p>
264 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on-dialer" target="_blank" rel="noopener">$(_ 'PPP PSTN chat')</a><p>
265 <a data-icon="conf" href="index.cgi?file=/etc/ppp/options" target="_blank" rel="noopener">$(_ 'PPP PSTN options')</a><p>
266 <a data-icon="conf" href="index.cgi?file=/etc/ppp/chap-secrets" target="_blank" rel="noopener">$(_ 'chap users')</a><p>
267 <a data-icon="conf" href="index.cgi?file=/etc/ppp/pap-secrets" target="_blank" rel="noopener">$(_ 'pap users')</a><p>
268 EOT
269 for i in /etc/ppp/peers/* ; do
270 [ -s "$i" ] && [ "$i" != "/etc/ppp/peers/gsm" ] && cat << EOT
271 <a data-icon="conf" href="index.cgi?file=$i" target="_blank" rel="noopener">$(basename $i)</a><p>
272 EOT
273 done
274 [ "$(which pptpd 2>/dev/null)" ] && cat <<EOT
275 <a data-icon="conf" href="index.cgi?file=/etc/pptpd.conf" target="_blank" rel="noopener">$(_ 'pptpd.conf')</a><p>
276 EOT
277 if [ "$(busybox ps x | grep "pppd" | awk '/modem/{print $1}')" ]; then
278 start_disabled='disabled'
279 else
280 stop_disabled='disabled'
281 fi
282 if [ "$(busybox ps x | grep "pppd" | awk '/eth/{print $1}')" ]; then
283 startoe_disabled='disabled'
284 else
285 stopoe_disabled='disabled'
286 fi
287 if [ "$(busybox ps x | grep "pppd" | awk '/gsm/{print $1}')" ]; then
288 startgsm_disabled='disabled'
289 else
290 stopgsm_disabled='disabled'
291 fi
292 head=" <footer>
293 </footer>
294 </section>
295 <section>
296 <header>
297 $(_ 'Install extra')
298 </header>"
299 while read file pkg name ; do
300 [ -z "$(which $file 2>/dev/null)" ] && echo $head && head="" &&
301 echo " <a href='pkgs.cgi?do=Install&pkg=$pkg'>$name</a>"
302 done <<EOT
303 sdptool bluez GSM / Bluetooth
304 pppssh dropbear SSH / VPN
305 EOT
306 #pptp pptpclient PPTP client
307 #pptpd poptop PPTP server
308 cat << EOT
309 <footer>
310 </footer>
311 </section>
312 </div>
314 EOT
315 if [ "$(which sdptool 2>/dev/null)" ]; then
316 cat <<EOT
317 <a name="pppgsm"></a>
318 <section>
319 <header>
320 <span data-icon="modem">$(_ 'GSM modem') -
321 $(_ 'Manage Bluetooth GSM Internet connections')</span>
322 </header>
323 <form method="get">
324 <input type="hidden" name="setpppgsm" />
325 <table>
326 <tr>
327 <td>$(_ 'GSM provider')</td>
328 <td><input type="text" name="gsmprovider" size="40" value="$(sed \
329 '/AT+CGDCONT/!d;s|.*IP","\(.*\)".|\1|' \
330 /etc/ppp/scripts/gsm.chat 2> /dev/null)" /></td>
331 </tr>
332 <tr>
333 <td>$(_ 'Bluetooth PIN')</td>
334 <td><input type="text" name="gsmpin" size="40" value="0000" /></td>
335 </tr>
336 </table>
337 <footer><!--
338 --><button type="submit" name="start_gsm" data-icon="start" $startgsm_disabled>$(_ 'Start' )</button><!--
339 --><button type="submit" name="stop_gsm" data-icon="stop" $stopgsm_disabled>$(_ 'Stop' )</button><!--
340 -->$(phone_names)</footer>
341 </form>
342 </section>
343 EOT
344 fi
345 cat << EOT
346 <a name="ppppstn"></a>
347 <section>
348 <header>
349 <span data-icon="modem">$(_ 'PSTN modem') -
350 $(_ 'Manage PSTN Internet connections')</span>
351 </header>
352 <form action="index.cgi" id="indexform"></form>
353 <form method="get">
354 <input type="hidden" name="setppppstn" />
355 <table>
356 <tr>
357 <td>$(_ 'Username')</td>
358 <td><input type="text" name="user" size="40" value="$ACCOUNT" /></td>
359 </tr>
360 <tr>
361 <td>$(_ 'Password')</td>
362 <td><input type="text" name="pass" size="40" value="$PASSPSTN" /></td>
363 </tr>
364 <tr>
365 <td>$(_ 'Phone number')</td>
366 <td><input type="text" name="phone" size="40" value="$PHONE" /></td>
367 </tr>
368 </table>
369 <footer><!--
370 --><button type="submit" name="start_pstn" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
371 --><button type="submit" name="stop_pstn" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
372 --></footer>
373 </form>
374 </section>
376 <a name="pppoe"></a>
377 <section>
378 <header>
379 <span data-icon="eth">$(_ 'Cable Modem') -
380 $(_ 'Manage PPPoE Internet connections')</span>
381 </header>
382 <form method="get">
383 <input type="hidden" name="setpppoe" />
384 <table>
385 <tr>
386 <td>$(_ 'Username')</td>
387 <td><input type="text" name="user" size="40" value="$USERNAME" /></td>
388 </tr>
389 <tr>
390 <td>$(_ 'Password')</td>
391 <td><input type="text" name="pass" size="40" value="$PASSWORD" /></td>
392 </tr>
393 </table>
394 <footer><!--
395 --><button type="submit" name="start_pppoe" data-icon="start" $startoe_disabled>$(_ 'Start' )</button><!--
396 --><button type="submit" name="stop_pppoe" data-icon="stop" $stopoe_disabled >$(_ 'Stop' )</button><!--
397 --></footer>
398 </form>
399 </section>
400 EOT
401 if [ "$(which pppssh 2>/dev/null)" ]; then
402 [ -s /etc/ppp/pppssh ] && . /etc/ppp/pppssh
403 ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)"
404 if [ "$(busybox ps x | grep "$ppp" | awk '/dbclient/{print $1}')" ]; then
405 startssh_disabled='disabled'
406 else
407 stopssh_disabled='disabled'
408 fi
409 cat <<EOT
410 <a name="pppssh"></a>
411 <section>
412 <header>
413 <span data-icon="vpn">$(_ 'Virtual Private Network') -
414 $(_ 'Manage private TCP/IP connections')</span>
415 </header>
416 <form method="get">
417 <input type="hidden" name="setpppssh" />
418 <table>
419 <tr>
420 <td>$(_ 'Peer')</td>
421 <td><input type="text" name="peer" size="50" value="${PEER:-user@elsewhere}" /></td>
422 </tr>
423 <tr>
424 <td>$(_ 'SSH options')</td>
425 <td><input type="text" name="ssharg" size="50" value="$SSHARG" /></td>
426 </tr>
427 <tr>
428 <td>$(_ 'Password')</td>
429 <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>
430 </tr>
431 <tr>
432 <td>$(_ 'Local IP address')</td>
433 <td><input type="text" name="localip" size="50" value="${LOCALIP:-192.168.254.1}" /></td>
434 </tr>
435 <tr>
436 <td>$(_ 'Remote IP address')</td>
437 <td><input type="text" name="remoteip" size="50" value="${REMOTEIP:-192.168.254.2}" /></td>
438 </tr>
439 <tr>
440 <td>$(_ 'Local PPP options')</td>
441 <td><input type="text" name="localpppopt" size="50" value="$LOCALPPP" /></td>
442 </tr>
443 <tr>
444 <td>$(_ 'Remote PPP options')</td>
445 <td><input type="text" name="remotepppopt" size="50" value="${REMOTEPPP:-proxyarp}" title="$(_ "You may need 'proxyarp' to use the new routes")" /></td>
446 </tr>
447 <tr>
448 <td>$(_ 'Peer routes')</td>
449 <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>
450 </tr>
451 <tr>
452 <td>$(_ 'UDP port')</td>
453 <td><input type="text" name="udp" size="50" value="$UDP" title="$(_ "Optional UDP port for a real-time but unencrypted link")"/></td>
454 </tr>
455 </table>
456 <footer><!--
457 --><button type="submit" name="start_pppssh" data-icon="start" $startssh_disabled>$(_ 'Start' )</button><!--
458 --><button type="submit" name="stop_pppssh" data-icon="stop" $stopssh_disabled>$(_ 'Stop' )</button><!--
459 --><button type="submit" name="send_key" data-icon="sync" >$(_ 'Send SSH key' )</button><!--
460 --></footer>
461 </form>
462 </section>
463 EOT
464 fi
466 xhtml_footer
467 exit 0