diff options
Diffstat (limited to 'freeradius3-model.lua')
-rw-r--r-- | freeradius3-model.lua | 134 |
1 files changed, 106 insertions, 28 deletions
diff --git a/freeradius3-model.lua b/freeradius3-model.lua index e3b1261..cf76e3f 100644 --- a/freeradius3-model.lua +++ b/freeradius3-model.lua @@ -12,10 +12,10 @@ subprocess = require("subprocess") local processname = "radiusd" local packagename = "freeradius3" local baseurl = "/etc/raddb" +local configfile = "/etc/raddb/radiusd.conf" local owner = "root" local group = "radius" -local config local configtable local macauthfiles @@ -27,24 +27,34 @@ local is_valid_filename = function(filename) return validator.is_valid_filename(filename) and string.match(dirname, baseurl) and not string.match(dirname, "%.%.") end -local get_config = function() - if config then return true end - local code, cmdresult = subprocess.call_capture({"radiusd", "-XC"}) - if 0 ~= code then - return false, string.match(cmdresult, "([^\n]+)\n$") - end - config = {} - for line in string.gmatch(cmdresult, "[^\n]+") do - if string.match(line, "^including") then - elseif string.match(line, "^Using") then - elseif string.match(line, "^reading") then - elseif string.match(line, "^Ignoring") then - --elseif string.match(line, "^Configuration ") then - elseif string.match(line, "^radiusd: ") then - elseif string.match(line, "^rlm_passwd: ") then - elseif string.match(line, "^%[/etc/raddb/") then - elseif string.match(line, "^%s*#") then - elseif string.match(line, "^%c") then +local get_config = function(filecontent) + if not filecontent then + local code, cmdresult = subprocess.call_capture({"radiusd", "-XC"}) + if 0 ~= code then + return nil, string.match(cmdresult, "([^\n]+)\n$") + end + filecontent = {} + for line in string.gmatch(cmdresult, "[^\n]+") do + if string.match(line, "^including") then + elseif string.match(line, "^Using") then + elseif string.match(line, "^reading") then + elseif string.match(line, "^Ignoring") then + --elseif string.match(line, "^Configuration ") then + elseif string.match(line, "^radiusd: ") then + elseif string.match(line, "^rlm_passwd: ") then + elseif string.match(line, "^%[/etc/raddb/") then + elseif string.match(line, "^%s*#") then + elseif string.match(line, "^%c") then + else + filecontent[#filecontent+1] = line + end + end + filecontent[#filecontent] = nil + end + local config = {} + for i,line in ipairs(filecontent) do + if string.match(line, "^%s*#") then + elseif string.match(line, "^%s*$") then else -- We want to remove spaces at beginning or end, and comments from end (being careful of quotes) local tmp = string.match(line, "%S.*") @@ -66,7 +76,6 @@ local get_config = function() config[#config+1] = tmp end end - config[#config] = nil -- At this point, every line should have {, =, or } -- We will parse the lines to create a table structure @@ -91,23 +100,45 @@ local get_config = function() result[#result+1] = {name=name, value=value} else mymodule.logevent("radiusd bad config line:"..config[i]) + i = i+1 end end return result, i+1 end - configtable = parselines(1) - config = table.concat(config,"\n") - - return true + return (parselines(1)), nil +end + +local function replacetags(configtable, value) + local tags = {} + while string.find(value, "%${") do + local tag = string.match(value, "%${%s*([^}]*)%s*}") + local tagvalue = "" + if tag ~= "" and tags[tag] then + tagvalue = tags[tag] + elseif tag ~= "" then + for i,first in ipairs(configtable) do + if string.find(first.name, "^"..tag.."$") then + tagvalue = first.value + tags[tag] = tagvalue + break + end + end + end + value = string.gsub(value, "%${%s*"..tag.."%s*}", tagvalue) + end + return value end local get_passwd_files = function() local files local configs - local result,errtxt = get_config() - if result then + local errtxt + if not configtable then + configtable,errtxt = get_config() + end + if configtable then -- Find the files by searching for modules / passwd files = {} configs = {} @@ -311,8 +342,11 @@ local get_macauth_files = function() return macauthfiles end - local result,errtxt = get_config() - if result then + local errtxt + if not configtable then + configtable,errtxt = get_config() + end + if configtable then -- Find the files by searching for modules / files / usersfile where key="%{Calling-Station-Id}" macauthfiles = {} for i,first in ipairs(configtable) do @@ -646,4 +680,48 @@ function mymodule.update_macauth_file(self, filedetails) return ret end +function mymodule.get_logfile(self, clientdata) + local retval = cfe({ type="group", value={}, label="Log File Configuration" }) + retval.value.facility = cfe({value="daemon", label="Syslog Facility"}) + retval.value.grep = cfe({ value="radiusd", label="Grep" }) + retval.value.filename = cfe({value="/var/log/radius/radius.log", label="File name"}) + + -- Unfortunately, the output of get_config doesn't seem to have the proper log settings + -- so, we need to parse the actual config file + local configtable,errtxt = get_config(fs.read_file_as_array(configfile)) + if configtable then + -- Find the files by searching for main / log + files = {} + configs = {} + for i,first in ipairs(configtable) do + if string.find(first.name, "^log$") then + for j,second in ipairs(first.value) do + if string.find(second.name, "^destination$") then + if second.value == "files" then + retval.value.facility = nil + retval.value.grep = nil + else + retval.value.filename = nil + end + elseif string.find(second.name, "^file$") then + if retval.value.filename then + retval.value.filename.value = replacetags(configtable, second.value) + end + elseif string.find(second.name, "^syslog_facility$") then + if retval.value.facility then + retval.value.facility.value = string.lower(second.value) + end + end + end + end + end + -- Default is log to file + if retval.value.facility and retval.value.filename then + retval.value.facility = nil + retval.value.grep = nil + end + end + return retval +end + return mymodule |