tazpanel annotate network.cgi @ rev 136

network.cgi: pscan is too slow, needs its own page
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Apr 16 14:40:49 2011 +0200 (2011-04-16)
parents 774a188359a2
children 6aa939753084
rev   line source
pankso@38 1 #!/bin/sh
pankso@38 2 #
pankso@38 3 # Network configuration CGI interface
pankso@38 4 #
pankso@112 5 # Copyright (C) 2011 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@106 32 for i in `iwlist $WIFI_INTERFACE scan | sed s/"Cell "/Cell-/ | grep "Cell-" | awk '{print $1}'`
pankso@106 33 do
pankso@106 34 SCAN=`iwlist $WIFI_INTERFACE scan last | \
pankso@106 35 awk '/(Cell|ESS|Qual|Encry|IE: WPA)/ {print}' | \
pankso@106 36 sed s/"Cell "/Cell-/ | grep -A 5 "$i"`
pankso@106 37 ESSID=`echo $SCAN | cut -d '"' -f 2`
pankso@106 38 if echo "$SCAN" | grep -q Quality; then
pankso@106 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@106 43 ENCRYPTION=`echo $SCAN | sed 's/.*key:\([^ ]*\).*/\1/'`
pankso@106 44 # Check encryption type
pankso@106 45 if echo "$SCAN" | grep -q WPA; then
pankso@106 46 ENCRYPTION="${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@106 57 echo "<td><img src='$IMAGES/wireless.png' />$ESSID</td>"
pankso@108 58 echo "<td>$QUALITY</td><td>$ENCRYPTION</td><td>$status $ip</td>"
pankso@106 59 echo '</tr>'
pankso@106 60 done
pankso@106 61 fi
pankso@106 62 table_end
pankso@106 63 }
pankso@106 64
pankso@41 65 # Actions commands before page is displayed
pascal@81 66 case " $(GET) " in
pascal@81 67 *\ start\ *)
pankso@41 68 # Here we sleep a bit to let udhcp get the lease before reloading
pankso@41 69 # page with status
pankso@76 70 /etc/init.d/network.sh start | log
pankso@41 71 sleep 2 ;;
pascal@81 72 *\ stop\ *)
pankso@76 73 /etc/init.d/network.sh stop | log ;;
pankso@108 74 *\ start-wifi\ *)
pankso@108 75 sed -i \
pankso@108 76 -e s'/^DHCP=.*/DHCP="yes"/' \
pankso@108 77 -e s'/^WIFI=.*/WIFI="yes"/' \
pankso@108 78 -e s'/^STATIC=.*/STATIC="no"/'/etc/network.conf
pankso@108 79 /etc/init.d/network.sh start | log
pankso@108 80 sleep 2 ;;
pankso@108 81 *\ hostname\ *)
pankso@108 82 echo $(gettext "Changed hostname:") $(GET hostname) | log
pankso@108 83 echo "$(GET hostname)" > /etc/hostname ;;
pankso@41 84 esac
pankso@41 85
paul@127 86 # Get values only now since they could have been modified by actions.
pankso@108 87 . /etc/network.conf
pankso@108 88
pankso@38 89 #
pankso@41 90 # Main Commands for pages
pankso@38 91 #
pankso@38 92
pascal@81 93 case " $(GET) " in
pascal@136 94 *\ scan\ *)
pascal@136 95 # Scan open ports
pascal@136 96 scan=$(GET scan)
pascal@136 97 xhtml_header
pascal@136 98 LOADING_MSG=$(gettext "Scanning open ports...")
pascal@136 99 loading_msg
pascal@136 100 cat << EOT
pascal@136 101 <h2>`gettext "Port scanning for"` $scan</h2>
pascal@136 102 <pre>
pascal@136 103 $(pscan -b $scan)
pascal@136 104 </pre>
pascal@136 105 EOT
pascal@136 106 ;;
pascal@81 107 *\ eth\ *)
pankso@41 108 # Wired connections settings
pankso@38 109 xhtml_header
pankso@107 110 if [ "$(GET ip)" ]; then
pascal@124 111 DHCP=no
pascal@124 112 STATIC=no
pascal@124 113 [ -n "$(GET dhcp)" ] && DHCP=yes
pascal@124 114 [ -n "$(GET static)" ] && STATIC=yes
pascal@124 115 LOADING_MSG=$(gettext "Setting up IP...")
pankso@107 116 loading_msg
pankso@107 117 sed -i \
pankso@107 118 -e s"/^INTERFACE=.*/INTERFACE=\"$(GET iface)\""/ \
pascal@124 119 -e s"/^DHCP=.*/DHCP=\"$DHCP\"/" \
pascal@124 120 -e s"/^STATIC=.*/STATIC=\"$STATIC\"/" \
pankso@107 121 -e s"/^NETMASK=.*/NETMASK=\"$(GET netmask)\"/" \
pankso@107 122 -e s"/^GATEWAY=.*/GATEWAY=\"$(GET gateway)\"/" \
pankso@107 123 -e s"/^DNS_SERVER=.*/DNS_SERVER=\"$(GET dns)\"/" \
pankso@107 124 -e s"/^IP=.*/IP=\"$(GET ip)\"/" /etc/network.conf
pankso@107 125 /etc/init.d/network stop | log
pankso@107 126 sleep 2
pankso@107 127 /etc/init.d/network start | log
pankso@107 128 fi
pankso@107 129 . /etc/network.conf
pankso@38 130 cat << EOT
pascal@136 131 <h2>`gettext "Ethernet connection"`</h2>
pankso@107 132
pankso@107 133 <h3>$(gettext "Setup a static IP")</h3>
pankso@107 134 <form method="get" action="$SCRIPT_NAME">
pankso@107 135 <input type="hidden" name="eth" />
pankso@107 136 $(table_start)
pankso@107 137 <thead>
pankso@107 138 <tr>
pankso@107 139 <td>$(gettext "Name")</td>
pankso@107 140 <td>$(gettext "Value")</td>
pankso@107 141 </tr>
pankso@107 142 </thead>
pankso@107 143 <tr>
pankso@107 144 <td>$(gettext "Interface")</td>
pankso@107 145 <td><input type="text" name="iface" size="20" value="$INTERFACE" /></td>
pankso@107 146 </tr>
pankso@107 147 <tr>
pankso@107 148 <td>$(gettext "IP address")</td>
pankso@107 149 <td><input type="text" name="ip" size="20" value="$IP" /></td>
pankso@107 150 </tr>
pankso@107 151 <tr>
pankso@107 152 <td>$(gettext "Netmask")</td>
pankso@107 153 <td><input type="text" name="netmask" size="20" value="$NETMASK" /></td>
pankso@107 154 </tr>
pankso@107 155 <tr>
pankso@107 156 <td>$(gettext "Gateway")</td>
pankso@107 157 <td><input type="text" name="gateway" size="20" value="$GATEWAY" /></td>
pankso@107 158 </tr>
pankso@107 159 <tr>
pankso@107 160 <td>$(gettext "DNS server")</td>
pankso@107 161 <td><input type="text" name="dns" size="20" value="$DNS_SERVER" /></td>
pankso@107 162 </tr>
pankso@107 163 $(table_end)
pascal@124 164 <input type="submit" name="static" value="`gettext "Activate (static)"`">
pascal@124 165 <input type="submit" name="dhcp" value="`gettext "Activate (DHCP)"`">
pascal@124 166 <input type="submit" name="disable" value="`gettext "Disable"`">
pankso@107 167 </form>
pankso@107 168
pankso@107 169 <h3>$(gettext "Configuration file")</h3>
pankso@107 170 <p>
pankso@107 171 $(gettext "These values are the ethernet settings in the main
pankso@107 172 /etc/network.conf configuration file")
pankso@107 173 </p>
pankso@41 174 <pre>
pankso@107 175 $(grep ^[A-V] /etc/network.conf | syntax_highlighter conf)
pankso@41 176 </pre>
pankso@107 177 <a class="button" href="index.cgi?file=/etc/network.conf&action=edit">
pankso@107 178 <img src="$IMAGES/edit.png" />$(gettext "Manual Edit")</a>
pankso@41 179 EOT
pankso@41 180 ;;
pascal@81 181 *\ wifi\ *)
pankso@41 182 # Wireless connections settings
pankso@41 183 xhtml_header
pankso@106 184 LOADING_MSG=$(gettext "Scanning wireless interface...")
pankso@106 185 loading_msg
pankso@41 186 cat << EOT
pascal@136 187 <h2>`gettext "Wireless connection"`</h2>
pankso@106 188 <div id="actions">
pankso@108 189 <a class="button" href="$SCRIPT_NAME?wifi&start-wifi=start-wifi">
pankso@108 190 <img src="$IMAGES/start.png" />$(gettext "Start")</a>
pankso@108 191 <a class="button" href="$SCRIPT_NAME?wifi&stop=stop">
pankso@108 192 <img src="$IMAGES/stop.png" />$(gettext "Stop")</a>
pankso@106 193 <a class="button" href="$SCRIPT_NAME?wifi=scan">
pankso@106 194 <img src="$IMAGES/recharge.png" />$(gettext "Scan")</a>
pankso@106 195 </div>
pankso@106 196 $(detect_wifi_networks)
pankso@106 197 EOT
pankso@106 198 cat << EOT
pankso@98 199 <h3>$(gettext "Configuration file")</h3>
pankso@98 200 <p>
pankso@98 201 $(gettext "These values are the wifi settings in the main
pankso@98 202 /etc/network.conf configuration file")
pankso@98 203 </p>
pankso@41 204 <pre>
pankso@107 205 $(grep ^WIFI /etc/network.conf | syntax_highlighter conf)
pankso@41 206 </pre>
pankso@98 207 <a class="button" href="index.cgi?file=/etc/network.conf&action=edit">
pankso@98 208 <img src="$IMAGES/edit.png" />$(gettext "Manual Edit")</a>
pankso@106 209
pankso@106 210 <h3>$(gettext "Output of") iwconfig</h3>
pankso@106 211 <pre>
pankso@106 212 $(iwconfig)
pankso@106 213 </pre>
pankso@41 214 EOT
pankso@41 215 ;;
pankso@41 216 *)
pankso@41 217 # Main Network page starting with a summary
pankso@41 218 xhtml_header
pankso@108 219 hostname=$(cat /etc/hostname)
pankso@41 220 cat << EOT
pascal@136 221 <h2>`gettext "Networking"`</h2>
pankso@41 222 <p>
pascal@136 223 `gettext "Manage network connections and services"`
pankso@41 224 </p>
pankso@41 225 <div id="actions">
pankso@74 226 <div class="float-left">
pankso@41 227 `gettext "Connection:"`
pankso@108 228 <a class="button" href="$SCRIPT_NAME?start">
pankso@108 229 <img src="$IMAGES/start.png" />$(gettext "Start")</a>
pankso@108 230 <a class="button" href="$SCRIPT_NAME?stop">
pankso@108 231 <img src="$IMAGES/stop.png" />$(gettext "Stop")</a>
pankso@74 232 </div>
pankso@74 233 <div class="float-right">
pankso@108 234 `gettext "Configuration:"`
pankso@74 235 <a class="button" href="index.cgi?file=/etc/network.conf">network.conf</a>
pankso@108 236 <a class="button" href="$SCRIPT_NAME?eth">Ethernet</a>
pankso@108 237 <a class="button" href="$SCRIPT_NAME?wifi">Wireless</a>
pankso@74 238 </div>
pankso@38 239 </div>
pankso@38 240
pankso@106 241 $(list_network_interfaces)
pankso@38 242
pascal@133 243 <a name="hosts"></a>
pankso@108 244 <h3>$(gettext "Hosts")</h3>
pankso@108 245 <pre>
pankso@108 246 $(cat /etc/hosts)
pankso@108 247 </pre>
pankso@108 248 <a class="button" href="index.cgi?file=/etc/hosts&action=edit">
pankso@108 249 <img src="$IMAGES/edit.png" />$(gettext "Edit hosts")</a>
pankso@108 250
pankso@108 251 <h3>$(gettext "Hostname")</h3>
pankso@108 252 <form method="get" name="$SCRIPT_NAME"
pankso@108 253 <input type="text" name="hostname" value="$hostname" />
pankso@108 254 <input type="submit" value="$(gettext "Change hostname")"
pankso@108 255 </form>
pankso@108 256
pankso@108 257
pascal@133 258 <a name="ifconfig"></a>
pankso@106 259 <h3>$(gettext "Output of ") ifconfig</h3>
pankso@38 260 <pre>
pankso@106 261 $(ifconfig)
pankso@38 262 </pre>
pascal@68 263
pascal@133 264 <a name="routing"></a>
pascal@68 265 <h3>`gettext "Routing table"`</h3>
pascal@68 266 <pre>
pankso@106 267 $(route -n)
pascal@68 268 </pre>
pascal@68 269
pascal@133 270 <a name="dns"></a>
pascal@68 271 <h3>`gettext "Domain name resolution"`</h3>
pascal@68 272 <pre>
pankso@106 273 $(cat /etc/resolv.conf)
pascal@68 274 </pre>
pascal@68 275
pascal@133 276 <a name="arp"></a>
pascal@68 277 <h3>`gettext "ARP table"`</h3>
pascal@68 278 <pre>
pankso@106 279 $(arp)
pascal@68 280 </pre>
pascal@131 281
pascal@133 282 <a name="connections"></a>
pascal@131 283 <h3>`gettext "IP Connections"`</h3>
pascal@131 284 <pre>
pascal@131 285 $(netstat -anp 2> /dev/null | sed '/UNIX domain sockets/,$d')
pascal@131 286 </pre>
pankso@38 287 EOT
pankso@38 288 ;;
pankso@38 289 esac
pankso@38 290
pankso@38 291 xhtml_footer
pankso@38 292 exit 0