summaryrefslogtreecommitdiffstats
path: root/provisioning-controller.lua
blob: f4386d9ec0d6fadf6b6cbfdf8f387f12e58132fc (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
module (..., package.seeall)

require("controllerfunctions")

default_action = "listdevices"

listtemplates = function( self )
	return self.model.list_templates()
end

edittemplate = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_template(self.clientdata.filename) end, self.model.update_template, self.clientdata, "Save", "Edit Template", "Template Saved")
end

createtemplate = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_template(self.clientdata.filename) end, self.model.create_template, self.clientdata, "Create", "Create Template", "Template Created")
end

deletetemplate = function( self )
	return self:redirect_to_referrer(self.model.delete_template(self.clientdata.filename))
end

listclassgroups = function( self )
	return self.model.list_class_groups()
end

editclassgroup = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_class_group(self.clientdata.class_group_id) end, self.model.update_class_group, self.clientdata, "Save", "Edit Class Group", "Class Group Saved")
end

createclassgroup = function( self )
	return controllerfunctions.handle_form(self, self.model.get_class_group, self.model.create_class_group, self.clientdata, "Create", "Create Class Group", "Parameter Class Created")
end

deleteclassgroup = function( self )
	return self:redirect_to_referrer(self.model.delete_class_group(self.clientdata.class_group_id))
end

listclasses = function( self )
	return self.model.list_classes()
end

editclass = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_class(self.clientdata.class_id) end, self.model.update_class, self.clientdata, "Save", "Edit Class", "Class Saved")
end

createclass = function( self )
	return controllerfunctions.handle_form(self, self.model.get_class, self.model.create_class, self.clientdata, "Create", "Create Class", "Class Created")
end

deleteclass = function( self )
	return self:redirect_to_referrer(self.model.delete_class(self.clientdata.class_id))
end

getclassvalues = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_class_options(self.clientdata.class_id) end, self.model.get_class_values, self.clientdata, "Fetch", "Get Device Values")
end

listgroups = function( self )
	return self.model.list_groups()
end

editgroup = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_group(self.clientdata.group_id) end, self.model.update_group, self.clientdata, "Save", "Edit Parameter Group", "Parameter Group Saved")
end

creategroup = function( self )
	return controllerfunctions.handle_form(self, self.model.get_group, self.model.create_group, self.clientdata, "Create", "Create Parameter Group", "Parameter Group Created")
end

deletegroup = function( self )
	return self:redirect_to_referrer(self.model.delete_group(self.clientdata.group_id))
end

listparams = function( self )
	return self.model.list_params()
end

editparam = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_param(self.clientdata.param_id) end, self.model.update_param, self.clientdata, "Save", "Edit Parameter", "Parameter Saved")
end

createparam = function( self )
	return controllerfunctions.handle_form(self, self.model.get_param, self.model.create_param, self.clientdata, "Create", "Create Parameter", "Parameter Created")
end

deleteparam = function( self )
	return self:redirect_to_referrer(self.model.delete_param(self.clientdata.param_id))
end

listdevices = function( self )
	return self.model.list_devices()
end

editdevice = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_device(self.clientdata.device_id) end, self.model.update_device, self.clientdata, "Save", "Edit Device", "Device Saved")
end

createdevice = function( self )
	local retval = controllerfunctions.handle_form(self, self.model.get_device, self.model.create_device, self.clientdata, "Create", "Create Device", "Device Created")
	if retval.value.device_id.value ~= "" and not retval.errtxt then
		-- Successfully created a device, redirect to edit it
		self:redirect("editdevice?device_id="..retval.value.device_id.value.."&redir=".. (self.clientdata.redir or "listdevices"))
	end
	return retval
end

duplicatedevice = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_device(self.clientdata.device_id) end, self.model.create_device, self.clientdata, "Duplicate", "Duplicate Device", "Duplicate Device Created")
end

deletedevice = function( self )
	return self:redirect_to_referrer(self.model.delete_device(self.clientdata.device_id))
end

editdeviceparams = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_editable_device_params(self.clientdata.device_id) end, self.model.set_editable_device_params, self.clientdata, "Save", "Edit Device Parameters", "Device Parameters Saved")
end

overridedeviceparams = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_device_params(self.clientdata.device_id) end, self.model.set_device_params, self.clientdata, "Save", "Override Device Parameters", "Device Parameters Saved")
end

getdevicevalues = function( self )
	return controllerfunctions.handle_form(self, self.model.get_search_options, self.model.fetch_device_values, self.clientdata, "Search", "Get Device Values")
end

searchdevices = function( self )
	return controllerfunctions.handle_form(self, self.model.get_search_options, self.model.search_device_values, self.clientdata, "Search", "Search Device Parameters")
end

editoptions = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_param_options(self.clientdata.param_id) end, self.model.set_param_options, self.clientdata, "Save", "Edit Parameter Options", "Parameter Options Saved")
end

listfiles = function( self )
	return self.model.list_files()
end

editfile = function( self )
	return controllerfunctions.handle_form(self, function() return self.model.get_filedetails(self.clientdata.filename) end, self.model.update_filedetails, self.clientdata, "Save", "Edit Script File", "Script File Saved")
end

dumpdatabase = function( self )
	return controllerfunctions.handle_form(self, self.model.get_database, self.model.dump_database, self.clientdata, "Submit", "Dump Provisioning Database")
end

getfile = function( self )
	return self.model.get_file(self.clientdata.mac, self.clientdata.ip, self.clientdata.agent)
end

putfile = function( self )
	return self.model.put_file(self.clientdata.mac, self.clientdata.data)
end