From e0b9cb8558b893f79f8502d443d1b82dec18c05a Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 9 Oct 2005 21:06:35 +0000 Subject: [PATCH] move some code in a shared awk script, add fast replacement functions for [ -z ] and [ = ], make code a bit more readable SVN-Revision: 2088 --- .../webif/files/usr/lib/webif/categories.awk | 27 ++++ .../webif/files/usr/lib/webif/common.awk | 12 ++ .../files/usr/lib/webif/display-dhcp.awk | 21 +++ .../files/usr/lib/webif/display-hosts.awk | 37 +++++ .../webif/files/usr/lib/webif/form.awk | 11 +- .../files/usr/lib/webif/subcategories.awk | 12 ++ .../webif/files/usr/lib/webif/webif.sh | 137 ++++++++---------- .../webif/files/www/cgi-bin/webif/config.sh | 5 +- .../webif/files/www/cgi-bin/webif/hosts.sh | 78 ++-------- .../webif/files/www/cgi-bin/webif/index.sh | 6 +- .../webif/files/www/cgi-bin/webif/lan.sh | 5 +- .../webif/files/www/cgi-bin/webif/system.sh | 7 +- .../webif/files/www/cgi-bin/webif/upgrade.sh | 4 +- .../webif/files/www/cgi-bin/webif/wan.sh | 74 +++++----- .../www/cgi-bin/webif/wireless-config.sh | 46 +++--- 15 files changed, 256 insertions(+), 226 deletions(-) create mode 100644 openwrt/package/webif/files/usr/lib/webif/categories.awk create mode 100644 openwrt/package/webif/files/usr/lib/webif/common.awk create mode 100644 openwrt/package/webif/files/usr/lib/webif/display-dhcp.awk create mode 100644 openwrt/package/webif/files/usr/lib/webif/display-hosts.awk create mode 100644 openwrt/package/webif/files/usr/lib/webif/subcategories.awk diff --git a/openwrt/package/webif/files/usr/lib/webif/categories.awk b/openwrt/package/webif/files/usr/lib/webif/categories.awk new file mode 100644 index 0000000000..26dcf39c5b --- /dev/null +++ b/openwrt/package/webif/files/usr/lib/webif/categories.awk @@ -0,0 +1,27 @@ +BEGIN { + n = 0 + sel = 0 + FS=":" +} +($3 == "category") && (categories !~ /:$4:/) { + categories = categories ":" $4 ":"; + n++ + if ($4 ~ "^" selected "$") sel = n + c[n] = $4 + if (f[$4] == "") f[$4] = rootdir "/" indexpage "?cat=" $4 +} +($3 == "name") && ((p[$4] == 0) || (p[$4] > int($5))) { + gsub(/^.*\//, "", $1); + p[$4] = int($5) + f[$4] = rootdir "/" $1 +} +END { + print "

Categories:

" +} diff --git a/openwrt/package/webif/files/usr/lib/webif/common.awk b/openwrt/package/webif/files/usr/lib/webif/common.awk new file mode 100644 index 0000000000..d7e50e2461 --- /dev/null +++ b/openwrt/package/webif/files/usr/lib/webif/common.awk @@ -0,0 +1,12 @@ +function start_form(title, field_opts) { + print "
" + if (title != "") print "

" title "

" + print "
" +} + +function end_form(form_help, form_help_link) { + print "
" + if (form_help != "") form_help = "
" form_help "
" + print "

Short help:

" form_help form_help_link "
" + print "
 
" +} diff --git a/openwrt/package/webif/files/usr/lib/webif/display-dhcp.awk b/openwrt/package/webif/files/usr/lib/webif/display-dhcp.awk new file mode 100644 index 0000000000..28c5067359 --- /dev/null +++ b/openwrt/package/webif/files/usr/lib/webif/display-dhcp.awk @@ -0,0 +1,21 @@ +BEGIN { + FS="[ \t]" + print "
" + start_form("Static IP addresses (for DHCP)") + print "" + print "" +} + +# only for valid MAC addresses +($1 ~ /^[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]$/) { + gsub(/#.*$/, ""); + print "" +} + +END { + print "" + print "
MAC addressIP
" $1 "" $2 "Remove
" + print "
" + end_form(); +} + diff --git a/openwrt/package/webif/files/usr/lib/webif/display-hosts.awk b/openwrt/package/webif/files/usr/lib/webif/display-hosts.awk new file mode 100644 index 0000000000..db522a3020 --- /dev/null +++ b/openwrt/package/webif/files/usr/lib/webif/display-hosts.awk @@ -0,0 +1,37 @@ +BEGIN { + FS="[ \t]" + start_form("Hostnames") + print "" + print "" + print "" +} + +# only for valid IPv4 addresses +($1 ~ /^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/) { + gsub(/#.*$/, ""); + output = "" + names_found = 0 + n = split($0, names, "[ \t]") + first = 1 + for (i = 2; i <= n; i++) { + if (names[i] != "") { + if (first != 1) output = output "" + output = output "" + first = 0 + names_found++ + } + } + if (names_found > 0) { + print "" output + print "" + } +} + +END { + print "" + print "" + print "" + print "
IPHostname

" names[i] "Remove
" $1 "

" + end_form() +} + diff --git a/openwrt/package/webif/files/usr/lib/webif/form.awk b/openwrt/package/webif/files/usr/lib/webif/form.awk index 8a3d110e72..c6bf747a4a 100644 --- a/openwrt/package/webif/files/usr/lib/webif/form.awk +++ b/openwrt/package/webif/files/usr/lib/webif/form.awk @@ -22,9 +22,8 @@ $1 ~ /^start_form/ { if ($3 != "") field_opts=" id=\"" $3 "\"" else field_opts="" if ($4 == "hidden") field_opts = field_opts " style=\"display: none\"" - print "
" - if ($2 != "") print "

" $2 "

" - print "
" + start_form($2, field_opts); + print "
" form_help = "" form_help_link = "" } @@ -78,10 +77,8 @@ $1 ~ /^helplink/ { form_help_link = "
" - if (form_help != "") form_help = "
" form_help "
" - print "

Short help:

" form_help form_help_link "
" + print "" + end_form(form_help, form_help_link); form_help = "" form_help_link = "" - print "
 
" } diff --git a/openwrt/package/webif/files/usr/lib/webif/subcategories.awk b/openwrt/package/webif/files/usr/lib/webif/subcategories.awk new file mode 100644 index 0000000000..b748de2cb4 --- /dev/null +++ b/openwrt/package/webif/files/usr/lib/webif/subcategories.awk @@ -0,0 +1,12 @@ +BEGIN { + FS=":" + print "

Sub-Categories:

" +} + diff --git a/openwrt/package/webif/files/usr/lib/webif/webif.sh b/openwrt/package/webif/files/usr/lib/webif/webif.sh index 9de03b955b..cd8115b7e4 100644 --- a/openwrt/package/webif/files/usr/lib/webif/webif.sh +++ b/openwrt/package/webif/files/usr/lib/webif/webif.sh @@ -4,49 +4,35 @@ cgidir=/www/cgi-bin/webif rootdir=/cgi-bin/webif indexpage=index.sh +# workarounds for stupid busybox fork/exec on [ ] +empty() { + case "$1" in + "") return 0 ;; + *) return 255 ;; + esac +} +equal() { + case "$1" in + "$2") return 0 ;; + *) return 255 ;; + esac +} + categories() { - grep '##WEBIF:' $cgidir/.categories $cgidir/*.sh 2>/dev/null | awk -F: ' - BEGIN { - n = 0 - sel = 0 - } - ($3 == "category") && (categories !~ /:$4:/) { - categories = categories ":" $4 ":"; - n++ - if ($4 ~ /^'"$1"'$/) sel = n - c[n] = $4 - if (f[$4] == "") f[$4] = "'"$rootdir/$indexpage"'?cat=" $4 - } - ($3 == "name") && ((p[$4] == 0) || (p[$4] > int($5))) { - gsub(/^.*\//, "", $1); - p[$4] = int($5) - f[$4] = "'"$rootdir"'/" $1 - } - END { - print "

Categories:

" - }' - + grep '##WEBIF:' $cgidir/.categories $cgidir/*.sh 2>/dev/null | \ + awk -v "selected=$1" \ + -v "rootdir=$rootdir" \ + -v "indexpage=$indexpage" \ + -f /usr/lib/webif/categories.awk - } subcategories() { - grep -H "##WEBIF:name:$1:" $cgidir/*.sh 2>/dev/null | sed -e 's,^.*/\([a-zA-Z\.\-]*\):\(.*\)$,\2:\1,' | sort -n | awk -F: ' - BEGIN { - print "

Sub-Categories:

" - } - ' - + grep -H "##WEBIF:name:$1:" $cgidir/*.sh 2>/dev/null | \ + sed -e 's,^.*/\([a-zA-Z\.\-]*\):\(.*\)$,\2:\1,' | \ + sort -n | \ + awk -v "selected=$2" \ + -v "rootdir=$rootdir" \ + -f /usr/lib/webif/subcategories.awk - } update_changes() { @@ -54,8 +40,14 @@ update_changes() { } header() { - ERROR=${ERROR:+

$ERROR



} - SAVED=${SAVED:+: Settings saved} + empty "$ERROR" && { + _saved_title="${SAVED:+: Settings saved}" + } || { + FORM_submit=""; + ERROR="

$ERROR



" + _saved_title=": Settings not saved" + } + _category="$1" _uptime="$(uptime)" _loadavg="${_uptime#*load average: }" @@ -64,8 +56,6 @@ header() { _hostname=$(cat /proc/sys/kernel/hostname) _version=$(cat /etc/banner | grep "(") _version="${_version%% ---*}" - _saved_title=${ERROR:+: Settings not saved} - _saved_title=${_saved_title:-$SAVED} _head="${3:+

$3$_saved_title

}" _form="${5:+
}" _savebutton="${5:+

}" @@ -106,9 +96,8 @@ Pragma: no-cache $_head $ERROR EOF - [ -z "$REMOTE_USER" \ - -a "${SCRIPT_NAME#/cgi-bin/}" != "webif.sh" ] && { - [ -z $FORM_passwd1 ] || { + empty "$REMOTE_USER" && equal "${SCRIPT_NAME#/cgi-bin/}" "webif.sh" && { + empty "$FORM_passwd" && { echo '
'
 			(
 				echo "$FORM_passwd1"
@@ -193,7 +182,7 @@ apply_passwd() {
 }
 
 display_form() {
-	echo "$1" | awk -F'|' -f /usr/lib/webif/form.awk
+	echo "$1" | awk -F'|' -f /usr/lib/webif/common.awk -f /usr/lib/webif/form.awk
 }
 
 list_remove() {
@@ -209,26 +198,34 @@ BEGIN {
 }
 
 handle_list() {
-	_new="${1:+$(list_remove "$LISTVAL" "$1") }"
-	_new="${_new:-$LISTVAL}"
-	LISTVAL="$_new"
-	LISTVAL="${LISTVAL# }"
-	LISTVAL="${LISTVAL%% }"
+	# $1 - remove
+	# $2 - add
+	# $3 - submit
+	# $4 - validate
 	
-	_validate="$4"
-	_validate="${4:-none}"
-	_changed="$1"
-	[ \! -z "$3" ] && validate "$_validate|$2" && {
-		LISTVAL="$LISTVAL $2"
-		_changed="$1$3"
+	empty "$1" || {
+		LISTVAL="$(list_remove "$LISTVAL" "$1") "
+		LISTVAL="${LISTVAL# }"
+		LISTVAL="${LISTVAL%% }"
+		_changed=1
+	}
+	
+	empty "$3" || {
+		validate "${4:-none}|$2" && {
+			LISTVAL="$LISTVAL $2"
+			_changed=1
+		}
 	}
 
-	_return="${_changed:+0}"
-	_return="${_return:-255}"
 	LISTVAL="${LISTVAL# }"
 	LISTVAL="${LISTVAL%% }"
 	LISTVAL="${LISTVAL:- }"
-	return $_return
+
+	if empty "$_changed"; then
+		return 255
+	else
+		return 0
+	fi
 }
 
 load_settings() {
@@ -240,6 +237,7 @@ validate() {
 	eval "$(echo "$1" | awk -f /usr/lib/webif/validate.awk)"
 }
 
+
 save_setting() {
 	mkdir -p /tmp/.webif
 	oldval=$(eval "echo \${$2}")
@@ -249,23 +247,8 @@ save_setting() {
 		grep -v "^$2=" /tmp/.webif/config-$1-old > /tmp/.webif/config-$1 2>&- 
 		oldval=""
 	}
-	[ "$oldval" != "$3" ] && echo "$2=\"$3\"" >> /tmp/.webif/config-$1
+	equal "$oldval" "$3" || echo "$2=\"$3\"" >> /tmp/.webif/config-$1
 	rm -f /tmp/.webif/config-$1-old
 }
 
 
-# common awk code for forms
-AWK_START_FORM='
-	print "
" - print "

" title "

" - print "
" -' -AWK_END_FORM=' - print "
" - if (form_help != "") form_help = "
" form_help "
" - print "

Short help:

" form_help form_help_link "
" - form_help = "" - form_help_link = "" - print "
 
" -' - diff --git a/openwrt/package/webif/files/www/cgi-bin/webif/config.sh b/openwrt/package/webif/files/www/cgi-bin/webif/config.sh index 254884fba4..b024561203 100755 --- a/openwrt/package/webif/files/www/cgi-bin/webif/config.sh +++ b/openwrt/package/webif/files/www/cgi-bin/webif/config.sh @@ -35,10 +35,9 @@ case "$FORM_mode" in save) header $FORM_cat . "Configuration: updating..." CHANGES="" - echo '
'
+		echo "
"
 		sh /usr/lib/webif/apply.sh
-		echo '
' - echo "${FORM_prev:+}" + echo "
${FORM_prev:+}" ;; esac diff --git a/openwrt/package/webif/files/www/cgi-bin/webif/hosts.sh b/openwrt/package/webif/files/www/cgi-bin/webif/hosts.sh index 5faa4885c6..72c7c62176 100755 --- a/openwrt/package/webif/files/www/cgi-bin/webif/hosts.sh +++ b/openwrt/package/webif/files/www/cgi-bin/webif/hosts.sh @@ -58,88 +58,30 @@ update_ethers() { ETHERS_FILE=/tmp/.webif/file-ethers } -[ ! -z "$FORM_add_host" ] && { +empty "$FORM_add_host" || { # add a host to /etc/hosts validate "ip|FORM_host_ip|IP Address|required|$FORM_host_ip hostname|FORM_host_name|Hostname|required|$FORM_host_name" && update_hosts add "$FORM_host_ip" "$FORM_host_name" } -[ ! -z "$FORM_add_dhcp" ] && { +empty "$FORM_add_dhcp" || { # add a host to /etc/ethers validate "mac|FORM_dhcp_mac|MAC Address|required|$FORM_dhcp_mac ip|FORM_dhcp_ip|IP|required|$FORM_dhcp_ip" && update_ethers add "$FORM_dhcp_mac" "$FORM_dhcp_ip" } -[ ! -z "$FORM_remove_host" ] && update_hosts del "$FORM_remove_ip" "$FORM_remove_name" -[ ! -z "$FORM_remove_dhcp" ] && update_ethers del "$FORM_remove_mac" +empty "$FORM_remove_host" || update_hosts del "$FORM_remove_ip" "$FORM_remove_name" +empty "$FORM_remove_dhcp" || update_ethers del "$FORM_remove_mac" header "Network" "Hosts" "Configured hosts" '' # Hosts in /etc/hosts -# FIXME: move formatting code in form.awk if possible -awk -v "url=$SCRIPT_NAME" ' -BEGIN { - FS="[ \t]" - title = "Hostnames" - '"$AWK_START_FORM"' - print "" - print "" - print "" -} - -# only for valid IPv4 addresses -($1 ~ /^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/) { - gsub(/#.*$/, ""); - output = "" - names_found = 0 - n = split($0, names, "[ \t]") - first = 1 - for (i = 2; i <= n; i++) { - if (names[i] != "") { - if (first != 1) output = output "" - output = output "" - first = 0 - names_found++ - } - } - if (names_found > 0) { - print "" output - print "" - } -} - -END { - print "" - print "" - print "" - print "
IPHostname

" names[i] "Remove
" $1 "

" - '"$AWK_END_FORM"' -} -' $HOSTS_FILE +awk -v "url=$SCRIPT_NAME" \ + -v "ip=$FORM_host_ip" \ + -v "name=$FORM_host_name" -f /usr/lib/webif/common.awk -f /usr/lib/webif/display-hosts.awk $HOSTS_FILE # Static DHCP mappings (/etc/ethers) -# FIXME: move formatting code in form.awk if possible -awk -v "url=$SCRIPT_NAME" ' -BEGIN { - FS="[ \t]" - title = "Static IP addresses (for DHCP)" - '"$AWK_START_FORM"' - print "
" - print "" - print "" -} - -# only for valid MAC addresses -($1 ~ /^[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]$/) { - gsub(/#.*$/, ""); - print "" -} - -END { - print "" - print "
MAC addressIP
" $1 "" $2 "Remove
" - print "
" - '"$AWK_END_FORM"' -} -' - < $ETHERS_FILE +awk -v "url=$SCRIPT_NAME" \ + -v "mac=$FORM_dhcp_mac" \ + -v "ip=$FORM_dhcp_ip" -f /usr/lib/webif/common.awk -f /usr/lib/webif/display-dhcp.awk $ETHERS_FILE footer ?> diff --git a/openwrt/package/webif/files/www/cgi-bin/webif/upgrade.sh b/openwrt/package/webif/files/www/cgi-bin/webif/upgrade.sh index 6de13d3309..6b5fe9a166 100755 --- a/openwrt/package/webif/files/www/cgi-bin/webif/upgrade.sh +++ b/openwrt/package/webif/files/www/cgi-bin/webif/upgrade.sh @@ -8,7 +8,7 @@ strip_cybertan() { rm $FORM_firmware } -[ -z "$FORM_submit" -o -z "$FORM_firmware" ] || { +empty "$FORM_submit" || empty "$FORM_firmware" || { [ -n $FORM_firmware ] && { HEADER=$(head -c4 $FORM_firmware | hexdump -e "8/1 \"%x\"") grep BCM947 /proc/cpuinfo > /dev/null && { @@ -35,7 +35,7 @@ strip_cybertan() { } } ?> - +
diff --git a/openwrt/package/webif/files/www/cgi-bin/webif/wan.sh b/openwrt/package/webif/files/www/cgi-bin/webif/wan.sh index 60a930de29..1d6202906c 100755 --- a/openwrt/package/webif/files/www/cgi-bin/webif/wan.sh +++ b/openwrt/package/webif/files/www/cgi-bin/webif/wan.sh @@ -13,7 +13,7 @@ handle_list "$FORM_dnsremove" "$FORM_dnsadd" "$FORM_dnssubmit" 'ip|FORM_dnsadd|W FORM_dnsadd=${FORM_dnsadd:-192.168.1.1} -[ -z $FORM_submit ] && { +if empty "$FORM_submit"; then FORM_wan_proto=${wan_proto:-$(nvram get wan_proto)} case "$FORM_wan_proto" in # supported types @@ -46,21 +46,17 @@ text|pptp_server_ip|$FORM_pptp_server_ip" redial=${ppp_demand:-$(nvram get ppp_demand)} case "$redial" in - 1|enabled|on) - FORM_ppp_redial="demand" - ;; - *) - FORM_ppp_redial="persist" - ;; + 1|enabled|on) FORM_ppp_redial="demand";; + *) FORM_ppp_redial="persist";; esac FORM_pptp_server_ip=${pptp_server_ip:-$(nvram get pptp_server_ip)} -} || { +else SAVED=1 - [ -z $FORM_wan_proto ] && { + empty "$FORM_wan_proto" && { ERROR="No WAN protocol selected" - return -1 + return 255 } case "$FORM_wan_proto" in @@ -83,41 +79,41 @@ ip|FORM_pptp_server_ip|PPTP server IP|$V_PPTP|$FORM_pptp_server_ip" && { # Settings specific to one protocol type case "$FORM_wan_proto" in - static) - save_setting network wan_gateway $FORM_wan_gateway - ;; - pptp) - save_setting network pptp_server_ip "$FORM_pptp_server_ip" - ;; + static) save_setting network wan_gateway $FORM_wan_gateway ;; + pptp) save_setting network pptp_server_ip "$FORM_pptp_server_ip" ;; esac # Common settings for PPTP, Static and DHCP - [ "$FORM_wan_proto" = "pptp" -o "$FORM_wan_proto" = "static" -o "$FORM_wan_proto" = "dhcp" ] && { - save_setting network wan_ipaddr $FORM_wan_ipaddr - save_setting network wan_netmask $FORM_wan_netmask - } + case "$FORM_wan_proto" in + pptp|static|dhcp) + save_setting network wan_ipaddr $FORM_wan_ipaddr + save_setting network wan_netmask $FORM_wan_netmask + ;; + esac # Common PPP settings - [ "$FORM_wan_proto" = "pppoe" -o "$FORM_wan_proto" = "pptp" ] && { - [ -z $FORM_ppp_username ] || save_setting network ppp_username $FORM_ppp_username - [ -z $FORM_ppp_passwd ] || save_setting network ppp_passwd $FORM_ppp_passwd - - # These can be blank - save_setting network ppp_idletime $FORM_ppp_idletime - save_setting network ppp_redialperiod $FORM_ppp_redialperiod - save_setting network ppp_mtu $FORM_ppp_mtu - - case "$FORM_ppp_redial" in - demand) - save_setting network ppp_demand 1 - ;; - persist) - save_setting network ppp_demand "" - ;; - esac - } + case "$FORM_wan_proto" in + pppoe|pptp) + empty "$FORM_ppp_username" || save_setting network ppp_username $FORM_ppp_username + empty "$FORM_ppp_passwd" || save_setting network ppp_passwd $FORM_ppp_passwd + + # These can be blank + save_setting network ppp_idletime "$FORM_ppp_idletime" + save_setting network ppp_redialperiod "$FORM_ppp_redialperiod" + save_setting network ppp_mtu "$FORM_ppp_mtu" + + case "$FORM_ppp_redial" in + demand) + save_setting network ppp_demand 1 + ;; + persist) + save_setting network ppp_demand "" + ;; + esac + ;; + esac } -} +fi header "Network" "WAN" "WAN settings" ' onLoad="modechange()" ' "$SCRIPT_NAME" ?> diff --git a/openwrt/package/webif/files/www/cgi-bin/webif/wireless-config.sh b/openwrt/package/webif/files/www/cgi-bin/webif/wireless-config.sh index e0f8a72022..36bf1b4473 100755 --- a/openwrt/package/webif/files/www/cgi-bin/webif/wireless-config.sh +++ b/openwrt/package/webif/files/www/cgi-bin/webif/wireless-config.sh @@ -22,7 +22,8 @@ for ch in $CHANNELS; do " done -if [ -z "$FORM_submit" -o \! -z "$ERROR" ]; then + +if empty "$FORM_submit"; then FORM_mode=${wl0_mode:-$(nvram get wl0_mode)} infra=${wl0_infra:-$(nvram get wl0_infra)} case "$infra" in @@ -80,7 +81,7 @@ if [ -z "$FORM_submit" -o \! -z "$ERROR" ]; then FORM_tkip=tkip ;; esac - [ $FORM_encryption = off ] && { + equal "$FORM_encryption" off && { wep=${wl0_wep:-$(nvram get wl0_wep)} case "$wep" in 1|enabled|on) FORM_encryption=wep;; @@ -95,8 +96,11 @@ if [ -z "$FORM_submit" -o \! -z "$ERROR" ]; then FORM_key=${key:-1} else SAVED=1 - [ "$FORM_encryption" = "wpa" ] && V_RADIUS="required" - [ "$FORM_encryption" = "psk" ] && V_PSK="required" + case "$FORM_encryption" in + wpa) V_RADIUS="required";; + psk) V_PSK="required";; + esac + validate " ip|FORM_radius_ipaddr|RADIUS IP address|$V_RADIUS|$FORM_radius_ipaddr wep|FORM_key1|WEP key 1||$FORM_key1 @@ -107,24 +111,21 @@ string|FORM_wpa_psk|WPA pre-shared key|min=8 max=63 $V_PSK|$FORM_wpa_psk string|FORM_radius_key|RADIUS server key|min=4 max=63 $V_RADIUS|$FORM_radius_key string|FORM_ssid|ESSID|required|$FORM_ssid int|FORM_channel|Channel|required min=1 max=$CHANNEL_MAX|$FORM_channel" && { - case "$FORM_mode" in - adhoc) - save_setting wireless wl0_mode sta - save_setting wireless wl0_infra 0 - ;; - *) - save_setting wireless wl0_mode "$FORM_mode" - save_setting wireless wl0_infra 1 - ;; - esac + + if equal "$FORM_mode" adhoc; then + FORM_mode=sta + infra="0" + fi + save_setting wireless wl0_mode "$FORM_mode" + save_setting wireless wl0_infra ${infra:-1} save_setting wireless wl0_ssid "$FORM_ssid" save_setting wireless wl0_channel "$FORM_channel" - case "$FORM_aes$FORM_tkip" in - aes) save_setting wireless wl0_crypto aes;; - tkip) save_setting wireless wl0_crypto tkip;; - aestkip) save_setting wireless wl0_crypto tkip+aes;; - esac + + crypto="" + equal "$FORM_aes" aes && crypto="aes" + equal "$FORM_tkip" tkip && crypto="tkip${crypto:++$crypto}" + case "$FORM_encryption" in psk) case "${FORM_wpa1}${FORM_wpa2}" in @@ -163,7 +164,8 @@ int|FORM_channel|Channel|required min=1 max=$CHANNEL_MAX|$FORM_channel" && { fi header "Network" "Wireless" "Wireless settings" ' onLoad="modechange()" ' "$SCRIPT_NAME" -?> + +cat < -