tazpanel view network.cgi @ rev 588
Un-fuzzy already translated messages; finish ru.po translations
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Wed Apr 20 11:36:15 2016 +0300 (2016-04-20) |
parents | a53b0b636b98 |
children | 26f60e49e3d5 |
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("&", "\\&", "g", value);
88 value = gensub("<", "\\<", "g", value);
89 value = gensub(">", "\\>", "g", value);
90 value = gensub("\"", "\\\"", "g", value);
92 # if value was already quoted - remove \" from begin and end
93 if (substr(value, 1, 2) == "\\\"")
94 value = substr(value, 3, length(value) - 4);
96 # output in form: variable:"escaped value"
97 printf "%s:\"%s\"", variable, value;
98 }
99 }
100 if (network == 1 && $0 ~ "}") { printf "}"; network = 0; next; }
101 }
102 END {print "\n];"}
103 ' /etc/wpa/wpa.conf | sed 's|\t||g;'
104 }
107 # Waiting for network link up
109 wait_up() {
110 for i in $(seq 5); do
111 [ -z "$(cat /sys/class/net/*/operstate | fgrep up)"] && sleep 1
112 done
113 }
115 select_if() {
116 echo '<select name="interface">'
117 for i in $(ls /sys/class/net); do
118 grep -qs 1 /sys/class/net/$i/carrier &&
119 echo "<option>$i"
120 done
121 echo '</select>'
122 }
124 # Actions commands before page is displayed
126 case " $(GET) " in
127 *\ start\ *)
128 /etc/init.d/network.sh start | log
129 # Here we sleep a bit to let udhcp get the lease before reloading
130 # the page with status
131 wait_up ;;
132 *\ stop\ *)
133 /etc/init.d/network.sh stop | log ;;
134 *\ restart\ *)
135 /etc/init.d/network.sh restart | log
136 wait_up ;;
137 *\ start_wifi\ *)
138 start_wifi ;;
139 *\ start_eth\ *)
140 start_eth ;;
141 *\ dowakeup\ *)
142 mac="$(GET macwakup)"
143 unset pass
144 [ "$(GET macpass)" ] && pass="-p $(GET macpass)"
145 if [ "$mac" ]; then
146 ether-wake $(GET iface) $mac $pass
147 else
148 ether-wake -b $(GET iface) $pass
149 fi
150 ;;
151 *\ hostname\ *)
152 hostname="$(GET hostname)"
153 echo $(_ 'Changed hostname: %s' "$hostname") | log
154 echo "$hostname" > /etc/hostname;;
155 *\ rmarp\ *)
156 arp -d $(urldecode "$(GET entry)") ;;
157 *\ addarp\ *)
158 arp -i $(GET interface) -s $(GET ip) $(GET mac) ;;
159 *\ proxyarp\ *)
160 arp -i $(GET interface) -Ds $(GET ip) $(GET interface) pub ;;
161 *\ toggleipforward\ *)
162 echo $((1 - $(cat $ip_forward))) > $ip_forward ;;
163 esac
165 case " $(POST) " in
166 *\ connect_wifi\ *)
167 # Connect to a Wi-Fi network
168 /etc/init.d/network.sh stop | log
169 password="$(POST password)"
171 # Escape special characters to use with sed substitutions
172 password="$(echo -n "$password" | sed 's|\\|\\\\|g; s|&|\\\&|g' | sed "s|'|'\"'\"'|g")"
174 sed -i \
175 -e "s|^WIFI_ESSID=.*|WIFI_ESSID=\"$(POST essid)\"|" \
176 -e "s|^WIFI_BSSID=.*|WIFI_BSSID=\"$(POST bssid)\"|" \
177 -e "s|^WIFI_KEY_TYPE=.*|WIFI_KEY_TYPE=\"$(POST keyType)\"|" \
178 -e "s|^WIFI_KEY=.*|WIFI_KEY='$password'|" \
179 -e "s|^WIFI_EAP_METHOD=.*|WIFI_EAP_METHOD=\"$(POST eap)\"|" \
180 -e "s|^WIFI_CA_CERT=.*|WIFI_CA_CERT=\"$(POST caCert)\"|" \
181 -e "s|^WIFI_CLIENT_CERT=.*|WIFI_CLIENT_CERT=\"$(POST clientCert)\"|" \
182 -e "s|^WIFI_IDENTITY=.*|WIFI_IDENTITY=\"$(POST identity)\"|" \
183 -e "s|^WIFI_ANONYMOUS_IDENTITY=.*|WIFI_ANONYMOUS_IDENTITY=\"$(POST anonymousIdentity)\"|" \
184 -e "s|^WIFI_PHASE2=.*|WIFI_PHASE2=\"$(POST phase2)\"|" \
185 /etc/network.conf
186 . /etc/network.conf
187 start_wifi
188 ;;
189 esac
192 # Get values only now since they could have been modified by actions.
194 . /etc/network.conf
200 #
201 # Main Commands for pages
202 #
204 case " $(GET) " in
206 *\ scan\ *)
207 # Scan open ports
208 scan=$(GET scan); back=$(GET back)
209 xhtml_header
210 loading_msg "$(_ 'Scanning open ports...')"
212 cat <<EOT
213 <section>
214 <header>
215 $(_ 'Port scanning for %s' $scan)
216 $(back_button "$back" "$(_ 'Network')" "")
217 </header>
218 <pre>$(pscan -b $scan)</pre>
219 </section>
220 EOT
221 ;;
224 *\ eth\ *)
225 # Wired connections settings
226 xhtml_header "$(_ 'Ethernet connection')"
228 PAR1="size=\"20\" required"; PAR="$PAR1 pattern=\"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\""
230 case "$STATIC" in
231 yes) use_static='checked';;
232 *) use_static='';;
233 esac
235 stop_disabled=''; start_disabled=''
236 if cat /sys/class/net/eth*/operstate | fgrep -q up; then
237 start_disabled='disabled'
238 else
239 stop_disabled='disabled'
240 fi
242 [ -s /etc/ethers ] || echo "#01:02:03:04:05:06 mystation" > /etc/ethers
243 [ -w /etc/network.conf ] && cat <<EOT
244 <p>$(_ "Here you can configure a wired connection using DHCP to \
245 automatically get a random IP or configure a static/fixed IP")</p>
247 <section>
248 <header>$(_ 'Configuration')</header>
249 <form action="index.cgi" id="indexform"></form>
250 <form id="conf">
251 <input type="hidden" name="eth"/>
252 <div>
253 <table>
254 <tr><td>$(_ 'Interface')</td>
255 <td><select name="iface" value="$INTERFACE" style="width:100%">
256 $(cd /sys/class/net; ls -1 | awk -viface="$INTERFACE" '{
257 sel = ($0 == iface) ? " selected":""
258 printf "<option value=\"%s\"%s>%s", $0, sel, $0
259 }')
260 </select></td>
261 </tr>
262 <tr><td>$(_ 'Static IP')</td>
263 <td><label><input type="checkbox" name="staticip" id="staticip" $use_static/>
264 $(_ 'Use static IP')</td>
265 </tr>
266 <tr id="st1"><td>$(_ 'IP address')</td>
267 <td><input type="text" name="ip" value="$IP" $PAR/></td>
268 </tr>
269 <tr id="st2"><td>$(_ 'Netmask')</td>
270 <td><input type="text" name="netmask" value="$NETMASK" $PAR/></td>
271 </tr>
272 <tr id="st3"><td>$(_ 'Gateway')</td>
273 <td><input type="text" name="gateway" value="$GATEWAY" $PAR/></td>
274 </tr>
275 <tr id="st4"><td>$(_ 'DNS server')</td>
276 <td><input type="text" name="dns" value="$DNS_SERVER" $PAR/></td>
277 </tr>
278 <tr><td>$(_ 'Wake up')</td>
279 <td><label><input type="checkbox" name="wakeup" id="wakeup" />
280 $(_ 'Wake up machines by network')</td>
281 </tr>
282 <tr id="wk1"><td>$(_ 'MAC address to wake up')</td>
283 <td><input type="text" name="macwakup" title="$(_ 'Leave empty for a general wakeup')" $PAR/><!--
284 --><button form="indexform" name="file" value="/etc/ethers" data-icon="@view@">$(_ 'List')</button>
285 </td>
286 </tr>
287 <tr id="wk2"><td>$(_ 'MAC/IP address password')</td>
288 <td><input type="text" name="macpass" title="$(_ 'Optional')" $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 id="wk3" 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 < 4; i++) {
310 document.getElementById('wk' + i).style.display = enabled ? '' : 'none';
311 }
312 }
314 document.getElementById('staticip').onchange = check_change;
315 document.getElementById('wakeup').onchange = check_change;
316 check_change();
317 </script>
318 EOT
319 cat <<EOT
320 <section>
321 <header>
322 $(_ 'Configuration file')
323 EOT
324 edit_button /etc/network.conf
325 cat <<EOT
326 </header>
327 <div>$(_ "These values are the ethernet settings in the main /etc/network.conf configuration file")</div>
328 <pre>$(awk '{if($1 !~ "WIFI" && $1 !~ "#" && $1 != ""){print $0}}' /etc/network.conf | syntax_highlighter conf)</pre>
329 </section>
330 EOT
331 ;;
335 *\ wifi_list\ *)
336 # Catch ESSIDs and format output.
337 # We get the list of networks by Cell and without spaces.
339 HIDDEN="$(_ '(hidden)')"
341 cat <<EOT
342 <table class="wide center zebra">
343 <thead>
344 <tr>
345 <td>$(_ 'Name')</td>
346 <td>$(_ 'Signal level')</td>
347 <td>$(_ 'Channel')</td>
348 <td>$(_ 'Encryption')</td>
349 <td>$(_ 'Status')</td>
350 </tr>
351 </thead>
352 <tbody>
353 EOT
354 if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
355 ifconfig $WIFI_INTERFACE up
356 for i in $(iwlist $WIFI_INTERFACE scan | sed '/Cell /!d;s/.*Cell \([^ ]*\).*/Cell.\1/')
357 do
358 SCAN=$(iwlist $WIFI_INTERFACE scan last | sed "/$i/,/Cell/!d" | sed '$d')
360 BSSID=$(echo "$SCAN" | sed -n 's|.*Address: \([^ ]*\).*|\1|p')
362 CHANNEL=$(echo "$SCAN" | sed -n 's|.*Channel[:=]\([^ ]*\).*|\1|p')
364 QUALITY=$(echo "$SCAN" | sed -n 's|.*Quality[:=]\([^ ]*\).*|\1|p')
365 QUALITY_ICON="lvl$(( 5*${QUALITY:-0} ))" # lvl0 .. lvl4, lvl5
366 case $QUALITY_ICON in
367 lvl0) QUALITY_ICON='@lvl0@';;
368 lvl1) QUALITY_ICON='@lvl1@';;
369 lvl2) QUALITY_ICON='@lvl2@';;
370 lvl3) QUALITY_ICON='@lvl3@';;
371 lvl4|lvl5) QUALITY_ICON='@lvl4@';;
372 esac
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 "$(_ 'Wireless connection')"
441 . /etc/network.conf
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 data-icon="@clock@">$(_ 'Scanning wireless interface...')</span></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 </table>
553 </form>
554 </div>
555 <footer>
556 <button form="connection" type="submit" name="wifi" data-icon="@ok@">$(_ 'Configure')</button>
557 <button data-icon="@user@" onclick="shareWiFi(); popup('popup_qr', 'show');">$(_ 'Share')</button>
558 </footer>
559 </section>
561 <script type="text/javascript">
562 function wifiSettingsChange() {
563 document.getElementById('connection').className =
564 document.getElementById('keyType').value.toLowerCase() + ' ' +
565 document.getElementById('eap').value.toLowerCase();
566 }
567 document.getElementById('keyType').onchange = wifiSettingsChange;
568 document.getElementById('eap').onchange = wifiSettingsChange;
570 document.getElementById('keyType').value = "$WIFI_KEY_TYPE"; wifiSettingsChange();
572 function shareWiFi() {
573 // S=<SSID>; T={WPA|WEP|nopass}; P=<password>; H=<hidden?>
574 // Escape ":" and ";" -> "\:" and "\;"
575 // No harm for regular networks marked as hidden
576 var text = "WIFI:" +
577 "S:" + document.getElementById('essid').value.replace(/:/g, "\\\\:").replace(/;/g, "\\\\;") + ";" +
578 "T:" + document.getElementById('keyType').value.replace("NONE", "nopass") + ";" +
579 "P:" + document.getElementById('password').value.replace(/:/g, "\\\\:").replace(/;/g, "\\\\;") + ";" +
580 "H:true;" +
581 ";";
582 document.getElementById('qrimg').title = text;
583 qr.image({
584 image: document.getElementById('qrimg'),
585 value: text,
586 size: 10
587 });
588 }
589 </script>
591 <div id="shader" class="hidden" onclick="popup('popup_qr', 'close');"></div>
593 <table id="popup_qr" class="hidden" onclick="popup('popup_qr', 'close')">
594 <tr>
595 <td style="text-align: center;">
596 <div id="popup_qr_inner">
597 <img id="qrimg"/><br/>
598 $(_ 'Share Wi-Fi network with your friends')
599 </div>
600 </td>
601 </tr>
602 </table>
603 EOT
604 fi
606 cat <<EOT
607 <section>
608 <header>
609 $(_ 'Configuration file')
610 EOT
611 edit_button /etc/network.conf
612 cat <<EOT
613 </header>
614 <div>$(_ "These values are the wifi settings in the main /etc/network.conf configuration file")</div>
615 <pre>$(grep ^WIFI /etc/network.conf | sed 's|WIFI_KEY=.*|WIFI_KEY="********"|' | syntax_highlighter conf)</pre>
616 </section>
619 <section>
620 <header>$(_ 'Output of iwconfig')</header>
621 <pre>$(iwconfig)</pre>
622 </section>
623 EOT
624 ;;
627 *)
628 # Main Network page starting with a summary
629 xhtml_header "$(_ 'Manage network connections and services')"
631 stop_disabled=''; start_disabled=''
632 if cat /sys/class/net/*/operstate | fgrep -q up; then
633 start_disabled='disabled'
634 else
635 stop_disabled='disabled'
636 fi
638 if [ ! -w '/etc/network.conf' ]; then
639 start_disabled='disabled'; stop_disabled='disabled'
640 fi
642 cat <<EOT
643 <form action="index.cgi" id="indexform"></form>
645 <form id="mainform"><!--
646 --><button name="start" data-icon="@start@" $start_disabled>$(_ 'Start' )</button><!--
647 --><button name="stop" data-icon="@stop@" $stop_disabled >$(_ 'Stop' )</button><!--
648 --><button name="restart" data-icon="@restart@" $stop_disabled >$(_ 'Restart')</button>
649 </form>
651 <div class="float-right"><!--
652 -->$(_ 'Configuration:')<!--
653 --><button form="indexform" name="file" value="/etc/network.conf" data-icon="@conf@">network.conf</button><!--
654 --><button form="mainform" name="eth" data-icon="@eth@">Ethernet</button><!--
655 --><button form="mainform" name="wifi" data-icon="@wifi@">Wireless</button>
656 </div>
659 <section>
660 <header>$(_ 'Network interfaces')</header>
661 $(list_network_interfaces)
662 <footer>
663 <input form="mainform" type="checkbox" name="opt" value="ipforward" $(
664 [ "$REMOTE_USER" != 'root' ] && echo ' disabled' ;
665 [ $(cat $ip_forward) -eq 1 ] && echo ' checked')/>
666 EOT
667 _ 'forward packets between interfaces'
668 [ "$REMOTE_USER" == 'root' ] && cat <<EOT
669 <button form="mainform" name="toggleipforward" data-icon="@ok@">$(_ 'Change')</button>
670 EOT
671 cat <<EOT
672 </footer>
673 </section>
676 <section>
677 <header id="hosts">$(_ 'Hosts'; edit_button /etc/hosts)</header>
678 <span data-icon="@info@">$(r=$(getdb hosts | wc -l);
679 _p '%d record in the hosts DB' \
680 '%d records in the hosts DB' "$r" \
681 "$r")</span>
682 <pre class="scroll">$(getdb hosts | fgrep -v 0.0.0.0)</pre>
683 <footer>
684 <form action="hosts.cgi">
685 <button data-icon="@admin@" data-root>$(_ 'Configure')</button>
686 $(_ 'Use hosts file as Ad blocker')
687 </form>
688 </footer>
689 </section>
692 <section>
693 <header>$(_ 'Hostname')</header>
694 <footer>
695 EOT
696 if [ -w '/etc/hostname' ]; then
697 cat <<EOT
698 <form>
699 <input type="text" name="hostname" value="$(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 <pre>$(ifconfig)</pre>
714 </section>
717 <section>
718 <header id="routing">$(_ 'Routing table')</header>
719 <pre>$(route -n)</pre>
720 </section>
723 <section>
724 <header id="dns">$(_ 'Domain name resolution'; edit_button /etc/resolv.conf)</header>
725 <pre>$(cat /etc/resolv.conf)</pre>
726 </section>
729 <section>
730 <header id="arp">$(_ 'ARP table')</header>
731 EOT
732 if [ "$REMOTE_USER" == "root" ]; then
733 echo "<table>"
734 arp -n | while read line ; do
735 cat <<EOT
736 <form>
737 <tr><td>
738 <input type="hidden" name="entry" value="$(urlencode "$(echo $line | \
739 sed 's/) .* on/ -i/;s/.*(//')")">
740 <button type="submit" data-icon="@remove@" name="rmarp"></button>
741 </td><td><pre>$line</pre></td></tr>
742 </form>
743 EOT
744 done
745 cat <<EOT
746 </table>
747 <footer>
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 <pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
766 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
767 </section>
769 EOT
770 [ "$REMOTE_USER" == "root" -a "$(which iptables-save)" ] && cat <<EOT
771 <section>
772 <header id="iptables">$(_ 'Firewall')
773 $(edit_button /etc/knockd.conf "$(_ 'Port knocker')")
774 </header>
775 <pre>$(iptables-save)</pre>
776 </section>
777 EOT
779 ;;
780 esac
782 xhtml_footer
783 exit 0