gluon-luci-admin: fix password setting
This commit is contained in:
parent
70b116fd61
commit
e7b434ef34
@ -16,24 +16,12 @@ $Id$
|
|||||||
|
|
||||||
local fs = require "nixio.fs"
|
local fs = require "nixio.fs"
|
||||||
|
|
||||||
local m = Map("system", translate("SSH keys"))
|
local f_keys = SimpleForm('keys', translate("SSH keys"), translate("You can provide your SSH keys here (one per line):"))
|
||||||
m.pageaction = false
|
f_keys.hidden = { submit_keys = '1' }
|
||||||
m.template = "cbi/simpleform"
|
|
||||||
|
|
||||||
if fs.access("/etc/config/dropbear") then
|
|
||||||
local s = m:section(TypedSection, "_dummy1", nil,
|
|
||||||
translate("You can provide your SSH keys here (one per line):"))
|
|
||||||
|
|
||||||
s.addremove = false
|
|
||||||
s.anonymous = true
|
|
||||||
|
|
||||||
function s.cfgsections()
|
|
||||||
return { "_keys" }
|
|
||||||
end
|
|
||||||
|
|
||||||
local keys
|
local keys
|
||||||
|
|
||||||
keys = s:option(TextValue, "_data", "")
|
keys = f_keys:field(TextValue, "keys", "")
|
||||||
keys.wrap = "off"
|
keys.wrap = "off"
|
||||||
keys.rows = 5
|
keys.rows = 5
|
||||||
keys.rmempty = true
|
keys.rmempty = true
|
||||||
@ -43,63 +31,59 @@ if fs.access("/etc/config/dropbear") then
|
|||||||
end
|
end
|
||||||
|
|
||||||
function keys.write(self, section, value)
|
function keys.write(self, section, value)
|
||||||
if value then
|
if not f_keys:formvalue('submit_keys') then return end
|
||||||
|
|
||||||
fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"):trim() .. "\n")
|
fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"):trim() .. "\n")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function keys.remove(self, section)
|
function keys.remove(self, section)
|
||||||
if keys:formvalue("_keys") then
|
if not f_keys:formvalue('submit_keys') then return end
|
||||||
|
|
||||||
fs.remove("/etc/dropbear/authorized_keys")
|
fs.remove("/etc/dropbear/authorized_keys")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local m2 = Map("system", translate("Password"))
|
local f_password = SimpleForm('password', translate("Password"),
|
||||||
m2.reset = false
|
translate(
|
||||||
m2.pageaction = false
|
|
||||||
m2.template = "cbi/simpleform"
|
|
||||||
|
|
||||||
local s = m2:section(TypedSection, "_dummy2", nil, translate(
|
|
||||||
"Alternatively, you can set a password to access you node. Please choose a secure password you don't use anywhere else.<br /><br />"
|
"Alternatively, you can set a password to access you node. Please choose a secure password you don't use anywhere else.<br /><br />"
|
||||||
.. "If you set an empty password, login via password will be disabled. This is the default."))
|
.. "If you set an empty password, login via password will be disabled. This is the default."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
f_password.hidden = { submit_password = '1' }
|
||||||
|
f_password.reset = false
|
||||||
|
|
||||||
s.addremove = false
|
local pw1 = f_password:field(Value, "pw1", translate("Password"))
|
||||||
s.anonymous = true
|
|
||||||
|
|
||||||
local pw1 = s:option(Value, "pw1", translate("Password"))
|
|
||||||
pw1.password = true
|
pw1.password = true
|
||||||
|
function pw1.cfgvalue()
|
||||||
local pw2 = s:option(Value, "pw2", translate("Confirmation"))
|
return ''
|
||||||
pw2.password = true
|
|
||||||
|
|
||||||
function s.cfgsections()
|
|
||||||
return { "_pass" }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function m2.on_commit(map)
|
local pw2 = f_password:field(Value, "pw2", translate("Confirmation"))
|
||||||
local v1 = pw1:formvalue("_pass")
|
pw2.password = true
|
||||||
local v2 = pw2:formvalue("_pass")
|
function pw2.cfgvalue()
|
||||||
|
return ''
|
||||||
|
end
|
||||||
|
|
||||||
if v1 and v2 then
|
function f_password:handle(state, data)
|
||||||
if v1 == v2 then
|
if not f_password:formvalue('submit_password') then return end
|
||||||
if #v1 > 0 then
|
|
||||||
if luci.sys.user.setpasswd('root', v1) == 0 then
|
if data.pw1 ~= data.pw2 then
|
||||||
m2.message = translate("Password changed.")
|
f_password.errmessage = translate("The password and the confirmation differ.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if data.pw1 and #data.pw1 > 0 then
|
||||||
|
if luci.sys.user.setpasswd('root', data.pw1) == 0 then
|
||||||
|
f_password.message = translate("Password changed.")
|
||||||
else
|
else
|
||||||
m2.errmessage = translate("Unable to change the password.")
|
f_password.errmessage = translate("Unable to change the password.")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- We don't check the return code here as the error 'password for root is already locked' is normal...
|
-- We don't check the return code here as the error 'password for root is already locked' is normal...
|
||||||
os.execute('passwd -l root >/dev/null')
|
os.execute('passwd -l root >/dev/null')
|
||||||
m2.message = translate("Password removed.")
|
f_password.message = translate("Password removed.")
|
||||||
end
|
|
||||||
else
|
|
||||||
m2.errmessage = translate("The password and the confirmation differ.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local c = Compound(m, m2)
|
local c = Compound(f_keys, f_password)
|
||||||
c.pageaction = false
|
c.pageaction = false
|
||||||
return c
|
return c
|
||||||
|
Loading…
Reference in New Issue
Block a user