tazpanel view network.cgi @ rev 110

Move to settings.cgi and improve Panel configuration
author Christophe Lincoln <pankso@slitaz.org>
date Fri Apr 15 10:15:40 2011 +0200 (2011-04-15)
parents cab93136cc87
children dce3e66c3ba4
line source
1 #!/bin/sh
2 #
3 # Network configuration CGI interface
4 #
6 # Common functions from libtazpanel
7 . lib/libtazpanel
8 get_config
9 header
11 TITLE="- Network"
13 # Catch ESSIDs and format output for GTK tree. We get the list of
14 # networks by Cell and without spaces.
15 detect_wifi_networks()
16 {
17 table_start
18 cat << EOT
19 <thead>
20 <tr>
21 <td>$(gettext "Name")</td>
22 <td>$(gettext "Quality")</td>
23 <td>$(gettext "Encryption")</td>
24 <td>$(gettext "Status")</td>
25 </tr>
26 </thead>
27 EOT
28 if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
29 ifconfig $WIFI_INTERFACE up
30 for i in `iwlist $WIFI_INTERFACE scan | sed s/"Cell "/Cell-/ | grep "Cell-" | awk '{print $1}'`
31 do
32 SCAN=`iwlist $WIFI_INTERFACE scan last | \
33 awk '/(Cell|ESS|Qual|Encry|IE: WPA)/ {print}' | \
34 sed s/"Cell "/Cell-/ | grep -A 5 "$i"`
35 ESSID=`echo $SCAN | cut -d '"' -f 2`
36 if echo "$SCAN" | grep -q Quality; then
37 QUALITY=`echo $SCAN | sed 's/.*Quality=\([^ ]*\).*/\1/' | sed 's/.*Quality:\([^ ]*\).*/\1/'`
38 else
39 QUALITY="-"
40 fi
41 ENCRYPTION=`echo $SCAN | sed 's/.*key:\([^ ]*\).*/\1/'`
42 # Check encryption type
43 if echo "$SCAN" | grep -q WPA; then
44 ENCRYPTION="${ENCRYPTION} (WPA)"
45 fi
46 # Connected or not connected...
47 if ifconfig | grep -A 1 $WIFI_INTERFACE | \
48 fgrep -q inet && iwconfig $WIFI_INTERFACE | \
49 grep ESSID | fgrep -q -w "$ESSID"; then
50 status=$(gettext "Connected")
51 else
52 status="---"
53 fi
54 echo '<tr>'
55 echo "<td><img src='$IMAGES/wireless.png' />$ESSID</td>"
56 echo "<td>$QUALITY</td><td>$ENCRYPTION</td><td>$status $ip</td>"
57 echo '</tr>'
58 done
59 fi
60 table_end
61 }
63 # Actions commands before page is displayed
64 case " $(GET) " in
65 *\ start\ *)
66 # Here we sleep a bit to let udhcp get the lease before reloading
67 # page with status
68 /etc/init.d/network.sh start | log
69 sleep 2 ;;
70 *\ stop\ *)
71 /etc/init.d/network.sh stop | log ;;
72 *\ start-wifi\ *)
73 sed -i \
74 -e s'/^DHCP=.*/DHCP="yes"/' \
75 -e s'/^WIFI=.*/WIFI="yes"/' \
76 -e s'/^STATIC=.*/STATIC="no"/'/etc/network.conf
77 /etc/init.d/network.sh start | log
78 sleep 2 ;;
79 *\ hostname\ *)
80 echo $(gettext "Changed hostname:") $(GET hostname) | log
81 echo "$(GET hostname)" > /etc/hostname ;;
82 esac
84 # Get values only now since ther could have been modified by actions.
85 . /etc/network.conf
87 #
88 # Main Commands for pages
89 #
91 case " $(GET) " in
92 *\ eth\ *)
93 # Wired connections settings
94 xhtml_header
95 if [ "$(GET ip)" ]; then
96 LOADING_MSG=$(gettext "Setting up static IP...")
97 loading_msg
98 sed -i \
99 -e s"/^INTERFACE=.*/INTERFACE=\"$(GET iface)\""/ \
100 -e s'/^DHCP=.*/DHCP="no"/' \
101 -e s'/^WIFI=.*/WIFI="no"/' \
102 -e s'/^STATIC=.*/STATIC="yes"/' \
103 -e s"/^NETMASK=.*/NETMASK=\"$(GET netmask)\"/" \
104 -e s"/^GATEWAY=.*/GATEWAY=\"$(GET gateway)\"/" \
105 -e s"/^DNS_SERVER=.*/DNS_SERVER=\"$(GET dns)\"/" \
106 -e s"/^IP=.*/IP=\"$(GET ip)\"/" /etc/network.conf
107 /etc/init.d/network stop | log
108 sleep 2
109 /etc/init.d/network start | log
110 fi
111 . /etc/network.conf
112 cat << EOT
113 <h2>`gettext "Ethernet connection`</h2>
115 <h3>$(gettext "Setup a static IP")</h3>
116 <form method="get" action="$SCRIPT_NAME">
117 <input type="hidden" name="eth" />
118 $(table_start)
119 <thead>
120 <tr>
121 <td>$(gettext "Name")</td>
122 <td>$(gettext "Value")</td>
123 </tr>
124 </thead>
125 <tr>
126 <td>$(gettext "Interface")</td>
127 <td><input type="text" name="iface" size="20" value="$INTERFACE" /></td>
128 </tr>
129 <tr>
130 <td>$(gettext "IP address")</td>
131 <td><input type="text" name="ip" size="20" value="$IP" /></td>
132 </tr>
133 <tr>
134 <td>$(gettext "Netmask")</td>
135 <td><input type="text" name="netmask" size="20" value="$NETMASK" /></td>
136 </tr>
137 <tr>
138 <td>$(gettext "Gateway")</td>
139 <td><input type="text" name="gateway" size="20" value="$GATEWAY" /></td>
140 </tr>
141 <tr>
142 <td>$(gettext "DNS server")</td>
143 <td><input type="text" name="dns" size="20" value="$DNS_SERVER" /></td>
144 </tr>
145 $(table_end)
146 <input type="submit" value="`gettext "Activate"`">
147 </form>
149 <h3>$(gettext "Configuration file")</h3>
150 <p>
151 $(gettext "These values are the ethernet settings in the main
152 /etc/network.conf configuration file")
153 </p>
154 <pre>
155 $(grep ^[A-V] /etc/network.conf | syntax_highlighter conf)
156 </pre>
157 <a class="button" href="index.cgi?file=/etc/network.conf&action=edit">
158 <img src="$IMAGES/edit.png" />$(gettext "Manual Edit")</a>
159 EOT
160 ;;
161 *\ wifi\ *)
162 # Wireless connections settings
163 xhtml_header
164 LOADING_MSG=$(gettext "Scanning wireless interface...")
165 loading_msg
166 cat << EOT
167 <h2>`gettext "Wireless connection`</h2>
168 <div id="actions">
169 <a class="button" href="$SCRIPT_NAME?wifi&start-wifi=start-wifi">
170 <img src="$IMAGES/start.png" />$(gettext "Start")</a>
171 <a class="button" href="$SCRIPT_NAME?wifi&stop=stop">
172 <img src="$IMAGES/stop.png" />$(gettext "Stop")</a>
173 <a class="button" href="$SCRIPT_NAME?wifi=scan">
174 <img src="$IMAGES/recharge.png" />$(gettext "Scan")</a>
175 </div>
176 $(detect_wifi_networks)
177 EOT
178 cat << EOT
179 <h3>$(gettext "Configuration file")</h3>
180 <p>
181 $(gettext "These values are the wifi settings in the main
182 /etc/network.conf configuration file")
183 </p>
184 <pre>
185 $(grep ^WIFI /etc/network.conf | syntax_highlighter conf)
186 </pre>
187 <a class="button" href="index.cgi?file=/etc/network.conf&action=edit">
188 <img src="$IMAGES/edit.png" />$(gettext "Manual Edit")</a>
190 <h3>$(gettext "Output of") iwconfig</h3>
191 <pre>
192 $(iwconfig)
193 </pre>
194 EOT
195 ;;
196 *)
197 # Main Network page starting with a summary
198 xhtml_header
199 hostname=$(cat /etc/hostname)
200 cat << EOT
201 <h2>`gettext "Networking`</h2>
202 <p>
203 `gettext "Manage network connections and services`
204 </p>
205 <div id="actions">
206 <div class="float-left">
207 `gettext "Connection:"`
208 <a class="button" href="$SCRIPT_NAME?start">
209 <img src="$IMAGES/start.png" />$(gettext "Start")</a>
210 <a class="button" href="$SCRIPT_NAME?stop">
211 <img src="$IMAGES/stop.png" />$(gettext "Stop")</a>
212 </div>
213 <div class="float-right">
214 `gettext "Configuration:"`
215 <a class="button" href="index.cgi?file=/etc/network.conf">network.conf</a>
216 <a class="button" href="$SCRIPT_NAME?eth">Ethernet</a>
217 <a class="button" href="$SCRIPT_NAME?wifi">Wireless</a>
218 </div>
219 </div>
221 $(list_network_interfaces)
223 <h3>$(gettext "Hosts")</h3>
224 <pre>
225 $(cat /etc/hosts)
226 </pre>
227 <a class="button" href="index.cgi?file=/etc/hosts&action=edit">
228 <img src="$IMAGES/edit.png" />$(gettext "Edit hosts")</a>
230 <h3>$(gettext "Hostname")</h3>
231 <form method="get" name="$SCRIPT_NAME"
232 <input type="text" name="hostname" value="$hostname" />
233 <input type="submit" value="$(gettext "Change hostname")"
234 </form>
237 <h3>$(gettext "Output of ") ifconfig</h3>
238 <pre>
239 $(ifconfig)
240 </pre>
242 <h3>`gettext "Routing table"`</h3>
243 <pre>
244 $(route -n)
245 </pre>
247 <h3>`gettext "Domain name resolution"`</h3>
248 <pre>
249 $(cat /etc/resolv.conf)
250 </pre>
252 <h3>`gettext "ARP table"`</h3>
253 <pre>
254 $(arp)
255 </pre>
256 EOT
257 ;;
258 esac
260 xhtml_footer
261 exit 0