tazpanel view network.cgi @ rev 501

*.cgi: Implement TazPanel title and sub-title; hardware.cgi: fix and improve modules search; index.cgi: complex code using awk was prevented 'make pot' to collect all messages, fix terminal history removing; tazpanel.js: disable buttons when no packages selected (pkgs.cgi: up / search / category lists); network.cgi: complex comment was prevented 'make pot' to collect all messages; powersaving.cgi: starting development; *.po: rebuild; tazpanel.ttf: add messages icons, so remove all the style/png images and change libtazpanel; *.css: title and sub-title, messages icons; test.cgi: add new icons.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Jun 08 04:32:19 2015 +0300 (2015-06-08)
parents 470ab4241de5
children 0e464ccf165e
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 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 "$(_ 'Ethernet connection')"
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 [ -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 "$(_ 'Wireless connection')"
438 . /etc/network.conf
440 start_disabled=''; stop_disabled=''
441 if iwconfig 2>/dev/null | grep -q 'Tx-Power=off'; then
442 stop_disabled='disabled'
443 else
444 start_disabled='disabled'
445 fi
447 [ -w /etc/network.conf ] && cat <<EOT
448 <form>
449 <input type="hidden" name="wifi"/>
450 <button name="start_wifi" data-icon="start" $start_disabled>$(_ 'Start')</button><!--
451 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
452 --><button type="submit" data-icon="refresh" $stop_disabled >$(_ 'Scan' )</button>
453 </form>
454 EOT
456 [ -w /etc/network.conf ] &&
457 if [ -n "$start_disabled" ]; then
458 cat <<EOT
459 <section id="wifiList">
460 <div style="text-align: center;"><span data-icon="clock">$(_ 'Scanning wireless interface...')</span></div>
461 </section>
463 <script type="text/javascript">
464 ajax('network.cgi?wifi_list', '1', 'wifiList');
465 $(parse_wpa_conf)
466 </script>
467 EOT
469 # Escape html characters in the WIFI_KEY
470 WIFI_KEY_ESCAPED="$(echo -n "$WIFI_KEY" | sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g')"
472 cat <<EOT
473 <section>
474 <header>$(_ 'Connection')</header>
475 <div>
476 <form method="post" action="?wifi" id="connection">
477 <input type="hidden" name="connect_wifi"/>
478 <input type="hidden" name="bssid" id="bssid"/>
479 <table>
480 <tr><td>$(_ 'Network SSID')</td>
481 <td><input type="text" name="essid" value="$WIFI_ESSID" id="essid"/></td>
482 </tr>
484 <tr><td>$(_ 'Security')</td>
485 <td><select name="keyType" id="keyType">
486 <option value="NONE">$(_ 'None')</option>
487 <option value="WEP" >WEP</option>
488 <option value="WPA" >WPA/WPA2 PSK</option>
489 <option value="EAP" >802.1x EAP</option>
490 </select>
491 </td>
492 </tr>
494 <tr class="eap">
495 <td><div>$(_ 'EAP method')</div></td>
496 <td><div><select name="eap" id="eap">
497 <option value="PEAP">PEAP</option>
498 <option value="TLS" >TLS</option>
499 <option value="TTLS">TTLS</option>
500 <option value="PWD" >PWD</option>
501 </select>
502 </div></td>
503 </tr>
505 <tr class="eap1">
506 <td><div>$(_ 'Phase 2 authentication')</div></td>
507 <td><div><select name="phase2" id="phase2">
508 <option value="none" >$(_ 'None')</option>
509 <option value="pap" >PAP</option>
510 <option value="mschap" >MSCHAP</option>
511 <option value="mschapv2">MSCHAPV2</option>
512 <option value="gtc" >GTC</option>
513 </select>
514 </div></td>
515 </tr>
517 <tr class="eap1">
518 <td><div>$(_ 'CA certificate')</div></td>
519 <td><div><input type="text" name="caCert" id="caCert"></div></td>
520 </tr>
522 <tr class="eap1">
523 <td><div>$(_ 'User certificate')</div></td>
524 <td><div><input type="text" name="clientCert" id="clientCert"></div></td>
525 </tr>
527 <tr class="eap">
528 <td><div>$(_ 'Identity')</div></td>
529 <td><div><input type="text" name="identity" id="identity"></div></td>
530 </tr>
532 <tr class="eap1">
533 <td><div>$(_ 'Anonymous identity')</div></td>
534 <td><div><input type="text" name="anonymousIdentity" id="anonymousIdentity"></div></td>
535 </tr>
537 <tr class="wep wpa eap">
538 <td><div>$(_ 'Password')</div></td>
539 <td><div>
540 <input type="password" name="password" value="$WIFI_KEY_ESCAPED" id="password"/>
541 <span data-img="view" title="$(_ 'Show password')"
542 onmousedown="document.getElementById('password').type='text'; return false"
543 onmouseup="document.getElementById('password').type='password'"
544 onmouseout="document.getElementById('password').type='password'"
545 ></span>
546 </div></td>
547 </tr>
549 <script type="text/javascript">
550 function wifiSettingsChange() {
551 document.getElementById('connection').className =
552 document.getElementById('keyType').value.toLowerCase() + ' ' +
553 document.getElementById('eap').value.toLowerCase();
554 }
555 document.getElementById('keyType').onchange = wifiSettingsChange;
556 document.getElementById('eap').onchange = wifiSettingsChange;
558 document.getElementById('keyType').value = "$WIFI_KEY_TYPE"; wifiSettingsChange();
559 </script>
561 <style type="text/css">
562 #connection input[type="text"], #connection input[type="password"] { width: 14rem; }
563 #connection select { width: 14.4rem; }
565 #connection td { padding: 0; margin: 0; }
566 #connection [class] div {
567 max-height: 0; overflow: hidden; padding: 0; margin: 0;
568 -webkit-transition: all 0.5s ease-in-out;
569 -moz-transition: all 0.5s ease-in-out;
570 transition: all 0.5s ease-in-out;
571 }
572 .wep .wep div, .wpa .wpa div, .eap .eap div,
573 .eap.peap .eap1 div, .eap.tls .eap1 div, .eap.ttls .eap1 div {
574 max-height: 2em !important;
575 }
576 </style>
578 </table>
579 </form>
580 </div>
581 <footer>
582 <button form="connection" type="submit" name="wifi" data-icon="ok">$(_ 'Configure')</button>
583 </footer>
584 </section>
585 EOT
586 fi
588 cat <<EOT
589 <section>
590 <header>
591 $(_ 'Configuration file')
592 EOT
593 [ -w /etc/network.conf ] && cat <<EOT
594 <form action="index.cgi">
595 <input type="hidden" name="file" value="/etc/network.conf"/>
596 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
597 </form>
598 EOT
599 cat <<EOT
600 </header>
601 <div>$(_ "These values are the wifi settings in the main /etc/network.conf configuration file")</div>
602 <pre>$(grep ^WIFI /etc/network.conf | sed 's|WIFI_KEY=.*|WIFI_KEY="********"|' | syntax_highlighter conf)</pre>
603 </section>
606 <section>
607 <header>$(_ 'Output of iwconfig')</header>
608 <pre>$(iwconfig)</pre>
609 </section>
610 EOT
611 ;;
614 *)
615 # Main Network page starting with a summary
616 xhtml_header "$(_ 'Manage network connections and services')"
618 stop_disabled=''; start_disabled=''
619 if cat /sys/class/net/*/operstate | fgrep -q up; then
620 start_disabled='disabled'
621 else
622 stop_disabled='disabled'
623 fi
625 if [ ! -w '/etc/network.conf' ]; then
626 start_disabled='disabled'; stop_disabled='disabled'
627 fi
629 cat <<EOT
630 <form action="index.cgi" id="indexform"></form>
632 <form id="mainform"><!--
633 --><button name="start" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
634 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
635 --><button name="restart" data-icon="restart" $stop_disabled >$(_ 'Restart')</button>
636 </form>
638 <div class="float-right"><!--
639 -->$(_ 'Configuration:')<!--
640 --><button form="indexform" name="file" value="/etc/network.conf" data-icon="conf">network.conf</button><!--
641 --><button form="mainform" name="eth" data-icon="eth">Ethernet</button><!--
642 --><button form="mainform" name="wifi" data-icon="wifi">Wireless</button>
643 </div>
646 <section>
647 <header>$(_ 'Network interfaces')</header>
648 $(list_network_interfaces)
649 <footer>
650 <input form="mainform" type="checkbox" name="opt" value="ipforward" $(
651 [ "$REMOTE_USER" != 'root' ] && echo ' disabled' ;
652 [ $(cat $ip_forward) -eq 1 ] && echo ' checked')/>
653 EOT
654 _ 'forward packets between interfaces'
655 [ "$REMOTE_USER" == 'root' ] && cat <<EOT
656 <button form="mainform" name="toggleipforward" data-icon="ok">$(_ 'Change')</button>
657 EOT
658 cat <<EOT
659 </footer>
660 </section>
663 <section>
664 <header id="hosts">
665 $(_ 'Hosts')
666 EOT
667 [ -w '/etc/hosts' ] && cat <<EOT
668 <form action="index.cgi">
669 <input type="hidden" name="file" value="/etc/hosts"/>
670 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
671 </form>
672 EOT
673 cat <<EOT
674 </header>
675 <footer>
676 <pre>$(cat '/etc/hosts')</pre>
677 </footer>
678 </section>
681 <section>
682 <header>$(_ 'Hostname')</header>
683 <footer>
684 EOT
685 if [ -w '/etc/hostname' ]; then
686 # was: name="hostname"; please don't use 'name' in name: unwanted webkit styling
687 cat <<EOT
688 <form>
689 <input type="text" name="host" value="$(cat /etc/hostname)"/><!--
690 --><button type="submit" data-icon="ok">$(_ 'Change')</button>
691 </form>
692 EOT
693 else
694 cat /etc/hostname
695 fi
696 cat <<EOT
697 </footer>
698 </section>
701 <section>
702 <header id="ifconfig">$(_ 'Output of ifconfig')</header>
703 <footer><pre>$(ifconfig)</pre></footer>
704 </section>
707 <section>
708 <header id="routing">$(_ 'Routing table')</header>
709 <footer><pre>$(route -n)</pre></footer>
710 </section>
713 <section>
714 <header id="dns">
715 $(_ 'Domain name resolution')
716 EOT
717 [ -w /etc/resolv.conf ] && cat <<EOT
718 <form action="index.cgi">
719 <input type="hidden" name="file" value="/etc/resolv.conf"/>
720 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
721 </form>
722 EOT
723 cat <<EOT
724 </header>
725 <footer><pre>$(cat /etc/resolv.conf)</pre></footer>
726 </section>
729 <section>
730 <header id="arp">$(_ 'ARP table')</header>
731 <footer>
732 EOT
733 if [ "$REMOTE_USER" == "root" ]; then
734 echo "<table>"
735 arp -n | while read line ; do
736 cat <<EOT
737 <form>
738 <tr><td>
739 <input type="hidden" name="entry" value="$(urlencode "$(echo $line | \
740 sed 's/) .* on/ -i/;s/.*(//')")">
741 <button type="submit" data-icon="remove" name="rmarp"></button>
742 </td><td><pre>$line</pre></td></tr>
743 </form>
744 EOT
745 done
746 cat <<EOT
747 </table>
748 <form>
749 IP <input type="text" name="ip" value="10.20.30.40" size="12" /> on $(select_if)<!--
750 --><button type="submit" data-icon="upgrade" name="proxyarp">$(_ 'Proxy')</button>
751 or <button type="submit" data-icon="add" name="addarp">$(_ 'Add')</button>
752 MAC <input type="text" name="mac" value="11:22:33:44:55:66" size="16" />
753 </form>
754 EOT
755 else
756 echo "<pre>$(arp -n)</pre>"
757 fi
758 cat <<EOT
759 </footer>
760 </section>
763 <section>
764 <header id="connections">$(_ 'IP Connections')</header>
765 <footer>
766 <pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
767 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
768 </footer>
769 </section>
771 EOT
772 [ "$REMOTE_USER" == "root" -a "$(which iptables-save)" ] && cat <<EOT
773 <section>
774 <header id="iptables">$(_ 'Firewall')</header>
775 <footer>
776 <pre>$(iptables-save)</pre>
777 </footer>
778 </section>
779 EOT
781 ;;
782 esac
784 xhtml_footer
785 exit 0