tazpanel annotate network.cgi @ rev 490

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