luci/modules/admin-core/luasrc/controller/admin/system.lua

211 lines
4.9 KiB
Lua
Raw Normal View History

module("luci.controller.admin.system", package.seeall)
2008-04-11 18:24:25 +00:00
require("luci.sys")
require("luci.http")
require("luci.util")
require("luci.fs")
require("luci.model.ipkg")
require("luci.model.uci")
2008-04-11 18:24:25 +00:00
2008-05-22 14:04:03 +00:00
function index()
entry({"admin", "system"}, template("admin_system/index"), "System", 30)
entry({"admin", "system", "packages"}, call("action_packages"), "Paketverwaltung", 10)
entry({"admin", "system", "packages", "ipkg"}, call("action_ipkg"), "IPKG-Konfiguration")
entry({"admin", "system", "passwd"}, call("action_passwd"), "Passwort ändern", 20)
entry({"admin", "system", "sshkeys"}, call("action_sshkeys"), "SSH-Schlüssel", 30)
entry({"admin", "system", "hostname"}, cbi("admin_system/hostname"), "Hostname", 40)
entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), "Einhängepunkte", 50)
entry({"admin", "system", "upgrade"}, call("action_upgrade"), "Firmwareupgrade", 60)
entry({"admin", "system", "reboot"}, call("action_reboot"), "Neu starten", 70)
2008-05-22 14:04:03 +00:00
end
2008-04-11 18:24:25 +00:00
function action_editor()
local file = luci.http.formvalue("file", "")
local data = luci.http.formvalue("data")
2008-04-11 18:24:25 +00:00
local err = nil
local msg = nil
local stat = true
if file and data then
stat, err = luci.fs.writefile(file, data)
2008-04-11 18:24:25 +00:00
end
if not stat then
err = luci.util.split(err, " ")
2008-04-11 18:24:25 +00:00
table.remove(err, 1)
msg = table.concat(err, " ")
end
local cnt, err = luci.fs.readfile(file)
2008-04-11 18:24:25 +00:00
if cnt then
cnt = luci.util.pcdata(cnt)
2008-04-11 18:24:25 +00:00
end
luci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg})
2008-04-11 18:24:25 +00:00
end
function action_ipkg()
local file = "/etc/ipkg.conf"
local data = luci.http.formvalue("data")
2008-04-11 18:24:25 +00:00
local stat = nil
local err = nil
if data then
stat, err = luci.fs.writefile(file, data)
2008-04-11 18:24:25 +00:00
end
local cnt = luci.fs.readfile(file)
2008-04-11 18:24:25 +00:00
if cnt then
cnt = luci.util.pcdata(cnt)
2008-04-11 18:24:25 +00:00
end
luci.template.render("admin_system/ipkg", {cnt=cnt, msg=err})
2008-04-11 18:24:25 +00:00
end
function action_packages()
local ipkg = luci.model.ipkg
2008-04-11 18:24:25 +00:00
local void = nil
local submit = luci.http.formvalue("submit")
2008-04-11 18:24:25 +00:00
-- Search query
local query = luci.http.formvalue("query")
2008-04-11 18:24:25 +00:00
query = (query ~= '') and query or nil
-- Packets to be installed
local install = submit and luci.http.formvaluetable("install")
2008-04-11 18:24:25 +00:00
-- Install from URL
local url = luci.http.formvalue("url")
2008-04-11 18:24:25 +00:00
if url and url ~= '' and submit then
if not install then
install = {}
end
install[url] = 1
end
-- Do install
2008-04-11 18:24:25 +00:00
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")
2008-04-11 18:24:25 +00:00
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")
2008-04-11 18:24:25 +00:00
if update then
void, update = ipkg.update()
end
-- Upgrade all packets
local upgrade = luci.http.formvalue("upgrade")
2008-04-11 18:24:25 +00:00
if upgrade then
void, upgrade = ipkg.upgrade()
end
-- Package info
local info = luci.model.ipkg.info(query)
2008-04-11 18:24:25 +00:00
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,
2008-04-11 18:24:25 +00:00
install=install, remove=remove, update=update, upgrade=upgrade})
end
function action_passwd()
local p1 = luci.http.formvalue("pwd1")
local p2 = luci.http.formvalue("pwd2")
2008-04-11 18:24:25 +00:00
local stat = nil
if p1 or p2 then
if p1 == p2 then
stat = luci.sys.user.setpasswd("root", p1)
2008-04-11 18:24:25 +00:00
else
stat = 10
end
end
luci.template.render("admin_system/passwd", {stat=stat})
2008-04-11 18:24:25 +00:00
end
function action_reboot()
local reboot = luci.http.formvalue("reboot")
luci.template.render("admin_system/reboot", {reboot=reboot})
2008-04-11 18:24:25 +00:00
if reboot then
luci.sys.reboot()
2008-04-11 18:24:25 +00:00
end
end
function action_sshkeys()
local file = "/etc/dropbear/authorized_keys"
local data = luci.http.formvalue("data")
2008-04-11 18:24:25 +00:00
local stat = nil
local err = nil
if data then
stat, err = luci.fs.writefile(file, data)
2008-04-11 18:24:25 +00:00
end
local cnt = luci.fs.readfile(file)
2008-04-11 18:24:25 +00:00
if cnt then
cnt = luci.util.pcdata(cnt)
2008-04-11 18:24:25 +00:00
end
luci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err})
2008-04-11 18:24:25 +00:00
end
function action_upgrade()
local ret = nil
local plat = luci.fs.mtime("/lib/upgrade/platform.sh")
2008-04-11 18:24:25 +00:00
local image = luci.http.upload("image")
local keepcfg = luci.http.formvalue("keepcfg")
2008-04-11 18:24:25 +00:00
if plat and image then
2008-04-11 18:24:25 +00:00
local kpattern = nil
if keepcfg then
local files = luci.model.uci.sections("luci").flash_keep
2008-04-11 18:24:25 +00:00
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)
2008-04-11 18:24:25 +00:00
end
luci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret})
2008-04-11 18:24:25 +00:00
end