Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

授权服务器不可用时停用 #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

qlwz
Copy link
Contributor

@qlwz qlwz commented Oct 24, 2018

授权服务器pingurl不返回Pong时停用wifidog,直到返回Pong则重新启动

@@ -93,6 +93,7 @@ function M.parse()
proto, host, port, path, s.msg_path, gw_id)
end)

cfg.proc_flag = 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proc_flag变量不需要保存到全局的config里面。只有heartbeat.lua里面局部使用。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为wifidog-ng做了luci
在op中点击luci的保存&应用会自动执行 /etc/inid.d/wifidog-ng start
导致会重新执行 echo 'enabled=1' > /proc/wifidog-ng/config
所以如果使用bool类型判断就会出问题。
如:
刚启动授权服务器出错
enabled = false (设置内核为禁用)
luci修改授权服务器地址(服务器还是错的)
/etc/inid.d/wifidog-ng start(这里会设置内核为启动)
wifidog-ng config reload
ping服务器 还是出错,但是之前的enabled是flase,所以本次不修改内核状态,但是内核状态是启用的
所以bool类型的enabled 无法真正表示内核的状态。只能用int类型。当config reload重置为0

http.request(url)
local r = http.request(url)

if not r or #r < 4 or r:sub(0, 4) ~= 'Pong' then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可优化为:
if not r or r:sub(0, 4) ~= "Pong" then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有写过lua,不知道sub长度不足会不会出错

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里另外考虑到兼容apfree wifidog 所以没有直接使用 if not r or r ~= "Pong" then

@@ -33,7 +33,19 @@ local function heartbeat()

local url = string.format("%s&sys_uptime=%d&sys_memfree=%d&sys_load=%d&wifidog_uptime=%d",
cfg.ping_url, sysinfo.uptime, sysinfo.memory.free, sysinfo.load[1], os.time() - start_time)
http.request(url)
local r = http.request(url)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proc_flag变量名没有意义。
可以在这里定义一个局部变量
local enabled = false

if cfg.proc_flag ~= 1 then
cfg.proc_flag = 1
os.execute("echo 'enabled=0' > /proc/wifidog-ng/config")
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if enabled then
enabled = false
os.execute("echo 'enabled=0' > /proc/wifidog-ng/config")
end

cfg.proc_flag = 2
os.execute("echo 'enabled=1' > /proc/wifidog-ng/config")
end
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not enabled then
enabled = true
os.execute("echo 'enabled=1' > /proc/wifidog-ng/config")
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants