tazpanel view network.cgi @ rev 174
tazpanel: typo
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun May 22 10:04:10 2011 +0200 (2011-05-22) |
parents | 6aa939753084 |
children | e0d1571d49ba |
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>
132 <p>
133 $(gettext "Here you can configure a wired connection using DHCP to
134 automatically get a random IP or configure a static/fixed IP")
135 </p>
136 <h3>$(gettext "Configuration")</h3>
137 <form method="get" action="$SCRIPT_NAME">
138 <input type="hidden" name="eth" />
139 $(table_start)
140 <thead>
141 <tr>
142 <td>$(gettext "Name")</td>
143 <td>$(gettext "Value")</td>
144 </tr>
145 </thead>
146 <tr>
147 <td>$(gettext "Interface")</td>
148 <td><input type="text" name="iface" size="20" value="$INTERFACE" /></td>
149 </tr>
150 <tr>
151 <td>$(gettext "IP address")</td>
152 <td><input type="text" name="ip" size="20" value="$IP" /></td>
153 </tr>
154 <tr>
155 <td>$(gettext "Netmask")</td>
156 <td><input type="text" name="netmask" size="20" value="$NETMASK" /></td>
157 </tr>
158 <tr>
159 <td>$(gettext "Gateway")</td>
160 <td><input type="text" name="gateway" size="20" value="$GATEWAY" /></td>
161 </tr>
162 <tr>
163 <td>$(gettext "DNS server")</td>
164 <td><input type="text" name="dns" size="20" value="$DNS_SERVER" /></td>
165 </tr>
166 $(table_end)
167 <input type="submit" name="static" value="`gettext "Activate (static)"`">
168 <input type="submit" name="dhcp" value="`gettext "Activate (DHCP)"`">
169 <input type="submit" name="disable" value="`gettext "Disable"`">
170 </form>
172 <h3>$(gettext "Configuration file")</h3>
173 <p>
174 $(gettext "These values are the ethernet settings in the main
175 /etc/network.conf configuration file")
176 </p>
177 <pre>
178 $(grep ^[A-V] /etc/network.conf | syntax_highlighter conf)
179 </pre>
180 <a class="button" href="index.cgi?file=/etc/network.conf&action=edit">
181 <img src="$IMAGES/edit.png" />$(gettext "Manual Edit")</a>
182 EOT
183 ;;
184 *\ wifi\ *)
185 # Wireless connections settings
186 xhtml_header
187 LOADING_MSG=$(gettext "Scanning wireless interface...")
188 loading_msg
189 cat << EOT
190 <h2>`gettext "Wireless connection"`</h2>
191 <div id="actions">
192 <a class="button" href="$SCRIPT_NAME?wifi&start-wifi=start-wifi">
193 <img src="$IMAGES/start.png" />$(gettext "Start")</a>
194 <a class="button" href="$SCRIPT_NAME?wifi&stop=stop">
195 <img src="$IMAGES/stop.png" />$(gettext "Stop")</a>
196 <a class="button" href="$SCRIPT_NAME?wifi=scan">
197 <img src="$IMAGES/recharge.png" />$(gettext "Scan")</a>
198 </div>
199 $(detect_wifi_networks)
200 EOT
201 cat << EOT
202 <h3>$(gettext "Configuration file")</h3>
203 <p>
204 $(gettext "These values are the wifi settings in the main
205 /etc/network.conf configuration file")
206 </p>
207 <pre>
208 $(grep ^WIFI /etc/network.conf | syntax_highlighter conf)
209 </pre>
210 <a class="button" href="index.cgi?file=/etc/network.conf&action=edit">
211 <img src="$IMAGES/edit.png" />$(gettext "Manual Edit")</a>
213 <h3>$(gettext "Output of") iwconfig</h3>
214 <pre>
215 $(iwconfig)
216 </pre>
217 EOT
218 ;;
219 *)
220 # Main Network page starting with a summary
221 xhtml_header
222 hostname=$(cat /etc/hostname)
223 cat << EOT
224 <h2>`gettext "Networking"`</h2>
225 <p>
226 `gettext "Manage network connections and services"`
227 </p>
228 <div id="actions">
229 <div class="float-left">
230 `gettext "Connection:"`
231 <a class="button" href="$SCRIPT_NAME?start">
232 <img src="$IMAGES/start.png" />$(gettext "Start")</a>
233 <a class="button" href="$SCRIPT_NAME?stop">
234 <img src="$IMAGES/stop.png" />$(gettext "Stop")</a>
235 </div>
236 <div class="float-right">
237 `gettext "Configuration:"`
238 <a class="button" href="index.cgi?file=/etc/network.conf">network.conf</a>
239 <a class="button" href="$SCRIPT_NAME?eth">Ethernet</a>
240 <a class="button" href="$SCRIPT_NAME?wifi">Wireless</a>
241 </div>
242 </div>
244 $(list_network_interfaces)
246 <a name="hosts"></a>
247 <h3>$(gettext "Hosts")</h3>
248 <pre>
249 $(cat /etc/hosts)
250 </pre>
251 <a class="button" href="index.cgi?file=/etc/hosts&action=edit">
252 <img src="$IMAGES/edit.png" />$(gettext "Edit hosts")</a>
254 <h3>$(gettext "Hostname")</h3>
255 <form method="get" name="$SCRIPT_NAME"
256 <input type="text" name="hostname" value="$hostname" />
257 <input type="submit" value="$(gettext "Change hostname")"
258 </form>
261 <a name="ifconfig"></a>
262 <h3>$(gettext "Output of ") ifconfig</h3>
263 <pre>
264 $(ifconfig)
265 </pre>
267 <a name="routing"></a>
268 <h3>`gettext "Routing table"`</h3>
269 <pre>
270 $(route -n)
271 </pre>
273 <a name="dns"></a>
274 <h3>`gettext "Domain name resolution"`</h3>
275 <pre>
276 $(cat /etc/resolv.conf)
277 </pre>
279 <a name="arp"></a>
280 <h3>`gettext "ARP table"`</h3>
281 <pre>
282 $(arp)
283 </pre>
285 <a name="connections"></a>
286 <h3>`gettext "IP Connections"`</h3>
287 <pre>
288 $(netstat -anp 2> /dev/null | sed -e '/UNIX domain sockets/,$d' \
289 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')
290 </pre>
291 EOT
292 ;;
293 esac
295 xhtml_footer
296 exit 0