OpenWrt Forum Archive

Topic: WebIF: Wireless Survey, LAN-Status, WAN-Status, Reboot, ipkg

The content of this topic has been archived on 21 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

These are some scripts I've been sitting on since rc4 I thought I should share.

Just a simple script to do a wireless survey. Uses wl if available.

/www/cgi-bin/webif/wireless-survey.sh

#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh
header "Status" "Survey" "Wireless survey"
?>

<pre><?
use_wl() {
 wl scan
 sleep 3
 wl scanresults
}
use_iwlist() {
 iwlist $(nvram get wl0_ifname) scanning | grep -v Bit\ Rate
}
exists $(which wl) && use_wl || use_iwlist
?></pre>

<? footer ?>
<!--
##WEBIF:name:Status:4:Survey
-->

Even simpler scripts for lan and wan status, essentially the same as the current wireless status:
/www/cgi-bin/webif/lan-status.sh

#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh
header "Status" "WAN" "WAN status"
?>

<pre><? ifconfig 2>&1 | grep -A 6 "`nvram get wan_ifname`" ?></pre>

<? footer ?>
<!--
##WEBIF:name:Status:4:WAN
-->

/www/cgi-bin/webif/wan-status.sh

#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh
header "Status" "LAN" "LAN status"
?>

<pre><? ifconfig 2>&1 | grep -A 6 "`nvram get lan_ifname`" ?></pre>

<? footer ?>
<!--
##WEBIF:name:Status:3:LAN
-->

slightly modified ipkg.sh to move the add/remove buttons closer to the actual packages. Note the position of $1 and $3 in the origional lines compared to the updated lines. I thought it was hard to tell which link went with which package...
/www/cgi-bin/webif/ipkg.sh

Replace line 24 with:
 print "<tr><td style=\"width: 10%\"><a href=\"ipkg.sh?action=remove&pkg=" link "\">Remove</td><td>" $1 "</td></tr>"

Replace line 42 with:
 print "<tr><td style=\"Width: 10%\"><a href=\"ipkg.sh?action=install&pkg=" link "\">Install</td><td>" $3 "</td></tr>"

For the reboot script to work, a new category has to be made:
/www/cgi-bin/webif/.categories

##WEBIF:category:Info
##WEBIF:category:Status
##WEBIF:category:System
##WEBIF:category:Network
##WEBIF:category:Reboot

Then create the reboot script:
/www/cgi-bin/webif/reboot.sh

#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh
header "Reboot" "Rebooting" "Rebooting the Router"
timeout=60
?>
<meta http-equiv="refresh" content="<? echo $timeout ?>;url=http://<? nvram get lan_ipaddr ?>">

Will return in <? echo $timeout ?> seconds.
<? reboot ?>
<? footer ?>
<!--
##WEBIF:name:Reboot:1:Rebooting
-->

EDIT: Found a typo
EDIT2: Some people had problems with accents, changed to $()

(Last edited by bobpaul on 1 Aug 2006, 05:18)

Thanks (bobpaul). With my base needs met with OpenVPN now working your scripts and others will make the web interface more informative.

-s-

Thx You for thoses nice script, very useful.

Can't make wireless survey to work..

Here's error message:

Wireless survey
eth1: Operation not supported scan Initiate a scan. Default an active scan across all channels for any SSID. Optional arg: SSID, the SSID to scan. Options: -s S, --ssid=S SSID to scan -t ST, --scan_type=ST [active|passive] scan type --bss_type=BT [bss/infra|ibss/adhoc] bss type to scan -b MAC, --bssid=MAC particular BSSID MAC address to scan, xx:xx:xx:xx:xx:xx -n N, --nprobes=N number of probes per scanned channel -a N, --active=N dwell time per channel for active scanning -p N, --passive=N dwell time per channel for passive scanning -h N, --home=N dwell time for the home channel between channel scans -c L, --channels=L comma or space separated list of channels to scan

Also if I do

#wl scan;sleep 3;wl scanresults

in shell, it bugs about eth1: operation not supported

What's wrong..? (It's working as AP)

Well, first let's check for your wireless interface.

nvram get wl0_ifname

Note that that is a lowercase L, as in WireLess. Make a note of what this is (I suspect eth1 due to your error above).


Now, it looks like wl is bugging out, so lets try iwlist instead.

iwlist scanning

it should say name       Interface doesn't support scanning. for none wireless interfaces, but then show scan results for your wireless interface.

Find the line that looks like "eth1      Scan completed :" and match the interface name with what the nvram command gave you. If they match, then good iwlist works and wl just sucks on your router wink.

Change this line of /www/cgi-bin/webif/wireless-survey.sh

from:
exists `which wl` && use_wl || use_iwlist
to:
use_iwlist

If everything says scanning unsupported or the scan completed interface doesn't match then we have a bigger problem (but I wouldn't expect your router to be work properly...) I would think if we force it to use iwlist it'll work, though. What hardware are you running on out of curriosity?

I tried using the survey script also but it doesn't seem to work properly on my WRT54GL v1 router (running RC5 and wl is not installed).

It seems the script wouldn't execute the 'nvram get wl0_ifname' command correctly and I had to replace
the line --> iwlist `nvram get wl0_ifname` scanning | grep -v Bit\ Rate
with ------> iwlist $(nvram get wl0_ifname) scanning | grep -v Bit\ Rate

In any case, the 'iwlist eth1 scanning' command returns 'eth1  No scan results' both inside and outside the script.

Does iwlist work on the WRT54GL v1?

Good scripts by the way!  They gave me the incentive to start modifying the webif..  Thanks

I wonder if the copy/paste screwed it up. The single quotes should be accents, from the same key with the ~ $() does the same thing, so that's good, though. I'll change it up above

Can't make it work with these instructions either..

root@Gateway:/www/cgi-bin/webif# nvram get wl0_ifname
eth1
root@Gateway:/www/cgi-bin/webif# wl scan
eth1: Operation not supported
scan    Initiate a scan.
        Default an active scan across all channels for any SSID.
        Optional arg: SSID, the SSID to scan.
        Options:
        -s S, --ssid=S          SSID to scan
        -t ST, --scan_type=ST   [active|passive] scan type
        --bss_type=BT           [bss/infra|ibss/adhoc] bss type to scan
        -b MAC, --bssid=MAC     particular BSSID MAC address to scan, xx:xx:xx:xx:xx:xx
        -n N, --nprobes=N       number of probes per scanned channel
        -a N, --active=N        dwell time per channel for active scanning
        -p N, --passive=N       dwell time per channel for passive scanning
        -h N, --home=N          dwell time for the home channel between channel scans
        -c L, --channels=L      comma or space separated list of channels to scan
root@Gateway:/www/cgi-bin/webif# iwlist scanning
lo        Interface doesn't support scanning.

eth0      Interface doesn't support scanning.

eth1      No scan results
sit0      Interface doesn't support scanning.

br0       Interface doesn't support scanning.

vlan0     Interface doesn't support scanning.

vlan1     Interface doesn't support scanning.

imq0      Interface doesn't support scanning.

sixbone   Interface doesn't support scanning.
root@Gateway:/www/cgi-bin/webif# iwlist eth1 scanning
eth1      No scan results
root@Gateway:/www/cgi-bin/webif# wl scanresults
root@Gateway:/www/cgi-bin/webif#

It's a WRT54GS v1.0

could it be that "scan"-options are disabled when running in AP mode? IMO you would need a scan only before connecting to a WLAN as a client... didn't test it yet, just guessing... ;-)

greetz...

jake1981 wrote:

...

root@Gateway:/www/cgi-bin/webif# iwlist eth1 scanning
eth1      No scan results

...
It's a WRT54GS v1.0

That looks correct. It just means that the router can't find any APs within range. Do you have a computer with wireless near the router? Can it see APs?

Maybe Owat is right. I'll try it on my other router tonight.

Yes, I have 4 other wrt54gs routers, 4 of my WRT's are working as APs and 1 is working in client-bridge mode. 3 of my routers are version 4.0, scanning works just fine with these..

They can also see my neighbours AP..

(Last edited by jake1981 on 4 Aug 2006, 07:42)

I also have this problem.

I have a wrt54gs v1, there is a laptop in range.

# wl scan
eth1: Operation not supported

# iwlist eth1 scanning
eth1      No scan results
# iwlist eth1 ap
eth1      Interface doesn't have a list of Peers/Access-Point
# iwlist eth1 event
eth1      Wireless Events supported :
# iwlist eth1 bitrate
eth1      unknown bit-rate information.
# iwlist eth1 txpower
eth1      unknown transmit-power information.
        Current Tx-Power:18 dBm      (63 mW)
#

The rest of the iwlist functions work.

(Last edited by pfudd on 4 Aug 2006, 20:02)

Hi all,

from the OpenWRT documentation [http://wiki.openwrt.org/ClientModeHowto]:

You can now scan for nearby access points. If iwlist doesn't find any networks on the first run, repeat the scanning a few times.

TIP: With iwlist you can only scan for networks when your AP is in client mode.

But don't know what's the matter with wl.

The discussion might have continued from here.