From db3ebe1722620d22fcfa33b9fcaca1d7608cb09d Mon Sep 17 00:00:00 2001 From: onefang Date: Sat, 14 Dec 2019 08:03:02 +1000 Subject: Validate the mirrors_list FQDN and BaseURL. Also, move the relatd tests into this new function. --- apt-panopticon.lua | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/apt-panopticon.lua b/apt-panopticon.lua index b87bf72..502ed6a 100755 --- a/apt-panopticon.lua +++ b/apt-panopticon.lua @@ -580,6 +580,26 @@ local downloads = function(host, URL, meta, release, list) end +local validateURL = function(m) + if " " == m.BaseURL:sub(-1, -1) then + W("space at end of BaseURL in mirror_list.txt! " .. m.BaseURL, "", "", m.FQDN) + m.BaseURL = m.BaseURL:sub(1, -2) + end + if "/" == m.BaseURL:sub(-1, -1) then + W("slash at end of BaseURL in mirror_list.txt! " .. m.BaseURL, "", "", m.FQDN) + m.BaseURL = m.BaseURL:sub(1, -2) + end + local p = url.parse("http://" .. m.BaseURL) + if nil == p.path then p.path = '' end + if nil ~= p.port then p.authority = authority .. ':' .. p.port end + if m.FQDN ~= p.authority then W("Something wrong in FDQN from mirror_list.txt! " .. m.FDQN, "", "", p.authority) end + if m.BaseURL ~= (p.authority .. p.path) then W("Something wrong in BaseURL from mirror_list.txt! " .. m.BaseURL, "", "", p.authority) end + if (nil ~= p.query) or (nil ~= p.fragment) or (nil ~= p.params) then W("Something wrong in BaseURL from mirror_list.txt, should be nothing after the path! " .. m.BaseURL, "", "", p.authority) end + if (nil ~= p.user) or (nil ~= p.userinfo) or (nil ~= p.password) then W("Something wrong in BaseURL from mirror_list.txt, should be no credentials! " .. m.BaseURL, "", "", p.authority) end + m.FQDN = p.authority + m.BaseURL = p.authority .. p.path + return m +end local getMirrors = function () local mirrors = {} local host = "" @@ -595,7 +615,7 @@ local getMirrors = function () d = string.lower(d) if "FQDN" == t then if "" ~= host then - mirrors[host] = m + mirrors[host] = validateURL(m) m = {} active = true end @@ -620,7 +640,7 @@ local getMirrors = function () end end if "" ~= host --[[and active]] then - mirrors[host] = m + mirrors[host] = validateURL(m) end end if APT.testing("DNSRR") then @@ -869,14 +889,6 @@ else checkHost(APT.options.referenceSite.value) for k, m in pairs(APT.mirrors) do - if "/" == m.BaseURL:sub(-1, -1) then - W("slash at end of BaseURL in mirror_list.txt! " .. m.BaseURL, "", "", m.FQDN) - m.BaseURL = m.BaseURL:sub(1, -2) - end - if " " == m.BaseURL:sub(-1, -1) then - W("space at end of BaseURL in mirror_list.txt! " .. m.BaseURL, "", "", m.FQDN) - m.BaseURL = m.BaseURL:sub(1, -2) - end local pu = url.parse("http://" .. m.BaseURL) if APT.options.referenceSite.value ~= pu.host then checkHost(m.BaseURL) -- cgit v1.1