wok rev 18017
ppp:add ppp.cgi
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat May 02 16:52:55 2015 +0200 (2015-05-02) |
parents | 5b7188f5cd91 |
children | 86becc422032 |
files | ppp/receipt ppp/stuff/ppp.cgi |
line diff
1.1 --- a/ppp/receipt Sat May 02 15:04:14 2015 +0200 1.2 +++ b/ppp/receipt Sat May 02 16:52:55 2015 +0200 1.3 @@ -12,6 +12,8 @@ 1.4 CONFIG_FILES="/etc/ppp" 1.5 HOST_ARCH="i486 arm" 1.6 1.7 +SUGGESTED="tazpanel" 1.8 + 1.9 # Rules to configure and make the package. 1.10 compile_rules() 1.11 { 1.12 @@ -40,11 +42,14 @@ 1.13 # Rules to gen a SliTaz package suitable for Tazpkg. 1.14 genpkg_rules() 1.15 { 1.16 - mkdir -p $fs/usr 1.17 + mkdir -p $fs/usr $fs/var/www/tazpanel/menu.d/network 1.18 cp -a $install/usr/sbin $fs/usr 1.19 [ -d "$install/usr/lib" ] && cp -a $install/usr/lib $fs/usr 1.20 cp -a $stuff/pppnc-server $fs/usr/sbin 1.21 ln $fs/usr/sbin/pppnc-server $fs/usr/sbin/pppnc-client 1.22 + cp -a $stuff/ppp.cgi $fs/var/www/tazpanel 1.23 + ln -s ../../ppp.cgi $fs/var/www/tazpanel/menu.d/network/ppp 1.24 + 1.25 # Config files. 1.26 mkdir -p $fs/etc/ppp/scripts $fs/etc/ppp/ip-up.d $fs/etc/ppp/ip-down.d 1.27 cp $stuff/README.scripts $fs/etc/ppp
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/ppp/stuff/ppp.cgi Sat May 02 16:52:55 2015 +0200 2.3 @@ -0,0 +1,338 @@ 2.4 +#!/bin/sh 2.5 +# 2.6 +# Network/PPP configuration CGI interface 2.7 +# 2.8 +# Copyright (C) 2015 SliTaz GNU/Linux - BSD License 2.9 +# 2.10 + 2.11 +# Common functions from libtazpanel 2.12 +. lib/libtazpanel 2.13 +get_config 2.14 + 2.15 + 2.16 +case "$1" in 2.17 + menu) 2.18 + TEXTDOMAIN_original=$TEXTDOMAIN 2.19 + export TEXTDOMAIN='ppp' 2.20 + 2.21 + cat <<EOT 2.22 +<li><a data-icon="removable" href="ppp.cgi" data-root>$(_ 'PPP Modem')</a></li> 2.23 +<li><a data-icon="upgrade" href="ppp.cgi#pppnc" data-root>$(_ 'Route shortcut')</a></li> 2.24 +EOT 2.25 + [ "$(which pptp 2>/dev/null)$(which pptpd 2>/dev/null)" ] && cat <<EOT 2.26 +<li><a data-icon="eth" href="ppp.cgi#pptp" data-root>$(_ 'VPN PPTP')</a></li> 2.27 +EOT 2.28 + [ "$(which pppssh 2>/dev/null)" ] && cat <<EOT 2.29 +<li><a data-icon="eth" href="ppp.cgi#pppssh" data-root>$(_ 'VPN PPP/SSH')</a></li> 2.30 +EOT 2.31 + export TEXTDOMAIN=$TEXTDOMAIN_original 2.32 + exit 2.33 +esac 2.34 + 2.35 + 2.36 +# 2.37 +# Commands 2.38 +# 2.39 + 2.40 +case " $(GET) " in 2.41 +*\ setppprtc\ *) 2.42 + if [ "$(GET start_rtc)" -a "$(GET user)" ]; then 2.43 + grep -s "$(GET user)" /etc/ppp/pap-secrets || 2.44 + echo "$(GET user) * $(GET pass)" >> /etc/ppp/pap-secrets 2.45 + grep -s "$(GET user)" /etc/ppp/chap-secrets || 2.46 + echo "$(GET user) * $(GET pass)" >> /etc/ppp/chap-secrets 2.47 + sed -i 's/^name /d' /etc/ppp/options 2.48 + echo "name $(GET user)" >> /etc/ppp/options 2.49 + /etc/ppp/scripts/ppp-off 2.50 + /etc/ppp/scripts/ppp-on & 2.51 + fi 2.52 + if [ "$(GET stop_rtc)" ]; then 2.53 + /etc/ppp/scripts/ppp-off 2.54 + fi 2.55 + ;; 2.56 +*\ setpppoe\ *) 2.57 + if [ "$(GET start_pppoe)" -a "$(GET user)" ]; then 2.58 + grep -s "$(GET user)" /etc/ppp/pap-secrets || 2.59 + echo "$(GET user) * $(GET pass)" >> /etc/ppp/pap-secrets 2.60 + grep -s "$(GET user)" /etc/ppp/chap-secrets || 2.61 + echo "$(GET user) * $(GET pass)" >> /etc/ppp/chap-secrets 2.62 + grep -qs pppoe /etc/ppp/options || cat > /etc/ppp/options <<EOT 2.63 +plugin rp-pppoe.so 2.64 +noipdefault 2.65 +defaultroute 2.66 +mtu 1492 2.67 +mru 1492 2.68 +lock 2.69 +EOT 2.70 + sed -i 's/^name /d' /etc/ppp/options 2.71 + echo "name $(GET user)" >> /etc/ppp/options 2.72 + ( . /etc/network.conf ; pppd $INTERFACE & ) 2.73 + fi 2.74 + if [ "$(GET stop_pppoe)" ]; then 2.75 + killall pppd 2.76 + fi 2.77 + ;; 2.78 +*\ setpppnc\ *) 2.79 + [ "$(GET stop_pppncs)" ] && killall pppnc-server 2.80 + [ "$(GET start_pppncs)" ] && 2.81 + pppnc-server $(GET port) "$(GET localip):$(GET remoteip)" & 2.82 + [ "$(GET stop_pppncc)" ] && killall pppnc-client 2.83 + [ "$(GET start_pppncc)" ] && 2.84 + pppnc-client $(GET serverip) $(GET port) "$(GET routes)" & 2.85 + ;; 2.86 +*\ setpppssh\ *) 2.87 + cat > /etc/ppp/pppssh <<EOT 2.88 +PEER="$(GET peer)" 2.89 +SSHARG="$(GET ssharg)" 2.90 +LOCALIP="$(GET localip)" 2.91 +REMOTEIP="$(GET remoteip)" 2.92 +LOCALPPP="$(GET localpppopt)" 2.93 +REMOTEPPP="$(GET remotepppopt)" 2.94 +ROUTES="$(GET routes)" 2.95 +EOT 2.96 + [ "$(GET pass)" ] && export DROPBEAR_PASSWORD="$(GET pass)" 2.97 + if [ "$(GET send_key)" ]; then 2.98 + ( dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key ; 2.99 + cat /etc/ssh/ssh_host_rsa_key.pub ) 2> /dev/null | \ 2.100 + grep ^ssh | dbclient $(echo $(GET send_key) | sed \ 2.101 + 's/.*\([A-Za-z0-9_\.-]*\).*/\1/') "mkdir .ssh 2> /dev/null ; \ 2.102 + while read key; do for i in authorized_keys authorized_keys2; do \ 2.103 + grep -qs '\$key' .ssh/\$i || echo '\$key' >> .ssh/\$i ; done ; done ; \ 2.104 + chmod 700 .ssh ; chmod 600 .ssh/authorized_keys*" 2.105 + fi 2.106 + if [ "$(GET stop_pppssh)" ]; then 2.107 + ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)" 2.108 + kill $(busybox ps x | grep "$ppp" | awk '/dbclient/{print $1}') 2.109 + fi 2.110 + if [ "$(GET start_pppssh)" ]; then 2.111 + pppssh "$(GET ssharg) $(GET peer)" \ 2.112 + "$(GET localip):$(GET remoteip) $(GET localpppopt)" \ 2.113 + "$(GET remotepppopt)" & 2.114 + fi 2.115 + ;; 2.116 +esac 2.117 + 2.118 +USERNAME="$(sed '/^name/!d;s/^[^ ]* *//' /etc/ppp/options)" 2.119 +PASSWORD="$(awk -v key=$USERNAME "\$1==key{print \$3}" /etc/ppp/pap-secrets)" 2.120 +ACCOUNT="$(sed '/^ACCOUNT=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)" 2.121 +PASSRTC="$(sed '/^PASSWORD=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)" 2.122 +PHONE="$(sed '/^TELEPHONE=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)" 2.123 +TITLE="$(_ 'TazPanel - Network') - $(_ 'PPP Connections')" 2.124 +header 2.125 +xhtml_header | sed 's/id="content"/id="content-sidebar"/' 2.126 +cat << EOT 2.127 +<div id="sidebar"> 2.128 +<section> 2.129 + <header> 2.130 + $(_ 'Documentation') 2.131 + </header> 2.132 + <a data-icon="web" href="http://ppp.samba.org/" target="_blank">$(_ 'PPP web page')</a><p> 2.133 + <a data-icon="help" href="index.cgi?exec=pppd%20--help" target="_blank">$(_ 'PPP help')</a><p> 2.134 + <a data-icon="help" href="index.cgi?exec=man%20pppd" target="_blank">$(_ 'PPP Manual')</a><p> 2.135 +EOT 2.136 +[ "$(which pptp 2>/dev/null)" ] && cat <<EOT 2.137 + <a data-icon="web" href="http://pptpclient.sourceforge.net/" target="_blank">$(_n 'PPTP web page')</a><p> 2.138 + <a data-icon="help" href="index.cgi?exec=pptp" target="_blank">$(_ 'PPTP Help')</a><p> 2.139 +EOT 2.140 +[ "$(which pptpd 2>/dev/null)" ] && cat <<EOT 2.141 + <a data-icon="web" href="http://poptop.sourceforge.net/" target="_blank">$(_n 'PPTPD web page')</a><p> 2.142 + <a data-icon="help" href="index.cgi?exec=pptpd%20--help" target="_blank">$(_ 'PPTPD Help')</a><p> 2.143 +EOT 2.144 +[ "$(which pppssh 2>/dev/null)" ] && cat <<EOT 2.145 + <a data-icon="web" href="http://doc.slitaz.org/en:guides:vpn" target="_blank">$(_n 'VPN Wiki')</a><p> 2.146 + <a data-icon="help" href="index.cgi?exec=dbclient" target="_blank">$(_ 'SSH Help')</a><p> 2.147 +EOT 2.148 +cat << EOT 2.149 + <footer> 2.150 + </footer> 2.151 +</section> 2.152 +<section> 2.153 + <header> 2.154 + $(_ 'Configuration') 2.155 + </header> 2.156 + <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on" target="_blank">$(_ 'PPP RTC script')</a><p> 2.157 + <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on-dialer" target="_blank">$(_ 'PPP dailer chat')</a><p> 2.158 + <a data-icon="conf" href="index.cgi?file=/etc/ppp/options" target="_blank">$(_ 'PPP options')</a><p> 2.159 + <a data-icon="conf" href="index.cgi?file=/etc/ppp/chap-secrets" target="_blank">$(_ 'chap users')</a><p> 2.160 + <a data-icon="conf" href="index.cgi?file=/etc/ppp/pap-secrets" target="_blank">$(_ 'pap users')</a><p> 2.161 +EOT 2.162 +for i in /etc/ppp/peers/* ; do 2.163 + [ -s "$i" ] && cat << EOT 2.164 + <a data-icon="conf" href="index.cgi?file=$i" target="_blank">$(basename $i)</a><p> 2.165 +EOT 2.166 +done 2.167 +[ "$(which pptpd 2>/dev/null)" ] && cat <<EOT 2.168 + <a data-icon="conf" href="index.cgi?file=/etc/pptpd.conf" target="_blank">$(_ 'pptpd.conf')</a><p> 2.169 +EOT 2.170 +if [ "$(busybox ps x | grep "pppd" | awk '/modem/{print $1}')" ]; then 2.171 + start_disabled='disabled' 2.172 +else 2.173 + stop_disabled='disabled' 2.174 +fi 2.175 +cat << EOT 2.176 + <footer> 2.177 + </footer> 2.178 +</section> 2.179 +</div> 2.180 + 2.181 +<section> 2.182 + <header> 2.183 + <span data-icon="removable">$(_ 'RTC modem') - 2.184 + $(_ 'Manage RTC Internet connections')</span> 2.185 + </header> 2.186 +<form action="index.cgi" id="indexform"></form> 2.187 +<form method="get" action="?setppprtc"> 2.188 + <table> 2.189 + <tr> 2.190 + <td>$(_ 'Username')</td> 2.191 + <td><input type="text" name="user" size="40" value="$ACCOUNT" /></td> 2.192 + </tr> 2.193 + <tr> 2.194 + <td>$(_ 'Password')</td> 2.195 + <td><input type="text" name="pass" size="40" value="$PASSRTC" /></td> 2.196 + </tr> 2.197 + <tr> 2.198 + <td>$(_ 'Phone number')</td> 2.199 + <td><input type="text" name="phone" size="40" value="$PHONE" /></td> 2.200 + </tr> 2.201 + </table> 2.202 +</form> 2.203 + <footer><!-- 2.204 + --><button form="conf" type="submit" name="start_rtc" data-icon="start" $start_disabled>$(_ 'Start' )</button><!-- 2.205 + --><button form="conf" type="submit" name="stop_rtc" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!-- 2.206 + --></footer> 2.207 +</section> 2.208 +EOT 2.209 + 2.210 +if [ "$(which pppoe 2>/dev/null)" ]; then 2.211 + cat <<EOT 2.212 +<a name="pppoe"></a> 2.213 +<section> 2.214 + <header> 2.215 + <span data-icon="eth">$(_ 'Cable Modem') - 2.216 + $(_ 'Manage PPPoE Internet connections')</span> 2.217 + </header> 2.218 +<form method="get" action="?setpppoe"> 2.219 + <table> 2.220 + <tr> 2.221 + <td>$(_ 'Username')</td> 2.222 + <td><input type="text" name="user" size="40" value="$USERNAME" /></td> 2.223 + </tr> 2.224 + <tr> 2.225 + <td>$(_ 'Password')</td> 2.226 + <td><input type="text" name="pass" size="40" value="$PASSWORD" /></td> 2.227 + </tr> 2.228 + </table> 2.229 +</form> 2.230 + <footer><!-- 2.231 + --><button form="conf" type="submit" name="start_pppoe" data-icon="start" >$(_ 'Start' )</button><!-- 2.232 + --><button form="conf" type="submit" name="stop_pppoe" data-icon="stop" >$(_ 'Stop' )</button><!-- 2.233 + --></footer> 2.234 +</section> 2.235 +EOT 2.236 +fi 2.237 + 2.238 +busybox ps x | grep -v grep | grep -q pppnc_server || stops_disabled='disabled' 2.239 +busybox ps x | grep -v grep | grep -q pppnc_client || stopc_disabled='disabled' 2.240 +cat <<EOT 2.241 +<a name="pppnc"></a> 2.242 +<section> 2.243 + <header> 2.244 + <span data-icon="upgrade">$(_ 'Route shortcut') - 2.245 + $(_ 'Reach unreachable networks')</span> 2.246 + </header> 2.247 +<form method="get" action="?setppprc"> 2.248 + <table> 2.249 + <tr> 2.250 + <td>$(_ 'TCP port')</td> 2.251 + <td><input type="text" name="port" size="50" value="1111" /></td> 2.252 + </tr> 2.253 + <tr> <td colspan=2 align=center>--- $(_ 'Server only') ---</td> </tr> 2.254 + <tr> 2.255 + <td>$(_ 'Local IP address')</td> 2.256 + <td><input type="text" name="localip" size="50" value="${LOCALIP:-192.168.254.1}" /></td> 2.257 + </tr> 2.258 + <tr> 2.259 + <td>$(_ 'Remote IP address')</td> 2.260 + <td><input type="text" name="remoteip" size="50" value="${REMOTEIP:-192.168.254.2}" /></td> 2.261 + <tr> <td colspan=2 align=center>--- $(_ 'Client only') ---</td> </tr> 2.262 + <tr> 2.263 + <td>$(_ 'Server IP address')</td> 2.264 + <td><input type="text" name="serverip" size="50" value="1.2.3.4" /></td> 2.265 + </tr> 2.266 + <tr> 2.267 + <td>$(_ 'Server routes')</td> 2.268 + <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')"/></td> 2.269 + </tr> 2.270 + </table> 2.271 +</form> 2.272 + <footer><!-- 2.273 + --><button form="conf" type="submit" name="start_pppncs" data-icon="start" >$(_ 'Start server' )</button><!-- 2.274 + --><button form="conf" type="submit" name="stop_pppncs" data-icon="stop" $stops_disabled>$(_ 'Stop server' )</button><!-- 2.275 + --><button form="conf" type="submit" name="start_pppncc" data-icon="start" >$(_ 'Start client' )</button><!-- 2.276 + --><button form="conf" type="submit" name="stop_pppncc" data-icon="stop" $stopc_disabled>$(_ 'Stop client' )</button><!-- 2.277 + --></footer> 2.278 +</section> 2.279 +EOT 2.280 +if [ "$(which pppssh 2>/dev/null)" ]; then 2.281 + [ -s /etc/ppp/pppssh ] && . /etc/ppp/pppssh 2.282 + ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)" 2.283 + if [ "$(busybox ps x | grep "$ppp" | awk '/dbclient/{print $1}')" ]; then 2.284 + start_disabled='disabled' 2.285 + else 2.286 + stop_disabled='disabled' 2.287 + fi 2.288 + cat <<EOT 2.289 +<a name="pppssh"></a> 2.290 +<section> 2.291 + <header> 2.292 + <span data-icon="eth">$(_ 'Virtual Private Network') - 2.293 + $(_ 'Manage private TCP/IP connections')</span> 2.294 + </header> 2.295 +<form method="get" action="?setpppssh"> 2.296 + <table> 2.297 + <tr> 2.298 + <td>$(_ 'Peer')</td> 2.299 + <td><input type="text" name="peer" size="50" value="${PEER:-user@elsewhere}" /></td> 2.300 + </tr> 2.301 + <tr> 2.302 + <td>$(_ 'SSH options')</td> 2.303 + <td><input type="text" name="ssharg" size="50" value="$SSHARG" /></td> 2.304 + </tr> 2.305 + <tr> 2.306 + <td>$(_ 'Password')</td> 2.307 + <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> 2.308 + </tr> 2.309 + <tr> 2.310 + <td>$(_ 'Local IP address')</td> 2.311 + <td><input type="text" name="localip" size="50" value="${LOCALIP:-192.168.254.1}" /></td> 2.312 + </tr> 2.313 + <tr> 2.314 + <td>$(_ 'Remote IP address')</td> 2.315 + <td><input type="text" name="remoteip" size="50" value="${REMOTEIP:-192.168.254.2}" /></td> 2.316 + </tr> 2.317 + <tr> 2.318 + <td>$(_ 'Local PPP options')</td> 2.319 + <td><input type="text" name="localpppopt" size="50" value="$LOCALPPP" /></td> 2.320 + </tr> 2.321 + <tr> 2.322 + <td>$(_ 'Remote PPP options')</td> 2.323 + <td><input type="text" name="remotepppopt" size="50" value="${REMOTEPPP:-proxyarp}" title="$(_ "You may 'proxyarp' to use the new routes")" /></td> 2.324 + </tr> 2.325 + <tr> 2.326 + <td>$(_ 'Peer routes')</td> 2.327 + <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')"/></td> 2.328 + </tr> 2.329 + </table> 2.330 +</form> 2.331 + <footer><!-- 2.332 + --><button form="conf" type="submit" name="start_pppssh" data-icon="start" $start_disabled>$(_ 'Start' )</button><!-- 2.333 + --><button form="conf" type="submit" name="stop_pppssh" data-icon="stop" $stop_disabled>$(_ 'Stop' )</button><!-- 2.334 + --><button form="conf" type="submit" name="send_key" data-icon="sync" >$(_ 'Send SSH key' )</button><!-- 2.335 + --></footer> 2.336 +</section> 2.337 +EOT 2.338 +fi 2.339 + 2.340 +xhtml_footer 2.341 +exit 0