modules/admin-mini: General UI improvements

This commit is contained in:
Steven Barth 2008-08-17 00:29:13 +00:00
parent 7d08bec3ae
commit 746fa9df8f
4 changed files with 79 additions and 69 deletions

View file

@ -21,7 +21,7 @@ function index()
entry({"mini", "system"}, alias("mini", "system", "index"), i18n("system"), 40)
entry({"mini", "system", "index"}, cbi("mini/system"), i18n("general"), 1)
entry({"mini", "system", "passwd"}, call("action_passwd"), i18n("a_s_changepw"), 10)
entry({"mini", "system", "passwd"}, form("mini/passwd"), i18n("a_s_changepw"), 10)
entry({"mini", "system", "backup"}, call("action_backup"), i18n("a_s_backup"), 80)
entry({"mini", "system", "upgrade"}, call("action_upgrade"), i18n("a_s_flash"), 90)
entry({"mini", "system", "reboot"}, call("action_reboot"), i18n("reboot"), 100)
@ -111,22 +111,6 @@ function action_upgrade()
luci.template.render("mini/upgrade", {sysupgrade=plat, ret=ret, keep_avail=keep_avail})
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("mini/passwd", {stat=stat})
end
function _keep_pattern()
local kpattern = ""
local files = luci.model.uci.get_all("luci", "flash_keep")

View file

@ -14,6 +14,7 @@ $Id$
]]--
require("luci.model.uci")
require("luci.sys")
require("luci.tools.webadmin")
m = Map("dhcp", "DHCP")
@ -21,7 +22,7 @@ s = m:section(TypedSection, "dhcp", "DHCP-Server")
s.anonymous = true
s:depends("interface", "lan")
enable = s:option(ListValue, "ignore", "", "")
enable = s:option(ListValue, "ignore", translate("enable"), "")
enable:value(0, translate("enable"))
enable:value(1, translate("disable"))
@ -52,9 +53,40 @@ time = s:option(Value, "leasetime")
time:depends("ignore", "0")
time.rmempty = true
m2 = Map("luci_ethers", translate("luci_ethers"))
s = m2:section(TypedSection, "static_lease", "")
m2 = Map("luci_ethers", translate("dhcp_leases"))
local leasefn, leasefp, leases
luci.model.uci.foreach("dhcp", "dnsmasq",
function(section)
leasefn = section.leasefile
end
)
local leasefp = leasefn and luci.fs.access(leasefn) and io.lines(leasefn)
if leasefp then
leases = {}
for lease in leasefp do
table.insert(leases, luci.util.split(lease, " "))
end
end
if leases then
v = m2:section(Table, leases, translate("dhcp_leases_active"))
ip = v:option(DummyValue, 3, translate("ipaddress"))
mac = v:option(DummyValue, 2, translate("macaddress"))
ltime = v:option(DummyValue, 1, translate("dhcp_timeremain"))
function ltime.cfgvalue(self, ...)
local value = DummyValue.cfgvalue(self, ...)
return luci.tools.webadmin.date_format(
os.difftime(tonumber(value), os.time())
)
end
end
s = m2:section(TypedSection, "static_lease", translate("luci_ethers"))
s.addremove = true
s.anonymous = true
s.template = "cbi/tblsection"

View file

@ -0,0 +1,43 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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$
]]--
f = SimpleForm("password", translate("a_s_changepw"), translate("a_s_changepw1"))
pw1 = f:field(Value, "pw1", translate("password"))
pw1.password = true
pw2 = f:field(Value, "pw2", translate("confirmation"))
pw2.password = true
function pw2.validate(self, value, section)
return pw1:formvalue(section) == value and value
end
function f.handle(self, state, data)
if state == FORM_VALID then
local stat = luci.sys.user.setpasswd("root", data.pw1) == 0
if stat then
f.message = translate("a_s_changepw_changed")
else
f.errmessage = translate("unknownerror")
end
data.pw1 = nil
data.pw2 = nil
end
return true
end
return f

View file

@ -1,49 +0,0 @@
<%#
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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$
-%>
<%+header%>
<h1><%:system%></h1>
<h2><%:a_s_changepw%></h2>
<p><%:a_s_changepw1%></p>
<div><br />
<% if stat then %>
<% if stat == 0 then %>
<code><%:a_s_changepw_changed%>!</code>
<% elseif stat == 10 then %>
<code class="error"><%:a_s_changepw_nomatch%>!</code>
<% else %>
<code class="error"><%:unknownerror%>!</code>
<% end %>
<% end %>
<% if not stat or stat == 10 then %>
<form method="post" action="<%=REQUEST_URI%>">
<div class="cbi-section-node">
<div class="cbi-value">
<div class="cbi-value-title"><%:password%></div>
<div class="cbi-value-field"><input type="password" name="pwd1" /></div>
</div>
<div class="cbi-value">
<div class="cbi-value-title"><%:confirmation%></div>
<div class="cbi-value-field"><input type="password" name="pwd2" /></div>
</div>
<br />
<div>
<input type="submit" value="<%:save%>" />
<input type="reset" value="<%:reset%>" />
</div>
</div>
</form>
<% end %>
</div>
<%+footer%>