log_level("info")
-- log_level("debug")
+-- Load required Lua modules
+local bit = require("bit")
local csv = require("csv")
+local notify = require("cqueues.notify")
+
+-- Helper function which will call a function if a given file has been changed
+local function call_on_change(path, callback)
+ -- Split the path into parent directory and filename
+ local dir, file = string.match(path, "(.*)/([^/]+)")
+
+ -- If we could not split the path (e.g. because it doesn't contain a /)
+ -- we will assume the file is in the current working directory
+ if not dir and not file then
+ dir = "."
+ file = path
+ end
+
+ -- Create a new watcher for the directory
+ local watcher = notify.opendir(dir)
+
+ -- Wake up when the file has changed
+ watcher:add(file, bit.bxor(notify.CREATE, notify.MODIFY))
+
+ -- Register a function that will call the callback on any changes
+ worker.coroutine(function()
+ for _, name in watcher:changes() do
+ callback()
+ end
+ end)
+end
local ETHERNET_SETTINGS_FILE = "/var/ipfire/ethernet/settings"
local DNS_SETTINGS_FILE = "/var/ipfire/dns/settings"