tazpanel view network.cgi @ rev 499

settings.cgi: disable live hardware clock on the page; base.css: fix statusbar height.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat May 23 17:20:17 2015 +0300 (2015-05-23)
parents 30d94e5563af
children 3117717c007d
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=$(_ 'TazPanel - 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 echo "<option>$i"
119 done
120 echo '</select>'
121 }
123 # Actions commands before page is displayed
125 case " $(GET) " in
126 *\ start\ *)
127 /etc/init.d/network.sh start | log
128 # Here we sleep a bit to let udhcp get the lease before reloading
129 # the page with status
130 wait_up ;;
131 *\ stop\ *)
132 /etc/init.d/network.sh stop | log ;;
133 *\ restart\ *)
134 /etc/init.d/network.sh restart | log
135 wait_up ;;
136 *\ start_wifi\ *)
137 start_wifi ;;
138 *\ start_eth\ *)
139 start_eth ;;
140 *\ dowakeup\ *)
141 mac="$(GET macwakup)"
142 unset pass
143 [ "$(GET macpass)" ] && pass="-p $(GET macpass)"
144 if [ "$mac" ]; then
145 ether-wake $(GET iface) $mac $pass
146 else
147 ether-wake -b $(GET iface) $pass
148 fi
149 ;;
150 *\ host\ *)
151 get_hostname="$(GET host)"
152 echo $(_ 'Changed hostname: %s' $get_hostname) | log
153 echo "$get_hostname" > /etc/hostname ;;
154 *\ rmarp\ *)
155 arp -d $(urldecode "$(GET entry)") ;;
156 *\ addarp\ *)
157 arp -i $(GET interface) -s $(GET ip) $(GET mac) ;;
158 *\ proxyarp\ *)
159 arp -i $(GET interface) -Ds $(GET ip) $(GET interface) pub ;;
160 *\ toggleipforward\ *)
161 echo $((1 - $(cat $ip_forward))) > $ip_forward ;;
162 esac
164 case " $(POST) " in
165 *\ connect_wifi\ *)
166 # Connect to a Wi-Fi network
167 /etc/init.d/network.sh stop | log
168 password="$(POST password)"
170 # Escape special characters to use with sed substitutions
171 password="$(echo -n "$password" | sed 's|\\|\\\\|g; s|&|\\\&|g' | sed "s|'|'\"'\"'|g")"
173 sed -i \
174 -e "s|^WIFI_ESSID=.*|WIFI_ESSID=\"$(POST essid)\"|" \
175 -e "s|^WIFI_BSSID=.*|WIFI_BSSID=\"$(POST bssid)\"|" \
176 -e "s|^WIFI_KEY_TYPE=.*|WIFI_KEY_TYPE=\"$(POST keyType)\"|" \
177 -e "s|^WIFI_KEY=.*|WIFI_KEY='$password'|" \
178 -e "s|^WIFI_EAP_METHOD=.*|WIFI_EAP_METHOD=\"$(POST eap)\"|" \
179 -e "s|^WIFI_CA_CERT=.*|WIFI_CA_CERT=\"$(POST caCert)\"|" \
180 -e "s|^WIFI_CLIENT_CERT=.*|WIFI_CLIENT_CERT=\"$(POST clientCert)\"|" \
181 -e "s|^WIFI_IDENTITY=.*|WIFI_IDENTITY=\"$(POST identity)\"|" \
182 -e "s|^WIFI_ANONYMOUS_IDENTITY=.*|WIFI_ANONYMOUS_IDENTITY=\"$(POST anonymousIdentity)\"|" \
183 -e "s|^WIFI_PHASE2=.*|WIFI_PHASE2=\"$(POST phase2)\"|" \
184 /etc/network.conf
185 . /etc/network.conf
186 start_wifi
187 ;;
188 esac
191 # Get values only now since they could have been modified by actions.
193 . /etc/network.conf
199 #
200 # Main Commands for pages
201 #
203 case " $(GET) " in
205 *\ scan\ *)
206 # Scan open ports
207 scan=$(GET scan); back=$(GET back)
208 xhtml_header
209 loading_msg "$(_ 'Scanning open ports...')"
211 cat <<EOT
212 <section>
213 <header>
214 $(_ 'Port scanning for %s' $scan)
215 $(back_button "$back" "$(_ 'Network')" "")
216 </header>
217 <pre>$(pscan -b $scan)</pre>
218 </section>
219 EOT
220 ;;
223 *\ eth\ *)
224 # Wired connections settings
225 xhtml_header
227 PAR1="size=\"20\" required"; PAR="$PAR1 pattern=\"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\""
229 case "$STATIC" in
230 yes) use_static='checked';;
231 *) use_static='';;
232 esac
234 stop_disabled=''; start_disabled=''
235 if cat /sys/class/net/eth*/operstate | fgrep -q up; then
236 start_disabled='disabled'
237 else
238 stop_disabled='disabled'
239 fi
241 [ -s /etc/ethers ] || echo "#01:02:03:04:05:06 mystation" > /etc/ethers
242 cat <<EOT
243 <h2>$(_ 'Ethernet connection')</h2>
244 EOT
245 [ -w /etc/network.conf ] && cat <<EOT
246 <p>$(_ "Here you can configure a wired connection using DHCP to \
247 automatically get a random IP or configure a static/fixed IP")</p>
249 <section>
250 <header>$(_ 'Configuration')</header>
251 <form action="index.cgi" id="indexform"></form>
252 <form id="conf">
253 <input type="hidden" name="eth"/>
254 <div>
255 <table>
256 <tr><td>$(_ 'Interface')</td>
257 <td><select name="iface" value="$INTERFACE" style="width:100%">
258 $(cd /sys/class/net; ls -1 | awk -viface="$INTERFACE" '{
259 sel = ($0 == iface) ? " selected":""
260 printf "<option value=\"%s\"%s>%s", $0, sel, $0
261 }')
262 </select></td>
263 </tr>
264 <tr><td>$(_ 'Static IP')</td>
265 <td><label><input type="checkbox" name="staticip" id="staticip" $use_static/>
266 $(_ 'Use static IP')</td>
267 </tr>
268 <tr id="st1"><td>$(_ 'IP address')</td>
269 <td><input type="text" name="ip" value="$IP" $PAR/></td>
270 </tr>
271 <tr id="st2"><td>$(_ 'Netmask')</td>
272 <td><input type="text" name="netmask" value="$NETMASK" $PAR/></td>
273 </tr>
274 <tr id="st3"><td>$(_ 'Gateway')</td>
275 <td><input type="text" name="gateway" value="$GATEWAY" $PAR/></td>
276 </tr>
277 <tr id="st4"><td>$(_ 'DNS server')</td>
278 <td><input type="text" name="dns" value="$DNS_SERVER" $PAR/></td>
279 </tr>
280 <tr><td>$(_ 'Wake up')</td>
281 <td><label><input type="checkbox" name="wakeup" id="wakeup" />
282 $(_ 'Wake up machines by network')</td>
283 </tr>
284 <tr id="wk1"><td>$(_ 'MAC address to wake up')</td>
285 <td><input type="text" name="macwakup" title="$(_ 'Leave empty for a general wakeup')" $PAR/><!--
286 --><button form="indexform" name="file" value="/etc/ethers" data-icon="view">$(_ 'List')</button>
287 </td>
288 </tr>
289 <tr id="wk2"><td>$(_ 'MAC/IP address password')</td>
290 <td><input type="text" name="macpass" title="$(_ 'Leave empty for a general wakeup')" $PAR/><!--
291 --><button form="indexform" name="exec" value="ether-wake --help" data-icon="help">$(_ 'Help')</button>
292 </td>
293 </tr>
294 </table>
295 </div>
296 </form>
297 <footer><!--
298 --><button form="conf" type="submit" name="start_eth" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
299 --><button form="conf" type="submit" name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
300 --><button form="conf" type="submit" name="dowakeup" data-icon="clock" $stop_disabled >$(_ 'Wake up')</button><!--
301 --></footer>
302 </section>
304 <script type="text/javascript">
305 function check_change() {
306 enabled = document.getElementById('staticip').checked;
307 for (i = 1; i < 5; i++) {
308 document.getElementById('st' + i).style.display = enabled ? '' : 'none';
309 }
310 enabled = document.getElementById('wakeup').checked;
311 for (i = 1; i < 3; i++) {
312 document.getElementById('wk' + i).style.display = enabled ? '' : 'none';
313 }
314 }
316 document.getElementById('staticip').onchange = check_change;
317 document.getElementById('wakeup').onchange = check_change;
318 check_change();
319 </script>
320 EOT
321 cat <<EOT
322 <section>
323 <header>
324 $(_ 'Configuration file')
325 EOT
326 [ -w /etc/network.conf ] && cat <<EOT
327 <form action="index.cgi">
328 <input type="hidden" name="file" value="/etc/network.conf"/>
329 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
330 </form>
331 EOT
332 cat <<EOT
333 </header>
334 <div>$(_ "These values are the ethernet settings in the main /etc/network.conf configuration file")</div>
335 <pre>$(awk '{if($1 !~ "WIFI" && $1 !~ "#" && $1 != ""){print $0}}' /etc/network.conf | syntax_highlighter conf)</pre>
336 </section>
337 EOT
338 ;;
342 *\ wifi_list\ *)
343 # Catch ESSIDs and format output.
344 # We get the list of networks by Cell and without spaces.
346 HIDDEN="$(_ '(hidden)')"
348 cat <<EOT
349 <table class="wide center zebra">
350 <thead>
351 <tr>
352 <td>$(_ 'Name')</td>
353 <td>$(_ 'Signal level')</td>
354 <td>$(_ 'Channel')</td>
355 <td>$(_ 'Encryption')</td>
356 <td>$(_ 'Status')</td>
357 </tr>
358 </thead>
359 <tbody>
360 EOT
361 if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
362 ifconfig $WIFI_INTERFACE up
363 for i in $(iwlist $WIFI_INTERFACE scan | sed '/Cell /!d;s/.*Cell \([^ ]*\).*/Cell.\1/')
364 do
365 SCAN=$(iwlist $WIFI_INTERFACE scan last | sed "/$i/,/Cell/!d" | sed '$d')
367 BSSID=$(echo "$SCAN" | sed -n 's|.*Address: \([^ ]*\).*|\1|p')
369 CHANNEL=$(echo "$SCAN" | sed -n 's|.*Channel[:=]\([^ ]*\).*|\1|p')
371 QUALITY=$(echo "$SCAN" | sed -n 's|.*Quality[:=]\([^ ]*\).*|\1|p')
372 QUALITY_ICON="lvl$(( 5*${QUALITY:-0} ))" # lvl0 .. lvl4, lvl5
373 LEVEL=$(echo "$SCAN" | sed -n 's|.*Signal level[:=]\([^ ]*\).*|\1|p; s|-|−|')
375 ENCRYPTION=$(echo "$SCAN" | sed -n 's|.*Encryption key[:=]\([^ ]*\).*|\1|p') # on/off
377 ESSID=$(echo "$SCAN" | sed -n 's|.*ESSID:"\([^"]*\).*|\1|p')
379 # WPA Type - Group Cipher - Pairwise Ciphers - Authentication Suites
380 # {WPA|WPA2}-{TKIP|CCMP}-{TKIP|CCMP|TKIP CCMP}-{PSK|802.1x}
381 #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|-$||')"
383 # Authentication type
384 AUTH="$(echo "$SCAN" | sed -n 's|.*Authentication Suites[^:]*: *\(.*\)|\1|p')"
385 if [ -n "$(echo -n $AUTH | fgrep PSK)" ]; then
386 # WPA-Personal. Authentication using password (PSK = pre-shared key)
387 WIFI_KEY_TYPE='WPA'
388 elif [ -n "$(echo -n $AUTH | fgrep 802.1x)" ]; then
389 # WPA-Enterprise. Authentication using username, password, certificates...
390 WIFI_KEY_TYPE='EAP'
391 else
392 WIFI_KEY_TYPE='NONE'
393 fi
395 # Check encryption type
396 if [ "$ENCRYPTION" == 'on' ]; then
397 # "WPA" or "WPA2" or "WPA/WPA2" (maybe also "WPA2/WPA")
398 ENC_SIMPLE=$(echo "$SCAN" | sed -n '/.*WPA.*/ s|.*\(WPA[^ ]*\).*|\1|p')
399 ENC_SIMPLE=$(echo $ENC_SIMPLE | sed 's| |/|')
400 ENC_ICON='sechi' # high
401 if [ -z "$ENC_SIMPLE" ]; then
402 WIFI_KEY_TYPE='WEP'
403 ENC_SIMPLE='WEP'; ENC_ICON='secmi' # middle
404 fi
405 else
406 WIFI_KEY_TYPE='NONE'
407 ENC_SIMPLE="$(_ 'None')"; ENC_ICON='seclo' # low
408 fi
410 # Connected or not connected...
411 if ifconfig $WIFI_INTERFACE | fgrep -q inet && \
412 iwconfig $WIFI_INTERFACE | fgrep -q "ESSID:\"$ESSID\""; then
413 status="$(_ 'Connected')"
414 else
415 status='---'
416 fi
418 cat <<EOT
419 <tr>
420 <td><a data-icon="wifi" onclick="loadcfg('$ESSID', '$BSSID', '$WIFI_KEY_TYPE')">${ESSID:-$HIDDEN}</a></td>
421 <td><span data-icon="$QUALITY_ICON" title="Quality: $QUALITY"> $LEVEL dBm</span></td>
422 <td>$CHANNEL</td>
423 <td><span data-icon="$ENC_ICON">$ENC_SIMPLE</span></td>
424 <td>$status</td>
425 </tr>
426 EOT
427 done
428 fi
429 cat <<EOT
430 </tbody>
431 </table>
432 EOT
433 exit 0
434 ;;
437 *\ wifi\ *)
438 # Wireless connections settings
439 xhtml_header
441 . /etc/network.conf
442 cat <<EOT
443 <h2>$(_ 'Wireless connection')</h2>
444 EOT
446 start_disabled=''; stop_disabled=''
447 if iwconfig 2>/dev/null | grep -q 'Tx-Power=off'; then
448 stop_disabled='disabled'
449 else
450 start_disabled='disabled'
451 fi
453 [ -w /etc/network.conf ] && cat <<EOT
454 <form>
455 <input type="hidden" name="wifi"/>
456 <button name="start_wifi" data-icon="start" $start_disabled>$(_ 'Start')</button><!--
457 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
458 --><button type="submit" data-icon="refresh" $stop_disabled >$(_ 'Scan' )</button>
459 </form>
460 EOT
462 [ -w /etc/network.conf ] &&
463 if [ -n "$start_disabled" ]; then
464 cat <<EOT
465 <section id="wifiList">
466 <div style="text-align: center;"><span data-icon="clock">$(_ 'Scanning wireless interface...')</span></div>
467 </section>
469 <script type="text/javascript">
470 ajax('network.cgi?wifi_list', '1', 'wifiList');
471 $(parse_wpa_conf)
472 </script>
473 EOT
475 # Escape html characters in the WIFI_KEY
476 WIFI_KEY_ESCAPED="$(echo -n "$WIFI_KEY" | sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g')"
478 cat <<EOT
479 <section>
480 <header>$(_ 'Connection')</header>
481 <div>
482 <form method="post" action="?wifi" id="connection">
483 <input type="hidden" name="connect_wifi"/>
484 <input type="hidden" name="bssid" id="bssid"/>
485 <table>
486 <tr><td>$(_ 'Network SSID')</td>
487 <td><input type="text" name="essid" value="$WIFI_ESSID" id="essid"/></td>
488 </tr>
490 <tr><td>$(_ 'Security')</td>
491 <td><select name="keyType" id="keyType">
492 <option value="NONE">$(_ 'None')</option>
493 <option value="WEP" >WEP</option>
494 <option value="WPA" >WPA/WPA2 PSK</option>
495 <option value="EAP" >802.1x EAP</option>
496 </select>
497 </td>
498 </tr>
500 <tr class="eap">
501 <td><div>$(_ 'EAP method')</div></td>
502 <td><div><select name="eap" id="eap">
503 <option value="PEAP">PEAP</option>
504 <option value="TLS" >TLS</option>
505 <option value="TTLS">TTLS</option>
506 <option value="PWD" >PWD</option>
507 </select>
508 </div></td>
509 </tr>
511 <tr class="eap1">
512 <td><div>$(_ 'Phase 2 authentication')</div></td>
513 <td><div><select name="phase2" id="phase2">
514 <option value="none" >$(_ 'None')</option>
515 <option value="pap" >PAP</option>
516 <option value="mschap" >MSCHAP</option>
517 <option value="mschapv2">MSCHAPV2</option>
518 <option value="gtc" >GTC</option>
519 </select>
520 </div></td>
521 </tr>
523 <tr class="eap1">
524 <td><div>$(_ 'CA certificate')</div></td>
525 <td><div><input type="text" name="caCert" id="caCert"></div></td>
526 </tr>
528 <tr class="eap1">
529 <td><div>$(_ 'User certificate')</div></td>
530 <td><div><input type="text" name="clientCert" id="clientCert"></div></td>
531 </tr>
533 <tr class="eap">
534 <td><div>$(_ 'Identity')</div></td>
535 <td><div><input type="text" name="identity" id="identity"></div></td>
536 </tr>
538 <tr class="eap1">
539 <td><div>$(_ 'Anonymous identity')</div></td>
540 <td><div><input type="text" name="anonymousIdentity" id="anonymousIdentity"></div></td>
541 </tr>
543 <tr class="wep wpa eap">
544 <td><div>$(_ 'Password')</div></td>
545 <td><div>
546 <input type="password" name="password" value="$WIFI_KEY_ESCAPED" id="password"/>
547 <span data-img="view" title="$(_ 'Show password')"
548 onmousedown="document.getElementById('password').type='text'; return false"
549 onmouseup="document.getElementById('password').type='password'"
550 onmouseout="document.getElementById('password').type='password'"
551 ></span>
552 </div></td>
553 </tr>
555 <script type="text/javascript">
556 function wifiSettingsChange() {
557 document.getElementById('connection').className =
558 document.getElementById('keyType').value.toLowerCase() + ' ' +
559 document.getElementById('eap').value.toLowerCase();
560 }
561 document.getElementById('keyType').onchange = wifiSettingsChange;
562 document.getElementById('eap').onchange = wifiSettingsChange;
564 document.getElementById('keyType').value = "$WIFI_KEY_TYPE"; wifiSettingsChange();
565 </script>
567 <style type="text/css">
568 #connection input[type="text"], #connection input[type="password"] { width: 14rem; }
569 #connection select { width: 14.4rem; }
571 #connection td { padding: 0; margin: 0; }
572 #connection [class] div {
573 max-height: 0; overflow: hidden; padding: 0; margin: 0;
574 -webkit-transition: all 0.5s ease-in-out;
575 -moz-transition: all 0.5s ease-in-out;
576 transition: all 0.5s ease-in-out;
577 }
578 .wep .wep div, .wpa .wpa div, .eap .eap div,
579 .eap.peap .eap1 div, .eap.tls .eap1 div, .eap.ttls .eap1 div {
580 max-height: 2em !important;
581 }
582 </style>
584 </table>
585 </form>
586 </div>
587 <footer>
588 <button form="connection" type="submit" name="wifi" data-icon="ok">$(_ 'Configure')</button>
589 </footer>
590 </section>
591 EOT
592 fi
594 cat <<EOT
595 <section>
596 <header>
597 $(_ 'Configuration file')
598 EOT
599 [ -w /etc/network.conf ] && cat <<EOT
600 <form action="index.cgi">
601 <input type="hidden" name="file" value="/etc/network.conf"/>
602 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
603 </form>
604 EOT
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
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 <h2>$(_ 'Networking')</h2>
638 <p>$(_ 'Manage network connections and services')</p>
640 <form action="index.cgi" id="indexform"></form>
642 <form id="mainform"><!--
643 --><button name="start" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
644 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
645 --><button name="restart" data-icon="restart" $stop_disabled >$(_ 'Restart')</button>
646 </form>
648 <div class="float-right"><!--
649 -->$(_ 'Configuration:')<!--
650 --><button form="indexform" name="file" value="/etc/network.conf" data-icon="conf">network.conf</button><!--
651 --><button form="mainform" name="eth" data-icon="eth">Ethernet</button><!--
652 --><button form="mainform" name="wifi" data-icon="wifi">Wireless</button>
653 </div>
656 <section>
657 <header>$(_ 'Network interfaces')</header>
658 $(list_network_interfaces)
659 <footer>
660 <input form="mainform" type="checkbox" name="opt" value="ipforward" $(
661 [ "$REMOTE_USER" == "root" ] || echo " disabled" ;
662 [ $(cat $ip_forward) -eq 1 ] && echo checked)/>
663 EOT
664 _ 'forward packets between interfaces'
665 [ "$REMOTE_USER" == "root" ] && cat <<EOT
666 <button form="mainform" name="toggleipforward" data-icon="ok">$(_ 'Change')</button>
667 EOT
668 cat <<EOT
669 </footer>
670 </section>
673 <section>
674 <header id="hosts">
675 $(_ 'Hosts')
676 EOT
677 [ -w /etc/hosts ] && cat <<EOT
678 <form action="index.cgi">
679 <input type="hidden" name="file" value="/etc/hosts"/>
680 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
681 </form>
682 EOT
683 cat <<EOT
684 </header>
685 <footer>
686 <pre>$(cat /etc/hosts)</pre>
687 </footer>
688 </section>
691 <section>
692 <header>$(_ 'Hostname')</header>
693 <footer>
694 EOT
695 if [ -w /etc/hostname ]; then
696 cat <<EOT
697 <form>
698 <!-- was: name="hostname"; please don't use 'name' in name: unwanted webkit styling -->
699 <input type="text" name="host" value="$(cat /etc/hostname)"/><!--
700 --><button type="submit" data-icon="ok">$(_ 'Change')</button>
701 </form>
702 EOT
703 else
704 cat /etc/hostname
705 fi
706 cat <<EOT
707 </footer>
708 </section>
711 <section>
712 <header id="ifconfig">$(_ 'Output of ifconfig')</header>
713 <footer><pre>$(ifconfig)</pre></footer>
714 </section>
717 <section>
718 <header id="routing">$(_ 'Routing table')</header>
719 <footer><pre>$(route -n)</pre></footer>
720 </section>
723 <section>
724 <header id="dns">
725 $(_ 'Domain name resolution')
726 EOT
727 [ -w /etc/resolv.conf ] && cat <<EOT
728 <form action="index.cgi">
729 <input type="hidden" name="file" value="/etc/resolv.conf"/>
730 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
731 </form>
732 EOT
733 cat <<EOT
734 </header>
735 <footer><pre>$(cat /etc/resolv.conf)</pre></footer>
736 </section>
739 <section>
740 <header id="arp">$(_ 'ARP table')</header>
741 <footer>
742 EOT
743 if [ "$REMOTE_USER" == "root" ]; then
744 echo "<table>"
745 arp -n | while read line ; do
746 cat <<EOT
747 <form>
748 <tr><td>
749 <input type="hidden" name="entry" value="$(urlencode "$(echo $line | \
750 sed 's/) .* on/ -i/;s/.*(//')")">
751 <button type="submit" data-icon="remove" name="rmarp"></button>
752 </td><td><pre>$line</pre></td></tr>
753 </form>
754 EOT
755 done
756 cat <<EOT
757 </table>
758 <form>
759 IP <input type="text" name="ip" value="10.20.30.40" size="12" /> on $(select_if)<!--
760 --><button type="submit" data-icon="upgrade" name="proxyarp">$(_ 'Proxy')</button>
761 or <button type="submit" data-icon="add" name="addarp">$(_ 'Add')</button>
762 MAC <input type="text" name="mac" value="11:22:33:44:55:66" size="16" />
763 </form>
764 EOT
765 else
766 echo "<pre>$(arp -n)</pre>"
767 fi
768 cat <<EOT
769 </footer>
770 </section>
773 <section>
774 <header id="connections">$(_ 'IP Connections')</header>
775 <footer>
776 <pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
777 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
778 </footer>
779 </section>
781 EOT
782 [ "$REMOTE_USER" == "root" -a "$(which iptables-save)" ] && cat <<EOT
783 <section>
784 <header id="iptables">$(_ 'Firewall')</header>
785 <footer>
786 <pre>$(iptables-save)</pre>
787 </footer>
788 </section>
789 EOT
791 ;;
792 esac
794 xhtml_footer
795 exit 0