Skip to content

Commit

Permalink
feat(client): dns.rules: Add options
Browse files Browse the repository at this point in the history
Options:
  query_type
  ip_version
  auth_user
  user_id
  clash_mode
  rewrite_ttl
  • Loading branch information
muink committed Nov 22, 2023
1 parent ae49bf2 commit 00ce97c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
32 changes: 32 additions & 0 deletions htdocs/luci-static/resources/view/homeproxy/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,25 @@ return view.extend({
so.rmempty = false;
so.readonly = true;

so = ss.option(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'),
_('Match query type.'));
so.modalonly = true;

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

so = ss.option(form.DynamicList, 'auth_user', _('Auth user'),
_('Match auth user.'));
so.modalonly = true;

so = ss.option(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'));
Expand Down Expand Up @@ -792,6 +806,19 @@ return view.extend({
_('Match user name.'));
so.modalonly = true;

so = ss.option(form.DynamicList, 'user_id', _('User ID'),
_('Match user ID.'));
so.datatype = 'uinteger';
so.modalonly = true;

so = ss.option(form.ListValue, 'clash_mode', _('Clash mode'),
_('Match clash mode.'));
so.value('', _('None'));
so.value('global', _('Global'));
so.value('rule', _('Rule'));
so.value('direct', _('Direct'));
so.modalonly = true;

so = ss.option(form.Flag, 'invert', _('Invert'),
_('Invert match result.'));
so.default = so.disabled;
Expand Down Expand Up @@ -845,6 +872,11 @@ return view.extend({
_('Disable cache and save cache in this query.'));
so.default = so.disabled;
so.modalonly = true;

so = ss.option(form.Value, 'rewrite_ttl', _('Rewrite TTL'),
_('Rewrite TTL in DNS responses.'));
so.datatype = 'uinteger';
so.modalonly = true;
/* DNS rules end */
/* Custom routing settings end */

Expand Down
33 changes: 32 additions & 1 deletion root/etc/homeproxy/scripts/generate_client.uc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'use strict';

import { readfile, writefile } from 'fs';
import { isnan } from 'math';
import { cursor } from 'uci';

import {
Expand Down Expand Up @@ -116,6 +117,30 @@ function parse_port(strport) {

}

function parse_dnsquery(strquery) {
if (type(strquery) !== 'array' || isEmpty(strquery))
return null;

let querys = [];
for (let i in strquery)
isnan(int(i)) ? push(querys, i) : push(querys, int(i));

return querys;

}

function parse_uid(struid) {
if (type(struid) !== 'array' || isEmpty(struid))
return null;

let uids = [];
for (let i in struid)
push(uids, int(i));

return uids;

}

function generate_outbound(node) {
if (type(node) !== 'object' || isEmpty(node))
return null;
Expand Down Expand Up @@ -378,7 +403,10 @@ if (!isEmpty(main_node)) {
return;

push(config.dns.rules, {
ip_version: strToInt(cfg.ip_version),
query_type: parse_dnsquery(cfg.query_type),
network: cfg.network,
auth_user: cfg.auth_user,
protocol: cfg.protocol,
domain: cfg.domain,
domain_suffix: cfg.domain_suffix,
Expand All @@ -394,10 +422,13 @@ if (!isEmpty(main_node)) {
process_name: cfg.process_name,
process_path: cfg.process_path,
user: cfg.user,
user_id: parse_uid(cfg.user_id),
clash_mode: cfg.clash_mode,
invert: (cfg.invert === '1'),
outbound: get_outbound(cfg.outbound),
server: get_resolver(cfg.server),
disable_cache: (cfg.dns_disable_cache === '1')
disable_cache: (cfg.dns_disable_cache === '1'),
rewrite_ttl: strToInt(cfg.rewrite_ttl)
});
});

Expand Down

0 comments on commit 00ce97c

Please sign in to comment.