tazpanel view network.cgi @ rev 121

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