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()
24 function m.on_commit(map)
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!")
42 if fs.access("/etc/config/dropbear") then
44 m2 = Map("dropbear", translate("SSH Access"),
45 translate("Dropbear offers <abbr title=\"Secure Shell\">SSH</abbr> network shell access and an integrated <abbr title=\"Secure Copy\">SCP</abbr> server"))
47 s = m2:section(TypedSection, "dropbear", translate("Dropbear Instance"))
52 ni = s:option(Value, "Interface", translate("Interface"),
53 translate("Listen only on the given interface or, if unspecified, on all"))
55 ni.template = "cbi/network_netlist"
60 pt = s:option(Value, "Port", translate("Port"),
61 translate("Specifies the listening port of this <em>Dropbear</em> instance"))
67 pa = s:option(Flag, "PasswordAuth", translate("Password authentication"),
68 translate("Allow <abbr title=\"Secure Shell\">SSH</abbr> password authentication"))
72 pa.default = pa.enabled
76 ra = s:option(Flag, "RootPasswordAuth", translate("Allow root logins with password"),
77 translate("Allow the <em>root</em> user to login with password"))
81 ra.default = ra.enabled
84 gp = s:option(Flag, "GatewayPorts", translate("Gateway ports"),
85 translate("Allow remote hosts to connect to local SSH forwarded ports"))
89 gp.default = gp.disabled
92 s2 = m2:section(TypedSection, "_dummy", translate("SSH-Keys"),
93 translate("Here you can paste public SSH-Keys (one per line) for SSH public-key authentication."))
96 s2.template = "cbi/tblsection"
98 function s2.cfgsections()
102 keys = s2:option(TextValue, "_data", "")
107 function keys.cfgvalue()
108 return fs.readfile("/etc/dropbear/authorized_keys") or ""
111 function keys.write(self, section, value)
113 fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"))