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

-- Load libraries
require("controllerfunctions")

local checkboxes = { "PermitRootLogin", "PasswordAuthentication", "UseDNS" }

default_action = "status"

function status(self)
	return self.model.getstatus()
end

function config(self)
	local output = {}
	local errtxt = {}
	local successfuledit
	if (self.clientdata.cmdsave) then
		local fields = { "Port", "ListenAddress", "PermitRootLogin", "PasswordAuthentication", "UseDNS", }
		local newconfig = {}
		for _ , v in pairs(fields) do
			newconfig[v] = self.clientdata[v] or ""
		end
		successfuledit, errtxt = self.model.write_config(newconfig)
	end

	local config = self.model.read_config() or {}
	output.cmdsave = cfe({
		name="cmdsave",
		label="Save above changes",
		value="Apply",
		type="submit",
	})

	output.Port = cfe({
		name="Port",
		label="Port",
		value=config.Port,
	})
	output.ListenAddress = cfe({
		name="ListenAddress",
		label="Listen address",
		value=config.ListenAddress,
	})
	output.PermitRootLogin = cfe({
		name="PermitRootLogin",
		label="Permit Root Login",
	})

	output.PasswordAuthentication = cfe({
		name="PasswordAuthentication",
		label="Password Authentication",
	})

	output.UseDNS = cfe({
		name="UseDNS",
		label="Use DNS",
	})

	-- Display checkboxes checked/unchecked
	for k,v in pairs(checkboxes) do
		output[v]['value']="yes"
		output[v]['type']="checkbox"
		if (config[v]) and (string.lower(tostring(config[v] or "")) == "yes") then
			output[v]['checked']="yes"
		end
	end

	-- Display results of previous save action
	if (self.clientdata.cmdsave) and not (successfuledit) then
		for k,v in pairs(self.clientdata) do
			if (output) and (output[k]) and (k) then
				output[k]['value'] = self.clientdata[k]
				output[k]['errtxt'] = errtxt[k]
			end
		end

		output.cmdsave.errtxt = "Save action was canceled because there was invalid input."
	elseif (self.clientdata.cmdsave) and (successfuledit) then
		output.cmdsave.descr = "* Configuration was succesfully saved"
	end

	return output
end

function startstop(self)
	return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata)
end

function expert(self)
	return controllerfunctions.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit Config", "Configuration Saved")
end

function connectedpeers(self)
	return self.model.list_conn_peers()
end
function welcome(self)
end