1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
5 local fs = require "nixio.fs"
7 m = Map("system", translate("Router Password"),
8 translate("Changes the administrator password for accessing the device"))
10 s = m:section(TypedSection, "_dummy", "")
14 pw1 = s:option(Value, "pw1", translate("Password"))
17 pw2 = s:option(Value, "pw2", translate("Confirmation"))
20 function s.cfgsections()
25 local v1 = pw1:formvalue("_pass")
26 local v2 = pw2:formvalue("_pass")
28 if v1 and v2 and #v1 > 0 and #v2 > 0 then
30 if luci.sys.user.setpasswd(luci.dispatcher.context.authuser, v1) == 0 then
31 m.message = translate("Password successfully changed!")
33 m.message = translate("Unknown Error, password not changed!")
36 m.message = translate("Given password confirmation did not match, password not changed!")
44 if fs.access("/etc/config/dropbear") then
46 m2 = Map("dropbear", translate("SSH Access"),
47 translate("Dropbear offers <abbr title=\"Secure Shell\">SSH</abbr> network shell access and an integrated <abbr title=\"Secure Copy\">SCP</abbr> server"))
49 s = m2:section(TypedSection, "dropbear", translate("Dropbear Instance"))
54 ni = s:option(Value, "Interface", translate("Interface"),
55 translate("Listen only on the given interface or, if unspecified, on all"))
57 ni.template = "cbi/network_netlist"
62 pt = s:option(Value, "Port", translate("Port"),
63 translate("Specifies the listening port of this <em>Dropbear</em> instance"))
69 pa = s:option(Flag, "PasswordAuth", translate("Password authentication"),
70 translate("Allow <abbr title=\"Secure Shell\">SSH</abbr> password authentication"))
74 pa.default = pa.enabled
78 ra = s:option(Flag, "RootPasswordAuth", translate("Allow root logins with password"),
79 translate("Allow the <em>root</em> user to login with password"))
83 ra.default = ra.enabled
86 gp = s:option(Flag, "GatewayPorts", translate("Gateway ports"),
87 translate("Allow remote hosts to connect to local SSH forwarded ports"))
91 gp.default = gp.disabled
94 s2 = m2:section(TypedSection, "_dummy", translate("SSH-Keys"),
95 translate("Here you can paste public SSH-Keys (one per line) for SSH public-key authentication."))
98 s2.template = "cbi/tblsection"
100 function s2.cfgsections()
104 keys = s2:option(TextValue, "_data", "")
109 function keys.cfgvalue()
110 return fs.readfile("/etc/dropbear/authorized_keys") or ""
113 function keys.write(self, section, value)
115 fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"))