Commit 882fa928 authored by Ted Trask's avatar Ted Trask

Added "local" source to get logs from local filesystem.

parent 306ce92d
......@@ -563,6 +563,8 @@ local connecttosource = function(source, cookiesfile)
else
success = true
end
elseif source.method == "local" then
success = true
end
return success
end
......@@ -577,6 +579,8 @@ local getlogcandidates = function(source, cookiesfile)
for file in string.gmatch(resultpage, "download%?name=([^\"]+)") do
candidates[#candidates+1] = file
end
elseif source.method == "local" then
candidates = fs.find_files_as_array(nil, source.source)
end
return candidates
end
......@@ -588,6 +592,8 @@ local getlogfile = function(source, cookiesfile, logfile)
local f = io.popen(cmd)
filecontent = f:read("*a")
f:close()
elseif source.method == "local" then
filecontent = fs.read_file(logfile)
end
return filecontent
end
......@@ -597,6 +603,8 @@ local deletelogfile = function(source, cookiesfile, logfile)
local cmd = "wget -O - --no-check-certificate --load-cookies "..cookiesfile.." --post-data 'name="..logfile.."' '"..source.method.."://"..source.source.."/cgi-bin/acf/alpine-baselayout/logfiles/delete' 2>/dev/null"
local f = io.popen(cmd)
f:close()
elseif source.method == "local" then
os.remove(logfile)
end
end
......@@ -647,7 +655,12 @@ end
local validatesource = function(sourcedata)
local success = modelfunctions.validateselect(sourcedata.value.method)
for i,name in ipairs({"sourcename", "userid", "passwd", "source"}) do
local test = {"sourcename", "source"}
if sourcedata.value.method.value ~= "local" then
test[#test+1] = "userid"
test[#test+1] = "passwd"
end
for i,name in ipairs(test) do
if sourcedata.value[name].value == "" then
sourcedata.value[name].errtxt = "Cannot be empty"
success = false
......@@ -683,10 +696,10 @@ end
function getnewsource()
local source = {}
source.sourcename = cfe({ label="Source Name" })
source.method = cfe({ type="select", value="https", label="Method", option={"http", "https"} })
source.method = cfe({ type="select", value="local", label="Method", option={"http", "https", "local"} })
source.userid = cfe({ label="UserID" })
source.passwd = cfe({ label="Password" })
source.source = cfe({ label="Source Address" })
source.source = cfe({ value="/var/log", label="Source Location / Address" })
source.tzislocal = cfe({ type="boolean", value=false, label="Using local timezone" })
source.enabled = cfe({ type="boolean", value=false, label="Enabled" })
return cfe({ type="group", value=source, label="Source" })
......@@ -700,6 +713,8 @@ function createsource(sourcedata)
for name,val in pairs(sourcedata.value) do
source[name] = val.value
end
-- remove spaces from sourcename
source.sourcename = string.gsub(source.sourcename, "%s+$", "")
local res, err = pcall(function()
databaseconnect(DatabaseUser)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment