From: Felix Fietkau Date: Sun, 9 Oct 2005 23:03:47 +0000 (+0000) Subject: add some partially crazy, but effective optimizations to webif X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=2f10920724383f85b652477ebed4ca9b96951a7d;p=openwrt%2Fsvn-archive%2Farchive.git add some partially crazy, but effective optimizations to webif SVN-Revision: 2090 --- diff --git a/openwrt/package/webif/files/usr/lib/webif/common.awk b/openwrt/package/webif/files/usr/lib/webif/common.awk index d7e50e2461..c6f180b729 100644 --- a/openwrt/package/webif/files/usr/lib/webif/common.awk +++ b/openwrt/package/webif/files/usr/lib/webif/common.awk @@ -1,5 +1,5 @@ function start_form(title, field_opts) { - print "
" + print "
" if (title != "") print "

" title "

" print "
" } diff --git a/openwrt/package/webif/files/usr/lib/webif/form.awk b/openwrt/package/webif/files/usr/lib/webif/form.awk index c6bf747a4a..844a56c4b4 100644 --- a/openwrt/package/webif/files/usr/lib/webif/form.awk +++ b/openwrt/package/webif/files/usr/lib/webif/form.awk @@ -14,7 +14,7 @@ BEGIN { gsub(/^[ \t]+/,"",$1) } -($1 != "") && ($1 !~ /^option/) { +($1 != "") && ($1 !~ /^option/) && (select_open == 1) { select_open = 0 print "" } diff --git a/openwrt/package/webif/files/usr/lib/webif/webif.sh b/openwrt/package/webif/files/usr/lib/webif/webif.sh index cd8115b7e4..973099cd0b 100644 --- a/openwrt/package/webif/files/usr/lib/webif/webif.sh +++ b/openwrt/package/webif/files/usr/lib/webif/webif.sh @@ -4,7 +4,7 @@ cgidir=/www/cgi-bin/webif rootdir=/cgi-bin/webif indexpage=index.sh -# workarounds for stupid busybox fork/exec on [ ] +# workarounds for stupid busybox slowness on [ ] empty() { case "$1" in "") return 0 ;; @@ -17,6 +17,10 @@ equal() { *) return 255 ;; esac } +# very crazy, but also very fast :-) +exists() { + ( < $1 ) 2>&- +} categories() { grep '##WEBIF:' $cgidir/.categories $cgidir/*.sh 2>/dev/null | \ @@ -54,7 +58,7 @@ header() { _uptime="${_uptime#*up }" _uptime="${_uptime%%,*}" _hostname=$(cat /proc/sys/kernel/hostname) - _version=$(cat /etc/banner | grep "(") + _version=$( grep "(" /etc/banner ) _version="${_version%% ---*}" _head="${3:+

$3$_saved_title

}" _form="${5:+
}" @@ -175,14 +179,18 @@ apply_passwd() { case ${SERVER_SOFTWARE%% *} in busybox) echo -n '/cgi-bin/webif:' > /etc/httpd.conf - cat /etc/passwd | grep root | cut -d: -f1,2 >> /etc/httpd.conf + grep root /etc/passwd | cut -d: -f1,2 >> /etc/httpd.conf killall -HUP httpd ;; esac } display_form() { - echo "$1" | awk -F'|' -f /usr/lib/webif/common.awk -f /usr/lib/webif/form.awk + if empty "$1"; then + awk -F'|' -f /usr/lib/webif/common.awk -f /usr/lib/webif/form.awk + else + echo "$1" | awk -F'|' -f /usr/lib/webif/common.awk -f /usr/lib/webif/form.awk + fi } list_remove() { @@ -229,26 +237,35 @@ handle_list() { } load_settings() { - [ \! "$1" = "nvram" -a -f /etc/config/$1 ] && . /etc/config/$1 - [ -f /tmp/.webif/config-$1 ] && . /tmp/.webif/config-$1 + equal "$1" "nvram" || { + exists /etc/config/$1 && . /etc/config/$1 + } + exists /tmp/.webif/config-$1 && . /tmp/.webif/config-$1 } validate() { - eval "$(echo "$1" | awk -f /usr/lib/webif/validate.awk)" + if empty "$1"; then + eval "$(awk -f /usr/lib/webif/validate.awk)" + else + eval "$(echo "$1" | awk -f /usr/lib/webif/validate.awk)" + fi } save_setting() { - mkdir -p /tmp/.webif + exists /tmp/.webif/* || mkdir -p /tmp/.webif oldval=$(eval "echo \${$2}") oldval=${oldval:-$(nvram get "$2")} grep "^$2=" /tmp/.webif/config-$1 >&- 2>&- && { - mv /tmp/.webif/config-$1 /tmp/.webif/config-$1-old 2>&- >&- - grep -v "^$2=" /tmp/.webif/config-$1-old > /tmp/.webif/config-$1 2>&- + grep -v "^$2=" /tmp/.webif/config-$1 > /tmp/.webif/config-$1-new 2>&- + mv /tmp/.webif/config-$1-new /tmp/.webif/config-$1 2>&- >&- oldval="" } equal "$oldval" "$3" || echo "$2=\"$3\"" >> /tmp/.webif/config-$1 - rm -f /tmp/.webif/config-$1-old } +is_bcm947xx() { + read _systype < /proc/cpuinfo + equal "${_systype##* }" "BCM947XX" +} 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 b024561203..373508d09c 100755 --- a/openwrt/package/webif/files/www/cgi-bin/webif/config.sh +++ b/openwrt/package/webif/files/www/cgi-bin/webif/config.sh @@ -26,8 +26,8 @@ case "$FORM_mode" in } done CONFIGFILES="" - for configname in $(ls file-* 2>&-); do - CONFIGFILES="$CONFIGFILES ${configname#file-}" + for configname in file-*; do + exists "$configname" && CONFIGFILES="$CONFIGFILES ${configname#file-}" done CONFIGFILES="${CONFIGFILES:+

