diff options
Diffstat (limited to 'modules/admin-full/luasrc/controller')
7 files changed, 520 insertions, 0 deletions
diff --git a/modules/admin-full/luasrc/controller/admin/index.lua b/modules/admin-full/luasrc/controller/admin/index.lua new file mode 100644 index 000000000..eb58e0042 --- /dev/null +++ b/modules/admin-full/luasrc/controller/admin/index.lua @@ -0,0 +1,49 @@ +--[[ +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.admin.index", package.seeall) + +function index() + luci.i18n.loadc("admin-core") + local i18n = luci.i18n.translate + + local root = node() + if not root.target then + root.target = alias("admin") + end + + entry({"about"}, template("about")).i18n = "admin-core" + + local page = node("admin") + page.target = alias("admin", "index") + page.title = i18n("administration", "Administration") + page.order = 10 + page.i18n = "admin-core" + page.sysauth = "root" + + local page = node("admin", "index") + page.target = template("admin_index/index") + page.title = i18n("overview", "Übersicht") + page.order = 10 + + local page = node("admin", "index", "luci") + page.target = cbi("admin_index/luci") + page.title = i18n("a_i_ui", "Oberfläche") + + entry({"admin", "logout"}, call("action_logout"), i18n("logout")) +end + +function action_logout() + luci.http.header("Set-Cookie", "sysauth=; path=/") + luci.http.redirect(luci.dispatcher.build_url()) +end
\ No newline at end of file diff --git a/modules/admin-full/luasrc/controller/admin/network.lua b/modules/admin-full/luasrc/controller/admin/network.lua new file mode 100644 index 000000000..871263334 --- /dev/null +++ b/modules/admin-full/luasrc/controller/admin/network.lua @@ -0,0 +1,49 @@ +--[[ +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.admin.network", package.seeall) + +function index() + require("luci.i18n") + local i18n = luci.i18n.translate + + local page = node("admin", "network") + page.target = template("admin_network/index") + page.title = i18n("network", "Netzwerk") + page.order = 50 + + local page = node("admin", "network", "vlan") + page.target = cbi("admin_network/vlan") + page.title = i18n("a_n_switch", "Switch") + page.order = 10 + + local page = node("admin", "network", "ifaces") + page.target = cbi("admin_network/ifaces") + page.title = i18n("interfaces", "Schnittstellen") + page.order = 20 + + local page = node("admin", "network", "dhcp") + page.target = cbi("admin_network/dhcp") + page.title = "DHCP" + page.order = 30 + + local page = node("admin", "network", "ptp") + page.target = cbi("admin_network/ptp") + page.title = "PPPoE / PPTP" + page.order = 40 + + local page = node("admin", "network", "routes") + page.target = cbi("admin_network/routes") + page.title = i18n("a_n_routes", "Routen") + page.order = 50 +end
\ No newline at end of file diff --git a/modules/admin-full/luasrc/controller/admin/services.lua b/modules/admin-full/luasrc/controller/admin/services.lua new file mode 100644 index 000000000..59defbbbd --- /dev/null +++ b/modules/admin-full/luasrc/controller/admin/services.lua @@ -0,0 +1,39 @@ +--[[ +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.admin.services", package.seeall) + +function index() + luci.i18n.loadc("admin-core") + local i18n = luci.i18n.translate + + local page = node("admin", "services") + page.target = template("admin_services/index") + page.title = i18n("services", "Dienste") + page.order = 40 + + local page = node("admin", "services", "httpd") + page.target = cbi("admin_services/httpd") + page.title = "Busybox HTTPd" + page.order = 10 + + local page = node("admin", "services", "dropbear") + page.target = cbi("admin_services/dropbear") + page.title = "Dropbear SSHd" + page.order = 20 + + local page = node("admin", "services", "dnsmasq") + page.target = cbi("admin_services/dnsmasq") + page.title = "Dnsmasq" + page.order = 30 +end
\ No newline at end of file diff --git a/modules/admin-full/luasrc/controller/admin/status.lua b/modules/admin-full/luasrc/controller/admin/status.lua new file mode 100644 index 000000000..3a0f04074 --- /dev/null +++ b/modules/admin-full/luasrc/controller/admin/status.lua @@ -0,0 +1,29 @@ +--[[ +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.admin.status", package.seeall) + +function index() + luci.i18n.loadc("admin-core") + local i18n = luci.i18n.translate + + entry({"admin", "status"}, template("admin_status/index"), i18n("status", "Status"), 20) + entry({"admin", "status", "syslog"}, call("action_syslog"), i18n("syslog", "Systemprotokoll")) + entry({"admin", "status", "routes"}, template("admin_status/routes"), "Routingtabelle", 10) + entry({"admin", "status", "iwscan"}, template("admin_status/iwscan"), "WLAN-Scan", 20) +end + +function action_syslog() + local syslog = luci.sys.syslog() + luci.template.render("admin_status/syslog", {syslog=syslog}) +end
\ No newline at end of file diff --git a/modules/admin-full/luasrc/controller/admin/system.lua b/modules/admin-full/luasrc/controller/admin/system.lua new file mode 100644 index 000000000..862a741cd --- /dev/null +++ b/modules/admin-full/luasrc/controller/admin/system.lua @@ -0,0 +1,221 @@ +--[[ +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.admin.system", package.seeall) + +function index() + luci.i18n.loadc("admin-core") + local i18n = luci.i18n.translate + + entry({"admin", "system"}, template("admin_system/index"), i18n("system", "System"), 30) + entry({"admin", "system", "packages"}, call("action_packages"), i18n("a_s_packages", "Paketverwaltung"), 10) + entry({"admin", "system", "packages", "ipkg"}, call("action_ipkg"), i18n("a_s_p_ipkg", "IPKG-Konfiguration")) + entry({"admin", "system", "passwd"}, call("action_passwd"), i18n("a_s_changepw", "Passwort ändern"), 20) + entry({"admin", "system", "sshkeys"}, call("action_sshkeys"), i18n("a_s_sshkeys", "SSH-Schlüssel"), 30) + entry({"admin", "system", "system"}, cbi("admin_system/system"), i18n("system", "System"), 40) + entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), i18n("a_s_fstab", "Einhängepunkte"), 50) + entry({"admin", "system", "upgrade"}, call("action_upgrade"), i18n("a_s_flash", "Firmwareupgrade"), 60) + entry({"admin", "system", "reboot"}, call("action_reboot"), i18n("reboot", "Neu starten"), 70) +end + +function action_editor() + local file = luci.http.formvalue("file", "") + local data = luci.http.formvalue("data") + local err = nil + local msg = nil + local stat = true + + if file and data then + stat, err = luci.fs.writefile(file, data) + end + + if not stat then + err = luci.util.split(err, " ") + table.remove(err, 1) + msg = table.concat(err, " ") + end + + local cnt, err = luci.fs.readfile(file) + if cnt then + cnt = luci.util.pcdata(cnt) + end + luci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg}) +end + +function action_ipkg() + local file = "/etc/ipkg.conf" + local data = luci.http.formvalue("data") + local stat = nil + local err = nil + + if data then + stat, err = luci.fs.writefile(file, data) + end + + local cnt = luci.fs.readfile(file) + if cnt then + cnt = luci.util.pcdata(cnt) + end + + luci.template.render("admin_system/ipkg", {cnt=cnt, msg=err}) +end + +function action_packages() + local ipkg = require("luci.model.ipkg") + local void = nil + local submit = luci.http.formvalue("submit") + + + -- Search query + local query = luci.http.formvalue("query") + query = (query ~= '') and query or nil + + + -- Packets to be installed + local install = submit and luci.http.formvaluetable("install") + + -- Install from URL + local url = luci.http.formvalue("url") + if url and url ~= '' and submit then + if not install then + install = {} + end + install[url] = 1 + end + + -- Do install + if install then + for k, v in pairs(install) do + void, install[k] = ipkg.install(k) + end + end + + + -- Remove packets + local remove = submit and luci.http.formvaluetable("remove") + if remove then + for k, v in pairs(remove) do + void, remove[k] = ipkg.remove(k) + end + end + + + -- Update all packets + local update = luci.http.formvalue("update") + if update then + void, update = ipkg.update() + end + + + -- Upgrade all packets + local upgrade = luci.http.formvalue("upgrade") + if upgrade then + void, upgrade = ipkg.upgrade() + end + + + -- Package info + local info = luci.model.ipkg.info(query) + info = info or {} + local pkgs = {} + + -- Sort after status and name + for k, v in pairs(info) do + local x = 0 + for i, j in pairs(pkgs) do + local vins = (v.Status and v.Status.installed) + local jins = (j.Status and j.Status.installed) + if vins ~= jins then + if vins then + break + end + else + if j.Package > v.Package then + break + end + end + x = i + end + table.insert(pkgs, x+1, v) + end + + luci.template.render("admin_system/packages", {pkgs=pkgs, query=query, + install=install, remove=remove, update=update, upgrade=upgrade}) +end + +function action_passwd() + local p1 = luci.http.formvalue("pwd1") + local p2 = luci.http.formvalue("pwd2") + local stat = nil + + if p1 or p2 then + if p1 == p2 then + stat = luci.sys.user.setpasswd("root", p1) + else + stat = 10 + end + end + + luci.template.render("admin_system/passwd", {stat=stat}) +end + +function action_reboot() + local reboot = luci.http.formvalue("reboot") + luci.template.render("admin_system/reboot", {reboot=reboot}) + if reboot then + luci.sys.reboot() + end +end + +function action_sshkeys() + local file = "/etc/dropbear/authorized_keys" + local data = luci.http.formvalue("data") + local stat = nil + local err = nil + + if data then + stat, err = luci.fs.writefile(file, data) + end + + local cnt = luci.fs.readfile(file) + if cnt then + cnt = luci.util.pcdata(cnt) + end + + luci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err}) +end + +function action_upgrade() + require("luci.model.uci") + local ret = nil + local plat = luci.fs.mtime("/lib/upgrade/platform.sh") + + local image = luci.http.upload("image") + local keepcfg = luci.http.formvalue("keepcfg") + + if plat and image then + local kpattern = nil + if keepcfg then + local files = luci.model.uci.get_all("luci", "flash_keep") + if files.luci and files.luci.flash_keep then + kpattern = "" + for k,v in pairs(files.luci.flash_keep) do + kpattern = kpattern .. " " .. v + end + end + end + ret = luci.sys.flash(image, kpattern) + end + + luci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret}) +end
\ No newline at end of file diff --git a/modules/admin-full/luasrc/controller/admin/uci.lua b/modules/admin-full/luasrc/controller/admin/uci.lua new file mode 100644 index 000000000..215a13a34 --- /dev/null +++ b/modules/admin-full/luasrc/controller/admin/uci.lua @@ -0,0 +1,99 @@ +--[[ +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.admin.uci", package.seeall) + +function index() + local i18n = luci.i18n.translate + + entry({"admin", "uci"}, nil, i18n("config")) + entry({"admin", "uci", "changes"}, call("action_changes"), i18n("changes")) + entry({"admin", "uci", "revert"}, call("action_revert"), i18n("revert")) + entry({"admin", "uci", "apply"}, call("action_apply"), i18n("apply")) +end + +function convert_changes(changes) + local ret = {} + for r, tbl in pairs(changes) do + for s, os in pairs(tbl) do + for o, v in pairs(os) do + local val, str + if (v == "") then + str = "-" + val = "" + else + str = "" + val = "="..v + end + str = r.."."..s + if o ~= ".type" then + str = str.."."..o + end + table.insert(ret, str..val) + end + end + end + return table.concat(ret, "\n") +end + +function action_changes() + local changes = convert_changes(luci.model.uci.changes()) + luci.template.render("admin_uci/changes", {changes=changes}) +end + +function action_apply() + local changes = luci.model.uci.changes() + local output = "" + + if changes then + local com = {} + local run = {} + + -- Collect files to be applied and commit changes + for r, tbl in pairs(changes) do + if r then + luci.model.uci.load(r) + luci.model.uci.commit(r) + luci.model.uci.unload(r) + if luci.config.uci_oncommit and luci.config.uci_oncommit[r] then + run[luci.config.uci_oncommit[r]] = true + end + end + end + + -- Search for post-commit commands + for cmd, i in pairs(run) do + output = output .. cmd .. ":" .. luci.sys.exec(cmd) .. "\n" + end + end + + + luci.template.render("admin_uci/apply", {changes=convert_changes(changes), output=output}) +end + + +function action_revert() + local changes = luci.model.uci.changes() + if changes then + local revert = {} + + -- Collect files to be reverted + for r, tbl in pairs(changes) do + luci.model.uci.load(r) + luci.model.uci.revert(r) + luci.model.uci.unload(r) + end + end + + luci.template.render("admin_uci/revert", {changes=convert_changes(changes)}) +end diff --git a/modules/admin-full/luasrc/controller/admin/wifi.lua b/modules/admin-full/luasrc/controller/admin/wifi.lua new file mode 100644 index 000000000..4bef0b7a5 --- /dev/null +++ b/modules/admin-full/luasrc/controller/admin/wifi.lua @@ -0,0 +1,34 @@ +--[[ +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.admin.wifi", package.seeall) + +function index() + luci.i18n.loadc("admin-core") + local i18n = luci.i18n.translate + + local page = node("admin", "wifi") + page.target = template("admin_wifi/index") + page.title = i18n("wifi", "Drahtlos") + page.order = 60 + + local page = node("admin", "wifi", "devices") + page.target = cbi("admin_wifi/devices") + page.title = i18n("devices", "Geräte") + page.order = 10 + + local page = node("admin", "wifi", "networks") + page.target = cbi("admin_wifi/networks") + page.title = i18n("networks", "Netze") + page.order = 20 +end
\ No newline at end of file |