From 746fa9df8f3d3443d82cd26d6717e7b5cf3dc8c1 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Sun, 17 Aug 2008 00:29:13 +0000 Subject: modules/admin-mini: General UI improvements --- .../admin-mini/luasrc/controller/mini/system.lua | 18 +------- modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua | 38 +++++++++++++++-- .../admin-mini/luasrc/model/cbi/mini/passwd.lua | 43 +++++++++++++++++++ modules/admin-mini/luasrc/view/mini/passwd.htm | 49 ---------------------- 4 files changed, 79 insertions(+), 69 deletions(-) create mode 100644 modules/admin-mini/luasrc/model/cbi/mini/passwd.lua delete mode 100644 modules/admin-mini/luasrc/view/mini/passwd.htm (limited to 'modules/admin-mini/luasrc') diff --git a/modules/admin-mini/luasrc/controller/mini/system.lua b/modules/admin-mini/luasrc/controller/mini/system.lua index 255e26f65..be6cdb6b5 100644 --- a/modules/admin-mini/luasrc/controller/mini/system.lua +++ b/modules/admin-mini/luasrc/controller/mini/system.lua @@ -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") diff --git a/modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua b/modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua index 3d26d6a9d..85b2c86aa 100644 --- a/modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua +++ b/modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua @@ -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" diff --git a/modules/admin-mini/luasrc/model/cbi/mini/passwd.lua b/modules/admin-mini/luasrc/model/cbi/mini/passwd.lua new file mode 100644 index 000000000..8ff18cb5c --- /dev/null +++ b/modules/admin-mini/luasrc/model/cbi/mini/passwd.lua @@ -0,0 +1,43 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Steven Barth +Copyright 2008 Jo-Philipp Wich + +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 \ No newline at end of file diff --git a/modules/admin-mini/luasrc/view/mini/passwd.htm b/modules/admin-mini/luasrc/view/mini/passwd.htm deleted file mode 100644 index ece9a5947..000000000 --- a/modules/admin-mini/luasrc/view/mini/passwd.htm +++ /dev/null @@ -1,49 +0,0 @@ -<%# -LuCI - Lua Configuration Interface -Copyright 2008 Steven Barth -Copyright 2008 Jo-Philipp Wich - -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%> -

<%:system%>

-

<%:a_s_changepw%>

-

<%:a_s_changepw1%>

-

-<% if stat then %> - <% if stat == 0 then %> - <%:a_s_changepw_changed%>! - <% elseif stat == 10 then %> - <%:a_s_changepw_nomatch%>! - <% else %> - <%:unknownerror%>! - <% end %> -<% end %> -<% if not stat or stat == 10 then %> -
-
-
-
<%:password%>
-
-
-
-
<%:confirmation%>
-
-
-
-
- - -
-
-
-<% end %> -
-<%+footer%> \ No newline at end of file -- cgit v1.2.3