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"))
9 m.apply_on_parse = true
11 s = m:section(TypedSection, "_dummy", "")
15 pw1 = s:option(Value, "pw1", translate("Password"))
18 pw2 = s:option(Value, "pw2", translate("Confirmation"))
21 function s.cfgsections()
26 local v1 = pw1:formvalue("_pass")
27 local v2 = pw2:formvalue("_pass")
29 if v1 and v2 and #v1 > 0 and #v2 > 0 then
31 if luci.sys.user.setpasswd(luci.dispatcher.context.authuser, v1) == 0 then
32 m.message = translate("Password successfully changed!")
34 m.message = translate("Unknown Error, password not changed!")
37 m.message = translate("Given password confirmation did not match, password not changed!")
45 if fs.access("/etc/config/dropbear") then
47 m2 = Map("dropbear", translate("SSH Access"),
48 translate("Dropbear offers <abbr title=\"Secure Shell\">SSH</abbr> network shell access and an integrated <abbr title=\"Secure Copy\">SCP</abbr> server"))
49 m2.apply_on_parse = true
51 s = m2:section(TypedSection, "dropbear", translate("Dropbear Instance"))
56 ni = s:option(Value, "Interface", translate("Interface"),
57 translate("Listen only on the given interface or, if unspecified, on all"))
59 ni.template = "cbi/network_netlist"
64 pt = s:option(Value, "Port", translate("Port"),
65 translate("Specifies the listening port of this <em>Dropbear</em> instance"))
71 pa = s:option(Flag, "PasswordAuth", translate("Password authentication"),
72 translate("Allow <abbr title=\"Secure Shell\">SSH</abbr> password authentication"))
76 pa.default = pa.enabled
80 ra = s:option(Flag, "RootPasswordAuth", translate("Allow root logins with password"),
81 translate("Allow the <em>root</em> user to login with password"))
85 ra.default = ra.enabled
88 gp = s:option(Flag, "GatewayPorts", translate("Gateway ports"),
89 translate("Allow remote hosts to connect to local SSH forwarded ports"))
93 gp.default = gp.disabled
96 s2 = m2:section(TypedSection, "_dummy", translate("SSH-Keys"),
97 translate("Here you can paste public SSH-Keys (one per line) for SSH public-key authentication."))
100 s2.template = "cbi/tblsection"
102 function s2.cfgsections()
106 keys = s2:option(TextValue, "_data", "")
110 function keys.cfgvalue()
111 return fs.readfile("/etc/dropbear/authorized_keys") or ""
114 function keys.write(self, section, value)
115 return fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"))
118 function keys.remove(self, section, value)
119 return fs.writefile("/etc/dropbear/authorized_keys", "")