tazpanel annotate network.cgi @ rev 112

Add some doc/help, use a BSD License and add COPYING file
author Christophe Lincoln <pankso@slitaz.org>
date Fri Apr 15 11:32:56 2011 +0200 (2011-04-15)
parents b898c9887a62
children 20b80d61e7c7
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
pankso@109 86 # Get values only now since ther 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@81 94 *\ eth\ *)
pankso@41 95 # Wired connections settings
pankso@38 96 xhtml_header
pankso@107 97 if [ "$(GET ip)" ]; then
pankso@107 98 LOADING_MSG=$(gettext "Setting up static IP...")
pankso@107 99 loading_msg
pankso@107 100 sed -i \
pankso@107 101 -e s"/^INTERFACE=.*/INTERFACE=\"$(GET iface)\""/ \
pankso@107 102 -e s'/^DHCP=.*/DHCP="no"/' \
pankso@107 103 -e s'/^WIFI=.*/WIFI="no"/' \
pankso@107 104 -e s'/^STATIC=.*/STATIC="yes"/' \
pankso@107 105 -e s"/^NETMASK=.*/NETMASK=\"$(GET netmask)\"/" \
pankso@107 106 -e s"/^GATEWAY=.*/GATEWAY=\"$(GET gateway)\"/" \
pankso@107 107 -e s"/^DNS_SERVER=.*/DNS_SERVER=\"$(GET dns)\"/" \
pankso@107 108 -e s"/^IP=.*/IP=\"$(GET ip)\"/" /etc/network.conf
pankso@107 109 /etc/init.d/network stop | log
pankso@107 110 sleep 2
pankso@107 111 /etc/init.d/network start | log
pankso@107 112 fi
pankso@107 113 . /etc/network.conf
pankso@38 114 cat << EOT
pankso@41 115 <h2>`gettext "Ethernet connection`</h2>
pankso@107 116
pankso@107 117 <h3>$(gettext "Setup a static IP")</h3>
pankso@107 118 <form method="get" action="$SCRIPT_NAME">
pankso@107 119 <input type="hidden" name="eth" />
pankso@107 120 $(table_start)
pankso@107 121 <thead>
pankso@107 122 <tr>
pankso@107 123 <td>$(gettext "Name")</td>
pankso@107 124 <td>$(gettext "Value")</td>
pankso@107 125 </tr>
pankso@107 126 </thead>
pankso@107 127 <tr>
pankso@107 128 <td>$(gettext "Interface")</td>
pankso@107 129 <td><input type="text" name="iface" size="20" value="$INTERFACE" /></td>
pankso@107 130 </tr>
pankso@107 131 <tr>
pankso@107 132 <td>$(gettext "IP address")</td>
pankso@107 133 <td><input type="text" name="ip" size="20" value="$IP" /></td>
pankso@107 134 </tr>
pankso@107 135 <tr>
pankso@107 136 <td>$(gettext "Netmask")</td>
pankso@107 137 <td><input type="text" name="netmask" size="20" value="$NETMASK" /></td>
pankso@107 138 </tr>
pankso@107 139 <tr>
pankso@107 140 <td>$(gettext "Gateway")</td>
pankso@107 141 <td><input type="text" name="gateway" size="20" value="$GATEWAY" /></td>
pankso@107 142 </tr>
pankso@107 143 <tr>
pankso@107 144 <td>$(gettext "DNS server")</td>
pankso@107 145 <td><input type="text" name="dns" size="20" value="$DNS_SERVER" /></td>
pankso@107 146 </tr>
pankso@107 147 $(table_end)
pankso@107 148 <input type="submit" value="`gettext "Activate"`">
pankso@107 149 </form>
pankso@107 150
pankso@107 151 <h3>$(gettext "Configuration file")</h3>
pankso@107 152 <p>
pankso@107 153 $(gettext "These values are the ethernet settings in the main
pankso@107 154 /etc/network.conf configuration file")
pankso@107 155 </p>
pankso@41 156 <pre>
pankso@107 157 $(grep ^[A-V] /etc/network.conf | syntax_highlighter conf)
pankso@41 158 </pre>
pankso@107 159 <a class="button" href="index.cgi?file=/etc/network.conf&action=edit">
pankso@107 160 <img src="$IMAGES/edit.png" />$(gettext "Manual Edit")</a>
pankso@41 161 EOT
pankso@41 162 ;;
pascal@81 163 *\ wifi\ *)
pankso@41 164 # Wireless connections settings
pankso@41 165 xhtml_header
pankso@106 166 LOADING_MSG=$(gettext "Scanning wireless interface...")
pankso@106 167 loading_msg
pankso@41 168 cat << EOT
pankso@41 169 <h2>`gettext "Wireless connection`</h2>
pankso@106 170 <div id="actions">
pankso@108 171 <a class="button" href="$SCRIPT_NAME?wifi&start-wifi=start-wifi">
pankso@108 172 <img src="$IMAGES/start.png" />$(gettext "Start")</a>
pankso@108 173 <a class="button" href="$SCRIPT_NAME?wifi&stop=stop">
pankso@108 174 <img src="$IMAGES/stop.png" />$(gettext "Stop")</a>
pankso@106 175 <a class="button" href="$SCRIPT_NAME?wifi=scan">
pankso@106 176 <img src="$IMAGES/recharge.png" />$(gettext "Scan")</a>
pankso@106 177 </div>
pankso@106 178 $(detect_wifi_networks)
pankso@106 179 EOT
pankso@106 180 cat << EOT
pankso@98 181 <h3>$(gettext "Configuration file")</h3>
pankso@98 182 <p>
pankso@98 183 $(gettext "These values are the wifi settings in the main
pankso@98 184 /etc/network.conf configuration file")
pankso@98 185 </p>
pankso@41 186 <pre>
pankso@107 187 $(grep ^WIFI /etc/network.conf | syntax_highlighter conf)
pankso@41 188 </pre>
pankso@98 189 <a class="button" href="index.cgi?file=/etc/network.conf&action=edit">
pankso@98 190 <img src="$IMAGES/edit.png" />$(gettext "Manual Edit")</a>
pankso@106 191
pankso@106 192 <h3>$(gettext "Output of") iwconfig</h3>
pankso@106 193 <pre>
pankso@106 194 $(iwconfig)
pankso@106 195 </pre>
pankso@41 196 EOT
pankso@41 197 ;;
pankso@41 198 *)
pankso@41 199 # Main Network page starting with a summary
pankso@41 200 xhtml_header
pankso@108 201 hostname=$(cat /etc/hostname)
pankso@41 202 cat << EOT
pankso@41 203 <h2>`gettext "Networking`</h2>
pankso@41 204 <p>
paul@52 205 `gettext "Manage network connections and services`
pankso@41 206 </p>
pankso@41 207 <div id="actions">
pankso@74 208 <div class="float-left">
pankso@41 209 `gettext "Connection:"`
pankso@108 210 <a class="button" href="$SCRIPT_NAME?start">
pankso@108 211 <img src="$IMAGES/start.png" />$(gettext "Start")</a>
pankso@108 212 <a class="button" href="$SCRIPT_NAME?stop">
pankso@108 213 <img src="$IMAGES/stop.png" />$(gettext "Stop")</a>
pankso@74 214 </div>
pankso@74 215 <div class="float-right">
pankso@108 216 `gettext "Configuration:"`
pankso@74 217 <a class="button" href="index.cgi?file=/etc/network.conf">network.conf</a>
pankso@108 218 <a class="button" href="$SCRIPT_NAME?eth">Ethernet</a>
pankso@108 219 <a class="button" href="$SCRIPT_NAME?wifi">Wireless</a>
pankso@74 220 </div>
pankso@38 221 </div>
pankso@38 222
pankso@106 223 $(list_network_interfaces)
pankso@38 224
pankso@108 225 <h3>$(gettext "Hosts")</h3>
pankso@108 226 <pre>
pankso@108 227 $(cat /etc/hosts)
pankso@108 228 </pre>
pankso@108 229 <a class="button" href="index.cgi?file=/etc/hosts&action=edit">
pankso@108 230 <img src="$IMAGES/edit.png" />$(gettext "Edit hosts")</a>
pankso@108 231
pankso@108 232 <h3>$(gettext "Hostname")</h3>
pankso@108 233 <form method="get" name="$SCRIPT_NAME"
pankso@108 234 <input type="text" name="hostname" value="$hostname" />
pankso@108 235 <input type="submit" value="$(gettext "Change hostname")"
pankso@108 236 </form>
pankso@108 237
pankso@108 238
pankso@106 239 <h3>$(gettext "Output of ") ifconfig</h3>
pankso@38 240 <pre>
pankso@106 241 $(ifconfig)
pankso@38 242 </pre>
pascal@68 243
pascal@68 244 <h3>`gettext "Routing table"`</h3>
pascal@68 245 <pre>
pankso@106 246 $(route -n)
pascal@68 247 </pre>
pascal@68 248
pascal@68 249 <h3>`gettext "Domain name resolution"`</h3>
pascal@68 250 <pre>
pankso@106 251 $(cat /etc/resolv.conf)
pascal@68 252 </pre>
pascal@68 253
pascal@68 254 <h3>`gettext "ARP table"`</h3>
pascal@68 255 <pre>
pankso@106 256 $(arp)
pascal@68 257 </pre>
pankso@38 258 EOT
pankso@38 259 ;;
pankso@38 260 esac
pankso@38 261
pankso@38 262 xhtml_footer
pankso@38 263 exit 0