tazpanel annotate network.cgi @ rev 303

3 weeks forging ;) Some bugs fixed, maybe all i18n improved (please, recheck 'po's!), couple of new features added... Enjoy!
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri May 04 13:00:43 2012 +0300 (2012-05-04)
parents 72e9955ebdff
children 3e9acc16f728
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@303 20 <table class="zebra">
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@303 150 <h3>$(gettext 'Configuration')</h3>
pankso@107 151 <form method="get" action="$SCRIPT_NAME">
pankso@107 152 <input type="hidden" name="eth" />
al@303 153 <table>
pankso@107 154 <thead>
pankso@107 155 <tr>
al@303 156 <td>$(gettext 'Name')</td>
al@303 157 <td>$(gettext 'Value')</td>
pankso@107 158 </tr>
pankso@107 159 </thead>
al@303 160 <tbody>
pankso@107 161 <tr>
al@303 162 <td>$(gettext 'Interface')</td>
pankso@107 163 <td><input type="text" name="iface" size="20" value="$INTERFACE" /></td>
pankso@107 164 </tr>
pankso@107 165 <tr>
al@303 166 <td>$(gettext 'IP address')</td>
pankso@107 167 <td><input type="text" name="ip" size="20" value="$IP" /></td>
pankso@107 168 </tr>
pankso@107 169 <tr>
al@303 170 <td>$(gettext 'Netmask')</td>
pankso@107 171 <td><input type="text" name="netmask" size="20" value="$NETMASK" /></td>
pankso@107 172 </tr>
pankso@107 173 <tr>
al@303 174 <td>$(gettext 'Gateway')</td>
pankso@107 175 <td><input type="text" name="gateway" size="20" value="$GATEWAY" /></td>
pankso@107 176 </tr>
pankso@107 177 <tr>
al@303 178 <td>$(gettext 'DNS server')</td>
pankso@107 179 <td><input type="text" name="dns" size="20" value="$DNS_SERVER" /></td>
pankso@107 180 </tr>
al@303 181 </tbody>
al@303 182 </table>
al@303 183 <input type="submit" name="static" value="$(gettext 'Activate (static)')">
al@303 184 <input type="submit" name="dhcp" value="$(gettext 'Activate (DHCP)')">
al@303 185 <input type="submit" name="disable" value="$(gettext 'Disable')">
pankso@107 186 </form>
pankso@107 187
al@303 188 <h3>$(gettext 'Configuration file')</h3>
al@303 189
al@303 190 <p>$(gettext "These values are the ethernet settings in the main \
al@303 191 /etc/network.conf configuration file")</p>
pankso@41 192 <pre>
pankso@107 193 $(grep ^[A-V] /etc/network.conf | syntax_highlighter conf)
pankso@41 194 </pre>
pankso@107 195 <a class="button" href="index.cgi?file=/etc/network.conf&action=edit">
al@303 196 <img src="$IMAGES/edit.png" />$(gettext 'Manual Edit')</a>
pankso@41 197 EOT
pankso@41 198 ;;
pascal@81 199 *\ wifi\ *)
pankso@41 200 # Wireless connections settings
pankso@41 201 xhtml_header
al@303 202 LOADING_MSG=$(gettext 'Scanning wireless interface...')
pankso@106 203 loading_msg
pankso@238 204 . /etc/network.conf
pankso@41 205 cat << EOT
al@303 206 <h2>$(gettext 'Wireless connection')</h2>
pankso@106 207 <div id="actions">
pankso@108 208 <a class="button" href="$SCRIPT_NAME?wifi&start-wifi=start-wifi">
al@303 209 <img src="$IMAGES/start.png" />$(gettext 'Start')</a>
pankso@108 210 <a class="button" href="$SCRIPT_NAME?wifi&stop=stop">
al@303 211 <img src="$IMAGES/stop.png" />$(gettext 'Stop')</a>
pankso@106 212 <a class="button" href="$SCRIPT_NAME?wifi=scan">
al@303 213 <img src="$IMAGES/recharge.png" />$(gettext 'Scan')</a>
pankso@106 214 </div>
pankso@106 215 $(detect_wifi_networks)
pankso@106 216 EOT
pankso@240 217 if [ "$(GET essid)" ]; then
pankso@240 218 WIFI_KEY=""
pankso@240 219 WIFI_KEY_TYPE=none
pankso@240 220 [ -n "$(GET key)" ] && WIFI_KEY="$(GET key)"
pankso@240 221 [ -n "$(GET keytype)" ] && WIFI_KEY_TYPE="$(GET keytype)"
pankso@247 222 /etc/init.d/network.sh stop | log
pankso@240 223 sed -i \
pankso@240 224 -e s"/^WIFI_ESSID=.*/WIFI_ESSID=\"$(GET essid)\""/ \
pankso@240 225 -e s"/^WIFI_KEY=.*/WIFI_KEY=\"$WIFI_KEY\"/" \
pankso@240 226 -e s"/^WIFI_KEY_TYPE=.*/WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"/" \
pankso@240 227 /etc/network.conf
pankso@240 228 . /etc/network.conf
pankso@247 229 start_wifi
pankso@240 230 fi
pankso@240 231 # ESSID names are clickable
pankso@240 232 if [ "$(GET select)" ]; then
pankso@240 233 if [ "$(GET select)" != "$WIFI_ESSID" ]; then
pankso@240 234 WIFI_KEY=""
pankso@240 235 fi
pankso@240 236 WIFI_ESSID="$(GET select)"
pankso@240 237 WIFI_KEY_TYPE="$(GET keytype)"
pankso@240 238 fi
pankso@106 239 cat << EOT
al@303 240 <h3>$(gettext 'Connection')</h3>
pankso@238 241 <form method="get" action="$SCRIPT_NAME">
pankso@240 242 <input type="hidden" name="connect-wifi" />
pankso@238 243 $(table_start)
pankso@238 244 <thead>
pankso@238 245 <tr>
al@303 246 <td>$(gettext 'Name')</td>
al@303 247 <td>$(gettext 'Value')</td>
pankso@238 248 </tr>
pankso@238 249 </thead>
pankso@238 250 <tr>
al@303 251 <td>$(gettext 'Wifi name (ESSID)')</td>
pankso@238 252 <td><input type="text" name="essid" size="30" value="$WIFI_ESSID" /></td>
pankso@238 253 </tr>
pankso@238 254 <tr>
al@303 255 <td>$(gettext 'Password (Wifi key)')</td>
pankso@240 256 <td><input type="password" name="key" size="30" value="$WIFI_KEY" /></td>
pankso@238 257 </tr>
pankso@238 258 <tr>
al@303 259 <td>$(gettext 'Encryption type')</td>
pankso@238 260 <td><input type="text" name="keytype" size="30" value="$WIFI_KEY_TYPE" /></td>
pankso@238 261 </tr>
pankso@238 262 $(table_end)
al@303 263 <input type="submit" name="wifi" value="$(gettext 'Configure')" />
pankso@238 264 </form>
pankso@238 265
al@303 266 <h3>$(gettext 'Configuration file')</h3>
al@303 267
al@303 268 <p>$(gettext "These values are the wifi settings in the main /etc/network.conf \
al@303 269 configuration file")</p>
al@303 270
al@303 271 <pre>$(grep ^WIFI /etc/network.conf | syntax_highlighter conf)</pre>
al@303 272
pankso@98 273 <a class="button" href="index.cgi?file=/etc/network.conf&action=edit">
al@303 274 <img src="$IMAGES/edit.png" />$(gettext 'Manual Edit')</a>
pankso@106 275
al@303 276 <h3>$(gettext 'Output of iwconfig')</h3>
al@303 277
al@303 278 <pre>$(iwconfig)</pre>
pankso@41 279 EOT
pankso@41 280 ;;
pankso@41 281 *)
pankso@41 282 # Main Network page starting with a summary
pankso@41 283 xhtml_header
pankso@108 284 hostname=$(cat /etc/hostname)
pankso@41 285 cat << EOT
al@303 286 <h2>$(gettext 'Networking')</h2>
al@303 287
al@303 288 <p>$(gettext 'Manage network connections and services')</p>
al@303 289
pankso@41 290 <div id="actions">
pankso@74 291 <div class="float-left">
pankso@108 292 <a class="button" href="$SCRIPT_NAME?start">
al@303 293 <img src="$IMAGES/start.png" />$(gettext 'Start')</a>
pankso@108 294 <a class="button" href="$SCRIPT_NAME?stop">
al@303 295 <img src="$IMAGES/stop.png" />$(gettext 'Stop')</a>
naitsirhc@269 296 <a class="button" href="$SCRIPT_NAME?restart">
al@303 297 <img src="$IMAGES/recharge.png" />$(gettext 'Restart')</a>
pankso@74 298 </div>
pankso@74 299 <div class="float-right">
al@303 300 $(gettext 'Configuration:')
pankso@74 301 <a class="button" href="index.cgi?file=/etc/network.conf">network.conf</a>
pankso@108 302 <a class="button" href="$SCRIPT_NAME?eth">Ethernet</a>
pankso@108 303 <a class="button" href="$SCRIPT_NAME?wifi">Wireless</a>
pankso@74 304 </div>
pankso@38 305 </div>
pankso@38 306
pankso@106 307 $(list_network_interfaces)
pankso@38 308
al@303 309 <h3 id="hosts">$(gettext 'Hosts')</h3>
al@303 310
al@303 311 <pre>$(cat /etc/hosts)</pre>
al@303 312
pankso@108 313 <a class="button" href="index.cgi?file=/etc/hosts&action=edit">
al@303 314 <img src="$IMAGES/edit.png" />$(gettext 'Edit hosts')</a>
pankso@108 315
al@303 316 <h3>$(gettext 'Hostname')</h3>
al@303 317
al@303 318 <form method="get" name="$SCRIPT_NAME">
pankso@108 319 <input type="text" name="hostname" value="$hostname" />
al@303 320 <input type="submit" value="$(gettext 'Change hostname')" />
pankso@108 321 </form>
pankso@108 322
pankso@108 323
al@303 324 <h3 id="ifconfig">$(gettext 'Output of ifconfig')</h3>
pascal@68 325
al@303 326 <pre>$(ifconfig)</pre>
pascal@68 327
al@303 328 <h3 id="routing">$(gettext 'Routing table')</h3>
pascal@68 329
al@303 330 <pre>$(route -n)</pre>
pascal@131 331
al@303 332 <h3 id="dns">$(gettext 'Domain name resolution')</h3>
al@303 333
al@303 334 <pre>$(cat /etc/resolv.conf)</pre>
al@303 335
al@303 336 <h3 id="arp">$(gettext 'ARP table')</h3>
al@303 337
al@303 338 <pre>$(arp)</pre>
al@303 339
al@303 340 <h3 id="connections">$(gettext 'IP Connections')</h3>
al@303 341
pascal@131 342 <pre>
pascal@156 343 $(netstat -anp 2> /dev/null | sed -e '/UNIX domain sockets/,$d' \
pascal@156 344 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')
pascal@131 345 </pre>
pankso@38 346 EOT
pankso@38 347 ;;
pankso@38 348 esac
pankso@38 349
pankso@38 350 xhtml_footer
pankso@38 351 exit 0