tazpanel annotate network.cgi @ rev 522

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