tazpanel annotate network.cgi @ rev 241

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