tazpanel view network.cgi @ rev 132

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