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