096f5b7e59c019b2557163ff39858a0490fe32c7
[project/luci.git] / modules / freifunk / luasrc / controller / freifunk / freifunk.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 module("luci.controller.freifunk.freifunk", package.seeall)
15
16 function index()
17         local i18n = luci.i18n.translate
18
19         local page  = node()
20         page.lock   = true
21         page.target = alias("freifunk")
22
23         local page    = node("freifunk")
24         page.title    = "Freifunk"
25         page.target   = alias("freifunk", "index")
26         page.order    = 5
27         page.setuser  = "nobody"
28         page.setgroup = "nogroup"
29         page.i18n     = "freifunk"
30         
31         local page  = node("freifunk", "index")
32         page.target = template("freifunk/index")
33         page.title  = "Übersicht"
34         page.order  = 10
35         
36         local page  = node("freifunk", "index", "contact")
37         page.target = template("freifunk/contact")
38         page.title  = "Kontakt"
39         
40         
41         local page  = node("freifunk", "status")
42         page.target = form("freifunk/public_status")
43         page.title  = "Status"
44         page.order  = 20
45         page.i18n   = "admin-core"
46         page.setuser  = false
47         page.setgroup = false
48         
49         assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, "OLSR", 30)
50         
51         if luci.fs.isfile("/etc/config/luci_statistics") then
52                 assign({"freifunk", "statistics"}, {"admin", "statistics", "graph"}, i18n("stat_statistics", "Statistiken"), 40)
53         end
54         
55         assign({"mini", "freifunk"}, {"admin", "freifunk"}, "Freifunk", 15)
56         entry({"admin", "freifunk"}, alias("admin", "freifunk", "index"), "Freifunk", 15)
57         local page  = node("admin", "freifunk", "index")
58         page.target = cbi("freifunk/freifunk")
59         page.title  = "Freifunk"
60         page.order  = 30
61         
62         local page  = node("admin", "freifunk", "contact")
63         page.target = cbi("freifunk/contact")
64         page.title  = "Kontakt"
65         page.order  = 40
66 end
67
68 function action_status()
69         local data = {}
70         
71         data.system, data.model, data.memtotal, data.memcached, data.membuffers, data.memfree = luci.sys.sysinfo()
72         data.perc_memfree = math.floor((data.memfree/data.memtotal)*100)
73         data.perc_membuffers = math.floor((data.membuffers/data.memtotal)*100)
74         data.perc_memcached = math.floor((data.memcached/data.memtotal)*100)
75         
76         data.wifi = luci.sys.wifi.getiwconfig()
77         
78         data.routes = {}
79         for i, r in pairs(luci.sys.net.routes()) do
80                 if r.Destination == "00000000" then
81                         table.insert(data.routes, r)
82                 end
83         end
84
85         
86         luci.template.render("public_status/index", data)
87 end