summaryrefslogtreecommitdiffstats
path: root/aconf/modules/dns-zone.lua
blob: ea909fbd76c0403abc73466ddf2fd9b158317088 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
--[[
Copyright (c) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
--]]

local M = require('aconf.model')


local RecordString = M.object.class(M.String)

function RecordString:decode(context, value)
   return (value:match('^"(.*)"$') or value):gsub('%\\(.)', '%1')
end

function RecordString:encode(context, value)
   return value:match('^[A-Za-z%d%.%-:]*$') or '"'..value:gsub(
      '(["\\])', '\\%1'
   )..'"'
end


local Record = M.new()
Record.class = RecordString{
   required=true, default='IN', visible=false, editable=true
}
Record.ttl = RecordString{ui_name='Time-to-live'}
Record.type = M.String{
   required=true,
   choice={'A', 'AAAA', 'CNAME', 'MX', 'NAPTR', 'NS', 'PTR', 'SOA', 'SRV'}
}
Record.rdata = RecordString{
   condition={type={'A', 'AAAA', 'CNAME', 'NS', 'PTR'}},
   required=true,
   ui_name='Resource data'
}
Record.priority = M.Integer{condition={type={'MX', 'SRV'}}, required=true}

Record.exchange = RecordString{condition={type='MX'}, required=true}

Record.order = M.Integer{condition={type='NAPTR'}, required=true}
Record.preference = M.Integer{condition={type='NAPTR'}, required=true}
Record.flags = RecordString{condition={type='NAPTR'}, required=true}
Record.service = RecordString{condition={type='NAPTR'}, required=true}
Record.regexp = RecordString{
   condition={type='NAPTR'}, required=true, ui_name='Regular expression'
}
Record.replacement = RecordString{condition={type='NAPTR'}, required=true}

Record.mname = RecordString{
   condition={type='SOA'}, required=true, ui_name='Primary server'
}
Record.rname = RecordString{
   condition={type='SOA'}, required=true, ui_name='Responsible'
}
Record.serial = RecordString{condition={type='SOA'}, required=true}
Record.refresh = RecordString{condition={type='SOA'}, required=true}
Record.retry = RecordString{condition={type='SOA'}, required=true}
Record.expiry = RecordString{condition={type='SOA'}, required=true}
Record.minimum = RecordString{condition={type='SOA'}, required=true}

Record.weight = M.Integer{condition={type='SRV'}, required=true}
Record.port = M.net.Port{condition={type='SRV'}, required=true}
Record.target = RecordString{condition={type='SRV'}, required=true}


local Zone = M.new()
Zone.origin = M.String{addr='$ORIGIN'}
Zone.ttl = M.String{addr='$TTL', ui_name='Time-to-live'}
Zone.records = M.Collection{
   key=M.String{pattern='[^$].*'},
   type=M.List{
      type=M.Model{model=Record, addr='*/*'},
      be_mode='enumerate',
      ui_member='Record'
   },
   addr='.',
   ui_member=''
}


M.register(
   'dns-zone',
   M.Collection{
      type=Zone, addr='/augeas/var/bind/pri', ui_name='DNS zones', ui_member=''
   }
)

M.permission.defaults('/dns-zone')