Merge pull request #1818 from dibdot/lxc_fix
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_system / admin.lua
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.
4
5 local fs = require "nixio.fs"
6
7 m = Map("system", translate("Router Password"),
8         translate("Changes the administrator password for accessing the device"))
9
10 s = m:section(TypedSection, "_dummy", "")
11 s.addremove = false
12 s.anonymous = true
13
14 pw1 = s:option(Value, "pw1", translate("Password"))
15 pw1.password = true
16
17 pw2 = s:option(Value, "pw2", translate("Confirmation"))
18 pw2.password = true
19
20 function s.cfgsections()
21         return { "_pass" }
22 end
23
24 function m.parse(map)
25         local v1 = pw1:formvalue("_pass")
26         local v2 = pw2:formvalue("_pass")
27
28         if v1 and v2 and #v1 > 0 and #v2 > 0 then
29                 if v1 == v2 then
30                         if luci.sys.user.setpasswd(luci.dispatcher.context.authuser, v1) == 0 then
31                                 m.message = translate("Password successfully changed!")
32                         else
33                                 m.message = translate("Unknown Error, password not changed!")
34                         end
35                 else
36                         m.message = translate("Given password confirmation did not match, password not changed!")
37                 end
38         end
39
40         Map.parse(map)
41 end
42
43
44 if fs.access("/etc/config/dropbear") then
45
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"))
48
49 s = m2:section(TypedSection, "dropbear", translate("Dropbear Instance"))
50 s.anonymous = true
51 s.addremove = true
52
53
54 ni = s:option(Value, "Interface", translate("Interface"),
55         translate("Listen only on the given interface or, if unspecified, on all"))
56
57 ni.template    = "cbi/network_netlist"
58 ni.nocreate    = true
59 ni.unspecified = true
60
61
62 pt = s:option(Value, "Port", translate("Port"),
63         translate("Specifies the listening port of this <em>Dropbear</em> instance"))
64
65 pt.datatype = "port"
66 pt.default  = 22
67
68
69 pa = s:option(Flag, "PasswordAuth", translate("Password authentication"),
70         translate("Allow <abbr title=\"Secure Shell\">SSH</abbr> password authentication"))
71
72 pa.enabled  = "on"
73 pa.disabled = "off"
74 pa.default  = pa.enabled
75 pa.rmempty  = false
76
77
78 ra = s:option(Flag, "RootPasswordAuth", translate("Allow root logins with password"),
79         translate("Allow the <em>root</em> user to login with password"))
80
81 ra.enabled  = "on"
82 ra.disabled = "off"
83 ra.default  = ra.enabled
84
85
86 gp = s:option(Flag, "GatewayPorts", translate("Gateway ports"),
87         translate("Allow remote hosts to connect to local SSH forwarded ports"))
88
89 gp.enabled  = "on"
90 gp.disabled = "off"
91 gp.default  = gp.disabled
92
93
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."))
96 s2.addremove = false
97 s2.anonymous = true
98 s2.template  = "cbi/tblsection"
99
100 function s2.cfgsections()
101         return { "_keys" }
102 end
103
104 keys = s2:option(TextValue, "_data", "")
105 keys.wrap    = "off"
106 keys.rows    = 3
107 keys.rmempty = false
108
109 function keys.cfgvalue()
110         return fs.readfile("/etc/dropbear/authorized_keys") or ""
111 end
112
113 function keys.write(self, section, value)
114         if value then
115                 fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"))
116         end
117 end
118
119 end
120
121 return m, m2