wok-6.x annotate ppp/stuff/ppp.cgi @ rev 18478

Add openvswitch
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Oct 07 15:13:06 2015 +0200 (2015-10-07)
parents c23b328bb7b2
children 35c789882b3c
rev   line source
pascal@18017 1 #!/bin/sh
pascal@18017 2 #
pascal@18017 3 # Network/PPP configuration CGI interface
pascal@18017 4 #
pascal@18017 5 # Copyright (C) 2015 SliTaz GNU/Linux - BSD License
pascal@18017 6 #
pascal@18017 7
pascal@18017 8 # Common functions from libtazpanel
pascal@18017 9 . lib/libtazpanel
pascal@18017 10 get_config
pascal@18017 11
pascal@18017 12
pascal@18017 13 case "$1" in
pascal@18017 14 menu)
pascal@18017 15 TEXTDOMAIN_original=$TEXTDOMAIN
pascal@18017 16 export TEXTDOMAIN='ppp'
pascal@18017 17
pascal@18025 18 case "$2" in
pascal@18025 19 *VPN*)
pascal@18025 20 [ "$(which pptp 2>/dev/null)$(which pptpd 2>/dev/null)" ] && cat <<EOT
al@18065 21 <li><a data-icon="vpn" href="ppp.cgi#pptp" data-root>$(_ 'PPTP')</a></li>
pascal@18025 22 EOT
pascal@18025 23 [ "$(which pppssh 2>/dev/null)" ] && cat <<EOT
pascal@18066 24 <li><a data-icon="vpn" href="ppp.cgi#pppssh" data-root>$(_ 'PPP/SSH')</a></li>
pascal@18025 25 EOT
pascal@18017 26 cat <<EOT
pascal@18017 27 <li><a data-icon="upgrade" href="ppp.cgi#pppnc" data-root>$(_ 'Route shortcut')</a></li>
pascal@18017 28 EOT
pascal@18025 29 ;;
pascal@18025 30 *)
pascal@18025 31 cat <<EOT
al@18065 32 <li><a data-icon="modem" href="ppp.cgi" data-root>$(_ 'PPP Modem')</a></li>
pascal@18017 33 EOT
pascal@18025 34 esac
pascal@18017 35 export TEXTDOMAIN=$TEXTDOMAIN_original
pascal@18017 36 exit
pascal@18017 37 esac
pascal@18017 38
pascal@18017 39
pascal@18017 40 #
pascal@18017 41 # Commands
pascal@18017 42 #
pascal@18017 43
pascal@18017 44 case " $(GET) " in
pascal@18025 45 *\ setppppstn\ *)
pascal@18025 46 if [ "$(GET start_pstn)" -a "$(GET user)" ]; then
pascal@18017 47 grep -s "$(GET user)" /etc/ppp/pap-secrets ||
pascal@18017 48 echo "$(GET user) * $(GET pass)" >> /etc/ppp/pap-secrets
pascal@18017 49 grep -s "$(GET user)" /etc/ppp/chap-secrets ||
pascal@18017 50 echo "$(GET user) * $(GET pass)" >> /etc/ppp/chap-secrets
pascal@18017 51 sed -i 's/^name /d' /etc/ppp/options
pascal@18017 52 echo "name $(GET user)" >> /etc/ppp/options
pascal@18017 53 /etc/ppp/scripts/ppp-off
pascal@18017 54 /etc/ppp/scripts/ppp-on &
pascal@18017 55 fi
pascal@18025 56 if [ "$(GET stop_pstn)" ]; then
pascal@18017 57 /etc/ppp/scripts/ppp-off
pascal@18017 58 fi
pascal@18017 59 ;;
pascal@18017 60 *\ setpppoe\ *)
pascal@18017 61 if [ "$(GET start_pppoe)" -a "$(GET user)" ]; then
pascal@18017 62 grep -s "$(GET user)" /etc/ppp/pap-secrets ||
pascal@18017 63 echo "$(GET user) * $(GET pass)" >> /etc/ppp/pap-secrets
pascal@18017 64 grep -s "$(GET user)" /etc/ppp/chap-secrets ||
pascal@18017 65 echo "$(GET user) * $(GET pass)" >> /etc/ppp/chap-secrets
pascal@18017 66 grep -qs pppoe /etc/ppp/options || cat > /etc/ppp/options <<EOT
pascal@18017 67 plugin rp-pppoe.so
pascal@18017 68 noipdefault
pascal@18017 69 defaultroute
pascal@18017 70 mtu 1492
pascal@18017 71 mru 1492
pascal@18017 72 lock
pascal@18017 73 EOT
pascal@18017 74 sed -i 's/^name /d' /etc/ppp/options
pascal@18017 75 echo "name $(GET user)" >> /etc/ppp/options
pascal@18017 76 ( . /etc/network.conf ; pppd $INTERFACE & )
pascal@18017 77 fi
pascal@18017 78 if [ "$(GET stop_pppoe)" ]; then
pascal@18017 79 killall pppd
pascal@18017 80 fi
pascal@18017 81 ;;
pascal@18017 82 *\ setpppnc\ *)
pascal@18017 83 [ "$(GET stop_pppncs)" ] && killall pppnc-server
pascal@18017 84 [ "$(GET start_pppncs)" ] &&
pascal@18042 85 pppnc-server "$(GET port)" "$(GET localip):$(GET remoteip)" &
pascal@18017 86 [ "$(GET stop_pppncc)" ] && killall pppnc-client
pascal@18017 87 [ "$(GET start_pppncc)" ] &&
pascal@18042 88 pppnc-client "$(GET serverip)" "$(GET port)" "$(GET routes)" &
pascal@18017 89 ;;
pascal@18017 90 *\ setpppssh\ *)
pascal@18017 91 cat > /etc/ppp/pppssh <<EOT
pascal@18017 92 PEER="$(GET peer)"
pascal@18017 93 SSHARG="$(GET ssharg)"
pascal@18017 94 LOCALIP="$(GET localip)"
pascal@18017 95 REMOTEIP="$(GET remoteip)"
pascal@18017 96 LOCALPPP="$(GET localpppopt)"
pascal@18017 97 REMOTEPPP="$(GET remotepppopt)"
pascal@18017 98 ROUTES="$(GET routes)"
pascal@18017 99 EOT
pascal@18017 100 [ "$(GET pass)" ] && export DROPBEAR_PASSWORD="$(GET pass)"
pascal@18042 101 case " $(GET) " in
pascal@18042 102 *\ send_key\ *)
pascal@18017 103 ( dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key ;
pascal@18017 104 cat /etc/ssh/ssh_host_rsa_key.pub ) 2> /dev/null | \
pascal@18017 105 grep ^ssh | dbclient $(echo $(GET send_key) | sed \
pascal@18017 106 's/.*\([A-Za-z0-9_\.-]*\).*/\1/') "mkdir .ssh 2> /dev/null ; \
pascal@18017 107 while read key; do for i in authorized_keys authorized_keys2; do \
pascal@18017 108 grep -qs '\$key' .ssh/\$i || echo '\$key' >> .ssh/\$i ; done ; done ; \
pascal@18017 109 chmod 700 .ssh ; chmod 600 .ssh/authorized_keys*"
pascal@18042 110 ;;
pascal@18042 111 *\ stop_pppssh\ *)
pascal@18017 112 ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)"
pascal@18042 113 kill $(busybox ps x | grep "$ppp" | awk '/pty/{next}/dbclient/{print $1}')
pascal@18042 114 ;;
pascal@18042 115 *\ start_pppssh\ *)
pascal@18042 116 EOT
pascal@18017 117 pppssh "$(GET ssharg) $(GET peer)" \
pascal@18017 118 "$(GET localip):$(GET remoteip) $(GET localpppopt)" \
pascal@18042 119 "$(GET remotepppopt)" "$(GET routes)" &
pascal@18042 120 ;;
pascal@18042 121 esac
pascal@18017 122 ;;
pascal@18017 123 esac
pascal@18017 124
pascal@18017 125 USERNAME="$(sed '/^name/!d;s/^[^ ]* *//' /etc/ppp/options)"
pascal@18017 126 PASSWORD="$(awk -v key=$USERNAME "\$1==key{print \$3}" /etc/ppp/pap-secrets)"
pascal@18017 127 ACCOUNT="$(sed '/^ACCOUNT=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
pascal@18025 128 PASSPSTN="$(sed '/^PASSWORD=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
pascal@18017 129 PHONE="$(sed '/^TELEPHONE=/!d;s/^.*=\([^ \t]*\).*/\1/' /etc/ppp/scripts/ppp-on)"
pascal@18020 130 busybox ps x | grep -v grep | grep -q pppnc_server || stops_disabled='disabled'
pascal@18020 131 busybox ps x | grep -v grep | grep -q pppnc_client || stopc_disabled='disabled'
pascal@18017 132 TITLE="$(_ 'TazPanel - Network') - $(_ 'PPP Connections')"
pascal@18017 133 header
pascal@18017 134 xhtml_header | sed 's/id="content"/id="content-sidebar"/'
pascal@18017 135 cat << EOT
pascal@18017 136 <div id="sidebar">
pascal@18017 137 <section>
pascal@18017 138 <header>
pascal@18017 139 $(_ 'Documentation')
pascal@18017 140 </header>
pascal@18017 141 <a data-icon="web" href="http://ppp.samba.org/" target="_blank">$(_ 'PPP web page')</a><p>
pascal@18017 142 <a data-icon="help" href="index.cgi?exec=pppd%20--help" target="_blank">$(_ 'PPP help')</a><p>
pascal@18017 143 <a data-icon="help" href="index.cgi?exec=man%20pppd" target="_blank">$(_ 'PPP Manual')</a><p>
pascal@18017 144 EOT
pascal@18017 145 [ "$(which pptp 2>/dev/null)" ] && cat <<EOT
pascal@18017 146 <a data-icon="web" href="http://pptpclient.sourceforge.net/" target="_blank">$(_n 'PPTP web page')</a><p>
pascal@18017 147 <a data-icon="help" href="index.cgi?exec=pptp" target="_blank">$(_ 'PPTP Help')</a><p>
pascal@18017 148 EOT
pascal@18017 149 [ "$(which pptpd 2>/dev/null)" ] && cat <<EOT
pascal@18017 150 <a data-icon="web" href="http://poptop.sourceforge.net/" target="_blank">$(_n 'PPTPD web page')</a><p>
pascal@18017 151 <a data-icon="help" href="index.cgi?exec=pptpd%20--help" target="_blank">$(_ 'PPTPD Help')</a><p>
pascal@18017 152 EOT
pascal@18017 153 [ "$(which pppssh 2>/dev/null)" ] && cat <<EOT
pascal@18017 154 <a data-icon="web" href="http://doc.slitaz.org/en:guides:vpn" target="_blank">$(_n 'VPN Wiki')</a><p>
pascal@18017 155 <a data-icon="help" href="index.cgi?exec=dbclient" target="_blank">$(_ 'SSH Help')</a><p>
pascal@18017 156 EOT
pascal@18017 157 cat << EOT
pascal@18017 158 <footer>
pascal@18017 159 </footer>
pascal@18017 160 </section>
pascal@18017 161 <section>
pascal@18017 162 <header>
pascal@18017 163 $(_ 'Configuration')
pascal@18017 164 </header>
pascal@18025 165 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on" target="_blank">$(_ 'PPP PSTN script')</a><p>
paul@18037 166 <a data-icon="conf" href="index.cgi?file=/etc/ppp/scripts/ppp-on-dialer" target="_blank">$(_ 'PPP dialer chat')</a><p>
pascal@18017 167 <a data-icon="conf" href="index.cgi?file=/etc/ppp/options" target="_blank">$(_ 'PPP options')</a><p>
pascal@18017 168 <a data-icon="conf" href="index.cgi?file=/etc/ppp/chap-secrets" target="_blank">$(_ 'chap users')</a><p>
pascal@18017 169 <a data-icon="conf" href="index.cgi?file=/etc/ppp/pap-secrets" target="_blank">$(_ 'pap users')</a><p>
pascal@18017 170 EOT
pascal@18017 171 for i in /etc/ppp/peers/* ; do
pascal@18017 172 [ -s "$i" ] && cat << EOT
pascal@18017 173 <a data-icon="conf" href="index.cgi?file=$i" target="_blank">$(basename $i)</a><p>
pascal@18017 174 EOT
pascal@18017 175 done
pascal@18017 176 [ "$(which pptpd 2>/dev/null)" ] && cat <<EOT
pascal@18017 177 <a data-icon="conf" href="index.cgi?file=/etc/pptpd.conf" target="_blank">$(_ 'pptpd.conf')</a><p>
pascal@18017 178 EOT
pascal@18017 179 if [ "$(busybox ps x | grep "pppd" | awk '/modem/{print $1}')" ]; then
pascal@18017 180 start_disabled='disabled'
pascal@18017 181 else
pascal@18017 182 stop_disabled='disabled'
pascal@18017 183 fi
pascal@18020 184 if [ "$(busybox ps x | grep "pppd" | awk '/eth/{print $1}')" ]; then
pascal@18020 185 startoe_disabled='disabled'
pascal@18020 186 else
pascal@18020 187 stopoe_disabled='disabled'
pascal@18020 188 fi
pascal@18017 189 cat << EOT
pascal@18017 190 <footer>
pascal@18017 191 </footer>
pascal@18017 192 </section>
pascal@18017 193 </div>
pascal@18017 194
pascal@18025 195 <a name="ppppstn"></a>
pascal@18017 196 <section>
pascal@18017 197 <header>
pascal@18067 198 <span data-icon="modem">$(_ 'PSTN modem') -
pascal@18025 199 $(_ 'Manage PSTN Internet connections')</span>
pascal@18017 200 </header>
pascal@18017 201 <form action="index.cgi" id="indexform"></form>
pascal@18042 202 <form method="get">
pascal@18042 203 <input type="hidden" name="setppppstn" />
pascal@18017 204 <table>
pascal@18017 205 <tr>
pascal@18017 206 <td>$(_ 'Username')</td>
pascal@18017 207 <td><input type="text" name="user" size="40" value="$ACCOUNT" /></td>
pascal@18017 208 </tr>
pascal@18017 209 <tr>
pascal@18017 210 <td>$(_ 'Password')</td>
pascal@18025 211 <td><input type="text" name="pass" size="40" value="$PASSPSTN" /></td>
pascal@18017 212 </tr>
pascal@18017 213 <tr>
pascal@18017 214 <td>$(_ 'Phone number')</td>
pascal@18017 215 <td><input type="text" name="phone" size="40" value="$PHONE" /></td>
pascal@18017 216 </tr>
pascal@18017 217 </table>
pascal@18042 218 <footer><!--
pascal@18042 219 --><button type="submit" name="start_pstn" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
pascal@18042 220 --><button type="submit" name="stop_pstn" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
pascal@18042 221 --></footer>
pascal@18017 222 </form>
pascal@18017 223 </section>
pascal@18017 224
pascal@18017 225 <a name="pppoe"></a>
pascal@18017 226 <section>
pascal@18017 227 <header>
pascal@18017 228 <span data-icon="eth">$(_ 'Cable Modem') -
pascal@18017 229 $(_ 'Manage PPPoE Internet connections')</span>
pascal@18017 230 </header>
pascal@18042 231 <form method="get">
pascal@18042 232 <input type="hidden" name="setpppoe" />
pascal@18017 233 <table>
pascal@18017 234 <tr>
pascal@18017 235 <td>$(_ 'Username')</td>
pascal@18017 236 <td><input type="text" name="user" size="40" value="$USERNAME" /></td>
pascal@18017 237 </tr>
pascal@18017 238 <tr>
pascal@18017 239 <td>$(_ 'Password')</td>
pascal@18017 240 <td><input type="text" name="pass" size="40" value="$PASSWORD" /></td>
pascal@18017 241 </tr>
pascal@18017 242 </table>
pascal@18042 243 <footer><!--
pascal@18042 244 --><button type="submit" name="start_pppoe" data-icon="start" $startoe_disabled>$(_ 'Start' )</button><!--
pascal@18042 245 --><button type="submit" name="stop_pppoe" data-icon="stop" $stopoe_disabled >$(_ 'Stop' )</button><!--
pascal@18042 246 --></footer>
pascal@18017 247 </form>
pascal@18017 248 </section>
pascal@18017 249
pascal@18017 250 <a name="pppnc"></a>
pascal@18017 251 <section>
pascal@18017 252 <header>
pascal@18017 253 <span data-icon="upgrade">$(_ 'Route shortcut') -
pascal@18017 254 $(_ 'Reach unreachable networks')</span>
pascal@18017 255 </header>
pascal@18042 256 <form method="get">
pascal@18042 257 <input type="hidden" name="setppprc" />
pascal@18017 258 <table>
pascal@18017 259 <tr>
pascal@18017 260 <td>$(_ 'TCP port')</td>
pascal@18017 261 <td><input type="text" name="port" size="50" value="1111" /></td>
pascal@18017 262 </tr>
pascal@18017 263 <tr> <td colspan=2 align=center>--- $(_ 'Server only') ---</td> </tr>
pascal@18017 264 <tr>
pascal@18017 265 <td>$(_ 'Local IP address')</td>
pascal@18017 266 <td><input type="text" name="localip" size="50" value="${LOCALIP:-192.168.254.1}" /></td>
pascal@18017 267 </tr>
pascal@18017 268 <tr>
pascal@18017 269 <td>$(_ 'Remote IP address')</td>
pascal@18017 270 <td><input type="text" name="remoteip" size="50" value="${REMOTEIP:-192.168.254.2}" /></td>
pascal@18017 271 <tr> <td colspan=2 align=center>--- $(_ 'Client only') ---</td> </tr>
pascal@18017 272 <tr>
pascal@18017 273 <td>$(_ 'Server IP address')</td>
pascal@18017 274 <td><input type="text" name="serverip" size="50" value="1.2.3.4" /></td>
pascal@18017 275 </tr>
pascal@18017 276 <tr>
pascal@18017 277 <td>$(_ 'Server routes')</td>
pascal@18041 278 <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>
pascal@18017 279 </tr>
pascal@18017 280 </table>
pascal@18042 281 <footer><!--
pascal@18042 282 --><button type="submit" name="start_pppncs" data-icon="start" >$(_ 'Start server' )</button><!--
pascal@18042 283 --><button type="submit" name="stop_pppncs" data-icon="stop" $stops_disabled>$(_ 'Stop server' )</button><!--
pascal@18042 284 --><button type="submit" name="start_pppncc" data-icon="start" >$(_ 'Start client' )</button><!--
pascal@18042 285 --><button type="submit" name="stop_pppncc" data-icon="stop" $stopc_disabled>$(_ 'Stop client' )</button><!--
pascal@18042 286 --></footer>
pascal@18017 287 </form>
pascal@18017 288 </section>
pascal@18017 289 EOT
pascal@18017 290 if [ "$(which pppssh 2>/dev/null)" ]; then
pascal@18017 291 [ -s /etc/ppp/pppssh ] && . /etc/ppp/pppssh
pascal@18017 292 ppp="$(sed '/pppd/!d;s/.*="\([^"]*\).*/\1/' /usr/bin/pppssh)"
pascal@18017 293 if [ "$(busybox ps x | grep "$ppp" | awk '/dbclient/{print $1}')" ]; then
pascal@18042 294 startssh_disabled='disabled'
pascal@18017 295 else
pascal@18042 296 stopssh_disabled='disabled'
pascal@18017 297 fi
pascal@18017 298 cat <<EOT
pascal@18017 299 <a name="pppssh"></a>
pascal@18017 300 <section>
pascal@18017 301 <header>
pascal@18067 302 <span data-icon="vpn">$(_ 'Virtual Private Network') -
pascal@18017 303 $(_ 'Manage private TCP/IP connections')</span>
pascal@18017 304 </header>
pascal@18042 305 <form method="get">
pascal@18042 306 <input type="hidden" name="setpppssh" />
pascal@18017 307 <table>
pascal@18017 308 <tr>
pascal@18017 309 <td>$(_ 'Peer')</td>
pascal@18017 310 <td><input type="text" name="peer" size="50" value="${PEER:-user@elsewhere}" /></td>
pascal@18017 311 </tr>
pascal@18017 312 <tr>
pascal@18017 313 <td>$(_ 'SSH options')</td>
pascal@18017 314 <td><input type="text" name="ssharg" size="50" value="$SSHARG" /></td>
pascal@18017 315 </tr>
pascal@18017 316 <tr>
pascal@18017 317 <td>$(_ 'Password')</td>
paul@18037 318 <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>
pascal@18017 319 </tr>
pascal@18017 320 <tr>
pascal@18017 321 <td>$(_ 'Local IP address')</td>
pascal@18017 322 <td><input type="text" name="localip" size="50" value="${LOCALIP:-192.168.254.1}" /></td>
pascal@18017 323 </tr>
pascal@18017 324 <tr>
pascal@18017 325 <td>$(_ 'Remote IP address')</td>
pascal@18017 326 <td><input type="text" name="remoteip" size="50" value="${REMOTEIP:-192.168.254.2}" /></td>
pascal@18017 327 </tr>
pascal@18017 328 <tr>
pascal@18017 329 <td>$(_ 'Local PPP options')</td>
pascal@18017 330 <td><input type="text" name="localpppopt" size="50" value="$LOCALPPP" /></td>
pascal@18017 331 </tr>
pascal@18017 332 <tr>
pascal@18017 333 <td>$(_ 'Remote PPP options')</td>
pascal@18034 334 <td><input type="text" name="remotepppopt" size="50" value="${REMOTEPPP:-proxyarp}" title="$(_ "You may need 'proxyarp' to use the new routes")" /></td>
pascal@18017 335 </tr>
pascal@18017 336 <tr>
pascal@18017 337 <td>$(_ 'Peer routes')</td>
pascal@18041 338 <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>
pascal@18017 339 </tr>
pascal@18017 340 </table>
pascal@18042 341 <footer><!--
pascal@18042 342 --><button type="submit" name="start_pppssh" data-icon="start" $startssh_disabled>$(_ 'Start' )</button><!--
pascal@18042 343 --><button type="submit" name="stop_pppssh" data-icon="stop" $stopssh_disabled>$(_ 'Stop' )</button><!--
pascal@18042 344 --><button type="submit" name="send_key" data-icon="sync" >$(_ 'Send SSH key' )</button><!--
pascal@18042 345 --></footer>
pascal@18017 346 </form>
pascal@18017 347 </section>
pascal@18017 348 EOT
pascal@18017 349 fi
pascal@18017 350
pascal@18017 351 xhtml_footer
pascal@18017 352 exit 0