module(..., package.seeall) -- Load libraries require("modelfunctions") require("validator") -- Set variables local configfile = "/etc/opennhrp/opennhrp.conf" local processname = "opennhrp" local packagename = "opennhrp" --[[ local descr = { Type = { ['incomplete']="The protocol address is being resolved", ['negative']="This protocol address is not available", ['cached']="Protocol address was resolved successfully", ['route']="This is a dynamic shortcut", ['dynamic']="This entry is from a node that connected to us", ['local']="Local interface address", ['static']="Static mapping from configuration file (e.g. address of core)", }, Flags= { -- ['up']="Connection is fully usable", ['lower-up']="ipsec connections is up, but registration is not yet done", }, } -- ################################################################################ -- LOCAL FUNCTIONS local function opennhrpctl_show() local cmd_output_result={} local cmd_output_result_table={} local cmd_output_error, opennhrpstatus local cmd = "/usr/sbin/opennhrpctl show 2>/dev/null" local f = io.popen( cmd ) for line in f:lines() do if string.find(line, "^Status:") then opennhrpstatus=line else table.insert(cmd_output_result, line) end end f:close() local cnt = 0 for k,v in pairs(cmd_output_result) do if string.find(v,"^Interface") then cnt = cnt + 1 cmd_output_result_table[cnt] = {} end if ( cnt > 0 ) and (v ~= "") then local k = string.match(v,"^(.-):%s?.*") cmd_output_result_table[cnt][k]=cfe({value=string.match(v,"^.-:%s?(.*)")}) local statusdescription = string.lower(string.match(v,"^.-:%s?(.*)")) if (type(descr[k]) == "table") then cmd_output_result_table[cnt][k]['descr']=descr[k][statusdescription] end end end local peers_list = {} for k,v in pairs(cmd_output_result_table) do if (v.Interface.value) and not (peers_list[v.Interface.value]) then peers_list[v.Interface.value] = {} end table.insert(peers_list[v.Interface.value], v) end return peers_list,opennhrpstatus,cmd_output_error end --]] -- ################################################################################ -- PUBLIC FUNCTIONS function startstop_service(action) return modelfunctions.startstop_service(processname, action) end function getstatus() return modelfunctions.getstatus(processname, packagename, "Opennhrp Status") end function getshowreport() local show = cfe({ type="longtext", label="OpenNHRP show report" }) local cmd = "/usr/sbin/opennhrpctl show 2>/dev/null" local f = io.popen( cmd ) show.value = f:read("*a") or "" return show end function getconfig() return cfe({ type="table", value={}, label="Edit Config" }) end function setconfig(config) return config end function getconfigfile() local filedetails = modelfunctions.getfiledetails(configfile) -- Validate return filedetails end function setconfigfile(filedetails) -- Validate --local result, filedetails = validateconfigfile(filedetails) local result = true if result then fs.write_file(configfile, format.dostounix(filedetails.value.filecontent.value)) end return filedetails end