wok view ppp/stuff/ppp.cgi @ rev 20181

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