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

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