From: Marek Vavrusa Date: Wed, 1 Jun 2016 07:08:20 +0000 (-0700) Subject: modules/daf: initial commit X-Git-Tag: v1.1.0~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ed94014adef94cbaa99372dce3470dd02b3da46;p=thirdparty%2Fknot-resolver.git modules/daf: initial commit --- diff --git a/doc/modules.rst b/doc/modules.rst index b40c802eb..83b169b3c 100644 --- a/doc/modules.rst +++ b/doc/modules.rst @@ -14,6 +14,7 @@ Knot DNS Resolver modules .. include:: ../modules/view/README.rst .. include:: ../modules/predict/README.rst .. include:: ../modules/http/README.rst +.. include:: ../modules/daf/README.rst .. include:: ../modules/graphite/README.rst .. include:: ../modules/kmemcached/README.rst .. include:: ../modules/redis/README.rst diff --git a/modules/daf/README.md b/modules/daf/README.md new file mode 100644 index 000000000..a267aaa7a --- /dev/null +++ b/modules/daf/README.md @@ -0,0 +1,13 @@ +.. _mod-daf: + +DNS Application Firewall +------------------------ + +This module is a high-level interface for other powerful filtering modules and DNS views. It provides an easy interface to apply and monitor DNS filtering rules and a persistent memory for them. It also provides a restful service interface and an HTTP interface. + +Example configuration +^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: lua + + modules = { 'http', 'daf' } diff --git a/modules/daf/daf.lua b/modules/daf/daf.lua new file mode 100644 index 000000000..1c8a7d140 --- /dev/null +++ b/modules/daf/daf.lua @@ -0,0 +1,44 @@ +local cqueues = require('cqueues') + +-- Module declaration +local M = { +} + +-- @function Public-facing API +local function api(h, stream) + print('DAF: ') + for k,v in h:each() do print(k,v) end +end + +-- @function Publish DAF statistics +local function publish(h, ws) + local ok = true + while ok do + -- Publish stats updates periodically + local push = tojson({}) + ok = ws:send(push) + cqueues.sleep(0.5) + end + ws:close() +end + +-- @function Cleanup module +function M.deinit() + if http then + http.endpoints['/daf'] = nil + http.snippets['/daf'] = nil + end +end + +-- @function Configure module +function M.config(conf) + if not http then error('"http" module is not loaded, cannot load DAF') end + -- Export API and data publisher + http.endpoints['/daf'] = {'application/json', api, publish} + -- Export snippet + http.snippets['/daf'] = {'Application Firewall', [[ +

Hello world!

+ ]]} +end + +return M \ No newline at end of file diff --git a/modules/daf/daf.mk b/modules/daf/daf.mk new file mode 100644 index 000000000..bd66866ae --- /dev/null +++ b/modules/daf/daf.mk @@ -0,0 +1,2 @@ +daf_SOURCES := daf.lua +$(call make_lua_module,daf) diff --git a/modules/modules.mk b/modules/modules.mk index 5924c3928..a3647382c 100644 --- a/modules/modules.mk +++ b/modules/modules.mk @@ -20,7 +20,8 @@ modules_TARGETS += ketcd \ predict \ dns64 \ renumber \ - http + http \ + daf endif # List of Golang modules