tazpanel diff network.cgi @ rev 432

libtazpanel: fix keymap list
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Apr 06 17:22:23 2015 +0200 (2015-04-06)
parents 299f204b8f1f
children a686450b8e9e
line diff
     1.1 --- a/network.cgi	Tue Mar 24 03:39:08 2015 +0200
     1.2 +++ b/network.cgi	Mon Apr 06 17:22:23 2015 +0200
     1.3 @@ -33,6 +33,51 @@
     1.4  }
     1.5  
     1.6  
     1.7 +# Connect to a Wi-Fi network
     1.8 +connect_wifi() {
     1.9 +	/etc/init.d/network.sh stop | log
    1.10 +	sed -i \
    1.11 +		-e "s|^WIFI_ESSID=.*|WIFI_ESSID=\"$(GET essid)\"|" \
    1.12 +		-e "s|^WIFI_BSSID=.*|WIFI_BSSID=\"$(GET bssid)\"|" \
    1.13 +		-e "s|^WIFI_KEY_TYPE=.*|WIFI_KEY_TYPE=\"$(GET keyType)\"|" \
    1.14 +		-e "s|^WIFI_KEY=.*|WIFI_KEY=\"$(GET password)\"|" \
    1.15 +		-e "s|^WIFI_EAP_METHOD=.*|WIFI_EAP_METHOD=\"$(GET eap)\"|" \
    1.16 +		-e "s|^WIFI_CA_CERT=.*|WIFI_CA_CERT=\"$(GET caCert)\"|" \
    1.17 +		-e "s|^WIFI_CLIENT_CERT=.*|WIFI_CLIENT_CERT=\"$(GET clientCert)\"|" \
    1.18 +		-e "s|^WIFI_IDENTITY=.*|WIFI_IDENTITY=\"$(GET identity)\"|" \
    1.19 +		-e "s|^WIFI_ANONYMOUS_IDENTITY=.*|WIFI_ANONYMOUS_IDENTITY=\"$(GET anonymousIdentity)\"|" \
    1.20 +		-e "s|^WIFI_PHASE2=.*|WIFI_PHASE2=\"$(GET phase2)\"|" \
    1.21 +		/etc/network.conf
    1.22 +	. /etc/network.conf
    1.23 +	start_wifi
    1.24 +}
    1.25 +
    1.26 +
    1.27 +# Start an Ethernet connection
    1.28 +
    1.29 +start_eth() {
    1.30 +	case "$(GET staticip)" in
    1.31 +		on) DHCP='no';  STATIC='yes';;
    1.32 +		*)  DHCP='yes'; STATIC='no';;
    1.33 +	esac
    1.34 +
    1.35 +	/etc/init.d/network.sh stop | log
    1.36 +	sleep 2
    1.37 +	sed -i \
    1.38 +		-e "s|^INTERFACE=.*|INTERFACE=\"$(GET iface)\"|" \
    1.39 +		-e 's|^WIFI=.*|WIFI="no"|' \
    1.40 +		-e "s|^DHCP=.*|DHCP=\"$DHCP\"|" \
    1.41 +		-e "s|^STATIC=.*|STATIC=\"$STATIC\"|" \
    1.42 +		-e "s|^IP=.*|IP=\"$(GET ip)\"|" \
    1.43 +		-e "s|^NETMASK=.*|NETMASK=\"$(GET netmask)\"|" \
    1.44 +		-e "s|^GATEWAY=.*|GATEWAY=\"$(GET gateway)\"|" \
    1.45 +		-e "s|^DNS_SERVER=.*|DNS_SERVER=\"$(GET dns)\"|" \
    1.46 +		/etc/network.conf
    1.47 +	/etc/init.d/network.sh start | log
    1.48 +	. /etc/network.conf
    1.49 +}
    1.50 +
    1.51 +
    1.52  # Use /etc/wpa/wpa.conf as single database for known networks, passwords, etc.
    1.53  # Translate this data to use in javascript.
    1.54  
    1.55 @@ -85,8 +130,12 @@
    1.56  	*\ restart\ *)
    1.57  		/etc/init.d/network.sh restart | log
    1.58  		wait_up ;;
    1.59 -	*\ start-wifi\ *)
    1.60 +	*\ start_wifi\ *)
    1.61  		start_wifi ;;
    1.62 +	*\ start_eth\ *)
    1.63 +		start_eth ;;
    1.64 +	*\ connect_wifi\ *)
    1.65 +		connect_wifi ;;
    1.66  	*\ host\ *)
    1.67  		get_hostname="$(GET host)"
    1.68  		echo $(eval_gettext 'Changed hostname: $get_hostname') | log
    1.69 @@ -129,28 +178,21 @@
    1.70  	*\ eth\ *)
    1.71  		# Wired connections settings
    1.72  		xhtml_header
    1.73 -		if [ "$(GET ip)" ]; then
    1.74 -			DHCP=no
    1.75 -			STATIC=no
    1.76 -			[ -n "$(GET dhcp)" ] && DHCP=yes
    1.77 -			[ -n "$(GET static)" ] && STATIC=yes
    1.78 -			LOADING_MSG=$(gettext 'Setting up IP...'); loading_msg
    1.79  
    1.80 -			sed -i \
    1.81 -				-e s"/^INTERFACE=.*/INTERFACE=\"$(GET iface)\""/ \
    1.82 -				-e s"/^DHCP=.*/DHCP=\"$DHCP\"/" \
    1.83 -				-e s"/^STATIC=.*/STATIC=\"$STATIC\"/" \
    1.84 -				-e s"/^NETMASK=.*/NETMASK=\"$(GET netmask)\"/" \
    1.85 -				-e s"/^GATEWAY=.*/GATEWAY=\"$(GET gateway)\"/" \
    1.86 -				-e s"/^DNS_SERVER=.*/DNS_SERVER=\"$(GET dns)\"/" \
    1.87 -				-e s"/^IP=.*/IP=\"$(GET ip)\"/" /etc/network.conf
    1.88 -			/etc/init.d/network stop | log
    1.89 -			sleep 2
    1.90 -			/etc/init.d/network start | log
    1.91 -			. /etc/network.conf
    1.92 +		PAR1="size=\"20\" required"; PAR="$PAR1 pattern=\"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\""
    1.93 +
    1.94 +		case "$STATIC" in
    1.95 +			yes) use_static='checked';;
    1.96 +			*)   use_static='';;
    1.97 +		esac
    1.98 +
    1.99 +		stop_disabled=''; start_disabled=''
   1.100 +		if cat /sys/class/net/eth*/operstate | fgrep -q up; then
   1.101 +			start_disabled='disabled'
   1.102 +		else
   1.103 +			stop_disabled='disabled'
   1.104  		fi
   1.105  
   1.106 -		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.107  		cat <<EOT
   1.108  <h2>$(gettext 'Ethernet connection')</h2>
   1.109  
   1.110 @@ -164,45 +206,48 @@
   1.111  		<div>
   1.112  			<table>
   1.113  				<tr><td>$(gettext 'Interface')</td>
   1.114 -					<td><select name="iface" value="$INTERFACE" style="width:100%"/>
   1.115 +					<td><select name="iface" value="$INTERFACE" style="width:100%">
   1.116  					$(cd /sys/class/net; ls -1 | awk -viface="$INTERFACE" '{
   1.117  						sel = ($0 == iface) ? " selected":""
   1.118  						printf "<option value=\"%s\"%s>%s", $0, sel, $0
   1.119  					}')
   1.120  					</select></td>
   1.121  				</tr>
   1.122 -				<tr><td>&nbsp;</td>
   1.123 -					<td><label><input type="checkbox" name="staticip" id="staticip"/>
   1.124 +				<tr><td>$(gettext 'Static IP')</td>
   1.125 +					<td><label><input type="checkbox" name="staticip" id="staticip" $use_static/>
   1.126  						$(gettext 'Use static IP')</td>
   1.127 -				<tr><td>$(gettext 'IP address')</td>
   1.128 -					<td><input type="text" name="ip"      id="st1" value="$IP"         $PAR/></td>
   1.129  				</tr>
   1.130 -				<tr><td>$(gettext 'Netmask')</td>
   1.131 -					<td><input type="text" name="netmask" id="st2" value="$NETMASK"    $PAR/></td>
   1.132 +				<tr id="st1"><td>$(gettext 'IP address')</td>
   1.133 +					<td><input type="text" name="ip"      value="$IP"         $PAR/></td>
   1.134  				</tr>
   1.135 -				<tr><td>$(gettext 'Gateway')</td>
   1.136 -					<td><input type="text" name="gateway" id="st3" value="$GATEWAY"    $PAR/></td>
   1.137 +				<tr id="st2"><td>$(gettext 'Netmask')</td>
   1.138 +					<td><input type="text" name="netmask" value="$NETMASK"    $PAR/></td>
   1.139  				</tr>
   1.140 -				<tr><td>$(gettext 'DNS server')</td>
   1.141 -					<td><input type="text" name="dns"     id="st4" value="$DNS_SERVER" $PAR/></td>
   1.142 +				<tr id="st3"><td>$(gettext 'Gateway')</td>
   1.143 +					<td><input type="text" name="gateway" value="$GATEWAY"    $PAR/></td>
   1.144 +				</tr>
   1.145 +				<tr id="st4"><td>$(gettext 'DNS server')</td>
   1.146 +					<td><input type="text" name="dns"     value="$DNS_SERVER" $PAR/></td>
   1.147  				</tr>
   1.148  			</table>
   1.149  		</div>
   1.150  	</form>
   1.151  	<footer><!--
   1.152 -		--><button form="conf" type="submit" name="static"  data-icon="ok"    >$(gettext 'Activate (static)')</button><!--
   1.153 -		--><button form="conf" type="submit" name="dhcp"    data-icon="ok"    >$(gettext 'Activate (DHCP)'  )</button><!--
   1.154 -		--><button form="conf" name="disable" data-icon="cancel">$(gettext 'Disable'          )</button><!--
   1.155 +		--><button form="conf" type="submit" name="start_eth" data-icon="start" $start_disabled>$(gettext 'Start'  )</button><!--
   1.156 +		--><button form="conf" type="submit" name="stop"      data-icon="stop"  $stop_disabled >$(gettext 'Stop'   )</button><!--
   1.157  	--></footer>
   1.158  </section>
   1.159  
   1.160  <script type="text/javascript">
   1.161 -	document.getElementById('staticip').onchange = static_change;
   1.162 +function static_change() {
   1.163 +	staticip = document.getElementById('staticip').checked;
   1.164 +	for (i = 1; i < 5; i++) {
   1.165 +		document.getElementById('st' + i).style.display = staticip ? '' : 'none';
   1.166 +	}
   1.167 +}
   1.168  
   1.169 -	function static_change() {
   1.170 -		staticip = document.getElementById('staticip');
   1.171 -		alert(staticip.checked);
   1.172 -	}
   1.173 +document.getElementById('staticip').onchange = static_change;
   1.174 +static_change();
   1.175  </script>
   1.176  
   1.177  <section>
   1.178 @@ -343,7 +388,7 @@
   1.179  		fi
   1.180  
   1.181  		cat <<EOT
   1.182 -	   <button name="start-wifi" data-icon="start"   $start_disabled>$(gettext 'Start')</button><!--
   1.183 +	   <button name="start_wifi" data-icon="start"   $start_disabled>$(gettext 'Start')</button><!--
   1.184  	--><button name="stop"       data-icon="stop"    $stop_disabled >$(gettext 'Stop' )</button><!--
   1.185  	--><button type="submit"     data-icon="refresh" $stop_disabled >$(gettext 'Scan' )</button>
   1.186  </form>
   1.187 @@ -361,23 +406,6 @@
   1.188  </script>
   1.189  EOT
   1.190  
   1.191 -			ESSID="$(GET essid)"
   1.192 -			#WIFI_KEY_TYPE="$(GET keyType)"
   1.193 -			#WIFI_KEY="$(GET key)"
   1.194 -			#WIFI_AP="$(GET ap)"
   1.195 -
   1.196 -			if [ -n "$ESSID" ]; then
   1.197 -				/etc/init.d/network.sh stop | log
   1.198 -				sed -i \
   1.199 -					-e "s/^WIFI_ESSID=.*/WIFI_ESSID=\"$essid\"/" \
   1.200 -					-e "s/^WIFI_KEY_TYPE=.*/WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"/" \
   1.201 -					-e "s/^WIFI_KEY=.*/WIFI_KEY=\"$WIFI_KEY\"/" \
   1.202 -					-e "s/^WIFI_AP=.*/WIFI_AP=\"$WIFI_AP\"/" \
   1.203 -					/etc/network.conf
   1.204 -				. /etc/network.conf
   1.205 -				start_wifi
   1.206 -			fi
   1.207 -
   1.208  			# ESSID names are clickable
   1.209  			#SELECT="$(GET select)"
   1.210  			#if [ -n "$SELECT" ]; then
   1.211 @@ -390,7 +418,8 @@
   1.212  	<header>$(gettext 'Connection')</header>
   1.213  	<div>
   1.214  		<form id="connection">
   1.215 -			<input type="hidden" name="connect-wifi"/>
   1.216 +			<input type="hidden" name="connect_wifi"/>
   1.217 +			<input type="hidden" name="bssid" id="bssid"/>
   1.218  			<table>
   1.219  				<tr><td>$(gettext 'Network SSID')</td>
   1.220  					<td><input type="text" name="essid" value="$WIFI_ESSID" id="essid"/></td>