tazpanel view network.cgi @ rev 527

Add hosts.cgi; update translations
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Aug 26 05:51:08 2015 +0300 (2015-08-26)
parents 4f619f973b88
children 7bf0e359133e
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 *\ hostname\ *)
152 hostname="$(GET hostname)"
153 echo $(_ 'Changed hostname: %s' "$hostname") | log
154 echo "$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 . /etc/network.conf
436 start_disabled=''; stop_disabled=''
437 if iwconfig 2>/dev/null | grep -q 'Tx-Power=off'; then
438 stop_disabled='disabled'
439 else
440 start_disabled='disabled'
441 fi
443 [ -w /etc/network.conf ] && cat <<EOT
444 <form>
445 <input type="hidden" name="wifi"/>
446 <button name="start_wifi" data-icon="start" $start_disabled>$(_ 'Start')</button><!--
447 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
448 --><button type="submit" data-icon="refresh" $stop_disabled >$(_ 'Scan' )</button>
449 </form>
450 EOT
452 [ -w /etc/network.conf ] &&
453 if [ -n "$start_disabled" ]; then
454 cat <<EOT
455 <section id="wifiList">
456 <div style="text-align: center;"><span data-icon="clock">$(_ 'Scanning wireless interface...')</span></div>
457 </section>
459 <script type="text/javascript">
460 ajax('network.cgi?wifi_list', '1', 'wifiList');
461 $(parse_wpa_conf)
462 </script>
463 EOT
465 # Escape html characters in the WIFI_KEY
466 WIFI_KEY_ESCAPED="$(echo -n "$WIFI_KEY" | sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g')"
468 cat <<EOT
469 <section>
470 <header>$(_ 'Connection')</header>
471 <div>
472 <form method="post" action="?wifi" id="connection">
473 <input type="hidden" name="connect_wifi"/>
474 <input type="hidden" name="bssid" id="bssid"/>
475 <table>
476 <tr><td>$(_ 'Network SSID')</td>
477 <td><input type="text" name="essid" value="$WIFI_ESSID" id="essid"/></td>
478 </tr>
480 <tr><td>$(_ 'Security')</td>
481 <td><select name="keyType" id="keyType">
482 <option value="NONE">$(_ 'None')</option>
483 <option value="WEP" >WEP</option>
484 <option value="WPA" >WPA/WPA2 PSK</option>
485 <option value="EAP" >802.1x EAP</option>
486 </select>
487 </td>
488 </tr>
490 <tr class="eap">
491 <td><div>$(_ 'EAP method')</div></td>
492 <td><div><select name="eap" id="eap">
493 <option value="PEAP">PEAP</option>
494 <option value="TLS" >TLS</option>
495 <option value="TTLS">TTLS</option>
496 <option value="PWD" >PWD</option>
497 </select>
498 </div></td>
499 </tr>
501 <tr class="eap1">
502 <td><div>$(_ 'Phase 2 authentication')</div></td>
503 <td><div><select name="phase2" id="phase2">
504 <option value="none" >$(_ 'None')</option>
505 <option value="pap" >PAP</option>
506 <option value="mschap" >MSCHAP</option>
507 <option value="mschapv2">MSCHAPV2</option>
508 <option value="gtc" >GTC</option>
509 </select>
510 </div></td>
511 </tr>
513 <tr class="eap1">
514 <td><div>$(_ 'CA certificate')</div></td>
515 <td><div><input type="text" name="caCert" id="caCert"></div></td>
516 </tr>
518 <tr class="eap1">
519 <td><div>$(_ 'User certificate')</div></td>
520 <td><div><input type="text" name="clientCert" id="clientCert"></div></td>
521 </tr>
523 <tr class="eap">
524 <td><div>$(_ 'Identity')</div></td>
525 <td><div><input type="text" name="identity" id="identity"></div></td>
526 </tr>
528 <tr class="eap1">
529 <td><div>$(_ 'Anonymous identity')</div></td>
530 <td><div><input type="text" name="anonymousIdentity" id="anonymousIdentity"></div></td>
531 </tr>
533 <tr class="wep wpa eap">
534 <td><div>$(_ 'Password')</div></td>
535 <td><div>
536 <input type="password" name="password" value="$WIFI_KEY_ESCAPED" id="password"/>
537 <span data-img="view" title="$(_ 'Show password')"
538 onmousedown="document.getElementById('password').type='text'; return false"
539 onmouseup="document.getElementById('password').type='password'"
540 onmouseout="document.getElementById('password').type='password'"
541 ></span>
542 </div></td>
543 </tr>
545 </table>
546 </form>
547 </div>
548 <footer>
549 <button form="connection" type="submit" name="wifi" data-icon="ok">$(_ 'Configure')</button>
550 <button data-icon="user" onclick="shareWiFi(); popup('popup_qr', 'show');">$(_ 'Share')</button>
551 </footer>
552 </section>
554 <script type="text/javascript">
555 function wifiSettingsChange() {
556 document.getElementById('connection').className =
557 document.getElementById('keyType').value.toLowerCase() + ' ' +
558 document.getElementById('eap').value.toLowerCase();
559 }
560 document.getElementById('keyType').onchange = wifiSettingsChange;
561 document.getElementById('eap').onchange = wifiSettingsChange;
563 document.getElementById('keyType').value = "$WIFI_KEY_TYPE"; wifiSettingsChange();
565 function shareWiFi() {
566 // S=<SSID>; T={WPA|WEP|nopass}; P=<password>; H=<hidden?>
567 // Escape ":" and ";" -> "\:" and "\;"
568 // No harm for regular networks marked as hidden
569 var text = "WIFI:" +
570 "S:" + document.getElementById('essid').value.replace(/:/g, "\\\\:").replace(/;/g, "\\\\;") + ";" +
571 "T:" + document.getElementById('keyType').value.replace("NONE", "nopass") + ";" +
572 "P:" + document.getElementById('password').value.replace(/:/g, "\\\\:").replace(/;/g, "\\\\;") + ";" +
573 "H:true;" +
574 ";";
575 document.getElementById('qrimg').title = text;
576 qr.image({
577 image: document.getElementById('qrimg'),
578 value: text,
579 size: 10
580 });
581 }
582 </script>
584 <div id="shader" class="hidden" onclick="popup('popup_qr', 'close');"></div>
586 <table id="popup_qr" class="hidden" onclick="popup('popup_qr', 'close')">
587 <tr>
588 <td style="text-align: center;">
589 <div id="popup_qr_inner">
590 <img id="qrimg"/><br/>
591 $(_ 'Share Wi-Fi network with your friends')
592 </div>
593 </td>
594 </tr>
595 </table>
596 EOT
597 fi
599 cat <<EOT
600 <section>
601 <header>
602 $(_ 'Configuration file')
603 EOT
604 edit_button /etc/network.conf
605 cat <<EOT
606 </header>
607 <div>$(_ "These values are the wifi settings in the main /etc/network.conf configuration file")</div>
608 <pre>$(grep ^WIFI /etc/network.conf | sed 's|WIFI_KEY=.*|WIFI_KEY="********"|' | syntax_highlighter conf)</pre>
609 </section>
612 <section>
613 <header>$(_ 'Output of iwconfig')</header>
614 <pre>$(iwconfig)</pre>
615 </section>
616 EOT
617 ;;
620 *)
621 # Main Network page starting with a summary
622 xhtml_header "$(_ 'Manage network connections and services')"
624 stop_disabled=''; start_disabled=''
625 if cat /sys/class/net/*/operstate | fgrep -q up; then
626 start_disabled='disabled'
627 else
628 stop_disabled='disabled'
629 fi
631 if [ ! -w '/etc/network.conf' ]; then
632 start_disabled='disabled'; stop_disabled='disabled'
633 fi
635 cat <<EOT
636 <form action="index.cgi" id="indexform"></form>
638 <form id="mainform"><!--
639 --><button name="start" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
640 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
641 --><button name="restart" data-icon="restart" $stop_disabled >$(_ 'Restart')</button>
642 </form>
644 <div class="float-right"><!--
645 -->$(_ 'Configuration:')<!--
646 --><button form="indexform" name="file" value="/etc/network.conf" data-icon="conf">network.conf</button><!--
647 --><button form="mainform" name="eth" data-icon="eth">Ethernet</button><!--
648 --><button form="mainform" name="wifi" data-icon="wifi">Wireless</button>
649 </div>
652 <section>
653 <header>$(_ 'Network interfaces')</header>
654 $(list_network_interfaces)
655 <footer>
656 <input form="mainform" type="checkbox" name="opt" value="ipforward" $(
657 [ "$REMOTE_USER" != 'root' ] && echo ' disabled' ;
658 [ $(cat $ip_forward) -eq 1 ] && echo ' checked')/>
659 EOT
660 _ 'forward packets between interfaces'
661 [ "$REMOTE_USER" == 'root' ] && cat <<EOT
662 <button form="mainform" name="toggleipforward" data-icon="ok">$(_ 'Change')</button>
663 EOT
664 cat <<EOT
665 </footer>
666 </section>
669 <section>
670 <header id="hosts">$(_ 'Hosts'; edit_button /etc/hosts)</header>
671 <span data-icon="info">$(r=$(getdb hosts | wc -l);
672 _p '%d record in the hosts DB' \
673 '%d records in the hosts DB' "$r" \
674 "$r")</span>
675 <pre class="scroll">$(getdb hosts | fgrep -v 0.0.0.0)</pre>
676 <footer>
677 <form action="hosts.cgi">
678 <button data-icon="admin" data-root>$(_ 'Configure')</button>
679 $(_ 'Use hosts file as Ad blocker')
680 </form>
681 </footer>
682 </section>
685 <section>
686 <header>$(_ 'Hostname')</header>
687 <footer>
688 EOT
689 if [ -w '/etc/hostname' ]; then
690 cat <<EOT
691 <form>
692 <input type="text" name="hostname" value="$(hostname)"/><!--
693 --><button type="submit" data-icon="ok">$(_ 'Change')</button>
694 </form>
695 EOT
696 else
697 cat /etc/hostname
698 fi
699 cat <<EOT
700 </footer>
701 </section>
704 <section>
705 <header id="ifconfig">$(_ 'Output of ifconfig')</header>
706 <pre>$(ifconfig)</pre>
707 </section>
710 <section>
711 <header id="routing">$(_ 'Routing table')</header>
712 <pre>$(route -n)</pre>
713 </section>
716 <section>
717 <header id="dns">$(_ 'Domain name resolution'; edit_button /etc/resolv.conf)</header>
718 <pre>$(cat /etc/resolv.conf)</pre>
719 </section>
722 <section>
723 <header id="arp">$(_ 'ARP table')</header>
724 EOT
725 if [ "$REMOTE_USER" == "root" ]; then
726 echo "<table>"
727 arp -n | while read line ; do
728 cat <<EOT
729 <form>
730 <tr><td>
731 <input type="hidden" name="entry" value="$(urlencode "$(echo $line | \
732 sed 's/) .* on/ -i/;s/.*(//')")">
733 <button type="submit" data-icon="remove" name="rmarp"></button>
734 </td><td><pre>$line</pre></td></tr>
735 </form>
736 EOT
737 done
738 cat <<EOT
739 </table>
740 <footer>
741 <form>
742 IP <input type="text" name="ip" value="10.20.30.40" size="12" /> on $(select_if)<!--
743 --><button type="submit" data-icon="upgrade" name="proxyarp">$(_ 'Proxy')</button>
744 or <button type="submit" data-icon="add" name="addarp">$(_ 'Add')</button>
745 MAC <input type="text" name="mac" value="11:22:33:44:55:66" size="16" />
746 </form>
747 EOT
748 else
749 echo "<pre>$(arp -n)</pre>"
750 fi
751 cat <<EOT
752 </footer>
753 </section>
756 <section>
757 <header id="connections">$(_ 'IP Connections')</header>
758 <pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
759 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
760 </section>
762 EOT
763 [ "$REMOTE_USER" == "root" -a "$(which iptables-save)" ] && cat <<EOT
764 <section>
765 <header id="iptables">$(_ 'Firewall')
766 $(edit_button /etc/knockd.conf "$(_ 'Port knocker')")
767 </header>
768 <pre>$(iptables-save)</pre>
769 </section>
770 EOT
772 ;;
773 esac
775 xhtml_footer
776 exit 0