diff options
Diffstat (limited to 'prototypejsdemo-controller.lua')
-rw-r--r-- | prototypejsdemo-controller.lua | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/prototypejsdemo-controller.lua b/prototypejsdemo-controller.lua new file mode 100644 index 0000000..547b91c --- /dev/null +++ b/prototypejsdemo-controller.lua @@ -0,0 +1,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 + |