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