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

syslinux/taziso: add burn
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat May 09 21:54:15 2015 +0200 (2015-05-09)
parents 5c05d949d429
children 56c606af68bc
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 dailer 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>