wok-next view ppp/stuff/ppp.cgi @ rev 18236
Up: tazpkg(819): re-write "desc" function
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Jul 24 15:13:34 2015 +0300 (2015-07-24) |
parents | c23b328bb7b2 |
children | 35c789882b3c |
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 EOT
100 [ "$(GET pass)" ] && export DROPBEAR_PASSWORD="$(GET pass)"
101 case " $(GET) " in
102 *\ send_key\ *)
103 ( dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key ;
104 cat /etc/ssh/ssh_host_rsa_key.pub ) 2> /dev/null | \
105 grep ^ssh | dbclient $(echo $(GET send_key) | sed \
106 's/.*\([A-Za-z0-9_\.-]*\).*/\1/') "mkdir .ssh 2> /dev/null ; \
107 while read key; do for i in authorized_keys authorized_keys2; do \
108 grep -qs '\$key' .ssh/\$i || echo '\$key' >> .ssh/\$i ; done ; done ; \
109 chmod 700 .ssh ; chmod 600 .ssh/authorized_keys*"
110 ;;
111 *\ stop_pppssh\ *)
112 ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)"
113 kill $(busybox ps x | grep "$ppp" | awk '/pty/{next}/dbclient/{print $1}')
114 ;;
115 *\ start_pppssh\ *)
116 EOT
117 pppssh "$(GET ssharg) $(GET peer)" \
118 "$(GET localip):$(GET remoteip) $(GET localpppopt)" \
119 "$(GET remotepppopt)" "$(GET routes)" &
120 ;;
121 esac
122 ;;
123 esac
125 USERNAME="$(sed '/^name/!d;s/^[^ ]* *//' /etc/ppp/options)"
126 PASSWORD="$(awk -v key=$USERNAME "\$1==key{print \$3}" /etc/ppp/pap-secrets)"
127 ACCOUNT="$(sed '/^ACCOUNT=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
128 PASSPSTN="$(sed '/^PASSWORD=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
129 PHONE="$(sed '/^TELEPHONE=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
130 busybox ps x | grep -v grep | grep -q pppnc_server || stops_disabled='disabled'
131 busybox ps x | grep -v grep | grep -q pppnc_client || stopc_disabled='disabled'
132 TITLE="$(_ 'TazPanel - Network') - $(_ 'PPP Connections')"
133 header
134 xhtml_header | sed 's/id="content"/id="content-sidebar"/'
135 cat << EOT
136 <div id="sidebar">
137 <section>
138 <header>
139 $(_ 'Documentation')
140 </header>
141 <a data-icon="web" href="http://ppp.samba.org/" target="_blank">$(_ 'PPP web page')</a><p>
142 <a data-icon="help" href="index.cgi?exec=pppd%20--help" target="_blank">$(_ 'PPP help')</a><p>
143 <a data-icon="help" href="index.cgi?exec=man%20pppd" target="_blank">$(_ 'PPP Manual')</a><p>
144 EOT
145 [ "$(which pptp 2>/dev/null)" ] && cat <<EOT
146 <a data-icon="web" href="http://pptpclient.sourceforge.net/" target="_blank">$(_n 'PPTP web page')</a><p>
147 <a data-icon="help" href="index.cgi?exec=pptp" target="_blank">$(_ 'PPTP Help')</a><p>
148 EOT
149 [ "$(which pptpd 2>/dev/null)" ] && cat <<EOT
150 <a data-icon="web" href="http://poptop.sourceforge.net/" target="_blank">$(_n 'PPTPD web page')</a><p>
151 <a data-icon="help" href="index.cgi?exec=pptpd%20--help" target="_blank">$(_ 'PPTPD Help')</a><p>
152 EOT
153 [ "$(which pppssh 2>/dev/null)" ] && cat <<EOT
154 <a data-icon="web" href="http://doc.slitaz.org/en:guides:vpn" target="_blank">$(_n 'VPN Wiki')</a><p>
155 <a data-icon="help" href="index.cgi?exec=dbclient" target="_blank">$(_ 'SSH Help')</a><p>
156 EOT
157 cat << EOT
158 <footer>
159 </footer>
160 </section>
161 <section>
162 <header>
163 $(_ 'Configuration')
164 </header>
165 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on" target="_blank">$(_ 'PPP PSTN script')</a><p>
166 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on-dialer" target="_blank">$(_ 'PPP dialer chat')</a><p>
167 <a data-icon="conf" href="index.cgi?file=/etc/ppp/options" target="_blank">$(_ 'PPP options')</a><p>
168 <a data-icon="conf" href="index.cgi?file=/etc/ppp/chap-secrets" target="_blank">$(_ 'chap users')</a><p>
169 <a data-icon="conf" href="index.cgi?file=/etc/ppp/pap-secrets" target="_blank">$(_ 'pap users')</a><p>
170 EOT
171 for i in /etc/ppp/peers/* ; do
172 [ -s "$i" ] && cat << EOT
173 <a data-icon="conf" href="index.cgi?file=$i" target="_blank">$(basename $i)</a><p>
174 EOT
175 done
176 [ "$(which pptpd 2>/dev/null)" ] && cat <<EOT
177 <a data-icon="conf" href="index.cgi?file=/etc/pptpd.conf" target="_blank">$(_ 'pptpd.conf')</a><p>
178 EOT
179 if [ "$(busybox ps x | grep "pppd" | awk '/modem/{print $1}')" ]; then
180 start_disabled='disabled'
181 else
182 stop_disabled='disabled'
183 fi
184 if [ "$(busybox ps x | grep "pppd" | awk '/eth/{print $1}')" ]; then
185 startoe_disabled='disabled'
186 else
187 stopoe_disabled='disabled'
188 fi
189 cat << EOT
190 <footer>
191 </footer>
192 </section>
193 </div>
195 <a name="ppppstn"></a>
196 <section>
197 <header>
198 <span data-icon="modem">$(_ 'PSTN modem') -
199 $(_ 'Manage PSTN Internet connections')</span>
200 </header>
201 <form action="index.cgi" id="indexform"></form>
202 <form method="get">
203 <input type="hidden" name="setppppstn" />
204 <table>
205 <tr>
206 <td>$(_ 'Username')</td>
207 <td><input type="text" name="user" size="40" value="$ACCOUNT" /></td>
208 </tr>
209 <tr>
210 <td>$(_ 'Password')</td>
211 <td><input type="text" name="pass" size="40" value="$PASSPSTN" /></td>
212 </tr>
213 <tr>
214 <td>$(_ 'Phone number')</td>
215 <td><input type="text" name="phone" size="40" value="$PHONE" /></td>
216 </tr>
217 </table>
218 <footer><!--
219 --><button type="submit" name="start_pstn" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
220 --><button type="submit" name="stop_pstn" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
221 --></footer>
222 </form>
223 </section>
225 <a name="pppoe"></a>
226 <section>
227 <header>
228 <span data-icon="eth">$(_ 'Cable Modem') -
229 $(_ 'Manage PPPoE Internet connections')</span>
230 </header>
231 <form method="get">
232 <input type="hidden" name="setpppoe" />
233 <table>
234 <tr>
235 <td>$(_ 'Username')</td>
236 <td><input type="text" name="user" size="40" value="$USERNAME" /></td>
237 </tr>
238 <tr>
239 <td>$(_ 'Password')</td>
240 <td><input type="text" name="pass" size="40" value="$PASSWORD" /></td>
241 </tr>
242 </table>
243 <footer><!--
244 --><button type="submit" name="start_pppoe" data-icon="start" $startoe_disabled>$(_ 'Start' )</button><!--
245 --><button type="submit" name="stop_pppoe" data-icon="stop" $stopoe_disabled >$(_ 'Stop' )</button><!--
246 --></footer>
247 </form>
248 </section>
250 <a name="pppnc"></a>
251 <section>
252 <header>
253 <span data-icon="upgrade">$(_ 'Route shortcut') -
254 $(_ 'Reach unreachable networks')</span>
255 </header>
256 <form method="get">
257 <input type="hidden" name="setppprc" />
258 <table>
259 <tr>
260 <td>$(_ 'TCP port')</td>
261 <td><input type="text" name="port" size="50" value="1111" /></td>
262 </tr>
263 <tr> <td colspan=2 align=center>--- $(_ 'Server only') ---</td> </tr>
264 <tr>
265 <td>$(_ 'Local IP address')</td>
266 <td><input type="text" name="localip" size="50" value="${LOCALIP:-192.168.254.1}" /></td>
267 </tr>
268 <tr>
269 <td>$(_ 'Remote IP address')</td>
270 <td><input type="text" name="remoteip" size="50" value="${REMOTEIP:-192.168.254.2}" /></td>
271 <tr> <td colspan=2 align=center>--- $(_ 'Client only') ---</td> </tr>
272 <tr>
273 <td>$(_ 'Server IP address')</td>
274 <td><input type="text" name="serverip" size="50" value="1.2.3.4" /></td>
275 </tr>
276 <tr>
277 <td>$(_ 'Server routes')</td>
278 <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>
279 </tr>
280 </table>
281 <footer><!--
282 --><button type="submit" name="start_pppncs" data-icon="start" >$(_ 'Start server' )</button><!--
283 --><button type="submit" name="stop_pppncs" data-icon="stop" $stops_disabled>$(_ 'Stop server' )</button><!--
284 --><button type="submit" name="start_pppncc" data-icon="start" >$(_ 'Start client' )</button><!--
285 --><button type="submit" name="stop_pppncc" data-icon="stop" $stopc_disabled>$(_ 'Stop client' )</button><!--
286 --></footer>
287 </form>
288 </section>
289 EOT
290 if [ "$(which pppssh 2>/dev/null)" ]; then
291 [ -s /etc/ppp/pppssh ] && . /etc/ppp/pppssh
292 ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)"
293 if [ "$(busybox ps x | grep "$ppp" | awk '/dbclient/{print $1}')" ]; then
294 startssh_disabled='disabled'
295 else
296 stopssh_disabled='disabled'
297 fi
298 cat <<EOT
299 <a name="pppssh"></a>
300 <section>
301 <header>
302 <span data-icon="vpn">$(_ 'Virtual Private Network') -
303 $(_ 'Manage private TCP/IP connections')</span>
304 </header>
305 <form method="get">
306 <input type="hidden" name="setpppssh" />
307 <table>
308 <tr>
309 <td>$(_ 'Peer')</td>
310 <td><input type="text" name="peer" size="50" value="${PEER:-user@elsewhere}" /></td>
311 </tr>
312 <tr>
313 <td>$(_ 'SSH options')</td>
314 <td><input type="text" name="ssharg" size="50" value="$SSHARG" /></td>
315 </tr>
316 <tr>
317 <td>$(_ 'Password')</td>
318 <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>
319 </tr>
320 <tr>
321 <td>$(_ 'Local IP address')</td>
322 <td><input type="text" name="localip" size="50" value="${LOCALIP:-192.168.254.1}" /></td>
323 </tr>
324 <tr>
325 <td>$(_ 'Remote IP address')</td>
326 <td><input type="text" name="remoteip" size="50" value="${REMOTEIP:-192.168.254.2}" /></td>
327 </tr>
328 <tr>
329 <td>$(_ 'Local PPP options')</td>
330 <td><input type="text" name="localpppopt" size="50" value="$LOCALPPP" /></td>
331 </tr>
332 <tr>
333 <td>$(_ 'Remote PPP options')</td>
334 <td><input type="text" name="remotepppopt" size="50" value="${REMOTEPPP:-proxyarp}" title="$(_ "You may need 'proxyarp' to use the new routes")" /></td>
335 </tr>
336 <tr>
337 <td>$(_ 'Peer routes')</td>
338 <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>
339 </tr>
340 </table>
341 <footer><!--
342 --><button type="submit" name="start_pppssh" data-icon="start" $startssh_disabled>$(_ 'Start' )</button><!--
343 --><button type="submit" name="stop_pppssh" data-icon="stop" $stopssh_disabled>$(_ 'Stop' )</button><!--
344 --><button type="submit" name="send_key" data-icon="sync" >$(_ 'Send SSH key' )</button><!--
345 --></footer>
346 </form>
347 </section>
348 EOT
349 fi
351 xhtml_footer
352 exit 0