Merge pull request #278 from nmav/ocserv
[project/luci.git] / modules / freifunk / luasrc / controller / freifunk / freifunk.lua
index 52b37dc..d4606e7 100644 (file)
@@ -11,19 +11,22 @@ You may obtain a copy of the License at
 
 $Id$
 ]]--
+
 module("luci.controller.freifunk.freifunk", package.seeall)
 
 function index()
-       local i18n = luci.i18n.translate
+       local uci = require "luci.model.uci".cursor()
+       local page
 
-       local page  = node()
-       page.lock   = true
-       page.target = alias("freifunk")
+       -- Frontend
+       page          = node()
+       page.lock     = true
+       page.target   = alias("freifunk")
        page.subindex = true
-       page.index = false
+       page.index    = false
 
-       local page    = node("freifunk")
-       page.title    = "Freifunk"
+       page          = node("freifunk")
+       page.title    = _("Freifunk")
        page.target   = alias("freifunk", "index")
        page.order    = 5
        page.setuser  = "nobody"
@@ -31,98 +34,77 @@ function index()
        page.i18n     = "freifunk"
        page.index    = true
 
-       local page  = node("freifunk", "index")
-       page.target = template("freifunk/index")
-       page.title  = "Übersicht"
-       page.order  = 10
+       page          = node("freifunk", "index")
+       page.target   = template("freifunk/index")
+       page.title    = _("Overview")
+       page.order    = 10
        page.indexignore = true
 
-       local page  = node("freifunk", "index", "contact")
-       page.target = template("freifunk/contact")
-       page.title  = "Kontakt"
+       page          = node("freifunk", "contact")
+       page.target   = template("freifunk/contact")
+       page.title    = _("Contact")
+       page.order    = 15
 
-       entry({"freifunk", "status"}, alias("freifunk", "status", "status"), "Status", 20)
-
-       local page  = node("freifunk", "status", "status")
-       page.target = form("freifunk/public_status")
-       page.title  = i18n("Overview")
-       page.order  = 20
-       page.i18n   = "admin-core"
+       page          = node("freifunk", "status")
+       page.target   = template("freifunk/public_status")
+       page.title    = _("Status")
+       page.order    = 20
+       page.i18n     = "base"
        page.setuser  = false
        page.setgroup = false
 
        entry({"freifunk", "status.json"}, call("jsonstatus"))
-       entry({"freifunk", "status", "zeroes"}, call("zeroes"), "Testdownload") 
+       entry({"freifunk", "status", "zeroes"}, call("zeroes"), "Testdownload")
 
-       assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, "OLSR", 30)
-
-       if nixio.fs.access("/etc/config/luci_statistics") then
-               assign({"freifunk", "graph"}, {"admin", "statistics", "graph"}, i18n("Statistics"), 40)
+       if nixio.fs.access("/usr/sbin/luci-splash") then
+               assign({"freifunk", "status", "splash"}, {"splash", "publicstatus"}, _("Splash"), 40)
        end
 
-       assign({"mini", "freifunk"}, {"admin", "freifunk"}, "Freifunk", 15)
-       entry({"admin", "freifunk"}, alias("admin", "freifunk", "index"), "Freifunk", 15)
-       local page  = node("admin", "freifunk", "index")
-       page.target = cbi("freifunk/freifunk")
-       page.title  = "Freifunk"
-       page.order  = 30
-
-       local page  = node("admin", "freifunk", "contact")
-       page.target = cbi("freifunk/contact")
-       page.title  = "Kontakt"
-       page.order  = 40
-
-       entry({"freifunk", "map"}, template("freifunk-map/frame"), i18n("Karte"), 50)
-       entry({"freifunk", "map", "content"}, template("freifunk-map/map"), nil, 51)
-end
+       page = assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, _("OLSR"), 30)
+       page.setuser = false
+       page.setgroup = false
 
-local function fetch_olsrd()
-       local sys = require "luci.sys"
-       local util = require "luci.util"
-       local table = require "table"
-       local rawdata = sys.httpget("http://127.0.0.1:2006/")
-
-       if #rawdata == 0 then
-               if nixio.fs.access("/proc/net/ipv6_route", "r") then
-                       rawdata = sys.httpget("http://[::1]:2006/")
-                       if #rawdata == 0 then
-                               return nil
-                       end
-               else
-                       return nil
-               end
+       if nixio.fs.access("/etc/config/luci_statistics") then
+               assign({"freifunk", "graph"}, {"admin", "statistics", "graph"}, _("Statistics"), 40)
        end
 
