rev |
line source |
pankso@38
|
1 #!/bin/sh
|
pankso@38
|
2 #
|
pankso@38
|
3 # Network configuration CGI interface
|
pankso@38
|
4 #
|
al@419
|
5 # Copyright (C) 2012-2015 SliTaz GNU/Linux - BSD License
|
pankso@112
|
6 #
|
pankso@38
|
7
|
al@419
|
8
|
pankso@38
|
9 # Common functions from libtazpanel
|
al@419
|
10
|
pankso@38
|
11 . lib/libtazpanel
|
pankso@38
|
12 get_config
|
pascal@81
|
13 header
|
pankso@38
|
14
|
al@443
|
15 TITLE=$(_ 'TazPanel - Network')
|
pankso@42
|
16
|
pankso@106
|
17
|
al@419
|
18 # Start a Wi-Fi connection
|
al@419
|
19
|
pankso@247
|
20 start_wifi() {
|
pankso@247
|
21 sed -i \
|
al@419
|
22 -e 's|^WIFI=.*|WIFI="yes"|' \
|
al@419
|
23 -e 's|^DHCP=.*|DHCP="yes"|' \
|
al@419
|
24 -e 's|^STATIC=.*|STATIC="no"|' /etc/network.conf
|
pankso@247
|
25 ifconfig $WIFI_INTERFACE up
|
pankso@247
|
26 iwconfig $WIFI_INTERFACE txpower auto
|
Christian@273
|
27 /etc/init.d/network.sh restart | log
|
al@463
|
28
|
al@463
|
29 # Sleep until connection established (max 5 seconds)
|
al@463
|
30 for i in $(seq 5); do
|
al@419
|
31 [ -n "$(iwconfig 2>/dev/null | fgrep Link)" ] && break
|
al@419
|
32 sleep 1
|
al@419
|
33 done
|
al@419
|
34 }
|
al@419
|
35
|
al@419
|
36
|
al@420
|
37 # Start an Ethernet connection
|
al@420
|
38
|
al@420
|
39 start_eth() {
|
al@420
|
40 case "$(GET staticip)" in
|
al@420
|
41 on) DHCP='no'; STATIC='yes';;
|
al@420
|
42 *) DHCP='yes'; STATIC='no';;
|
al@420
|
43 esac
|
al@420
|
44
|
al@420
|
45 /etc/init.d/network.sh stop | log
|
al@420
|
46 sleep 2
|
al@420
|
47 sed -i \
|
al@420
|
48 -e "s|^INTERFACE=.*|INTERFACE=\"$(GET iface)\"|" \
|
al@420
|
49 -e 's|^WIFI=.*|WIFI="no"|' \
|
al@420
|
50 -e "s|^DHCP=.*|DHCP=\"$DHCP\"|" \
|
al@420
|
51 -e "s|^STATIC=.*|STATIC=\"$STATIC\"|" \
|
al@420
|
52 -e "s|^IP=.*|IP=\"$(GET ip)\"|" \
|
al@420
|
53 -e "s|^NETMASK=.*|NETMASK=\"$(GET netmask)\"|" \
|
al@420
|
54 -e "s|^GATEWAY=.*|GATEWAY=\"$(GET gateway)\"|" \
|
al@420
|
55 -e "s|^DNS_SERVER=.*|DNS_SERVER=\"$(GET dns)\"|" \
|
al@420
|
56 /etc/network.conf
|
al@420
|
57 /etc/init.d/network.sh start | log
|
al@420
|
58 . /etc/network.conf
|
al@420
|
59 }
|
al@420
|
60
|
al@420
|
61
|
al@419
|
62 # Use /etc/wpa/wpa.conf as single database for known networks, passwords, etc.
|
al@419
|
63 # Translate this data to use in javascript.
|
al@419
|
64
|
al@419
|
65 parse_wpa_conf() {
|
al@419
|
66 awk '
|
al@419
|
67 BEGIN { print "networks = ["; begin_list = 1; network = 0; }
|
al@419
|
68 {
|
al@419
|
69 if ($0 == "network={") {
|
al@419
|
70 if (begin_list == 0) print ",";
|
al@419
|
71 begin_list = 0;
|
al@419
|
72 printf "{"; begin_obj = 1;
|
al@419
|
73 network = 1; next;
|
al@419
|
74 }
|
al@419
|
75 if (network == 1) {
|
al@419
|
76 if ($0 ~ "=") {
|
al@419
|
77 if (begin_obj == 0) printf ", ";
|
al@419
|
78 begin_obj = 0;
|
al@463
|
79
|
al@463
|
80 # split line into variable and value (note "=" can appear in the value)
|
al@463
|
81 split($0, a, "="); variable = a[1];
|
al@463
|
82 value = gensub(variable "=", "", "");
|
al@463
|
83
|
al@463
|
84 # escape html entities
|
al@463
|
85 value = gensub("\\\\", "\\\\", "g", value);
|
al@463
|
86 value = gensub("&", "\\&", "g", value);
|
al@463
|
87 value = gensub("<", "\\<", "g", value);
|
al@463
|
88 value = gensub(">", "\\>", "g", value);
|
al@463
|
89 value = gensub("\"", "\\\"", "g", value);
|
al@463
|
90
|
al@463
|
91 # if value was already quoted - remove \" from begin and end
|
al@463
|
92 if (substr(value, 1, 2) == "\\\"")
|
al@463
|
93 value = substr(value, 3, length(value) - 4);
|
al@463
|
94
|
al@463
|
95 # output in form: variable:"escaped value"
|
al@463
|
96 printf "%s:\"%s\"", variable, value;
|
al@419
|
97 }
|
al@419
|
98 }
|
al@419
|
99 if (network == 1 && $0 ~ "}") { printf "}"; network = 0; next; }
|
al@419
|
100 }
|
al@419
|
101 END {print "\n];"}
|
al@419
|
102 ' /etc/wpa/wpa.conf | sed 's|\t||g;'
|
al@419
|
103 }
|
al@419
|
104
|
al@419
|
105
|
al@419
|
106 # Waiting for network link up
|
al@419
|
107
|
al@419
|
108 wait_up() {
|
al@463
|
109 for i in $(seq 5); do
|
al@419
|
110 [ -z "$(cat /sys/class/net/*/operstate | fgrep up)"] && sleep 1
|
al@419
|
111 done
|
pankso@247
|
112 }
|
pankso@247
|
113
|
al@463
|
114
|
pankso@41
|
115 # Actions commands before page is displayed
|
al@419
|
116
|
pascal@81
|
117 case " $(GET) " in
|
pascal@81
|
118 *\ start\ *)
|
al@419
|
119 /etc/init.d/network.sh start | log
|
pankso@41
|
120 # Here we sleep a bit to let udhcp get the lease before reloading
|
paul@205
|
121 # the page with status
|
al@419
|
122 wait_up ;;
|
pascal@81
|
123 *\ stop\ *)
|
pankso@76
|
124 /etc/init.d/network.sh stop | log ;;
|
naitsirhc@269
|
125 *\ restart\ *)
|
al@419
|
126 /etc/init.d/network.sh restart | log
|
al@419
|
127 wait_up ;;
|
al@420
|
128 *\ start_wifi\ *)
|
al@419
|
129 start_wifi ;;
|
al@420
|
130 *\ start_eth\ *)
|
al@420
|
131 start_eth ;;
|
pascal@475
|
132 *\ dowakeup\ *)
|
pascal@475
|
133 mac="$(GET macwakup)"
|
pascal@475
|
134 unset pass
|
pascal@477
|
135 [ "$(GET macpass)" ] && pass="-p $(GET macpass)"
|
pascal@475
|
136 if [ "$mac" ]; then
|
pascal@475
|
137 ether-wake $(GET iface) $mac $pass
|
pascal@475
|
138 else
|
pascal@475
|
139 ether-wake -b $(GET iface) $pass
|
pascal@475
|
140 fi
|
pascal@475
|
141 ;;
|
al@419
|
142 *\ host\ *)
|
al@419
|
143 get_hostname="$(GET host)"
|
al@443
|
144 echo $(_ 'Changed hostname: %s' $get_hostname) | log
|
al@303
|
145 echo "$get_hostname" > /etc/hostname ;;
|
pankso@41
|
146 esac
|
pankso@41
|
147
|
al@463
|
148 case " $(POST) " in
|
al@463
|
149 *\ connect_wifi\ *)
|
al@463
|
150 # Connect to a Wi-Fi network
|
al@463
|
151 /etc/init.d/network.sh stop | log
|
al@463
|
152 password="$(POST password)"
|
al@463
|
153
|
al@463
|
154 # Escape special characters to use with sed substitutions
|
al@463
|
155 password="$(echo -n "$password" | sed 's|\\|\\\\|g; s|&|\\\&|g' | sed "s|'|'\"'\"'|g")"
|
al@463
|
156
|
al@463
|
157 sed -i \
|
al@463
|
158 -e "s|^WIFI_ESSID=.*|WIFI_ESSID=\"$(POST essid)\"|" \
|
al@463
|
159 -e "s|^WIFI_BSSID=.*|WIFI_BSSID=\"$(POST bssid)\"|" \
|
al@463
|
160 -e "s|^WIFI_KEY_TYPE=.*|WIFI_KEY_TYPE=\"$(POST keyType)\"|" \
|
al@463
|
161 -e "s|^WIFI_KEY=.*|WIFI_KEY='$password'|" \
|
al@463
|
162 -e "s|^WIFI_EAP_METHOD=.*|WIFI_EAP_METHOD=\"$(POST eap)\"|" \
|
al@463
|
163 -e "s|^WIFI_CA_CERT=.*|WIFI_CA_CERT=\"$(POST caCert)\"|" \
|
al@463
|
164 -e "s|^WIFI_CLIENT_CERT=.*|WIFI_CLIENT_CERT=\"$(POST clientCert)\"|" \
|
al@463
|
165 -e "s|^WIFI_IDENTITY=.*|WIFI_IDENTITY=\"$(POST identity)\"|" \
|
al@463
|
166 -e "s|^WIFI_ANONYMOUS_IDENTITY=.*|WIFI_ANONYMOUS_IDENTITY=\"$(POST anonymousIdentity)\"|" \
|
al@463
|
167 -e "s|^WIFI_PHASE2=.*|WIFI_PHASE2=\"$(POST phase2)\"|" \
|
al@463
|
168 /etc/network.conf
|
al@463
|
169 . /etc/network.conf
|
al@463
|
170 start_wifi
|
al@463
|
171 ;;
|
al@463
|
172 esac
|
al@463
|
173
|
al@419
|
174
|
paul@127
|
175 # Get values only now since they could have been modified by actions.
|
al@419
|
176
|
pankso@108
|
177 . /etc/network.conf
|
pankso@108
|
178
|
al@419
|
179
|
al@419
|
180
|
al@419
|
181
|
al@419
|
182
|
pankso@38
|
183 #
|
pankso@41
|
184 # Main Commands for pages
|
pankso@38
|
185 #
|
pankso@38
|
186
|
pascal@81
|
187 case " $(GET) " in
|
al@419
|
188
|
pascal@136
|
189 *\ scan\ *)
|
pascal@136
|
190 # Scan open ports
|
al@419
|
191 scan=$(GET scan); back=$(GET back)
|
pascal@136
|
192 xhtml_header
|
al@443
|
193 LOADING_MSG=$(_ 'Scanning open ports...'); loading_msg
|
al@303
|
194
|
al@419
|
195 cat <<EOT
|
al@419
|
196 <section>
|
al@419
|
197 <header>
|
al@443
|
198 $(_ 'Port scanning for %s' $scan)
|
al@443
|
199 $(back_button "$back" "$(_ 'Network')" "")
|
al@419
|
200 </header>
|
al@419
|
201 <pre>$(pscan -b $scan)</pre>
|
al@419
|
202 </section>
|
pascal@136
|
203 EOT
|
pascal@136
|
204 ;;
|
al@303
|
205
|
al@419
|
206
|
pascal@81
|
207 *\ eth\ *)
|
pankso@41
|
208 # Wired connections settings
|
pankso@38
|
209 xhtml_header
|
al@419
|
210
|
al@420
|
211 PAR1="size=\"20\" required"; PAR="$PAR1 pattern=\"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\""
|
al@420
|
212
|
al@420
|
213 case "$STATIC" in
|
al@420
|
214 yes) use_static='checked';;
|
al@420
|
215 *) use_static='';;
|
al@420
|
216 esac
|
al@420
|
217
|
al@420
|
218 stop_disabled=''; start_disabled=''
|
al@420
|
219 if cat /sys/class/net/eth*/operstate | fgrep -q up; then
|
al@420
|
220 start_disabled='disabled'
|
al@420
|
221 else
|
al@420
|
222 stop_disabled='disabled'
|
pankso@107
|
223 fi
|
al@419
|
224
|
pascal@477
|
225 [ -s /etc/ethers ] || echo "#01:02:03:04:05:06 mystation" > /etc/ethers
|
al@419
|
226 cat <<EOT
|
al@443
|
227 <h2>$(_ 'Ethernet connection')</h2>
|
pascal@435
|
228 EOT
|
pascal@435
|
229 [ -w /etc/network.conf ] && cat <<EOT
|
al@443
|
230 <p>$(_ "Here you can configure a wired connection using DHCP to \
|
al@303
|
231 automatically get a random IP or configure a static/fixed IP")</p>
|
al@303
|
232
|
al@312
|
233 <section>
|
al@443
|
234 <header>$(_ 'Configuration')</header>
|
pascal@477
|
235 <form action="index.cgi" id="indexform"></form>
|
al@419
|
236 <form id="conf">
|
al@419
|
237 <input type="hidden" name="eth"/>
|
al@419
|
238 <div>
|
al@419
|
239 <table>
|
al@443
|
240 <tr><td>$(_ 'Interface')</td>
|
al@420
|
241 <td><select name="iface" value="$INTERFACE" style="width:100%">
|
al@419
|
242 $(cd /sys/class/net; ls -1 | awk -viface="$INTERFACE" '{
|
al@419
|
243 sel = ($0 == iface) ? " selected":""
|
al@419
|
244 printf "<option value=\"%s\"%s>%s", $0, sel, $0
|
al@419
|
245 }')
|
al@419
|
246 </select></td>
|
al@419
|
247 </tr>
|
al@443
|
248 <tr><td>$(_ 'Static IP')</td>
|
al@420
|
249 <td><label><input type="checkbox" name="staticip" id="staticip" $use_static/>
|
al@443
|
250 $(_ 'Use static IP')</td>
|
al@419
|
251 </tr>
|
al@443
|
252 <tr id="st1"><td>$(_ 'IP address')</td>
|
al@420
|
253 <td><input type="text" name="ip" value="$IP" $PAR/></td>
|
al@419
|
254 </tr>
|
al@443
|
255 <tr id="st2"><td>$(_ 'Netmask')</td>
|
al@420
|
256 <td><input type="text" name="netmask" value="$NETMASK" $PAR/></td>
|
al@419
|
257 </tr>
|
al@443
|
258 <tr id="st3"><td>$(_ 'Gateway')</td>
|
al@420
|
259 <td><input type="text" name="gateway" value="$GATEWAY" $PAR/></td>
|
al@420
|
260 </tr>
|
al@443
|
261 <tr id="st4"><td>$(_ 'DNS server')</td>
|
al@420
|
262 <td><input type="text" name="dns" value="$DNS_SERVER" $PAR/></td>
|
al@419
|
263 </tr>
|
pascal@475
|
264 <tr><td>$(_ 'Wake up')</td>
|
pascal@475
|
265 <td><label><input type="checkbox" name="wakeup" id="wakeup" />
|
pascal@475
|
266 $(_ 'Wake up machines by network')</td>
|
pascal@475
|
267 </tr>
|
pascal@475
|
268 <tr id="wk1"><td>$(_ 'MAC address to wake up')</td>
|
pascal@475
|
269 <td><input type="text" name="macwakup" title="$(_ 'Leave empty for a general wakeup')" $PAR/><!--
|
pascal@477
|
270 --><button form="indexform" name="file" value="/etc/ethers" data-icon="view">$(_ 'List')</button>
|
pascal@477
|
271 </td>
|
pascal@477
|
272 </tr>
|
pascal@477
|
273 <tr id="wk2"><td>$(_ 'MAC/IP address password')</td>
|
pascal@477
|
274 <td><input type="text" name="macpass" title="$(_ 'Leave empty for a general wakeup')" $PAR/><!--
|
pascal@477
|
275 --><button form="indexform" name="exec" value="ether-wake --help" data-icon="help">$(_ 'Help')</button>
|
pascal@475
|
276 </td>
|
pascal@475
|
277 </tr>
|
al@419
|
278 </table>
|
al@419
|
279 </div>
|
al@419
|
280 </form>
|
al@419
|
281 <footer><!--
|
al@443
|
282 --><button form="conf" type="submit" name="start_eth" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
|
al@443
|
283 --><button form="conf" type="submit" name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
|
pascal@475
|
284 --><button form="conf" type="submit" name="dowakeup" data-icon="clock" $stop_disabled >$(_ 'Wake up')</button><!--
|
al@419
|
285 --></footer>
|
al@419
|
286 </section>
|
al@419
|
287
|
al@419
|
288 <script type="text/javascript">
|
pascal@475
|
289 function check_change() {
|
pascal@475
|
290 enabled = document.getElementById('staticip').checked;
|
al@420
|
291 for (i = 1; i < 5; i++) {
|
pascal@475
|
292 document.getElementById('st' + i).style.display = enabled ? '' : 'none';
|
pascal@475
|
293 }
|
pascal@475
|
294 enabled = document.getElementById('wakeup').checked;
|
pascal@477
|
295 for (i = 1; i < 3; i++) {
|
pascal@475
|
296 document.getElementById('wk' + i).style.display = enabled ? '' : 'none';
|
al@420
|
297 }
|
al@420
|
298 }
|
al@419
|
299
|
pascal@475
|
300 document.getElementById('staticip').onchange = check_change;
|
pascal@475
|
301 document.getElementById('wakeup').onchange = check_change;
|
pascal@475
|
302 check_change();
|
al@419
|
303 </script>
|
pascal@435
|
304 EOT
|
pascal@435
|
305 cat <<EOT
|
al@419
|
306 <section>
|
al@419
|
307 <header>
|
al@443
|
308 $(_ 'Configuration file')
|
pascal@435
|
309 EOT
|
pascal@435
|
310 [ -w /etc/network.conf ] && cat <<EOT
|
al@419
|
311 <form action="index.cgi">
|
al@419
|
312 <input type="hidden" name="file" value="/etc/network.conf"/>
|
al@443
|
313 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
|
al@419
|
314 </form>
|
pascal@435
|
315 EOT
|
pascal@435
|
316 cat <<EOT
|
al@419
|
317 </header>
|
al@443
|
318 <div>$(_ "These values are the ethernet settings in the main /etc/network.conf configuration file")</div>
|
al@419
|
319 <pre>$(awk '{if($1 !~ "WIFI" && $1 !~ "#" && $1 != ""){print $0}}' /etc/network.conf | syntax_highlighter conf)</pre>
|
al@419
|
320 </section>
|
al@419
|
321 EOT
|
al@419
|
322 ;;
|
al@419
|
323
|
al@419
|
324
|
al@419
|
325
|
al@419
|
326 *\ wifi_list\ *)
|
al@419
|
327 # Catch ESSIDs and format output.
|
al@419
|
328 # We get the list of networks by Cell and without spaces.
|
al@419
|
329
|
al@443
|
330 HIDDEN="$(_ '(hidden)')"
|
al@419
|
331
|
al@419
|
332 cat <<EOT
|
al@419
|
333 <table class="wide center zebra">
|
pankso@107
|
334 <thead>
|
pankso@107
|
335 <tr>
|
al@443
|
336 <td>$(_ 'Name')</td>
|
al@443
|
337 <td>$(_ 'Signal level')</td>
|
al@443
|
338 <td>$(_ 'Channel')</td>
|
al@443
|
339 <td>$(_ 'Encryption')</td>
|
al@443
|
340 <td>$(_ 'Status')</td>
|
pankso@107
|
341 </tr>
|
pankso@107
|
342 </thead>
|
al@303
|
343 <tbody>
|
al@419
|
344 EOT
|
al@419
|
345 if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
|
al@419
|
346 ifconfig $WIFI_INTERFACE up
|
al@419
|
347 for i in $(iwlist $WIFI_INTERFACE scan | sed '/Cell /!d;s/.*Cell \([^ ]*\).*/Cell.\1/')
|
al@419
|
348 do
|
al@419
|
349 SCAN=$(iwlist $WIFI_INTERFACE scan last | sed "/$i/,/Cell/!d" | sed '$d')
|
al@419
|
350
|
al@419
|
351 BSSID=$(echo "$SCAN" | sed -n 's|.*Address: \([^ ]*\).*|\1|p')
|
al@419
|
352
|
al@419
|
353 CHANNEL=$(echo "$SCAN" | sed -n 's|.*Channel[:=]\([^ ]*\).*|\1|p')
|
al@419
|
354
|
al@419
|
355 QUALITY=$(echo "$SCAN" | sed -n 's|.*Quality[:=]\([^ ]*\).*|\1|p')
|
al@419
|
356 QUALITY_ICON="lvl$(( 5*${QUALITY:-0} ))" # lvl0 .. lvl4, lvl5
|
al@419
|
357 LEVEL=$(echo "$SCAN" | sed -n 's|.*Signal level[:=]\([^ ]*\).*|\1|p; s|-|−|')
|
al@419
|
358
|
al@419
|
359 ENCRYPTION=$(echo "$SCAN" | sed -n 's|.*Encryption key[:=]\([^ ]*\).*|\1|p') # on/off
|
al@419
|
360
|
al@419
|
361 ESSID=$(echo "$SCAN" | sed -n 's|.*ESSID:"\([^"]*\).*|\1|p')
|
al@419
|
362
|
al@419
|
363 # WPA Type - Group Cipher - Pairwise Ciphers - Authentication Suites
|
al@419
|
364 # {WPA|WPA2}-{TKIP|CCMP}-{TKIP|CCMP|TKIP CCMP}-{PSK|802.1x}
|
al@419
|
365 #CAPABILITIES="$(echo "$SCAN" | grep -e 'IE: .*WPA*' -A3 | cut -d: -f2 | sed -e 's|^ ||' -e '/WPA2/s|.*|=WPA2|' -e '/WPA /s|.*|=WPA|' -e '/--/d' | tr '\n' '-' | tr '=' '\n' | sed -e '/^$/d' -e 's|-$||')"
|
al@419
|
366
|
al@419
|
367 # Authentication type
|
al@419
|
368 AUTH="$(echo "$SCAN" | sed -n 's|.*Authentication Suites[^:]*: *\(.*\)|\1|p')"
|
al@419
|
369 if [ -n "$(echo -n $AUTH | fgrep PSK)" ]; then
|
al@419
|
370 # WPA-Personal. Authentication using password (PSK = pre-shared key)
|
al@419
|
371 WIFI_KEY_TYPE='WPA'
|
al@419
|
372 elif [ -n "$(echo -n $AUTH | fgrep 802.1x)" ]; then
|
al@419
|
373 # WPA-Enterprise. Authentication using username, password, certificates...
|
al@419
|
374 WIFI_KEY_TYPE='EAP'
|
al@419
|
375 else
|
al@419
|
376 WIFI_KEY_TYPE='NONE'
|
al@419
|
377 fi
|
al@419
|
378
|
al@419
|
379 # Check encryption type
|
al@419
|
380 if [ "$ENCRYPTION" == 'on' ]; then
|
al@419
|
381 # "WPA" or "WPA2" or "WPA/WPA2" (maybe also "WPA2/WPA")
|
al@419
|
382 ENC_SIMPLE=$(echo "$SCAN" | sed -n '/.*WPA.*/ s|.*\(WPA[^ ]*\).*|\1|p')
|
al@419
|
383 ENC_SIMPLE=$(echo $ENC_SIMPLE | sed 's| |/|')
|
al@419
|
384 ENC_ICON='sechi' # high
|
al@419
|
385 if [ -z "$ENC_SIMPLE" ]; then
|
al@419
|
386 WIFI_KEY_TYPE='WEP'
|
al@419
|
387 ENC_SIMPLE='WEP'; ENC_ICON='secmi' # middle
|
al@419
|
388 fi
|
al@419
|
389 else
|
al@419
|
390 WIFI_KEY_TYPE='NONE'
|
al@443
|
391 ENC_SIMPLE="$(_ 'None')"; ENC_ICON='seclo' # low
|
al@419
|
392 fi
|
al@419
|
393
|
al@419
|
394 # Connected or not connected...
|
al@419
|
395 if ifconfig $WIFI_INTERFACE | fgrep -q inet && \
|
al@419
|
396 iwconfig $WIFI_INTERFACE | fgrep -q "ESSID:\"$ESSID\""; then
|
al@443
|
397 status="$(_ 'Connected')"
|
al@419
|
398 else
|
al@419
|
399 status='---'
|
al@419
|
400 fi
|
al@419
|
401
|
al@419
|
402 cat <<EOT
|
al@419
|
403 <tr>
|
al@419
|
404 <td><a data-icon="wifi" onclick="loadcfg('$ESSID', '$BSSID', '$WIFI_KEY_TYPE')">${ESSID:-$HIDDEN}</a></td>
|
al@419
|
405 <td><span data-icon="$QUALITY_ICON" title="Quality: $QUALITY"> $LEVEL dBm</span></td>
|
al@419
|
406 <td>$CHANNEL</td>
|
al@419
|
407 <td><span data-icon="$ENC_ICON">$ENC_SIMPLE</span></td>
|
al@419
|
408 <td>$status</td>
|
al@419
|
409 </tr>
|
al@419
|
410 EOT
|
al@419
|
411 done
|
al@419
|
412 fi
|
al@419
|
413 cat <<EOT
|
al@303
|
414 </tbody>
|
al@419
|
415 </table>
|
al@419
|
416 EOT
|
al@419
|
417 exit 0
|
al@419
|
418 ;;
|
al@419
|
419
|
al@419
|
420
|
al@419
|
421 *\ wifi\ *)
|
al@419
|
422 # Wireless connections settings
|
al@419
|
423 xhtml_header
|
al@419
|
424
|
al@419
|
425 . /etc/network.conf
|
al@419
|
426 cat <<EOT
|
al@443
|
427 <h2>$(_ 'Wireless connection')</h2>
|
al@419
|
428 EOT
|
al@419
|
429
|
al@419
|
430 start_disabled=''; stop_disabled=''
|
al@419
|
431 if iwconfig 2>/dev/null | grep -q 'Tx-Power=off'; then
|
al@419
|
432 stop_disabled='disabled'
|
al@419
|
433 else
|
al@419
|
434 start_disabled='disabled'
|
al@419
|
435 fi
|
al@419
|
436
|
pascal@435
|
437 [ -w /etc/network.conf ] && cat <<EOT
|
pascal@435
|
438 <form>
|
pascal@435
|
439 <input type="hidden" name="wifi"/>
|
al@443
|
440 <button name="start_wifi" data-icon="start" $start_disabled>$(_ 'Start')</button><!--
|
al@443
|
441 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
|
al@443
|
442 --><button type="submit" data-icon="refresh" $stop_disabled >$(_ 'Scan' )</button>
|
pankso@107
|
443 </form>
|
al@419
|
444 EOT
|
al@419
|
445
|
pascal@435
|
446 [ -w /etc/network.conf ] &&
|
al@419
|
447 if [ -n "$start_disabled" ]; then
|
al@419
|
448 cat <<EOT
|
al@419
|
449 <section id="wifiList">
|
al@443
|
450 <div style="text-align: center;"><span id="ajaxStatus"></span>$(_ 'Scanning wireless interface...')</div>
|
al@312
|
451 </section>
|
pankso@107
|
452
|
al@419
|
453 <script type="text/javascript">
|
pascal@441
|
454 ajax('network.cgi?wifi_list', '1', 'wifiList');
|
al@419
|
455 $(parse_wpa_conf)
|
al@419
|
456 </script>
|
al@419
|
457 EOT
|
al@419
|
458
|
al@463
|
459 # Escape html characters in the WIFI_KEY
|
al@463
|
460 WIFI_KEY_ESCAPED="$(echo -n "$WIFI_KEY" | sed 's|&|\&|g; s|<|\<|g; s|>|\>|g; s|"|\"|g')"
|
al@419
|
461
|
al@419
|
462 cat <<EOT
|
al@312
|
463 <section>
|
al@443
|
464 <header>$(_ 'Connection')</header>
|
al@419
|
465 <div>
|
al@463
|
466 <form method="post" action="?wifi" id="connection">
|
al@420
|
467 <input type="hidden" name="connect_wifi"/>
|
al@420
|
468 <input type="hidden" name="bssid" id="bssid"/>
|
al@419
|
469 <table>
|
al@443
|
470 <tr><td>$(_ 'Network SSID')</td>
|
al@419
|
471 <td><input type="text" name="essid" value="$WIFI_ESSID" id="essid"/></td>
|
al@419
|
472 </tr>
|
al@303
|
473
|
al@443
|
474 <tr><td>$(_ 'Security')</td>
|
al@419
|
475 <td><select name="keyType" id="keyType">
|
al@443
|
476 <option value="NONE">$(_ 'None')</option>
|
al@419
|
477 <option value="WEP" >WEP</option>
|
al@419
|
478 <option value="WPA" >WPA/WPA2 PSK</option>
|
al@419
|
479 <option value="EAP" >802.1x EAP</option>
|
al@419
|
480 </select>
|
al@419
|
481 </td>
|
al@419
|
482 </tr>
|
al@419
|
483
|
al@419
|
484 <tr class="eap">
|
al@443
|
485 <td><div>$(_ 'EAP method')</div></td>
|
al@419
|
486 <td><div><select name="eap" id="eap">
|
al@419
|
487 <option value="PEAP">PEAP</option>
|
al@419
|
488 <option value="TLS" >TLS</option>
|
al@419
|
489 <option value="TTLS">TTLS</option>
|
al@419
|
490 <option value="PWD" >PWD</option>
|
al@419
|
491 </select>
|
al@419
|
492 </div></td>
|
al@419
|
493 </tr>
|
al@419
|
494
|
al@419
|
495 <tr class="eap1">
|
al@443
|
496 <td><div>$(_ 'Phase 2 authentication')</div></td>
|
al@419
|
497 <td><div><select name="phase2" id="phase2">
|
al@443
|
498 <option value="none" >$(_ 'None')</option>
|
al@419
|
499 <option value="pap" >PAP</option>
|
al@419
|
500 <option value="mschap" >MSCHAP</option>
|
al@419
|
501 <option value="mschapv2">MSCHAPV2</option>
|
al@419
|
502 <option value="gtc" >GTC</option>
|
al@419
|
503 </select>
|
al@419
|
504 </div></td>
|
al@419
|
505 </tr>
|
al@419
|
506
|
al@419
|
507 <tr class="eap1">
|
al@443
|
508 <td><div>$(_ 'CA certificate')</div></td>
|
al@419
|
509 <td><div><input type="text" name="caCert" id="caCert"></div></td>
|
al@419
|
510 </tr>
|
al@419
|
511
|
al@419
|
512 <tr class="eap1">
|
al@443
|
513 <td><div>$(_ 'User certificate')</div></td>
|
al@419
|
514 <td><div><input type="text" name="clientCert" id="clientCert"></div></td>
|
al@419
|
515 </tr>
|
al@419
|
516
|
al@419
|
517 <tr class="eap">
|
al@443
|
518 <td><div>$(_ 'Identity')</div></td>
|
al@419
|
519 <td><div><input type="text" name="identity" id="identity"></div></td>
|
al@419
|
520 </tr>
|
al@419
|
521
|
al@419
|
522 <tr class="eap1">
|
al@443
|
523 <td><div>$(_ 'Anonymous identity')</div></td>
|
al@419
|
524 <td><div><input type="text" name="anonymousIdentity" id="anonymousIdentity"></div></td>
|
al@419
|
525 </tr>
|
al@419
|
526
|
al@419
|
527 <tr class="wep wpa eap">
|
al@443
|
528 <td><div>$(_ 'Password')</div></td>
|
al@419
|
529 <td><div>
|
al@463
|
530 <input type="password" name="password" value="$WIFI_KEY_ESCAPED" id="password"/>
|
al@443
|
531 <span data-img="view" title="$(_ 'Show password')"
|
al@419
|
532 onmousedown="document.getElementById('password').type='text'; return false"
|
al@419
|
533 onmouseup="document.getElementById('password').type='password'"
|
al@419
|
534 onmouseout="document.getElementById('password').type='password'"
|
al@419
|
535 ></span>
|
al@419
|
536 </div></td>
|
al@419
|
537 </tr>
|
al@419
|
538
|
al@419
|
539 <script type="text/javascript">
|
al@419
|
540 function wifiSettingsChange() {
|
al@419
|
541 document.getElementById('connection').className =
|
al@419
|
542 document.getElementById('keyType').value.toLowerCase() + ' ' +
|
al@419
|
543 document.getElementById('eap').value.toLowerCase();
|
al@419
|
544 }
|
al@419
|
545 document.getElementById('keyType').onchange = wifiSettingsChange;
|
al@419
|
546 document.getElementById('eap').onchange = wifiSettingsChange;
|
al@419
|
547
|
al@419
|
548 document.getElementById('keyType').value = "$WIFI_KEY_TYPE"; wifiSettingsChange();
|
al@419
|
549 </script>
|
al@419
|
550
|
al@419
|
551 <style type="text/css">
|
al@419
|
552 #connection input[type="text"], #connection input[type="password"] { width: 14rem; }
|
al@419
|
553 #connection select { width: 14.4rem; }
|
al@419
|
554
|
al@419
|
555 #connection td { padding: 0; margin: 0; }
|
al@419
|
556 #connection [class] div {
|
al@419
|
557 max-height: 0; overflow: hidden; padding: 0; margin: 0;
|
al@419
|
558 -webkit-transition: all 0.5s ease-in-out;
|
al@419
|
559 -moz-transition: all 0.5s ease-in-out;
|
al@419
|
560 transition: all 0.5s ease-in-out;
|
al@419
|
561 }
|
al@419
|
562 .wep .wep div, .wpa .wpa div, .eap .eap div,
|
al@419
|
563 .eap.peap .eap1 div, .eap.tls .eap1 div, .eap.ttls .eap1 div {
|
al@419
|
564 max-height: 2em !important;
|
al@419
|
565 }
|
al@419
|
566 </style>
|
al@419
|
567
|
al@419
|
568 </table>
|
al@419
|
569 </form>
|
al@419
|
570 </div>
|
al@419
|
571 <footer>
|
al@443
|
572 <button form="connection" type="submit" name="wifi" data-icon="ok">$(_ 'Configure')</button>
|
al@419
|
573 </footer>
|
al@419
|
574 </section>
|
al@419
|
575 EOT
|
al@419
|
576 fi
|
al@419
|
577
|
al@419
|
578 cat <<EOT
|
al@419
|
579 <section>
|
al@419
|
580 <header>
|
al@443
|
581 $(_ 'Configuration file')
|
pascal@435
|
582 EOT
|
pascal@435
|
583 [ -w /etc/network.conf ] && cat <<EOT
|
al@419
|
584 <form action="index.cgi">
|
al@419
|
585 <input type="hidden" name="file" value="/etc/network.conf"/>
|
al@443
|
586 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
|
al@419
|
587 </form>
|
pascal@435
|
588 EOT
|
pascal@435
|
589 cat <<EOT
|
al@419
|
590 </header>
|
al@443
|
591 <div>$(_ "These values are the wifi settings in the main /etc/network.conf configuration file")</div>
|
al@463
|
592 <pre>$(grep ^WIFI /etc/network.conf | sed 's|WIFI_KEY=.*|WIFI_KEY="********"|' | syntax_highlighter conf)</pre>
|
al@419
|
593 </section>
|
al@419
|
594
|
al@419
|
595
|
al@419
|
596 <section>
|
al@443
|
597 <header>$(_ 'Output of iwconfig')</header>
|
al@419
|
598 <pre>$(iwconfig)</pre>
|
al@312
|
599 </section>
|
pankso@41
|
600 EOT
|
pankso@41
|
601 ;;
|
pankso@238
|
602
|
al@303
|
603
|
pankso@41
|
604 *)
|
pankso@41
|
605 # Main Network page starting with a summary
|
pankso@41
|
606 xhtml_header
|
al@419
|
607
|
al@419
|
608 stop_disabled=''; start_disabled=''
|
al@419
|
609 if cat /sys/class/net/*/operstate | fgrep -q up; then
|
al@419
|
610 start_disabled='disabled'
|
al@419
|
611 else
|
al@419
|
612 stop_disabled='disabled'
|
al@419
|
613 fi
|
al@419
|
614
|
al@439
|
615 if [ ! -w /etc/network.conf ]; then
|
al@439
|
616 start_disabled='disabled'; stop_disabled='disabled'
|
al@439
|
617 fi
|
al@439
|
618
|
al@419
|
619 cat <<EOT
|
al@443
|
620 <h2>$(_ 'Networking')</h2>
|
al@303
|
621
|
al@443
|
622 <p>$(_ 'Manage network connections and services')</p>
|
al@303
|
623
|
al@419
|
624 <form action="index.cgi" id="indexform"></form>
|
al@439
|
625
|
al@419
|
626 <form id="mainform"><!--
|
al@443
|
627 --><button name="start" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
|
al@443
|
628 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
|
al@443
|
629 --><button name="restart" data-icon="restart" $stop_disabled >$(_ 'Restart')</button>
|
al@419
|
630 </form>
|
al@439
|
631
|
al@419
|
632 <div class="float-right"><!--
|
al@443
|
633 -->$(_ 'Configuration:')<!--
|
al@419
|
634 --><button form="indexform" name="file" value="/etc/network.conf" data-icon="conf">network.conf</button><!--
|
al@419
|
635 --><button form="mainform" name="eth" data-icon="eth">Ethernet</button><!--
|
al@419
|
636 --><button form="mainform" name="wifi" data-icon="wifi">Wireless</button>
|
pankso@38
|
637 </div>
|
pankso@38
|
638
|
al@419
|
639
|
al@419
|
640 <section>
|
al@443
|
641 <header>$(_ 'Network interfaces')</header>
|
al@419
|
642 $(list_network_interfaces)
|
al@312
|
643 </section>
|
pankso@38
|
644
|
al@419
|
645
|
al@312
|
646 <section>
|
al@443
|
647 <header id="hosts">$(_ 'Hosts')</header>
|
al@419
|
648 <pre>$(cat /etc/hosts)</pre>
|
pascal@435
|
649 EOT
|
pascal@435
|
650 [ -w /etc/hosts ] && cat <<EOT
|
al@419
|
651 <footer>
|
al@419
|
652 <form action="index.cgi">
|
al@419
|
653 <input type="hidden" name="file" value="/etc/hosts"/>
|
al@443
|
654 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
|
al@419
|
655 </form>
|
al@419
|
656 </footer>
|
pascal@435
|
657 EOT
|
pascal@435
|
658 cat <<EOT
|
al@312
|
659 </section>
|
pankso@108
|
660
|
al@419
|
661
|
al@312
|
662 <section>
|
al@443
|
663 <header>$(_ 'Hostname')</header>
|
al@419
|
664 <footer>
|
pascal@435
|
665 EOT
|
pascal@435
|
666 if [ -w /etc/hostname ]; then
|
pascal@435
|
667 cat <<EOT
|
al@419
|
668 <form>
|
al@419
|
669 <!-- was: name="hostname"; please don't use 'name' in name: unwanted webkit styling -->
|
al@419
|
670 <input type="text" name="host" value="$(cat /etc/hostname)"/><!--
|
al@443
|
671 --><button type="submit" data-icon="ok">$(_ 'Change')</button>
|
al@419
|
672 </form>
|
pascal@435
|
673 EOT
|
pascal@435
|
674 else
|
pascal@435
|
675 cat /etc/hostname
|
pascal@435
|
676 fi
|
pascal@435
|
677 cat <<EOT
|
al@419
|
678 </footer>
|
al@312
|
679 </section>
|
pankso@108
|
680
|
al@419
|
681
|
al@312
|
682 <section>
|
al@443
|
683 <header id="ifconfig">$(_ 'Output of ifconfig')</header>
|
al@419
|
684 <pre>$(ifconfig)</pre>
|
al@312
|
685 </section>
|
pascal@68
|
686
|
al@419
|
687
|
al@312
|
688 <section>
|
al@443
|
689 <header id="routing">$(_ 'Routing table')</header>
|
al@419
|
690 <pre>$(route -n)</pre>
|
al@312
|
691 </section>
|
pascal@131
|
692
|
al@419
|
693
|
al@312
|
694 <section>
|
al@443
|
695 <header id="dns">$(_ 'Domain name resolution')</header>
|
al@419
|
696 <pre>$(cat /etc/resolv.conf)</pre>
|
al@312
|
697 </section>
|
al@303
|
698
|
al@419
|
699
|
al@312
|
700 <section>
|
al@443
|
701 <header id="arp">$(_ 'ARP table')</header>
|
al@419
|
702 <pre>$(arp)</pre>
|
al@312
|
703 </section>
|
al@303
|
704
|
al@419
|
705
|
al@312
|
706 <section>
|
al@443
|
707 <header id="connections">$(_ 'IP Connections')</header>
|
al@419
|
708 <pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
|
al@419
|
709 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
|
al@312
|
710 </section>
|
pankso@38
|
711 EOT
|
pankso@38
|
712 ;;
|
pankso@38
|
713 esac
|
pankso@38
|
714
|
pankso@38
|
715 xhtml_footer
|
pankso@38
|
716 exit 0
|