tazpanel annotate network.cgi @ rev 463

Add prism.js syntax highlighter; now files can be edited "in place" without page reloading; allow ANY characters in the Wi-Fi password (bug 126); change web-app layout: main window isn't scrollable, with scrollable contents.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Apr 24 16:00:14 2015 +0300 (2015-04-24)
parents 169f1ccfb613
children c23efdafb18d
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
al@463 114
pankso@41 115 # Actions commands before page is displayed
al@419 116
pascal@81 117 case " $(GET) " in
pascal@81 118 *\ start\ *)
al@419 119 /etc/init.d/network.sh start | log
pankso@41 120 # Here we sleep a bit to let udhcp get the lease before reloading
paul@205 121 # the page with status
al@419 122 wait_up ;;
pascal@81 123 *\ stop\ *)
pankso@76 124 /etc/init.d/network.sh stop | log ;;
naitsirhc@269 125 *\ restart\ *)
al@419 126 /etc/init.d/network.sh restart | log
al@419 127 wait_up ;;
al@420 128 *\ start_wifi\ *)
al@419 129 start_wifi ;;
al@420 130 *\ start_eth\ *)
al@420 131 start_eth ;;
al@419 132 *\ host\ *)
al@419 133 get_hostname="$(GET host)"
al@443 134 echo $(_ 'Changed hostname: %s' $get_hostname) | log
al@303 135 echo "$get_hostname" > /etc/hostname ;;
pankso@41 136 esac
pankso@41 137
al@463 138 case " $(POST) " in
al@463 139 *\ connect_wifi\ *)
al@463 140 # Connect to a Wi-Fi network
al@463 141 /etc/init.d/network.sh stop | log
al@463 142 password="$(POST password)"
al@463 143
al@463 144 # Escape special characters to use with sed substitutions
al@463 145 password="$(echo -n "$password" | sed 's|\\|\\\\|g; s|&|\\\&|g' | sed "s|'|'\"'\"'|g")"
al@463 146
al@463 147 sed -i \
al@463 148 -e "s|^WIFI_ESSID=.*|WIFI_ESSID=\"$(POST essid)\"|" \
al@463 149 -e "s|^WIFI_BSSID=.*|WIFI_BSSID=\"$(POST bssid)\"|" \
al@463 150 -e "s|^WIFI_KEY_TYPE=.*|WIFI_KEY_TYPE=\"$(POST keyType)\"|" \
al@463 151 -e "s|^WIFI_KEY=.*|WIFI_KEY='$password'|" \
al@463 152 -e "s|^WIFI_EAP_METHOD=.*|WIFI_EAP_METHOD=\"$(POST eap)\"|" \
al@463 153 -e "s|^WIFI_CA_CERT=.*|WIFI_CA_CERT=\"$(POST caCert)\"|" \
al@463 154 -e "s|^WIFI_CLIENT_CERT=.*|WIFI_CLIENT_CERT=\"$(POST clientCert)\"|" \
al@463 155 -e "s|^WIFI_IDENTITY=.*|WIFI_IDENTITY=\"$(POST identity)\"|" \
al@463 156 -e "s|^WIFI_ANONYMOUS_IDENTITY=.*|WIFI_ANONYMOUS_IDENTITY=\"$(POST anonymousIdentity)\"|" \
al@463 157 -e "s|^WIFI_PHASE2=.*|WIFI_PHASE2=\"$(POST phase2)\"|" \
al@463 158 /etc/network.conf
al@463 159 . /etc/network.conf
al@463 160 start_wifi
al@463 161 ;;
al@463 162 esac
al@463 163
al@419 164
paul@127 165 # Get values only now since they could have been modified by actions.
al@419 166
pankso@108 167 . /etc/network.conf
pankso@108 168
al@419 169
al@419 170
al@419 171
al@419 172
pankso@38 173 #
pankso@41 174 # Main Commands for pages
pankso@38 175 #
pankso@38 176
pascal@81 177 case " $(GET) " in
al@419 178
pascal@136 179 *\ scan\ *)
pascal@136 180 # Scan open ports
al@419 181 scan=$(GET scan); back=$(GET back)
pascal@136 182 xhtml_header
al@443 183 LOADING_MSG=$(_ 'Scanning open ports...'); loading_msg
al@303 184
al@419 185 cat <<EOT
al@419 186 <section>
al@419 187 <header>
al@443 188 $(_ 'Port scanning for %s' $scan)
al@443 189 $(back_button "$back" "$(_ 'Network')" "")
al@419 190 </header>
al@419 191 <pre>$(pscan -b $scan)</pre>
al@419 192 </section>
pascal@136 193 EOT
pascal@136 194 ;;
al@303 195
al@419 196
pascal@81 197 *\ eth\ *)
pankso@41 198 # Wired connections settings
pankso@38 199 xhtml_header
al@419 200
al@420 201 PAR1="size=\"20\" required"; PAR="$PAR1 pattern=\"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\""
al@420 202
al@420 203 case "$STATIC" in
al@420 204 yes) use_static='checked';;
al@420 205 *) use_static='';;
al@420 206 esac
al@420 207
al@420 208 stop_disabled=''; start_disabled=''
al@420 209 if cat /sys/class/net/eth*/operstate | fgrep -q up; then
al@420 210 start_disabled='disabled'
al@420 211 else
al@420 212 stop_disabled='disabled'
pankso@107 213 fi
al@419 214
al@419 215 cat <<EOT
al@443 216 <h2>$(_ 'Ethernet connection')</h2>
pascal@435 217 EOT
pascal@435 218 [ -w /etc/network.conf ] && cat <<EOT
al@443 219 <p>$(_ "Here you can configure a wired connection using DHCP to \
al@303 220 automatically get a random IP or configure a static/fixed IP")</p>
al@303 221
al@312 222 <section>
al@443 223 <header>$(_ 'Configuration')</header>
al@419 224 <form id="conf">
al@419 225 <input type="hidden" name="eth"/>
al@419 226 <div>
al@419 227 <table>
al@443 228 <tr><td>$(_ 'Interface')</td>
al@420 229 <td><select name="iface" value="$INTERFACE" style="width:100%">
al@419 230 $(cd /sys/class/net; ls -1 | awk -viface="$INTERFACE" '{
al@419 231 sel = ($0 == iface) ? " selected":""
al@419 232 printf "<option value=\"%s\"%s>%s", $0, sel, $0
al@419 233 }')
al@419 234 </select></td>
al@419 235 </tr>
al@443 236 <tr><td>$(_ 'Static IP')</td>
al@420 237 <td><label><input type="checkbox" name="staticip" id="staticip" $use_static/>
al@443 238 $(_ 'Use static IP')</td>
al@419 239 </tr>
al@443 240 <tr id="st1"><td>$(_ 'IP address')</td>
al@420 241 <td><input type="text" name="ip" value="$IP" $PAR/></td>
al@419 242 </tr>
al@443 243 <tr id="st2"><td>$(_ 'Netmask')</td>
al@420 244 <td><input type="text" name="netmask" value="$NETMASK" $PAR/></td>
al@419 245 </tr>
al@443 246 <tr id="st3"><td>$(_ 'Gateway')</td>
al@420 247 <td><input type="text" name="gateway" value="$GATEWAY" $PAR/></td>
al@420 248 </tr>
al@443 249 <tr id="st4"><td>$(_ 'DNS server')</td>
al@420 250 <td><input type="text" name="dns" value="$DNS_SERVER" $PAR/></td>
al@419 251 </tr>
al@419 252 </table>
al@419 253 </div>
al@419 254 </form>
al@419 255 <footer><!--
al@443 256 --><button form="conf" type="submit" name="start_eth" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
al@443 257 --><button form="conf" type="submit" name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
al@419 258 --></footer>
al@419 259 </section>
al@419 260
al@419 261 <script type="text/javascript">
al@420 262 function static_change() {
al@420 263 staticip = document.getElementById('staticip').checked;
al@420 264 for (i = 1; i < 5; i++) {
al@420 265 document.getElementById('st' + i).style.display = staticip ? '' : 'none';
al@420 266 }
al@420 267 }
al@419 268
al@420 269 document.getElementById('staticip').onchange = static_change;
al@420 270 static_change();
al@419 271 </script>
pascal@435 272 EOT
pascal@435 273 cat <<EOT
al@419 274 <section>
al@419 275 <header>
al@443 276 $(_ 'Configuration file')
pascal@435 277 EOT
pascal@435 278 [ -w /etc/network.conf ] && cat <<EOT
al@419 279 <form action="index.cgi">
al@419 280 <input type="hidden" name="file" value="/etc/network.conf"/>
al@443 281 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
al@419 282 </form>
pascal@435 283 EOT
pascal@435 284 cat <<EOT
al@419 285 </header>
al@443 286 <div>$(_ "These values are the ethernet settings in the main /etc/network.conf configuration file")</div>
al@419 287 <pre>$(awk '{if($1 !~ "WIFI" && $1 !~ "#" && $1 != ""){print $0}}' /etc/network.conf | syntax_highlighter conf)</pre>
al@419 288 </section>
al@419 289 EOT
al@419 290 ;;
al@419 291
al@419 292
al@419 293
al@419 294 *\ wifi_list\ *)
al@419 295 # Catch ESSIDs and format output.
al@419 296 # We get the list of networks by Cell and without spaces.
al@419 297
al@443 298 HIDDEN="$(_ '(hidden)')"
al@419 299
al@419 300 cat <<EOT
al@419 301 <table class="wide center zebra">
pankso@107 302 <thead>
pankso@107 303 <tr>
al@443 304 <td>$(_ 'Name')</td>
al@443 305 <td>$(_ 'Signal level')</td>
al@443 306 <td>$(_ 'Channel')</td>
al@443 307 <td>$(_ 'Encryption')</td>
al@443 308 <td>$(_ 'Status')</td>
pankso@107 309 </tr>
pankso@107 310 </thead>
al@303 311 <tbody>
al@419 312 EOT
al@419 313 if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
al@419 314 ifconfig $WIFI_INTERFACE up
al@419 315 for i in $(iwlist $WIFI_INTERFACE scan | sed '/Cell /!d;s/.*Cell \([^ ]*\).*/Cell.\1/')
al@419 316 do
al@419 317 SCAN=$(iwlist $WIFI_INTERFACE scan last | sed "/$i/,/Cell/!d" | sed '$d')
al@419 318
al@419 319 BSSID=$(echo "$SCAN" | sed -n 's|.*Address: \([^ ]*\).*|\1|p')
al@419 320
al@419 321 CHANNEL=$(echo "$SCAN" | sed -n 's|.*Channel[:=]\([^ ]*\).*|\1|p')
al@419 322
al@419 323 QUALITY=$(echo "$SCAN" | sed -n 's|.*Quality[:=]\([^ ]*\).*|\1|p')
al@419 324 QUALITY_ICON="lvl$(( 5*${QUALITY:-0} ))" # lvl0 .. lvl4, lvl5
al@419 325 LEVEL=$(echo "$SCAN" | sed -n 's|.*Signal level[:=]\([^ ]*\).*|\1|p; s|-|−|')
al@419 326
al@419 327 ENCRYPTION=$(echo "$SCAN" | sed -n 's|.*Encryption key[:=]\([^ ]*\).*|\1|p') # on/off
al@419 328
al@419 329 ESSID=$(echo "$SCAN" | sed -n 's|.*ESSID:"\([^"]*\).*|\1|p')
al@419 330
al@419 331 # WPA Type - Group Cipher - Pairwise Ciphers - Authentication Suites
al@419 332 # {WPA|WPA2}-{TKIP|CCMP}-{TKIP|CCMP|TKIP CCMP}-{PSK|802.1x}
al@419 333 #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 334
al@419 335 # Authentication type
al@419 336 AUTH="$(echo "$SCAN" | sed -n 's|.*Authentication Suites[^:]*: *\(.*\)|\1|p')"
al@419 337 if [ -n "$(echo -n $AUTH | fgrep PSK)" ]; then
al@419 338 # WPA-Personal. Authentication using password (PSK = pre-shared key)
al@419 339 WIFI_KEY_TYPE='WPA'
al@419 340 elif [ -n "$(echo -n $AUTH | fgrep 802.1x)" ]; then
al@419 341 # WPA-Enterprise. Authentication using username, password, certificates...
al@419 342 WIFI_KEY_TYPE='EAP'
al@419 343 else
al@419 344 WIFI_KEY_TYPE='NONE'
al@419 345 fi
al@419 346
al@419 347 # Check encryption type
al@419 348 if [ "$ENCRYPTION" == 'on' ]; then
al@419 349 # "WPA" or "WPA2" or "WPA/WPA2" (maybe also "WPA2/WPA")
al@419 350 ENC_SIMPLE=$(echo "$SCAN" | sed -n '/.*WPA.*/ s|.*\(WPA[^ ]*\).*|\1|p')
al@419 351 ENC_SIMPLE=$(echo $ENC_SIMPLE | sed 's| |/|')
al@419 352 ENC_ICON='sechi' # high
al@419 353 if [ -z "$ENC_SIMPLE" ]; then
al@419 354 WIFI_KEY_TYPE='WEP'
al@419 355 ENC_SIMPLE='WEP'; ENC_ICON='secmi' # middle
al@419 356 fi
al@419 357 else
al@419 358 WIFI_KEY_TYPE='NONE'
al@443 359 ENC_SIMPLE="$(_ 'None')"; ENC_ICON='seclo' # low
al@419 360 fi
al@419 361
al@419 362 #
al@419 363 #if echo $SCAN | grep -q 'Mode:Managed'; then
al@419 364 # AP="&amp;ap=$(echo $SCAN | sed 's/.*Address: \([^ ]*\).*/\1/')"
al@419 365 #else
al@419 366 # AP=''
al@419 367 #fi
al@419 368
al@419 369 # Connected or not connected...
al@419 370 if ifconfig $WIFI_INTERFACE | fgrep -q inet && \
al@419 371 iwconfig $WIFI_INTERFACE | fgrep -q "ESSID:\"$ESSID\""; then
al@443 372 status="$(_ 'Connected')"
al@419 373 else
al@419 374 status='---'
al@419 375 fi
al@419 376
al@419 377 cat <<EOT
al@419 378 <tr>
al@419 379 <td><a data-icon="wifi" onclick="loadcfg('$ESSID', '$BSSID', '$WIFI_KEY_TYPE')">${ESSID:-$HIDDEN}</a></td>
al@419 380 <td><span data-icon="$QUALITY_ICON" title="Quality: $QUALITY"> $LEVEL dBm</span></td>
al@419 381 <td>$CHANNEL</td>
al@419 382 <td><span data-icon="$ENC_ICON">$ENC_SIMPLE</span></td>
al@419 383 <td>$status</td>
al@419 384 </tr>
al@419 385 EOT
al@419 386 done
al@419 387 fi
al@419 388 cat <<EOT
al@303 389 </tbody>
al@419 390 </table>
al@419 391 EOT
al@419 392 exit 0
al@419 393 ;;
al@419 394
al@419 395
al@419 396 *\ wifi\ *)
al@419 397 # Wireless connections settings
al@419 398 xhtml_header
al@419 399
al@419 400 . /etc/network.conf
al@419 401 cat <<EOT
al@443 402 <h2>$(_ 'Wireless connection')</h2>
al@419 403 EOT
al@419 404
al@419 405 start_disabled=''; stop_disabled=''
al@419 406 if iwconfig 2>/dev/null | grep -q 'Tx-Power=off'; then
al@419 407 stop_disabled='disabled'
al@419 408 else
al@419 409 start_disabled='disabled'
al@419 410 fi
al@419 411
pascal@435 412 [ -w /etc/network.conf ] && cat <<EOT
pascal@435 413 <form>
pascal@435 414 <input type="hidden" name="wifi"/>
al@443 415 <button name="start_wifi" data-icon="start" $start_disabled>$(_ 'Start')</button><!--
al@443 416 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
al@443 417 --><button type="submit" data-icon="refresh" $stop_disabled >$(_ 'Scan' )</button>
pankso@107 418 </form>
al@419 419 EOT
al@419 420
pascal@435 421 [ -w /etc/network.conf ] &&
al@419 422 if [ -n "$start_disabled" ]; then
al@419 423 cat <<EOT
al@419 424 <section id="wifiList">
al@443 425 <div style="text-align: center;"><span id="ajaxStatus"></span>$(_ 'Scanning wireless interface...')</div>
al@312 426 </section>
pankso@107 427
al@419 428 <script type="text/javascript">
pascal@441 429 ajax('network.cgi?wifi_list', '1', 'wifiList');
al@419 430 $(parse_wpa_conf)
al@419 431 </script>
al@419 432 EOT
al@419 433
al@463 434 # Escape html characters in the WIFI_KEY
al@463 435 WIFI_KEY_ESCAPED="$(echo -n "$WIFI_KEY" | sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g')"
al@419 436
al@419 437 cat <<EOT
al@312 438 <section>
al@443 439 <header>$(_ 'Connection')</header>
al@419 440 <div>
al@463 441 <form method="post" action="?wifi" id="connection">
al@420 442 <input type="hidden" name="connect_wifi"/>
al@420 443 <input type="hidden" name="bssid" id="bssid"/>
al@419 444 <table>
al@443 445 <tr><td>$(_ 'Network SSID')</td>
al@419 446 <td><input type="text" name="essid" value="$WIFI_ESSID" id="essid"/></td>
al@419 447 </tr>
al@303 448
al@443 449 <tr><td>$(_ 'Security')</td>
al@419 450 <td><select name="keyType" id="keyType">
al@443 451 <option value="NONE">$(_ 'None')</option>
al@419 452 <option value="WEP" >WEP</option>
al@419 453 <option value="WPA" >WPA/WPA2 PSK</option>
al@419 454 <option value="EAP" >802.1x EAP</option>
al@419 455 </select>
al@419 456 </td>
al@419 457 </tr>
al@419 458
al@419 459 <tr class="eap">
al@443 460 <td><div>$(_ 'EAP method')</div></td>
al@419 461 <td><div><select name="eap" id="eap">
al@419 462 <option value="PEAP">PEAP</option>
al@419 463 <option value="TLS" >TLS</option>
al@419 464 <option value="TTLS">TTLS</option>
al@419 465 <option value="PWD" >PWD</option>
al@419 466 </select>
al@419 467 </div></td>
al@419 468 </tr>
al@419 469
al@419 470 <tr class="eap1">
al@443 471 <td><div>$(_ 'Phase 2 authentication')</div></td>
al@419 472 <td><div><select name="phase2" id="phase2">
al@443 473 <option value="none" >$(_ 'None')</option>
al@419 474 <option value="pap" >PAP</option>
al@419 475 <option value="mschap" >MSCHAP</option>
al@419 476 <option value="mschapv2">MSCHAPV2</option>
al@419 477 <option value="gtc" >GTC</option>
al@419 478 </select>
al@419 479 </div></td>
al@419 480 </tr>
al@419 481
al@419 482 <tr class="eap1">
al@443 483 <td><div>$(_ 'CA certificate')</div></td>
al@419 484 <td><div><input type="text" name="caCert" id="caCert"></div></td>
al@419 485 </tr>
al@419 486
al@419 487 <tr class="eap1">
al@443 488 <td><div>$(_ 'User certificate')</div></td>
al@419 489 <td><div><input type="text" name="clientCert" id="clientCert"></div></td>
al@419 490 </tr>
al@419 491
al@419 492 <tr class="eap">
al@443 493 <td><div>$(_ 'Identity')</div></td>
al@419 494 <td><div><input type="text" name="identity" id="identity"></div></td>
al@419 495 </tr>
al@419 496
al@419 497 <tr class="eap1">
al@443 498 <td><div>$(_ 'Anonymous identity')</div></td>
al@419 499 <td><div><input type="text" name="anonymousIdentity" id="anonymousIdentity"></div></td>
al@419 500 </tr>
al@419 501
al@419 502 <tr class="wep wpa eap">
al@443 503 <td><div>$(_ 'Password')</div></td>
al@419 504 <td><div>
al@463 505 <input type="password" name="password" value="$WIFI_KEY_ESCAPED" id="password"/>
al@443 506 <span data-img="view" title="$(_ 'Show password')"
al@419 507 onmousedown="document.getElementById('password').type='text'; return false"
al@419 508 onmouseup="document.getElementById('password').type='password'"
al@419 509 onmouseout="document.getElementById('password').type='password'"
al@419 510 ></span>
al@419 511 </div></td>
al@419 512 </tr>
al@419 513
al@419 514 <script type="text/javascript">
al@419 515 function wifiSettingsChange() {
al@419 516 document.getElementById('connection').className =
al@419 517 document.getElementById('keyType').value.toLowerCase() + ' ' +
al@419 518 document.getElementById('eap').value.toLowerCase();
al@419 519 }
al@419 520 document.getElementById('keyType').onchange = wifiSettingsChange;
al@419 521 document.getElementById('eap').onchange = wifiSettingsChange;
al@419 522
al@419 523 document.getElementById('keyType').value = "$WIFI_KEY_TYPE"; wifiSettingsChange();
al@419 524 </script>
al@419 525
al@419 526 <style type="text/css">
al@419 527 #connection input[type="text"], #connection input[type="password"] { width: 14rem; }
al@419 528 #connection select { width: 14.4rem; }
al@419 529
al@419 530 #connection td { padding: 0; margin: 0; }
al@419 531 #connection [class] div {
al@419 532 max-height: 0; overflow: hidden; padding: 0; margin: 0;
al@419 533 -webkit-transition: all 0.5s ease-in-out;
al@419 534 -moz-transition: all 0.5s ease-in-out;
al@419 535 transition: all 0.5s ease-in-out;
al@419 536 }
al@419 537 .wep .wep div, .wpa .wpa div, .eap .eap div,
al@419 538 .eap.peap .eap1 div, .eap.tls .eap1 div, .eap.ttls .eap1 div {
al@419 539 max-height: 2em !important;
al@419 540 }
al@419 541 </style>
al@419 542
al@419 543 </table>
al@419 544 </form>
al@419 545 </div>
al@419 546 <footer>
al@443 547 <button form="connection" type="submit" name="wifi" data-icon="ok">$(_ 'Configure')</button>
al@419 548 </footer>
al@419 549 </section>
al@419 550 EOT
al@419 551 fi
al@419 552
al@419 553 cat <<EOT
al@419 554 <section>
al@419 555 <header>
al@443 556 $(_ 'Configuration file')
pascal@435 557 EOT
pascal@435 558 [ -w /etc/network.conf ] && cat <<EOT
al@419 559 <form action="index.cgi">
al@419 560 <input type="hidden" name="file" value="/etc/network.conf"/>
al@443 561 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
al@419 562 </form>
pascal@435 563 EOT
pascal@435 564 cat <<EOT
al@419 565 </header>
al@443 566 <div>$(_ "These values are the wifi settings in the main /etc/network.conf configuration file")</div>
al@463 567 <pre>$(grep ^WIFI /etc/network.conf | sed 's|WIFI_KEY=.*|WIFI_KEY="********"|' | syntax_highlighter conf)</pre>
al@419 568 </section>
al@419 569
al@419 570
al@419 571 <section>
al@443 572 <header>$(_ 'Output of iwconfig')</header>
al@419 573 <pre>$(iwconfig)</pre>
al@312 574 </section>
pankso@41 575 EOT
pankso@41 576 ;;
pankso@238 577
al@303 578
pankso@41 579 *)
pankso@41 580 # Main Network page starting with a summary
pankso@41 581 xhtml_header
al@419 582
al@419 583 stop_disabled=''; start_disabled=''
al@419 584 if cat /sys/class/net/*/operstate | fgrep -q up; then
al@419 585 start_disabled='disabled'
al@419 586 else
al@419 587 stop_disabled='disabled'
al@419 588 fi
al@419 589
al@439 590 if [ ! -w /etc/network.conf ]; then
al@439 591 start_disabled='disabled'; stop_disabled='disabled'
al@439 592 fi
al@439 593
al@419 594 cat <<EOT
al@443 595 <h2>$(_ 'Networking')</h2>
al@303 596
al@443 597 <p>$(_ 'Manage network connections and services')</p>
al@303 598
al@419 599 <form action="index.cgi" id="indexform"></form>
al@439 600
al@419 601 <form id="mainform"><!--
al@443 602 --><button name="start" data-icon="start" $start_disabled>$(_ 'Start' )</button><!--
al@443 603 --><button name="stop" data-icon="stop" $stop_disabled >$(_ 'Stop' )</button><!--
al@443 604 --><button name="restart" data-icon="restart" $stop_disabled >$(_ 'Restart')</button>
al@419 605 </form>
al@439 606
al@419 607 <div class="float-right"><!--
al@443 608 -->$(_ 'Configuration:')<!--
al@419 609 --><button form="indexform" name="file" value="/etc/network.conf" data-icon="conf">network.conf</button><!--
al@419 610 --><button form="mainform" name="eth" data-icon="eth">Ethernet</button><!--
al@419 611 --><button form="mainform" name="wifi" data-icon="wifi">Wireless</button>
pankso@38 612 </div>
pankso@38 613
al@419 614
al@419 615 <section>
al@443 616 <header>$(_ 'Network interfaces')</header>
al@419 617 $(list_network_interfaces)
al@312 618 </section>
pankso@38 619
al@419 620
al@312 621 <section>
al@443 622 <header id="hosts">$(_ 'Hosts')</header>
al@419 623 <pre>$(cat /etc/hosts)</pre>
pascal@435 624 EOT
pascal@435 625 [ -w /etc/hosts ] && cat <<EOT
al@419 626 <footer>
al@419 627 <form action="index.cgi">
al@419 628 <input type="hidden" name="file" value="/etc/hosts"/>
al@443 629 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
al@419 630 </form>
al@419 631 </footer>
pascal@435 632 EOT
pascal@435 633 cat <<EOT
al@312 634 </section>
pankso@108 635
al@419 636
al@312 637 <section>
al@443 638 <header>$(_ 'Hostname')</header>
al@419 639 <footer>
pascal@435 640 EOT
pascal@435 641 if [ -w /etc/hostname ]; then
pascal@435 642 cat <<EOT
al@419 643 <form>
al@419 644 <!-- was: name="hostname"; please don't use 'name' in name: unwanted webkit styling -->
al@419 645 <input type="text" name="host" value="$(cat /etc/hostname)"/><!--
al@443 646 --><button type="submit" data-icon="ok">$(_ 'Change')</button>
al@419 647 </form>
pascal@435 648 EOT
pascal@435 649 else
pascal@435 650 cat /etc/hostname
pascal@435 651 fi
pascal@435 652 cat <<EOT
al@419 653 </footer>
al@312 654 </section>
pankso@108 655
al@419 656
al@312 657 <section>
al@443 658 <header id="ifconfig">$(_ 'Output of ifconfig')</header>
al@419 659 <pre>$(ifconfig)</pre>
al@312 660 </section>
pascal@68 661
al@419 662
al@312 663 <section>
al@443 664 <header id="routing">$(_ 'Routing table')</header>
al@419 665 <pre>$(route -n)</pre>
al@312 666 </section>
pascal@131 667
al@419 668
al@312 669 <section>
al@443 670 <header id="dns">$(_ 'Domain name resolution')</header>
al@419 671 <pre>$(cat /etc/resolv.conf)</pre>
al@312 672 </section>
al@303 673
al@419 674
al@312 675 <section>
al@443 676 <header id="arp">$(_ 'ARP table')</header>
al@419 677 <pre>$(arp)</pre>
al@312 678 </section>
al@303 679
al@419 680
al@312 681 <section>
al@443 682 <header id="connections">$(_ 'IP Connections')</header>
al@419 683 <pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
al@419 684 -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
al@312 685 </section>
pankso@38 686 EOT
pankso@38 687 ;;
pankso@38 688 esac
pankso@38 689
pankso@38 690 xhtml_footer
pankso@38 691 exit 0