-       local data = {}
+       -- backend
+       assign({"mini", "freifunk"}, {"admin", "freifunk"}, _("Freifunk"), 5)
+       entry({"admin", "freifunk"}, alias("admin", "freifunk", "index"), _("Freifunk"), 5)
 
-       local tables = util.split(util.trim(rawdata), "\r?\n\r?\n", nil, true)
+       page        = node("admin", "freifunk")
+       page.target = template("freifunk/adminindex")
+       page.title  = _("Freifunk")
+       page.order  = 5
 
+       page        = node("admin", "freifunk", "basics")
+       page.target = cbi("freifunk/basics")
+       page.title  = _("Basic Settings")
+       page.order  = 5
+       
+       page        = node("admin", "freifunk", "basics", "profile")
+       page.target = cbi("freifunk/profile")
+       page.title  = _("Profile")
+       page.order  = 10
 
-       for i, tbl in ipairs(tables) do
-               local lines = util.split(tbl, "\r?\n", nil, true)
-               local name  = table.remove(lines, 1):sub(8)
-               local keys  = util.split(table.remove(lines, 1), "\t")
-               local split = #keys - 1
+       page        = node("admin", "freifunk", "basics", "profile_expert")
+       page.target = cbi("freifunk/profile_expert")
+       page.title  = _("Profile (Expert)")
+       page.order  = 20
 
-               data[name] = {}
+       page        = node("admin", "freifunk", "Index-Page")
+       page.target = cbi("freifunk/user_index")
+       page.title  = _("Index Page")
+       page.order  = 50
 
-               for j, line in ipairs(lines) do
-                       local fields = util.split(line, "\t", split)
-                       data[name][j] = {}
-                       for k, key in pairs(keys) do
-                               data[name][j][key] = fields[k]
-                       end
-
-                       if data[name][j].Linkcost then
-                               data[name][j].LinkQuality,
-                               data[name][j].NLQ,
-                               data[name][j].ETX =
-                               data[name][j].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")
-                       end
-               end
-       end
+       page        = node("admin", "freifunk", "contact")
+       page.target = cbi("freifunk/contact")
+       page.title  = _("Contact")
+       page.order  = 15
 
-       return data
+       entry({"freifunk", "map"}, template("freifunk-map/frame"), _("Map"), 50)
+       entry({"freifunk", "map", "content"}, template("freifunk-map/map"), nil, 51)
+       entry({"admin", "freifunk", "profile_error"}, template("freifunk/profile_error"))
 end
 
 function zeroes()
@@ -189,7 +171,6 @@ function jsonstatus()
        root.network = {}
        root.wireless = {devices = {}, interfaces = {}, status = {}}
        local wifs = root.wireless.interfaces
-       local wifidata = luci.sys.wifi.getiwconfig() or {}
        local netdata = luci.sys.net.deviceinfo() or {}
 
        for _, vif in ipairs(ffwifs) do
@@ -199,14 +180,23 @@ function jsonstatus()
                        if s.device == vif and s.network == vif then
                                wifs[#wifs+1] = s
                                if s.ifname then
-                                       root.wireless.status[s.ifname] = wifidata[s.ifname]
+                                       local iwinfo = luci.sys.wifi.getiwinfo(s.ifname)
+                                       if iwinfo then
+                                               root.wireless.status[s.ifname] = { }
+
+                                               local _, f
+                                               for _, f in ipairs({
+                                                       "channel", "txpower", "bitrate", "signal", "noise",
+                                                       "quality", "quality_max", "mode", "ssid", "bssid", "encryption", "ifname"
+                                               }) do
+                                                       root.wireless.status[s.ifname][f] = iwinfo[f]
+                                               end
+                                       end
                                end
                        end
                end)
        end
 
-       root.olsrd = fetch_olsrd()
-
        http.prepare_content("application/json")
        ltn12.pump.all(json.Encoder(root):source(), http.write)
 end