summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-mod-system/luasrc/model
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-11-20 10:50:03 +0100
committerJo-Philipp Wich <jo@mein.io>2018-11-20 11:01:50 +0100
commit447f0c81713e567706c970d5c8fdea732dac52d4 (patch)
tree8160ab608be83ffe85dfc529c7ad0f5a0a5141d3 /modules/luci-mod-system/luasrc/model
parentfc87173e1faf00b5e12c223f400b18a69abac852 (diff)
luci-mod-system: restructure administration pages
Split password, dropbear and SSH key configuration into separate pages in order to improve the form layout and to simplify the code. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-mod-system/luasrc/model')
-rw-r--r--modules/luci-mod-system/luasrc/model/cbi/admin_system/admin.lua124
-rw-r--r--modules/luci-mod-system/luasrc/model/cbi/admin_system/dropbear.lua53
2 files changed, 53 insertions, 124 deletions
diff --git a/modules/luci-mod-system/luasrc/model/cbi/admin_system/admin.lua b/modules/luci-mod-system/luasrc/model/cbi/admin_system/admin.lua
deleted file mode 100644
index 34289533bf..0000000000
--- a/modules/luci-mod-system/luasrc/model/cbi/admin_system/admin.lua
+++ /dev/null
@@ -1,124 +0,0 @@
--- Copyright 2008 Steven Barth <steven@midlink.org>
--- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
--- Licensed to the public under the Apache License 2.0.
-
-local fs = require "nixio.fs"
-
-m = Map("system", translate("Router Password"),
- translate("Changes the administrator password for accessing the device"))
-m.apply_on_parse = true
-
-s = m:section(TypedSection, "_dummy", "")
-s.addremove = false
-s.anonymous = true
-
-pw1 = s:option(Value, "pw1", translate("Password"))
-pw1.password = true
-
-pw2 = s:option(Value, "pw2", translate("Confirmation"))
-pw2.password = true
-
-function s.cfgsections()
- return { "_pass" }
-end
-
-function m.parse(map)
- local v1 = pw1:formvalue("_pass")
- local v2 = pw2:formvalue("_pass")
-
- if v1 and v2 and #v1 > 0 and #v2 > 0 then
- if v1 == v2 then
- if luci.sys.user.setpasswd(luci.dispatcher.context.authuser, v1) == 0 then
- m.message = translate("Password successfully changed!")
- else
- m.message = translate("Unknown Error, password not changed!")
- end
- else
- m.message = translate("Given password confirmation did not match, password not changed!")
- end
- end
-
- Map.parse(map)
-end
-
-
-if fs.access("/etc/config/dropbear") then
-
-m2 = Map("dropbear", translate("SSH Access"),
- translate("Dropbear offers <abbr title=\"Secure Shell\">SSH</abbr> network shell access and an integrated <abbr title=\"Secure Copy\">SCP</abbr> server"))
-m2.apply_on_parse = true
-
-s = m2:section(TypedSection, "dropbear", translate("Dropbear Instance"))
-s.anonymous = true
-s.addremove = true
-
-
-ni = s:option(Value, "Interface", translate("Interface"),
- translate("Listen only on the given interface or, if unspecified, on all"))
-
-ni.template = "cbi/network_netlist"
-ni.nocreate = true
-ni.unspecified = true
-
-
-pt = s:option(Value, "Port", translate("Port"),
- translate("Specifies the listening port of this <em>Dropbear</em> instance"))
-
-pt.datatype = "port"
-pt.default = 22
-
-
-pa = s:option(Flag, "PasswordAuth", translate("Password authentication"),
- translate("Allow <abbr title=\"Secure Shell\">SSH</abbr> password authentication"))
-
-pa.enabled = "on"
-pa.disabled = "off"
-pa.default = pa.enabled
-pa.rmempty = false
-
-
-ra = s:option(Flag, "RootPasswordAuth", translate("Allow root logins with password"),
- translate("Allow the <em>root</em> user to login with password"))
-
-ra.enabled = "on"
-ra.disabled = "off"
-ra.default = ra.enabled
-
-
-gp = s:option(Flag, "GatewayPorts", translate("Gateway ports"),
- translate("Allow remote hosts to connect to local SSH forwarded ports"))
-
-gp.enabled = "on"
-gp.disabled = "off"
-gp.default = gp.disabled
-
-
-s2 = m2:section(TypedSection, "_dummy", translate("SSH-Keys"),
- translate("Here you can paste public SSH-Keys (one per line) for SSH public-key authentication."))
-s2.addremove = false
-s2.anonymous = true
-s2.template = "cbi/tblsection"
-
-function s2.cfgsections()
- return { "_keys" }
-end
-
-keys = s2:option(TextValue, "_data", "")
-keys.wrap = "off"
-keys.rows = 3
-
-function keys.cfgvalue()
- return fs.readfile("/etc/dropbear/authorized_keys") or ""
-end
-
-function keys.write(self, section, value)
- return fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"))
-end
-
-function keys.remove(self, section, value)
- return fs.writefile("/etc/dropbear/authorized_keys", "")
-end
-
-end
-
-return m, m2
diff --git a/modules/luci-mod-system/luasrc/model/cbi/admin_system/dropbear.lua b/modules/luci-mod-system/luasrc/model/cbi/admin_system/dropbear.lua
new file mode 100644
index 0000000000..1a1695d2be
--- /dev/null
+++ b/modules/luci-mod-system/luasrc/model/cbi/admin_system/dropbear.lua
@@ -0,0 +1,53 @@
+-- Copyright 2008 Steven Barth <steven@midlink.org>
+-- Copyright 2011-2018 Jo-Philipp Wich <jo@mein.io>
+-- Licensed to the public under the Apache License 2.0.
+
+m = Map("dropbear", translate("SSH Access"),
+ translate("Dropbear offers <abbr title=\"Secure Shell\">SSH</abbr> network shell access and an integrated <abbr title=\"Secure Copy\">SCP</abbr> server"))
+m.apply_on_parse = true
+
+s = m:section(TypedSection, "dropbear", translate("Dropbear Instance"))
+s.anonymous = true
+s.addremove = true
+
+
+ni = s:option(Value, "Interface", translate("Interface"),
+ translate("Listen only on the given interface or, if unspecified, on all"))
+
+ni.template = "cbi/network_netlist"
+ni.nocreate = true
+ni.unspecified = true
+
+
+pt = s:option(Value, "Port", translate("Port"),
+ translate("Specifies the listening port of this <em>Dropbear</em> instance"))
+
+pt.datatype = "port"
+pt.default = 22
+
+
+pa = s:option(Flag, "PasswordAuth", translate("Password authentication"),
+ translate("Allow <abbr title=\"Secure Shell\">SSH</abbr> password authentication"))
+
+pa.enabled = "on"
+pa.disabled = "off"
+pa.default = pa.enabled
+pa.rmempty = false
+
+
+ra = s:option(Flag, "RootPasswordAuth", translate("Allow root logins with password"),
+ translate("Allow the <em>root</em> user to login with password"))
+
+ra.enabled = "on"
+ra.disabled = "off"
+ra.default = ra.enabled
+
+
+gp = s:option(Flag, "GatewayPorts", translate("Gateway ports"),
+ translate("Allow remote hosts to connect to local SSH forwarded ports"))
+
+gp.enabled = "on"
+gp.disabled = "off"
+gp.default = gp.disabled
+
+return m