summaryrefslogtreecommitdiffstats
path: root/tinydns-controller.lua
blob: 030257fa081d3645ec2a24573d315e619006e8dd (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
module(..., package.seeall)

local pvt = {}

local list_redir = function (self)
	self.conf.action = "status"
	self.conf.type = "redir"
	error (self.conf)
end

mvc = {}
mvc.on_load = function(self, parent)
	if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then
		self.worker[self.conf.action] = list_redir(self)
	end
end

local function getstatus(self)
	local status = self.model.getstatus()
	if (#status.status.value > 0) then
		status.status.value = "Enabled"
	else
		status.status.value = "Disabled"
	end

	return status
end

function status(self)
	local config = {}
	config.settings = {}
--	local array = {}
	local locations=self.model.getlocations(self)
	local availablesigns = self.model.check_signs("prefix")

	
	config.locations = cfe ({
		name="locations",
		label="Locations",
		value=locations,
		})

--[[
	local prefix = "."
	config.settings.nsourdomain = cfe ({
		name="nsourdomain",
		label=availablesigns[prefix],
		value=self.model.getconfigobjects(self,prefix),
		})

	local prefix = "&"
	config.settings.nsdomain = cfe ({
		name="nsdomain",
		label=availablesigns[prefix],
		value=self.model.getconfigobjects(self,prefix),
		})

	local prefix = "="
	config.settings.host = cfe ({
		name="host",
		label=availablesigns[prefix],
		value=self.model.getconfigobjects(self,prefix),
		})

	local prefix = "+"
	config.settings.alias = cfe ({
		name="alias",
		label=availablesigns[prefix],
		value=self.model.getconfigobjects(self,prefix),
		})

	local prefix = "@"
	config.settings.mx = cfe ({
		name="mx",
		label=availablesigns[prefix],
		value=self.model.getconfigobjects(self,prefix),
		})

	local prefix = "^"
	config.settings.ptr = cfe ({
		name="ptr",
		label=availablesigns[prefix],
		value=self.model.getconfigobjects(self,prefix),
		})

	local prefix = "C"
	config.settings.cname = cfe ({
		name="cname",
		label=availablesigns[prefix],
		value=self.model.getconfigobjects(self,prefix),
		})

	local prefix = "Z"
	config.settings.soa = cfe ({
		name="soa",
		label=availablesigns[prefix],
		value=self.model.getconfigobjects(self,prefix),
		})

	local prefix = ":"
	config.settings.generic = cfe ({
		name="generic",
		label=availablesigns[prefix],
		value=self.model.getconfigobjects(self,prefix),
		})

--]]
	config.settings.all = cfe ({
		name="generic",
		label="All available records",
		value=self.model.getconfigobjects(self),
		})

	local counter
--	colapse_output(config.settings, pvt)

---[[
	-- We count the rows of the previous columns
	-- This counter is then used to set the default filter (when user has not entered any values)
	-- FIXME: This is a uggly way of doing things. It's just a way to get going faster
	local filterstage = 3

	local mytable = config.settings
	for k1,v1 in pairs(mytable) do
		if not (counter) then counter = 0 end		
		if (type(v1) == "table") then
			for k2,v2 in pairs(v1) do
				if (type(v2) == "table") then
					for s1,vs1 in pairs(v2) do
						if (type(vs1) == "table") then
							for s2,vs2 in pairs(vs1) do
								if (filterstage) and (filterstage == 2) then
									mytable[k1][k2][s1][s2] = {}	-- Removes stage2 and above
								else

									if (type(vs2) == "table") then
										for s3,vs3 in pairs(vs2) do
											if (filterstage) and (filterstage == 3) and not (vs3.name) then
												mytable[k1][k2][s1][s2][s3] = {}	-- Removes stage3 and above
											end
										end
									end

								end
							end
						end
					end
				end
			end
		end
	end
--]]
	config.debug = cfe ({
		name="debug",
		label="Counted rows",
		value=pvt,
		errtxt=" ",
		})


	return { status=getstatus(self), config=config }
end

function config(self)
	local config = self.model.getconfigobjects(self)
	local debug = self.model.getdebug(self)
	return ({
		status=getstatus(self),
		config=config,
		debug=debug,
	 	})
end