blob: 547b91c6152da9de6fadeb37c304a35d85a408f2 (
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
|
-- ipsec controller
module(..., package.seeall)
--require("posix")
require("json")
require("validator")
function test(self)
local a = {}
return a
end
-- quick and dirty json resolver. could be done with viewtype?
-- anyway... the file would be a oneliner anyway...
local function json_resolver(self)
io.write("\n\n"..json.encode(self).."\n")
end
local function text_resolver(self)
io.write("content-type: application/json\n\n"..tostring(self).."\n");
end
function submit(self)
-- overwrite resolver. quick and dirty...
view_resolver = function(self)
return json_resolver
end
local ret = {}
-- only validation here is we test if mask is 'aaa'
if self.clientdata.mask == "aaa" then
ret.success = false
ret.errors = { mask = "'aaa' is a netmask...?" }
else
ret.success = true
end
return ret
end
function load(self)
-- overwrite resolver. quick and dirty...
view_resolver = function(self)
return json_resolver
end
local status, t = self.model.get_iface_by_name(self.clientdata.ifname)
local ret = {}
if status then
ret = {
ifenable = "true",
iftype = t.method.value,
address = t.address.value,
mask = t.netmask.value,
gateway = t.gateway.value
}
else
ret.ifenable = "false";
end
return ret
end
function check_ipv4(self)
-- overload resolver quick'n dirty
view_resolver = function(self)
return text_resolver
end
local ip = self.clientdata.address
local valid, msg = validator.is_ipv4(ip)
if valid or ip == "" or ip == nil then
return ""
else
return msg
end
end
|