summaryrefslogtreecommitdiffstats
path: root/aconf/modules/dnsmasq.lua
blob: 770a1d10cc61b05c331e634e7717a5322f092c70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
--[[
Copyright (c) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
--]]

local M = require('aconf.model')

local filter_conf = '/etc/dnsmasq-filter.conf'

local Address = M.new()
Address.address = M.net.IPAddress{be_mode='parent-value'}
Address.domain = M.String

local Filter = M.new()
Filter.enabled = M.Boolean{
   compute=function(obj)
      return M.node.contains(obj:fetch('../conf-file'), filter_conf)
   end,
   store=function(obj, value)
      local files = obj:fetch('../conf-file')
      if value then M.node.insert(files, filter_conf)
      else files[filter_conf] = nil end
   end
}
Filter.redirect_address = M.net.IPAddress{
   compute=function(obj)
      local addr = obj.address
      return addr and addr.address
   end,
   store=function(obj, value)
      obj.address = value and {address=value, domain='#'} or nil
   end
}
Filter.address = M.Model{model=Address, visible=false}
Filter.whitelist = M.Set{
   type=M.net.DomainName,
   addr='server/\\#/domain',
   ui_name='Domain whitelist',
   widget='inline'
}

local Dnsmasq = M.new()
Dnsmasq.filter = M.Model{
   model=Filter,
   addr='/augeas'..filter_conf,
   be_mode={server='value', ['server/\\#/domain']='enumerate'}
}
Dnsmasq.conf_file = M.Set{
   type=M.String,
   addr='/augeas/etc/dnsmasq.conf/conf-file',
   be_mode='enumerate',
   visible=false
}

M.register('dnsmasq', Dnsmasq)
M.permission.defaults('/dnsmasq')