From 78a2e215462406afe097dafc81e664234333aef7 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 30 Sep 2005 22:06:05 +0000 Subject: [PATCH] some webif fixes, support for lists in webif.sh, cleanup SVN-Revision: 2012 --- .../webif/files/usr/lib/webif/form.awk | 9 +- .../webif/files/usr/lib/webif/validate.awk | 4 +- .../webif/files/usr/lib/webif/webif.sh | 115 ++++++++++++------ .../www/cgi-bin/webif/wireless-config.sh | 65 ++-------- 4 files changed, 98 insertions(+), 95 deletions(-) diff --git a/openwrt/package/webif/files/usr/lib/webif/form.awk b/openwrt/package/webif/files/usr/lib/webif/form.awk index 9bca13551c..8a405bcb98 100644 --- a/openwrt/package/webif/files/usr/lib/webif/form.awk +++ b/openwrt/package/webif/files/usr/lib/webif/form.awk @@ -59,13 +59,20 @@ $1 ~ /^select/ { else option_title = $2 print "" option_title "" } +($1 ~ /^listedit/) { + n = split($4 " ", items, " ") + for (i = 1; i <= n; i++) { + if (items[i] != "") print "" items[i] " Remove" + } + print "" +} $1 ~ /^text/ { print "" $4 } $1 ~ /^submit/ { print "" } $1 ~ /^helpitem/ { form_help = form_help "
" $2 ":
" } $1 ~ /^helptext/ { form_help = form_help "
" $2 "
" } $1 ~ /^helplink/ { form_help_link = "" } -{ +($1 ~ /^checkbox/) || ($1 ~ /^radio/) { print $5 } diff --git a/openwrt/package/webif/files/usr/lib/webif/validate.awk b/openwrt/package/webif/files/usr/lib/webif/validate.awk index c806400ca2..da765017d2 100644 --- a/openwrt/package/webif/files/usr/lib/webif/validate.awk +++ b/openwrt/package/webif/files/usr/lib/webif/validate.awk @@ -64,7 +64,7 @@ $1 == "string" { $1 == "mac" { valid_type = 1 - if ((value != "") && (value !~ /^[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]*$/)) { + if ((value != "") && (value !~ /^[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]$/)) { valid = 0 verr = "Invalid value" } @@ -111,4 +111,6 @@ valid_type == 1 { END { print output "ERROR=\"" error "\";\n" + if (error == "") print "return 0" + else print "return 255" } diff --git a/openwrt/package/webif/files/usr/lib/webif/webif.sh b/openwrt/package/webif/files/usr/lib/webif/webif.sh index fd1b63174b..445b234ec6 100644 --- a/openwrt/package/webif/files/usr/lib/webif/webif.sh +++ b/openwrt/package/webif/files/usr/lib/webif/webif.sh @@ -4,24 +4,8 @@ cgidir=/www/cgi-bin/webif rootdir=/cgi-bin/webif indexpage=index.sh -header() { - CATEGORY="$1" - UPTIME="$(uptime)" - LOADAVG="${UPTIME#*load average: }" - UPTIME="${UPTIME#*up }" - UPTIME="${UPTIME%%,*}" - HOSTNAME=$(cat /proc/sys/kernel/hostname) - VERSION=$(cat /etc/banner | grep "(") - VERSION="${VERSION%% ---*}" - SAVED=${SAVED:+: Settings saved} - SAVED_TITLE=${ERROR:+: Settings not saved} - SAVED_TITLE=${SAVED_TITLE:-$SAVED} - ERROR=${ERROR:+

$ERROR



} - HEAD="${3:+

$3$SAVED_TITLE

}" - FORM="${5:+
}" - SAVEBUTTON="${5:+

}" - - CATEGORIES=$(grep '##WEBIF:category' $cgidir/.categories $cgidir/*.sh 2>/dev/null | awk -F: ' +categories() { + grep '##WEBIF:category' $cgidir/.categories $cgidir/*.sh 2>/dev/null | awk -F: ' BEGIN { print "

Categories:

    " } @@ -32,9 +16,11 @@ header() { } END { print "
" - }' -) + }' - +} - SUBCATEGORIES=${2:+$(grep -H "##WEBIF:name:$1:" $cgidir/*.sh 2>/dev/null | sed -e 's,^.*/\([a-zA-Z\.\-]*\):\(.*\)$,\2:\1,' | sort -n | awk -F: ' +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:

    " } @@ -45,7 +31,28 @@ header() { END { print "
" } - ' -)} + ' - +} + +header() { + ERROR=${ERROR:+

$ERROR



} + SAVED=${SAVED:+: Settings saved} + _category="$1" + _uptime="$(uptime)" + _loadavg="${_uptime#*load average: }" + _uptime="${_uptime#*up }" + _uptime="${_uptime%%,*}" + _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:+

}" + _categories=$(categories $1) + _subcategories=${2:+$(subcategories $1 $2)} + cat <

Status:

    -
  • Hostname: $HOSTNAME
  • -
  • Uptime: $UPTIME
  • -
  • Load: $LOADAVG
  • -
  • Version: $VERSION
  • +
  • Hostname: $_hostname
  • +
  • Uptime: $_uptime
  • +
  • Load: $_loadavg
  • +
  • Version: $_version
