tazpanel view network.cgi @ rev 626

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 08:30:05 2019 +0100 (2019-02-26)
parents 95d7ed740572
children 9f6e7841d19c
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 *\ 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 *\ delvlan\ *)
164 vconfig rem $(GET vlan) ;;
165 *\ addvlan\ *)
166 grep -q '^8021q ' /proc/modules || modprobe 8021q
167 vlan=$(GET if).$(GET id)
168 prio=$(GET priority)
169 [ -e /proc/net/vlan/$vlan ] || vconfig add ${vlan/./ }
170 for i in $(seq 0 7); do
171 vconfig set_ingress_map $vlan $i ${prio:-$i}
172 vconfig set_egress_map $vlan $i ${prio:-$i}
173 done ;;
174 esac
176 case " $(POST) " in
177 *\ connect_wifi\ *)
178 # Connect to a Wi-Fi network
179 /etc/init.d/network.sh stop | log
180 password="$(POST password)"
182 # Escape special characters to use with sed substitutions
183 password="$(echo -n "$password" | sed 's|\\|\\\\|g; s|&|\\\&|g' | sed "s|'|'\"'\"'|g")"
185 sed -i \
186 -e "s|^WIFI_ESSID=.*|WIFI_ESSID=\"$(POST essid)\"|" \
187 -e "s|^WIFI_BSSID=.*|WIFI_BSSID=\"$(POST bssid)\"|" \
188 -e "s|^WIFI_KEY_TYPE=.*|WIFI_KEY_TYPE=\"$(POST keyType)\"|" \
189 -e "s|^WIFI_KEY=.*|WIFI_KEY='$password'|" \
190 -e "s|^WIFI_EAP_METHOD=.*|WIFI_EAP_METHOD=\"$(POST eap)\"|" \
191 -e "s|^WIFI_CA_CERT=.*|WIFI_CA_CERT=\"$(POST caCert)\"|" \
192 -e "s|^WIFI_CLIENT_CERT=.*|WIFI_CLIENT_CERT=\"$(POST clientCert)\"|" \
193 -e "s|^WIFI_IDENTITY=.*|WIFI_IDENTITY=\"$(POST identity)\"|" \
194 -e "s|^WIFI_ANONYMOUS_IDENTITY=.*|WIFI_ANONYMOUS_IDENTITY=\"$(POST anonymousIdentity)\"|" \
195 -e "s|^WIFI_PHASE2=.*|WIFI_PHASE2=\"$(POST phase2)\"|" \
196 /etc/network.conf
197 . /etc/network.conf
198 start_wifi
199 ;;
200 esac
203 # Get values only now since they could have been modified by actions.
205 . /etc/network.conf
211 #
212 # Main Commands for pages
213 #
215 case " $(GET) " in
217 *\ scan\ *)
218 # Scan open ports
219 scan=$(GET scan); back=$(GET back)
220 xhtml_header
221 loading_msg "$(_ 'Scanning open ports...')"
223 cat <<EOT
224 <section>
225 <header>
226 $(_ 'Port scanning for %s' $scan)
227 $(back_button "$back" "$(_ 'Network')" "")
228 </header>
229 <pre>$(pscan -b $scan)</pre>
230 </section>
231 EOT
232 ;;
235 *\ eth\ *)
236 # Wired connections settings
237 xhtml_header "$(_ 'Ethernet connection')"
239 PAR1="size=\"20\" required"; PAR="$PAR1 pattern=\"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\""
241 case "$STATIC" in
242 yes) use_static='checked';;
243 *) use_static='';;
244 esac
246 stop_disabled=''; start_disabled=''
247 if cat /sys/class/net/eth*/operstate | fgrep -q up; then
248 start_disabled='disabled'
249 else
250 stop_disabled='disabled'
251 fi
253 [ -s /etc/ethers ] || echo "#01:02:03:04:05:06 mystation" > /etc/ethers
254 [ -w /etc/network.conf ] && cat <<EOT
255 <p>$(_ "Here you can configure a wired connection using DHCP to \
256 automatically get a random IP or configure a static/fixed IP")</p>
258 <section>
259 <header>$(_ 'Configuration')</header>
260 <form action="index.cgi" id="indexform"></form>
261 <form id="conf">
262 <input type="hidden" name="eth"/>
263 <div>
264 <table>
265 <tr><td>$(_ 'Interface')</td>
266 <td><select name="iface" value="$INTERFACE" style="width:100%">
267 $(cd /sys/class/net; ls -1 | awk -viface="$INTERFACE" '{
268 sel = ($0 == iface) ? " selected":""
269 printf "<option value=\"%s\"%s>%s", $0, sel, $0
270 }')
271 </select></td>
272 </tr>
273 <tr><td>$(_ 'Static IP')</td>
274 <td><label><input type="checkbox" name="staticip" id="staticip" $use_static/>
275 $(_ 'Use static IP')</td>
276 </tr>
277 <tr id="st1"><td>$(_ 'IP address')</td>
278 <td><input type="text" name="ip" value="$IP" $PAR/></td>
279 </tr>
280 <tr id="st2"><td>$(_ 'Netmask')</td>
281 <td><input type="text" name="netmask" value="$NETMASK" $PAR/></td>
282 </tr>
283 <tr id="st3"><td>$(_ 'Gateway')</td>
284 <td><input type="text" name="gateway" value="$GATEWAY" $PAR/></td>
285 </tr>
286 <tr id="st4"><td>$(_ 'DNS server')</td>
287 <td><input type="text" name="dns" value="$DNS_SERVER" $PAR/></td>
288 </tr>
289 <tr><td>$(_ 'Wake up')</td>
290 <td><label><input type="checkbox" name="wakeup" id="wakeup" />
291 $(_ 'Wake up machines by network')</td>
292 </tr>
293 <tr id="wk1"><td>$(_ 'MAC address to wake up')</td>
294 <td><input type="text" name="macwakup" title="$(_ 'Leave empty for a general wakeup')" $PAR/><!--
295 --><button form="indexform" name="file" value="/etc/ethers" data-icon="@view@">$(_ 'List')</button>
296 </td>
297 </tr>
298 <tr id="wk2"><td>$(_ 'MAC/IP address password')</td>
299 <td><input type="text" name="macpass" title="$(_ 'Optional')" $PAR/><!--
300 --><button form="indexform" name="exec" value="ether-wake --help" data-icon="@help@">$(_ 'Help')</button>
301 </td>
302 </tr>
303 </table>
304 </div>
305 </form>
306 <footer><!--
307 --><button form="conf" type="submit" name="start_eth" data-icon="@start@" $start_disabled>$(_ 'Start' )</button><!--
308 --><button form="conf" type="submit" name="stop" data-icon="@stop@" $stop_disabled >$(_ 'Stop' )</button><!--
309 --><button id="wk3" form="conf" type="submit" name="dowakeup" data-icon="@clock@" $stop_disabled >$(_ 'Wake up')</button><!--
310 --></footer>
311 </section>
313 <script type="text/javascript">
314 function check_change() {
315 enabled = document.getElementById('staticip').checked;
316 for (i = 1; i < 5; i++) {
317 document.getElementById('st' + i).style.display = enabled ? '' : 'none';
318 }
319 enabled = document.getElementById('wakeup').checked;
320 for (i = 1; i < 4; i++) {
321 document.getElementById('wk' + i).style.display = enabled ? '' : 'none';
322 }
323 }
325 document.getElementById('staticip').onchange = check_change;
326 document.getElementById('wakeup').onchange = check_change;
327 check_change();
328 </script>
329 EOT
330 cat <<EOT
331 <section>
332 <header>
333 $(_ 'Configuration file')
334 EOT
335 edit_button /etc/network.conf
336 cat <<EOT
337 </header>
338 <div>$(_ "These values are the ethernet settings in the main /etc/network.conf configuration file")</div>
339 <pre>$(awk '{if($1 !~ "WIFI" && $1 !~ "#" && $1 != ""){print $0}}' /etc/network.conf | syntax_highlighter conf)</pre>
340 </section>
341 EOT
342 ;;
346 *\ wifi_list\ *)
347 # Catch ESSIDs and format output.
348 # We get the list of networks by Cell and without spaces.
350 HIDDEN="$(_ '(hidden)')"
352 cat <<EOT
353 <table class="wide center zebra">
354 <thead>
355 <tr>
356 <td>$(_ 'Name')</td>
357 <td>$(_ 'Signal level')</td>
358 <td>$(_ 'Channel')</td>
359 <td>$(_ 'Encryption')</td>
360 <td>$(_ 'Status')</td>
361 </tr>
362 </thead>
363 <tbody>
364 EOT
365 if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
366 ifconfig $WIFI_INTERFACE up
367 for i in $(iwlist $WIFI_INTERFACE scan | sed '/Cell /!d;s/.*Cell \([^ ]*\).*/Cell.\1/')
368 do
369 SCAN=$(iwlist $WIFI_INTERFACE scan last | sed "/$i/,/Cell/!d" | sed '$d')
371 BSSID=$(echo "$SCAN" | sed -n 's|.*Address: \([^ ]*\).*|\1|p')
373 CHANNEL=$(echo "$SCAN" | sed -n 's|.*Channel[:=]\([^ ]*\).*|\1|p')
375 QUALITY=$(echo "$SCAN" | sed -n 's|.*Quality[:=]\([^ ]*\).*|\1|p')
376 QUALITY_ICON="lvl$(( 5*${QUALITY:-0} ))" # lvl0 .. lvl4, lvl5
377 case $QUALITY_ICON in
378 lvl0) QUALITY_ICON='@lvl0@';;
379 lvl1) QUALITY_ICON='@lvl1@';;
380 lvl2) QUALITY_ICON='@lvl2@';;
381 lvl3) QUALITY_ICON='@lvl3@';;
382 lvl4|lvl5) QUALITY_ICON='@lvl4@';;
383 esac
384 LEVEL=$(echo "$SCAN" | sed -n 's|.*Signal level[:=]\([^ ]*\).*|\1|p; s|-|−|')
386 ENCRYPTION=$(echo "$SCAN" | sed -n 's|.*Encryption key[:=]\([^ ]*\).*|\1|p') # on/off
388 ESSID=$(echo "$SCAN" | sed -n 's|.*ESSID:"\([^"]*\).*|\1|p')
390 # WPA Type - Group Cipher - Pairwise Ciphers - Authentication Suites
391 # {WPA|WPA2}-{TKIP|CCMP}-{TKIP|CCMP|TKIP CCMP}-{PSK|802.1x}
392 #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|-$||')"
394 # Authentication type
395 AUTH="$(echo "$SCAN" | sed -n 's|.*Authentication Suites[^:]*: *\(.*\)|\1|p')"
396 if [ -n "$(echo -n $AUTH | fgrep PSK)" ]; then
397 # WPA-Personal. Authentication using password (PSK = pre-shared key)
398 WIFI_KEY_TYPE='WPA'
399 elif [ -n "$(echo -n $AUTH | fgrep 802.1x)" ]; then
400 # WPA-Enterprise. Authentication using username, password, certificates...
401 WIFI_KEY_TYPE='EAP'
402 else
403 WIFI_KEY_TYPE='NONE'
404 fi
406 # Check encryption type
407 if [ "$ENCRYPTION" = 'on' ]; then
408 # "WPA" or "WPA2" or "WPA/WPA2" (maybe also "WPA2/WPA")
409 ENC_SIMPLE=$(echo "$SCAN" | sed -n '/.*WPA.*/ s|.*\(WPA[^ ]*\).*|\1|p')
410 ENC_SIMPLE=$(echo $ENC_SIMPLE | sed 's| |/|')
411 ENC_ICON='@sechi@' # high
412 if [ -z "$ENC_SIMPLE" ]; then
413 WIFI_KEY_TYPE='WEP'
414 ENC_SIMPLE='WEP'; ENC_ICON='@secmi@' # middle
415 fi
416 else
417 WIFI_KEY_TYPE='NONE'
418 ENC_SIMPLE="$(_ 'None')"; ENC_ICON='@seclo@' # low
419 fi
421 # Connected or not connected...
422 if ifconfig $WIFI_INTERFACE | fgrep -q inet && \
423 iwconfig $WIFI_INTERFACE | fgrep -q "ESSID:\"$ESSID\""; then
424 status="$(_ 'Connected')"
425 else
426 status='---'
427 fi
429 cat <<EOT
430 <tr>
431 <td><a data-icon="@wifi@" onclick="loadcfg('$ESSID', '$BSSID', '$WIFI_KEY_TYPE')">${ESSID:-$HIDDEN}</a></td>
432 <td><span data-icon="$QUALITY_ICON" title="Quality: $QUALITY"> $LEVEL dBm</span></td>
433 <td>$CHANNEL</td>
434 <td><span data-icon="$ENC_ICON">$ENC_SIMPLE</span></td>
435 <td>$status</td>
436 </tr>
437 EOT
438 done
439 fi
440 cat <<EOT
441 </tbody>
442 </table>
443 EOT
444 exit 0
445 ;;
448 *\ wifi\ *)
449 # Wireless connections settings
450 xhtml_header "$(_ 'Wireless connection')"
452 . /etc/network.conf
454 start_disabled=''; stop_disabled=''
455 if iwconfig 2>/dev/null | grep -q 'Tx-Power=off'; then
456 stop_disabled='disabled'
457 else
458 start_disabled='disabled'
459 fi
461 [ -w /etc/network.conf ] && cat <<EOT
462 <form>
463 <input type="hidden" name="wifi"/>
464 <button name="start_wifi" data-icon="@start@" $start_disabled>$(_ 'Start')</button><!--
465 --><button name="stop" data-icon="@stop@" $stop_disabled >$(_ 'Stop' )</button><!--
466 --><button type="submit" data-icon="@refresh@" $stop_disabled >$(_ 'Scan' )</button>
467 </form>
468 EOT
470 [ -w /etc/network.conf ] &&
471 if [ -n "$start_disabled" ]; then
472 cat <<EOT
473 <section id="wifiList">
474 <div style="text-align: center;"><span data-icon="@clock@">$(_ 'Scanning wireless interface...')</span></div>
475 </section>
477 <script type="text/javascript">
478 ajax('network.cgi?wifi_list', '1', 'wifiList');
479 $(parse_wpa_conf)
480 </script>
481 EOT
483 # Escape html characters in the WIFI_KEY
484 WIFI_KEY_ESCAPED="$(echo -n "$WIFI_KEY" | sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g')"
486 cat <<EOT
487 <section>
488 <header>$(_ 'Connection')</header>
489 <div>
490 <form method="post" action="?wifi" id="connection">
491 <input type="hidden" name="connect_wifi"/>
492 <input type="hidden" name="bssid" id="bssid"/>
493 <table>
494 <tr><td>$(_ 'Network SSID')</td>
495 <td><input type="text" name="essid" value="$WIFI_ESSID" id="essid"/></td>
496 </tr>
498 <tr><td>$(_ 'Security')</td>
499 <td><select name="keyType" id="keyType">
500 <option value="NONE">$(_ 'None')</option>
501 <option value="WEP" >WEP</option>
502 <option value="WPA" >WPA/WPA2 PSK</option>
503 <option value="EAP" >802.1x EAP</option>
504 </select>
505 </td>
506 </tr>
508 <tr class="eap">
509 <td><div>$(_ 'EAP method')</div></td>
510 <td><div><select name="eap" id="eap">
511 <option value="PEAP">PEAP</option>
512 <option value="TLS" >TLS</option>
513 <option value="TTLS">TTLS</option>
514 <option value="PWD" >PWD</option>
515 </select>
516 </div></td>
517 </tr>
519 <tr class="eap1">
520 <td><div>$(_ 'Phase 2 authentication')</div></td>
521 <td><div><select name="phase2" id="phase2">
522 <option value="none" >$(_ 'None')</option>
523 <option value="pap" >PAP</option>
524 <option value="mschap" >MSCHAP</option>
525 <option value="mschapv2">MSCHAPV2</option>
526 <option value="gtc" >GTC</option>
527 </select>
528 </div></td>
529 </tr>
531 <tr class="eap1">
532 <td><div>$(_ 'CA certificate')</div></td>
533 <td><div><input type="text" name="caCert" id="caCert"></div></td>
534 </tr>
536 <tr class="eap1">
537 <td><div>$(_ 'User certificate')</div></td>
538 <td><div><input type="text" name="clientCert" id="clientCert"></div></td>
539 </tr>
541 <tr class="eap">
542 <td><div>$(_ 'Identity')</div></td>
543 <td><div><input type="text" name="identity" id="identity"></div></td>
544 </tr>
546 <tr class="eap1">
547 <td><div>$(_ 'Anonymous identity')</div></td>
548 <td><div><input type="text" name="anonymousIdentity" id="anonymousIdentity"></div></td>
549 </tr>
551 <tr class="wep wpa eap">
552 <td><div>$(_ 'Password')</div></td>
553 <td><div>
554 <input type="password" name="password" value="$WIFI_KEY_ESCAPED" id="password"/>
555 <span data-img="@view@" title="$(_ 'Show password')"
556 onmousedown="document.getElementById('password').type='text'; return false"
557 onmouseup="document.getElementById('password').type='password'"
558 onmouseout="document.getElementById('password').type='password'"
559 ></span>
560 </div></td>
561 </tr>
563 </table>
564 </form>
565 </div>
566 <footer>
567 <button form="connection" type="submit" name="wifi" data-icon="@ok@">$(_ 'Configure')</button>
568 <button data-icon="@user@" onclick="shareWiFi(); popup('popup_qr', 'show');">$(_ 'Share')</button>
569 </footer>
570 </section>
572 <script type="text/javascript">
573 function wifiSettingsChange() {
574 document.getElementById('connection').className =
575 document.getElementById('keyType').value.toLowerCase() + ' ' +
576 document.getElementById('eap').value.toLowerCase();
577 }
578 document.getElementById('keyType').onchange = wifiSettingsChange;
579 document.getElementById('eap').onchange = wifiSettingsChange;
581 document.getElementById('keyType').value = "$WIFI_KEY_TYPE"; wifiSettingsChange();
583 function shareWiFi() {
584 // S=<SSID>; T={WPA|WEP|nopass}; P=<password>; H=<hidden?>
585 // Escape ":" and ";" -> "\:" and "\;"
586 // No harm for regular networks marked as hidden
587 var text = "WIFI:" +
588 "S:" + document.getElementById('essid').value.replace(/:/g, "\\\\:").replace(/;/g, "\\\\;") + ";" +
589 "T:" + document.getElementById('keyType').value.replace("NONE", "nopass") + ";" +
590 "P:" + document.getElementById('password').value.replace(/:/g, "\\\\:").replace(/;/g, "\\\\;") + ";" +
591 "H:true;" +
592 ";";
593 document.getElementById('qrimg').title = text;
594 qr.image({
595 image: document.getElementById('qrimg'),
596 value: text,
597 size: 10
598 });
599 }
600 </script>
602 <div id="shader" class="hidden" onclick="popup('popup_qr', 'close');"></div>
604 <table id="popup_qr" class="hidden" onclick="popup('popup_qr', 'close')">
605 <tr>
606 <td style="text-align: center;">
607 <div id="popup_qr_inner">
608 <img id="qrimg"/><br/>
609 $(_ 'Share Wi-Fi network with your friends')
610 </div>
611 </td>
612 </tr>
613 </table>
614 EOT
615 fi
617 cat <<EOT
618 <section>
619 <header>
620 $(_ 'Configuration file')
621 EOT
622 edit_button /etc/network.conf
623 cat <<EOT
624 </header>
625 <div>$(_ "These values are the wifi settings in the main /etc/network.conf configuration file")</div>
626 <pre>$(grep ^WIFI /etc/network.conf | sed 's|WIFI_KEY=.*|WIFI_KEY="********"|' | syntax_highlighter conf)</pre>
627 </section>
630 <section>
631 <header>$(_ 'Output of iwconfig')</header>
632 <pre>$(iwconfig)</pre>
633 </section>
634 EOT
635 ;;
638 *)
639 # Main Network page starting with a summary
640 xhtml_header "$(_ 'Manage network connections and services')"
642 stop_disabled=''; start_disabled=''
643 if cat /sys/class/net/*/operstate | fgrep -q up; then
644 start_disabled='disabled'
645 else
646 stop_disabled='disabled'
647 fi
649 if [ ! -w '/etc/network.conf' ]; then
650 start_disabled='disabled'; stop_disabled='disabled'
651 fi
653 cat <<EOT
654 <form action="index.cgi" id="indexform"></form>
656 <form id="mainform"><!--
657 --><button name="start" data-icon="@start@" $start_disabled>$(_ 'Start' )</button><!--
658 --><button name="stop" data-icon="@stop@" $stop_disabled >$(_ 'Stop' )</button><!--
659 --><button name="restart" data-icon="@restart@" $stop_disabled >$(_ 'Restart')</button>
660 </form>
662 <div class="float-right"><!--
663 -->$(_ 'Configuration:')<!--
664 --><button form="indexform" name="file" value="/etc/network.conf" data-icon="@conf@">network.conf</button><!--
665 --><button form="mainform" name="eth" data-icon="@eth@">Ethernet</button><!--
666 --><button form="mainform" name="wifi" data-icon="@wifi@">Wireless</button>
667 </div>
670 <section>
671 <header>$(_ 'Network interfaces')</header>
672 $(list_network_interfaces)
673 <footer>
674 <input form="mainform" type="checkbox" name="opt" value="ipforward" $(
675 [ "$REMOTE_USER" != 'root' ] && echo ' disabled' ;
676 [ $(cat $ip_forward) -eq 1 ] && echo ' checked')/>
677 EOT
678 _ 'forward packets between interfaces'
679 [ "$REMOTE_USER" = 'root' ] && cat <<EOT
680 <button form="mainform" name="toggleipforward" data-icon="@ok@">$(_ 'Change')</button>
681 EOT
682 cat <<EOT
683 </footer>
684 </section>
687 <section>
688 <header id="hosts">$(_ 'Hosts'; edit_button /etc/hosts)</header>
689 <span data-icon="@info@">$(r=$(getdb hosts | wc -l);
690 _p '%d record in the hosts DB' \
691 '%d records in the hosts DB' "$r" \
692 "$r")</span>
693 <pre class="scroll">$(getdb hosts | fgrep -v 0.0.0.0)</pre>
694 <footer>
695 <form action="hosts.cgi">
696 <button data-icon="@admin@" data-root>$(_ 'Configure')</button>
697 $(_ 'Use hosts file as Ad blocker')
698 </form>
699 </footer>
700 </section>
703 <section>
704 <header>$(_ 'Hostname')</header>
705 <footer>
706 EOT
707 if [ -w '/etc/hostname' ]; then
708 cat <<EOT
709 <form>
710 <input type="text" name="hostname" value="$(hostname)"/><!--
711 --><button type="submit" data-icon="@ok@">$(_ 'Change')</button>
712 </form>
713 EOT
714 else
715 cat /etc/hostname
716 fi
717 cat <<EOT
718 </footer>
719 </section>
721 EOT
722 devs="$(for i in $(sed '/:/!d;s/:.*//' /proc/net/dev); do
723 [ -e /proc/net/vlan/$i ] && continue
724 [ -e /sys/class/net/$i/flags ] || continue
725 [ $(($(cat /sys/class/net/$i/flags) & 0x1080)) -eq 4096 ] &&
726 echo $i
727 done)"
728 if [ "$REMOTE_USER" = "root" -a -n "$devs" ]; then
729 cat <<EOT
730 <section>
731 <header id="vlan">$(_ 'VLAN')</header>
732 <footer>
733 <form>
734 EOT
735 vlans="$(ls /proc/net/vlan/ 2> /dev/null | sed '/config/d')"
736 if [ -n "$vlans" ]; then
737 cat <<EOT
738 <table class="wide zebra center">
739 <thead>
740 <tr>
741 <td>$(_ 'Interface')</td>
742 <td>id</td>
743 <td>$(_ 'priority')</td>
744 </tr>
745 </thead>
746 <tbody>
747 EOT
748 for i in $vlans ; do
749 cat <<EOT
750 <tr>
751 <td><input type="radio" name="vlan" value="$i"/>$i</td>
752 <td>$(sed '/VID/!d;s/.*VID: \([^ ]*\).*/\1/' /proc/net/vlan/$i)</td>
753 <td>$(sed '/EGRESS/!d;s/.*: 0:\([^: ]*\).*/\1/' /proc/net/vlan/$i)</td>
754 <td></td>
755 </tr>
756 EOT
757 done
758 cat <<EOT
759 </tbody>
760 </table>
761 <button type="submit" data-icon="@remove@" name="delvlan">$(_ 'Remove')</button> $(_ 'or')
762 EOT
763 fi
764 cat <<EOT
765 <button type="submit" data-icon="@add@" name="addvlan">$(_ 'Add')</button>
766 $(_ 'on') <select name="if">
767 $(for i in $devs; do echo "<option>$i</option>"; done)
768 </select> id
769 <input type="text" name="id" value="1" size="4" title="1..4095" />
770 $(_ 'priority') <select name="prio">
771 $(for i in $(seq 0 7); do echo "<option>$i</option>"; done)
772 </select>
773 </form>
774 </footer>
775 </section>
777 EOT
778 fi
779 cat <<EOT
781 <section>
782 <header id="ifconfig">$(_ 'Output of ifconfig')</header>
783 <pre>$(ifconfig)</pre>
784 </section>
787 <section>
788 <header id="routing">$(_ 'Routing table')</header>
789 <pre>$(route -n)</pre>
790 </section>
793 <section>
794 <header id="dns">$(_ 'Domain name resolution'; edit_button /etc/resolv.conf)</header>
795 <pre>$(cat /etc/resolv.conf)</pre>
796 </section>
799 <section>
800 <header id="arp">$(_ 'ARP table')</header>
801 EOT
802 if [ "$REMOTE_USER" = "root" ]; then
803 echo "<table>"
804 arp -n | while read line ; do
805 cat <<EOT
806 <form>
807 <tr><td>
808 <input type="hidden" name="entry" value="$(urlencode "$(echo $line | \
809 sed 's/) .* on/ -i/;s/.*(//')")">
810 <button type="submit" data-icon="@remove@" name="rmarp"></button>
811 </td><td><pre>$line</pre></td></tr>
812 </form>
813 EOT
814 done
815 cat <<EOT
816 </table>
817 <footer>
818 <form>
819 IP <input type="text" name="ip" value="10.20.30.40" size="12" /> $(_ 'on') $(select_if)<!--
820 --><button type="submit" data-icon="@upgrade@" name="proxyarp">$(_ 'Proxy')</button>
821 $(_ 'or') <button type="submit" data-icon="@add@" name="addarp">$(_ 'Add')</button>
822 MAC <input type="text" name="mac" value="11:22:33:44:55:66" size="16" />
823 </form>
824 EOT
825 else
826 echo "<pre>$(arp -n)</pre>"
827 fi
828 cat <<EOT
829 </footer>
830 </section>
833 <section>
834 <header id="connections">$(_ 'IP Connections')</header>
835 <pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
836 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
837 </section>
839 EOT
840 [ "$REMOTE_USER" = "root" -a "$(which iptables-save)" ] && cat <<EOT
841 <section>
842 <header id="iptables">$(_ 'Firewall')
843 $(edit_button /etc/knockd.conf "$(_ 'Port knocker')")
844 </header>
845 <pre>$(iptables-save)</pre>
846 </section>
847 EOT
849 ;;
850 esac
852 xhtml_footer
853 exit 0