summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-mod-freifunk/luasrc/controller
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2014-12-03 15:17:05 +0100
committerJo-Philipp Wich <jow@openwrt.org>2015-01-08 16:26:20 +0100
commit1bb4822dca6113f73e3bc89e2acf15935e6f8e92 (patch)
tree35e16f100466e4e00657199b38bb3d87d52bf73f /modules/luci-mod-freifunk/luasrc/controller
parent9edd0e46c3f880727738ce8ca6ff1c8b85f99ef4 (diff)
Rework LuCI build system
* Rename subdirectories to their repective OpenWrt package names * Make each LuCI module its own standalone package * Deploy a shared luci.mk which is used by each module Makefile Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'modules/luci-mod-freifunk/luasrc/controller')
-rw-r--r--modules/luci-mod-freifunk/luasrc/controller/freifunk/freifunk.lua202
-rw-r--r--modules/luci-mod-freifunk/luasrc/controller/freifunk/remote_update.lua62
2 files changed, 264 insertions, 0 deletions
diff --git a/modules/luci-mod-freifunk/luasrc/controller/freifunk/freifunk.lua b/modules/luci-mod-freifunk/luasrc/controller/freifunk/freifunk.lua
new file mode 100644
index 0000000000..d4606e750f
--- /dev/null
+++ b/modules/luci-mod-freifunk/luasrc/controller/freifunk/freifunk.lua
@@ -0,0 +1,202 @@
+--[[
+LuCI - Lua Configuration Interface
+
+Copyright 2008 Steven Barth <steven@midlink.org>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+]]--
+
+module("luci.controller.freifunk.freifunk", package.seeall)
+
+function index()
+ local uci = require "luci.model.uci".cursor()
+ local page
+
+ -- Frontend
+ page = node()
+ page.lock = true
+ page.target = alias("freifunk")
+ page.subindex = true
+ page.index = false
+
+ page = node("freifunk")
+ page.title = _("Freifunk")
+ page.target = alias("freifunk", "index")
+ page.order = 5
+ page.setuser = "nobody"
+ page.setgroup = "nogroup"
+ page.i18n = "freifunk"
+ page.index = true
+
+ page = node("freifunk", "index")
+ page.target = template("freifunk/index")
+ page.title = _("Overview")
+ page.order = 10
+ page.indexignore = true
+
+ page = node("freifunk", "contact")
+ page.target = template("freifunk/contact")
+ page.title = _("Contact")
+ page.order = 15
+
+ 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")
+
+ if nixio.fs.access("/usr/sbin/luci-splash") then
+ assign({"freifunk", "status", "splash"}, {"splash", "publicstatus"}, _("Splash"), 40)
+ end
+
+ page = assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, _("OLSR"), 30)
+ page.setuser = false
+ page.setgroup = false
+
+ if nixio.fs.access("/etc/config/luci_statistics") then
+ assign({"freifunk", "graph"}, {"admin", "statistics", "graph"}, _("Statistics"), 40)
+ end
+
+ -- backend
+ assign({"mini", "freifunk"}, {"admin", "freifunk"}, _("Freifunk"), 5)
+ entry({"admin", "freifunk"}, alias("admin", "freifunk", "index"), _("Freifunk"), 5)
+
+ 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
+
+ page = node("admin", "freifunk", "basics", "profile_expert")
+ page.target = cbi("freifunk/profile_expert")
+ page.title = _("Profile (Expert)")
+ page.order = 20
+
+ page = node("admin", "freifunk", "Index-Page")
+ page.target = cbi("freifunk/user_index")
+ page.title = _("Index Page")
+ page.order = 50
+
+ page = node("admin", "freifunk", "contact")
+ page.target = cbi("freifunk/contact")
+ page.title = _("Contact")
+ page.order = 15
+
+ 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()
+ local string = require "string"
+ local http = require "luci.http"
+ local zeroes = string.rep(string.char(0), 8192)
+ local cnt = 0
+ local lim = 1024 * 1024 * 1024
+
+ http.prepare_content("application/x-many-zeroes")
+
+ while cnt < lim do
+ http.write(zeroes)
+ cnt = cnt + #zeroes
+ end
+end
+
+function jsonstatus()
+ local root = {}
+ local sys = require "luci.sys"
+ local uci = require "luci.model.uci"
+ local util = require "luci.util"
+ local http = require "luci.http"
+ local json = require "luci.json"
+ local ltn12 = require "luci.ltn12"
+ local version = require "luci.version"
+ local webadmin = require "luci.tools.webadmin"
+
+ local cursor = uci.cursor_state()
+
+ local ffzone = webadmin.firewall_find_zone("freifunk")
+ local ffznet = ffzone and cursor:get("firewall", ffzone, "network")
+ local ffwifs = ffznet and util.split(ffznet, " ") or {}
+
+
+ root.protocol = 1
+
+ root.system = {
+ uptime = {sys.uptime()},
+ loadavg = {sys.loadavg()},
+ sysinfo = {sys.sysinfo()},
+ hostname = sys.hostname()
+ }
+
+ root.firmware = {
+ luciname=version.luciname,
+ luciversion=version.luciversion,
+ distname=version.distname,
+ distversion=version.distversion
+ }
+
+ root.freifunk = {}
+ cursor:foreach("freifunk", "public", function(s)
+ root.freifunk[s[".name"]] = s
+ end)
+
+ cursor:foreach("system", "system", function(s)
+ root.geo = {
+ latitude = s.latitude,
+ longitude = s.longitude
+ }
+ end)
+
+ root.network = {}
+ root.wireless = {devices = {}, interfaces = {}, status = {}}
+ local wifs = root.wireless.interfaces
+ local netdata = luci.sys.net.deviceinfo() or {}
+
+ for _, vif in ipairs(ffwifs) do
+ root.network[vif] = cursor:get_all("network", vif)
+ root.wireless.devices[vif] = cursor:get_all("wireless", vif)
+ cursor:foreach("wireless", "wifi-iface", function(s)
+ if s.device == vif and s.network == vif then
+ wifs[#wifs+1] = s
+ if s.ifname then
+ 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
+
+ http.prepare_content("application/json")
+ ltn12.pump.all(json.Encoder(root):source(), http.write)
+end
diff --git a/modules/luci-mod-freifunk/luasrc/controller/freifunk/remote_update.lua b/modules/luci-mod-freifunk/luasrc/controller/freifunk/remote_update.lua
new file mode 100644
index 0000000000..cc8dd142de
--- /dev/null
+++ b/modules/luci-mod-freifunk/luasrc/controller/freifunk/remote_update.lua
@@ -0,0 +1,62 @@
+--[[
+LuCI - Lua Configuration Interface
+
+Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+]]--
+
+module("luci.controller.freifunk.remote_update", package.seeall)
+
+function index()
+ if not nixio.fs.access("/usr/sbin/remote-update") then
+ return
+ end
+
+ entry({"admin", "system", "remote_update"}, call("act_remote_update"),
+ _("Freifunk Remote Update"), 90)
+end
+
+function act_remote_update()
+ if luci.http.formvalue("flash") == "1" then
+ if luci.http.formvalue("confirm") == "1" then
+ local nobackup = ( luci.http.formvalue("keepcfg") ~= "1" )
+ local noverify = ( luci.http.formvalue("verify") ~= "1" )
+
+ luci.http.redirect("/luci-static/flashing.html")
+
+ os.execute("start-stop-daemon -S -b -x /usr/sbin/remote-update -- %s%s-s 5 -y" % {
+ noverify and "-v " or "",
+ nobackup and "-n " or ""
+ })
+ else
+ luci.template.render("freifunk/remote_update", {confirm=1})
+ end
+ else
+ local fd = io.popen("remote-update -c")
+ local update = { }
+
+ if fd then
+ while true do
+ local ln=fd:read("*l")
+
+ if not ln then break
+ elseif ln:find("Local: ") then update.locvar = ln:match("Local: (%d+)")
+ elseif ln:find("Remote: ") then update.remver = ln:match("Remote: (%d+)")
+ elseif ln == "--" then update.info = ""
+ elseif update.info ~= nil then
+ update.info = update.info .. ln .. "\n"
+ end
+ end
+
+ fd:close()
+ end
+
+ luci.template.render("freifunk/remote_update", {update=update})
+ end
+end