summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2015-07-31 16:50:23 +0000
committerTed Trask <ttrask01@yahoo.com>2015-07-31 16:50:23 +0000
commitbfa5631ea54cf0ac4e895618ebb1e573a4e73e9e (patch)
treed2980b98dee9079821b0c2436384c3d0b1f012a0
parentad89906997afb99222400c060e12dd95c798147e (diff)
downloadacf-freeradius3-bfa5631ea54cf0ac4e895618ebb1e573a4e73e9e.tar.bz2
acf-freeradius3-bfa5631ea54cf0ac4e895618ebb1e573a4e73e9e.tar.xz
Modify logfile to get logging info from the config and use common view
-rw-r--r--freeradius3-controller.lua4
l---------[-rw-r--r--]freeradius3-logfile-html.lsp7
-rw-r--r--freeradius3-model.lua134
3 files changed, 111 insertions, 34 deletions
diff --git a/freeradius3-controller.lua b/freeradius3-controller.lua
index 29748d7..93446a1 100644
--- a/freeradius3-controller.lua
+++ b/freeradius3-controller.lua
@@ -58,4 +58,8 @@ function mymodule.editmacauthfile(self)
return self.handle_form(self, self.model.get_macauth_file, self.model.update_macauth_file, self.clientdata, "Save", "Edit File", "File Saved")
end
+function mymodule.logfile(self)
+ return self.model.get_logfile(self, self.clientdata)
+end
+
return mymodule
diff --git a/freeradius3-logfile-html.lsp b/freeradius3-logfile-html.lsp
index edb192d..ac8854f 100644..120000
--- a/freeradius3-logfile-html.lsp
+++ b/freeradius3-logfile-html.lsp
@@ -1,6 +1 @@
-<% local data, viewlibrary = ...
-%>
-
-<% if viewlibrary and viewlibrary.dispatch_component then
- viewlibrary.dispatch_component("alpine-baselayout/logfiles/view", {filename="/var/log/radius/radius.log"})
-end %>
+../logfile-html.lsp \ No newline at end of file
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