tazpanel annotate network.cgi @ rev 617

revision of german messages
author Hans-G?nter Theisgen
date Mon Oct 09 17:15:22 2017 +0100 (2017-10-09)
parents 26f60e49e3d5
children bf8941ab3cc3
rev   line source
pankso@38 1 #!/bin/sh
pankso@38 2 #
pankso@38 3 # Network configuration CGI interface
pankso@38 4 #
al@419 5 # Copyright (C) 2012-2015 SliTaz GNU/Linux - BSD License
pankso@112 6 #
pankso@38 7
al@419 8
pankso@38 9 # Common functions from libtazpanel
al@419 10
pascal@613 11 . ./lib/libtazpanel
pankso@38 12 get_config
pascal@81 13 header
pankso@38 14
al@501 15 TITLE=$(_ 'Network')
pankso@42 16
pascal@493 17 ip_forward=/proc/sys/net/ipv4/ip_forward
pankso@106 18
al@419 19 # Start a Wi-Fi connection
al@419 20
pankso@247 21 start_wifi() {
pankso@247 22 sed -i \
al@419 23 -e 's|^WIFI=.*|WIFI="yes"|' \
al@419 24 -e 's|^DHCP=.*|DHCP="yes"|' \
al@419 25 -e 's|^STATIC=.*|STATIC="no"|' /etc/network.conf
pankso@247 26 ifconfig $WIFI_INTERFACE up
pankso@247 27 iwconfig $WIFI_INTERFACE txpower auto
Christian@273 28 /etc/init.d/network.sh restart | log
al@463 29
al@463 30 # Sleep until connection established (max 5 seconds)
al@463 31 for i in $(seq 5); do
al@419 32 [ -n "$(iwconfig 2>/dev/null | fgrep Link)" ] && break
al@419 33 sleep 1
al@419 34 done
al@419 35 }
al@419 36
al@419 37
al@420 38 # Start an Ethernet connection
al@420 39
al@420 40 start_eth() {
al@420 41 case "$(GET staticip)" in
al@420 42 on) DHCP='no'; STATIC='yes';;
al@420 43 *) DHCP='yes'; STATIC='no';;
al@420 44 esac
al@420 45
al@420 46 /etc/init.d/network.sh stop | log
al@420 47 sleep 2
al@420 48 sed -i \
al@420 49 -e "s|^INTERFACE=.*|INTERFACE=\"$(GET iface)\"|" \
al@420 50 -e 's|^WIFI=.*|WIFI="no"|' \
al@420 51 -e "s|^DHCP=.*|DHCP=\"$DHCP\"|" \
al@420 52 -e "s|^STATIC=.*|STATIC=\"$STATIC\"|" \
al@420 53 -e "s|^IP=.*|IP=\"$(GET ip)\"|" \
al@420 54 -e "s|^NETMASK=.*|NETMASK=\"$(GET netmask)\"|" \
al@420 55 -e "s|^GATEWAY=.*|GATEWAY=\"$(GET gateway)\"|" \
al@420 56 -e "s|^DNS_SERVER=.*|DNS_SERVER=\"$(GET dns)\"|" \
al@420 57 /etc/network.conf
al@420 58 /etc/init.d/network.sh start | log
al@420 59 . /etc/network.conf
al@420 60 }
al@420 61
al@420 62
al@419 63 # Use /etc/wpa/wpa.conf as single database for known networks, passwords, etc.
al@419 64 # Translate this data to use in javascript.
al@419 65
al@419 66 parse_wpa_conf() {
al@419 67 awk '
al@419 68 BEGIN { print "networks = ["; begin_list = 1; network = 0; }
al@419 69 {
al@419 70 if ($0 == "network={") {
al@419 71 if (begin_list == 0) print ",";
al@419 72 begin_list = 0;
al@419 73 printf "{"; begin_obj = 1;
al@419 74 network = 1; next;
al@419 75 }
al@419 76 if (network == 1) {
al@419 77 if ($0 ~ "=") {
al@419 78 if (begin_obj == 0) printf ", ";
al@419 79 begin_obj = 0;
al@463 80
al@463 81 # split line into variable and value (note "=" can appear in the value)
al@463 82 split($0, a, "="); variable = a[1];
al@463 83 value = gensub(variable "=", "", "");
al@463 84
al@463 85 # escape html entities
al@463 86 value = gensub("\\\\", "\\\\", "g", value);
al@463 87 value = gensub("&", "\\&", "g", value);
al@463 88 value = gensub("<", "\\&lt;", "g", value);
al@463 89 value = gensub(">", "\\&gt;", "g", value);
al@463 90 value = gensub("\"", "\\\"", "g", value);
al@463 91
al@463 92 # if value was already quoted - remove \" from begin and end
al@463 93 if (substr(value, 1, 2) == "\\\"")
al@463 94 value = substr(value, 3, length(value) - 4);
al@463 95
al@463 96 # output in form: variable:"escaped value"
al@463 97 printf "%s:\"%s\"", variable, value;
al@419 98 }
al@419 99 }
al@419 100 if (network == 1 && $0 ~ "}") { printf "}"; network = 0; next; }
al@419 101 }
al@419 102 END {print "\n];"}
al@419 103 ' /etc/wpa/wpa.conf | sed 's|\t||g;'
al@419 104 }
al@419 105
al@419 106
al@419 107 # Waiting for network link up
al@419 108
al@419 109 wait_up() {
al@463 110 for i in $(seq 5); do
al@419 111 [ -z "$(cat /sys/class/net/*/operstate | fgrep up)"] && sleep 1
al@419 112 done
pankso@247 113 }
pankso@247 114
pascal@485 115 select_if() {
pascal@485 116 echo '<select name="interface">'
pascal@485 117 for i in $(ls /sys/class/net); do
pascal@511 118 grep -qs 1 /sys/class/net/$i/carrier &&
pascal@485 119 echo "<option>$i"
pascal@485 120 done
pascal@485 121 echo '</select>'
pascal@485 122 }
al@463 123
pankso@41 124 # Actions commands before page is displayed
al@419 125
pascal@81 126 case " $(GET) " in
pascal@81 127 *\ start\ *)
al@419 128 /etc/init.d/network.sh start | log
pankso@41 129 # Here we sleep a bit to let udhcp get the lease before reloading
paul@205 130 # the page with status
al@419 131 wait_up ;;
pascal@81 132 *\ stop\ *)
pankso@76 133 /etc/init.d/network.sh stop | log ;;
naitsirhc@269 134 *\ restart\ *)
al@419 135 /etc/init.d/network.sh restart | log
al@419 136 wait_up ;;
al@420 137 *\ start_wifi\ *)
al@419 138 start_wifi ;;
al@420 139 *\ start_eth\ *)
al@420 140 start_eth ;;
pascal@475 141 *\ dowakeup\ *)
pascal@475 142 mac="$(GET macwakup)"
pascal@475 143 unset pass
pascal@477 144 [ "$(GET macpass)" ] && pass="-p $(GET macpass)"
pascal@475 145 if [ "$mac" ]; then
pascal@475 146 ether-wake $(GET iface) $mac $pass
pascal@475 147 else
pascal@475 148 ether-wake -b $(GET iface) $pass
pascal@475 149 fi
pascal@475 150 ;;
al@526 151 *\ hostname\ *)
al@526 152 hostname="$(GET hostname)"
al@526 153 echo $(_ 'Changed hostname: %s' "$hostname") | log
al@526 154 echo "$hostname" > /etc/hostname;;
pascal@485 155 *\ rmarp\ *)
pascal@485 156 arp -d $(urldecode "$(GET entry)") ;;
pascal@485 157 *\ addarp\ *)
pascal@485 158 arp -i $(GET interface) -s $(GET ip) $(GET mac) ;;
pascal@485 159 *\ proxyarp\ *)
pascal@493 160 arp -i $(GET interface) -Ds $(GET ip) $(GET interface) pub ;;
pascal@493 161 *\ toggleipforward\ *)
pascal@493 162 echo $((1 - $(cat $ip_forward))) > $ip_forward ;;
pascal@614 163 *\ delvlan\ *)
pascal@614 164 vconfig rem $(GET vlan) ;;
pascal@614 165 *\ addvlan\ *)
pascal@614 166 grep -q '^8021q ' /proc/modules || modprobe 8021q
pascal@614 167 vlan=$(GET if).$(GET id)
pascal@614 168 prio=$(GET priority)
pascal@614 169 [ -e /proc/net/vlan/$vlan ] || vconfig add ${vlan/./ }
pascal@614 170 for i in $(seq 0 7); do
pascal@614 171 vconfig set_ingress_map $vlan $i ${prio:-$i}
pascal@614 172 vconfig set_egress_map $vlan $i ${prio:-$i}
pascal@614 173 done ;;
pankso@41 174 esac
pankso@41 175
al@463 176 case " $(POST) " in
al@463 177 *\ connect_wifi\ *)
al@463 178 # Connect to a Wi-Fi network
al@463 179 /etc/init.d/network.sh stop | log
al@463 180 password="$(POST password)"
al@463 181
al@463 182 # Escape special characters to use with sed substitutions
al@463 183 password="$(echo -n "$password" | sed 's|\\|\\\\|g; s|&|\\\&|g' | sed "s|'|'\"'\"'|g")"
al@463 184
al@463 185 sed -i \
al@463 186 -e "s|^WIFI_ESSID=.*|WIFI_ESSID=\"$(POST essid)\"|" \
al@463 187 -e "s|^WIFI_BSSID=.*|WIFI_BSSID=\"$(POST bssid)\"|" \
al@463 188 -e "s|^WIFI_KEY_TYPE=.*|WIFI_KEY_TYPE=\"$(POST keyType)\"|" \
al@463 189 -e "s|^WIFI_KEY=.*|WIFI_KEY='$password'|" \
al@463 190 -e "s|^WIFI_EAP_METHOD=.*|WIFI_EAP_METHOD=\"$(POST eap)\"|" \
al@463 191 -e "s|^WIFI_CA_CERT=.*|WIFI_CA_CERT=\"$(POST caCert)\"|" \
al@463 192 -e "s|^WIFI_CLIENT_CERT=.*|WIFI_CLIENT_CERT=\"$(POST clientCert)\"|" \
al@463 193 -e "s|^WIFI_IDENTITY=.*|WIFI_IDENTITY=\"$(POST identity)\"|" \
al@463 194 -e "s|^WIFI_ANONYMOUS_IDENTITY=.*|WIFI_ANONYMOUS_IDENTITY=\"$(POST anonymousIdentity)\"|" \
al@463 195 -e "s|^WIFI_PHASE2=.*|WIFI_PHASE2=\"$(POST phase2)\"|" \
al@463 196 /etc/network.conf
al@463 197 . /etc/network.conf
al@463 198 start_wifi
al@463 199 ;;
al@463 200 esac
al@463 201
al@419 202
paul@127 203 # Get values only now since they could have been modified by actions.
al@419 204
pankso@108 205 . /etc/network.conf
pankso@108 206
al@419 207
al@419 208
al@419 209
al@419 210
pankso@38 211 #
pankso@41 212 # Main Commands for pages
pankso@38 213 #
pankso@38 214
pascal@81 215 case " $(GET) " in
al@419 216
pascal@136 217 *\ scan\ *)
pascal@136 218 # Scan open ports
al@419 219 scan=$(GET scan); back=$(GET back)
pascal@136 220 xhtml_header
al@498 221 loading_msg "$(_ 'Scanning open ports...')"
al@303 222
al@419 223 cat <<EOT
al@419 224 <section>
al@419 225 <header>
al@443 226 $(_ 'Port scanning for %s' $scan)
al@443 227 $(back_button "$back" "$(_ 'Network')" "")
al@419 228 </header>
al@419 229 <pre>$(pscan -b $scan)</pre>
al@419 230 </section>
pascal@136 231 EOT
pascal@136 232 ;;
al@303 233
al@419 234
pascal@81 235 *\ eth\ *)
pankso@41 236 # Wired connections settings
al@501 237 xhtml_header "$(_ 'Ethernet connection')"
al@419 238
al@420 239 PAR1="size=\"20\" required"; PAR="$PAR1 pattern=\"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\""
al@420 240
al@420 241 case "$STATIC" in
al@420 242 yes) use_static='checked';;
al@420 243 *) use_static='';;
al@420 244 esac
al@420 245
al@420 246 stop_disabled=''; start_disabled=''
al@420 247 if cat /sys/class/net/eth*/operstate | fgrep -q up; then
al@420 248 start_disabled='disabled'
al@420 249 else
al@420 250 stop_disabled='disabled'
pankso@107 251 fi
al@419 252
pascal@477 253 [ -s /etc/ethers ] || echo "#01:02:03:04:05:06 mystation" > /etc/ethers
pascal@435 254 [ -w /etc/network.conf ] && cat <<EOT
al@443 255 <p>$(_ "Here you can configure a wired connection using DHCP to \
al@303 256 automatically get a random IP or configure a static/fixed IP")</p>
al@303 257
al@312 258 <section>
al@443 259 <header>$(_ 'Configuration')</header>
pascal@477 260 <form action="index.cgi" id="indexform"></form>
al@419 261 <form id="conf">
al@419 262 <input type="hidden" name="eth"/>
al@419 263 <div>
al@419 264 <table>
al@443 265 <tr><td>$(_ 'Interface')</td>
al@420 266 <td><select name="iface" value="$INTERFACE" style="width:100%">
al@419 267 $(cd /sys/class/net; ls -1 | awk -viface="$INTERFACE" '{
al@419 268 sel = ($0 == iface) ? " selected":""
al@419 269 printf "<option value=\"%s\"%s>%s", $0, sel, $0
al@419 270 }')
al@419 271 </select></td>
al@419 272 </tr>
al@443 273 <tr><td>$(_ 'Static IP')</td>
al@420 274 <td><label><input type="checkbox" name="staticip" id="staticip" $use_static/>
al@443 275 $(_ 'Use static IP')</td>
al@419 276 </tr>
al@443 277 <tr id="st1"><td>$(_ 'IP address')</td>
al@420 278 <td><input type="text" name="ip" value="$IP" $PAR/></td>
al@419 279 </tr>
al@443 280 <tr id="st2"><td>$(_ 'Netmask')</td>
al@420 281 <td><input type="text" name="netmask" value="$NETMASK" $PAR/></td>
al@419 282 </tr>
al@443 283 <tr id="st3"><td>$(_ 'Gateway')</td>
al@420 284 <td><input type="text" name="gateway" value="$GATEWAY" $PAR/></td>
al@420 285 </tr>
al@443 286 <tr id="st4"><td>$(_ 'DNS server')</td>
al@420 287 <td><input type="text" name="dns" value="$DNS_SERVER" $PAR/></td>
al@419 288 </tr>
pascal@475 289 <tr><td>$(_ 'Wake up')</td>
pascal@475 290 <td><label><input type="checkbox" name="wakeup" id="wakeup" />
pascal@475 291 $(_ 'Wake up machines by network')</td>
pascal@475 292 </tr>
pascal@475 293 <tr id="wk1"><td>$(_ 'MAC address to wake up')</td>
pascal@475 294 <td><input type="text" name="macwakup" title="$(_ 'Leave empty for a general wakeup')" $PAR/><!--
al@558 295 --><button form="indexform" name="file" value="/etc/ethers" data-icon="@view@">$(_ 'List')</button>
pascal@477 296 </td>
pascal@477 297 </tr>
pascal@477 298 <tr id="wk2"><td>$(_ 'MAC/IP address password')</td>
pascal@536 299 <td><input type="text" name="macpass" title="$(_ 'Optional')" $PAR/><!--
al@558 300 --><button form="indexform" name="exec" value="ether-wake --help" data-icon="@help@">$(_ 'Help')</button>
pascal@475 301 </td>
pascal@475 302 </tr>
al@419 303 </table>
al@419 304 </div>
al@419 305 </form>
al@419 306 <footer><!--
al@558 307 --><button form="conf" type="submit" name="start_eth" data-icon="@start@" $start_disabled>$(_ 'Start' )</button><!--
al@558 308 --><button form="conf" type="submit" name="stop" data-icon="@stop@" $stop_disabled >$(_ 'Stop' )</button><!--
al@558 309 --><button id="wk3" form="conf" type="submit" name="dowakeup" data-icon="@clock@" $stop_disabled >$(_ 'Wake up')</button><!--
al@419 310 --></footer>
al@419 311 </section>
al@419 312
al@419 313 <script type="text/javascript">
pascal@475 314 function check_change() {
pascal@475 315 enabled = document.getElementById('staticip').checked;
al@420 316 for (i = 1; i < 5; i++) {
pascal@475 317 document.getElementById('st' + i).style.display = enabled ? '' : 'none';
pascal@475 318 }
pascal@475 319 enabled = document.getElementById('wakeup').checked;
pascal@535 320 for (i = 1; i < 4; i++) {
pascal@475 321 document.getElementById('wk' + i).style.display = enabled ? '' : 'none';
al@420 322 }
al@420 323 }
al@419 324
pascal@475 325 document.getElementById('staticip').onchange = check_change;
pascal@475 326 document.getElementById('wakeup').onchange = check_change;
pascal@475 327 check_change();
al@419 328 </script>
pascal@435 329 EOT
pascal@435 330 cat <<EOT
al@419 331 <section>
al@419 332 <header>
al@443 333 $(_ 'Configuration file')
pascal@435 334 EOT
pascal@523 335 edit_button /etc/network.conf
pascal@435 336 cat <<EOT
al@419 337 </header>
al@443 338 <div>$(_ "These values are the ethernet settings in the main /etc/network.conf configuration file")</div>
al@419 339 <pre>$(awk '{if($1 !~ "WIFI" && $1 !~ "#" && $1 != ""){print $0}}' /etc/network.conf | syntax_highlighter conf)</pre>
al@419 340 </section>
al@419 341 EOT
al@419 342 ;;
al@419 343
al@419 344
al@419 345
al@419 346 *\ wifi_list\ *)
al@419 347 # Catch ESSIDs and format output.
al@419 348 # We get the list of networks by Cell and without spaces.
al@419 349
al@443 350 HIDDEN="$(_ '(hidden)')"
al@419 351
al@419 352 cat <<EOT
al@419 353 <table class="wide center zebra">
pankso@107 354 <thead>
pankso@107 355 <tr>
al@443 356 <td>$(_ 'Name')</td>
al@443 357 <td>$(_ 'Signal level')</td>
al@443 358 <td>$(_ 'Channel')</td>
al@443 359 <td>$(_ 'Encryption')</td>
al@443 360 <td>$(_ 'Status')</td>
pankso@107 361 </tr>
pankso@107 362 </thead>
al@303 363 <tbody>
al@419 364 EOT
al@419 365 if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
al@419 366 ifconfig $WIFI_INTERFACE up
al@419 367 for i in $(iwlist $WIFI_INTERFACE scan | sed '/Cell /!d;s/.*Cell \([^ ]*\).*/Cell.\1/')
al@419 368 do
al@419 369 SCAN=$(iwlist $WIFI_INTERFACE scan last | sed "/$i/,/Cell/!d" | sed '$d')
al@419 370
al@419 371 BSSID=$(echo "$SCAN" | sed -n 's|.*Address: \([^ ]*\).*|\1|p')
al@419 372
al@419 373 CHANNEL=$(echo "$SCAN" | sed -n 's|.*Channel[:=]\([^ ]*\).*|\1|p')
al@419 374
al@419 375 QUALITY=$(echo "$SCAN" | sed -n 's|.*Quality[:=]\([^ ]*\).*|\1|p')
al@419 376 QUALITY_ICON="lvl$(( 5*${QUALITY:-0} ))" # lvl0 .. lvl4, lvl5
al@558 377 case $QUALITY_ICON in
al@558 378 lvl0) QUALITY_ICON='@lvl0@';;
al@558 379 lvl1) QUALITY_ICON='@lvl1@';;
al@558 380 lvl2) QUALITY_ICON='@lvl2@';;
al@558 381 lvl3) QUALITY_ICON='@lvl3@';;
al@558 382 lvl4|lvl5) QUALITY_ICON='@lvl4@';;
al@558 383 esac
al@419 384 LEVEL=$(echo "$SCAN" | sed -n 's|.*Signal level[:=]\([^ ]*\).*|\1|p; s|-|−|')
al@419 385
al@419 386 ENCRYPTION=$(echo "$SCAN" | sed -n 's|.*Encryption key[:=]\([^ ]*\).*|\1|p') # on/off
al@419 387
al@419 388 ESSID=$(echo "$SCAN" | sed -n 's|.*ESSID:"\([^"]*\).*|\1|p')
al@419 389
al@419 390 # WPA Type - Group Cipher - Pairwise Ciphers - Authentication Suites
al@419 391 # {WPA|WPA2}-{TKIP|CCMP}-{TKIP|CCMP|TKIP CCMP}-{PSK|802.1x}
al@419 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|-$||')"
al@419 393
al@419 394 # Authentication type
al@419 395 AUTH="$(echo "$SCAN" | sed -n 's|.*Authentication Suites[^:]*: *\(.*\)|\1|p')"
al@419 396 if [ -n "$(echo -n $AUTH | fgrep PSK)" ]; then
al@419 397 # WPA-Personal. Authentication using password (PSK = pre-shared key)
al@419 398 WIFI_KEY_TYPE='WPA'
al@419 399 elif [ -n "$(echo -n $AUTH | fgrep 802.1x)" ]; then
al@419 400 # WPA-Enterprise. Authentication using username, password, certificates...
al@419 401 WIFI_KEY_TYPE='EAP'
al@419 402 else
al@419 403 WIFI_KEY_TYPE='NONE'
al@419 404 fi
al@419 405
al@419 406 # Check encryption type
al@419 407 if [ "$ENCRYPTION" == 'on' ]; then
al@419 408 # "WPA" or "WPA2" or "WPA/WPA2" (maybe also "WPA2/WPA")
al@419 409 ENC_SIMPLE=$(echo "$SCAN" | sed -n '/.*WPA.*/ s|.*\(WPA[^ ]*\).*|\1|p')
al@419 410 ENC_SIMPLE=$(echo $ENC_SIMPLE | sed 's| |/|')
al@558 411 ENC_ICON='@sechi@' # high
al@419 412 if [ -z "$ENC_SIMPLE" ]; then
al@419 413 WIFI_KEY_TYPE='WEP'
al@558 414 ENC_SIMPLE='WEP'; ENC_ICON='@secmi@' # middle
al@419 415 fi
al@419 416 else
al@419 417 WIFI_KEY_TYPE='NONE'
al@558 418 ENC_SIMPLE="$(_ 'None')"; ENC_ICON='@seclo@' # low
al@419 419 fi
al@419 420
al@419 421 # Connected or not connected...
al@419 422 if ifconfig $WIFI_INTERFACE | fgrep -q inet && \
al@419 423 iwconfig $WIFI_INTERFACE | fgrep -q "ESSID:\"$ESSID\""; then
al@443 424 status="$(_ 'Connected')"
al@419 425 else
al@419 426 status='---'
al@419 427 fi
al@419 428
al@419 429 cat <<EOT
al@419 430 <tr>
al@558 431 <td><a data-icon="@wifi@" onclick="loadcfg('$ESSID', '$BSSID', '$WIFI_KEY_TYPE')">${ESSID:-$HIDDEN}</a></td>
al@419 432 <td><span data-icon="$QUALITY_ICON" title="Quality: $QUALITY"> $LEVEL dBm</span></td>
al@419 433 <td>$CHANNEL</td>
al@419 434 <td><span data-icon="$ENC_ICON">$ENC_SIMPLE</span></td>
al@419 435 <td>$status</td>
al@419 436 </tr>
al@419 437 EOT
al@419 438 done
al@419 439 fi
al@419 440 cat <<EOT
al@303 441 </tbody>
al@419 442 </table>
al@419 443 EOT
al@419 444 exit 0
al@419 445 ;;
al@419 446
al@419 447
al@419 448 *\ wifi\ *)
al@419 449 # Wireless connections settings
al@501 450 xhtml_header "$(_ 'Wireless connection')"
al@419 451
al@419 452 . /etc/network.conf
al@419 453
al@419 454 start_disabled=''; stop_disabled=''
al@419 455 if iwconfig 2>/dev/null | grep -q 'Tx-Power=off'; then
al@419 456 stop_disabled='disabled'
al@419 457 else
al@419 458 start_disabled='disabled'
al@419 459 fi
al@419 460
pascal@435 461 [ -w /etc/network.conf ] && cat <<EOT
pascal@435 462 <form>
pascal@435 463 <input type="hidden" name="wifi"/>
al@558 464 <button name="start_wifi" data-icon="@start@" $start_disabled>$(_ 'Start')</button><!--
al@558 465 --><button name="stop" data-icon="@stop@" $stop_disabled >$(_ 'Stop' )</button><!--
al@558 466 --><button type="submit" data-icon="@refresh@" $stop_disabled >$(_ 'Scan' )</button>
pankso@107 467 </form>
al@419 468 EOT
al@419 469
pascal@435 470 [ -w /etc/network.conf ] &&
al@419 471 if [ -n "$start_disabled" ]; then
al@419 472 cat <<EOT
al@419 473 <section id="wifiList">
al@558 474 <div style="text-align: center;"><span data-icon="@clock@">$(_ 'Scanning wireless interface...')</span></div>
al@312 475 </section>
pankso@107 476
al@419 477 <script type="text/javascript">
pascal@441 478 ajax('network.cgi?wifi_list', '1', 'wifiList');
al@419 479 $(parse_wpa_conf)
al@419 480 </script>
al@419 481 EOT
al@419 482
al@463 483 # Escape html characters in the WIFI_KEY
al@463 484 WIFI_KEY_ESCAPED="$(echo -n "$WIFI_KEY" | sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g')"
al@419 485
al@419 486 cat <<EOT
al@312 487 <section>
al@443 488 <header>$(_ 'Connection')</header>
al@419 489 <div>
al@463 490 <form method="post" action="?wifi" id="connection">
al@420 491 <input type="hidden" name="connect_wifi"/>
al@420 492 <input type="hidden" name="bssid" id="bssid"/>
al@419 493 <table>
al@443 494 <tr><td>$(_ 'Network SSID')</td>
al@419 495 <td><input type="text" name="essid" value="$WIFI_ESSID" id="essid"/></td>
al@419 496 </tr>
al@303 497
al@443 498 <tr><td>$(_ 'Security')</td>
al@419 499 <td><select name="keyType" id="keyType">
al@443 500 <option value="NONE">$(_ 'None')</option>
al@419 501 <option value="WEP" >WEP</option>
al@419 502 <option value="WPA" >WPA/WPA2 PSK</option>
al@419 503 <option value="EAP" >802.1x EAP</option>
al@419 504 </select>
al@419 505 </td>
al@419 506 </tr>
al@419 507
al@419 508 <tr class="eap">
al@443 509 <td><div>$(_ 'EAP method')</div></td>
al@419 510 <td><div><select name="eap" id="eap">
al@419 511 <option value="PEAP">PEAP</option>
al@419 512 <option value="TLS" >TLS</option>
al@419 513 <option value="TTLS">TTLS</option>
al@419 514 <option value="PWD" >PWD</option>
al@419 515 </select>
al@419 516 </div></td>
al@419 517 </tr>
al@419 518
al@419 519 <tr class="eap1">
al@443 520 <td><div>$(_ 'Phase 2 authentication')</div></td>
al@419 521 <td><div><select name="phase2" id="phase2">
al@443 522 <option value="none" >$(_ 'None')</option>
al@419 523 <option value="pap" >PAP</option>
al@419 524 <option value="mschap" >MSCHAP</option>
al@419 525 <option value="mschapv2">MSCHAPV2</option>
al@419 526 <option value="gtc" >GTC</option>
al@419 527 </select>
al@419 528 </div></td>
al@419 529 </tr>
al@419 530
al@419 531 <tr class="eap1">
al@443 532 <td><div>$(_ 'CA certificate')</div></td>
al@419 533 <td><div><input type="text" name="caCert" id="caCert"></div></td>
al@419 534 </tr>
al@419 535
al@419 536 <tr class="eap1">
al@443 537 <td><div>$(_ 'User certificate')</div></td>
al@419 538 <td><div><input type="text" name="clientCert" id="clientCert"></div></td>
al@419 539 </tr>
al@419 540
al@419 541 <tr class="eap">
al@443 542 <td><div>$(_ 'Identity')</div></td>
al@419 543 <td><div><input type="text" name="identity" id="identity"></div></td>
al@419 544 </tr>
al@419 545
al@419 546 <tr class="eap1">
al@443 547 <td><div>$(_ 'Anonymous identity')</div></td>
al@419 548 <td><div><input type="text" name="anonymousIdentity" id="anonymousIdentity"></div></td>
al@419 549 </tr>
al@419 550
al@419 551 <tr class="wep wpa eap">
al@443 552 <td><div>$(_ 'Password')</div></td>
al@419 553 <td><div>
al@463 554 <input type="password" name="password" value="$WIFI_KEY_ESCAPED" id="password"/>
al@558 555 <span data-img="@view@" title="$(_ 'Show password')"
al@419 556 onmousedown="document.getElementById('password').type='text'; return false"
al@419 557 onmouseup="document.getElementById('password').type='password'"
al@419 558 onmouseout="document.getElementById('password').type='password'"
al@419 559 ></span>
al@419 560 </div></td>
al@419 561 </tr>
al@419 562
al@522 563 </table>
al@522 564 </form>
al@522 565 </div>
al@522 566 <footer>
al@558 567 <button form="connection" type="submit" name="wifi" data-icon="@ok@">$(_ 'Configure')</button>
al@558 568 <button data-icon="@user@" onclick="shareWiFi(); popup('popup_qr', 'show');">$(_ 'Share')</button>
al@522 569 </footer>
al@522 570 </section>
al@522 571
al@522 572 <script type="text/javascript">
al@419 573 function wifiSettingsChange() {
al@419 574 document.getElementById('connection').className =
al@419 575 document.getElementById('keyType').value.toLowerCase() + ' ' +
al@419 576 document.getElementById('eap').value.toLowerCase();
al@419 577 }
al@419 578 document.getElementById('keyType').onchange = wifiSettingsChange;
al@419 579 document.getElementById('eap').onchange = wifiSettingsChange;
al@419 580
al@419 581 document.getElementById('keyType').value = "$WIFI_KEY_TYPE"; wifiSettingsChange();
al@419 582
al@522 583 function shareWiFi() {
al@522 584 // S=<SSID>; T={WPA|WEP|nopass}; P=<password>; H=<hidden?>
al@522 585 // Escape ":" and ";" -> "\:" and "\;"
al@522 586 // No harm for regular networks marked as hidden
al@522 587 var text = "WIFI:" +
al@522 588 "S:" + document.getElementById('essid').value.replace(/:/g, "\\\\:").replace(/;/g, "\\\\;") + ";" +
al@522 589 "T:" + document.getElementById('keyType').value.replace("NONE", "nopass") + ";" +
al@522 590 "P:" + document.getElementById('password').value.replace(/:/g, "\\\\:").replace(/;/g, "\\\\;") + ";" +
al@522 591 "H:true;" +
al@522 592 ";";
al@522 593 document.getElementById('qrimg').title = text;
al@522 594 qr.image({
al@522 595 image: document.getElementById('qrimg'),
al@522 596 value: text,
al@522 597 size: 10
al@522 598 });
al@419 599 }
al@522 600 </script>
al@419 601
al@522 602 <div id="shader" class="hidden" onclick="popup('popup_qr', 'close');"></div>
al@522 603
al@522 604 <table id="popup_qr" class="hidden" onclick="popup('popup_qr', 'close')">
al@522 605 <tr>
al@522 606 <td style="text-align: center;">
al@522 607 <div id="popup_qr_inner">
al@525 608 <img id="qrimg"/><br/>
al@522 609 $(_ 'Share Wi-Fi network with your friends')
al@522 610 </div>
al@522 611 </td>
al@522 612 </tr>
al@522 613 </table>
al@419 614 EOT
al@419 615 fi
al@419 616
al@419 617 cat <<EOT
al@419 618 <section>
al@419 619 <header>
al@443 620 $(_ 'Configuration file')
pascal@435 621 EOT
pascal@523 622 edit_button /etc/network.conf
pascal@435 623 cat <<EOT
al@419 624 </header>
al@443 625 <div>$(_ "These values are the wifi settings in the main /etc/network.conf configuration file")</div>
al@463 626 <pre>$(grep ^WIFI /etc/network.conf | sed 's|WIFI_KEY=.*|WIFI_KEY="********"|' | syntax_highlighter conf)</pre>
al@419 627 </section>
al@419 628
al@419 629
al@419 630 <section>
al@443 631 <header>$(_ 'Output of iwconfig')</header>
al@419 632 <pre>$(iwconfig)</pre>
al@312 633 </section>
pankso@41 634 EOT
pankso@41 635 ;;
pankso@238 636
al@303 637
pankso@41 638 *)
pankso@41 639 # Main Network page starting with a summary
al@501 640 xhtml_header "$(_ 'Manage network connections and services')"
al@419 641
al@419 642 stop_disabled=''; start_disabled=''
al@419 643 if cat /sys/class/net/*/operstate | fgrep -q up; then
al@419 644 start_disabled='disabled'
al@419 645 else
al@419 646 stop_disabled='disabled'
al@419 647 fi
al@419 648
al@501 649 if [ ! -w '/etc/network.conf' ]; then
al@439 650 start_disabled='disabled'; stop_disabled='disabled'
al@439 651 fi
al@439 652
al@419 653 cat <<EOT
al@419 654 <form action="index.cgi" id="indexform"></form>
al@439 655
al@419 656 <form id="mainform"><!--
al@558 657 --><button name="start" data-icon="@start@" $start_disabled>$(_ 'Start' )</button><!--
al@558 658 --><button name="stop" data-icon="@stop@" $stop_disabled >$(_ 'Stop' )</button><!--
al@558 659 --><button name="restart" data-icon="@restart@" $stop_disabled >$(_ 'Restart')</button>
al@419 660 </form>
al@439 661
al@419 662 <div class="float-right"><!--
al@443 663 -->$(_ 'Configuration:')<!--
al@558 664 --><button form="indexform" name="file" value="/etc/network.conf" data-icon="@conf@">network.conf</button><!--
al@558 665 --><button form="mainform" name="eth" data-icon="@eth@">Ethernet</button><!--
al@558 666 --><button form="mainform" name="wifi" data-icon="@wifi@">Wireless</button>
pankso@38 667 </div>
pankso@38 668
al@419 669
al@419 670 <section>
al@443 671 <header>$(_ 'Network interfaces')</header>
al@419 672 $(list_network_interfaces)
pascal@493 673 <footer>
pascal@493 674 <input form="mainform" type="checkbox" name="opt" value="ipforward" $(
al@501 675 [ "$REMOTE_USER" != 'root' ] && echo ' disabled' ;
al@501 676 [ $(cat $ip_forward) -eq 1 ] && echo ' checked')/>
pascal@493 677 EOT
pascal@493 678 _ 'forward packets between interfaces'
al@501 679 [ "$REMOTE_USER" == 'root' ] && cat <<EOT
al@558 680 <button form="mainform" name="toggleipforward" data-icon="@ok@">$(_ 'Change')</button>
pascal@493 681 EOT
pascal@493 682 cat <<EOT
pascal@493 683 </footer>
al@312 684 </section>
pankso@38 685
al@419 686
al@312 687 <section>
al@525 688 <header id="hosts">$(_ 'Hosts'; edit_button /etc/hosts)</header>
al@558 689 <span data-icon="@info@">$(r=$(getdb hosts | wc -l);
al@527 690 _p '%d record in the hosts DB' \
al@527 691 '%d records in the hosts DB' "$r" \
al@526 692 "$r")</span>
al@526 693 <pre class="scroll">$(getdb hosts | fgrep -v 0.0.0.0)</pre>
al@526 694 <footer>
al@527 695 <form action="hosts.cgi">
al@558 696 <button data-icon="@admin@" data-root>$(_ 'Configure')</button>
al@526 697 $(_ 'Use hosts file as Ad blocker')
al@526 698 </form>
al@526 699 </footer>
al@312 700 </section>
pankso@108 701
al@419 702
al@312 703 <section>
al@443 704 <header>$(_ 'Hostname')</header>
al@419 705 <footer>
pascal@435 706 EOT
al@501 707 if [ -w '/etc/hostname' ]; then
pascal@435 708 cat <<EOT
al@419 709 <form>
al@526 710 <input type="text" name="hostname" value="$(hostname)"/><!--
al@558 711 --><button type="submit" data-icon="@ok@">$(_ 'Change')</button>
al@419 712 </form>
pascal@435 713 EOT
pascal@435 714 else
pascal@435 715 cat /etc/hostname
pascal@435 716 fi
pascal@435 717 cat <<EOT
al@419 718 </footer>
al@312 719 </section>
pankso@108 720
pascal@614 721 EOT
pascal@614 722 devs="$(for i in $(sed '/:/!d;s/:.*//' /proc/net/dev); do
pascal@614 723 [ -e /proc/net/vlan/$i ] && continue
pascal@614 724 [ -e /sys/class/net/$i/flags ] || continue
pascal@614 725 [ $(($(cat /sys/class/net/$i/flags) & 0x1080)) -eq 4096 ] &&
pascal@614 726 echo $i
pascal@614 727 done)"
pascal@614 728 if [ "$REMOTE_USER" == "root" -a -n "$devs" ]; then
pascal@614 729 cat <<EOT
pascal@614 730 <section>
pascal@614 731 <header id="vlan">$(_ 'VLAN')</header>
pascal@614 732 <footer>
pascal@614 733 <form>
pascal@614 734 EOT
pascal@614 735 vlans="$(ls /proc/net/vlan/ 2> /dev/null | sed '/config/d')"
pascal@614 736 if [ -n "$vlans" ]; then
pascal@614 737 cat <<EOT
pascal@614 738 <table class="wide zebra center">
pascal@614 739 <thead>
pascal@614 740 <tr>
pascal@614 741 <td>$(_ 'Interface')</td>
pascal@614 742 <td>id</td>
pascal@614 743 <td>$(_ 'priority')</td>
pascal@614 744 </tr>
pascal@614 745 </thead>
pascal@614 746 <tbody>
pascal@614 747 EOT
pascal@614 748 for i in $vlans ; do
pascal@614 749 cat <<EOT
pascal@614 750 <tr>
pascal@614 751 <td><input type="radio" name="vlan" value="$i"/>$i</td>
pascal@614 752 <td>$(sed '/VID/!d;s/.*VID: \([^ ]*\).*/\1/' /proc/net/vlan/$i)</td>
pascal@614 753 <td>$(sed '/EGRESS/!d;s/.*: 0:\([^: ]*\).*/\1/' /proc/net/vlan/$i)</td>
pascal@614 754 <td></td>
pascal@614 755 </tr>
pascal@614 756 EOT
pascal@614 757 done
pascal@614 758 cat <<EOT
pascal@614 759 </tbody>
pascal@614 760 </table>
pascal@614 761 <button type="submit" data-icon="@remove@" name="delvlan">$(_ 'Remove')</button> $(_ 'or')
pascal@614 762 EOT
pascal@614 763 fi
pascal@614 764 cat <<EOT
pascal@614 765 <button type="submit" data-icon="@add@" name="addvlan">$(_ 'Add')</button>
pascal@614 766 $(_ 'on') <select name="if">
pascal@614 767 $(for i in $devs; do echo "<option>$i</option>"; done)
pascal@614 768 </select> id
pascal@614 769 <input type="text" name="id" value="1" size="4" title="1..4095" />
pascal@614 770 $(_ 'priority') <select name="prio">
pascal@614 771 $(for i in $(seq 0 7); do echo "<option>$i</option>"; done)
pascal@614 772 </select>
pascal@614 773 </form>
pascal@614 774 </footer>
pascal@614 775 </section>
pascal@614 776
pascal@614 777 EOT
pascal@614 778 fi
pascal@614 779 cat <<EOT
al@419 780
al@312 781 <section>
al@443 782 <header id="ifconfig">$(_ 'Output of ifconfig')</header>
al@525 783 <pre>$(ifconfig)</pre>
al@312 784 </section>
pascal@68 785
al@419 786
al@312 787 <section>
al@443 788 <header id="routing">$(_ 'Routing table')</header>
al@525 789 <pre>$(route -n)</pre>
al@312 790 </section>
pascal@131 791
al@419 792
al@312 793 <section>
al@525 794 <header id="dns">$(_ 'Domain name resolution'; edit_button /etc/resolv.conf)</header>
al@525 795 <pre>$(cat /etc/resolv.conf)</pre>
al@312 796 </section>
al@303 797
al@419 798
al@312 799 <section>
al@443 800 <header id="arp">$(_ 'ARP table')</header>
pascal@485 801 EOT
pascal@485 802 if [ "$REMOTE_USER" == "root" ]; then
pascal@485 803 echo "<table>"
pascal@485 804 arp -n | while read line ; do
pascal@485 805 cat <<EOT
pascal@485 806 <form>
pascal@485 807 <tr><td>
pascal@485 808 <input type="hidden" name="entry" value="$(urlencode "$(echo $line | \
pascal@485 809 sed 's/) .* on/ -i/;s/.*(//')")">
al@558 810 <button type="submit" data-icon="@remove@" name="rmarp"></button>
pascal@485 811 </td><td><pre>$line</pre></td></tr>
pascal@485 812 </form>
pascal@485 813 EOT
pascal@485 814 done
pascal@485 815 cat <<EOT
al@525 816 </table>
al@525 817 <footer>
pascal@485 818 <form>
pascal@614 819 IP <input type="text" name="ip" value="10.20.30.40" size="12" /> $(_ 'on') $(select_if)<!--
al@558 820 --><button type="submit" data-icon="@upgrade@" name="proxyarp">$(_ 'Proxy')</button>
pascal@614 821 $(_ 'or') <button type="submit" data-icon="@add@" name="addarp">$(_ 'Add')</button>
pascal@485 822 MAC <input type="text" name="mac" value="11:22:33:44:55:66" size="16" />
pascal@485 823 </form>
pascal@485 824 EOT
pascal@485 825 else
pascal@485 826 echo "<pre>$(arp -n)</pre>"
pascal@485 827 fi
pascal@485 828 cat <<EOT
pascal@485 829 </footer>
al@312 830 </section>
al@303 831
al@419 832
al@312 833 <section>
al@443 834 <header id="connections">$(_ 'IP Connections')</header>
al@419 835 <pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
al@419 836 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
al@312 837 </section>
pascal@495 838
pankso@38 839 EOT
pascal@495 840 [ "$REMOTE_USER" == "root" -a "$(which iptables-save)" ] && cat <<EOT
pascal@495 841 <section>
pascal@523 842 <header id="iptables">$(_ 'Firewall')
pascal@523 843 $(edit_button /etc/knockd.conf "$(_ 'Port knocker')")
pascal@523 844 </header>
pascal@495 845 <pre>$(iptables-save)</pre>
pascal@495 846 </section>
pascal@495 847 EOT
pascal@495 848
pankso@38 849 ;;
pankso@38 850 esac
pankso@38 851
pankso@38 852 xhtml_footer
pankso@38 853 exit 0