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