Config files:

$CONFIGFILES
}" echo $CONFIGFILES 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 72c7c62176..ff7d9dcbf0 100755 --- a/openwrt/package/webif/files/www/cgi-bin/webif/hosts.sh +++ b/openwrt/package/webif/files/www/cgi-bin/webif/hosts.sh @@ -2,12 +2,13 @@ &- 2>&- +exists /tmp/.webif/file-hosts && HOSTS_FILE=/tmp/.webif/file-hosts || HOSTS_FILE=/etc/hosts +exists /tmp/.webif/file-ethers && ETHERS_FILE=/tmp/.webif/file-ethers || ETHERS_FILE=/etc/ethers +exists $HOSTS_FILE || touch $HOSTS_FILE >&- 2>&- +exists $ETHERS_FILE || touch $ETHERS_FILE >&- 2>&- update_hosts() { - mkdir -p /tmp/.webif + exists /tmp/.webif/* || mkdir -p /tmp/.webif awk -v "mode=$1" -v "ip=$2" -v "name=$3" ' BEGIN { FS="[ \t]" @@ -37,13 +38,13 @@ processed == 0 { } END { if ((mode == "add") && (host_added == 0)) print ip " " name -}' - < "$HOSTS_FILE" > /tmp/.webif/file-hosts-new +}' "$HOSTS_FILE" > /tmp/.webif/file-hosts-new mv "/tmp/.webif/file-hosts-new" "/tmp/.webif/file-hosts" HOSTS_FILE=/tmp/.webif/file-hosts } update_ethers() { - mkdir -p /tmp/.webif + exists /tmp/.webif/* || mkdir -p /tmp/.webif case "$1" in add) grep -E -v "^[ \t]*$2" $ETHERS_FILE > /tmp/.webif/file-ethers-new @@ -60,14 +61,21 @@ update_ethers() { 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" + validate < Firmware Version - + Kernel Version diff --git a/openwrt/package/webif/files/www/cgi-bin/webif/lan.sh b/openwrt/package/webif/files/www/cgi-bin/webif/lan.sh index 8ce03b4b57..b853a7b6eb 100755 --- a/openwrt/package/webif/files/www/cgi-bin/webif/lan.sh +++ b/openwrt/package/webif/files/www/cgi-bin/webif/lan.sh @@ -17,10 +17,12 @@ if empty "$FORM_submit"; then FORM_lan_gateway=${lan_gateway:-$(nvram get lan_gateway)} else SAVED=1 - validate " + validate < -|onchange=\"modechange()\" -radio|wan_proto|$FORM_wan_proto|dhcp|DHCP
|onchange=\"modechange()\" -radio|wan_proto|$FORM_wan_proto|static|Static IP
|onchange=\"modechange()\" +radio|wan_proto|$FORM_wan_proto|none|None
|onchange="modechange()" +radio|wan_proto|$FORM_wan_proto|dhcp|DHCP
|onchange="modechange()" +radio|wan_proto|$FORM_wan_proto|static|Static IP
|onchange="modechange()" $PPPOE_OPTION $PPTP_OPTION end_form @@ -170,8 +175,8 @@ end_form start_form|PPP Settings|ppp_settings|hidden field|PPP Redial Policy|ppp_redial|hidden -radio|ppp_redial|$FORM_ppp_redial|demand|Connect on Demand
|onChange=\"modechange()\" -radio|ppp_redial|$FORM_ppp_redial|persist|Keep Alive|onChange=\"modechange()\" +radio|ppp_redial|$FORM_ppp_redial|demand|Connect on Demand
|onChange="modechange()" +radio|ppp_redial|$FORM_ppp_redial|persist|Keep Alive|onChange="modechange()" field|Maximum Idle Time|ppp_demand_idletime|hidden text|ppp_idletime|$FORM_ppp_idletime field|Redial Timeout|ppp_persist_redialperiod|hidden @@ -182,7 +187,8 @@ field|PPP Password|ppp_passwd|hidden text|ppp_passwd|$FORM_ppp_passwd field|PPP MTU|ppp_mtu|hidden text|ppp_mtu|$FORM_ppp_mtu -end_form" +end_form +EOF footer ?>