wok-next view ppp/stuff/ppp.cgi @ rev 19355
drobbear/pppssh: optional UDP unencrypted link
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Jul 26 13:47:19 2016 +0200 (2016-07-26) |
parents | 35c789882b3c |
children | 50aef5b483cb |
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 case "$1" in
14 menu)
15 TEXTDOMAIN_original=$TEXTDOMAIN
16 export TEXTDOMAIN='ppp'
18 case "$2" in
19 *VPN*)
20 [ "$(which pptp 2>/dev/null)$(which pptpd 2>/dev/null)" ] && cat <<EOT
21 <li><a data-icon="vpn" href="ppp.cgi#pptp" data-root>$(_ 'PPTP')</a></li>
22 EOT
23 [ "$(which pppssh 2>/dev/null)" ] && cat <<EOT
24 <li><a data-icon="vpn" href="ppp.cgi#pppssh" data-root>$(_ 'PPP/SSH')</a></li>
25 EOT
26 cat <<EOT
27 <li><a data-icon="upgrade" href="ppp.cgi#pppnc" data-root>$(_ 'Route shortcut')</a></li>
28 EOT
29 ;;
30 *)
31 cat <<EOT
32 <li><a data-icon="modem" href="ppp.cgi" data-root>$(_ 'PPP Modem')</a></li>
33 EOT
34 esac
35 export TEXTDOMAIN=$TEXTDOMAIN_original
36 exit
37 esac
40 #
41 # Commands
42 #
44 case " $(GET) " in
45 *\ setppppstn\ *)
46 if [ "$(GET start_pstn)" -a "$(GET user)" ]; then
47 grep -s "$(GET user)" /etc/ppp/pap-secrets ||
48 echo "$(GET user) * $(GET pass)" >> /etc/ppp/pap-secrets
49 grep -s "$(GET user)" /etc/ppp/chap-secrets ||
50 echo "$(GET user) * $(GET pass)" >> /etc/ppp/chap-secrets
51 sed -i 's/^name /d' /etc/ppp/options
52 echo "name $(GET user)" >> /etc/ppp/options
53 /etc/ppp/scripts/ppp-off
54 /etc/ppp/scripts/ppp-on &
55 fi
56 if [ "$(GET stop_pstn)" ]; then
57 /etc/ppp/scripts/ppp-off
58 fi
59 ;;
60 *\ setpppoe\ *)
61 if [ "$(GET start_pppoe)" -a "$(GET user)" ]; then
62 grep -s "$(GET user)" /etc/ppp/pap-secrets ||
63 echo "$(GET user) * $(GET pass)" >> /etc/ppp/pap-secrets
64 grep -s "$(GET user)" /etc/ppp/chap-secrets ||
65 echo "$(GET user) * $(GET pass)" >> /etc/ppp/chap-secrets
66 grep -qs pppoe /etc/ppp/options || cat > /etc/ppp/options <<EOT
67 plugin rp-pppoe.so
68 noipdefault
69 defaultroute
70 mtu 1492
71 mru 1492
72 lock
73 EOT
74 sed -i 's/^name /d' /etc/ppp/options
75 echo "name $(GET user)" >> /etc/ppp/options
76 ( . /etc/network.conf ; pppd $INTERFACE & )
77 fi
78 if [ "$(GET stop_pppoe)" ]; then
79 killall pppd
80 fi
81 ;;
82 *\ setpppnc\ *)
83 [ "$(GET stop_pppncs)" ] && killall pppnc-server
84 [ "$(GET start_pppncs)" ] &&
85 pppnc-server "$(GET port)" "$(GET localip):$(GET remoteip)" &
86 [ "$(GET stop_pppncc)" ] && killall pppnc-client
87 [ "$(GET start_pppncc)" ] &&
88 pppnc-client "$(GET serverip)" "$(GET port)" "$(GET routes)" &
89 ;;
90 *\ setpppssh\ *)
91 cat > /etc/ppp/pppssh <<EOT
92 PEER="$(GET peer)"
93 SSHARG="$(GET ssharg)"
94 LOCALIP="$(GET localip)"
95 REMOTEIP="$(GET remoteip)"
96 LOCALPPP="$(GET localpppopt)"
97 REMOTEPPP="$(GET remotepppopt)"
98 ROUTES="$(GET routes)"
99 UDP="$(GET udp)"
100 EOT
101 [ "$(GET pass)" ] && export DROPBEAR_PASSWORD="$(GET pass)"
102 case " $(GET) " in
103 *\ send_key\ *)
104 ( dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key ;
105 cat /etc/ssh/ssh_host_rsa_key.pub ) 2> /dev/null | \
106 grep ^ssh | dbclient $(echo $(GET send_key) | sed \
107 's/.*\([A-Za-z0-9_\.-]*\).*/\1/') "mkdir .ssh 2> /dev/null ; \
108 while read key; do for i in authorized_keys authorized_keys2; do \
109 grep -qs '\$key' .ssh/\$i || echo '\$key' >> .ssh/\$i ; done ; done ; \
110 chmod 700 .ssh ; chmod 600 .ssh/authorized_keys*"
111 ;;
112 *\ stop_pppssh\ *)
113 ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)"
114 kill $(busybox ps x | grep "$ppp" | awk '/pty/{next}/dbclient/{print $1}')
115 ;;
116 *\ start_pppssh\ *)
117 EOT
118 pppssh "$(GET ssharg) $(GET peer)" \
119 "$(GET localip):$(GET remoteip) $(GET localpppopt)" \
120 "$(GET remotepppopt)" "$(GET routes)" "$(GET udp)" &
121 ;;
122 esac
123 ;;
124 esac
126 USERNAME="$(sed '/^name/!d;s/^[^ ]* *//' /etc/ppp/options)"
127 PASSWORD="$(awk -v key=$USERNAME "\$1==key{print \$3}" /etc/ppp/pap-secrets)"
128 ACCOUNT="$(sed '/^ACCOUNT=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
129 PASSPSTN="$(sed '/^PASSWORD=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
130 PHONE="$(sed '/^TELEPHONE=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
131 busybox ps x | grep -v grep | grep -q pppnc_server || stops_disabled='disabled'
132 busybox ps x | grep -v grep | grep -q pppnc_client || stopc_disabled='disabled'
133 TITLE="$(_ 'TazPanel - Network') - $(_ 'PPP Connections')"
134 header
135 xhtml_header | sed 's/id="content"/id="content-sidebar"/'
136 cat << EOT
137 <div id="sidebar">
138 <section>
139 <header>
140 $(_ 'Documentation')
141 </header>
142 <a data-icon="web" href="http://ppp.samba.org/" target="_blank">$(_ 'PPP web page')</a><p>
143 <a data-icon="help" href="index.cgi?exec=pppd%20--help" target="_blank">$(_ 'PPP help')</a><p>
144 <a data-icon="help" href="index.cgi?exec=man%20pppd" target="_blank">$(_ 'PPP Manual')</a><p>
145 EOT
146 [ "$(which pptp 2>/dev/null)" ] && cat <<EOT
147 <a data-icon="web" href="http://pptpclient.sourceforge.net/" target="_blank">$(_n 'PPTP web page')</a><p>
148 <a data-icon="help" href="index.cgi?exec=pptp" target="_blank">$(_ 'PPTP Help')</a><p>
149 EOT
150 [ "$(which pptpd 2>/dev/null)" ] && cat <<EOT
151 <a data-icon="web" href="http://poptop.sourceforge.net/" target="_blank">$(_n 'PPTPD web page')</a><p>
152 <a data-icon="help" href="index.cgi?exec=pptpd%20--help" target="_blank">$(_ 'PPTPD Help')</a><p>
153 EOT
154 [ "$(which pppssh 2>/dev/null)" ] && cat <<EOT
155 <a data-icon="web" href="http://doc.slitaz.org/en:guides:vpn" target="_blank">$(_n 'VPN Wiki')</a><p>
156 <a data-icon="help" href="index.cgi?exec=dbclient" target="_blank">$(_ 'SSH Help')</a><p>
157 EOT
158 cat << EOT
159 <footer>
160 </footer>
161 </section>
162 <section>
163 <header>
164 $(_ 'Configuration')
165 </header>
166 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on" target="_blank">$(_ 'PPP PSTN script')</a><p>
167 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on-dialer" target="_blank">$(_ 'PPP dialer chat')</a><p>
168 <a data-icon="conf" href="index.cgi?file=/etc/ppp/options" target="_blank">$(_ 'PPP options')</a><p>
169 <a data-icon="conf" href="index.cgi?file=/etc/ppp/chap-secrets" target="_blank">$(_ 'chap users')</a><p>
170 <a data-icon="conf" href="index.cgi?file=/etc/ppp/pap-secrets" target="_blank">$(_ 'pap users')</a><p>
171 EOT
172 for i in /etc/ppp/peers/* ; do
173 [ -s "$i" ] && cat << EOT
174 <a data-icon="conf" href="index.cgi?file=$i" target="_blank">$(basename $i)</a><p>
175 EOT
176 done
177 [ "$(which pptpd 2>/dev/null)" ] && cat <<EOT
178 <a data-icon="conf" href="index.cgi?file=/etc/pptpd.conf" target="_blank">$(_ 'pptpd.conf')</a><p>
179 EOT
180 if [ "$(busybox ps x | grep "pppd" | awk '/modem/{print $1}')" ]; then
181 start_disabled='disabled'
182 else
183 stop_disabled='disabled'
184 fi
185 if [ "$(busybox ps x | grep "pppd" | awk '/eth/{print $1}')" ]; then
186 startoe_disabled='disabled'
187 else
188 stopoe_disabled='disabled'
189 fi
190 cat << EOT
191 <footer>
192 </footer>
193 </section>
194 </div>
196 <a name="ppppstn"></a>
197 <section>
198 <header>
199 <span data-icon="modem">$(_ 'PSTN modem') -
200 $(_ 'Manage PSTN Internet connections')</span>
201 </header>
202 <form action="index.cgi" id="indexform"></form>
203 <form method="get">
204 <input type="hidden" name="setppppstn" />
205 <table>
206 <tr>
207 <td>$(_ 'Username')</td>
208 <td><input type="text" name="user" size="40" value="$ACCOUNT" /></td>
209 </tr>
210 <tr>
211 <td>$(_ 'Password')</td>
212 <td><input type="text" name="pass" size="40" value="$PASSPSTN" /></td>
213 </tr>
214 <tr>
215 <td>$(_ 'Phone number')</td>
216 <td><input type="text" name="phone" size="40" value="$PHONE" /></td>
217 </tr>
218 </table>
219 <footer><!--
220 --><button type="submit" name="start_pstn" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
221 --><button type="submit" name="stop_pstn" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
222 --></footer>
223 </form>
224 </section>
226 <a name="pppoe"></a>
227 <section>
228 <header>
229 <span data-icon="eth">$(_ 'Cable Modem') -
230 $(_ 'Manage PPPoE Internet connections')</span>
231 </header>
232 <form method="get">
233 <input type="hidden" name="setpppoe" />
234 <table>
235 <tr>
236 <td>$(_ 'Username')</td>
237 <td><input type="text" name="user" size="40" value="$USERNAME" /></td>
238 </tr>
239 <tr>
240 <td>$(_ 'Password')</td>
241 <td><input type="text" name="pass" size="40" value="$PASSWORD" /></td>
242 </tr>
243 </table>
244 <footer><!--
245 --><button type="submit" name="start_pppoe" data-icon="start" $startoe_disabled>$(_ 'Start' )</button><!--
246 --><button type="submit" name="stop_pppoe" data-icon="stop" $stopoe_disabled >$(_ 'Stop' )</button><!--
247 --></footer>
248 </form>
249 </section>
251 <a name="pppnc"></a>
252 <section>
253 <header>
254 <span data-icon="upgrade">$(_ 'Route shortcut') -
255 $(_ 'Reach unreachable networks')</span>
256 </header>
257 <form method="get">
258 <input type="hidden" name="setppprc" />
259 <table>
260 <tr>
261 <td>$(_ 'UDP port')</td>
262 <td><input type="text" name="port" size="50" value="1111" /></td>
263 </tr>
264 <tr> <td colspan=2 align=center>--- $(_ 'Server only') ---</td> </tr>
265 <tr>
266 <td>$(_ 'Local IP address')</td>
267 <td><input type="text" name="localip" size="50" value="${LOCALIP:-192.168.254.1}" /></td>
268 </tr>
269 <tr>
270 <td>$(_ 'Remote IP address')</td>
271 <td><input type="text" name="remoteip" size="50" value="${REMOTEIP:-192.168.254.2}" /></td>
272 <tr> <td colspan=2 align=center>--- $(_ 'Client only') ---</td> </tr>
273 <tr>
274 <td>$(_ 'Server IP address')</td>
275 <td><input type="text" name="serverip" size="50" value="1.2.3.4" /></td>
276 </tr>
277 <tr>
278 <td>$(_ 'Server routes')</td>
279 <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>
280 </tr>
281 </table>
282 <footer><!--
283 --><button type="submit" name="start_pppncs" data-icon="start" >$(_ 'Start server' )</button><!--
284 --><button type="submit" name="stop_pppncs" data-icon="stop" $stops_disabled>$(_ 'Stop server' )</button><!--
285 --><button type="submit" name="start_pppncc" data-icon="start" >$(_ 'Start client' )</button><!--
286 --><button type="submit" name="stop_pppncc" data-icon="stop" $stopc_disabled>$(_ 'Stop client' )</button><!--
287 --></footer>
288 </form>
289 </section>
290 EOT
291 if [ "$(which pppssh 2>/dev/null)" ]; then
292 [ -s /etc/ppp/pppssh ] && . /etc/ppp/pppssh
293 ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)"
294 if [ "$(busybox ps x | grep "$ppp" | awk '/dbclient/{print $1}')" ]; then
295 startssh_disabled='disabled'
296 else
297 stopssh_disabled='disabled'
298 fi
299 cat <<EOT
300 <a name="pppssh"></a>
301 <section>
302 <header>
303 <span data-icon="vpn">$(_ 'Virtual Private Network') -
304 $(_ 'Manage private TCP/IP connections')</span>
305 </header>
306 <form method="get">
307 <input type="hidden" name="setpppssh" />
308 <table>
309 <tr>
310 <td>$(_ 'Peer')</td>
311 <td><input type="text" name="peer" size="50" value="${PEER:-user@elsewhere}" /></td>
312 </tr>
313 <tr>
314 <td>$(_ 'SSH options')</td>
315 <td><input type="text" name="ssharg" size="50" value="$SSHARG" /></td>
316 </tr>
317 <tr>
318 <td>$(_ 'Password')</td>
319 <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>
320 </tr>
321 <tr>
322 <td>$(_ 'Local IP address')</td>
323 <td><input type="text" name="localip" size="50" value="${LOCALIP:-192.168.254.1}" /></td>
324 </tr>
325 <tr>
326 <td>$(_ 'Remote IP address')</td>
327 <td><input type="text" name="remoteip" size="50" value="${REMOTEIP:-192.168.254.2}" /></td>
328 </tr>
329 <tr>
330 <td>$(_ 'Local PPP options')</td>
331 <td><input type="text" name="localpppopt" size="50" value="$LOCALPPP" /></td>
332 </tr>
333 <tr>
334 <td>$(_ 'Remote PPP options')</td>
335 <td><input type="text" name="remotepppopt" size="50" value="${REMOTEPPP:-proxyarp}" title="$(_ "You may need 'proxyarp' to use the new routes")" /></td>
336 </tr>
337 <tr>
338 <td>$(_ 'Peer routes')</td>
339 <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>
340 </tr>
341 <tr>
342 <td>$(_ 'UDP port')</td>
343 <td><input type="text" name="udp" size="50" value="$UDP" title="$(_ "Optional UDP port for a real-time but unencrypted link")"/></td>
344 </tr>
345 </table>
346 <footer><!--
347 --><button type="submit" name="start_pppssh" data-icon="start" $startssh_disabled>$(_ 'Start' )</button><!--
348 --><button type="submit" name="stop_pppssh" data-icon="stop" $stopssh_disabled>$(_ 'Stop' )</button><!--
349 --><button type="submit" name="send_key" data-icon="sync" >$(_ 'Send SSH key' )</button><!--
350 --></footer>
351 </form>
352 </section>
353 EOT
354 fi
356 xhtml_footer
357 exit 0