Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classify fields with the same logic in DNS Rule and Routing Rule to improve their readability #125

Merged
merged 3 commits into from
Jul 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 68 additions & 56 deletions htdocs/luci-static/resources/view/homeproxy/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,17 +432,23 @@ return view.extend({
ss.sectiontitle = L.bind(hp.loadDefaultLabel, this, data[0]);
ss.renderSectionAdd = L.bind(hp.renderSectionAdd, this, ss);

so = ss.option(form.Value, 'label', _('Label'));
ss.tab('field_other', _('Other Fields'));
ss.tab('field_host', _('Host Fields'));
ss.tab('field_port', _('Port Fields'));
ss.tab('field_source_ip', _('SRC-IP Fields'));
ss.tab('field_source_port', _('SRC-Port Fields'));

so = ss.taboption('field_other', form.Value, 'label', _('Label'));
so.load = L.bind(hp.loadDefaultLabel, this, data[0]);
so.validate = L.bind(hp.validateUniqueValue, this, data[0], 'routing_rule', 'label');
so.modalonly = true;

so = ss.option(form.Flag, 'enabled', _('Enable'));
so = ss.taboption('field_other', form.Flag, 'enabled', _('Enable'));
so.default = so.enabled;
so.rmempty = false;
so.editable = true;

so = ss.option(form.ListValue, 'mode', _('Mode'),
so = ss.taboption('field_other', form.ListValue, 'mode', _('Mode'),
_('The default rule uses the following matching logic:<br/>' +
'<code>(domain || domain_suffix || domain_keyword || domain_regex || ip_cidr || ip_is_private)</code> &&<br/>' +
'<code>(port || port_range)</code> &&<br/>' +
Expand All @@ -455,97 +461,97 @@ return view.extend({
so.rmempty = false;
so.readonly = true;

so = ss.option(form.ListValue, 'ip_version', _('IP version'),
so = ss.taboption('field_other', form.ListValue, 'ip_version', _('IP version'),
_('4 or 6. Not limited if empty.'));
so.value('4', _('IPv4'));
so.value('6', _('IPv6'));
so.value('', _('Both'));
so.modalonly = true;

so = ss.option(form.MultiValue, 'protocol', _('Protocol'),
so = ss.taboption('field_other', form.MultiValue, 'protocol', _('Protocol'),
_('Sniffed protocol, see <a target="_blank" href="https://sing-box.sagernet.org/configuration/route/sniff/">Sniff</a> for details.'));
so.value('http', _('HTTP'));
so.value('tls', _('TLS'));
so.value('quic', _('QUIC'));
so.value('stun', _('STUN'));

so = ss.option(form.ListValue, 'network', _('Network'));
so = ss.taboption('field_other', form.ListValue, 'network', _('Network'));
so.value('tcp', _('TCP'));
so.value('udp', _('UDP'));
so.value('', _('Both'));

so = ss.option(form.DynamicList, 'domain', _('Domain name'),
so = ss.taboption('field_host', form.DynamicList, 'domain', _('Domain name'),
_('Match full domain.'));
so.datatype = 'hostname';
so.modalonly = true;

so = ss.option(form.DynamicList, 'domain_suffix', _('Domain suffix'),
so = ss.taboption('field_host', form.DynamicList, 'domain_suffix', _('Domain suffix'),
_('Match domain suffix.'));
so.modalonly = true;

so = ss.option(form.DynamicList, 'domain_keyword', _('Domain keyword'),
so = ss.taboption('field_host', form.DynamicList, 'domain_keyword', _('Domain keyword'),
_('Match domain using keyword.'));
so.modalonly = true;

so = ss.option(form.DynamicList, 'domain_regex', _('Domain regex'),
so = ss.taboption('field_host', form.DynamicList, 'domain_regex', _('Domain regex'),
_('Match domain using regular expression.'));
so.modalonly = true;

so = ss.option(form.DynamicList, 'source_ip_cidr', _('Source IP CIDR'),
so = ss.taboption('field_source_ip', form.DynamicList, 'source_ip_cidr', _('Source IP CIDR'),
_('Match source IP CIDR.'));
so.datatype = 'or(cidr, ipaddr)';
so.modalonly = true;

so = ss.option(form.Flag, 'source_ip_is_private', _('Private source IP'),
so = ss.taboption('field_source_ip', form.Flag, 'source_ip_is_private', _('Private source IP'),
_('Match private source IP.'));
so.default = so.disabled;
so.rmempty = false;
so.modalonly = true;

so = ss.option(form.DynamicList, 'ip_cidr', _('IP CIDR'),
so = ss.taboption('field_host', form.DynamicList, 'ip_cidr', _('IP CIDR'),
_('Match IP CIDR.'));
so.datatype = 'or(cidr, ipaddr)';
so.modalonly = true;

so = ss.option(form.Flag, 'ip_is_private', _('Private IP'),
so = ss.taboption('field_host', form.Flag, 'ip_is_private', _('Private IP'),
_('Match private IP.'));
so.default = so.disabled;
so.rmempty = false;
so.modalonly = true;

so = ss.option(form.DynamicList, 'source_port', _('Source port'),
so = ss.taboption('field_source_port', form.DynamicList, 'source_port', _('Source port'),
_('Match source port.'));
so.datatype = 'port';
so.modalonly = true;

so = ss.option(form.DynamicList, 'source_port_range', _('Source port range'),
so = ss.taboption('field_source_port', form.DynamicList, 'source_port_range', _('Source port range'),
_('Match source port range. Format as START:/:END/START:END.'));
so.validate = validatePortRange;
so.modalonly = true;

so = ss.option(form.DynamicList, 'port', _('Port'),
so = ss.taboption('field_port', form.DynamicList, 'port', _('Port'),
_('Match port.'));
so.datatype = 'port';
so.modalonly = true;

so = ss.option(form.DynamicList, 'port_range', _('Port range'),
so = ss.taboption('field_port', form.DynamicList, 'port_range', _('Port range'),
_('Match port range. Format as START:/:END/START:END.'));
so.validate = validatePortRange;
so.modalonly = true;

so = ss.option(form.DynamicList, 'process_name', _('Process name'),
so = ss.taboption('field_other', form.DynamicList, 'process_name', _('Process name'),
_('Match process name.'));
so.modalonly = true;

so = ss.option(form.DynamicList, 'process_path', _('Process path'),
so = ss.taboption('field_other', form.DynamicList, 'process_path', _('Process path'),
_('Match process path.'));
so.modalonly = true;

so = ss.option(form.DynamicList, 'user', _('User'),
so = ss.taboption('field_other', form.DynamicList, 'user', _('User'),
_('Match user name.'));
so.modalonly = true;

so = ss.option(form.MultiValue, 'rule_set', _('Rule set'),
so = ss.taboption('field_other', form.MultiValue, 'rule_set', _('Rule set'),
_('Match rule set.'));
so.load = function(section_id) {
delete this.keylist;
Expand All @@ -561,18 +567,18 @@ return view.extend({
}
so.modalonly = true;

so = ss.option(form.Flag, 'rule_set_ipcidr_match_source', _('Match source IP via rule set'),
so = ss.taboption('field_other', form.Flag, 'rule_set_ipcidr_match_source', _('Match source IP via rule set'),
_('Make IP CIDR in rule set used to match the source IP.'));
so.default = so.disabled;
so.rmempty = false;
so.modalonly = true;

so = ss.option(form.Flag, 'invert', _('Invert'),
so = ss.taboption('field_other', form.Flag, 'invert', _('Invert'),
_('Invert match result.'));
so.default = so.disabled;
so.modalonly = true;

so = ss.option(form.ListValue, 'outbound', _('Outbound'),
so = ss.taboption('field_other', form.ListValue, 'outbound', _('Outbound'),
_('Tag of the target outbound.'));
so.load = function(section_id) {
delete this.keylist;
Expand Down Expand Up @@ -758,17 +764,23 @@ return view.extend({
ss.sectiontitle = L.bind(hp.loadDefaultLabel, this, data[0]);
ss.renderSectionAdd = L.bind(hp.renderSectionAdd, this, ss);

so = ss.option(form.Value, 'label', _('Label'));
ss.tab('field_other', _('Other Fields'));
ss.tab('field_host', _('Host Fields'));
ss.tab('field_port', _('Port Fields'));
ss.tab('field_source_ip', _('SRC-IP Fields'));
ss.tab('field_source_port', _('SRC-Port Fields'));

so = ss.taboption('field_other', form.Value, 'label', _('Label'));
so.load = L.bind(hp.loadDefaultLabel, this, data[0]);
so.validate = L.bind(hp.validateUniqueValue, this, data[0], 'dns_rule', 'label');
so.modalonly = true;

so = ss.option(form.Flag, 'enabled', _('Enable'));
so = ss.taboption('field_other', form.Flag, 'enabled', _('Enable'));
so.default = so.enabled;
so.rmempty = false;
so.editable = true;

so = ss.option(form.ListValue, 'mode', _('Mode'),
so = ss.taboption('field_other', form.ListValue, 'mode', _('Mode'),
_('The default rule uses the following matching logic:<br/>' +
'<code>(domain || domain_suffix || domain_keyword || domain_regex)</code> &&<br/>' +
'<code>(port || port_range)</code> &&<br/>' +
Expand All @@ -781,99 +793,99 @@ return view.extend({
so.rmempty = false;
so.readonly = true;

so = ss.option(form.ListValue, 'ip_version', _('IP version'));
so = ss.taboption('field_other', form.ListValue, 'ip_version', _('IP version'));
so.value('4', _('IPv4'));
so.value('6', _('IPv6'));
so.value('', _('Both'));
so.modalonly = true;

so = ss.option(form.DynamicList, 'query_type', _('Query type'),
so = ss.taboption('field_other', form.DynamicList, 'query_type', _('Query type'),
_('Match query type.'));
so.modalonly = true;

so = ss.option(form.ListValue, 'network', _('Network'));
so = ss.taboption('field_other', form.ListValue, 'network', _('Network'));
so.value('tcp', _('TCP'));
so.value('udp', _('UDP'));
so.value('', _('Both'));

so = ss.option(form.MultiValue, 'protocol', _('Protocol'),
so = ss.taboption('field_other', form.MultiValue, 'protocol', _('Protocol'),
_('Sniffed protocol, see <a target="_blank" href="https://sing-box.sagernet.org/configuration/route/sniff/">Sniff</a> for details.'));
so.value('http', _('HTTP'));
so.value('tls', _('TLS'));
so.value('quic', _('QUIC'));
so.value('dns', _('DNS'));
so.value('stun', _('STUN'));

so = ss.option(form.DynamicList, 'domain', _('Domain name'),
so = ss.taboption('field_host', form.DynamicList, 'domain', _('Domain name'),
_('Match full domain.'));
so.datatype = 'hostname';
so.modalonly = true;

so = ss.option(form.DynamicList, 'domain_suffix', _('Domain suffix'),
so = ss.taboption('field_host', form.DynamicList, 'domain_suffix', _('Domain suffix'),
_('Match domain suffix.'));
so.modalonly = true;

so = ss.option(form.DynamicList, 'domain_keyword', _('Domain keyword'),
so = ss.taboption('field_host', form.DynamicList, 'domain_keyword', _('Domain keyword'),
_('Match domain using keyword.'));
so.modalonly = true;

so = ss.option(form.DynamicList, 'domain_regex', _('Domain regex'),
so = ss.taboption('field_host', form.DynamicList, 'domain_regex', _('Domain regex'),
_('Match domain using regular expression.'));
so.modalonly = true;

so = ss.option(form.DynamicList, 'port', _('Port'),
so = ss.taboption('field_port', form.DynamicList, 'port', _('Port'),
_('Match port.'));
so.datatype = 'port';
so.modalonly = true;

so = ss.option(form.DynamicList, 'port_range', _('Port range'),
so = ss.taboption('field_port', form.DynamicList, 'port_range', _('Port range'),
_('Match port range. Format as START:/:END/START:END.'));
so.validate = validatePortRange;
so.modalonly = true;

so = ss.option(form.DynamicList, 'source_ip_cidr', _('Source IP CIDR'),
so = ss.taboption('field_source_ip', form.DynamicList, 'source_ip_cidr', _('Source IP CIDR'),
_('Match source IP CIDR.'));
so.datatype = 'or(cidr, ipaddr)';
so.modalonly = true;

so = ss.option(form.Flag, 'source_ip_is_private', _('Private source IP'),
so = ss.taboption('field_source_ip', form.Flag, 'source_ip_is_private', _('Private source IP'),
_('Match private source IP.'));
so.default = so.disabled;
so.modalonly = true;

so = ss.option(form.DynamicList, 'ip_cidr', _('IP CIDR'),
so = ss.taboption('field_other', form.DynamicList, 'ip_cidr', _('IP CIDR'),
_('Match IP CIDR with query response.'));
so.datatype = 'or(cidr, ipaddr)';
so.modalonly = true;

so = ss.option(form.Flag, 'ip_is_private', _('Private IP'),
so = ss.taboption('field_other', form.Flag, 'ip_is_private', _('Private IP'),
_('Match private IP with query response.'));
so.default = so.disabled;
so.modalonly = true;

so = ss.option(form.DynamicList, 'source_port', _('Source port'),
so = ss.taboption('field_source_port', form.DynamicList, 'source_port', _('Source port'),
_('Match source port.'));
so.datatype = 'port';
so.modalonly = true;

so = ss.option(form.DynamicList, 'source_port_range', _('Source port range'),
so = ss.taboption('field_source_port', form.DynamicList, 'source_port_range', _('Source port range'),
_('Match source port range. Format as START:/:END/START:END.'));
so.validate = validatePortRange;
so.modalonly = true;

so = ss.option(form.DynamicList, 'process_name', _('Process name'),
so = ss.taboption('field_other', form.DynamicList, 'process_name', _('Process name'),
_('Match process name.'));
so.modalonly = true;

so = ss.option(form.DynamicList, 'process_path', _('Process path'),
so = ss.taboption('field_other', form.DynamicList, 'process_path', _('Process path'),
_('Match process path.'));
so.modalonly = true;

so = ss.option(form.DynamicList, 'user', _('User'),
so = ss.taboption('field_other', form.DynamicList, 'user', _('User'),
_('Match user name.'));
so.modalonly = true;

so = ss.option(form.MultiValue, 'rule_set', _('Rule set'),
so = ss.taboption('field_other', form.MultiValue, 'rule_set', _('Rule set'),
_('Match rule set.'));
so.load = function(section_id) {
delete this.keylist;
Expand All @@ -889,17 +901,17 @@ return view.extend({
}
so.modalonly = true;

so = ss.option(form.Flag, 'rule_set_ipcidr_match_source', _('Rule set IP CIDR as source IP'),
so = ss.taboption('field_other', form.Flag, 'rule_set_ipcidr_match_source', _('Rule set IP CIDR as source IP'),
_('Make <code>ipcidr</code> in rule sets match the source IP.'));
so.default = so.disabled;
so.modalonly = true;

so = ss.option(form.Flag, 'invert', _('Invert'),
so = ss.taboption('field_other', form.Flag, 'invert', _('Invert'),
_('Invert match result.'));
so.default = so.disabled;
so.modalonly = true;

so = ss.option(form.MultiValue, 'outbound', _('Outbound'),
so = ss.taboption('field_other', form.MultiValue, 'outbound', _('Outbound'),
_('Match outbound.'));
so.load = function(section_id) {
delete this.keylist;
Expand All @@ -917,7 +929,7 @@ return view.extend({
}
so.modalonly = true;

so = ss.option(form.ListValue, 'server', _('Server'),
so = ss.taboption('field_other', form.ListValue, 'server', _('Server'),
_('Tag of the target dns server.'));
so.load = function(section_id) {
delete this.keylist;
Expand All @@ -936,17 +948,17 @@ return view.extend({
so.rmempty = false;
so.editable = true;

so = ss.option(form.Flag, 'dns_disable_cache', _('Disable dns cache'),
so = ss.taboption('field_other', form.Flag, 'dns_disable_cache', _('Disable dns cache'),
_('Disable cache and save cache in this query.'));
so.default = so.disabled;
so.modalonly = true;

so = ss.option(form.Value, 'rewrite_ttl', _('Rewrite TTL'),
so = ss.taboption('field_other', form.Value, 'rewrite_ttl', _('Rewrite TTL'),
_('Rewrite TTL in DNS responses.'));
so.datatype = 'uinteger';
so.modalonly = true;

so = ss.option(form.Value, 'client_subnet', _('EDNS Client subnet'),
so = ss.taboption('field_other', form.Value, 'client_subnet', _('EDNS Client subnet'),
_('Append a <code>edns0-subnet</code> OPT extra record with the specified IP prefix to every query by default.<br/>' +
'If value is an IP address instead of prefix, <code>/32</code> or <code>/128</code> will be appended automatically.'));
so.datatype = 'or(cidr, ipaddr)';
Expand All @@ -973,7 +985,7 @@ return view.extend({
so.modalonly = true;

so = ss.option(form.Flag, 'enabled', _('Enable'));
so.default = o.enabled;
so.default = so.enabled;
so.rmempty = false;
so.editable = true;

Expand Down