tazpanel view network.cgi @ rev 523

lib/libtazpanel: add edit_button()
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Aug 08 16:06:55 2015 +0200 (2015-08-08)
parents 8b67a70440c2
children 5323427d34b9
line source
1 #!/bin/sh
2 #
3 # Network configuration CGI interface
4 #
5 # Copyright (C) 2012-2015 SliTaz GNU/Linux - BSD License
6 #
9 # Common functions from libtazpanel
11 . lib/libtazpanel
12 get_config
13 header
15 TITLE=$(_ 'Network')
17 ip_forward=/proc/sys/net/ipv4/ip_forward
19 # Start a Wi-Fi connection
21 start_wifi() {
22 sed -i \
23 -e 's|^WIFI=.*|WIFI="yes"|' \
24 -e 's|^DHCP=.*|DHCP="yes"|' \
25 -e 's|^STATIC=.*|STATIC="no"|' /etc/network.conf
26 ifconfig $WIFI_INTERFACE up
27 iwconfig $WIFI_INTERFACE txpower auto
28 /etc/init.d/network.sh restart | log
30 # Sleep until connection established (max 5 seconds)
31 for i in $(seq 5); do
32 [ -n "$(iwconfig 2>/dev/null | fgrep Link)" ] && break
33 sleep 1
34 done
35 }
38 # Start an Ethernet connection
40 start_eth() {
41 case "$(GET staticip)" in
42 on) DHCP='no'; STATIC='yes';;
43 *) DHCP='yes'; STATIC='no';;
44 esac
46 /etc/init.d/network.sh stop | log
47 sleep 2
48 sed -i \
49 -e "s|^INTERFACE=.*|INTERFACE=\"$(GET iface)\"|" \
50 -e 's|^WIFI=.*|WIFI="no"|' \
51 -e "s|^DHCP=.*|DHCP=\"$DHCP\"|" \
52 -e "s|^STATIC=.*|STATIC=\"$STATIC\"|" \
53 -e "s|^IP=.*|IP=\"$(GET ip)\"|" \
54 -e "s|^NETMASK=.*|NETMASK=\"$(GET netmask)\"|" \
55 -e "s|^GATEWAY=.*|GATEWAY=\"$(GET gateway)\"|" \
56 -e "s|^DNS_SERVER=.*|DNS_SERVER=\"$(GET dns)\"|" \
57 /etc/network.conf
58 /etc/init.d/network.sh start | log
59 . /etc/network.conf
60 }
63 # Use /etc/wpa/wpa.conf as single database for known networks, passwords, etc.
64 # Translate this data to use in javascript.
66 parse_wpa_conf() {
67 awk '
68 BEGIN { print "networks = ["; begin_list = 1; network = 0; }
69 {
70 if ($0 == "network={") {
71 if (begin_list == 0) print ",";
72 begin_list = 0;
73 printf "{"; begin_obj = 1;
74 network = 1; next;
75 }
76 if (network == 1) {
77 if ($0 ~ "=") {
78 if (begin_obj == 0) printf ", ";
79 begin_obj = 0;
81 # split line into variable and value (note "=" can appear in the value)
82 split($0, a, "="); variable = a[1];
83 value = gensub(variable "=", "", "");
85 # escape html entities
86 value = gensub("\\\\", "\\\\", "g", value);
87 value = gensub("&", "\\&amp;", "g", value);
88 value = gensub("<", "\\&lt;", "g", value);
89 value = gensub(">", "\\&gt;", "g", value);
90 value = gensub("\"", "\\\"", "g", value);
92 # if value was already quoted - remove \" from begin and end
93 if (substr(value, 1, 2) == "\\\"")
94 value = substr(value, 3, length(value) - 4);
96 # output in form: variable:"escaped value"
97 printf "%s:\"%s\"", variable, value;
98 }
99 }
100 if (network == 1 && $0 ~ "}") { printf "}"; network = 0; next; }
101 }
102 END {print "\n];"}
103 ' /etc/wpa/wpa.conf | sed 's|\t||g;'
104 }
107 # Waiting for network link up
109 wait_up() {
110 for i in $(seq 5); do
111 [ -z "$(cat /sys/class/net/*/operstate | fgrep up)"] && sleep 1
112 done
113 }
115 select_if() {
116 echo '<select name="interface">'
117 for i in $(ls /sys/class/net); do
118 grep -qs 1 /sys/class/net/$i/carrier &&
119 echo "<option>$i"
120 done
121 echo '</select>'
122 }
124 # Actions commands before page is displayed
126 case " $(GET) " in
127 *\ start\ *)
128 /etc/init.d/network.sh start | log
129 # Here we sleep a bit to let udhcp get the lease before reloading
130 # the page with status
131 wait_up ;;
132 *\ stop\ *)
133 /etc/init.d/network.sh stop | log ;;
134 *\ restart\ *)
135 /etc/init.d/network.sh restart | log
136 wait_up ;;
137 *\ start_wifi\ *)
138 start_wifi ;;
139 *\ start_eth\ *)
140 start_eth ;;
141 *\ dowakeup\ *)
142 mac="$(GET macwakup)"
143 unset pass
144 [ "$(GET macpass)" ] && pass="-p $(GET macpass)"
145 if [ "$mac" ]; then
146 ether-wake $(GET iface) $mac $pass
147 else
148 ether-wake -b $(GET iface) $pass
149 fi
150 ;;
151 *\ host\ *)
152 get_hostname="$(GET host)"
153 echo $(_ 'Changed hostname: %s' $get_hostname) | log
154 echo "$get_hostname" > /etc/hostname ;;
155 *\ rmarp\ *)
156 arp -d $(urldecode "$(GET entry)") ;;
157 *\ addarp\ *)
158 arp -i $(GET interface) -s $(GET ip) $(GET mac) ;;
159 *\ proxyarp\ *)
160 arp -i $(GET interface) -Ds $(GET ip) $(GET interface) pub ;;
161 *\ toggleipforward\ *)
162 echo $((1 - $(cat $ip_forward))) > $ip_forward ;;
163 esac
165 case " $(POST) " in
166 *\ connect_wifi\ *)
167 # Connect to a Wi-Fi network
168 /etc/init.d/network.sh stop | log
169 password="$(POST password)"
171 # Escape special characters to use with sed substitutions
172 password="$(echo -n "$password" | sed 's|\\|\\\\|g; s|&|\\\&|g' | sed "s|'|'\"'\"'|g")"
174 sed -i \
175 -e "s|^WIFI_ESSID=.*|WIFI_ESSID=\"$(POST essid)\"|" \
176 -e "s|^WIFI_BSSID=.*|WIFI_BSSID=\"$(POST bssid)\"|" \
177 -e "s|^WIFI_KEY_TYPE=.*|WIFI_KEY_TYPE=\"$(POST keyType)\"|" \
178 -e "s|^WIFI_KEY=.*|WIFI_KEY='$password'|" \
179 -e "s|^WIFI_EAP_METHOD=.*|WIFI_EAP_METHOD=\"$(POST eap)\"|" \
180 -e "s|^WIFI_CA_CERT=.*|WIFI_CA_CERT=\"$(POST caCert)\"|" \
181 -e "s|^WIFI_CLIENT_CERT=.*|WIFI_CLIENT_CERT=\"$(POST clientCert)\"|" \
182 -e "s|^WIFI_IDENTITY=.*|WIFI_IDENTITY=\"$(POST identity)\"|" \
183 -e "s|^WIFI_ANONYMOUS_IDENTITY=.*|WIFI_ANONYMOUS_IDENTITY=\"$(POST anonymousIdentity)\"|" \
184 -e "s|^WIFI_PHASE2=.*|WIFI_PHASE2=\"$(POST phase2)\"|" \
185 /etc/network.conf
186 . /etc/network.conf
187 start_wifi
188 ;;
189 esac
192 # Get values only now since they could have been modified by actions.
194 . /etc/network.conf
200 #
201 # Main Commands for pages
202 #
204 case " $(GET) " in
206 *\ scan\ *)
207 # Scan open ports
208 scan=$(GET scan); back=$(GET back)
209 xhtml_header
210 loading_msg "$(_ 'Scanning open ports...')"
212 cat <<EOT
213 <section>
214 <header>
215 $(_ 'Port scanning for %s' $scan)
216 $(back_button "$back" "$(_ 'Network')" "")
217 </header>
218 <pre>$(pscan -b $scan)</pre>
219 </section>
220 EOT
221 ;;
224 *\ eth\ *)
225 # Wired connections settings
226 xhtml_header "$(_ 'Ethernet connection')"
228 PAR1="size=\"20\" required"; PAR="$PAR1 pattern=\"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\""
230 case "$STATIC" in
231 yes) use_static='checked';;
232 *) use_static='';;
233 esac
235 stop_disabled=''; start_disabled=''
236 if cat /sys/class/net/eth*/operstate | fgrep -q up; then
237 start_disabled='disabled'
238 else
239 stop_disabled='disabled'
240 fi
242 [ -s /etc/ethers ] || echo "#01:02:03:04:05:06 mystation" > /etc/ethers
243 [ -w /etc/network.conf ] && cat <<EOT
244 <p>$(_ "Here you can configure a wired connection using DHCP to \
245 automatically get a random IP or configure a static/fixed IP")</p>
247 <section>
248 <header>$(_ 'Configuration')</header>
249 <form action="index.cgi" id="indexform"></form>
250 <form id="conf">
251 <input type="hidden" name="eth"/>
252 <div>
253 <table>
254 <tr><td>$(_ 'Interface')</td>
255 <td><select name="iface" value="$INTERFACE" style="width:100%">
256 $(cd /sys/class/net; ls -1 | awk -viface="$INTERFACE" '{
257 sel = ($0 == iface) ? " selected":""
258 printf "<option value=\"%s\"%s>%s", $0, sel, $0
259 }')
260 </select></td>
261 </tr>
262 <tr><td>$(_ 'Static IP')</td>
263 <td><label><input type="checkbox" name="staticip" id="staticip" $use_static/>
264 $(_ 'Use static IP')</td>
265 </tr>
266 <tr id="st1"><td>$(_ 'IP address')</td>
267 <td><input type="text" name="ip" value="$IP" $PAR/></td>
268 </tr>
269 <tr id="st2"><td>$(_ 'Netmask')</td>
270 <td><input type="text" name="netmask" value="$NETMASK" $PAR/></td>
271 </tr>
272 <tr id="st3"><td>$(_ 'Gateway')</td>
273 <td><input type="text" name="gateway" value="$GATEWAY" $PAR/></td>
274 </tr>
275 <tr id="st4"><td>$(_ 'DNS server')</td>
276 <td><input type="text" name="dns" value="$DNS_SERVER" $PAR/></td>
277 </tr>
278 <tr><td>$(_ 'Wake up')</td>
279 <td><label><input type="checkbox" name="wakeup" id="wakeup" />
280 $(_ 'Wake up machines by network')</td>
281 </tr>
282 <tr id="wk1"><td>$(_ 'MAC address to wake up')</td>
283 <td><input type="text" name="macwakup" title="$(_ 'Leave empty for a general wakeup')" $PAR/><!--
284 --><button form="indexform" name="file" value="/etc/ethers" data-icon="view">$(_ 'List')</button>
285 </td>
286 </tr>
287 <tr id="wk2"><td>$(_ 'MAC/IP address password')</td>
288 <td><input type="text" name="macpass" title="$(_ 'Leave empty for a general wakeup')" $PAR/><!--
289 --><button form="indexform" name="exec" value="ether-wake --help" data-icon="help">$(_ 'Help')</button>
290 </td>
291 </tr>
292 </table>
293 </div>
294 </form>
295 <footer><!--
296 --><button form="conf" type="submit" name="start_eth" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
297 --><button form="conf" type="submit" name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
298 --><button form="conf" type="submit" name="dowakeup" data-icon="clock" $stop_disabled >$(_ 'Wake up')</button><!--
299 --></footer>
300 </section>
302 <script type="text/javascript">
303 function check_change() {
304 enabled = document.getElementById('staticip').checked;
305 for (i = 1; i < 5; i++) {
306 document.getElementById('st' + i).style.display = enabled ? '' : 'none';
307 }
308 enabled = document.getElementById('wakeup').checked;
309 for (i = 1; i < 3; i++) {
310 document.getElementById('wk' + i).style.display = enabled ? '' : 'none';
311 }
312 }
314 document.getElementById('staticip').onchange = check_change;
315 document.getElementById('wakeup').onchange = check_change;
316 check_change();
317 </script>
318 EOT
319 cat <<EOT
320 <section>
321 <header>
322 $(_ 'Configuration file')
323 EOT
324 edit_button /etc/network.conf
325 cat <<EOT
326 </header>
327 <div>$(_ "These values are the ethernet settings in the main /etc/network.conf configuration file")</div>
328 <pre>$(awk '{if($1 !~ "WIFI" && $1 !~ "#" && $1 != ""){print $0}}' /etc/network.conf | syntax_highlighter conf)</pre>
329 </section>
330 EOT
331 ;;
335 *\ wifi_list\ *)
336 # Catch ESSIDs and format output.
337 # We get the list of networks by Cell and without spaces.
339 HIDDEN="$(_ '(hidden)')"
341 cat <<EOT
342 <table class="wide center zebra">
343 <thead>
344 <tr>
345 <td>$(_ 'Name')</td>
346 <td>$(_ 'Signal level')</td>
347 <td>$(_ 'Channel')</td>
348 <td>$(_ 'Encryption')</td>
349 <td>$(_ 'Status')</td>
350 </tr>
351 </thead>
352 <tbody>
353 EOT
354 if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
355 ifconfig $WIFI_INTERFACE up
356 for i in $(iwlist $WIFI_INTERFACE scan | sed '/Cell /!d;s/.*Cell \([^ ]*\).*/Cell.\1/')
357 do
358 SCAN=$(iwlist $WIFI_INTERFACE scan last | sed "/$i/,/Cell/!d" | sed '$d')
360 BSSID=$(echo "$SCAN" | sed -n 's|.*Address: \([^ ]*\).*|\1|p')
362 CHANNEL=$(echo "$SCAN" | sed -n 's|.*Channel[:=]\([^ ]*\).*|\1|p')
364 QUALITY=$(echo "$SCAN" | sed -n 's|.*Quality[:=]\([^ ]*\).*|\1|p')
365 QUALITY_ICON="lvl$(( 5*${QUALITY:-0} ))" # lvl0 .. lvl4, lvl5
366 LEVEL=$(echo "$SCAN" | sed -n 's|.*Signal level[:=]\([^ ]*\).*|\1|p; s|-|−|')
368 ENCRYPTION=$(echo "$SCAN" | sed -n 's|.*Encryption key[:=]\([^ ]*\).*|\1|p') # on/off
370 ESSID=$(echo "$SCAN" | sed -n 's|.*ESSID:"\([^"]*\).*|\1|p')
372 # WPA Type - Group Cipher - Pairwise Ciphers - Authentication Suites
373 # {WPA|WPA2}-{TKIP|CCMP}-{TKIP|CCMP|TKIP CCMP}-{PSK|802.1x}
374 #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|-$||')"
376 # Authentication type
377 AUTH="$(echo "$SCAN" | sed -n 's|.*Authentication Suites[^:]*: *\(.*\)|\1|p')"
378 if [ -n "$(echo -n $AUTH | fgrep PSK)" ]; then
379 # WPA-Personal. Authentication using password (PSK = pre-shared key)
380 WIFI_KEY_TYPE='WPA'
381 elif [ -n "$(echo -n $AUTH | fgrep 802.1x)" ]; then
382 # WPA-Enterprise. Authentication using username, password, certificates...
383 WIFI_KEY_TYPE='EAP'
384 else
385 WIFI_KEY_TYPE='NONE'
386 fi
388 # Check encryption type
389 if [ "$ENCRYPTION" == 'on' ]; then
390 # "WPA" or "WPA2" or "WPA/WPA2" (maybe also "WPA2/WPA")
391 ENC_SIMPLE=$(echo "$SCAN" | sed -n '/.*WPA.*/ s|.*\(WPA[^ ]*\).*|\1|p')
392 ENC_SIMPLE=$(echo $ENC_SIMPLE | sed 's| |/|')
393 ENC_ICON='sechi' # high
394 if [ -z "$ENC_SIMPLE" ]; then
395 WIFI_KEY_TYPE='WEP'
396 ENC_SIMPLE='WEP'; ENC_ICON='secmi' # middle
397 fi
398 else
399 WIFI_KEY_TYPE='NONE'
400 ENC_SIMPLE="$(_ 'None')"; ENC_ICON='seclo' # low
401 fi
403 # Connected or not connected...
404 if ifconfig $WIFI_INTERFACE | fgrep -q inet && \
405 iwconfig $WIFI_INTERFACE | fgrep -q "ESSID:\"$ESSID\""; then
406 status="$(_ 'Connected')"
407 else
408 status='---'
409 fi
411 cat <<EOT
412 <tr>
413 <td><a data-icon="wifi" onclick="loadcfg('$ESSID', '$BSSID', '$WIFI_KEY_TYPE')">${ESSID:-$HIDDEN}</a></td>
414 <td><span data-icon="$QUALITY_ICON" title="Quality: $QUALITY"> $LEVEL dBm</span></td>
415 <td>$CHANNEL</td>
416 <td><span data-icon="$ENC_ICON">$ENC_SIMPLE</span></td>
417 <td>$status</td>
418 </tr>
419 EOT
420 done
421 fi
422 cat <<EOT
423 </tbody>
424 </table>
425 EOT
426 exit 0
427 ;;
430 *\ wifi\ *)
431 # Wireless connections settings
432 xhtml_header "$(_ 'Wireless connection')"
434 cat <<EOT
435 <style type="text/css">
436 #connection input[type="text"], #connection input[type="password"] { width: 14rem; }
437 #connection select { width: 14.4rem; }
439 #connection td { padding: 0; margin: 0; }
440 #connection [class] div {
441 max-height: 0; overflow: hidden; padding: 0; margin: 0;
442 -webkit-transition: all 0.5s ease-in-out;
443 -moz-transition: all 0.5s ease-in-out;
444 transition: all 0.5s ease-in-out;
445 }
446 .wep .wep div, .wpa .wpa div, .eap .eap div,
447 .eap.peap .eap1 div, .eap.tls .eap1 div, .eap.ttls .eap1 div {
448 max-height: 2em !important;
449 }
451 #shader {
452 z-index: 100;
453 position: fixed; top: 0; left: 0; width: 100%; height: 100%;
454 background-color: #000;
455 opacity: 0.6;
456 }
457 #shader.hidden {
458 display: none;
459 opacity: 0;
460 }
462 #popup_qr {
463 z-index: 101;
464 position: fixed;
465 width: 100%;
466 bottom: 2em;
467 transition: all 0.5s;
468 -webkit-transition: all 0.5s;
469 -webkit-transition-delay: 0.3s;
470 }
471 #popup_qr_inner {
472 display: inline-block;
473 text-align: center;
474 margin: 0.5em;
475 background: #fff; color: #222;
476 border: 0.16em solid ; border-radius: 0.5em;
478 padding: 0.5em;
479 }
480 #popup_qr.hidden {bottom: -100em; }
482 #qrimg { margin: 3em 1.5em 2em 3em; }
483 </style>
484 EOT
487 . /etc/network.conf
489 start_disabled=''; stop_disabled=''
490 if iwconfig 2>/dev/null | grep -q 'Tx-Power=off'; then
491 stop_disabled='disabled'
492 else
493 start_disabled='disabled'
494 fi
496 [ -w /etc/network.conf ] && cat <<EOT
497 <form>
498 <input type="hidden" name="wifi"/>
499 <button name="start_wifi" data-icon="start" $start_disabled>$(_ 'Start')</button><!--
500 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
501 --><button type="submit" data-icon="refresh" $stop_disabled >$(_ 'Scan' )</button>
502 </form>
503 EOT
505 [ -w /etc/network.conf ] &&
506 if [ -n "$start_disabled" ]; then
507 cat <<EOT
508 <section id="wifiList">
509 <div style="text-align: center;"><span data-icon="clock">$(_ 'Scanning wireless interface...')</span></div>
510 </section>
512 <script type="text/javascript">
513 ajax('network.cgi?wifi_list', '1', 'wifiList');
514 $(parse_wpa_conf)
515 </script>
516 EOT
518 # Escape html characters in the WIFI_KEY
519 WIFI_KEY_ESCAPED="$(echo -n "$WIFI_KEY" | sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g')"
521 cat <<EOT
522 <section>
523 <header>$(_ 'Connection')</header>
524 <div>
525 <form method="post" action="?wifi" id="connection">
526 <input type="hidden" name="connect_wifi"/>
527 <input type="hidden" name="bssid" id="bssid"/>
528 <table>
529 <tr><td>$(_ 'Network SSID')</td>
530 <td><input type="text" name="essid" value="$WIFI_ESSID" id="essid"/></td>
531 </tr>
533 <tr><td>$(_ 'Security')</td>
534 <td><select name="keyType" id="keyType">
535 <option value="NONE">$(_ 'None')</option>
536 <option value="WEP" >WEP</option>
537 <option value="WPA" >WPA/WPA2 PSK</option>
538 <option value="EAP" >802.1x EAP</option>
539 </select>
540 </td>
541 </tr>
543 <tr class="eap">
544 <td><div>$(_ 'EAP method')</div></td>
545 <td><div><select name="eap" id="eap">
546 <option value="PEAP">PEAP</option>
547 <option value="TLS" >TLS</option>
548 <option value="TTLS">TTLS</option>
549 <option value="PWD" >PWD</option>
550 </select>
551 </div></td>
552 </tr>
554 <tr class="eap1">
555 <td><div>$(_ 'Phase 2 authentication')</div></td>
556 <td><div><select name="phase2" id="phase2">
557 <option value="none" >$(_ 'None')</option>
558 <option value="pap" >PAP</option>
559 <option value="mschap" >MSCHAP</option>
560 <option value="mschapv2">MSCHAPV2</option>
561 <option value="gtc" >GTC</option>
562 </select>
563 </div></td>
564 </tr>
566 <tr class="eap1">
567 <td><div>$(_ 'CA certificate')</div></td>
568 <td><div><input type="text" name="caCert" id="caCert"></div></td>
569 </tr>
571 <tr class="eap1">
572 <td><div>$(_ 'User certificate')</div></td>
573 <td><div><input type="text" name="clientCert" id="clientCert"></div></td>
574 </tr>
576 <tr class="eap">
577 <td><div>$(_ 'Identity')</div></td>
578 <td><div><input type="text" name="identity" id="identity"></div></td>
579 </tr>
581 <tr class="eap1">
582 <td><div>$(_ 'Anonymous identity')</div></td>
583 <td><div><input type="text" name="anonymousIdentity" id="anonymousIdentity"></div></td>
584 </tr>
586 <tr class="wep wpa eap">
587 <td><div>$(_ 'Password')</div></td>
588 <td><div>
589 <input type="password" name="password" value="$WIFI_KEY_ESCAPED" id="password"/>
590 <span data-img="view" title="$(_ 'Show password')"
591 onmousedown="document.getElementById('password').type='text'; return false"
592 onmouseup="document.getElementById('password').type='password'"
593 onmouseout="document.getElementById('password').type='password'"
594 ></span>
595 </div></td>
596 </tr>
598 </table>
599 </form>
600 </div>
601 <footer>
602 <button form="connection" type="submit" name="wifi" data-icon="ok">$(_ 'Configure')</button>
603 <button data-icon="user" onclick="shareWiFi(); popup('popup_qr', 'show');">$(_ 'Share')</button>
604 </footer>
605 </section>
607 <script type="text/javascript">
608 function wifiSettingsChange() {
609 document.getElementById('connection').className =
610 document.getElementById('keyType').value.toLowerCase() + ' ' +
611 document.getElementById('eap').value.toLowerCase();
612 }
613 document.getElementById('keyType').onchange = wifiSettingsChange;
614 document.getElementById('eap').onchange = wifiSettingsChange;
616 document.getElementById('keyType').value = "$WIFI_KEY_TYPE"; wifiSettingsChange();
618 $(cat $PANEL/lib/qr.js.include)
620 function shareWiFi() {
621 // S=<SSID>; T={WPA|WEP|nopass}; P=<password>; H=<hidden?>
622 // Escape ":" and ";" -> "\:" and "\;"
623 // No harm for regular networks marked as hidden
624 var text = "WIFI:" +
625 "S:" + document.getElementById('essid').value.replace(/:/g, "\\\\:").replace(/;/g, "\\\\;") + ";" +
626 "T:" + document.getElementById('keyType').value.replace("NONE", "nopass") + ";" +
627 "P:" + document.getElementById('password').value.replace(/:/g, "\\\\:").replace(/;/g, "\\\\;") + ";" +
628 "H:true;" +
629 ";";
630 document.getElementById('qrimg').title = text;
631 qr.image({
632 image: document.getElementById('qrimg'),
633 value: text,
634 size: 10
635 });
636 }
637 </script>
639 <div id="shader" class="hidden" onclick="popup('popup_qr', 'close');"></div>
641 <table id="popup_qr" class="hidden" onclick="popup('popup_qr', 'close')">
642 <tr>
643 <td style="text-align: center;">
644 <div id="popup_qr_inner">
645 <img id="qrimg" src="#" /><br/>
646 $(_ 'Share Wi-Fi network with your friends')
647 </div>
648 </td>
649 </tr>
650 </table>
651 EOT
652 fi
654 cat <<EOT
655 <section>
656 <header>
657 $(_ 'Configuration file')
658 EOT
659 edit_button /etc/network.conf
660 cat <<EOT
661 </header>
662 <div>$(_ "These values are the wifi settings in the main /etc/network.conf configuration file")</div>
663 <pre>$(grep ^WIFI /etc/network.conf | sed 's|WIFI_KEY=.*|WIFI_KEY="********"|' | syntax_highlighter conf)</pre>
664 </section>
667 <section>
668 <header>$(_ 'Output of iwconfig')</header>
669 <pre>$(iwconfig)</pre>
670 </section>
671 EOT
672 ;;
675 *)
676 # Main Network page starting with a summary
677 xhtml_header "$(_ 'Manage network connections and services')"
679 stop_disabled=''; start_disabled=''
680 if cat /sys/class/net/*/operstate | fgrep -q up; then
681 start_disabled='disabled'
682 else
683 stop_disabled='disabled'
684 fi
686 if [ ! -w '/etc/network.conf' ]; then
687 start_disabled='disabled'; stop_disabled='disabled'
688 fi
690 cat <<EOT
691 <form action="index.cgi" id="indexform"></form>
693 <form id="mainform"><!--
694 --><button name="start" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
695 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
696 --><button name="restart" data-icon="restart" $stop_disabled >$(_ 'Restart')</button>
697 </form>
699 <div class="float-right"><!--
700 -->$(_ 'Configuration:')<!--
701 --><button form="indexform" name="file" value="/etc/network.conf" data-icon="conf">network.conf</button><!--
702 --><button form="mainform" name="eth" data-icon="eth">Ethernet</button><!--
703 --><button form="mainform" name="wifi" data-icon="wifi">Wireless</button>
704 </div>
707 <section>
708 <header>$(_ 'Network interfaces')</header>
709 $(list_network_interfaces)
710 <footer>
711 <input form="mainform" type="checkbox" name="opt" value="ipforward" $(
712 [ "$REMOTE_USER" != 'root' ] && echo ' disabled' ;
713 [ $(cat $ip_forward) -eq 1 ] && echo ' checked')/>
714 EOT
715 _ 'forward packets between interfaces'
716 [ "$REMOTE_USER" == 'root' ] && cat <<EOT
717 <button form="mainform" name="toggleipforward" data-icon="ok">$(_ 'Change')</button>
718 EOT
719 cat <<EOT
720 </footer>
721 </section>
724 <section>
725 <header id="hosts">
726 $(_ 'Hosts')
727 EOT
728 edit_button /etc/hosts
729 cat <<EOT
730 </header>
731 <footer>
732 <pre>$(getdb hosts)</pre>
733 </footer>
734 </section>
737 <section>
738 <header>$(_ 'Hostname')</header>
739 <footer>
740 EOT
741 if [ -w '/etc/hostname' ]; then
742 # was: name="hostname"; please don't use 'name' in name: unwanted webkit styling
743 cat <<EOT
744 <form>
745 <input type="text" name="host" value="$(cat /etc/hostname)"/><!--
746 --><button type="submit" data-icon="ok">$(_ 'Change')</button>
747 </form>
748 EOT
749 else
750 cat /etc/hostname
751 fi
752 cat <<EOT
753 </footer>
754 </section>
757 <section>
758 <header id="ifconfig">$(_ 'Output of ifconfig')</header>
759 <footer><pre>$(ifconfig)</pre></footer>
760 </section>
763 <section>
764 <header id="routing">$(_ 'Routing table')</header>
765 <footer><pre>$(route -n)</pre></footer>
766 </section>
769 <section>
770 <header id="dns">
771 $(_ 'Domain name resolution')
772 EOT
773 edit_button /etc/resolv.conf
774 cat <<EOT
775 </header>
776 <footer><pre>$(cat /etc/resolv.conf)</pre></footer>
777 </section>
780 <section>
781 <header id="arp">$(_ 'ARP table')</header>
782 <footer>
783 EOT
784 if [ "$REMOTE_USER" == "root" ]; then
785 echo "<table>"
786 arp -n | while read line ; do
787 cat <<EOT
788 <form>
789 <tr><td>
790 <input type="hidden" name="entry" value="$(urlencode "$(echo $line | \
791 sed 's/) .* on/ -i/;s/.*(//')")">
792 <button type="submit" data-icon="remove" name="rmarp"></button>
793 </td><td><pre>$line</pre></td></tr>
794 </form>
795 EOT
796 done
797 cat <<EOT
798 </table>
799 <form>
800 IP <input type="text" name="ip" value="10.20.30.40" size="12" /> on $(select_if)<!--
801 --><button type="submit" data-icon="upgrade" name="proxyarp">$(_ 'Proxy')</button>
802 or <button type="submit" data-icon="add" name="addarp">$(_ 'Add')</button>
803 MAC <input type="text" name="mac" value="11:22:33:44:55:66" size="16" />
804 </form>
805 EOT
806 else
807 echo "<pre>$(arp -n)</pre>"
808 fi
809 cat <<EOT
810 </footer>
811 </section>
814 <section>
815 <header id="connections">$(_ 'IP Connections')</header>
816 <footer>
817 <pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
818 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
819 </footer>
820 </section>
822 EOT
823 [ "$REMOTE_USER" == "root" -a "$(which iptables-save)" ] && cat <<EOT
824 <section>
825 <header id="iptables">$(_ 'Firewall')
826 $(edit_button /etc/knockd.conf "$(_ 'Port knocker')")
827 </header>
828 <footer>
829 <pre>$(iptables-save)</pre>
830 </footer>
831 </section>
832 EOT
834 ;;
835 esac
837 xhtml_footer
838 exit 0