From 10086c539c85fd11cd1c5339e7659b8c04ffb525 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Mon, 4 Feb 2008 16:52:27 +0000 Subject: Config-tab information: Some config-info is displayed in the config-tab. Postmaster and etrn info (if it exists in the config). git-svn-id: svn://svn.alpinelinux.org/acf/fetchmail/trunk@688 ab2d0c66-481e-0410-8bed-d214d4d58bed --- fetchmail-config-html.lsp | 2 +- fetchmail-model.lua | 118 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 112 insertions(+), 8 deletions(-) diff --git a/fetchmail-config-html.lsp b/fetchmail-config-html.lsp index 9ae4af1..df784c7 100644 --- a/fetchmail-config-html.lsp +++ b/fetchmail-config-html.lsp @@ -194,7 +194,7 @@ if (cmdform) and (cmdform[tags[1]]) then DEBUGGING

DEBUG INFO: CFE

") io.write(html.cfe_unpack(form)) io.write("
") diff --git a/fetchmail-model.lua b/fetchmail-model.lua index 2be471b..5f589b4 100644 --- a/fetchmail-model.lua +++ b/fetchmail-model.lua @@ -85,6 +85,105 @@ local function getmailboxes() return mailboxes end +local function read_config() +--[[ +imap/pop3 lines are: +1 2 3 4 5 6 7 8 9 10 +poll protocol no dns username password +11 12 13 14 15 16 17 +is smtphost no rewrite fetchall + +pop3domain lines are: +1 2 3 4 5 6 7 8 9 10 11 12 +poll localdomainst protocol pop3 no dns username password +13 14 15 16 17 18 19 20 21 22 +to * here smtphost smtpaddress no rewrite fetchall + +etrn is: +1 2 3 4 5 6 +pool protocol etrn smtpdomain +--]] +-- local configcontent = {} + local configcontent_popimap = {} + local configcontent_popdomain = {} + local configcontent_postmaster = {} + local configcontent_etrn = {} + local path = configfile + local valid = nil + configcontenttable = fs.read_file_as_array(path) or {} + for k,v in pairs(configcontenttable) do + if (string.match(v, "^%s*#Begin Fetchmail Webconf")) then valid=1 end + if (valid) then +-- if not (configcontent[k]) then configcontent[k] = {} end +-- if not (configcontent_popimap[k]) then configcontent_popimap[k] = {} end +-- if not (configcontent_popdomain[k]) then configcontent_popdomain[k] = {} end + + local DISABLED = string.match(v, "^%s*(#)") + + -- Set parameters for POP3 or IMAP + local val = {RHOST=2, CHECK=9 ,METHOD=4, RBOX=8, PASSWD=10, LBOX=12, LHOST=14} + local configcontent = {} + configcontent[k] = {} + for kk,vv in pairs(val) do + configcontent[k][kk] = tostring(string.match(v,"^%s*" .. string.rep("%S*%s*",vv-1) .. "(%S*)%s*")) + end + -- Remove quotes from passwords + if (configcontent[k]["PASSWD"]) then + configcontent[k]["PASSWD"] = string.match(configcontent[k]["PASSWD"], "^\"(.-)\"") + end + -- Check if row is valid config + if (configcontent[k]["CHECK"]) and (string.lower(configcontent[k]["CHECK"]) == "password") then + table.insert(configcontent_popimap,configcontent[k]) + end + + -- Set parameters for POP3domain + local val = {RHOST=2, METHOD=6, RBOX=10, CHECK=11, PASSWD=12, LHOST=17, DOMAIN=19,} + local configcontent = {} + configcontent[k] = {} + for kk,vv in pairs(val) do + configcontent[k][kk] = tostring(string.match(v,"^%s*" .. string.rep("%S*%s*",vv-1) .. "(%S*)%s*")) + end + -- Remove quotes from passwords + if (configcontent[k]["PASSWD"]) then + configcontent[k]["PASSWD"] = string.match(configcontent[k]["PASSWD"], "^\"(.-)\"") + end + -- Check if row is valid config + if (configcontent[k]["CHECK"]) and (string.lower(configcontent[k]["CHECK"]) == "password") then + table.insert(configcontent_popdomain,configcontent[k]) + end + + -- Set parameters for etrn + local val = {ETRNSMTPHOST=2, CHECK=4, ETRNDOMAIN=6} + local configcontent = {} + configcontent[k] = {} + for kk,vv in pairs(val) do + configcontent[k][kk] = tostring(string.match(v,"^%s*" .. string.rep("%S*%s*",vv-1) .. "(%S*)%s*")) + end + -- Check if row is valid config + if (configcontent[k]["CHECK"]) and (string.lower(configcontent[k]["CHECK"]) == "etrn") then + configcontent_etrn=configcontent[k] + end + + -- Set parameters for postmaster + local val = {CHECK=2, POSTMASTER=3} + local configcontent = {} + configcontent[k] = {} + for kk,vv in pairs(val) do + configcontent[k][kk] = tostring(string.match(v,"^%s*" .. string.rep("%S*%s*",vv-1) .. "(%S*)%s*")) + end + -- Check if row is valid config + if (configcontent[k]["CHECK"]) and (string.lower(configcontent[k]["CHECK"]) == "postmaster") then + configcontent_postmaster=configcontent[k] + end + + + end + if (string.match(v, "^%s*#End Fetchmail Webconf")) then valid=nil end + end + configcontent = configcontent_postmaster + return configcontent,configcontent_etrn,configcontent_postmaster + +end -- ################################################################################ -- PUBLIC FUNCTIONS @@ -139,7 +238,6 @@ function get_filedetails() local config = {} local filenameerrtxt if (fs.is_file(path)) then - configcontent = getopts.getoptsfromfile(path) or config filedetails = fs.stat(path) config = getconfig(path) else @@ -190,12 +288,18 @@ function get_filedetails() end function getconfig() local config = {} - if (fs.is_file(configfile)) then - configcontent = getopts.getoptsfromfile(configfile) or config - else + local configcontent, configcontentetrn, configcontent_postmaster = read_config() + if not (fs.is_file(configfile)) then config["configfile"] = "Config file '".. configfile .. "' is missing!" end + config["debug"] = cfe({ + name="debug", + label = "Debug info", + type = "longtext", + value = configcontent, + }) + -- Next section selects which configurations we should show to the user @@ -214,17 +318,17 @@ function getconfig() config["postmaster"] = cfe({ name="postmaster", label = "Postmaster", - value = "xxx@xxx.xx", + value = configcontent_postmaster["POSTMASTER"], }) config["etrnremote"] = cfe({ name="etrnremote", label = "Remote server", - value = "xxx", + value = configcontentetrn["ETRNSMTPHOST"], }) config["etrnquedomain"] = cfe({ name="etrnquedomain", label = "Queued domain", - value = "xxx", + value = configcontentetrn["ETRNDOMAIN"], }) --[[ -- cgit v1.2.3