From: Steven Barth Date: Thu, 22 May 2008 14:04:03 +0000 (+0000) Subject: Merge branch 'menu' X-Git-Tag: 0.8.0~1011 X-Git-Url: http://git.openwrt.org/?p=project%2Fluci.git;a=commitdiff_plain;h=6604399aa8f35d33c53a5e5a1fea765f401aef5e Merge branch 'menu' --- diff --git a/applications/community-halle/Makefile b/applications/community-halle/Makefile new file mode 100644 index 0000000000..81a96f6a83 --- /dev/null +++ b/applications/community-halle/Makefile @@ -0,0 +1,2 @@ +include ../../build/config.mk +include ../../build/module.mk \ No newline at end of file diff --git a/applications/community-halle/root/etc/uci-defaults/ffluci-community-halle b/applications/community-halle/root/etc/uci-defaults/ffluci-community-halle new file mode 100644 index 0000000000..8e4286a57b --- /dev/null +++ b/applications/community-halle/root/etc/uci-defaults/ffluci-community-halle @@ -0,0 +1,16 @@ +#!/bin/sh +uci batch <<-EOF + set freifunk.community.name='Freifunk Halle' + set freifunk.community.homepage=http://halle.freifunk.net + set freifunk.community.essid=halle.freifunk.net + set freifunk.community.bssid=02:CA:FF:EE:BA:BE + set freifunk.community.realm=pool.freifunk-halle.net + set freifunk.community.channel=1 + set freifunk.community.net=104.0.0.0 + set freifunk.community.mask=255.0.0.0 + set freifunk.community.dhcp=10.0.0.0 + set freifunk.community.dhcpmask=255.255.255.0 + set freifunk.community.dns='88.198.178.18 141.54.1.1 212.204.49.83 208.67.220.220 208.67.222.222' + commit freifunk +EOF + diff --git a/applications/luci-fw/src/controller/luci_fw/luci_fw.lua b/applications/luci-fw/src/controller/luci_fw/luci_fw.lua new file mode 100644 index 0000000000..864455ca8f --- /dev/null +++ b/applications/luci-fw/src/controller/luci_fw/luci_fw.lua @@ -0,0 +1,18 @@ +module("ffluci.controller.luci_fw.luci_fw", package.seeall) + +function index() + local page = node("admin", "network", "portfw") + page.target = cbi("luci_fw/portfw") + page.title = "Portweiterleitung" + page.order = 70 + + local page = node("admin", "network", "routing") + page.target = cbi("luci_fw/routing") + page.title = "Routing" + page.order = 72 + + local page = node("admin", "network", "firewall") + page.target = cbi("luci_fw/firewall") + page.title = "Firewall" + page.order = 74 +end \ No newline at end of file diff --git a/applications/luci-fw/src/model/cbi/admin_network/firewall.lua b/applications/luci-fw/src/model/cbi/admin_network/firewall.lua deleted file mode 100644 index 7c89d07c55..0000000000 --- a/applications/luci-fw/src/model/cbi/admin_network/firewall.lua +++ /dev/null @@ -1,73 +0,0 @@ --- ToDo: Translate, Add descriptions and help texts -m = Map("luci_fw", "Firewall", [[Mit Hilfe der Firewall können Zugriffe auf das Netzwerk -erlaubt, verboten oder umgeleitet werden.]]) - -s = m:section(TypedSection, "rule") -s.addremove = true -s.anonymous = true - -chain = s:option(ListValue, "chain", "Kette") -chain:value("forward", "Forward") -chain:value("input", "Input") -chain:value("output", "Output") -chain:value("prerouting", "Prerouting") -chain:value("postrouting", "Postrouting") - -iface = s:option(ListValue, "iface", "Eingangsschnittstelle") -iface.optional = true - -oface = s:option(ListValue, "oface", "Ausgangsschnittstelle") -oface.optional = true - -for k, v in pairs(ffluci.model.uci.sections("network")) do - if v[".type"] == "interface" and k ~= "loopback" then - iface:value(k) - oface:value(k) - end -end - -proto = s:option(ListValue, "proto", "Protokoll") -proto.optional = true -proto:value("") -proto:value("tcp", "TCP") -proto:value("udp", "UDP") - -s:option(Value, "source", "Quelladresse").optional = true -s:option(Value, "destination", "Zieladresse").optional = true -s:option(Value, "mac", "MAC-Adresse").optional = true - -sport = s:option(Value, "sport", "Quellport") -sport.optional = true -sport:depends("proto", "tcp") -sport:depends("proto", "udp") - -dport = s:option(Value, "dport", "Zielport") -dport.optional = true -dport:depends("proto", "tcp") -dport:depends("proto", "udp") - -tosrc = s:option(Value, "tosrc", "Neue Quelladresse [SNAT]") -tosrc.optional = true -tosrc:depends("jump", "SNAT") - -tosrc = s:option(Value, "todest", "Neue Zieladresse [DNAT]") -tosrc.optional = true -tosrc:depends("jump", "DNAT") - -jump = s:option(ListValue, "jump", "Aktion") -jump.rmempty = true -jump:value("", "") -jump:value("ACCEPT", "annehmen (ACCEPT)") -jump:value("REJECT", "zurückweisen (REJECT)") -jump:value("DROP", "verwerfen (DROP)") -jump:value("LOG", "protokollieren (LOG)") -jump:value("DNAT", "Ziel umschreiben (DNAT) [nur Prerouting]") -jump:value("MASQUERADE", "maskieren (MASQUERADE) [nur Postrouting]") -jump:value("SNAT", "Quelle umschreiben (SNAT) [nur Postrouting]") - - -add = s:option(Value, "command", "Eigener Befehl") -add.size = 50 -add.rmempty = true - -return m diff --git a/applications/luci-fw/src/model/cbi/admin_network/portfw.lua b/applications/luci-fw/src/model/cbi/admin_network/portfw.lua deleted file mode 100644 index 90ebb4c24d..0000000000 --- a/applications/luci-fw/src/model/cbi/admin_network/portfw.lua +++ /dev/null @@ -1,28 +0,0 @@ --- ToDo: Translate, Add descriptions and help texts -require("ffluci.sys") -m = Map("luci_fw", "Portweiterleitung", [[Portweiterleitungen ermöglichen es interne -Netzwerkdienste von einem anderen externen Netzwerk aus erreichbar zu machen.]]) - -s = m:section(TypedSection, "portfw") -s.template = "cbi/tblsection" -s.addremove = true -s.anonymous = true - -iface = s:option(ListValue, "iface", "Schnittstelle", "Externe Schnittstelle") -iface.default = "wan" -for k, v in pairs(ffluci.model.uci.sections("network")) do - if v[".type"] == "interface" and k ~= "loopback" then - iface:value(k) - end -end - -proto = s:option(ListValue, "proto", "Protokoll") -proto:value("tcp", "TCP") -proto:value("udp", "UDP") -proto:value("tcpudp", "TCP + UDP") - -dport = s:option(Value, "dport", "Externer Port", "Port[:Endport]") - -to = s:option(Value, "to", "Interne Adresse", "IP-Adresse[:Zielport[-Zielendport]]") - -return m diff --git a/applications/luci-fw/src/model/cbi/admin_network/routing.lua b/applications/luci-fw/src/model/cbi/admin_network/routing.lua deleted file mode 100644 index 5805b1d3f7..0000000000 --- a/applications/luci-fw/src/model/cbi/admin_network/routing.lua +++ /dev/null @@ -1,28 +0,0 @@ --- ToDo: Translate, Add descriptions and help texts -require("ffluci.sys") -m = Map("luci_fw", "Routing", [[An dieser Stelle wird festlegt, welcher Netzverkehr zwischen einzelnen -Schnittstellen erlaubt werden soll. Es werden jeweils nur neue Verbindungen -betrachtet, d.h. Pakete von aufgebauten oder zugehörigen Verbindungen werden automatisch in beide Richtungen -akzeptiert, auch wenn das Feld "beide Richtungen" nicht explizit gesetzt ist. -NAT ermöglicht Adressübersetzung.]]) - -s = m:section(TypedSection, "routing") -s.template = "cbi/tblsection" -s.addremove = true -s.anonymous = true - -iface = s:option(ListValue, "iface", "Eingang", "Eingangsschnittstelle") -oface = s:option(ListValue, "oface", "Ausgang", "Ausgangsschnittstelle") - -for k, v in pairs(ffluci.model.uci.sections("network")) do - if v[".type"] == "interface" and k ~= "loopback" then - iface:value(k) - oface:value(k) - end -end - -s:option(Flag, "fwd", "FWD", "weiterleiten").rmempty = true -s:option(Flag, "nat", "NAT", "übersetzen").rmempty = true -s:option(Flag, "bidi", "<->", "beide Richtungen").rmempty = true - -return m diff --git a/applications/luci-fw/src/model/cbi/luci_fw/firewall.lua b/applications/luci-fw/src/model/cbi/luci_fw/firewall.lua new file mode 100644 index 0000000000..7c89d07c55 --- /dev/null +++ b/applications/luci-fw/src/model/cbi/luci_fw/firewall.lua @@ -0,0 +1,73 @@ +-- ToDo: Translate, Add descriptions and help texts +m = Map("luci_fw", "Firewall", [[Mit Hilfe der Firewall können Zugriffe auf das Netzwerk +erlaubt, verboten oder umgeleitet werden.]]) + +s = m:section(TypedSection, "rule") +s.addremove = true +s.anonymous = true + +chain = s:option(ListValue, "chain", "Kette") +chain:value("forward", "Forward") +chain:value("input", "Input") +chain:value("output", "Output") +chain:value("prerouting", "Prerouting") +chain:value("postrouting", "Postrouting") + +iface = s:option(ListValue, "iface", "Eingangsschnittstelle") +iface.optional = true + +oface = s:option(ListValue, "oface", "Ausgangsschnittstelle") +oface.optional = true + +for k, v in pairs(ffluci.model.uci.sections("network")) do + if v[".type"] == "interface" and k ~= "loopback" then + iface:value(k) + oface:value(k) + end +end + +proto = s:option(ListValue, "proto", "Protokoll") +proto.optional = true +proto:value("") +proto:value("tcp", "TCP") +proto:value("udp", "UDP") + +s:option(Value, "source", "Quelladresse").optional = true +s:option(Value, "destination", "Zieladresse").optional = true +s:option(Value, "mac", "MAC-Adresse").optional = true + +sport = s:option(Value, "sport", "Quellport") +sport.optional = true +sport:depends("proto", "tcp") +sport:depends("proto", "udp") + +dport = s:option(Value, "dport", "Zielport") +dport.optional = true +dport:depends("proto", "tcp") +dport:depends("proto", "udp") + +tosrc = s:option(Value, "tosrc", "Neue Quelladresse [SNAT]") +tosrc.optional = true +tosrc:depends("jump", "SNAT") + +tosrc = s:option(Value, "todest", "Neue Zieladresse [DNAT]") +tosrc.optional = true +tosrc:depends("jump", "DNAT") + +jump = s:option(ListValue, "jump", "Aktion") +jump.rmempty = true +jump:value("", "") +jump:value("ACCEPT", "annehmen (ACCEPT)") +jump:value("REJECT", "zurückweisen (REJECT)") +jump:value("DROP", "verwerfen (DROP)") +jump:value("LOG", "protokollieren (LOG)") +jump:value("DNAT", "Ziel umschreiben (DNAT) [nur Prerouting]") +jump:value("MASQUERADE", "maskieren (MASQUERADE) [nur Postrouting]") +jump:value("SNAT", "Quelle umschreiben (SNAT) [nur Postrouting]") + + +add = s:option(Value, "command", "Eigener Befehl") +add.size = 50 +add.rmempty = true + +return m diff --git a/applications/luci-fw/src/model/cbi/luci_fw/portfw.lua b/applications/luci-fw/src/model/cbi/luci_fw/portfw.lua new file mode 100644 index 0000000000..90ebb4c24d --- /dev/null +++ b/applications/luci-fw/src/model/cbi/luci_fw/portfw.lua @@ -0,0 +1,28 @@ +-- ToDo: Translate, Add descriptions and help texts +require("ffluci.sys") +m = Map("luci_fw", "Portweiterleitung", [[Portweiterleitungen ermöglichen es interne +Netzwerkdienste von einem anderen externen Netzwerk aus erreichbar zu machen.]]) + +s = m:section(TypedSection, "portfw") +s.template = "cbi/tblsection" +s.addremove = true +s.anonymous = true + +iface = s:option(ListValue, "iface", "Schnittstelle", "Externe Schnittstelle") +iface.default = "wan" +for k, v in pairs(ffluci.model.uci.sections("network")) do + if v[".type"] == "interface" and k ~= "loopback" then + iface:value(k) + end +end + +proto = s:option(ListValue, "proto", "Protokoll") +proto:value("tcp", "TCP") +proto:value("udp", "UDP") +proto:value("tcpudp", "TCP + UDP") + +dport = s:option(Value, "dport", "Externer Port", "Port[:Endport]") + +to = s:option(Value, "to", "Interne Adresse", "IP-Adresse[:Zielport[-Zielendport]]") + +return m diff --git a/applications/luci-fw/src/model/cbi/luci_fw/routing.lua b/applications/luci-fw/src/model/cbi/luci_fw/routing.lua new file mode 100644 index 0000000000..5805b1d3f7 --- /dev/null +++ b/applications/luci-fw/src/model/cbi/luci_fw/routing.lua @@ -0,0 +1,28 @@ +-- ToDo: Translate, Add descriptions and help texts +require("ffluci.sys") +m = Map("luci_fw", "Routing", [[An dieser Stelle wird festlegt, welcher Netzverkehr zwischen einzelnen +Schnittstellen erlaubt werden soll. Es werden jeweils nur neue Verbindungen +betrachtet, d.h. Pakete von aufgebauten oder zugehörigen Verbindungen werden automatisch in beide Richtungen +akzeptiert, auch wenn das Feld "beide Richtungen" nicht explizit gesetzt ist. +NAT ermöglicht Adressübersetzung.]]) + +s = m:section(TypedSection, "routing") +s.template = "cbi/tblsection" +s.addremove = true +s.anonymous = true + +iface = s:option(ListValue, "iface", "Eingang", "Eingangsschnittstelle") +oface = s:option(ListValue, "oface", "Ausgang", "Ausgangsschnittstelle") + +for k, v in pairs(ffluci.model.uci.sections("network")) do + if v[".type"] == "interface" and k ~= "loopback" then + iface:value(k) + oface:value(k) + end +end + +s:option(Flag, "fwd", "FWD", "weiterleiten").rmempty = true +s:option(Flag, "nat", "NAT", "übersetzen").rmempty = true +s:option(Flag, "bidi", "<->", "beide Richtungen").rmempty = true + +return m diff --git a/applications/luci-fw/src/model/menu/50luci-fw.lua b/applications/luci-fw/src/model/menu/50luci-fw.lua deleted file mode 100644 index b7543b0621..0000000000 --- a/applications/luci-fw/src/model/menu/50luci-fw.lua +++ /dev/null @@ -1,4 +0,0 @@ -sel("admin", "network") -act("portfw", "Portweiterleitung") -act("routing", "Routing") -act("firewall", "Firewall") \ No newline at end of file diff --git a/applications/luci-splash/src/controller/splash/splash.lua b/applications/luci-splash/src/controller/splash/splash.lua index 62088be52d..7d837cd34d 100644 --- a/applications/luci-splash/src/controller/splash/splash.lua +++ b/applications/luci-splash/src/controller/splash/splash.lua @@ -1,5 +1,16 @@ module("ffluci.controller.splash.splash", package.seeall) +function index() + local page = node("admin", "services", "splash") + page.target = cbi("splash/splash") + page.title = "Client-Splash" + + node("splash", "splash", "activate").target = action_activate + node("splash", "splash", "allowed").target = action_allowed + node("splash", "splash", "unknown").target = action_unknown + node("splash", "splash", "splash").target = template("splash_splash/splash") +end + function action_activate() local mac = ffluci.sys.net.ip4mac(ffluci.http.env.REMOTE_ADDR) if mac and ffluci.http.formvalue("accept") then @@ -10,7 +21,7 @@ function action_activate() end end -function action_accepted() +function action_allowed() ffluci.http.redirect(ffluci.dispatcher.build_url()) end diff --git a/applications/luci-splash/src/model/cbi/admin_services/splash.lua b/applications/luci-splash/src/model/cbi/admin_services/splash.lua deleted file mode 100644 index fe4d2c3ee8..0000000000 --- a/applications/luci-splash/src/model/cbi/admin_services/splash.lua +++ /dev/null @@ -1,30 +0,0 @@ --- ToDo: Translate, Add descriptions and help texts -require("ffluci.model.uci") - -m = Map("luci_splash", "Client-Splash", [[Client-Splash ist das Freifunk Hotspot-Authentifizierungs-System.]]) - -s = m:section(NamedSection, "general", "core", "Allgemein") -s:option(Value, "leasetime", "Freigabezeit", "h") - -s = m:section(TypedSection, "iface", "Schnittstellen") -s.addremove = true -s.anonymous = true - -iface = s:option(ListValue, "network", "Schnittstelle") -for k, v in pairs(ffluci.model.uci.sections("network")) do - if v[".type"] == "interface" and k ~= "loopback" then - iface:value(k) - end -end - -s = m:section(TypedSection, "whitelist", "Automatische Freigabe") -s.addremove = true -s.anonymous = true -s:option(Value, "mac", "MAC-Adresse") - -s = m:section(TypedSection, "blacklist", "Automatische Sperrung") -s.addremove = true -s.anonymous = true -s:option(Value, "mac", "MAC-Adresse") - -return m \ No newline at end of file diff --git a/applications/luci-splash/src/model/cbi/splash/splash.lua b/applications/luci-splash/src/model/cbi/splash/splash.lua new file mode 100644 index 0000000000..fe4d2c3ee8 --- /dev/null +++ b/applications/luci-splash/src/model/cbi/splash/splash.lua @@ -0,0 +1,30 @@ +-- ToDo: Translate, Add descriptions and help texts +require("ffluci.model.uci") + +m = Map("luci_splash", "Client-Splash", [[Client-Splash ist das Freifunk Hotspot-Authentifizierungs-System.]]) + +s = m:section(NamedSection, "general", "core", "Allgemein") +s:option(Value, "leasetime", "Freigabezeit", "h") + +s = m:section(TypedSection, "iface", "Schnittstellen") +s.addremove = true +s.anonymous = true + +iface = s:option(ListValue, "network", "Schnittstelle") +for k, v in pairs(ffluci.model.uci.sections("network")) do + if v[".type"] == "interface" and k ~= "loopback" then + iface:value(k) + end +end + +s = m:section(TypedSection, "whitelist", "Automatische Freigabe") +s.addremove = true +s.anonymous = true +s:option(Value, "mac", "MAC-Adresse") + +s = m:section(TypedSection, "blacklist", "Automatische Sperrung") +s.addremove = true +s.anonymous = true +s:option(Value, "mac", "MAC-Adresse") + +return m \ No newline at end of file diff --git a/applications/luci-splash/src/model/menu/50luci-splash.lua b/applications/luci-splash/src/model/menu/50luci-splash.lua deleted file mode 100644 index 99f7caa52b..0000000000 --- a/applications/luci-splash/src/model/menu/50luci-splash.lua +++ /dev/null @@ -1,2 +0,0 @@ -sel("admin", "services") -act("splash", "Client-Splash") \ No newline at end of file diff --git a/applications/sgi-haserl/root/www/cgi-bin/ffluci b/applications/sgi-haserl/root/www/cgi-bin/ffluci index 183a6ad412..f3d85df642 100755 --- a/applications/sgi-haserl/root/www/cgi-bin/ffluci +++ b/applications/sgi-haserl/root/www/cgi-bin/ffluci @@ -1,4 +1,3 @@ #!/usr/bin/haserl --shell=luac -package.path = "/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;" .. package.path -package.cpath = "/usr/lib/lua/?.so;" .. package.cpath -require("ffluci.dispatcher").httpdispatch() \ No newline at end of file +require("ffluci.dispatcher").createindex() +ffluci.dispatcher.httpdispatch() \ No newline at end of file diff --git a/applications/sgi-webuci/root/lib/webuci/main.lua b/applications/sgi-webuci/root/lib/webuci/main.lua index 50ac8184b7..f21934e0a8 100644 --- a/applications/sgi-webuci/root/lib/webuci/main.lua +++ b/applications/sgi-webuci/root/lib/webuci/main.lua @@ -1,11 +1,9 @@ -package.path = "/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;" .. package.path -package.cpath = "/usr/lib/lua/?.so;" .. package.cpath module("webuci", package.seeall) function prepare_req(uri) env = {} env.REQUEST_URI = uri - require("ffluci.menu").get() + require("ffluci.dispatcher").createindex() end function init_req(context) @@ -19,5 +17,5 @@ function init_req(context) end function handle_req(context) - require("ffluci.dispatcher").httpdispatch() + ffluci.dispatcher.httpdispatch() end \ No newline at end of file diff --git a/build/config.mk b/build/config.mk index af0b443d53..372fc8a570 100644 --- a/build/config.mk +++ b/build/config.mk @@ -1,3 +1,3 @@ LUAC = luac LUAC_OPTIONS = -s -LUCI_INSTALLDIR = /usr/lib/lua/ffluci \ No newline at end of file +LUCI_INSTALLDIR = /usr/lib/lua/5.1/ffluci \ No newline at end of file diff --git a/contrib/package/ffluci/Makefile b/contrib/package/ffluci/Makefile index ca75402611..34c796e2d2 100644 --- a/contrib/package/ffluci/Makefile +++ b/contrib/package/ffluci/Makefile @@ -5,7 +5,7 @@ PKG_SOURCE_URL:=https://dev.leipzig.freifunk.net/svn/ff-luci/$(PKG_BRANCH) PKG_REV:=$(shell LC_ALL=C svn info ${PKG_SOURCE_URL} | sed -ne's/^Last Changed Rev: //p') PKG_NAME:=ffluci -PKG_VERSION:=0.4+svn$(PKG_REV) +PKG_VERSION:=0.5+svn$(PKG_REV) PKG_RELEASE:=1 PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) diff --git a/contrib/package/lua-luci/patches/200-lua-path.patch b/contrib/package/lua-luci/patches/200-lua-path.patch index 62dd00e399..60797e98de 100644 --- a/contrib/package/lua-luci/patches/200-lua-path.patch +++ b/contrib/package/lua-luci/patches/200-lua-path.patch @@ -1,15 +1,36 @@ ---- b/src/luaconf.h 2008-05-06 20:10:46.000000000 +0200 -+++ a/src/luaconf.h 2008-05-06 20:10:27.000000000 +0200 -@@ -95,9 +95,9 @@ - ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" - +diff -ur lua-5.1.3/etc/lua.pc lua-5.1.3-new/etc/lua.pc +--- lua-5.1.3/etc/lua.pc 2008-01-11 14:12:59.000000000 +0100 ++++ lua-5.1.3-new/etc/lua.pc 2008-05-18 22:09:24.000000000 +0200 +@@ -8,7 +8,7 @@ + R= 5.1.3 + + # grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/' +-prefix= /usr/local ++prefix= /usr + INSTALL_BIN= ${prefix}/bin + INSTALL_INC= ${prefix}/include + INSTALL_LIB= ${prefix}/lib +diff -ur lua-5.1.3/Makefile lua-5.1.3-new/Makefile +--- lua-5.1.3/Makefile 2008-05-18 22:06:55.000000000 +0200 ++++ lua-5.1.3-new/Makefile 2008-05-18 22:09:13.000000000 +0200 +@@ -12,7 +12,7 @@ + # doc directory.) You may want to make these paths consistent with LUA_ROOT, + # LUA_LDIR, and LUA_CDIR in luaconf.h (and also with etc/lua.pc). + # +-INSTALL_TOP= /usr/local ++INSTALL_TOP= /usr + INSTALL_BIN= $(INSTALL_TOP)/bin + INSTALL_INC= $(INSTALL_TOP)/include + INSTALL_LIB= $(INSTALL_TOP)/lib +diff -ur lua-5.1.3/src/luaconf.h lua-5.1.3-new/src/luaconf.h +--- lua-5.1.3/src/luaconf.h 2008-05-18 22:07:11.000000000 +0200 ++++ lua-5.1.3-new/src/luaconf.h 2008-05-18 22:09:50.000000000 +0200 +@@ -95,7 +95,7 @@ + ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" + #else --#define LUA_ROOT "/usr/local/" --#define LUA_LDIR LUA_ROOT "share/lua/5.1/" --#define LUA_CDIR LUA_ROOT "lib/lua/5.1/" -+#define LUA_ROOT "/usr/" -+#define LUA_LDIR LUA_ROOT "share/lua/" -+#define LUA_CDIR LUA_ROOT "lib/lua/" +-#define LUA_ROOT "/usr/local/" ++#define LUA_ROOT "/usr/" + #define LUA_LDIR LUA_ROOT "share/lua/5.1/" + #define LUA_CDIR LUA_ROOT "lib/lua/5.1/" #define LUA_PATH_DEFAULT \ - "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ - LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua" diff --git a/core/root/etc/config/luci b/core/root/etc/config/luci index b15b152894..7a7aa333e8 100644 --- a/core/root/etc/config/luci +++ b/core/root/etc/config/luci @@ -1,10 +1,9 @@ config core main - option lang de - option mediaurlbase /ffluci/media - option imagebase /ffluci/images - -config core category_privileges - option public nobody:nogroup + option lang de + option mediaurlbase /ffluci/media + option resourcebase /ffluci/images + option title "Freifunk Kamikaze" + option subtitle Fledermausedition config extern flash_keep option uci "/etc/config" diff --git a/core/src/dispatcher.lua b/core/src/dispatcher.lua index 0a66ccd3ad..84c665edab 100644 --- a/core/src/dispatcher.lua +++ b/core/src/dispatcher.lua @@ -4,63 +4,6 @@ FFLuCI - Dispatcher Description: The request dispatcher and module dispatcher generators - -The dispatching process: - For a detailed explanation of the dispatching process we assume: - You have installed the FFLuCI CGI-Dispatcher in /cgi-bin/ffluci - - To enforce a higher level of security only the CGI-Dispatcher - resides inside the web server's document root, everything else - stays inside an external directory, we assume this is /lua/ffluci - for this explanation. - - All controllers and action are reachable as sub-objects of /cgi-bin/ffluci - as if they were virtual folders and files - e.g.: /cgi-bin/ffluci/public/info/about - /cgi-bin/ffluci/admin/network/interfaces - and so on. - - The PATH_INFO variable holds the dispatch path and - will be split into three parts: /category/module/action - - Category: This is the category in which modules are stored in - By default there are two categories: - "public" - which is the default public category - "admin" - which is the default protected category - - As FFLuCI itself does not implement authentication - you should make sure that "admin" and other sensitive - categories are protected by the webserver. - - E.g. for busybox add a line like: - /cgi-bin/ffluci/admin:root:$p$root - to /etc/httpd.conf to protect the "admin" category - - - Module: This is the controller which will handle the request further - It is always a submodule of ffluci.controller, so a module - called "helloworld" will be stored in - /lua/ffluci/controller/helloworld.lua - You are free to submodule your controllers any further. - - Action: This is action that will be invoked after loading the module. - The kind of how the action will be dispatched depends on - the module dispatcher that is defined in the controller. - See the description of the default module dispatcher down - on this page for some examples. - - - The main dispatcher at first searches for the module by trying to - include ffluci.controller.category.module - (where "category" is the category name and "module" is the module name) - If this fails a 404 status code will be send to the client and FFLuCI exits - - Then the main dispatcher calls the module dispatcher - ffluci.controller.category.module.dispatcher with the request object - as the only argument. The module dispatcher is then responsible - for the further dispatching process. - - FileId: $Id$ @@ -80,48 +23,24 @@ See the License for the specific language governing permissions and limitations under the License. ]]-- - module("ffluci.dispatcher", package.seeall) require("ffluci.http") -require("ffluci.template") -require("ffluci.config") require("ffluci.sys") +require("ffluci.fs") --- Sets privilege for given category -function assign_privileges(category) - local cp = ffluci.config.category_privileges - if cp and cp[category] then - local u, g = cp[category]:match("([^:]+):([^:]+)") - ffluci.sys.process.setuser(u) - ffluci.sys.process.setgroup(g) - end -end +-- Local dispatch database +local tree = {nodes={}} +-- Global request object +request = {} --- Builds a URL from a triple of category, module and action -function build_url(category, module, action) - category = category or "public" - module = module or "index" - action = action or "index" - - local pattern = ffluci.http.dispatcher() .. "/%s/%s/%s" - return pattern:format(category, module, action) -end +-- Active dispatched node +dispatched = nil --- Dispatches the "request" -function dispatch(req) - request = req - local m = "ffluci.controller." .. request.category .. "." .. request.module - local stat, module = pcall(require, m) - if not stat then - return error404() - else - module.request = request - module.dispatcher = module.dispatcher or dynamic - setfenv(module.dispatcher, module) - return module.dispatcher(request) - end +-- Builds a URL +function build_url(...) + return ffluci.http.dispatcher() .. "/" .. table.concat(arg, "/") end -- Sends a 404 error code and renders the "error404" template if available @@ -129,6 +48,7 @@ function error404(message) ffluci.http.status(404, "Not Found") message = message or "Not Found" + require("ffluci.template") if not pcall(ffluci.template.render, "error404") then ffluci.http.prepare_content("text/plain") print(message) @@ -140,6 +60,7 @@ end function error500(message) ffluci.http.status(500, "Internal Server Error") + require("ffluci.template") if not pcall(ffluci.template.render, "error500", {message=message}) then ffluci.http.prepare_content("text/plain") print(message) @@ -147,154 +68,124 @@ function error500(message) return false end - -- Dispatches a request depending on the PATH_INFO variable function httpdispatch() local pathinfo = ffluci.http.env.PATH_INFO or "" - local parts = pathinfo:gmatch("/[%w-]+") + local c = tree - local sanitize = function(s, default) - return s and s:sub(2) or default + for s in pathinfo:gmatch("/([%w-]+)") do + table.insert(request, s) end - local cat = sanitize(parts(), "public") - local mod = sanitize(parts(), "index") - local act = sanitize(parts(), "index") - - assign_privileges(cat) - dispatch({category=cat, module=mod, action=act}) -end - - --- Dispatchers -- - - --- The Action Dispatcher searches the module for any function called --- action_"request.action" and calls it -function action(...) - local disp = require("ffluci.dispatcher") - if not disp._action(...) then - disp.error404() - end + dispatch() end --- The CBI dispatcher directly parses and renders the CBI map which is --- placed in ffluci/modles/cbi/"request.module"/"request.action" -function cbi(...) - local disp = require("ffluci.dispatcher") - if not disp._cbi(...) then - disp.error404() +function dispatch() + local c = tree + local track = {} + + for i, s in ipairs(request) do + c = c.nodes[s] + if not c then + break + end + + for k, v in pairs(c) do + track[k] = v + end end -end - --- The dynamic dispatcher chains the action, submodule, simpleview and CBI dispatcher --- in this particular order. It is the default dispatcher. -function dynamic(...) - local disp = require("ffluci.dispatcher") - if not disp._action(...) - and not disp._submodule(...) - and not disp._simpleview(...) - and not disp._cbi(...) then - disp.error404() + + + if track.i18n then + require("ffluci.i18n").loadc(track.i18n) end -end - --- The Simple View Dispatcher directly renders the template --- which is placed in ffluci/views/"request.module"/"request.action" -function simpleview(...) - local disp = require("ffluci.dispatcher") - if not disp._simpleview(...) then - disp.error404() + + if track.setuser then + ffluci.sys.process.setuser(track.setuser) end -end - - --- The submodule dispatcher tries to load a submodule of the controller --- and calls its "action"-function -function submodule(...) - local disp = require("ffluci.dispatcher") - if not disp._submodule(...) then - disp.error404() + + if track.setgroup then + ffluci.sys.process.setgroup(track.setgroup) end -end - - --- Internal Dispatcher Functions -- - -function _action(request) - local action = getfenv(2)["action_" .. request.action:gsub("-", "_")] - local i18n = require("ffluci.i18n") - if action then - i18n.loadc(request.category .. "_" .. request.module) - i18n.loadc(request.category .. "_" .. request.module .. "_" .. request.action) - action() - return true + + if c and type(c.target) == "function" then + dispatched = c + + stat, err = pcall(c.target) + if not stat then + error500(err) + end else - return false + error404() end end -function _cbi(request) - local disp = require("ffluci.dispatcher") - local tmpl = require("ffluci.template") - local cbi = require("ffluci.cbi") - local i18n = require("ffluci.i18n") - - local path = request.category.."_"..request.module.."/"..request.action +-- Calls the index function of all available controllers +function createindex() + local root = ffluci.sys.libpath() .. "/controller/" + local suff = ".lua" + for i,c in ipairs(ffluci.fs.glob(root .. "*/*" .. suff)) do + c = "ffluci.controller." .. c:sub(#root+1, #c-#suff):gsub("/", ".", 1) + stat, mod = pcall(require, c) - local stat, map = pcall(cbi.load, path) - if stat and map then - local stat, err = pcall(map.parse, map) - if not stat then - disp.error500(err) - return true + if stat and mod and type(mod.index) == "function" then + ffluci.util.updfenv(mod.index, ffluci.dispatcher) + pcall(mod.index) end - i18n.loadc(request.category .. "_" .. request.module) - i18n.loadc(request.category .. "_" .. request.module .. "_" .. request.action) - tmpl.render("cbi/header") - map:render() - tmpl.render("cbi/footer") - return true - elseif not stat then - disp.error500(map) - return true - else - return false end end -function _simpleview(request) - local i18n = require("ffluci.i18n") - local tmpl = require("ffluci.template") +-- Fetch a dispatching node +function node(...) + local c = tree - local path = request.category.."_"..request.module.."/"..request.action + for k,v in ipairs(arg) do + if not c.nodes[v] then + c.nodes[v] = {nodes={}} + end + + c = c.nodes[v] + end - local stat, t = pcall(tmpl.Template, path) - if stat then - i18n.loadc(request.category .. "_" .. request.module) - i18n.loadc(request.category .. "_" .. request.module .. "_" .. request.action) - t:render() - return true - else - return false + return c +end + +-- Subdispatchers -- +function alias(...) + local req = arg + return function() + request = req + dispatch() end end +function template(name) + require("ffluci.template") + return function() ffluci.template.render(name) end +end -function _submodule(request) - local i18n = require("ffluci.i18n") - local m = "ffluci.controller." .. request.category .. "." .. - request.module .. "." .. request.action - local stat, module = pcall(require, m) +function cbi(model) + require("ffluci.cbi") + require("ffluci.template") - if stat and module.action then - i18n.loadc(request.category .. "_" .. request.module) - i18n.loadc(request.category .. "_" .. request.module .. "_" .. request.action) - return pcall(module.action) + return function() + local stat, res = pcall(ffluci.cbi.load, model) + if not stat then + error500(res) + return true + end + + local stat, err = pcall(res.parse, res) + if not stat then + error500(err) + return true + end + + ffluci.template.render("cbi/header") + res:render() + ffluci.template.render("cbi/footer") end - - return false end \ No newline at end of file diff --git a/core/src/i18n/default.en b/core/src/i18n/default.en index 726095ae76..d76b770e96 100644 --- a/core/src/i18n/default.en +++ b/core/src/i18n/default.en @@ -10,13 +10,5 @@ apply = "Apply" changes = "Changes" revert = "Revert" -index = "Overview" -system = "System" -services = "Services" -network = "Network" -wifi = "Wifi" -status = "Status" -statistic = "Statistic" - config = "Configuration" path = "Path" \ No newline at end of file diff --git a/core/src/init.lua b/core/src/init.lua index 8d4cea2e96..f54854e4e5 100644 --- a/core/src/init.lua +++ b/core/src/init.lua @@ -25,5 +25,5 @@ limitations under the License. ]]-- module("ffluci", package.seeall) -__version__ = "0.4" +__version__ = "0.5" __appname__ = "FFLuCI" diff --git a/core/src/menu.lua b/core/src/menu.lua index d6f65116e4..9328e332c2 100644 --- a/core/src/menu.lua +++ b/core/src/menu.lua @@ -28,6 +28,7 @@ module("ffluci.menu", package.seeall) require("ffluci.fs") require("ffluci.util") require("ffluci.sys") +require("ffluci.dispatcher") -- Default modelpath modelpattern = ffluci.sys.libpath() .. "/model/menu/*.lua" @@ -39,98 +40,7 @@ scope = { isfile = ffluci.fs.isfile } --- Local menu database -local menu = nil - --- The current pointer -local menuc = {} - --- Adds a menu category to the current menu and selects it -function add(cat, controller, title, order) - order = order or 100 - if not menu[cat] then - menu[cat] = {} - end - - local entry = {} - entry[".descr"] = title - entry[".order"] = order - entry[".contr"] = controller - - menuc = entry - - local i = 0 - for k,v in ipairs(menu[cat]) do - if v[".order"] > entry[".order"] then - break - end - i = k - end - table.insert(menu[cat], i+1, entry) - - return true -end - --- Adds an action to the current menu -function act(action, title) - table.insert(menuc, {action = action, descr = title}) - return true -end - --- Selects a menu category -function sel(cat, controller) - if not menu[cat] then - return nil - end - menuc = menu[cat] - - local stat = nil - for k,v in ipairs(menuc) do - if v[".contr"] == controller then - menuc = v - stat = true - end - end - - return stat -end - - --- Collect all menu information provided in the model dir -function collect() - local generators = {} - - local m = ffluci.fs.glob(modelpattern) or {} - for k, menu in pairs(m) do - local f = loadfile(menu) - if f then - table.insert(generators, f) - end - end - - return generators -end - --- Parse the collected information -function parse(generators) - menu = {} - for i, f in pairs(generators) do - local env = ffluci.util.clone(scope) - - env.add = add - env.sel = sel - env.act = act - - setfenv(f, env) - f() - end - return menu -end - -- Returns the menu information function get() - if not menu then - menu = parse(collect()) - end return menu end \ No newline at end of file diff --git a/core/src/template.lua b/core/src/template.lua index 6f4e4adb03..a56b49d83a 100644 --- a/core/src/template.lua +++ b/core/src/template.lua @@ -55,7 +55,7 @@ viewns = { controller = ffluci.http.dispatcher(), uploadctrl = ffluci.http.dispatcher_upload(), media = ffluci.config.main.mediaurlbase, - images = ffluci.config.main.imagebase, + resource = ffluci.config.main.resourcebase, write = io.write, include = function(name) Template(name):render(getfenv(2)) end, } diff --git a/core/src/view/footer.htm b/core/src/view/footer.htm index 67856771b4..f324408a1c 100644 --- a/core/src/view/footer.htm +++ b/core/src/view/footer.htm @@ -2,6 +2,6 @@
-
FFLuCI 0.3 - Freifunk Lua Configuration Interface
+
<%=require("ffluci").__appname__ .. " " .. ffluci.__version__%> - Freifunk Lua Configuration Interface
\ No newline at end of file diff --git a/core/src/view/header.htm b/core/src/view/header.htm index 9bb8b8be99..99b43805d3 100644 --- a/core/src/view/header.htm +++ b/core/src/view/header.htm @@ -1,21 +1,33 @@ <% require("ffluci.sys") local load1, load5, load15 = ffluci.sys.loadavg() -local req = require("ffluci.dispatcher").request -local menu = require("ffluci.menu").get()[req.category] -menu = menu or {} + +local request = require("ffluci.dispatcher").request +local category = request[1] +local tree = ffluci.dispatcher.node() +local cattree = category and ffluci.dispatcher.node(category) +local node = ffluci.dispatcher.dispatched + +local c = tree +for i,r in ipairs(request) do + if c.nodes and c.nodes[r] then + c = c.nodes[r] + c._menu_selected = true + end +end + require("ffluci.i18n").loadc("default") + require("ffluci.http").prepare_content("text/html") %> - - + <% if node and node.css then %><% end %> - FFLuCI + FFLuCI - Freifunk Lua Configuration Interface
- Freifunk Kamikaze
- <%:batmanedition Fledermausedition%> + <%~luci.main.title%>
+ <%~luci.main.subtitle%>
-<%:path Pfad%>: "><%=translate(req.category, req.category)%>"><%=translate(req.module, req.module)%>"><%=translate(req.action, req.action)%> +<%:path Pfad%>: <% +local c = tree +local url = controller +for k,v in pairs(request) do + if c.nodes and c.nodes[v] then + c = c.nodes[v] + url = url .. "/" .. v + %><%=c.title or v%> <% if k ~= #request then %>» <% end + end +end +%>
+<% +local function submenu(prefix, node) + if not node._menu_selected or not node.nodes then + return false + end + local index = {} + for k, n in pairs(node.nodes) do + table.insert(index, {name=k, order=n.order or 100}) + end + + table.sort(index, function(a, b) return a.order < b.order end) +%> +
    + <% for j, v in pairs(index) do + local nnode = node.nodes[v.name]%> +
  • + class="yellowtext"<%end%>><%=nnode.title%> + <% submenu(prefix .. v.name .. "/", nnode) %> +
  • <% end %> +
+<% +end + +if cattree and cattree.nodes then + local index = {} + for k, node in pairs(cattree.nodes) do + table.insert(index, {name=k, order=node.order or 100}) + end + + table.sort(index, function(a, b) return a.order < b.order end) + + for i, k in ipairs(index) do + node = cattree.nodes[k.name] + if node.title then %> + class="yellowtext"<%end%>><%=node.title%> + <%submenu("/" .. category .. "/" .. k.name .. "/", node)%> +
+<% end + end +end +%>