luci-app-bmx7: show mDNS menu if available
[feed/routing.git] / luci-app-bmx7 / files / usr / lib / lua / luci / controller / bmx7.lua
1 --[[
2 Copyright (C) 2011 Pau Escrich <pau@dabax.net>
3 Contributors Jo-Philipp Wich <xm@subsignal.org>
4 Roger Pueyo Centelles <roger.pueyo@guifi.net>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 The full GNU General Public License is included in this distribution in
21 the file called "COPYING".
22 --]]
23
24 module("luci.controller.bmx7", package.seeall)
25
26 function index()
27 local place = {}
28 local ucim = require "luci.model.uci"
29 local uci = ucim.cursor()
30
31 -- checking if ignore is on
32 if uci:get("luci-bmx7","luci","ignore") == "1" then
33 return nil
34 end
35
36 -- getting value from uci database
37 local uci_place = uci:get("luci-bmx7","luci","place")
38
39 -- default values
40 if uci_place == nil then
41 place = {"bmx7"}
42 else
43 local util = require "luci.util"
44 place = util.split(uci_place," ")
45 end
46
47 -- getting position of menu
48 local uci_position = uci:get("luci-bmx7","luci","position")
49
50
51 ---------------------------
52 -- Placing the pages in the menu
53 ---------------------------
54
55 -- Status (default)
56 entry(place,call("action_status_j"),place[#place],tonumber(uci_position))
57
58 table.insert(place,"Status")
59 entry(place,call("action_status_j"),"Status",0)
60 table.remove(place)
61
62 -- Topology
63 table.insert(place,"Topology")
64 entry(place,call("topology"),"Topology",1)
65 table.remove(place)
66
67 -- Nodes
68 table.insert(place,"Nodes")
69 entry(place,call("action_nodes_j"),"Nodes",2)
70 table.remove(place)
71
72 -- Tunnels
73 table.insert(place,"Gateways")
74 entry(place,call("action_tunnels_j"),"Gateways",3)
75 table.remove(place)
76
77 -- Integrate bmx7-mdns if present
78 if nixio.fs.stat("/usr/lib/lua/luci/model/cbi/bmx7-mdns.lua","type") ~= nil then
79 table.insert(place,"mDNS")
80 entry(place, cbi("bmx7-mdns"), "mesh DNS", 1).dependent=false
81 table.remove(place)
82 end
83
84 end
85
86
87 function action_status_j()
88 luci.template.render("bmx7/status_j", {})
89 end
90
91 function action_tunnels_j()
92 luci.template.render("bmx7/tunnels_j", {})
93 end
94
95 function topology()
96 luci.template.render("bmx7/topology", {})
97 end
98
99 function action_nodes_j()
100 luci.template.render("bmx7/nodes_j", {})
101 end