treewide: filter shell arguments through shellquote() where applicable
[project/luci.git] / applications / luci-app-adblock / luasrc / controller / adblock.lua
index efa99b5..763c0b4 100644 (file)
@@ -1,12 +1,11 @@
--- Copyright 2017 Dirk Brenken (dev@brenken.org)
+-- Copyright 2017-2018 Dirk Brenken (dev@brenken.org)
 -- This is free software, licensed under the Apache License, Version 2.0
 
 module("luci.controller.adblock", package.seeall)
 
-local fs = require("nixio.fs")
-local util = require("luci.util")
+local util  = require("luci.util")
 local templ = require("luci.template")
-local i18n = require("luci.i18n")
+local i18n  = require("luci.i18n")
 
 function index()
        if not nixio.fs.access("/etc/config/adblock") then
@@ -24,15 +23,21 @@ function index()
 end
 
 function logread()
-       local logfile = util.trim(util.exec("logread -e 'adblock'"))
+       local logfile
+
+       if nixio.fs.access("/var/log/messages") then
+               logfile = util.trim(util.exec("grep -F 'adblock-' /var/log/messages"))
+       else
+               logfile = util.trim(util.exec("logread -e 'adblock-'"))
+       end
        templ.render("adblock/logread", {title = i18n.translate("Adblock Logfile"), content = logfile})
 end
 
 function queryData(domain)
-       if domain and domain:match("^[a-zA-Z0-9%-%._]+$") then
+       if domain then
                luci.http.prepare_content("text/plain")
-               local cmd = "/etc/init.d/adblock query %q 2>&1"
-               local util = io.popen(cmd % domain)
+               local cmd = "/etc/init.d/adblock query %s 2>&1"
+               local util = io.popen(cmd % util.shellquote(domain))
                if util then
                        while true do
                                local line = util:read("*l")