d4e0745aa668058e2976ac669e132455eb5ebe6a
[feed/routing.git] / luci-app-bmx6 / files / usr / lib / lua / luci / model / cbi / bmx6 / main.lua
1 --[[
2 Copyright (C) 2011 Pau Escrich <pau@dabax.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 The full GNU General Public License is included in this distribution in
19 the file called "COPYING".
20 --]]
21
22 local sys = require("luci.sys")
23 local bmx6json = require("luci.model.bmx6json")
24
25 m = Map("bmx6", "bmx6")
26
27 -- Getting json and Checking if bmx6-json is avaiable
28 local options = bmx6json.get("options")
29 if options == nil or options.OPTIONS == nil then
30 m.message = "bmx6-json plugin is not running or some mistake in luci-bmx6 configuration, check /etc/config/luci-bmx6"
31 else
32 options = options.OPTIONS
33 end
34
35 -- Getting a list of interfaces
36 local eth_int = luci.sys.net.devices()
37
38 local tunDev = m:section(TypedSection,"tunDev",translate("Tunnel device"),translate("Define incoming ipip tunnel interface name"))
39 tunDev.addremove = true
40 tunDev.anonymous = true
41 tunDev:option(Value,"tunDev",translate("Name"),translate("Name for the tunnel network device"))
42 tunDev:option(Value,"tun4Address", translate("IPv4 address/length"),translate("Specify default IPv4 tunnel address and announced range (ex. 10.1.2.3/24)"))
43 tunDev:option(Value,"tun6Address", translate("IPv6 address/length"),translate("Specify default IPv6 tunnel address and announced range (ex. 2012:0:0:123:0:0:0:1/64)"))
44
45 -- IP section
46 local ipV = m:section(NamedSection,"ipVersion","ipVersion",translate("Miscellaneous IP options"))
47 ipV.addremove = false
48 local lipv = ipV:option(ListValue,"ipVersion",translate("IP version"))
49 lipv:value("6","6")
50 lipv.default = "6"
51
52 -- rest of ip options are optional, getting them from json
53 local ipoptions = {}
54 for _,o in ipairs(options) do
55 if o.name == "ipVersion" and o.CHILD_OPTIONS ~= nil then
56 ipoptions = o.CHILD_OPTIONS
57 break
58 end
59 end
60
61 local help = ""
62 local name = ""
63 local value = nil
64
65 for _,o in ipairs(ipoptions) do
66 if o.name ~= nil then
67 help = ""
68 name = o.name
69 if o.help ~= nil then
70 help = bmx6json.text2html(o.help)
71 end
72
73 if o.syntax ~= nil then
74 help = help .. "<br/><strong>Syntax: </strong>" .. bmx6json.text2html(o.syntax)
75 end
76
77 if o.def ~= nil then
78 help = help .. "<br/><strong> Default: </strong>" .. bmx6json.text2html(o.def)
79 end
80
81 value = ipV:option(Value,name,name,help)
82 value.optional = true
83 end
84 end
85
86 -- Interfaces section
87 local interfaces = m:section(TypedSection,"dev",translate("Devices"),translate("Network devices to mesh with"))
88 interfaces.addremove = true
89 interfaces.anonymous = true
90 local intlv = interfaces:option(ListValue,"dev",translate("Device"))
91
92 for _,i in ipairs(eth_int) do
93 intlv:value(i,i)
94 end
95
96 function m.on_commit(self,map)
97 local err = sys.call('bmx6 -c --configReload > /tmp/bmx6-luci.err.tmp')
98 if err ~= 0 then
99 m.message = sys.exec("cat /tmp/bmx6-luci.err.tmp")
100 end
101 end
102
103 return m
104