gluon/package/gluon-config-mode/files/usr/lib/lua/luci/tools/config-mode.lua

30 lines
758 B
Lua
Raw Normal View History

2013-09-28 21:18:36 +00:00
local luci = require "luci"
local io = require "io"
module "luci.tools.config-mode"
2013-09-28 21:18:36 +00:00
function setup_fastd_secret(name)
local uci = luci.model.uci.cursor()
local secret = uci:get("fastd", name, "secret")
if not secret or not secret:match("%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x") then
local f = io.popen("fastd --generate-key --machine-readable", "r")
local secret = f:read("*a")
f:close()
uci:set("fastd", name, "secret", secret)
uci:save("fastd")
uci:commit("fastd")
end
end
function get_fastd_pubkey(name)
local f = io.popen("/etc/init.d/fastd show_key " .. name, "r")
local key = f:read("*a")
f:close()
return key
end