Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fqrouter/4660859 to your computer and use it in GitHub Desktop.
Save fqrouter/4660859 to your computer and use it in GitHub Desktop.
if [ -f /tmp/skip-only-enable-connectable-sta-mode-wifi-interface ] ; then
logger -s -t fqrouter skip-only-enable-connectable-sta-mode-wifi-interface found
return
fi
if [ "remove" == "$ACTION" -a "wlan0" == "$INTERFACE" ] ; then
/etc/init.d/disable_sta_mode_wifi_interfaces start
fi
if [ "add" == "$ACTION" -a "wlan0" == "$INTERFACE" ] ; then
logger -s -t fqrouter try to bring up sta mode wifi interface
sta-mode-wifi-interface-up &
fi
#!/bin/sh /etc/rc.common
START=19 # just before network start
disable_sta_mode_wifi_interface() {
local section="$1"
config_get mode $section 'mode'
config_get ssid $section 'ssid'
if [ sta == $mode ] ; then
logger -s -t fqrouter disable sta mode wifi interface $ssid
uci_set wireless $section disabled 1
fi
}
start() {
config_load 'wireless'
config_foreach disable_sta_mode_wifi_interface 'wifi-iface'
uci_commit
logger -s -t fqrouter all sta mode wifi interfaces disabled
}
#!/usr/bin/lua
require 'uci'
require 'dumper'
require 'nixio'
local pid_file = io.open('/tmp/sta-mode-wifi-interface-up.pid', 'r')
if pid_file ~= nil then
local that_pid = pid_file:read('*a')
io.close(pid_file)
os.execute('logger -s -t fqrouter sta-mode-wifi-interface-up that pid is: ' .. that_pid)
local cmdline_file = io.open('/proc/' .. that_pid .. '/cmdline', 'r')
if cmdline_file ~= nil then
io.close(cmdline_file)
os.execute('logger -s -t fqrouter sta-mode-wifi-interface-up found another instance ' .. that_pid)
os.exit()
end
end
local this_pid = nixio.getpid()
os.execute('echo -n ' .. this_pid .. ' > /tmp/sta-mode-wifi-interface-up.pid')
os.execute('logger -s -t fqrouter sta-mode-wifi-interface-up.pid: ' .. this_pid)
x = uci.cursor()
function exit_if_sta_mode_wifi_interface_enabled(section)
if 'sta' == section.mode and '0' == section.disabled then
os.execute('logger -s -t fqrouter std mod wifi interface ' .. section.ssid .. ' already enabled')
os.exit()
end
end
x:foreach('wireless', 'wifi-iface', exit_if_sta_mode_wifi_interface_enabled)
os.execute('logger -s -t fqrouter no sta mode wifi interface enabled')
function is_interface_up(ifname)
local f = assert(io.popen('ifconfig '..ifname, 'r'))
local output = assert(f:read('*a'))
return output:find('RUNNING')
end
for count=1,10 do
if is_interface_up('wlan0') then
break
end
os.execute('sleep 1')
end
if not is_interface_up('wlan0') then
os.execute('logger -s -t fqrouter wlan0 not up in given time')
os.exit()
end
os.execute('logger -s -t fqrouter wlan0 is up')
local ssid_list = {}
local ssid_present = {}
for i = 1, 3 do
local iw = require'luci.sys'.wifi.getiwinfo('radio0')
for k, v in ipairs(iw.scanlist or {}) do
if v.ssid ~= nil and ssid_present[v.ssid] == nil then
table.insert(ssid_list, v.ssid)
ssid_present[v.ssid] = v
end
end
os.execute('logger -s -t fqrouter "ssid list: ' .. table.concat(ssid_list, ', ') .. '"')
end
local no_sta_mode_wifi_interface_configured = true
function enable_sta_mode_wifi_interface(section)
if 'sta' == section.mode then
no_sta_mode_wifi_interface_configured = false
if ssid_present[section.ssid] ~= nil then
os.execute('logger -s -t fqrouter found ' .. section.ssid)
x:set('wireless', section['.name'], 'disabled', 0)
x:commit('wireless')
os.execute('touch /tmp/skip-only-enable-connectable-sta-mode-wifi-interface')
os.execute('wifi up')
os.execute('rm /tmp/skip-only-enable-connectable-sta-mode-wifi-interface')
os.execute('sleep 10')
if is_interface_up('wlan0-1') then
os.execute('rm /tmp/upstream-status')
else
os.execute('echo "UPSTREAM_TIMEOUT" > /tmp/upstream-status')
os.execute('logger -s -t fqrouter sta mode wifi interface not up in given time')
x:set('wireless', section['.name'], 'disabled', 1)
x:commit('wireless')
os.execute('touch /tmp/skip-only-enable-connectable-sta-mode-wifi-interface')
os.execute('wifi down')
os.execute('wifi up')
os.execute('rm /tmp/skip-only-enable-connectable-sta-mode-wifi-interface')
end
os.exit()
end
end
end
x = uci.cursor()
x:foreach('wireless', 'wifi-iface', enable_sta_mode_wifi_interface)
if no_sta_mode_wifi_interface_configured then
os.execute('echo "UPSTREAM_NOT_CONFIGURED" > /tmp/upstream-status')
os.execute('logger -s -t fqrouter no sta mode wifi interface configured')
else
os.execute('echo "UPSTREAM_NOT_AVAILABLE" > /tmp/upstream-status')
os.execute('logger -s -t fqrouter no sta mode wifi interface available')
end
@wayilive
Copy link

hey,我是从你的博客搜索过来的,因为wp那边一直注册不了,我想问一下,如果我不用装你定制的固件,但又想实现功能,请问能如何利用、配置你的脚本呢?其实我的需求主要是:

1.家里的wifi、办公室的wifi、华为e5的3g路由,如何让703n在多个常用路由之间无缝的切换?当一个没信号时自动切到另一个?然后中继这些路由的信号?目前中继一个是可以了,但没办法自动切换……

2.在实现1的基础上,能不能划分vlan?一个用密码接入,可以翻墙,一个无密码,不能翻墙?或者是一个无线一个有线?

3.在1的基础上,当有wifi时,网口当lan口用,当没有wifi时,将703n的网口到有线网上,即可将有线网转为无线网?

我想第1个应该是能利用你的脚本来实现的,但请问需要加装什么软件包,和如何部署配置这些脚本呢?谢谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment