]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules/daf: initial commit
authorMarek Vavrusa <marek@vavrusa.com>
Wed, 1 Jun 2016 07:08:20 +0000 (00:08 -0700)
committerMarek Vavrusa <marek@vavrusa.com>
Wed, 6 Jul 2016 06:33:38 +0000 (23:33 -0700)
doc/modules.rst
modules/daf/README.md [new file with mode: 0644]
modules/daf/daf.lua [new file with mode: 0644]
modules/daf/daf.mk [new file with mode: 0644]
modules/modules.mk

index b40c802ebde7c8f437964f2f1712e2afdfd8fe68..83b169b3c9301def5ea5f6c8c457f08e2d4661a9 100644 (file)
@@ -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 (file)
index 0000000..a267aaa
--- /dev/null
@@ -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 (file)
index 0000000..1c8a7d1
--- /dev/null
@@ -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', [[
+               <p>Hello world!</p>
+       ]]}
+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 (file)
index 0000000..bd66866
--- /dev/null
@@ -0,0 +1,2 @@
+daf_SOURCES := daf.lua
+$(call make_lua_module,daf)
index 5924c39281c2c7cd75a55f2f48347ebfc09ba778..a3647382ce884ebe2231d5041cd8d5df2fdbee70 100644 (file)
@@ -20,7 +20,8 @@ modules_TARGETS += ketcd \
                    predict \
                    dns64 \
                    renumber \
-                   http
+                   http \
+                   daf
 endif
 
 # List of Golang modules