518864ebb6ea97a47b809533ac25d648c61b1b15
[lede-routing/.git] / plugins.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 local sys = require("luci.sys")
22
23 m = Map("bmx6", "bmx6")
24 plugins_dir = {"/usr/lib/","/var/lib","/lib"}
25
26 plugin = m:section(TypedSection,"plugin","Plugin")
27 plugin.addremove = true
28 plugin.anonymous = true
29 plv = plugin:option(ListValue,"plugin", "Plugin")
30
31 for _,d in ipairs(plugins_dir) do
32         pl = luci.sys.exec("cd "..d..";ls bmx6_*")
33         if #pl > 6 then
34                 for _,v in ipairs(luci.util.split(pl,"\n")) do
35                         plv:value(v,v)
36                 end
37         end
38 end
39
40
41 function m.on_commit(self,map)
42         local err = sys.call('/etc/init.d/bmx6 restart')
43         if err ~= 0 then
44                 m.message = sys.exec("Cannot restart bmx6")
45         end
46 end
47
48
49 return m
50