modules/admin-full: fix extroot and fsck availability check (https://dev.openwrt...
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_system / admin.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 local fs = require "nixio.fs"
17
18 m = Map("system", translate("Router Password"),
19         translate("Changes the administrator password for accessing the device"))
20
21 s = m:section(TypedSection, "_dummy", "")
22 s.addremove = false
23 s.anonymous = true
24
25 pw1 = s:option(Value, "pw1", translate("Password"))
26 pw1.password = true
27
28 pw2 = s:option(Value, "pw2", translate("Confirmation"))
29 pw2.password = true
30
31 function s.cfgsections()
32         return { "_pass" }
33 end
34
35 function m.on_commit(map)
36         local v1 = pw1:formvalue("_pass")
37         local v2 = pw2:formvalue("_pass")
38
39         if v1 and v2 and #v1 > 0 and #v2 > 0 then
40                 if v1 == v2 then
41                         if luci.sys.user.setpasswd(luci.dispatcher.context.authuser, v1) == 0 then
42                                 m.message = translate("Password successfully changed!")
43                         else
44                                 m.message = translate("Unknown Error, password not changed!")
45                         end
46                 else
47                         m.message = translate("Given password confirmation did not match, password not changed!")
48                 end
49         end
50 end
51
52
53 if fs.access("/etc/config/dropbear") then
54
55 m2 = Map("dropbear", translate("SSH Access"),
56         translate("Dropbear offers <abbr title=\"Secure Shell\">SSH</abbr> network shell access and an integrated <abbr title=\"Secure Copy\">SCP</abbr> server"))
57
58 s = m2:section(TypedSection, "dropbear", translate("Dropbear Instance"))
59 s.anonymous = true
60 s.addremove = true
61
62
63 ni = s:option(Value, "Interface", translate("Interface"),
64         translate("Listen only on the given interface or, if unspecified, on all"))
65
66 ni.template    = "cbi/network_netlist"
67 ni.nocreate    = true
68 ni.unspecified = true
69
70
71 pt = s:option(Value, "Port", translate("Port"),
72         translate("Specifies the listening port of this <em>Dropbear</em> instance"))
73
74 pt.datatype = "port"
75 pt.default  = 22
76
77
78 pa = s:option(Flag, "PasswordAuth", translate("Password authentication"),
79         translate("Allow <abbr title=\"Secure Shell\">SSH</abbr> password authentication"))
80
81 pa.enabled  = "on"
82 pa.disabled = "off"
83 pa.default  = pa.enabled
84 pa.rmempty  = false
85
86
87 ra = s:option(Flag, "RootPasswordAuth", translate("Allow root logins with password"),
88         translate("Allow the <em>root</em> user to login with password"))
89
90 ra.enabled  = "on"
91 ra.disabled = "off"
92 ra.default  = ra.enabled
93
94
95 gp = s:option(Flag, "GatewayPorts", translate("Gateway ports"),
96         translate("Allow remote hosts to connect to local SSH forwarded ports"))
97
98 gp.enabled  = "on"
99 gp.disabled = "off"
100 gp.default  = gp.disabled
101
102
103 s2 = m2:section(TypedSection, "_dummy", translate("SSH-Keys"),
104         translate("Here you can paste public SSH-Keys (one per line) for SSH public-key authentication."))
105 s2.addremove = false
106 s2.anonymous = true
107 s2.template  = "cbi/tblsection"
108
109 function s2.cfgsections()
110         return { "_keys" }
111 end
112
113 keys = s2:option(TextValue, "_data", "")
114 keys.wrap    = "off"
115 keys.rows    = 3
116 keys.rmempty = false
117
118 function keys.cfgvalue()
119         return fs.readfile("/etc/dropbear/authorized_keys") or ""
120 end
121
122 function keys.write(self, section, value)
123         if value then
124                 fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"))
125         end
126 end
127
128 end
129
130 return m, m2