tazpanel annotate network.cgi @ rev 384
New style and use /usr/bin/tazpanel to lauch a browser
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Feb 20 00:07:26 2014 +0100 (2014-02-20) |
parents | 8ec43100e75e |
children | 106b85c1951c |
rev | line source |
---|---|
pankso@38 | 1 #!/bin/sh |
pankso@38 | 2 # |
pankso@38 | 3 # Network configuration CGI interface |
pankso@38 | 4 # |
pankso@379 | 5 # Copyright (C) 2012-2014 SliTaz GNU/Linux - BSD License |
pankso@112 | 6 # |
pankso@38 | 7 |
pankso@38 | 8 # Common functions from libtazpanel |
pankso@38 | 9 . lib/libtazpanel |
pankso@38 | 10 get_config |
pascal@81 | 11 header |
pankso@38 | 12 |
al@292 | 13 TITLE=$(gettext 'TazPanel - Network') |
pankso@42 | 14 |
pankso@106 | 15 # Catch ESSIDs and format output for GTK tree. We get the list of |
pankso@106 | 16 # networks by Cell and without spaces. |
pankso@106 | 17 detect_wifi_networks() |
pankso@106 | 18 { |
pankso@106 | 19 cat << EOT |
al@311 | 20 <table class="zebra outbox"> |
al@303 | 21 <thead> |
al@303 | 22 <tr> |
al@303 | 23 <td>$(gettext 'Name')</td> |
al@303 | 24 <td>$(gettext 'Quality')</td> |
al@303 | 25 <td>$(gettext 'Encryption')</td> |
al@303 | 26 <td>$(gettext 'Status')</td> |
al@303 | 27 </tr> |
al@303 | 28 </thead> |
al@303 | 29 <tbody> |
pankso@106 | 30 EOT |
pankso@106 | 31 if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then |
pankso@106 | 32 ifconfig $WIFI_INTERFACE up |
pascal@321 | 33 for i in $(iwlist $WIFI_INTERFACE scan | sed '/Cell /!d;s/.*Cell \([^ ]*\).*/Cell.\1/') |
pankso@106 | 34 do |
pascal@321 | 35 SCAN=$(iwlist $WIFI_INTERFACE scan last | sed "/$i/,/Cell/!d" | sed '$d') |
pascal@322 | 36 ESSID=$(echo $SCAN | sed 's/.*ESSID:"\([^"]*\).*/\1/') |
pankso@106 | 37 if echo "$SCAN" | grep -q Quality; then |
al@362 | 38 QUALITY=$(echo $SCAN | sed '/ *Quality/s/.*Quality[:=]\([^ ]*\).*/\1/') |
pankso@106 | 39 else |
pankso@106 | 40 QUALITY="-" |
pankso@106 | 41 fi |
pascal@322 | 42 ENCRYPTION=$(echo $SCAN | sed 's/.*key:\([^ ]*\).*/\1/') |
pankso@106 | 43 # Check encryption type |
pankso@239 | 44 if echo "$SCAN" | grep -q WPA*; then |
pankso@239 | 45 ENCRYPTION="WPA" |
pankso@106 | 46 fi |
pascal@322 | 47 if echo $SCAN | grep -q 'Mode:Managed'; then |
pascal@322 | 48 AP="&ap=$(echo $SCAN | sed 's/.*Address: \([^ ]*\).*/\1/')" |
pascal@322 | 49 else |
pascal@322 | 50 AP="" |
pascal@322 | 51 fi |
pankso@106 | 52 # Connected or not connected... |
pankso@106 | 53 if ifconfig | grep -A 1 $WIFI_INTERFACE | \ |
pankso@108 | 54 fgrep -q inet && iwconfig $WIFI_INTERFACE | \ |
pascal@323 | 55 fgrep -q "ESSID:\"$ESSID\""; then |
al@303 | 56 status=$(gettext 'Connected') |
pankso@106 | 57 else |
pankso@108 | 58 status="---" |
pankso@106 | 59 fi |
pankso@106 | 60 echo '<tr>' |
pascal@322 | 61 echo "<td><a href=\"$SCRIPT_NAME?wifi&select=$ESSID&keytype=$ENCRYPTION&$AP\"> |
pankso@239 | 62 <img src='$IMAGES/wireless.png' />$ESSID</a></td>" |
pankso@108 | 63 echo "<td>$QUALITY</td><td>$ENCRYPTION</td><td>$status $ip</td>" |
pankso@106 | 64 echo '</tr>' |
pankso@106 | 65 done |
pankso@106 | 66 fi |
al@303 | 67 cat << EOT |
al@303 | 68 </tbody> |
al@303 | 69 </table> |
al@303 | 70 EOT |
pankso@106 | 71 } |
pankso@106 | 72 |
pankso@247 | 73 # Start a wifi connection |
pankso@247 | 74 start_wifi() { |
pankso@247 | 75 sed -i \ |
pankso@247 | 76 -e s'/^DHCP=.*/DHCP="yes"/' \ |
pankso@247 | 77 -e s'/^WIFI=.*/WIFI="yes"/' \ |
pankso@250 | 78 -e s'/^STATIC=.*/STATIC="no"/' /etc/network.conf |
pankso@247 | 79 ifconfig $WIFI_INTERFACE up |
pankso@247 | 80 iwconfig $WIFI_INTERFACE txpower auto |
Christian@273 | 81 /etc/init.d/network.sh restart | log |
pankso@247 | 82 sleep 2 |
pankso@247 | 83 } |
pankso@247 | 84 |
pankso@41 | 85 # Actions commands before page is displayed |
pascal@81 | 86 case " $(GET) " in |
pascal@81 | 87 *\ start\ *) |
pankso@41 | 88 # Here we sleep a bit to let udhcp get the lease before reloading |
paul@205 | 89 # the page with status |
pankso@76 | 90 /etc/init.d/network.sh start | log |
pankso@41 | 91 sleep 2 ;; |
pascal@81 | 92 *\ stop\ *) |
pankso@76 | 93 /etc/init.d/network.sh stop | log ;; |
naitsirhc@269 | 94 *\ restart\ *) |
naitsirhc@269 | 95 /etc/init.d/network.sh restart | log ;; |
pankso@247 | 96 *\ start-wifi\ *) start_wifi ;; |
pankso@108 | 97 *\ hostname\ *) |
al@303 | 98 get_hostname="$(GET hostname)" |
al@303 | 99 echo $(eval_gettext 'Changed hostname: $get_hostname') | log |
al@303 | 100 echo "$get_hostname" > /etc/hostname ;; |
pankso@41 | 101 esac |
pankso@41 | 102 |
paul@127 | 103 # Get values only now since they could have been modified by actions. |
pankso@108 | 104 . /etc/network.conf |
pankso@108 | 105 |
pankso@38 | 106 # |
pankso@41 | 107 # Main Commands for pages |
pankso@38 | 108 # |
pankso@38 | 109 |
pascal@81 | 110 case " $(GET) " in |
pascal@136 | 111 *\ scan\ *) |
pascal@136 | 112 # Scan open ports |
pascal@136 | 113 scan=$(GET scan) |
pascal@136 | 114 xhtml_header |
al@303 | 115 LOADING_MSG=$(gettext 'Scanning open ports...') |
pascal@136 | 116 loading_msg |
pascal@136 | 117 cat << EOT |
al@303 | 118 <h2>$(eval_gettext 'Port scanning for $scan')</h2> |
al@303 | 119 |
al@303 | 120 <pre>$(pscan -b $scan)</pre> |
pascal@136 | 121 EOT |
pascal@136 | 122 ;; |
al@303 | 123 |
pascal@81 | 124 *\ eth\ *) |
pankso@41 | 125 # Wired connections settings |
pankso@38 | 126 xhtml_header |
pankso@107 | 127 if [ "$(GET ip)" ]; then |
pascal@124 | 128 DHCP=no |
pascal@124 | 129 STATIC=no |
pascal@124 | 130 [ -n "$(GET dhcp)" ] && DHCP=yes |
pascal@124 | 131 [ -n "$(GET static)" ] && STATIC=yes |
al@303 | 132 LOADING_MSG=$(gettext 'Setting up IP...') |
pankso@107 | 133 loading_msg |
pankso@107 | 134 sed -i \ |
pankso@107 | 135 -e s"/^INTERFACE=.*/INTERFACE=\"$(GET iface)\""/ \ |
pascal@124 | 136 -e s"/^DHCP=.*/DHCP=\"$DHCP\"/" \ |
pascal@124 | 137 -e s"/^STATIC=.*/STATIC=\"$STATIC\"/" \ |
pankso@107 | 138 -e s"/^NETMASK=.*/NETMASK=\"$(GET netmask)\"/" \ |
pankso@107 | 139 -e s"/^GATEWAY=.*/GATEWAY=\"$(GET gateway)\"/" \ |
pankso@107 | 140 -e s"/^DNS_SERVER=.*/DNS_SERVER=\"$(GET dns)\"/" \ |
pankso@107 | 141 -e s"/^IP=.*/IP=\"$(GET ip)\"/" /etc/network.conf |
pankso@107 | 142 /etc/init.d/network stop | log |
pankso@107 | 143 sleep 2 |
pankso@107 | 144 /etc/init.d/network start | log |
pankso@240 | 145 . /etc/network.conf |
pankso@107 | 146 fi |
pankso@38 | 147 cat << EOT |
al@303 | 148 <h2>$(gettext 'Ethernet connection')</h2> |
al@303 | 149 |
al@303 | 150 <p>$(gettext "Here you can configure a wired connection using DHCP to \ |
al@303 | 151 automatically get a random IP or configure a static/fixed IP")</p> |
al@303 | 152 |
al@312 | 153 <section> |
al@303 | 154 <h3>$(gettext 'Configuration')</h3> |
pankso@107 | 155 <form method="get" action="$SCRIPT_NAME"> |
pankso@107 | 156 <input type="hidden" name="eth" /> |
al@303 | 157 <table> |
pankso@107 | 158 <thead> |
pankso@107 | 159 <tr> |
al@303 | 160 <td>$(gettext 'Name')</td> |
al@303 | 161 <td>$(gettext 'Value')</td> |
pankso@107 | 162 </tr> |
pankso@107 | 163 </thead> |
al@303 | 164 <tbody> |
pankso@107 | 165 <tr> |
al@303 | 166 <td>$(gettext 'Interface')</td> |
pankso@107 | 167 <td><input type="text" name="iface" size="20" value="$INTERFACE" /></td> |
pankso@107 | 168 </tr> |
pankso@107 | 169 <tr> |
al@303 | 170 <td>$(gettext 'IP address')</td> |
pankso@107 | 171 <td><input type="text" name="ip" size="20" value="$IP" /></td> |
pankso@107 | 172 </tr> |
pankso@107 | 173 <tr> |
al@303 | 174 <td>$(gettext 'Netmask')</td> |
pankso@107 | 175 <td><input type="text" name="netmask" size="20" value="$NETMASK" /></td> |
pankso@107 | 176 </tr> |
pankso@107 | 177 <tr> |
al@303 | 178 <td>$(gettext 'Gateway')</td> |
pankso@107 | 179 <td><input type="text" name="gateway" size="20" value="$GATEWAY" /></td> |
pankso@107 | 180 </tr> |
pankso@107 | 181 <tr> |
al@303 | 182 <td>$(gettext 'DNS server')</td> |
pankso@107 | 183 <td><input type="text" name="dns" size="20" value="$DNS_SERVER" /></td> |
pankso@107 | 184 </tr> |
al@303 | 185 </tbody> |
al@303 | 186 </table> |
al@303 | 187 <input type="submit" name="static" value="$(gettext 'Activate (static)')"> |
al@303 | 188 <input type="submit" name="dhcp" value="$(gettext 'Activate (DHCP)')"> |
al@303 | 189 <input type="submit" name="disable" value="$(gettext 'Disable')"> |
pankso@107 | 190 </form> |
al@312 | 191 </section> |
pankso@107 | 192 |
al@312 | 193 <section> |
al@303 | 194 <h3>$(gettext 'Configuration file')</h3> |
al@303 | 195 |
al@303 | 196 <p>$(gettext "These values are the ethernet settings in the main \ |
al@303 | 197 /etc/network.conf configuration file")</p> |
pankso@41 | 198 <pre> |
pankso@107 | 199 $(grep ^[A-V] /etc/network.conf | syntax_highlighter conf) |
pankso@41 | 200 </pre> |
pankso@107 | 201 <a class="button" href="index.cgi?file=/etc/network.conf&action=edit"> |
al@303 | 202 <img src="$IMAGES/edit.png" />$(gettext 'Manual Edit')</a> |
al@312 | 203 </section> |
pankso@41 | 204 EOT |
pankso@41 | 205 ;; |
pascal@81 | 206 *\ wifi\ *) |
pankso@41 | 207 # Wireless connections settings |
pankso@41 | 208 xhtml_header |
al@303 | 209 LOADING_MSG=$(gettext 'Scanning wireless interface...') |
pankso@106 | 210 loading_msg |
pankso@238 | 211 . /etc/network.conf |
pankso@41 | 212 cat << EOT |
al@303 | 213 <h2>$(gettext 'Wireless connection')</h2> |
pankso@106 | 214 <div id="actions"> |
pankso@108 | 215 <a class="button" href="$SCRIPT_NAME?wifi&start-wifi=start-wifi"> |
al@303 | 216 <img src="$IMAGES/start.png" />$(gettext 'Start')</a> |
pankso@108 | 217 <a class="button" href="$SCRIPT_NAME?wifi&stop=stop"> |
al@303 | 218 <img src="$IMAGES/stop.png" />$(gettext 'Stop')</a> |
pankso@106 | 219 <a class="button" href="$SCRIPT_NAME?wifi=scan"> |
al@303 | 220 <img src="$IMAGES/recharge.png" />$(gettext 'Scan')</a> |
pankso@106 | 221 </div> |
pankso@106 | 222 $(detect_wifi_networks) |
pankso@106 | 223 EOT |
pascal@322 | 224 WIFI_AP="$(GET ap)" |
pascal@321 | 225 WIFI_KEY="$(GET key)" |
pascal@321 | 226 case "$(GET keytype)" in |
pascal@321 | 227 ''|off) WIFI_KEY_TYPE=none ;; |
pascal@322 | 228 *) WIFI_KEY_TYPE=any ;; |
pascal@321 | 229 esac |
pankso@240 | 230 if [ "$(GET essid)" ]; then |
pankso@247 | 231 /etc/init.d/network.sh stop | log |
pankso@240 | 232 sed -i \ |
pankso@240 | 233 -e s"/^WIFI_ESSID=.*/WIFI_ESSID=\"$(GET essid)\""/ \ |
pankso@240 | 234 -e s"/^WIFI_KEY=.*/WIFI_KEY=\"$WIFI_KEY\"/" \ |
pankso@240 | 235 -e s"/^WIFI_KEY_TYPE=.*/WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"/" \ |
pascal@322 | 236 -e s"/^WIFI_AP=.*/WIFI_AP=\"$WIFI_AP\"/" \ |
pankso@240 | 237 /etc/network.conf |
pankso@240 | 238 . /etc/network.conf |
pankso@247 | 239 start_wifi |
pankso@240 | 240 fi |
pankso@240 | 241 # ESSID names are clickable |
pankso@240 | 242 if [ "$(GET select)" ]; then |
pankso@240 | 243 if [ "$(GET select)" != "$WIFI_ESSID" ]; then |
pankso@240 | 244 WIFI_KEY="" |
pankso@240 | 245 fi |
pankso@240 | 246 WIFI_ESSID="$(GET select)" |
pankso@240 | 247 fi |
pankso@106 | 248 cat << EOT |
al@312 | 249 <section> |
al@303 | 250 <h3>$(gettext 'Connection')</h3> |
pankso@238 | 251 <form method="get" action="$SCRIPT_NAME"> |
pankso@240 | 252 <input type="hidden" name="connect-wifi" /> |
pankso@238 | 253 $(table_start) |
pankso@238 | 254 <thead> |
pankso@238 | 255 <tr> |
al@303 | 256 <td>$(gettext 'Name')</td> |
al@303 | 257 <td>$(gettext 'Value')</td> |
pankso@238 | 258 </tr> |
pankso@238 | 259 </thead> |
pankso@238 | 260 <tr> |
al@303 | 261 <td>$(gettext 'Wifi name (ESSID)')</td> |
pankso@238 | 262 <td><input type="text" name="essid" size="30" value="$WIFI_ESSID" /></td> |
pankso@238 | 263 </tr> |
pankso@238 | 264 <tr> |
al@303 | 265 <td>$(gettext 'Password (Wifi key)')</td> |
pankso@240 | 266 <td><input type="password" name="key" size="30" value="$WIFI_KEY" /></td> |
pankso@238 | 267 </tr> |
pankso@238 | 268 <tr> |
al@303 | 269 <td>$(gettext 'Encryption type')</td> |
pankso@238 | 270 <td><input type="text" name="keytype" size="30" value="$WIFI_KEY_TYPE" /></td> |
pankso@238 | 271 </tr> |
pascal@322 | 272 <tr> |
pascal@322 | 273 <td>$(gettext 'Access point')</td> |
pascal@322 | 274 <td><input type="text" name="ap" size="30" value="$WIFI_AP" /></td> |
pascal@322 | 275 </tr> |
pankso@238 | 276 $(table_end) |
al@303 | 277 <input type="submit" name="wifi" value="$(gettext 'Configure')" /> |
pankso@238 | 278 </form> |
al@312 | 279 </section> |
pankso@238 | 280 |
al@312 | 281 <section> |
al@303 | 282 <h3>$(gettext 'Configuration file')</h3> |
al@303 | 283 |
al@303 | 284 <p>$(gettext "These values are the wifi settings in the main /etc/network.conf \ |
al@303 | 285 configuration file")</p> |
al@303 | 286 |
al@303 | 287 <pre>$(grep ^WIFI /etc/network.conf | syntax_highlighter conf)</pre> |
al@303 | 288 |
pankso@98 | 289 <a class="button" href="index.cgi?file=/etc/network.conf&action=edit"> |
al@303 | 290 <img src="$IMAGES/edit.png" />$(gettext 'Manual Edit')</a> |
al@312 | 291 </section> |
pankso@106 | 292 |
al@312 | 293 <section> |
al@303 | 294 <h3>$(gettext 'Output of iwconfig')</h3> |
al@303 | 295 |
al@303 | 296 <pre>$(iwconfig)</pre> |
al@312 | 297 </section> |
pankso@41 | 298 EOT |
pankso@41 | 299 ;; |
pankso@41 | 300 *) |
pankso@41 | 301 # Main Network page starting with a summary |
pankso@41 | 302 xhtml_header |
pankso@108 | 303 hostname=$(cat /etc/hostname) |
pankso@41 | 304 cat << EOT |
al@303 | 305 <h2>$(gettext 'Networking')</h2> |
al@303 | 306 |
al@303 | 307 <p>$(gettext 'Manage network connections and services')</p> |
al@303 | 308 |
al@312 | 309 <section> |
pankso@41 | 310 <div id="actions"> |
pankso@74 | 311 <div class="float-left"> |
pankso@108 | 312 <a class="button" href="$SCRIPT_NAME?start"> |
al@303 | 313 <img src="$IMAGES/start.png" />$(gettext 'Start')</a> |
pankso@108 | 314 <a class="button" href="$SCRIPT_NAME?stop"> |
al@303 | 315 <img src="$IMAGES/stop.png" />$(gettext 'Stop')</a> |
naitsirhc@269 | 316 <a class="button" href="$SCRIPT_NAME?restart"> |
al@303 | 317 <img src="$IMAGES/recharge.png" />$(gettext 'Restart')</a> |
pankso@74 | 318 </div> |
pankso@74 | 319 <div class="float-right"> |
al@303 | 320 $(gettext 'Configuration:') |
pankso@74 | 321 <a class="button" href="index.cgi?file=/etc/network.conf">network.conf</a> |
pankso@108 | 322 <a class="button" href="$SCRIPT_NAME?eth">Ethernet</a> |
pankso@108 | 323 <a class="button" href="$SCRIPT_NAME?wifi">Wireless</a> |
pankso@74 | 324 </div> |
pankso@38 | 325 </div> |
pankso@38 | 326 |
pankso@106 | 327 $(list_network_interfaces) |
al@312 | 328 </section> |
pankso@38 | 329 |
al@312 | 330 <section> |
al@303 | 331 <h3 id="hosts">$(gettext 'Hosts')</h3> |
al@303 | 332 |
al@303 | 333 <pre>$(cat /etc/hosts)</pre> |
al@303 | 334 |
pankso@108 | 335 <a class="button" href="index.cgi?file=/etc/hosts&action=edit"> |
al@303 | 336 <img src="$IMAGES/edit.png" />$(gettext 'Edit hosts')</a> |
al@312 | 337 </section> |
pankso@108 | 338 |
al@312 | 339 <section> |
al@303 | 340 <h3>$(gettext 'Hostname')</h3> |
al@303 | 341 |
al@303 | 342 <form method="get" name="$SCRIPT_NAME"> |
pankso@108 | 343 <input type="text" name="hostname" value="$hostname" /> |
al@303 | 344 <input type="submit" value="$(gettext 'Change hostname')" /> |
pankso@108 | 345 </form> |
al@312 | 346 </section> |
pankso@108 | 347 |
al@312 | 348 <section> |
al@303 | 349 <h3 id="ifconfig">$(gettext 'Output of ifconfig')</h3> |
pascal@68 | 350 |
al@303 | 351 <pre>$(ifconfig)</pre> |
al@312 | 352 </section> |
pascal@68 | 353 |
al@312 | 354 <section> |
al@303 | 355 <h3 id="routing">$(gettext 'Routing table')</h3> |
pascal@68 | 356 |
al@303 | 357 <pre>$(route -n)</pre> |
al@312 | 358 </section> |
pascal@131 | 359 |
al@312 | 360 <section> |
al@303 | 361 <h3 id="dns">$(gettext 'Domain name resolution')</h3> |
al@303 | 362 |
al@303 | 363 <pre>$(cat /etc/resolv.conf)</pre> |
al@312 | 364 </section> |
al@303 | 365 |
al@312 | 366 <section> |
al@303 | 367 <h3 id="arp">$(gettext 'ARP table')</h3> |
al@303 | 368 |
al@303 | 369 <pre>$(arp)</pre> |
al@312 | 370 </section> |
al@303 | 371 |
al@312 | 372 <section> |
al@303 | 373 <h3 id="connections">$(gettext 'IP Connections')</h3> |
al@303 | 374 |
pascal@131 | 375 <pre> |
pascal@156 | 376 $(netstat -anp 2> /dev/null | sed -e '/UNIX domain sockets/,$d' \ |
pascal@156 | 377 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#') |
pascal@131 | 378 </pre> |
al@312 | 379 </section> |
pankso@38 | 380 EOT |
pankso@38 | 381 ;; |
pankso@38 | 382 esac |
pankso@38 | 383 |
pankso@38 | 384 xhtml_footer |
pankso@38 | 385 exit 0 |