Skip to content
Snippets Groups Projects
Commit c3fcb81a authored by Nils Schneider's avatar Nils Schneider
Browse files

ssh keys

parent 29b48052
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ $Id$ ...@@ -16,7 +16,7 @@ $Id$
module("luci.controller.admin.system", package.seeall) module("luci.controller.admin.system", package.seeall)
function index() function index()
entry({"admin", "passwd"}, form("admin/passwd"), _("Admin Password"), 10) entry({"admin", "passwd"}, cbi("admin/passwd"), _("Admin Password"), 10)
entry({"admin", "backup"}, call("action_backup"), _("Backup / Restore"), 80) entry({"admin", "backup"}, call("action_backup"), _("Backup / Restore"), 80)
entry({"admin", "upgrade"}, call("action_upgrade"), _("Flash Firmware"), 90) entry({"admin", "upgrade"}, call("action_upgrade"), _("Flash Firmware"), 90)
entry({"admin", "reboot"}, call("action_reboot"), _("Reboot"), 100) entry({"admin", "reboot"}, call("action_reboot"), _("Reboot"), 100)
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
LuCI - Lua Configuration Interface LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org> Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net> Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
Copyright 2013 Nils Schneider <nils@nilsschneider.net>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
...@@ -12,34 +13,73 @@ You may obtain a copy of the License at ...@@ -12,34 +13,73 @@ You may obtain a copy of the License at
$Id$ $Id$
]]-- ]]--
f = SimpleForm("password", translate("Admin Password"), translate("Change the password of the system administrator (User <code>root</code>)"))
pw1 = f:field(Value, "pw1", translate("Password")) local fs = require "nixio.fs"
local m, s, pw1, pw2
m = Map("system", "Passwort &amp; SSH Keys")
s = m:section(TypedSection, translate("Router Password"),
translate("Changes the administrator password for accessing the device"))
s.addremove = false
s.anonymous = true
pw1 = s:option(Value, "pw1", translate("Password"))
pw1.password = true pw1.password = true
pw1.rmempty = false
pw2 = f:field(Value, "pw2", translate("Confirmation")) pw2 = s:option(Value, "pw2", translate("Confirmation"))
pw2.password = true pw2.password = true
pw2.rmempty = false
function pw2.validate(self, value, section) function s.cfgsections()
return pw1:formvalue(section) == value and value return { "_pass" }
end
function m.on_commit(map)
local v1 = pw1:formvalue("_pass")
local v2 = pw2:formvalue("_pass")
if v1 and v2 and #v1 > 0 and #v2 > 0 then
if v1 == v2 then
if luci.sys.user.setpasswd(luci.dispatcher.context.authuser, v1) == 0 then
m.message = translate("Password successfully changed!")
else
m.message = translate("Unknown Error, password not changed!")
end
else
m.message = translate("Given password confirmation did not match, password not changed!")
end
end
end end
function f.handle(self, state, data) if fs.access("/etc/config/dropbear") then
if state == FORM_VALID then s = m:section(TypedSection, "_keys", "SSH Keys",
local stat = luci.sys.user.setpasswd("root", data.pw1) == 0 translate("Here you can paste public SSH-Keys (one per line) for SSH public-key authentication."))
if stat then s.addremove = false
f.message = translate("Password successfully changed") s.anonymous = true
else
f.errmessage = translate("Unknown Error") function s.cfgsections()
end return { "_keys" }
end
data.pw1 = nil
data.pw2 = nil local keys
end
return true keys = s:option(TextValue, "_data", "")
keys.wrap = "off"
keys.rows = 3
keys.rmempty = false
function keys.cfgvalue()
return fs.readfile("/etc/dropbear/authorized_keys") or ""
end
function keys.write(self, section, value)
if value then
fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"))
end
end
end end
return f return m
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment