local rsm_serials = require("luamods/rsm_serials")
local command = require("luamods/command")
local layout = require("luamods/layout")
local cgi = require("luamods/cgi")
local rsm_conf = require("config/rsm_conf")
local db = require("luamods/db")
header = layout.getHeader()
footer = layout.getFooter()
userLevel = db.getPriv(layout.username) or 1
function log(m)
command.ex([[logger -t webconfig ]]..[["]]..m..[["]])
end
if (userLevel == 1) then
buttonControl = " disabled"
inputControl = " readonly"
else
buttonControl = ""
inputControl = ""
end
serialConfig = command.ex([[cat ]]..rsm_conf.serialconfig_path) or ""
modbusConfig = command.ex([[cat ]]..rsm_conf.mdd_xml_path) or ""
templatesFiles = {}
if (modbusConfig ~= "") then
modbusPath = modbusConfig:match([[(.-)]]) or ""
templatesPath = modbusConfig:match([[(.-)]]) or ""
if (templatesPath ~= "") then
templatesFiles = command.getFilesInTable(templatesPath)
end
end
if (cgi.post.deleteButton == "Delete Device") and (userLevel ~= 1) then
file = cgi.post.file or ""
file = file:gsub("[^%w%.]+","")
command.ex(rsm_conf.mdd_down)
command.ex([[rm ]]..modbusPath..[[/]]..file)
command.ex(rsm_conf.mdd_up)
label = cgi.post.label or "unknown"
bus = cgi.post.bus or "unknown"
-- Stop here
content = [[
Edit ModBus Device
Device Deleted
Device with filename "]]..file..[[" has been removed.
]]
print(header..content..footer)
os.exit()
end
end
newLabel = cgi.post.label or "unknown"
newTemplate = cgi.post.template or "unknown"
newConfig = cgi.post.config or rsm_conf.serialconfig_path
newPort = cgi.post.bus or "unknown"
newOwner = "mdd"
newSlave = cgi.post.slave or "unknown"
newMuxport = cgi.post.muxport or "unknown"
newMuxslave = cgi.post.muxslave or "unknown"
-- new --
newMuxbaud = cgi.post.muxbaud or "unknown"
newMuxparity = cgi.post.muxparity or "unknown"
newMuxdata = cgi.post.muxdata or "unknown"
newMuxstop = cgi.post.muxstop or "unknown"
newMuxtype = cgi.post.muxtype or "unknown"
newXML = [[
]]..newSerial..[[
]]..newTemplate..[[
]]..newConfig..[[]]..newPort..[[]]..newOwner..[[]]..newSlave..[[]]..newMuxport..[[]]..newMuxslave..[[]]..newMuxbaud..[[]]..newMuxparity..[[]]..newMuxdata..[[]]..newMuxstop..[[]]..newMuxtype..[[
]]
command.ex(rsm_conf.mdd_down)
command.writefile(modbusPath..[[/]]..newFile, newXML)
command.ex(rsm_conf.mdd_up)
filename = newFile
saved = 1
mode = "edit"
else
filename = cgi.get.file or ""
if (filename == "") then
mode = "new"
else
filename = filename:gsub("[^%w%.]+","")
mode = "edit"
end
end
bus = cgi.get.bus or cgi.post.bus or ""
b, bCfg = serialConfig:match([[(.-)]])
if (b == bus) and (bCfg ~= nil) then
if bCfg:match("%s-mdd%s-") == nil then
mismatch = 1
else
mismatch = 0
end
else
mismatch = 1
end
if (mode == "edit") then
cfg = command.ex([[cat ]]..modbusPath..[[/]]..filename) or ""
if (cfg:match("(.+)") == nil) then
-- bail on error
content = [[
Edit ModBus Device
Invalid file
The specified file does not appear to be a valid ModBus device file.