starttime = mg.time(true) hostname = pihole.hostname() webhome = pihole.webhome() theme = pihole.webtheme() -- Get name of script by matching whatever is after the last "/" in the URI scriptname = mg.script_name:match(".*/(.*).lp$"):gsub("-", "/") -- Fall back to "index.lp" if no match is found (e.g. when accessing the root) if scriptname == nil or string.len(scriptname) == 0 then scriptname = "index.lp" end -- Boolean check if string starts with a given prefix function startsWith(text, prefix) return text:find(prefix, 1, true) == 1 end -- Function returning GET parameter value (or nil if not set) function GET(name) if not mg.request_info.query_string then return nil end return mg.request_info.query_string:match(name.."=([^&]*)") -- mg.get_var(mg.request_info.query_string, "REQUEST_URI") end -- Function checking if val is in tab function in_array (val, tab) for index, value in ipairs(tab) do if value == val then return true end end return false end -- Function to sanitize hostname containing invalid HTML characters function sanitize_hostname(str) -- Check if string contains any of the HTML special characters if str:find("&<>\"'") then return "invalid hostname" end -- Return the original string if no special characters are found return str end -- Sanitize hostname hostname = sanitize_hostname(hostname) -- Variable to check if user is already authenticated is_authenticated = mg.request_info.is_authenticated ?>