summaryrefslogtreecommitdiffhomepage
path: root/modules/admin-core/src/controller
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-05-08 15:37:41 +0000
committerSteven Barth <steven@midlink.org>2008-05-08 15:37:41 +0000
commitaa9ccf77c6648515ba58c37b9345cdbd561028db (patch)
treeb0270202d47b6c5e179f8475302bb3ef0d1c9402 /modules/admin-core/src/controller
parenta3a51464fd8cffa6d18fa3f18be9c699901abd0d (diff)
* Mördercommit ;-)
* Major Repository Reorganisation * API 0.4 Softfreeze to come
Diffstat (limited to 'modules/admin-core/src/controller')
-rw-r--r--modules/admin-core/src/controller/admin/index.lua1
-rw-r--r--modules/admin-core/src/controller/admin/network.lua1
-rw-r--r--modules/admin-core/src/controller/admin/services.lua1
-rw-r--r--modules/admin-core/src/controller/admin/system.lua200
-rw-r--r--modules/admin-core/src/controller/admin/uci.lua61
-rw-r--r--modules/admin-core/src/controller/admin/wifi.lua1
6 files changed, 265 insertions, 0 deletions
diff --git a/modules/admin-core/src/controller/admin/index.lua b/modules/admin-core/src/controller/admin/index.lua
new file mode 100644
index 0000000000..b4a7720f8b
--- /dev/null
+++ b/modules/admin-core/src/controller/admin/index.lua
@@ -0,0 +1 @@
+module("ffluci.controller.admin.index", package.seeall) \ No newline at end of file
diff --git a/modules/admin-core/src/controller/admin/network.lua b/modules/admin-core/src/controller/admin/network.lua
new file mode 100644
index 0000000000..0e3165f085
--- /dev/null
+++ b/modules/admin-core/src/controller/admin/network.lua
@@ -0,0 +1 @@
+module("ffluci.controller.admin.network", package.seeall) \ No newline at end of file
diff --git a/modules/admin-core/src/controller/admin/services.lua b/modules/admin-core/src/controller/admin/services.lua
new file mode 100644
index 0000000000..42181212bd
--- /dev/null
+++ b/modules/admin-core/src/controller/admin/services.lua
@@ -0,0 +1 @@
+module("ffluci.controller.admin.services", package.seeall) \ No newline at end of file
diff --git a/modules/admin-core/src/controller/admin/system.lua b/modules/admin-core/src/controller/admin/system.lua
new file mode 100644
index 0000000000..7a927d6047
--- /dev/null
+++ b/modules/admin-core/src/controller/admin/system.lua
@@ -0,0 +1,200 @@
+module("ffluci.controller.admin.system", package.seeall)
+
+require("ffluci.sys")
+require("ffluci.http")
+require("ffluci.util")
+require("ffluci.fs")
+require("ffluci.model.ipkg")
+require("ffluci.model.uci")
+
+function action_editor()
+ local file = ffluci.http.formvalue("file", "")
+ local data = ffluci.http.formvalue("data")
+ local err = nil
+ local msg = nil
+ local stat = true
+
+ if file and data then
+ stat, err = ffluci.fs.writefile(file, data)
+ end
+
+ if not stat then
+ err = ffluci.util.split(err, " ")
+ table.remove(err, 1)
+ msg = table.concat(err, " ")
+ end
+
+ local cnt, err = ffluci.fs.readfile(file)
+ if cnt then
+ cnt = ffluci.util.pcdata(cnt)
+ end
+ ffluci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg})
+end
+
+function action_ipkg()
+ local file = "/etc/ipkg.conf"
+ local data = ffluci.http.formvalue("data")
+ local stat = nil
+ local err = nil
+
+ if data then
+ stat, err = ffluci.fs.writefile(file, data)
+ end
+
+ local cnt = ffluci.fs.readfile(file)
+ if cnt then
+ cnt = ffluci.util.pcdata(cnt)
+ end
+
+ ffluci.template.render("admin_system/ipkg", {cnt=cnt, msg=err})
+end
+
+function action_packages()
+ local ipkg = ffluci.model.ipkg
+ local void = nil
+ local submit = ffluci.http.formvalue("submit")
+
+
+ -- Search query
+ local query = ffluci.http.formvalue("query")
+ query = (query ~= '') and query or nil
+
+
+ -- Packets to be installed
+ local install = submit and ffluci.http.formvaluetable("install")
+
+ -- Install from URL
+ local url = ffluci.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 ffluci.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 = ffluci.http.formvalue("update")
+ if update then
+ void, update = ipkg.update()
+ end
+
+
+ -- Upgrade all packets
+ local upgrade = ffluci.http.formvalue("upgrade")
+ if upgrade then
+ void, upgrade = ipkg.upgrade()
+ end
+
+
+ -- Package info
+ local info = ffluci.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
+
+ ffluci.template.render("admin_system/packages", {pkgs=pkgs, query=query,
+ install=install, remove=remove, update=update, upgrade=upgrade})
+end
+
+function action_passwd()
+ local p1 = ffluci.http.formvalue("pwd1")
+ local p2 = ffluci.http.formvalue("pwd2")
+ local stat = nil
+
+ if p1 or p2 then
+ if p1 == p2 then
+ stat = ffluci.sys.user.setpasswd("root", p1)
+ else
+ stat = 10
+ end
+ end
+
+ ffluci.template.render("admin_system/passwd", {stat=stat})
+end
+
+function action_reboot()
+ local reboot = ffluci.http.formvalue("reboot")
+ ffluci.template.render("admin_system/reboot", {reboot=reboot})
+ if reboot then
+ ffluci.sys.reboot()
+ end
+end
+
+function action_sshkeys()
+ local file = "/etc/dropbear/authorized_keys"
+ local data = ffluci.http.formvalue("data")
+ local stat = nil
+ local err = nil
+
+ if data then
+ stat, err = ffluci.fs.writefile(file, data)
+ end
+
+ local cnt = ffluci.fs.readfile(file)
+ if cnt then
+ cnt = ffluci.util.pcdata(cnt)
+ end
+
+ ffluci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err})
+end
+
+function action_upgrade()
+ local ret = nil
+ local plat = ffluci.fs.mtime("/lib/upgrade/platform.sh")
+
+ local image = ffluci.http.formvalue("image")
+ local imgname = ffluci.http.formvalue("image_name")
+ local keepcfg = ffluci.http.formvalue("keepcfg")
+
+ if plat and imgname then
+ local kpattern = nil
+ if keepcfg then
+ local files = ffluci.model.uci.sections("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 = ffluci.sys.flash(image, kpattern)
+ end
+
+ ffluci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret})
+end \ No newline at end of file
diff --git a/modules/admin-core/src/controller/admin/uci.lua b/modules/admin-core/src/controller/admin/uci.lua
new file mode 100644
index 0000000000..cb4a95ba5c
--- /dev/null
+++ b/modules/admin-core/src/controller/admin/uci.lua
@@ -0,0 +1,61 @@
+module("ffluci.controller.admin.uci", package.seeall)
+require("ffluci.util")
+require("ffluci.sys")
+
+-- This function has a higher priority than the admin_uci/apply template
+function action_apply()
+ local changes = ffluci.model.uci.changes()
+ local output = ""
+
+ if changes then
+ local com = {}
+ local run = {}
+
+ -- Collect files to be applied and commit changes
+ for i, line in ipairs(ffluci.util.split(changes)) do
+ local r = line:match("^-?([^.]+)")
+ if r then
+ com[r] = true
+
+ if ffluci.config.uci_oncommit and ffluci.config.uci_oncommit[r] then
+ run[ffluci.config.uci_oncommit[r]] = true
+ end
+ end
+ end
+
+ -- Apply
+ for config, i in pairs(com) do
+ ffluci.model.uci.commit(config)
+ end
+
+ -- Search for post-commit commands
+ for cmd, i in pairs(run) do
+ output = output .. cmd .. ":" .. ffluci.sys.exec(cmd) .. "\n"
+ end
+ end
+
+ ffluci.template.render("admin_uci/apply", {changes=changes, output=output})
+end
+
+
+function action_revert()
+ local changes = ffluci.model.uci.changes()
+ if changes then
+ local revert = {}
+
+ -- Collect files to be reverted
+ for i, line in ipairs(ffluci.util.split(changes)) do
+ local r = line:match("^-?([^.]+)")
+ if r then
+ revert[r] = true
+ end
+ end
+
+ -- Revert them
+ for k, v in pairs(revert) do
+ ffluci.model.uci.revert(k)
+ end
+ end
+
+ ffluci.template.render("admin_uci/revert", {changes=changes})
+end \ No newline at end of file
diff --git a/modules/admin-core/src/controller/admin/wifi.lua b/modules/admin-core/src/controller/admin/wifi.lua
new file mode 100644
index 0000000000..bc1040c715
--- /dev/null
+++ b/modules/admin-core/src/controller/admin/wifi.lua
@@ -0,0 +1 @@
+module("ffluci.controller.admin.wifi", package.seeall) \ No newline at end of file