Revision: 4822
Author: kemen04
Date: Sat Sep 5 14:38:09 2009
Log: add patches done by Stefan Stapelberg <
ste...@rent-a-guru.de>
* Rewrite of status-wlan-survey.sh
* Caching of permissions for viewing pages.
* Caching the list of categories/subcategories on a per-user base.
(Provides a 2 second speedup of network.sh on my WRT54G V2.2)
http://code.google.com/p/x-wrt/source/detail?r=4822
Added:
/trunk/package/webif/files/usr/lib/webif/acl.awk
/trunk/package/webif/files/www/images/lock.png
/trunk/package/webif/files/www/images/transmit.png
Modified:
/trunk/package/webif/files/usr/lib/webif/categories.awk
/trunk/package/webif/files/usr/lib/webif/subcategories.awk
/trunk/package/webif/files/usr/lib/webif/webif.sh
/trunk/package/webif/files/www/cgi-bin/webif/graphs-subcategories.sh
/trunk/package/webif/files/www/cgi-bin/webif/status-wlan-survey.sh
/trunk/package/webif/files/www/cgi-bin/webif/system-access-control.sh
=======================================
--- /dev/null
+++ /trunk/package/webif/files/usr/lib/webif/acl.awk Sat Sep 5 14:38:09
2009
@@ -0,0 +1,55 @@
+BEGIN { FS=":"; nc = 0; ns = 0;
+ if (USER != "root" && USER != "admin")
+ config_load("webif_access_control")
+}
+/^##WEBIF:category:/ {
+ if (categories !~ /:$3:/) {
+ categories = categories ":" $3 ":";
+ c[++nc] = $3
+ }
+ next;
+}
+/^##WEBIF:name:/ {
+ url = FILENAME;
+ gsub(/^.*\//, "", url);
+ if (USER != "root" && USER != "admin" && $3 != "-") {
+ if ($3 != "Graphs")
+ allowed = config_get_bool(USER, $3"_"$4, "0")
+ else allowed = config_get_bool(USER, "Graphs", "0")
+ }
+ if ((USER == "root" || USER == "admin") || allowed == "1" || $3 == "-") {
+ sp[$3,$5] = $4;
+ st[$3,$5] = $5;
+ sf[$3,$5] = rootdir "/" url;
+ if ((p[$3] == 0) || (int($4) < p[$3])) {
+ p[$3] = int($4) + 1;
+ f[$3] = rootdir "/" url;
+ }
+ }
+}
+END {
+ fname = cachedir "/cat_" USER;
+ for (i = 1; i <= nc; i++) {
+ if (c[i] == "-")
+ print("-:-") > fname;
+
+ else if (f[c[i]] != "")
+ print(c[i] ":" f[c[i]]) > fname;
+ }
+ close(fname);
+
+ fname = cachedir "/subcat_" USER;
+ cmd = "sort -n >" fname;
+
+ for (i = 1; i <= nc; i++) {
+ if (f[c[i]] == "")
+ continue;
+
+ for (k in sf) {
+ split(k, key, SUBSEP);
+ if (key[1] == c[i])
+ print(key[1] ":" sp[k] ":" st[k] ":" sf[k]) | cmd;
+ }
+ }
+ close(cmd);
+}
=======================================
--- /dev/null
+++ /trunk/package/webif/files/www/images/lock.png Sat Sep 5 14:38:09 2009
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/package/webif/files/www/images/transmit.png Sat Sep 5 14:38:09
2009
@@ -0,0 +1,20 @@
+‰PNG
+
+
+IHDR óÿa gAMA ¯È7 Šé tEXtSoftware Adobe
ImageReadyqÉe< IDAT8Ë
+’]H“a † ’0 ‚N= Ã0$£È“"
+‚R ”’¢ƒ@Í2ü!Qt©¥1Q–CS·e
+l*2—?Œ k,
+%ŠRv
+ ØAu ëË«{™
+?ÕÁà /ïu?×ó¼Ÿ 0mªiOŠÊA¸g é.ƒ Ó`²m ‰[ FêS¶Þß
+W
+Œ27 /ÆUAX
+ƒ§>˜ê‚@U yåö€iO<Sî fûáY@—{àa ê
+c×a¤ Æë!| Fkáî¹ zòãÿ „{œÌ
Ž L¶ Ò5ÿî4pÅŒ·ÐJß ƒ€Â|%àÌt¬ „»ÒxÒa0;¨Žvƒ±Æ½ŒÖ%H·Yº3ô—Ìà½ØŒ« wÞ^:³
+üš¢ÕbÐr<ÕÄc‡“HŸôœ1]+£Õ‰W.ñ †Êað²¾ àÊ]¢ãt"mV«B ÷<4 q˜¤ûŠ™þõÙ ×ÌÒ
+&x éúñœµp'×"]?¾"uÍ ¦õ˜™›G‘ Ô¦¼4Iw• mÙ_
+;Œ“n ß%¤k™ŸŸÏ‰D"©ÒµÐ™ MéQ ÅQw ®*`ß'“tW‰ÜÓb
+cÛ5ã: ÓýÀPÙ ÁßB¡ÐWºóNI÷-
+iP½ßLmòúh¶¤ “¶ûšûUH7*ÝxéfĶ+ØÇâ$¼y„ßï÷þ|
+[òAuÝ%p™–ôX€Fp ”I·H‹Ù½ñl‚÷¨óJ0 \ ¼æõzß¹Ýî„M? -É¢Ê7mû•U‚» || ïç l´··Ûwº» |
Xð÷_ #‚#‚×ìvû熆†äÿ þ"¸wãL°OðJMMÍÈ? g ^ lÛzQpcEEÅTiiéÉ¿ ö ÎÙiÖX
Î...ÎTÅmœý õ&ÉÙ»G]Ö IEND®B`‚
=======================================
--- /trunk/package/webif/files/usr/lib/webif/categories.awk Wed Jun 11
05:21:28 2008
+++ /trunk/package/webif/files/usr/lib/webif/categories.awk Sat Sep 5
14:38:09 2009
@@ -1,47 +1,3 @@
-BEGIN {
- n = 0
- sel = 0
- FS=":"
- config_load("webif_access_control")
-}
-($3 == "category") && (categories !~ /:$4:/) {
- categories = categories ":" $4 ":";
- n++
- if ($4 ~ "^" selected "$") sel = n
- c[n] = $4
- if ($4 == "-") f[$4] = rootdir "/" indexpage "?cat=" $4
-}
-($3 == "name") {
- gsub(/^.*\//, "", $1);
- if ($4 != "Graphs") {
- var = config_get_bool(USER, $4"_"$5, "0")
- }
- else {
- var = config_get_bool(USER, "Graphs", "0")
- }
- if ((var == "1") || (USER == "root") || (USER == "admin")) {
- if ((p[$4] == 0) || (p[$4] > int($5))) {
- p[$4] = int($5) + 1
- f[$4] = rootdir "/" $1
- }
- }
-}
-END {
- print "<ul>"
-
- for (i = 1; i <= n; i++) {
- if (f[c[i]] != "") {
- if (sel == i) print " <li class=\"selected\"><a href=\""
f[c[i]] "\">@TR<<" c[i] ">></a></li>"
- else {
- if (c[i] == "-") {
- print " <li class=\"separator\">-</li>"
- }
- else {
- print " <li><a href=\"" f[c[i]] "\">@TR<<" c[i] ">></a></li>";
- }
- }
- }
- }
-
- print "</ul>"
-}
+$1 == "-" { print "<li class=\"separator\"> </li>"; next; }
+$1 ~ "^" selected "$" { print "<li class=\"selected\"><a href=\""
$2 "?cat=" $1 "\">@TR<<" $1 ">></a></li>"; next; }
+ { print "<li><a href=\"" $2 "?cat=" $1 "\">@TR<<" $1 ">></a></li>"; }
=======================================
--- /trunk/package/webif/files/usr/lib/webif/subcategories.awk Wed Jun 11
05:21:28 2008
+++ /trunk/package/webif/files/usr/lib/webif/subcategories.awk Sat Sep 5
14:38:09 2009
@@ -1,22 +1,2 @@
-BEGIN {
- FS=":"
- print "<h3><strong>@TR<<Subcategories>>:</strong></h3>"
- print "<ul>"
- config_load("webif_access_control")
-}
-{
- if ($3 != "Graphs") {
- var = config_get_bool(USER, $3"_"$4, "0")
- }
- else {
- var = config_get_bool(USER, "Graphs", "0")
- }
- if ((var == "1") || (USER == "root") || (USER == "admin")) {
- if ($5 ~ "^" selected "$") print " <li class=\"selected\"><a href=\""
rootdir "/" $6 "\">@TR<<" $5 ">></a></li>"
- else print " <li><a href=\"" rootdir "/" $6 "\">@TR<<" $5 ">></a></li>"
- }
-}
-END {
- print "</ul>"
-}
-
+$1 ~ category && $3 ~ "^" selected "$" { print "<li class=\"selected\"><a
href=\"" $4 "\">@TR<<" $3 ">></a></li>"; next; }
+$1 ~ category { print "<li><a href=\"" $4 "\">@TR<<" $3 ">></a></li>"; }
=======================================
--- /trunk/package/webif/files/usr/lib/webif/webif.sh Wed Aug 19 01:14:13
2009
+++ /trunk/package/webif/files/usr/lib/webif/webif.sh Sat Sep 5 14:38:09
2009
@@ -16,30 +16,45 @@
wwwdir=/www
cgidir=/www/cgi-bin/webif
rootdir=/cgi-bin/webif
+cachedir=/tmp/.webcache
+cachetime=7200 # cache time-out: 5 days
+
. /usr/lib/webif/functions.sh
. /lib/config/uci.sh
uci_load "webif"
_device="$CONFIG_general_device_name"
+init_cache() {
+ [ -d $cachedir ] || mkdir $cachedir 2>/dev/null 1>&2
+ awk -F: -v rootdir="$rootdir" -v cachedir="$cachedir" -v
USER="${1:-root}" \
+ -f /usr/lib/webif/common.awk -f /usr/lib/webif/acl.awk
$cgidir/.categories $cgidir/*.sh 2>/dev/null
+}
+
categories() {
- grep '##WEBIF' $cgidir/.categories $cgidir/*.sh 2>/dev/null | \
- awk -v "selected=$1" \
- -v "USER=$REMOTE_USER" \
- -v "rootdir=$rootdir" \
- -f /usr/lib/webif/common.awk \
- -f /usr/lib/webif/categories.awk -
+ cachefile="$cachedir/cat_${REMOTE_USER:-root}"
+ #awk -F: -v selected="$1" -f /usr/lib/webif/categories.awk $cachefile
2>/dev/null
+ sed -e 's%^-:-$%<li>\ </li>%' \
+ -e 's%^\([^:]*\):\(.*\)$%<li><a href="\2?cat=\1">@TR<<\1>></a></li>%'
\
+ -e '/'"$1"'/s%^<li>\(.*\)$%<li class="selected">\1%' $cachefile
2>/dev/null
}
subcategories() {
- grep -H "##WEBIF:name:$1:" $cgidir/*.sh 2>/dev/null | \
- sed -e 's,^.*/\([a-zA-Z0-9\.\-]*\):\(.*\)$,\2:\1,' | \
- sort -n | \
- awk -v "selected=$2" \
- -v "rootdir=$rootdir" \
- -v "USER=$REMOTE_USER" \
- -f /usr/lib/webif/common.awk \
- -f /usr/lib/webif/subcategories.awk -
+ cachefile="$cachedir/subcat_${REMOTE_USER:-root}"
+ #awk -F: -v category="$1" -v selected="$2" -f
/usr/lib/webif/subcategories.awk $cachefile 2>/dev/null
+
+ sed -e '/^'"$1"':/!d' \
+ -e 's%[^:]*:[^:]*:\([^:]*\):\(.*\)$%<li><a
href="\2">@TR<<\1>></a></li>%' \
+ -e '/<<'"$2"'>>/s%^<li>\(.*\)$%<li class="selected">\1%' $cachefile
2>/dev/null
+}
+
+perm_denied() {
+ [ "$REMOTE_USER" = "root" -o "$REMOTE_USER" = "admin" ] && return 1
+ [ "$SCRIPT_NAME" = "/cgi-bin/webif/config.sh" ] && return 1
+
+ cachefile="$cachedir/subcat_${REMOTE_USER:-root}"
+ grep -q "$SCRIPT_NAME" $cachefile 2>/dev/null && return 1
+ return 0
}
ShowWIPWarning() {
@@ -115,6 +130,12 @@
ERROR="<h3 class=\"warning\">$ERROR</h3>"
_saved_title=": @TR<<Settings not saved>>"
}
+
+ # Initialize the categories cache if not done already
+ [ -s "$cachedir/cat_${REMOTE_USER:-root}" ] || init_cache
${REMOTE_USER:-root}
+ #cache_needs_update="$(find $cachedir -mmin -$cachetime -name
cat_${REMOTE_USER:-root} 2>/dev/null | wc -l)"
+ #[ "$cache_needs_update" = "0" ] && init_cache ${REMOTE_USER:-root}
+
_category="$1"
_firmware_version="$CONFIG_general_firmware_version"
@@ -248,22 +269,11 @@
apply_passwd
}
}
- if [ "$REMOTE_USER" != "root" -a "$REMOTE_USER" != "admin" ]; then
- config_load webif_access_control
- if [ "$1" != "Graphs" -a "$2" != "" ]; then
- webifform=`grep "##WEBIF:name:${1}:[0-9][0-9][0-9]:${2}"
/www/cgi-bin/webif/*.sh |cut -d':' -f5`
- config_get_bool permission "$REMOTE_USER" "${1}_${webifform}" 0
- elif [ "$2" != "" ]; then
- permission="1"
- else
- config_get_bool permission "$REMOTE_USER" "Graphs" 0
- fi
- if [ "$permission" = "0" ]; then
- echo "Permission Denied"
- footer
- exit
- fi
- fi
+ perm_denied "$_category" && {
+ echo "Permission Denied"
+ footer
+ exit
+ }
}
#######################################################
=======================================
--- /trunk/package/webif/files/www/cgi-bin/webif/graphs-subcategories.sh
Thu Mar 12 22:37:44 2009
+++ /trunk/package/webif/files/www/cgi-bin/webif/graphs-subcategories.sh
Sat Sep 5 14:38:09 2009
@@ -1,16 +1,17 @@
#!/bin/sh
+
+cachedir=/tmp/.webcache
+
+uci_load network
+
subcategories() {
- (
- echo "#""#WEBIF:name:Graphs:1:graphs_cpu_subcategory#CPU:graphs-cpu.sh"
-
echo "#""#WEBIF:name:Graphs:160:graphs_bandwidth_subcategory#Bandwidth:graphs-bandwidth.sh"
-
echo "#""#WEBIF:name:Graphs:3:graphs_vnstat_subcategory#Vnstat:graphs-vnstat.sh"
- cat /proc/net/dev | \
- egrep -v "No statistics available" | \
- sed -n '/:/{s/:.*//;s/^
*\(.*\)/##WEBIF:name:Graphs:2:graphs_if_Traffic#Traffic\>\>
\1@TR\<\<:graphs-if.sh?if=\1/;p}'
- ) | \
- awk -v "selected=$2" \
- -v "USER=$REMOTE_USER" \
- -v "rootdir=$rootdir" \
- -f /usr/lib/webif/common.awk \
- -f /usr/lib/webif/subcategories.awk -
-}
+ [ -s "$cachedir/graphs" ] || { # create a cache if it does not
exists already
+ [ -d "$cachedir" ] || mkdir "$cachedir" 2>/dev/null 1>&2
+ (echo "Graphs:10:CPU:graphs-cpu.sh"
+ echo "Graphs:20:Bandwidth:graphs-bandwidth.sh"
+ echo "Graphs:30:Vnstat:graphs-vnstat.sh"
+ sed -n -e "/:/"'{s/:.*//;s/^ *\(.*\)/Graphs:50:Traffic\>\>
\1@TR\<\<:graphs-if.sh?if=\1/;p}' /proc/net/dev 2>/dev/null
+ ) | sort -n >$cachedir/graphs
+ }
+ awk -F: -v "category=Graphs" -v "selected=$2" -f
/usr/lib/webif/common.awk -f /usr/lib/webif/subcategories.awk
$cachedir/graphs
+}
=======================================
--- /trunk/package/webif/files/www/cgi-bin/webif/status-wlan-survey.sh Mon
Mar 9 11:06:11 2009
+++ /trunk/package/webif/files/www/cgi-bin/webif/status-wlan-survey.sh Sat
Sep 5 14:38:09 2009
@@ -1,7 +1,9 @@
#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh
+
#################################
+#
# Wireless survey page
#
# Description:
@@ -11,57 +13,72 @@
# Jeremy Collake <
jeremy....@gmail.com>
# Travis Kemen <
thep...@berlios.de>
#
-# TODO:
-# I originally wrote this before I had bothered to learn much about
-# awk, so it uses 'pure' shell scripting. It would be much simpler
-# and probably more efficient to use awk. Maybe recode someday, but
-# why fix what's isn't broken...
-#
-
-header "Status" "Site Survey" "@TR<<Site Survey>>"
+# Completely rewritten for speed improvement into pure AWK by
+# Stefan Stapelberg <
ste...@rent-a-guru.de>
+
+MACLIST_URL="
http://standards.ieee.org/cgi-bin/ouisearch?"
+
config_cb() {
local cfg_type="$1"
local cfg_name="$2"
case "$cfg_type" in
- wifi-device)
- append DEVICES "$cfg_name"
- ;;
- wifi-iface)
- append vface "$cfg_name" "$N"
- ;;
+ wifi-device) append devices "$cfg_name" ;;
+ wifi-iface) append vface "$cfg_name" "$N" ;;
esac
}
+
uci_load wireless
-for DEVICE in $DEVICES; do
- config_get type $DEVICE type
- echo "$type" |grep -q broadcom
- [ "$?" = 0 ] && {
- config_get disabled $DEVICE disabled
+
+for device in $devices; do
+ config_get type $device type
+ [ "$type" = "broadcom" ] && {
+ config_get disabled $device disabled
[ "$disabled" = "0" ] && scan_iface=1
}
- echo "$type" |grep -q atheros
- [ "$?" = 0 ] && {
- config_get disabled $DEVICE disabled
- [ "$disabled" = "0" ] && atheros_devices="$atheros_devices $DEVICE"
+ [ "$type" = "atheros" ] && {
+ config_get disabled $device disabled
+ [ "$disabled" = "0" ] && atheros_devices="$atheros_devices $device"
+ }
+ [ "$type" = "mac80211" ] && {
+ config_get disabled $device disabled
+ [ "$disabled" = "1" ] && {
+ scan_iface=1
+ FORM_clientswitch=1
+ }
}
done
+
for ath_device in $atheros_devices; do
for i in $vface; do
config_get iface $i device
if [ "$iface" = "$ath_device" ]; then
config_get mode $i mode
- echo "$mode" |grep -q sta
- [ "$?" = 0 ] && scan_iface=1
+ [ "$mode" = "sta" ] && scan_iface=1
fi
done
done
+header "Status" "Site Survey" "@TR<<Site Survey>>"
+
+equal "$scan_iface" "1" || {
+ echo '<div class="settings">'
+ echo "@TR<<No wireless networks were found>>."
+ echo '</div>'
+ footer
+ exit
+}
+
+SCAN_BUTTON='@TR<<Start the scan now>>'
+tempfile=$(mktemp /tmp/.survtemp.XXXXXX)
+
if [ "$FORM_clientswitch" != "" ]; then
- for DEVICE in $DEVICES; do
- config_get type $DEVICE type
- echo "$type" |grep -q broadcom
- [ "$?" = 0 ] && {
+ SCAN_BUTTON='@TR<<Start the scan again>>'
+ echo "<p style=\"margin: 1em 0;\">@TR<<Please wait, the scan needs some
time>> ...</p>"
+
+ for device in $devices; do
+ config_get type $device type
+ [ "$type" = "broadcom" ] && {
wifi down
wlc stdin <<EOF
down
@@ -103,186 +120,133 @@
ssid OpenWrt
enabled 1
EOF
- scan_iface=1
break
}
- echo "$type" |grep -q atheros
- [ "$?" = 0 ] && {
+ [ "$type" = "atheros" ] && {
wifi down >/dev/null
wlanconfig ath0 create wlandev wifi0 wlanmode sta >/dev/null
- scan_iface=1
ifconfig ath0 up
sleep 3
}
-
+ [ "$type" = "mac80211" ] && {
+ wifi down >/dev/null
+ ifconfig wlan0 up
+ sleep 3
+ }
done
fi
-if [ "$scan_iface" != "1" ]; then
- cat <<EOF
+got_result=0
+
+for i in 1 2 3 4; do
+ iwlist scan 2>/dev/null | tee "$tempfile" | grep -qi 'Cell [0-9][0-9] -
Address:' && {
+ got_result=1
+ break;
+ }
+done
+
+cat <<-EOF
<div class="settings">
<form enctype="multipart/form-data" method="post" action="$SCRIPT_NAME">
<h3><strong>@TR<<Wireless Survey>></strong></h3>
-<p>@TR<<HelpText WLAN Survey#Your wireless adaptor is not in client mode.
To do a scan it must be put into client mode for a few seconds. Your WLAN
traffic will be interrupted during this brief period.>></p>
-<input type="submit" value=" @TR<<Scan>> " name="clientswitch" />
+<p style="margin-bottom: 1em;">
+@TR<<wlan_survey_helptext#Your wireless adaptor is not in client mode.<br
/>To do a scan it must be put into client mode for a few seconds.>>
+<br /><br />
+<span class="red">@TR<<wlan_survey_warning#<b>Note:</b> Your WLAN traffic
will be interrupted during this brief period.>></span>
+</p>
+<input style="margin-left: 12em;" type="submit" name="clientswitch"
value=" $SCAN_BUTTON " />
</form>
-<div class="clearfix"> </div></div>
+<div class="clearfix"> </div>
+</div>
+<br />
EOF
-fi
-
-##### Variables
-
-MAX_TRIES=4
-MAX_CELLS=100
-tempfile=$(mktemp /tmp/.survtemp.XXXXXX)
-tempfile2=$(mktemp /tmp/.survtemp.XXXXXX)
-
-if [ "$scan_iface" = "1" ]; then
-#echo " Please wait while scan is performed ... <br /><br />"
-counter=0
-for counter in $(seq 1 $MAX_TRIES); do
- #echo "."
- iwlist scan > $tempfile 2> /dev/null
- grep -i "Address" < $tempfile >> /dev/null
- equal "$?" "0" && break
- sleep 1
-done
-
-first_hit=1
-if [ $counter -gt $MAX_TRIES ]; then
- echo "<tr><td>@TR<<Sorry, no scan results.>></td></tr>"
-else
- current=0
- counter=0
- for counter in $(seq 1 $MAX_CELLS); do
- current_line=$(sed '2,$ d' < $tempfile)
- empty "$current_line" && break
- # line must contain both "Cell" and "Address" to be considered
- # start of a new cell..
- echo "$current_line" | grep "Cell" >> /dev/null
- result_one=$?
- echo "$current_line" | grep "Address" >> /dev/null
- result_two=$?
- equal "$result_one" "0" && equal "$result_two" "0" && {
- equal "$first_hit" "0" && {
- let "current+=1"
- }
- first_hit=0
- }
- equal "$first_hit" "0" && {
- echo "$current_line" >> "$tempfile"_"${current}"
- }
-
- sed 1d < $tempfile > $tempfile2
- rm $tempfile
- mv $tempfile2 $tempfile
- done
-
- current=0
- counter=0
- for counter in $(seq 1 $MAX_CELLS); do
- ! exists "$tempfile"_"${current}" && break
- ####################################################
- # parse out MAC
- address_pre=$(sed '2,$ d' < "$tempfile"_"${current}" | sed -e
s/'Cell'//g -e s/'Address'//g -e s/'-'//g)
- count=0
- for i in $address_pre; do
- case $count in
- 0) CELL_ID=$i;;
- 2) MAC_ID=$i;;
- 3) break;;
- esac
- let "count+=1"
- done
-
- ####################################################
- # parse out essid
- ESSID=$(grep -i "ESSID" < "$tempfile"_"${current}" | sed -e
s/'ESSID:'//g -e s/'"'//g)
-
- grep -q "Frequency:" < "$tempfile"_"${current}"
- if [ "$?" = "0" ]; then
- ####################################################
- # parse out channel
- CHANNEL_ID=$(grep -i "Frequency:" < "$tempfile"_"${current}" | sed -e
s/'Frequency:'//g -e s/' '//g)
-
- ####################################################
- # parse out signal
- quality_pre=$(grep -i "Quality" < "$tempfile"_"${current}" | sed -e
s/'Quality='//g -e s/'Signal level='//g -e s/'dBm'//g -e s/'Noise
level='//g)
- else
- ####################################################
- # parse out channel
- CHANNEL_ID=$(grep -i "Channel" < "$tempfile"_"${current}" | sed -e
s/'Channel:'//g -e s/' '//g)
-
- ####################################################
- # parse out signal
- quality_pre=$(grep -i "Quality" < "$tempfile"_"${current}" | sed -e
s/'Quality:'//g -e s/'Signal level:'//g -e s/'dBm'//g -e s/'Noise
level:'//g)
- fi
- count=0
- for i in $quality_pre; do
- case $count in
- 0) QUALITY=$i;;
- 1) SIGNAL_DBM=$i;;
- 2) NOISE_DBM=$i
- break;;
- esac
- let "count+=1"
- done
-
- #
- # only show quality if it's not 0/0
- #
- if ! equal "$QUALITY" "0/0"; then
- QUALITY_STRING="string|<tr><td>@TR<<Quality>> $QUALITY</td></tr>"
- fi
-
- NOISE_BASE=-99
- NOISE_DELTA=$(expr $NOISE_BASE - $NOISE_DBM)
-
- SIGNAL_INTEGRITY=$(expr $SIGNAL_DBM + $NOISE_DELTA)
- MAC_DASHES=$(echo "$MAC_ID" | sed s/':'/'-'/g)
- MAC_FIRST_THREE=$(echo "$MAC_DASHES" | cut -c1-8)
- SNR_PERCENT=$(expr 100 + $SIGNAL_INTEGRITY)
-
- FORM_cells="$FORM_cells
- string|<tr><td><strong>@TR<<Cell>></strong> $CELL_ID</td></tr>
- string|<tr><td><strong>@TR<<SSID>></strong> $ESSID (<a
href=\"
http://standards.ieee.org/cgi-bin/ouisearch?$MAC_FIRST_THREE\"
target=\"_blank\">$MAC_DASHES</a>)</td></tr>
- string|<tr><td><strong>@TR<<Channel>></strong> $CHANNEL_ID</td></tr>
- $QUALITY_STRING
- string|<tr><td><strong>@TR<<Signal>></strong> $SIGNAL_DBM dBm /
<strong>@TR<<Noise>></strong> $NOISE_DBM dBm</td></tr><tr><td>
-# I guess is more graphic
- progressbar|SNR|<strong>@TR<<SNR>></strong> $SIGNAL_INTEGRITY dBm|200|
$SNR_PERCENT|"$SNR_PERCENT%"
-# progressbar|SNR|<strong>@TR<<SNR>></strong> $SIGNAL_INTEGRITY dBm|200|
$SNR_PERCENT|$SIGNAL_INTEGRITY dBm
- string|</td></tr><tr><td> </td></tr>"
-
- rm -f "$tempfile"_"${current}"
- let "found_networks+=1"
- let "current+=1"
- done
-fi # end if were scan results
+
+equal "$got_result" "1" || {
+ SCAN_BUTTON="@TR<<Start survey>>"
+ echo '<div class="settings" style="margin-top: 1em;">'
+ echo '<p>@TR<<status_wlan_noresults#Sorry, there are no scan results.
Please do a search by clicking on>>'
+ echo "<i>${SCAN_BUTTON}</i> @TR<<above>>.</p>"
+ echo '</div>'
+ footer
+ rm "$tempfile"
+ exit
+}
+
+FORM_cells=$(awk -v "maclist_url=$MACLIST_URL" '
+BEGIN { nc = 0; }
+ $1 == "Cell" && $4 == "Address:" {
+ nc = $2 + 0; # strip leading zero
+ macaddr[nc] = $5;
+}
+nc > 0 {
+ if ($1 ~ /^ESSID:/) {
+ sub(/^ *ESSID:"/, "", $0);
+ sub(/"$/, "", $0);
+ essid[nc] = $0;
+ next;
+ }
+ if ($1 ~ /^Channel:/) {
+ split($1, arr, ":");
+ channel[nc] = arr[2];
+ next;
+ }
+ if ($1 ~ /^Quality:/ && $2 ~ /^Signal$/) {
+ split($1, arr, ":");
+ quality[nc] = arr[2];
+
+ split($3, arr, ":");
+ siglevel[nc] = arr[2];
+
+ split($6, arr, ":");
+ noiselevel[nc] = arr[2];
+ next;
+ }
+ if ($1 ~ /^Encryption/) {
+ split($2, arr, ":");
+ enc[nc] = arr[2];
+ }
+}
+END { for (i=1; i <= nc; i++) {
+ split(macaddr[i], arr, ":");
+ abbr_macaddr = arr[1] "-" arr[2] "-" arr[3];
+
+ noise_delta = -99 - noiselevel[i];
+ integrity = siglevel[i] + noise_delta;
+ psnr = 100 + integrity;
+
+ img_url = "<img src=\"/images/";
+ if (enc[i] == "on")
+ img_url = img_url "lock.png";
+ else img_url = img_url "transmit.png";
+ img_url = img_url "\" width=\"16\" height=\"16\" border=\"0\" alt=\"\"
/>";
+
+ printf("string|<tr><td class=\"wlscan\" valign=\"top\"
nowrap=\"nowrap\">%s<span class=\"essid\">%s</span><br />\n",
+ img_url, essid[i]);
+ printf("string|<span class=\"wlinfo\"><a title=\"@TR<<Cell>> %d\"
href=\"%s?%s\" target=\"_blank\">%s</a>\n",
+ i, maclist_url, abbr_macaddr, macaddr[i]);
+ printf("string| @TR<<on>> @TR<<Channel>> %d</span>", channel[i]);
+ if (quality[i] != "0/0")
+ printf("<br />\nstring|<span
class=\"wlinfo\">@TR<<Quality>>: %s</span>", quality[i]);
+ printf("</td>\n");
+ printf("string|<td valign=\"top\">@TR<<Signal>> %d @TR<<dbm>> /
@TR<<Noise>> %d @TR<<dbm>><br />\n",
+ siglevel[i], noiselevel[i]);
+ printf("progressbar|SNR|@TR<<SNR>> %d @TR<<dbm>>|200|%d|\"%d%%\"\n",
integrity, psnr, psnr);
+ printf("string|</td></tr><tr><td colspan=\"2\"> </td></tr>\n");
+ }
+}' "$tempfile")
rm -f "$tempfile"
-rm -f "$tempfile2"
-
-if ! empty "$FORM_clientswitch"; then
- #echo "<tr><td>Restoring settings...</tr></td>"
- # restore radio to its original state
- wifi >/dev/null
-fi
-fi # end if is in 'allowed to scan' mode
-
-if [ "$scan_iface" = "1" ]; then
- if equal "$found_networks" "0"; then
- echo "@TR<<No wireless networks were found>>."
- else
- display_form <<EOF
- start_form|@TR<<Survey Results>>
- $FORM_cells
- end_form|
+
+# Restore radio to its original state
+empty "$FORM_clientswitch" || wifi >/dev/null 2>&1
+
+display_form <<-EOF
+start_form|@TR<<Survey Results>>
+$FORM_cells
+end_form|
EOF
- fi
-fi
footer ?>
<!--
-##WEBIF:name:Status:980:Site Survey
+##WEBIF:name:Status:900:Site Survey
-->
=======================================
--- /trunk/package/webif/files/www/cgi-bin/webif/system-access-control.sh
Wed Mar 25 13:15:56 2009
+++ /trunk/package/webif/files/www/cgi-bin/webif/system-access-control.sh
Sat Sep 5 14:38:09 2009
@@ -1,9 +1,10 @@
#!/usr/bin/webif-page
-<%
-. "/usr/lib/webif/webif.sh"
+<?
+. /usr/lib/webif/webif.sh
###################################################################
-# system configuration page
+#
+# System configuration page
#
# Description:
# Configures access control for the webif
@@ -17,6 +18,10 @@
# /etc/config/webif_access_control
#
+cachedir=/tmp/.webcache
+#admin is also a superuser but maybe removed in the future.
+superuser=root
+
mkdir /tmp/.webif/
exists /etc/config/webif_access_control || touch
/etc/config/webif_access_control
@@ -26,105 +31,105 @@
EOF
equal "$FORM_password_add" "$FORM_password2_add" || {
[ -n "$ERROR" ] && ERROR="${ERROR}<br />"
- ERROR="${ERROR}@TR<<Passwords do not match>><br />"
+ ERROR="${ERROR}@TR<<password_mismatch#The passwords do not match!>><br
/>"
}
if [ "${FORM_user_add}" = "root" -o "${FORM_user_add}" = "admin" ]; then
[ -n "$ERROR" ] && ERROR="${ERROR}<br />"
- ERROR="${ERROR}@TR<<root and admin are already users.>><br />"
+ ERROR="${ERROR}@TR<<root and admin are already users>>.<br />"
fi
empty "$ERROR" && {
password=$(httpd -m $FORM_password_add)
[ -e /tmp/.webif/file-httpd.conf ] || cp /etc/httpd.conf
/tmp/.webif/file-httpd.conf
- echo "/cgi-bin/webif/:${FORM_user_add}:${password}" >>
/tmp/.webif/file-httpd.conf
+ echo "/cgi-bin/webif/:${FORM_user_add}:${password}"
>>/tmp/.webif/file-httpd.conf
uci_add "webif_access_control" "accesscontrol" "${FORM_user_add}"
}
fi
header "System" "Access Control" "@TR<<Access Control>>" '' "$SCRIPT_NAME"
+
exists /tmp/.webif/file-httpd.conf &&
HTTPD_CONFIG_FILE=/tmp/.webif/file-httpd.conf ||
HTTPD_CONFIG_FILE=/etc/httpd.conf
-cat $HTTPD_CONFIG_FILE | awk '
-BEGIN {
- FS=":"
- ucount = 0
- include("/usr/lib/webif/common.awk")
- start_form("Users")
- if ((ENVIRON["FORM_submit"] != "") &&
((ENVIRON["FORM_change_password_"$2] != "") ||
(ENVIRON["FORM_remove_user_"$2] == ""))) system("/bin/rm
/tmp/.webif/file-httpd.conf; touch/tmp/.webif/file-httpd.conf")
-}
-(($1 == "/cgi-bin/webif/") && (($2 != "root") && ($2 != "admin"))) {
+
+awk -F: -v "cachedir=$cachedir" -v "superuser=$superuser" '
+BEGIN { ucount = 0;
+ include("/usr/lib/webif/common.awk");
+ start_form("@TR<<Users>>");
+
+ if (ENVIRON["FORM_submit"] != "") {
+ if (ENVIRON["FORM_remove_user_"$2] != "") {
+ system("/bin/rm -f " cachedir "/cat" $2);
+ system("/bin/rm -f " cachedir "/subcat" $2);
+ system("/bin/rm /tmp/.webif/file-httpd.conf;
touch/tmp/.webif/file-httpd.conf");
+ } else if (ENVIRON["FORM_change_password_"$2] != "")
+ system("/bin/rm /tmp/.webif/file-httpd.conf;
touch/tmp/.webif/file-httpd.conf");
+ }
+}
+($1 == "/cgi-bin/webif/" && $2 != superuser && $2 != "admin") {
if (ENVIRON["FORM_remove_user_" $2] == "") {
- field($2)
- password("user_"$2, ENVIRON["FORM_user_" $2])
- field(" ","")
- submit("change_password_"$2, "Change Password")
- field(" ","")
- submit("remove_user_"$2, "Remove "$2)
- ucount = ucount + 1
+ field($2);
+ password("user_"$2, ENVIRON["FORM_user_" $2]);
+ submit("change_password_"$2, "@TR<<system_acl_changepw#Change
Password>>");
+ field(" ");
+ print "<span class=\"smalltext\"><a href=\""
ENVIRON["SCRIPT_NAME"] "?remove_user_"
$2 "\">@TR<<system_acl_remove_user#Remove user>> " $2 "</a></span>";
+ field(" ");
+ ucount = ucount + 1;
}
}
((ENVIRON["FORM_submit"] != "") && ($1 != "")) {
if (($1 == "/cgi-bin/webif/") && (ENVIRON["FORM_remove_user_"$2] == "")
&& (ENVIRON["FORM_change_password_"$2] == "")) {
- print $1":"$2":"$3 >> "/tmp/.webif/file-httpd.conf"
+ print $1":"$2":"$3 >>"/tmp/.webif/file-httpd.conf";
}
if ($1 != "/cgi-bin/webif/") {
- print $1":"$2 >> "/tmp/.webif/file-httpd.conf"
+ print $1":"$2 >>"/tmp/.webif/file-httpd.conf";
}
if (ENVIRON["FORM_change_password_"$2] != "") {
- ("httpd -m " ENVIRON["FORM_user_"$2]) | getline password
- print $1":"$2":"password >> "/tmp/.webif/file-httpd.conf"
+ ("httpd -m " ENVIRON["FORM_user_"$2]) | getline password;
+ print $1":"$2":"password >>"/tmp/.webif/file-httpd.conf";
}
}
END {
- if (ucount == 0) {
- print "<tr><td>No users defined."
- }
- end_form("","",1)
- start_form("Add User")
- field("Username")
- textinput3("user_add", ENVIRON["FORM_user_add"])
- field("Password")
- password("password_add")
- field("Confirm Password")
- password("password2_add")
- field(" ","")
- submit("add_user", "Add User")
- end_form("","",1)
-}'
+ if (ucount == 0)
+ print "<tr><td>No users defined.";
+
+ end_form("","",1);
+ start_form("@TR<<Add User>>");
+ field("@TR<<Username>>");
+ textinput3("user_add", ENVIRON["FORM_user_add"]);
+ field("@TR<<Password>>");
+ password("password_add");
+ field("@TR<<Confirm Password>>");
+ password("password2_add");
+ field(" ","");
+ submit("add_user", "@TR<<Add User>>");
+ end_form("","",1);
+}' $HTTPD_CONFIG_FILE 2>/dev/null
+
exists /tmp/.webif/file-httpd.conf &&
HTTPD_CONFIG_FILE=/tmp/.webif/file-httpd.conf ||
HTTPD_CONFIG_FILE=/etc/httpd.conf
-users=`cat $HTTPD_CONFIG_FILE | awk '
-BEGIN {
- FS=":"
-}
-($1 == "/cgi-bin/webif/") {
- if (($2 != "root") && ($2 != "admin")) print $2
-}`
+users=$(awk -F":" '($1 == "/cgi-bin/webif/") { if (($2 != "root") &&
($2 != "admin")) print $2 }' $HTTPD_CONFIG_FILE 2>/dev/null)
for user in $users; do
export user
- grep -H "##[W]EBIF:name:" /www/cgi-bin/webif/*.sh |sed
-e 's,^.*/\([a-zA-Z0-9\.\-]*\):\(.*\)$,\2:\1,' |sort -n |awk '
+ #[ -s $cachedir/subcat_${user} ] || init_cache "$user"
+ awk -F: '
BEGIN {
- FS=":"
include("/usr/lib/webif/common.awk")
config_load("webif_access_control")
- start_form("User:" ENVIRON["user"])
-}
-($2 == "name") {
+ start_form("@TR<<ACL User>>: " ENVIRON["user"])
+}
+{
if (ENVIRON["FORM_submit"] == "") {
- if ($3 != "Graphs") {
- var = config_get_bool(ENVIRON["user"], $3"_"$4, "0")
- }
- else {
+ if ($1 != "Graphs") {
+ var = config_get_bool(ENVIRON["user"], $1"_"$2, "0")
+ } else {
var = config_get_bool(ENVIRON["user"], "Graphs", "0")
}
- }
- else {
- if ($3 != "Graphs") {
- varorig = config_get_bool(ENVIRON["user"], $3"_"$4, "0")
- var2 = "FORM_" ENVIRON["user"] "_" $3 "_" $4
+ } else {
+ if ($1 != "Graphs") {
+ varorig = config_get_bool(ENVIRON["user"], $1"_"$2, "0")
+ var2 = "FORM_" ENVIRON["user"] "_" $1 "_" $2
var = ENVIRON[var2]
if (varorig != var) {
- uci_set("webif_access_control", ENVIRON["user"], $3 "_" $4, var)
- }
- }
- else {
+ uci_set("webif_access_control", ENVIRON["user"], $1 "_" $2, var)
+ }
+ } else {
varorig = config_get_bool(ENVIRON["user"], "Graphs", "0")
var2 = "FORM_" ENVIRON["user"] "_Graphs"
var = ENVIRON[var2]
@@ -133,19 +138,18 @@
}
}
}
- if ((category != $3) && ($3 != GRAPHS)) {
- field("<h2>@TR<<"$3">></h2>")
- }
- category = $3
- if ($3 != GRAPHS) {
- if ($3 == "Graphs") {
- GRAPHS = $3
+ if (($1 != category) && ($1 != GRAPHS)) {
+ field("<h2>@TR<<"$1">></h2>")
+ }
+ category = $1
+ if ($1 != GRAPHS) {
+ if ($1 == "Graphs") {
+ GRAPHS = $1
field("@TR<<Graphs>>")
select(ENVIRON["user"]"_Graphs", var)
- }
- else {
- field("@TR<<"$5">>")
- select(ENVIRON["user"]"_"$3"_"$4, var)
+ } else {
+ field("@TR<<"$3">>")
+ select(ENVIRON["user"]"_"$1"_"$2, var)
}
option("1", "@TR<<Enabled>>")
option("0", "@TR<<Disabled>>")
@@ -153,13 +157,15 @@
select_open = 0
}
}
-END {
- end_form("","",1)
-}'
+ END {
+ end_form("","",1)
+ }' $cachedir/subcat_$superuser
done
-footer %>
+footer
+
+?>
<!--
-##WEBIF:name:System:150:Access Control
+##WEBIF:name:System:160:Access Control
-->