- $CATEGORIES - $SUBCATEGORIES + $_categories + $_subcategories - $FORM + $_form
- $HEAD + $_head $ERROR EOF [ -z "$REMOTE_USER" \ @@ -127,9 +134,9 @@ EOF } footer() { - CHANGES=$(($(cat /tmp/.webif/config-* 2>&- | wc -l))) - CHANGES=${CHANGES#0} - CHANGES=${CHANGES:+(${CHANGES})} + _changes=$(($(cat /tmp/.webif/config-* 2>&- | wc -l))) + _changes=${_changes#0} + _changes=${_changes:+(${_changes})} cat <
@@ -138,14 +145,14 @@ footer() { @@ -169,19 +176,49 @@ display_form() { echo "$1" | awk -F'|' -f /usr/lib/webif/form.awk } -mkdir -p /tmp/.webif +list_remove() { + echo "$1 " | awk ' +BEGIN { + RS=" " + FS=":" + first = 1 +} +($0 !~ /^'"$2"'/) { + if (first != 1) printf " " + printf $0 + first = 0 +}' +} + +handle_list() { + _new="${1:+$(list_remove "$LISTVAL" "$1") }" + _new="${_new:-$LISTVAL}" + LISTVAL="$_new" + + _validate="$4" + _validate="${4:-none}" + [ \! -z "$3" ] && validate "$_validate|$2" && LISTVAL="$LISTVAL $2" + + _changed="$1$3" + _return="${_changed:+0}" + _return="${_return:-255}" + LISTVAL="${LISTVAL# }" + LISTVAL="${LISTVAL%% }" + LISTVAL="${LISTVAL:- }" + return $_return +} load_settings() { [ \! "$1" = "nvram" -a -f /etc/config/$1 ] && . /etc/config/$1 - [ -f /tmp/.webif/config-$1 ] && . /tmp/.webif/config-$1 + [ -f /tmp/.webif/config-$1 ] && . /tmp/.webif/config-$1 } validate() { eval "$(echo "$1" | awk -f /usr/lib/webif/validate.awk)" - [ -z "$ERROR" ] && return 0 || return 255 } save_setting() { + mkdir -p /tmp/.webif oldval=$(eval "echo \${$2}") oldval=${oldval:-$(nvram get "$2")} mv /tmp/.webif/config-$1 /tmp/.webif/config-$1-old 2>&- >&- 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 c3c5bfde9e..ddc44f62a1 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 @@ -4,33 +4,15 @@ load_settings "wireless" -WDS=${wl0_wds:-$(nvram get wl0_wds)} -WDS="${WDS# }" -[ -z "$FORM_wdsremove" ] || { - WDS=$(echo "$WDS " | awk ' -BEGIN { - RS=" " - FS=":" - first = 1 -} -($0 !~ /^'"$FORM_wdsremove"'/) { - if (first != 1) printf " " - printf $0 - first = 0 -} -END { print "" }') - WDS="${WDS:- }" - save_setting wireless wl0_wds "$WDS" - FORM_submit="" -} -[ \! -z "$FORM_wdssubmit" ] && { - validate "mac|FORM_newmac|WDS MAC address||$FORM_newmac" && { - WDS="$WDS $FORM_newmac" - WDS="${WDS# }" - save_setting wireless wl0_wds "$WDS" - } +FORM_wds="${wl0_wds:-$(nvram get wl0_wds)}" +LISTVAL="$FORM_wds" +handle_list "$FORM_wdsremove" "$FORM_wdsadd" "$FORM_wdssubmit" 'mac|FORM_wdsadd|WDS MAC address|required' && { + FORM_wds="$LISTVAL" + save_setting wireless wl0_wds "$FORM_wds" FORM_submit="" } +FORM_wdsadd=${FORM_wdsadd:-00:00:00:00:00:00} + CC=${wl0_country_code:-$(nvram get wl0_country_code)} case "$CC" in All|all|ALL) CHANNELS="1 2 3 4 5 6 7 8 9 10 11 12 13 14"; CHANNEL_MAX=14 ;; @@ -43,7 +25,6 @@ for ch in $CHANNELS; do done if [ -z "$FORM_submit" ]; then - FORM_newmac=${FORM_newmac:-00:00:00:00:00:00} FORM_mode=${wl0_mode:-$(nvram get wl0_mode)} FORM_ssid=${wl0_ssid:-$(nvram get wl0_ssid)} FORM_channel=${wl0_channel:-$(nvram get wl0_channel)} @@ -243,36 +224,12 @@ radio|key|$FORM_key|3 text|key3|$FORM_key3|
radio|key|$FORM_key|4 text|key4|$FORM_key4|
+end_form +start_form|WDS connections +listedit|wds|$SCRIPT_NAME|$FORM_wds|$FORM_wdsadd end_form" -?> -
-

WDS connections

-
- -" -} -' -?> - - - - -
" $0 " Remove
-
-
 
-
-
 
- - +footer ?> -- 2.30.2