tazpanel annotate network.cgi @ rev 312

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