]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
Added periodicity and fixed status messages.
authorŠtěpán Balážik <stepan.balazik@nic.cz>
Wed, 19 Oct 2016 11:10:13 +0000 (13:10 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 20 Oct 2016 16:45:14 +0000 (18:45 +0200)
modules/version/README.rst
modules/version/version.lua

index cc8a6e17c84cd928cd3bab4c00ec9ebf5ce8bec5..314a28260e3cb5ffe5758293a68af1a22526cbfd 100644 (file)
@@ -5,6 +5,13 @@ Version
 
 Module checks for new version and CVE_.
 
+Configuration
+^^^^^^^^^^^^^
+.. code-block:: lua
+
+          version.config(2*day)
+       -- configure period of check (defaults to 1*day)
+
 Running
 ^^^^^^^
 
@@ -12,4 +19,4 @@ Running
 
           modules.load("version")
 
-.. _cves: https://cve.mitre.org/
+.. _cve: https://cve.mitre.org/
index 6d3a9c3cb43e5a35d72b45bf3eaa8527df5a3c0c..20e377f4d53f58ea338eb56d9fac5fd84a881fbb 100644 (file)
@@ -60,7 +60,7 @@ local function parse(record)
     local version = parseVersion(str)
     local localVersion = getLocalVersion()
     if version ~= localVersion then
-        output = output .. string.format("[version] Newer version of Knot DNS Resolver is available. (Current: %s, Available: %s)\n", localVersion, version)
+        output = output .. string.format("[version] Current version of Knot DNS Resolver is different from the latest stable one available. (Current: %s, Latest stable: %s)\n", localVersion, version)
     end
     if CVE ~= "N/A" then
         output = output .. string.format("[version] CVE: %s\n", CVE)
@@ -79,8 +79,35 @@ local function request (answer)
     end
 end
 
-function M.init()
+local function callhome()
     resolve('et.knot-resolver.cz', kres.type.TXT, kres.class.IN, 0, request)
 end
 
+function M.config(period)
+    if period == nil then 
+        print("Expected number of miliseconds. Using default version.config(1*day)")
+        return
+    end
+    if type(period) ~= "number" then
+        print("Expected number of miliseconds. Using default version.config(1*day)")
+        return
+    end
+    version.period = period
+    print(period)
+    if M.ev then event.cancel(M.ev) end
+    M.ev = event.recurrent(M.period, callhome)
+end
+
+
+function M.init()
+    if period == nil then 
+        M.period = 1*day
+    end
+    M.ev = event.recurrent(M.period, callhome)
+end
+
+function M.deinit()
+    if M.ev then event.cancel(M.ev) end
+end
+
 return M
\ No newline at end of file