From 355473297d9d1bf097819240ee2d5833a7d62d1d Mon Sep 17 00:00:00 2001 From: Christian Korber Date: Mon, 29 Jul 2024 13:52:42 +0200 Subject: [PATCH] luci-app-snmpd: refactor advanced settings Advanced settings (groups, access, com2sec) are refactored in a new function. Redundant comments are also deleted. Signed-off-by: Christian Korber --- .../luci-static/resources/view/snmpd/snmpd.js | 248 +++++++++--------- 1 file changed, 129 insertions(+), 119 deletions(-) diff --git a/applications/luci-app-snmpd/htdocs/luci-static/resources/view/snmpd/snmpd.js b/applications/luci-app-snmpd/htdocs/luci-static/resources/view/snmpd/snmpd.js index 141b59a914..a2b5300a8f 100644 --- a/applications/luci-app-snmpd/htdocs/luci-static/resources/view/snmpd/snmpd.js +++ b/applications/luci-app-snmpd/htdocs/luci-static/resources/view/snmpd/snmpd.js @@ -74,6 +74,134 @@ return L.view.extend({ go.remove = snmpd_sys_remove; }, + populateAdvancedSettings(tab, s) { + let o, g, go; + + o = s.taboption('advanced', form.SectionValue, '__advanced__', + form.GridSection, 'com2sec', null, + _('Here you can configure com2sec options')); + + g = o.subsection; + g.anonymous = true; + g.addremove = true; + g.nodescriptions = true; + g.modaltitle = 'com2sec Settings'; + + go = g.option(form.Value, 'secname', _('Secname'), + _('Arbitrary label for use in group settings')); + go.optional = false; + go.rmempty = false; + + go = g.option(form.Value, 'source', _('Source'), + _('Source describes a host or network')); + go.rmempty = false; + + go = g.option(form.Value, 'community', _('Community'), + _('The community name that is used')); + go.optional = false; + go.rmempty = false; + + o = s.taboption('advanced', form.SectionValue, '__advanced__', + form.GridSection, 'group', null, + _('Here you can configure group options')); + + g = o.subsection; + g.anonymous = true; + g.addremove = true; + g.nodescriptions = true; + g.modaltitle = 'Group Settings'; + + go = g.option(form.Value, 'group', _('Group'), + _('A group maps com2sec names to access names')); + go.optional = false; + go.rmempty = false; + + go = g.option(form.ListValue, 'version', _('Version'), + _('The used version for the group')); + go.value('v1', _('SNMPv1')); + go.value('v2c', _('SNMPv2c')); + go.value('usm', _('SNMPv3')); + go.optional = false; + go.rmempty = false; + + go = g.option(form.Value, 'secname', _('Secname'), + _('Here you define which secname is mapped to the group')); + go.optional = false; + go.rmempty = false; + + o = s.taboption('advanced', form.SectionValue, '__advanced__', + form.GridSection, 'access', null, + _('Here you can configure access options')); + + g = o.subsection; + g.anonymous = true; + g.addremove = true; + g.nodescriptions = true; + g.modaltitle = 'Access Settings'; + + go = g.option(form.Value, 'group', _('Group'), + _('The group that is mapped to the views (Read, Write, Notify)')); + go.optional = false; + go.rmempty = false; + + go = g.option(form.Value, 'context', _('Context'), + _('The context of the request')); + go.modalonly = true; + + go = g.option(form.ListValue, 'version', _('Version'), + _('The used version for access configuration')); + go.value('any', _('Any version')); + go.value('v1', _('SNMPv1')); + go.value('v2c', _('SNMPv2c')); + go.value('usm', _('SNMPv3')); + go.optional = false; + go.rmempty = false; + + go = g.option(form.ListValue, 'level', _('Level'), + _('Level of security')); + go.value('noauth', _('No authentication')); + go.value('auth', _('Authentication')); + go.value('priv', _('Authentication and encryption')); + go.default = 'noauth'; + go.optional = false; + go.rmempty = false; + + go = g.option(form.ListValue, 'prefix', _('Prefix'), + _('Specification how context of requests is matched to context')); + go.value('exact', _('Exact')); + go.value('prefix', _('Prefix')); + go.optional = false; + go.default = 'exact'; + go.rmempty = false; + + go = g.option(form.ListValue, 'read', _('Read'), + _('Read access modification for groups')); + go.value('all', _('All')); + go.value('none', _('None')); + go.default = 'none'; + go.rmempty = false; + go.modalonly = true; + go.optional = false; + + go = g.option(form.ListValue, 'write', _('Write'), + _('Write access modification for groups')); + go.value('all', _('All')); + go.value('none', _('None')); + go.default = 'none'; + go.rmempty = false; + go.modalonly = true; + go.optional = false; + + go = g.option(form.ListValue, 'notify', _('Notify'), + _('Notify access modification for groups')); + go.value('all', _('All')); + go.value('none', _('None')); + go.default = 'none'; + go.rmempty = false; + go.modalonly = true; + go.optional = false; + }, + populateV1V2CSettings: function(subsection, desc, access, s) { let g, go, o, community, community_src, mode, mask; @@ -353,125 +481,7 @@ return L.view.extend({ this.populateGlobalSettings('general', s); s.tab('advanced', _('Advanced Settings')); - - o = s.taboption('advanced', form.SectionValue, '__advanced__', - form.GridSection, 'com2sec', null, - _('Here you can configure com2sec options')); - - g = o.subsection; - g.anonymous = true; - g.addremove = true; - - go = g.option(form.Value, 'secname', _('Secname'), - _('Arbitrary label for use in group settings')); - go.optional = false; - go.rmempty = false; - - go = g.option(form.Value, 'source', _('Source'), - _('Source describes a host or network')); - go.rmempty = false; - - go = g.option(form.Value, 'community', _('Community'), - _('The community name that is used')); - go.optional = false; - go.rmempty = false; - - o = s.taboption('advanced', form.SectionValue, '__advanced__', - form.GridSection, 'group', null, - _('Here you can configure group options')); - - g = o.subsection; - g.anonymous = true; - g.addremove = true; - - go = g.option(form.Value, 'group', _('Group'), - _('A group maps com2sec names to access names')); - go.optional = false; - go.rmempty = false; - - go = g.option(form.Value, 'version', _('Version'), - _('The used version for the group')); - go.value('v1', _('SNMPv1')); - go.value('v2c' _('SNMPv2c')); - go.value('usm', _('SNMPv3')); - go.optional = false; - go.rmempty = false; - - go = g.option(form.Value, 'secname', _('Secname'), - _('Here you define which secname is mapped to the group')); - go.optional = false; - go.rmempty = false; - - o = s.taboption('advanced', form.SectionValue, '__advanced__', - form.GridSection, 'access', null, - _('Here you can configure access options')); - - g = o.subsection; - g.anonymous = true; - g.addremove = true; - - go = g.option(form.Value, 'group', _('Group'), - _('The group that is mapped to the views (Read, Write, Notify)')); - go.optional = false; - go.rmempty = false; - - go = g.option(form.Value, 'context', _('Context'), - _('The context of the request')); - go.default = 'none'; - go.modalonly = true; - - go = g.option(form.Value, 'version', _('Version'), - _('The used version for access configuration')); - go.value('any', _('Any version')); - go.value('v1', _('SNMPv1')); - go.value('v2c' _('SNMPv2c')); - go.value('usm', _('SNMPv3')); - go.optional = false; - go.rmempty = false; - - go = g.option(form.Value, 'level', _('Level'), - _('Level of security')); - go.value('noauth', _('No authentication (standard for SNMPv1/v2c)')); - go.value('auth', _('Authentication')); - go.value('priv', _('Authentication and encryption')); - go.default = 'noauth'; - go.optional = false; - go.rmempty = false; - - go = g.option(form.Value, 'prefix', _('Prefix'), - _('Specification how context of requests is matched to context')); - go.value('exact', _('Exact')); - go.value('prefix', _('Prefix')); - go.optional = false; - go.default = 'excact'; - go.rmempty = false; - - go = g.option(form.Value, 'read', _('Read'), - _('Read access modification for groups')); - go.value('all', _('All')); - go.value('none', _('None')); - go.default = 'none'; - go.rmempty = false; - go.modalonly = true; - go.optional = false; - - go = g.option(form.Value, 'write', _('Write'), - _('Write access modification for groups')); - go.value('all', _('All')); - go.value('none', _('None')); - go.default = 'none'; - go.rmempty = false; - go.modalonly = true; - go.optional = false; - - go = g.option(form.Value, 'notify', _('Notify'), - _('Notify access modification for groups')); - go.value('all', _('All')); - go.value('none', _('None')); - go.default = 'none'; - go.rmempty = false; - go.modalonly = true; - go.optional = false; + this.populateAdvancedSettings('advanced', s); s.tab('v1/v2c', _('SNMPv1/SNMPv2c')); this.populateV1V2CSettings('access_default', -- 2.30.2