tazpanel view network.cgi @ rev 520

PROVIDE support in package list report
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Aug 04 11:16:14 2015 +0200 (2015-08-04)
parents 0e464ccf165e
children 8b67a70440c2
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 [ -w /etc/network.conf ] && cat <<EOT
325 <form action="index.cgi">
326 <input type="hidden" name="file" value="/etc/network.conf"/>
327 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
328 </form>
329 EOT
330 cat <<EOT
331 </header>
332 <div>$(_ "These values are the ethernet settings in the main /etc/network.conf configuration file")</div>
333 <pre>$(awk '{if($1 !~ "WIFI" && $1 !~ "#" && $1 != ""){print $0}}' /etc/network.conf | syntax_highlighter conf)</pre>
334 </section>
335 EOT
336 ;;
340 *\ wifi_list\ *)
341 # Catch ESSIDs and format output.
342 # We get the list of networks by Cell and without spaces.
344 HIDDEN="$(_ '(hidden)')"
346 cat <<EOT
347 <table class="wide center zebra">
348 <thead>
349 <tr>
350 <td>$(_ 'Name')</td>
351 <td>$(_ 'Signal level')</td>
352 <td>$(_ 'Channel')</td>
353 <td>$(_ 'Encryption')</td>
354 <td>$(_ 'Status')</td>
355 </tr>
356 </thead>
357 <tbody>
358 EOT
359 if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
360 ifconfig $WIFI_INTERFACE up
361 for i in $(iwlist $WIFI_INTERFACE scan | sed '/Cell /!d;s/.*Cell \([^ ]*\).*/Cell.\1/')
362 do
363 SCAN=$(iwlist $WIFI_INTERFACE scan last | sed "/$i/,/Cell/!d" | sed '$d')
365 BSSID=$(echo "$SCAN" | sed -n 's|.*Address: \([^ ]*\).*|\1|p')
367 CHANNEL=$(echo "$SCAN" | sed -n 's|.*Channel[:=]\([^ ]*\).*|\1|p')
369 QUALITY=$(echo "$SCAN" | sed -n 's|.*Quality[:=]\([^ ]*\).*|\1|p')
370 QUALITY_ICON="lvl$(( 5*${QUALITY:-0} ))" # lvl0 .. lvl4, lvl5
371 LEVEL=$(echo "$SCAN" | sed -n 's|.*Signal level[:=]\([^ ]*\).*|\1|p; s|-|−|')
373 ENCRYPTION=$(echo "$SCAN" | sed -n 's|.*Encryption key[:=]\([^ ]*\).*|\1|p') # on/off
375 ESSID=$(echo "$SCAN" | sed -n 's|.*ESSID:"\([^"]*\).*|\1|p')
377 # WPA Type - Group Cipher - Pairwise Ciphers - Authentication Suites
378 # {WPA|WPA2}-{TKIP|CCMP}-{TKIP|CCMP|TKIP CCMP}-{PSK|802.1x}
379 #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|-$||')"
381 # Authentication type
382 AUTH="$(echo "$SCAN" | sed -n 's|.*Authentication Suites[^:]*: *\(.*\)|\1|p')"
383 if [ -n "$(echo -n $AUTH | fgrep PSK)" ]; then
384 # WPA-Personal. Authentication using password (PSK = pre-shared key)
385 WIFI_KEY_TYPE='WPA'
386 elif [ -n "$(echo -n $AUTH | fgrep 802.1x)" ]; then
387 # WPA-Enterprise. Authentication using username, password, certificates...
388 WIFI_KEY_TYPE='EAP'
389 else
390 WIFI_KEY_TYPE='NONE'
391 fi
393 # Check encryption type
394 if [ "$ENCRYPTION" == 'on' ]; then
395 # "WPA" or "WPA2" or "WPA/WPA2" (maybe also "WPA2/WPA")
396 ENC_SIMPLE=$(echo "$SCAN" | sed -n '/.*WPA.*/ s|.*\(WPA[^ ]*\).*|\1|p')
397 ENC_SIMPLE=$(echo $ENC_SIMPLE | sed 's| |/|')
398 ENC_ICON='sechi' # high
399 if [ -z "$ENC_SIMPLE" ]; then
400 WIFI_KEY_TYPE='WEP'
401 ENC_SIMPLE='WEP'; ENC_ICON='secmi' # middle
402 fi
403 else
404 WIFI_KEY_TYPE='NONE'
405 ENC_SIMPLE="$(_ 'None')"; ENC_ICON='seclo' # low
406 fi
408 # Connected or not connected...
409 if ifconfig $WIFI_INTERFACE | fgrep -q inet && \
410 iwconfig $WIFI_INTERFACE | fgrep -q "ESSID:\"$ESSID\""; then
411 status="$(_ 'Connected')"
412 else
413 status='---'
414 fi
416 cat <<EOT
417 <tr>
418 <td><a data-icon="wifi" onclick="loadcfg('$ESSID', '$BSSID', '$WIFI_KEY_TYPE')">${ESSID:-$HIDDEN}</a></td>
419 <td><span data-icon="$QUALITY_ICON" title="Quality: $QUALITY"> $LEVEL dBm</span></td>
420 <td>$CHANNEL</td>
421 <td><span data-icon="$ENC_ICON">$ENC_SIMPLE</span></td>
422 <td>$status</td>
423 </tr>
424 EOT
425 done
426 fi
427 cat <<EOT
428 </tbody>
429 </table>
430 EOT
431 exit 0
432 ;;
435 *\ wifi\ *)
436 # Wireless connections settings
437 xhtml_header "$(_ 'Wireless connection')"
439 . /etc/network.conf
441 start_disabled=''; stop_disabled=''
442 if iwconfig 2>/dev/null | grep -q 'Tx-Power=off'; then
443 stop_disabled='disabled'
444 else
445 start_disabled='disabled'
446 fi
448 [ -w /etc/network.conf ] && cat <<EOT
449 <form>
450 <input type="hidden" name="wifi"/>
451 <button name="start_wifi" data-icon="start" $start_disabled>$(_ 'Start')</button><!--
452 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
453 --><button type="submit" data-icon="refresh" $stop_disabled >$(_ 'Scan' )</button>
454 </form>
455 EOT
457 [ -w /etc/network.conf ] &&
458 if [ -n "$start_disabled" ]; then
459 cat <<EOT
460 <section id="wifiList">
461 <div style="text-align: center;"><span data-icon="clock">$(_ 'Scanning wireless interface...')</span></div>
462 </section>
464 <script type="text/javascript">
465 ajax('network.cgi?wifi_list', '1', 'wifiList');
466 $(parse_wpa_conf)
467 </script>
468 EOT
470 # Escape html characters in the WIFI_KEY
471 WIFI_KEY_ESCAPED="$(echo -n "$WIFI_KEY" | sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g')"
473 cat <<EOT
474 <section>
475 <header>$(_ 'Connection')</header>
476 <div>
477 <form method="post" action="?wifi" id="connection">
478 <input type="hidden" name="connect_wifi"/>
479 <input type="hidden" name="bssid" id="bssid"/>
480 <table>
481 <tr><td>$(_ 'Network SSID')</td>
482 <td><input type="text" name="essid" value="$WIFI_ESSID" id="essid"/></td>
483 </tr>
485 <tr><td>$(_ 'Security')</td>
486 <td><select name="keyType" id="keyType">
487 <option value="NONE">$(_ 'None')</option>
488 <option value="WEP" >WEP</option>
489 <option value="WPA" >WPA/WPA2 PSK</option>
490 <option value="EAP" >802.1x EAP</option>
491 </select>
492 </td>
493 </tr>
495 <tr class="eap">
496 <td><div>$(_ 'EAP method')</div></td>
497 <td><div><select name="eap" id="eap">
498 <option value="PEAP">PEAP</option>
499 <option value="TLS" >TLS</option>
500 <option value="TTLS">TTLS</option>
501 <option value="PWD" >PWD</option>
502 </select>
503 </div></td>
504 </tr>
506 <tr class="eap1">
507 <td><div>$(_ 'Phase 2 authentication')</div></td>
508 <td><div><select name="phase2" id="phase2">
509 <option value="none" >$(_ 'None')</option>
510 <option value="pap" >PAP</option>
511 <option value="mschap" >MSCHAP</option>
512 <option value="mschapv2">MSCHAPV2</option>
513 <option value="gtc" >GTC</option>
514 </select>
515 </div></td>
516 </tr>
518 <tr class="eap1">
519 <td><div>$(_ 'CA certificate')</div></td>
520 <td><div><input type="text" name="caCert" id="caCert"></div></td>
521 </tr>
523 <tr class="eap1">
524 <td><div>$(_ 'User certificate')</div></td>
525 <td><div><input type="text" name="clientCert" id="clientCert"></div></td>
526 </tr>
528 <tr class="eap">
529 <td><div>$(_ 'Identity')</div></td>
530 <td><div><input type="text" name="identity" id="identity"></div></td>
531 </tr>
533 <tr class="eap1">
534 <td><div>$(_ 'Anonymous identity')</div></td>
535 <td><div><input type="text" name="anonymousIdentity" id="anonymousIdentity"></div></td>
536 </tr>
538 <tr class="wep wpa eap">
539 <td><div>$(_ 'Password')</div></td>
540 <td><div>
541 <input type="password" name="password" value="$WIFI_KEY_ESCAPED" id="password"/>
542 <span data-img="view" title="$(_ 'Show password')"
543 onmousedown="document.getElementById('password').type='text'; return false"
544 onmouseup="document.getElementById('password').type='password'"
545 onmouseout="document.getElementById('password').type='password'"
546 ></span>
547 </div></td>
548 </tr>
550 <script type="text/javascript">
551 function wifiSettingsChange() {
552 document.getElementById('connection').className =
553 document.getElementById('keyType').value.toLowerCase() + ' ' +
554 document.getElementById('eap').value.toLowerCase();
555 }
556 document.getElementById('keyType').onchange = wifiSettingsChange;
557 document.getElementById('eap').onchange = wifiSettingsChange;
559 document.getElementById('keyType').value = "$WIFI_KEY_TYPE"; wifiSettingsChange();
560 </script>
562 <style type="text/css">
563 #connection input[type="text"], #connection input[type="password"] { width: 14rem; }
564 #connection select { width: 14.4rem; }
566 #connection td { padding: 0; margin: 0; }
567 #connection [class] div {
568 max-height: 0; overflow: hidden; padding: 0; margin: 0;
569 -webkit-transition: all 0.5s ease-in-out;
570 -moz-transition: all 0.5s ease-in-out;
571 transition: all 0.5s ease-in-out;
572 }
573 .wep .wep div, .wpa .wpa div, .eap .eap div,
574 .eap.peap .eap1 div, .eap.tls .eap1 div, .eap.ttls .eap1 div {
575 max-height: 2em !important;
576 }
577 </style>
579 </table>
580 </form>
581 </div>
582 <footer>
583 <button form="connection" type="submit" name="wifi" data-icon="ok">$(_ 'Configure')</button>
584 </footer>
585 </section>
586 EOT
587 fi
589 cat <<EOT
590 <section>
591 <header>
592 $(_ 'Configuration file')
593 EOT
594 [ -w /etc/network.conf ] && cat <<EOT
595 <form action="index.cgi">
596 <input type="hidden" name="file" value="/etc/network.conf"/>
597 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
598 </form>
599 EOT
600 cat <<EOT
601 </header>
602 <div>$(_ "These values are the wifi settings in the main /etc/network.conf configuration file")</div>
603 <pre>$(grep ^WIFI /etc/network.conf | sed 's|WIFI_KEY=.*|WIFI_KEY="********"|' | syntax_highlighter conf)</pre>
604 </section>
607 <section>
608 <header>$(_ 'Output of iwconfig')</header>
609 <pre>$(iwconfig)</pre>
610 </section>
611 EOT
612 ;;
615 *)
616 # Main Network page starting with a summary
617 xhtml_header "$(_ 'Manage network connections and services')"
619 stop_disabled=''; start_disabled=''
620 if cat /sys/class/net/*/operstate | fgrep -q up; then
621 start_disabled='disabled'
622 else
623 stop_disabled='disabled'
624 fi
626 if [ ! -w '/etc/network.conf' ]; then
627 start_disabled='disabled'; stop_disabled='disabled'
628 fi
630 cat <<EOT
631 <form action="index.cgi" id="indexform"></form>
633 <form id="mainform"><!--
634 --><button name="start" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
635 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
636 --><button name="restart" data-icon="restart" $stop_disabled >$(_ 'Restart')</button>
637 </form>
639 <div class="float-right"><!--
640 -->$(_ 'Configuration:')<!--
641 --><button form="indexform" name="file" value="/etc/network.conf" data-icon="conf">network.conf</button><!--
642 --><button form="mainform" name="eth" data-icon="eth">Ethernet</button><!--
643 --><button form="mainform" name="wifi" data-icon="wifi">Wireless</button>
644 </div>
647 <section>
648 <header>$(_ 'Network interfaces')</header>
649 $(list_network_interfaces)
650 <footer>
651 <input form="mainform" type="checkbox" name="opt" value="ipforward" $(
652 [ "$REMOTE_USER" != 'root' ] && echo ' disabled' ;
653 [ $(cat $ip_forward) -eq 1 ] && echo ' checked')/>
654 EOT
655 _ 'forward packets between interfaces'
656 [ "$REMOTE_USER" == 'root' ] && cat <<EOT
657 <button form="mainform" name="toggleipforward" data-icon="ok">$(_ 'Change')</button>
658 EOT
659 cat <<EOT
660 </footer>
661 </section>
664 <section>
665 <header id="hosts">
666 $(_ 'Hosts')
667 EOT
668 [ -w '/etc/hosts' ] && cat <<EOT
669 <form action="index.cgi">
670 <input type="hidden" name="file" value="/etc/hosts"/>
671 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
672 </form>
673 EOT
674 cat <<EOT
675 </header>
676 <footer>
677 <pre>$(getdb hosts)</pre>
678 </footer>
679 </section>
682 <section>
683 <header>$(_ 'Hostname')</header>
684 <footer>
685 EOT
686 if [ -w '/etc/hostname' ]; then
687 # was: name="hostname"; please don't use 'name' in name: unwanted webkit styling
688 cat <<EOT
689 <form>
690 <input type="text" name="host" value="$(cat /etc/hostname)"/><!--
691 --><button type="submit" data-icon="ok">$(_ 'Change')</button>
692 </form>
693 EOT
694 else
695 cat /etc/hostname
696 fi
697 cat <<EOT
698 </footer>
699 </section>
702 <section>
703 <header id="ifconfig">$(_ 'Output of ifconfig')</header>
704 <footer><pre>$(ifconfig)</pre></footer>
705 </section>
708 <section>
709 <header id="routing">$(_ 'Routing table')</header>
710 <footer><pre>$(route -n)</pre></footer>
711 </section>
714 <section>
715 <header id="dns">
716 $(_ 'Domain name resolution')
717 EOT
718 [ -w /etc/resolv.conf ] && cat <<EOT
719 <form action="index.cgi">
720 <input type="hidden" name="file" value="/etc/resolv.conf"/>
721 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
722 </form>
723 EOT
724 cat <<EOT
725 </header>
726 <footer><pre>$(cat /etc/resolv.conf)</pre></footer>
727 </section>
730 <section>
731 <header id="arp">$(_ 'ARP table')</header>
732 <footer>
733 EOT
734 if [ "$REMOTE_USER" == "root" ]; then
735 echo "<table>"
736 arp -n | while read line ; do
737 cat <<EOT
738 <form>
739 <tr><td>
740 <input type="hidden" name="entry" value="$(urlencode "$(echo $line | \
741 sed 's/) .* on/ -i/;s/.*(//')")">
742 <button type="submit" data-icon="remove" name="rmarp"></button>
743 </td><td><pre>$line</pre></td></tr>
744 </form>
745 EOT
746 done
747 cat <<EOT
748 </table>
749 <form>
750 IP <input type="text" name="ip" value="10.20.30.40" size="12" /> on $(select_if)<!--
751 --><button type="submit" data-icon="upgrade" name="proxyarp">$(_ 'Proxy')</button>
752 or <button type="submit" data-icon="add" name="addarp">$(_ 'Add')</button>
753 MAC <input type="text" name="mac" value="11:22:33:44:55:66" size="16" />
754 </form>
755 EOT
756 else
757 echo "<pre>$(arp -n)</pre>"
758 fi
759 cat <<EOT
760 </footer>
761 </section>
764 <section>
765 <header id="connections">$(_ 'IP Connections')</header>
766 <footer>
767 <pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
768 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
769 </footer>
770 </section>
772 EOT
773 [ "$REMOTE_USER" == "root" -a "$(which iptables-save)" ] && cat <<EOT
774 <section>
775 <header id="iptables">$(_ 'Firewall')</header>
776 <footer>
777 <pre>$(iptables-save)</pre>
778 </footer>
779 </section>
780 EOT
782 ;;
783 esac
785 xhtml_footer
786 exit 0