Verified Commit fcdf8d6e authored by Marek Vavruša's avatar Marek Vavruša Committed by Tomas Krizek

added package_version() in Lua, removed version module

The package_version() function returns current build information.
Removed the version module instead of fixing, as it's being obsoleted.
parent 97a43e26
......@@ -65,7 +65,6 @@ kresd.amalg.c
libkres.amalg.c
/doc/kresd.8
/libkres.pc
/modules/version/version.lua
/tags
/coverage
/coverage.stats
......@@ -3,6 +3,7 @@ new_read_globals = {
'help',
'quit',
'hostname',
'package_version',
'moduledir',
'user',
'verbose',
......
......@@ -2,7 +2,7 @@
MAJOR := 2
MINOR := 4
PATCH := 0
EXTRA :=
EXTRA ?=
ABIVER := 7
BUILDMODE := dynamic
HARDENING := yes
......
......@@ -349,6 +349,18 @@ Environment
end
end)
.. function:: package_version()
:return: Current package version.
This returns current package version (the version of the binary) as a string.
.. code-block:: lua
> package_version()
2.1.1
Network configuration
^^^^^^^^^^^^^^^^^^^^^
......
......@@ -70,6 +70,7 @@ static int l_help(lua_State *L)
"help()\n show this help\n"
"quit()\n quit\n"
"hostname()\n hostname\n"
"package_version()\n return package version\n"
"user(name[, group])\n change process user (and group)\n"
"verbose(true|false)\n toggle verbose mode\n"
"option(opt[, new_val])\n get/set server option\n"
......@@ -209,6 +210,13 @@ static int l_hostname(lua_State *L)
return 1;
}
/** Return server package version. */
static int l_package_version(lua_State *L)
{
lua_pushliteral(L, PACKAGE_VERSION);
return 1;
}
char *engine_get_moduledir(struct engine *engine) {
return engine->moduledir;
}
......@@ -646,6 +654,8 @@ static int init_state(struct engine *engine)
lua_setglobal(engine->L, "quit");
lua_pushcfunction(engine->L, l_hostname);
lua_setglobal(engine->L, "hostname");
lua_pushcfunction(engine->L, l_package_version);
lua_setglobal(engine->L, "package_version");
lua_pushcfunction(engine->L, l_moduledir);
lua_setglobal(engine->L, "moduledir");
lua_pushcfunction(engine->L, l_verbose);
......
......@@ -23,7 +23,6 @@ Knot DNS Resolver modules
.. include:: ../modules/dns64/README.rst
.. include:: ../modules/renumber/README.rst
.. include:: ../modules/cookies/README.rst
.. include:: ../modules/version/README.rst
.. include:: ../modules/bogus_log/README.rst
.. include:: ../modules/workarounds/README.rst
.. include:: ../modules/dnstap/README.rst
......
......@@ -35,7 +35,6 @@ modules_TARGETS += bogus_log \
http \
daf \
workarounds \
version \
ta_signal_query \
priming \
serve_stale \
......
.. _mod-version:
Version
-------
Module checks for new version and CVE_, and issues warning messages.
Configuration
^^^^^^^^^^^^^
.. code-block:: lua
version.config(2*day)
-- configure period of check (defaults to 1*day)
Running
^^^^^^^
.. code-block:: lua
modules.load("version")
.. _cve: https://cve.mitre.org/
local M = {}
local function parseCVE(str)
local _, last = str:find("CVE")
local position = last+2
return str:sub(position,-1)
end
local function parseVersion(str)
local branch = "stable"
local _, last = str:find(branch)
local position = last+3
local delimiter = #str
if str:find("|",position) then
delimiter = str:find("|",position)-1
end
return str:sub(position, delimiter)
end
--Parses version from server and compares it to the installed one
local function parse(record)
local output = ""
local str = record:tostring(0)
local CVE = parseCVE(str)
local version = parseVersion(str)
local localVersion = '@VERSION@'
if version ~= localVersion then
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)
if CVE ~= "N/A" then
output = output .. string.format("[version] CVE: %s\n", CVE)
end
end
io.write(output)
end
--Parses record from answer
local function request (answer)
local pkt = kres.pkt_t(answer)
if pkt:rcode() == kres.rcode.NOERROR then
parse(pkt:rrsets(kres.section.ANSWER)[1])
else
log('[version] Request for version ended with rcode: ', pkt:rcode())
return
end
end
local function callhome()
resolve('et.knot-resolver.cz', kres.type.TXT, kres.class.IN, 0, request)
end
function M.config(period)
if not period or type(period) ~= "number" then
log("[version] Using default version.config(1*day)")
return
end
M.period = period
if M.ev then event.cancel(M.ev) end
M.ev = event.recurrent(M.period, callhome)
end
function M.init()
M.period = M.period or 1 * day
M.ev = event.recurrent(M.period, callhome)
end
function M.deinit()
if M.ev then event.cancel(M.ev) end
end
return M
version_SOURCES := version.lua
modules/version/version.lua: modules/version/version.lua.in
@$(call quiet,SED,$<) -e "s/@VERSION@/$(VERSION)/" $< > $@
$(call make_lua_module,version)
version-clean:
@$(call quiet,RM,modules/version/version.lua) modules/version/version.lua
.PHONY: version-clean
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment