tazpanel diff network.cgi @ rev 419

Bunch of changes. Development in progress, please note it have few known bugs.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Mar 24 03:39:08 2015 +0200 (2015-03-24)
parents 106b85c1951c
children a279382f786f
line diff
     1.1 --- a/network.cgi	Sat Jan 03 17:11:14 2015 +0200
     1.2 +++ b/network.cgi	Tue Mar 24 03:39:08 2015 +0200
     1.3 @@ -2,125 +2,130 @@
     1.4  #
     1.5  # Network configuration CGI interface
     1.6  #
     1.7 -# Copyright (C) 2012-2014 SliTaz GNU/Linux - BSD License
     1.8 +# Copyright (C) 2012-2015 SliTaz GNU/Linux - BSD License
     1.9  #
    1.10  
    1.11 +
    1.12  # Common functions from libtazpanel
    1.13 +
    1.14  . lib/libtazpanel
    1.15  get_config
    1.16  header
    1.17  
    1.18  TITLE=$(gettext 'TazPanel - Network')
    1.19  
    1.20 -# Catch ESSIDs and format output for GTK tree. We get the list of
    1.21 -# networks by Cell and without spaces.
    1.22 -detect_wifi_networks()
    1.23 -{
    1.24 -	cat << EOT
    1.25 -<table class="zebra outbox">
    1.26 -	<thead>
    1.27 -		<tr>
    1.28 -			<td>$(gettext 'Name')</td>
    1.29 -			<td>$(gettext 'Quality')</td>
    1.30 -			<td>$(gettext 'Encryption')</td>
    1.31 -			<td>$(gettext 'Status')</td>
    1.32 -		</tr>
    1.33 -	</thead>
    1.34 -	<tbody>
    1.35 -EOT
    1.36 -	if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
    1.37 -		ifconfig $WIFI_INTERFACE up
    1.38 -		for i in $(iwlist $WIFI_INTERFACE scan | sed '/Cell /!d;s/.*Cell \([^ ]*\).*/Cell.\1/')
    1.39 -		do
    1.40 -			SCAN=$(iwlist $WIFI_INTERFACE scan last | sed "/$i/,/Cell/!d" | sed '$d')
    1.41 -			ESSID=$(echo $SCAN | sed 's/.*ESSID:"\([^"]*\).*/\1/')
    1.42 -			if echo "$SCAN" | grep -q Quality; then
    1.43 -				QUALITY=$(echo $SCAN | sed '/ *Quality/s/.*Quality[:=]\([^ ]*\).*/\1/')
    1.44 -			else
    1.45 -				QUALITY="-"
    1.46 -			fi
    1.47 -			ENCRYPTION=$(echo $SCAN | sed 's/.*key:\([^ ]*\).*/\1/')
    1.48 -			# Check encryption type
    1.49 -			if echo "$SCAN" | grep -q WPA*; then
    1.50 -				ENCRYPTION="WPA"
    1.51 -			fi
    1.52 -			if echo $SCAN | grep -q 'Mode:Managed'; then
    1.53 -				AP="ap=$(echo $SCAN | sed 's/.*Address: \([^ ]*\).*/\1/')"
    1.54 -			else
    1.55 -				AP=""
    1.56 -			fi
    1.57 -			# Connected or not connected...
    1.58 -			if ifconfig | grep -A 1 $WIFI_INTERFACE | \
    1.59 -				fgrep -q inet && iwconfig $WIFI_INTERFACE | \
    1.60 -				fgrep -q "ESSID:\"$ESSID\""; then
    1.61 -				status=$(gettext 'Connected')
    1.62 -			else
    1.63 -				status="---"
    1.64 -			fi
    1.65 -			echo '<tr>'
    1.66 -			echo "<td><a href=\"?wifi&amp;select=$ESSID&amp;keytype=$ENCRYPTION&amp;$AP\">
    1.67 -				<img src='$IMAGES/wireless.png' />$ESSID</a></td>"
    1.68 -			echo "<td>$QUALITY</td><td>$ENCRYPTION</td><td>$status $ip</td>"
    1.69 -			echo '</tr>'
    1.70 -		done
    1.71 -	fi
    1.72 -	cat << EOT
    1.73 -	</tbody>
    1.74 -</table>
    1.75 -EOT
    1.76 -}
    1.77  
    1.78 -# Start a wifi connection
    1.79 +# Start a Wi-Fi connection
    1.80 +
    1.81  start_wifi() {
    1.82  	sed -i \
    1.83 -		-e s'/^DHCP=.*/DHCP="yes"/' \
    1.84 -		-e s'/^WIFI=.*/WIFI="yes"/' \
    1.85 -		-e s'/^STATIC=.*/STATIC="no"/' /etc/network.conf
    1.86 +		-e 's|^WIFI=.*|WIFI="yes"|' \
    1.87 +		-e 's|^DHCP=.*|DHCP="yes"|' \
    1.88 +		-e 's|^STATIC=.*|STATIC="no"|' /etc/network.conf
    1.89  	ifconfig $WIFI_INTERFACE up
    1.90  	iwconfig $WIFI_INTERFACE txpower auto
    1.91  	/etc/init.d/network.sh restart | log
    1.92 -	sleep 2
    1.93 +	# Sleep until connection established (max 20 seconds)
    1.94 +	for i in $(seq 20); do
    1.95 +		[ -n "$(iwconfig 2>/dev/null | fgrep Link)" ] && break
    1.96 +		sleep 1
    1.97 +	done
    1.98 +}
    1.99 +
   1.100 +
   1.101 +# Use /etc/wpa/wpa.conf as single database for known networks, passwords, etc.
   1.102 +# Translate this data to use in javascript.
   1.103 +
   1.104 +parse_wpa_conf() {
   1.105 +	awk '
   1.106 +	BEGIN { print "networks = ["; begin_list = 1; network = 0; }
   1.107 +	{
   1.108 +		if ($0 == "network={") {
   1.109 +			if (begin_list == 0) print ",";
   1.110 +			begin_list = 0;
   1.111 +			printf "{"; begin_obj = 1;
   1.112 +			network = 1; next;
   1.113 +		}
   1.114 +		if (network == 1) {
   1.115 +			if ($0 ~ "=") {
   1.116 +				if (begin_obj == 0) printf ", ";
   1.117 +				begin_obj = 0;
   1.118 +				split($0, a, "=");
   1.119 +				if (a[2] ~ "\"")
   1.120 +					printf "%s:%s", a[1], a[2];
   1.121 +				else
   1.122 +					printf "%s:\"%s\"", a[1], a[2];
   1.123 +			}
   1.124 +		}
   1.125 +		if (network == 1 && $0 ~ "}") { printf "}"; network = 0; next; }
   1.126 +	}
   1.127 +	END {print "\n];"}
   1.128 +	' /etc/wpa/wpa.conf | sed 's|\t||g;'
   1.129 +}
   1.130 +
   1.131 +
   1.132 +# Waiting for network link up
   1.133 +
   1.134 +wait_up() {
   1.135 +	for i in $(seq 10); do
   1.136 +		[ -z "$(cat /sys/class/net/*/operstate | fgrep up)"] && sleep 1
   1.137 +	done
   1.138  }
   1.139  
   1.140  # Actions commands before page is displayed
   1.141 +
   1.142  case " $(GET) " in
   1.143  	*\ start\ *)
   1.144 +		/etc/init.d/network.sh start | log
   1.145  		# Here we sleep a bit to let udhcp get the lease before reloading
   1.146  		# the page with status
   1.147 -		/etc/init.d/network.sh start | log
   1.148 -		sleep 2 ;;
   1.149 +		wait_up ;;
   1.150  	*\ stop\ *)
   1.151  		/etc/init.d/network.sh stop | log ;;
   1.152  	*\ restart\ *)
   1.153 -		/etc/init.d/network.sh restart | log ;;
   1.154 -	*\ start-wifi\ *) start_wifi ;;
   1.155 -	*\ hostname\ *)
   1.156 -		get_hostname="$(GET hostname)"
   1.157 +		/etc/init.d/network.sh restart | log
   1.158 +		wait_up ;;
   1.159 +	*\ start-wifi\ *)
   1.160 +		start_wifi ;;
   1.161 +	*\ host\ *)
   1.162 +		get_hostname="$(GET host)"
   1.163  		echo $(eval_gettext 'Changed hostname: $get_hostname') | log
   1.164  		echo "$get_hostname" > /etc/hostname ;;
   1.165  esac
   1.166  
   1.167 +
   1.168  # Get values only now since they could have been modified by actions.
   1.169 +
   1.170  . /etc/network.conf
   1.171  
   1.172 +
   1.173 +
   1.174 +
   1.175 +
   1.176  #
   1.177  # Main Commands for pages
   1.178  #
   1.179  
   1.180  case " $(GET) " in
   1.181 +
   1.182  	*\ scan\ *)
   1.183  		# Scan open ports
   1.184 -		scan=$(GET scan)
   1.185 +		scan=$(GET scan); back=$(GET back)
   1.186  		xhtml_header
   1.187 -		LOADING_MSG=$(gettext 'Scanning open ports...')
   1.188 -		loading_msg
   1.189 -		cat << EOT
   1.190 -<h2>$(eval_gettext 'Port scanning for $scan')</h2>
   1.191 +		LOADING_MSG=$(gettext 'Scanning open ports...'); loading_msg
   1.192  
   1.193 -<pre>$(pscan -b $scan)</pre>
   1.194 +		cat <<EOT
   1.195 +<section>
   1.196 +	<header>
   1.197 +		$(eval_gettext 'Port scanning for $scan')
   1.198 +		$(back_button "$back" "$(gettext 'Network')" "")
   1.199 +	</header>
   1.200 +	<pre>$(pscan -b $scan)</pre>
   1.201 +</section>
   1.202  EOT
   1.203  		;;
   1.204  
   1.205 +
   1.206  	*\ eth\ *)
   1.207  		# Wired connections settings
   1.208  		xhtml_header
   1.209 @@ -129,8 +134,8 @@
   1.210  			STATIC=no
   1.211  			[ -n "$(GET dhcp)" ] && DHCP=yes
   1.212  			[ -n "$(GET static)" ] && STATIC=yes
   1.213 -			LOADING_MSG=$(gettext 'Setting up IP...')
   1.214 -			loading_msg
   1.215 +			LOADING_MSG=$(gettext 'Setting up IP...'); loading_msg
   1.216 +
   1.217  			sed -i \
   1.218  				-e s"/^INTERFACE=.*/INTERFACE=\"$(GET iface)\""/ \
   1.219  				-e s"/^DHCP=.*/DHCP=\"$DHCP\"/" \
   1.220 @@ -144,239 +149,475 @@
   1.221  			/etc/init.d/network start | log
   1.222  			. /etc/network.conf
   1.223  		fi
   1.224 -		cat << EOT
   1.225 +
   1.226 +		PAR1="size=\"20\" required"; PAR="$PAR1 pattern=\"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\" data-x=\"Four numbers, each in range 0-255, delimited by full stop.\""
   1.227 +		cat <<EOT
   1.228  <h2>$(gettext 'Ethernet connection')</h2>
   1.229  
   1.230  <p>$(gettext "Here you can configure a wired connection using DHCP to \
   1.231  automatically get a random IP or configure a static/fixed IP")</p>
   1.232  
   1.233  <section>
   1.234 -<h3>$(gettext 'Configuration')</h3>
   1.235 -<form method="get" action="">
   1.236 -	<input type="hidden" name="eth" />
   1.237 -	<table>
   1.238 +	<header>$(gettext 'Configuration')</header>
   1.239 +	<form id="conf">
   1.240 +		<input type="hidden" name="eth"/>
   1.241 +		<div>
   1.242 +			<table>
   1.243 +				<tr><td>$(gettext 'Interface')</td>
   1.244 +					<td><select name="iface" value="$INTERFACE" style="width:100%"/>
   1.245 +					$(cd /sys/class/net; ls -1 | awk -viface="$INTERFACE" '{
   1.246 +						sel = ($0 == iface) ? " selected":""
   1.247 +						printf "<option value=\"%s\"%s>%s", $0, sel, $0
   1.248 +					}')
   1.249 +					</select></td>
   1.250 +				</tr>
   1.251 +				<tr><td>&nbsp;</td>
   1.252 +					<td><label><input type="checkbox" name="staticip" id="staticip"/>
   1.253 +						$(gettext 'Use static IP')</td>
   1.254 +				<tr><td>$(gettext 'IP address')</td>
   1.255 +					<td><input type="text" name="ip"      id="st1" value="$IP"         $PAR/></td>
   1.256 +				</tr>
   1.257 +				<tr><td>$(gettext 'Netmask')</td>
   1.258 +					<td><input type="text" name="netmask" id="st2" value="$NETMASK"    $PAR/></td>
   1.259 +				</tr>
   1.260 +				<tr><td>$(gettext 'Gateway')</td>
   1.261 +					<td><input type="text" name="gateway" id="st3" value="$GATEWAY"    $PAR/></td>
   1.262 +				</tr>
   1.263 +				<tr><td>$(gettext 'DNS server')</td>
   1.264 +					<td><input type="text" name="dns"     id="st4" value="$DNS_SERVER" $PAR/></td>
   1.265 +				</tr>
   1.266 +			</table>
   1.267 +		</div>
   1.268 +	</form>
   1.269 +	<footer><!--
   1.270 +		--><button form="conf" type="submit" name="static"  data-icon="ok"    >$(gettext 'Activate (static)')</button><!--
   1.271 +		--><button form="conf" type="submit" name="dhcp"    data-icon="ok"    >$(gettext 'Activate (DHCP)'  )</button><!--
   1.272 +		--><button form="conf" name="disable" data-icon="cancel">$(gettext 'Disable'          )</button><!--
   1.273 +	--></footer>
   1.274 +</section>
   1.275 +
   1.276 +<script type="text/javascript">
   1.277 +	document.getElementById('staticip').onchange = static_change;
   1.278 +
   1.279 +	function static_change() {
   1.280 +		staticip = document.getElementById('staticip');
   1.281 +		alert(staticip.checked);
   1.282 +	}
   1.283 +</script>
   1.284 +
   1.285 +<section>
   1.286 +	<header>
   1.287 +		$(gettext 'Configuration file')
   1.288 +		<form action="index.cgi">
   1.289 +			<input type="hidden" name="file" value="/etc/network.conf"/>
   1.290 +			<button name="action" value="edit" data-icon="edit">$(gettext 'Edit')</button>
   1.291 +		</form>
   1.292 +	</header>
   1.293 +	<div>$(gettext "These values are the ethernet settings in the main /etc/network.conf configuration file")</div>
   1.294 +	<pre>$(awk '{if($1 !~ "WIFI" && $1 !~ "#" && $1 != ""){print $0}}' /etc/network.conf | syntax_highlighter conf)</pre>
   1.295 +</section>
   1.296 +EOT
   1.297 +		;;
   1.298 +
   1.299 +
   1.300 +
   1.301 +	*\ wifi_list\ *)
   1.302 +		# Catch ESSIDs and format output.
   1.303 +		# We get the list of networks by Cell and without spaces.
   1.304 +
   1.305 +		HIDDEN="$(gettext '(hidden)')"
   1.306 +
   1.307 +		cat <<EOT
   1.308 +<table class="wide center zebra">
   1.309  	<thead>
   1.310  		<tr>
   1.311  			<td>$(gettext 'Name')</td>
   1.312 -			<td>$(gettext 'Value')</td>
   1.313 +			<td>$(gettext 'Signal level')</td>
   1.314 +			<td>$(gettext 'Channel')</td>
   1.315 +			<td>$(gettext 'Encryption')</td>
   1.316 +			<td>$(gettext 'Status')</td>
   1.317  		</tr>
   1.318  	</thead>
   1.319  	<tbody>
   1.320 -	<tr>
   1.321 -		<td>$(gettext 'Interface')</td>
   1.322 -		<td><input type="text" name="iface" size="20" value="$INTERFACE" /></td>
   1.323 -	</tr>
   1.324 -	<tr>
   1.325 -		<td>$(gettext 'IP address')</td>
   1.326 -		<td><input type="text" name="ip" size="20" value="$IP" /></td>
   1.327 -	</tr>
   1.328 -	<tr>
   1.329 -		<td>$(gettext 'Netmask')</td>
   1.330 -		<td><input type="text" name="netmask" size="20" value="$NETMASK" /></td>
   1.331 -	</tr>
   1.332 -	<tr>
   1.333 -		<td>$(gettext 'Gateway')</td>
   1.334 -		<td><input type="text" name="gateway" size="20" value="$GATEWAY" /></td>
   1.335 -	</tr>
   1.336 -	<tr>
   1.337 -		<td>$(gettext 'DNS server')</td>
   1.338 -		<td><input type="text" name="dns" size="20" value="$DNS_SERVER" /></td>
   1.339 -	</tr>
   1.340 +EOT
   1.341 +		if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
   1.342 +			ifconfig $WIFI_INTERFACE up
   1.343 +			for i in $(iwlist $WIFI_INTERFACE scan | sed '/Cell /!d;s/.*Cell \([^ ]*\).*/Cell.\1/')
   1.344 +			do
   1.345 +				SCAN=$(iwlist $WIFI_INTERFACE scan last | sed "/$i/,/Cell/!d" | sed '$d')
   1.346 +
   1.347 +				BSSID=$(echo "$SCAN" | sed -n 's|.*Address: \([^ ]*\).*|\1|p')
   1.348 +
   1.349 +				CHANNEL=$(echo "$SCAN" | sed -n 's|.*Channel[:=]\([^ ]*\).*|\1|p')
   1.350 +
   1.351 +				QUALITY=$(echo "$SCAN" | sed -n 's|.*Quality[:=]\([^ ]*\).*|\1|p')
   1.352 +				QUALITY_ICON="lvl$(( 5*${QUALITY:-0} ))"		# lvl0 .. lvl4, lvl5
   1.353 +				LEVEL=$(echo "$SCAN" | sed -n 's|.*Signal level[:=]\([^ ]*\).*|\1|p; s|-|−|')
   1.354 +
   1.355 +				ENCRYPTION=$(echo "$SCAN" | sed -n 's|.*Encryption key[:=]\([^ ]*\).*|\1|p')		# on/off
   1.356 +
   1.357 +				ESSID=$(echo "$SCAN" | sed -n 's|.*ESSID:"\([^"]*\).*|\1|p')
   1.358 +
   1.359 +				# WPA Type - Group Cipher - Pairwise Ciphers - Authentication Suites
   1.360 +				# {WPA|WPA2}-{TKIP|CCMP}-{TKIP|CCMP|TKIP CCMP}-{PSK|802.1x}
   1.361 +				#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|-$||')"
   1.362 +
   1.363 +				# Authentication type
   1.364 +				AUTH="$(echo "$SCAN" | sed -n 's|.*Authentication Suites[^:]*: *\(.*\)|\1|p')"
   1.365 +				if [ -n "$(echo -n $AUTH | fgrep PSK)" ]; then
   1.366 +					# WPA-Personal. Authentication using password (PSK = pre-shared key)
   1.367 +					WIFI_KEY_TYPE='WPA'
   1.368 +				elif [ -n "$(echo -n $AUTH | fgrep 802.1x)" ]; then
   1.369 +					# WPA-Enterprise. Authentication using username, password, certificates...
   1.370 +					WIFI_KEY_TYPE='EAP'
   1.371 +				else
   1.372 +					WIFI_KEY_TYPE='NONE'
   1.373 +				fi
   1.374 +
   1.375 +				# Check encryption type
   1.376 +				if [ "$ENCRYPTION" == 'on' ]; then
   1.377 +					# "WPA" or "WPA2" or "WPA/WPA2" (maybe also "WPA2/WPA")
   1.378 +					ENC_SIMPLE=$(echo "$SCAN" | sed -n '/.*WPA.*/ s|.*\(WPA[^ ]*\).*|\1|p')
   1.379 +					ENC_SIMPLE=$(echo $ENC_SIMPLE | sed 's| |/|')
   1.380 +					ENC_ICON='sechi' # high
   1.381 +					if [ -z "$ENC_SIMPLE" ]; then
   1.382 +						WIFI_KEY_TYPE='WEP'
   1.383 +						ENC_SIMPLE='WEP'; ENC_ICON='secmi' # middle
   1.384 +					fi
   1.385 +				else
   1.386 +					WIFI_KEY_TYPE='NONE'
   1.387 +					ENC_SIMPLE="$(gettext 'None')"; ENC_ICON='seclo' # low
   1.388 +				fi
   1.389 +
   1.390 +				# 
   1.391 +				#if echo $SCAN | grep -q 'Mode:Managed'; then
   1.392 +				#	AP="&amp;ap=$(echo $SCAN | sed 's/.*Address: \([^ ]*\).*/\1/')"
   1.393 +				#else
   1.394 +				#	AP=''
   1.395 +				#fi
   1.396 +
   1.397 +				# Connected or not connected...
   1.398 +				if  ifconfig $WIFI_INTERFACE | fgrep -q inet && \
   1.399 +					iwconfig $WIFI_INTERFACE | fgrep -q "ESSID:\"$ESSID\""; then
   1.400 +					status="$(gettext 'Connected')"
   1.401 +				else
   1.402 +					status='---'
   1.403 +				fi
   1.404 +
   1.405 +				cat <<EOT
   1.406 +<tr>
   1.407 +	<td><a data-icon="wifi" onclick="loadcfg('$ESSID', '$BSSID', '$WIFI_KEY_TYPE')">${ESSID:-$HIDDEN}</a></td>
   1.408 +	<td><span data-icon="$QUALITY_ICON" title="Quality: $QUALITY"> $LEVEL dBm</span></td>
   1.409 +	<td>$CHANNEL</td>
   1.410 +	<td><span data-icon="$ENC_ICON">$ENC_SIMPLE</span></td>
   1.411 +	<td>$status</td>
   1.412 +</tr>
   1.413 +EOT
   1.414 +			done
   1.415 +		fi
   1.416 +		cat <<EOT
   1.417  	</tbody>
   1.418 -	</table>
   1.419 -		<input type="submit" name="static" value="$(gettext 'Activate (static)')">
   1.420 -		<input type="submit" name="dhcp" value="$(gettext 'Activate (DHCP)')">
   1.421 -		<input type="submit" name="disable" value="$(gettext 'Disable')">
   1.422 +</table>
   1.423 +EOT
   1.424 +		exit 0
   1.425 +		;;
   1.426 +
   1.427 +
   1.428 +	*\ wifi\ *)
   1.429 +		# Wireless connections settings
   1.430 +		xhtml_header
   1.431 +
   1.432 +		. /etc/network.conf
   1.433 +		cat <<EOT
   1.434 +<h2>$(gettext 'Wireless connection')</h2>
   1.435 +
   1.436 +<form>
   1.437 +	<input type="hidden" name="wifi"/>
   1.438 +EOT
   1.439 +
   1.440 +		start_disabled=''; stop_disabled=''
   1.441 +		if iwconfig 2>/dev/null | grep -q 'Tx-Power=off'; then
   1.442 +			stop_disabled='disabled'
   1.443 +		else
   1.444 +			start_disabled='disabled'
   1.445 +		fi
   1.446 +
   1.447 +		cat <<EOT
   1.448 +	   <button name="start-wifi" data-icon="start"   $start_disabled>$(gettext 'Start')</button><!--
   1.449 +	--><button name="stop"       data-icon="stop"    $stop_disabled >$(gettext 'Stop' )</button><!--
   1.450 +	--><button type="submit"     data-icon="refresh" $stop_disabled >$(gettext 'Scan' )</button>
   1.451  </form>
   1.452 +EOT
   1.453 +
   1.454 +		if [ -n "$start_disabled" ]; then
   1.455 +			cat <<EOT
   1.456 +<section id="wifiList">
   1.457 +	<div style="text-align: center;"><span id="ajaxStatus"></span>$(gettext 'Scanning wireless interface...')</div>
   1.458  </section>
   1.459  
   1.460 +<script type="text/javascript">
   1.461 +	ajax('/network.cgi?wifi_list', '1', 'wifiList');
   1.462 +	$(parse_wpa_conf)
   1.463 +</script>
   1.464 +EOT
   1.465 +
   1.466 +			ESSID="$(GET essid)"
   1.467 +			#WIFI_KEY_TYPE="$(GET keyType)"
   1.468 +			#WIFI_KEY="$(GET key)"
   1.469 +			#WIFI_AP="$(GET ap)"
   1.470 +
   1.471 +			if [ -n "$ESSID" ]; then
   1.472 +				/etc/init.d/network.sh stop | log
   1.473 +				sed -i \
   1.474 +					-e "s/^WIFI_ESSID=.*/WIFI_ESSID=\"$essid\"/" \
   1.475 +					-e "s/^WIFI_KEY_TYPE=.*/WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"/" \
   1.476 +					-e "s/^WIFI_KEY=.*/WIFI_KEY=\"$WIFI_KEY\"/" \
   1.477 +					-e "s/^WIFI_AP=.*/WIFI_AP=\"$WIFI_AP\"/" \
   1.478 +					/etc/network.conf
   1.479 +				. /etc/network.conf
   1.480 +				start_wifi
   1.481 +			fi
   1.482 +
   1.483 +			# ESSID names are clickable
   1.484 +			#SELECT="$(GET select)"
   1.485 +			#if [ -n "$SELECT" ]; then
   1.486 +			#	[ "$SELECT" != "$WIFI_ESSID" ] && WIFI_KEY=''
   1.487 +			#	WIFI_ESSID="$SELECT"
   1.488 +			#fi
   1.489 +
   1.490 +			cat <<EOT
   1.491  <section>
   1.492 -<h3>$(gettext 'Configuration file')</h3>
   1.493 +	<header>$(gettext 'Connection')</header>
   1.494 +	<div>
   1.495 +		<form id="connection">
   1.496 +			<input type="hidden" name="connect-wifi"/>
   1.497 +			<table>
   1.498 +				<tr><td>$(gettext 'Network SSID')</td>
   1.499 +					<td><input type="text" name="essid" value="$WIFI_ESSID" id="essid"/></td>
   1.500 +				</tr>
   1.501  
   1.502 -<p>$(gettext "These values are the ethernet settings in the main \
   1.503 -/etc/network.conf configuration file")</p>
   1.504 -<pre>
   1.505 -$(grep ^[A-V] /etc/network.conf | syntax_highlighter conf)
   1.506 -</pre>
   1.507 -<a class="button" href="index.cgi?file=/etc/network.conf&amp;action=edit">
   1.508 -	<img src="$IMAGES/edit.png" />$(gettext 'Manual Edit')</a>
   1.509 +				<tr><td>$(gettext 'Security')</td>
   1.510 +					<td><select name="keyType" id="keyType">
   1.511 +							<option value="NONE">$(gettext 'None')</option>
   1.512 +							<option value="WEP" >WEP</option>
   1.513 +							<option value="WPA" >WPA/WPA2 PSK</option>
   1.514 +							<option value="EAP" >802.1x EAP</option>
   1.515 +						</select>
   1.516 +					</td>
   1.517 +				</tr>
   1.518 +
   1.519 +				<tr class="eap">
   1.520 +					<td><div>$(gettext 'EAP method')</div></td>
   1.521 +					<td><div><select name="eap" id="eap">
   1.522 +							<option value="PEAP">PEAP</option>
   1.523 +							<option value="TLS" >TLS</option>
   1.524 +							<option value="TTLS">TTLS</option>
   1.525 +							<option value="PWD" >PWD</option>
   1.526 +						</select>
   1.527 +					</div></td>
   1.528 +				</tr>
   1.529 +
   1.530 +				<tr class="eap1">
   1.531 +					<td><div>$(gettext 'Phase 2 authentication')</div></td>
   1.532 +					<td><div><select name="phase2" id="phase2">
   1.533 +							<option value="none"    >$(gettext 'None')</option>
   1.534 +							<option value="pap"     >PAP</option>
   1.535 +							<option value="mschap"  >MSCHAP</option>
   1.536 +							<option value="mschapv2">MSCHAPV2</option>
   1.537 +							<option value="gtc"     >GTC</option>
   1.538 +						</select>
   1.539 +					</div></td>
   1.540 +				</tr>
   1.541 +
   1.542 +				<tr class="eap1">
   1.543 +					<td><div>$(gettext 'CA certificate')</div></td>
   1.544 +					<td><div><input type="text" name="caCert" id="caCert"></div></td>
   1.545 +				</tr>
   1.546 +
   1.547 +				<tr class="eap1">
   1.548 +					<td><div>$(gettext 'User certificate')</div></td>
   1.549 +					<td><div><input type="text" name="clientCert" id="clientCert"></div></td>
   1.550 +				</tr>
   1.551 +
   1.552 +				<tr class="eap">
   1.553 +					<td><div>$(gettext 'Identity')</div></td>
   1.554 +					<td><div><input type="text" name="identity" id="identity"></div></td>
   1.555 +				</tr>
   1.556 +
   1.557 +				<tr class="eap1">
   1.558 +					<td><div>$(gettext 'Anonymous identity')</div></td>
   1.559 +					<td><div><input type="text" name="anonymousIdentity" id="anonymousIdentity"></div></td>
   1.560 +				</tr>
   1.561 +
   1.562 +				<tr class="wep wpa eap">
   1.563 +					<td><div>$(gettext 'Password')</div></td>
   1.564 +					<td><div>
   1.565 +						<input type="password" name="password" value="$WIFI_KEY" id="password"/>
   1.566 +						<span data-img="view" title="$(gettext 'Show password')"
   1.567 +							onmousedown="document.getElementById('password').type='text'; return false"
   1.568 +							  onmouseup="document.getElementById('password').type='password'"
   1.569 +							 onmouseout="document.getElementById('password').type='password'"
   1.570 +						></span>
   1.571 +					</div></td>
   1.572 +				</tr>
   1.573 +
   1.574 +
   1.575 +<!--
   1.576 +				<tr><td>$(gettext 'Access point')</td>
   1.577 +					<td><input type="text" name="ap" value="$WIFI_AP"/></td>
   1.578 +				</tr>
   1.579 +-->
   1.580 +
   1.581 +				<script type="text/javascript">
   1.582 +function wifiSettingsChange() {
   1.583 +	document.getElementById('connection').className = 
   1.584 +		document.getElementById('keyType').value.toLowerCase() + ' ' + 
   1.585 +		document.getElementById('eap').value.toLowerCase();
   1.586 +}
   1.587 +document.getElementById('keyType').onchange = wifiSettingsChange;
   1.588 +document.getElementById('eap').onchange = wifiSettingsChange;
   1.589 +
   1.590 +document.getElementById('keyType').value = "$WIFI_KEY_TYPE"; wifiSettingsChange();
   1.591 +				</script>
   1.592 +
   1.593 +				<style type="text/css">
   1.594 +#connection input[type="text"], #connection input[type="password"] { width: 14rem; }
   1.595 +#connection select { width: 14.4rem; }
   1.596 +
   1.597 +#connection td { padding: 0; margin: 0; }
   1.598 +#connection [class] div {
   1.599 +	max-height: 0; overflow: hidden; padding: 0; margin: 0;
   1.600 +	-webkit-transition: all 0.5s ease-in-out;
   1.601 +	   -moz-transition: all 0.5s ease-in-out;
   1.602 +	        transition: all 0.5s ease-in-out;
   1.603 +}
   1.604 +.wep .wep div, .wpa .wpa div, .eap .eap div,
   1.605 +.eap.peap .eap1 div, .eap.tls .eap1 div, .eap.ttls .eap1 div {
   1.606 +	max-height: 2em !important;
   1.607 +}
   1.608 +				</style>
   1.609 +
   1.610 +			</table>
   1.611 +		</form>
   1.612 +	</div>
   1.613 +	<footer>
   1.614 +		<button form="connection" type="submit" name="wifi" data-icon="ok">$(gettext 'Configure')</button>
   1.615 +	</footer>
   1.616 +</section>
   1.617 +EOT
   1.618 +		fi
   1.619 +
   1.620 +		cat <<EOT
   1.621 +<section>
   1.622 +	<header>
   1.623 +		$(gettext 'Configuration file')
   1.624 +		<form action="index.cgi">
   1.625 +			<input type="hidden" name="file" value="/etc/network.conf"/>
   1.626 +			<button name="action" value="edit" data-icon="edit">$(gettext 'Edit')</button>
   1.627 +		</form>
   1.628 +	</header>
   1.629 +	<div>$(gettext "These values are the wifi settings in the main /etc/network.conf configuration file")</div>
   1.630 +	<pre>$(grep ^WIFI /etc/network.conf | sed '/WIFI_KEY=/s|".*"|"********"|' | syntax_highlighter conf)</pre>
   1.631 +</section>
   1.632 +
   1.633 +
   1.634 +<section>
   1.635 +	<header>$(gettext 'Output of iwconfig')</header>
   1.636 +	<pre>$(iwconfig)</pre>
   1.637  </section>
   1.638  EOT
   1.639  		;;
   1.640 -	*\ wifi\ *)
   1.641 -		# Wireless connections settings
   1.642 -		xhtml_header
   1.643 -		LOADING_MSG=$(gettext 'Scanning wireless interface...')
   1.644 -		loading_msg
   1.645 -		. /etc/network.conf
   1.646 -		cat << EOT
   1.647 -<h2>$(gettext 'Wireless connection')</h2>
   1.648 -<div id="actions">
   1.649 -	<a class="button" href="?wifi&amp;start-wifi=start-wifi">
   1.650 -		<img src="$IMAGES/start.png" />$(gettext 'Start')</a>
   1.651 -	<a class="button" href="?wifi&amp;stop=stop">
   1.652 -		<img src="$IMAGES/stop.png" />$(gettext 'Stop')</a>
   1.653 -	<a class="button" href="?wifi=scan">
   1.654 -		<img src="$IMAGES/recharge.png" />$(gettext 'Scan')</a>
   1.655 -</div>
   1.656 -$(detect_wifi_networks)
   1.657 -EOT
   1.658 -		WIFI_AP="$(GET ap)"
   1.659 -		WIFI_KEY="$(GET key)"
   1.660 -		case "$(GET keytype)" in
   1.661 -		''|off)	WIFI_KEY_TYPE=none ;;
   1.662 -		*)	WIFI_KEY_TYPE=any  ;;
   1.663 -		esac
   1.664 -		if [ "$(GET essid)" ]; then
   1.665 -			/etc/init.d/network.sh stop | log
   1.666 -			sed -i \
   1.667 -				-e s"/^WIFI_ESSID=.*/WIFI_ESSID=\"$(GET essid)\""/ \
   1.668 -				-e s"/^WIFI_KEY=.*/WIFI_KEY=\"$WIFI_KEY\"/" \
   1.669 -				-e s"/^WIFI_KEY_TYPE=.*/WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"/" \
   1.670 -				-e s"/^WIFI_AP=.*/WIFI_AP=\"$WIFI_AP\"/" \
   1.671 -				/etc/network.conf
   1.672 -			. /etc/network.conf
   1.673 -			start_wifi
   1.674 -		fi
   1.675 -		# ESSID names are clickable
   1.676 -		if [ "$(GET select)" ]; then
   1.677 -			if [ "$(GET select)" != "$WIFI_ESSID" ]; then
   1.678 -				WIFI_KEY=""
   1.679 -			fi
   1.680 -			WIFI_ESSID="$(GET select)"
   1.681 -		fi
   1.682 -	cat << EOT
   1.683 -<section>
   1.684 -<h3>$(gettext 'Connection')</h3>
   1.685 -<form method="get" action="">
   1.686 -	<input type="hidden" name="connect-wifi" />
   1.687 -	$(table_start)
   1.688 -	<thead>
   1.689 -		<tr>
   1.690 -			<td>$(gettext 'Name')</td>
   1.691 -			<td>$(gettext 'Value')</td>
   1.692 -		</tr>
   1.693 -	</thead>
   1.694 -	<tr>
   1.695 -		<td>$(gettext 'Wifi name (ESSID)')</td>
   1.696 -		<td><input type="text" name="essid" size="30" value="$WIFI_ESSID" /></td>
   1.697 -	</tr>
   1.698 -	<tr>
   1.699 -		<td>$(gettext 'Password (Wifi key)')</td>
   1.700 -		<td><input type="password" name="key" size="30" value="$WIFI_KEY" /></td>
   1.701 -	</tr>
   1.702 -	<tr>
   1.703 -		<td>$(gettext 'Encryption type')</td>
   1.704 -		<td><input type="text" name="keytype" size="30" value="$WIFI_KEY_TYPE" /></td>
   1.705 -	</tr>
   1.706 -	<tr>
   1.707 -		<td>$(gettext 'Access point')</td>
   1.708 -		<td><input type="text" name="ap" size="30" value="$WIFI_AP" /></td>
   1.709 -	</tr>
   1.710 -	$(table_end)
   1.711 -		<input type="submit" name="wifi" value="$(gettext 'Configure')" />
   1.712 -</form>
   1.713 -</section>
   1.714  
   1.715 -<section>
   1.716 -<h3>$(gettext 'Configuration file')</h3>
   1.717  
   1.718 -<p>$(gettext "These values are the wifi settings in the main /etc/network.conf \
   1.719 -configuration file")</p>
   1.720 -
   1.721 -<pre>$(grep ^WIFI /etc/network.conf | sed '/WIFI_KEY=/s|".*"|"********"|' | \
   1.722 -syntax_highlighter conf)</pre>
   1.723 -
   1.724 -<a class="button" href="index.cgi?file=/etc/network.conf&amp;action=edit">
   1.725 -	<img src="$IMAGES/edit.png" />$(gettext 'Manual Edit')</a>
   1.726 -</section>
   1.727 -
   1.728 -<section>
   1.729 -<h3>$(gettext 'Output of iwconfig')</h3>
   1.730 -
   1.731 -<pre>$(iwconfig)</pre>
   1.732 -</section>
   1.733 -EOT
   1.734 -		;;
   1.735  	*)
   1.736  		# Main Network page starting with a summary
   1.737  		xhtml_header
   1.738 -		hostname=$(cat /etc/hostname)
   1.739 -		cat << EOT
   1.740 +
   1.741 +		stop_disabled=''; start_disabled=''
   1.742 +		if cat /sys/class/net/*/operstate | fgrep -q up; then
   1.743 +			start_disabled='disabled'
   1.744 +		else
   1.745 +			stop_disabled='disabled'
   1.746 +		fi
   1.747 +
   1.748 +		cat <<EOT
   1.749  <h2>$(gettext 'Networking')</h2>
   1.750  
   1.751  <p>$(gettext 'Manage network connections and services')</p>
   1.752  
   1.753 -<section>
   1.754 -<div id="actions">
   1.755 -	<div class="float-left">
   1.756 -		<a class="button" href="?start">
   1.757 -			<img src="$IMAGES/start.png" />$(gettext 'Start')</a>
   1.758 -		<a class="button" href="?stop">
   1.759 -			<img src="$IMAGES/stop.png" />$(gettext 'Stop')</a>
   1.760 -		<a class="button" href="?restart">
   1.761 -			<img src="$IMAGES/recharge.png" />$(gettext 'Restart')</a>
   1.762 -	</div>
   1.763 -	<div class="float-right">
   1.764 -		$(gettext 'Configuration:')
   1.765 -		<a class="button" href="index.cgi?file=/etc/network.conf">network.conf</a>
   1.766 -		<a class="button" href="?eth">Ethernet</a>
   1.767 -		<a class="button" href="?wifi">Wireless</a>
   1.768 -	</div>
   1.769 +<form action="index.cgi" id="indexform"></form>
   1.770 +
   1.771 +<form id="mainform"><!--
   1.772 +	--><button name="start"   data-icon="start"   $start_disabled>$(gettext 'Start'  )</button><!--
   1.773 +	--><button name="stop"    data-icon="stop"    $stop_disabled >$(gettext 'Stop'   )</button><!--
   1.774 +	--><button name="restart" data-icon="restart" $stop_disabled >$(gettext 'Restart')</button>
   1.775 +</form>
   1.776 +<div class="float-right"><!--
   1.777 +	-->$(gettext 'Configuration:')<!--
   1.778 +	--><button form="indexform" name="file" value="/etc/network.conf" data-icon="conf">network.conf</button><!--
   1.779 +	--><button form="mainform" name="eth" data-icon="eth">Ethernet</button><!--
   1.780 +	--><button form="mainform" name="wifi" data-icon="wifi">Wireless</button>
   1.781  </div>
   1.782  
   1.783 -$(list_network_interfaces)
   1.784 +
   1.785 +<section>
   1.786 +	<header>$(gettext 'Network interfaces')</header>
   1.787 +	$(list_network_interfaces)
   1.788  </section>
   1.789  
   1.790 +
   1.791  <section>
   1.792 -<h3 id="hosts">$(gettext 'Hosts')</h3>
   1.793 -
   1.794 -<pre>$(cat /etc/hosts)</pre>
   1.795 -
   1.796 -<a class="button" href="index.cgi?file=/etc/hosts&amp;action=edit">
   1.797 -	<img src="$IMAGES/edit.png" />$(gettext 'Edit hosts')</a>
   1.798 +	<header id="hosts">$(gettext 'Hosts')</header>
   1.799 +	<pre>$(cat /etc/hosts)</pre>
   1.800 +	<footer>
   1.801 +		<form action="index.cgi">
   1.802 +			<input type="hidden" name="file" value="/etc/hosts"/>
   1.803 +			<button name="action" value="edit" data-icon="edit">$(gettext 'Edit')</button>
   1.804 +		</form>
   1.805 +	</footer>
   1.806  </section>
   1.807  
   1.808 +
   1.809  <section>
   1.810 -<h3>$(gettext 'Hostname')</h3>
   1.811 -
   1.812 -<form method="get" name="">
   1.813 -	<input type="text" name="hostname" value="$hostname" />
   1.814 -	<input type="submit" value="$(gettext 'Change hostname')" />
   1.815 -</form>
   1.816 +	<header>$(gettext 'Hostname')</header>
   1.817 +	<footer>
   1.818 +		<form>
   1.819 +			<!-- was: name="hostname"; please don't use 'name' in name: unwanted webkit styling -->
   1.820 +			<input type="text" name="host" value="$(cat /etc/hostname)"/><!--
   1.821 +			--><button type="submit" data-icon="ok">$(gettext 'Change')</button>
   1.822 +		</form>
   1.823 +	</footer>
   1.824  </section>
   1.825  
   1.826 +
   1.827  <section>
   1.828 -<h3 id="ifconfig">$(gettext 'Output of ifconfig')</h3>
   1.829 -
   1.830 -<pre>$(ifconfig)</pre>
   1.831 +	<header id="ifconfig">$(gettext 'Output of ifconfig')</header>
   1.832 +	<pre>$(ifconfig)</pre>
   1.833  </section>
   1.834  
   1.835 +
   1.836  <section>
   1.837 -<h3 id="routing">$(gettext 'Routing table')</h3>
   1.838 -
   1.839 -<pre>$(route -n)</pre>
   1.840 +	<header id="routing">$(gettext 'Routing table')</header>
   1.841 +	<pre>$(route -n)</pre>
   1.842  </section>
   1.843  
   1.844 +
   1.845  <section>
   1.846 -<h3 id="dns">$(gettext 'Domain name resolution')</h3>
   1.847 -
   1.848 -<pre>$(cat /etc/resolv.conf)</pre>
   1.849 +	<header id="dns">$(gettext 'Domain name resolution')</header>
   1.850 +	<pre>$(cat /etc/resolv.conf)</pre>
   1.851  </section>
   1.852  
   1.853 +
   1.854  <section>
   1.855 -<h3 id="arp">$(gettext 'ARP table')</h3>
   1.856 -
   1.857 -<pre>$(arp)</pre>
   1.858 +	<header id="arp">$(gettext 'ARP table')</header>
   1.859 +	<pre>$(arp)</pre>
   1.860  </section>
   1.861  
   1.862 +
   1.863  <section>
   1.864 -<h3 id="connections">$(gettext 'IP Connections')</h3>
   1.865 -
   1.866 -<pre>
   1.867 -$(netstat -anp 2> /dev/null | sed -e '/UNIX domain sockets/,$d' \
   1.868 --e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')
   1.869 -</pre>
   1.870 +	<header id="connections">$(gettext 'IP Connections')</header>
   1.871 +	<pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
   1.872 +-e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
   1.873  </section>
   1.874  EOT
   1.875  		;;