luci: support proxy server settings.

This commit is contained in:
Nick Peng
2023-01-08 22:33:54 +08:00
parent 5392857539
commit ee4816da5c
8 changed files with 132 additions and 5 deletions

View File

@@ -269,6 +269,21 @@ msgstr "未运行"
msgid "No check certificate"
msgstr "停用证书校验"
msgid "Please set proxy server first."
msgstr "请先设置代理服务器。"
msgid "Proxy Server"
msgstr "代理服务器"
msgid "Proxy Server URL, format: [socks5|http]://user:pass@ip:port."
msgstr "代理服务器地址,格式:[socks5|http]://user:pass@ip:port。"
msgid "Proxy server URL format error, format: [socks5|http]://user:pass@ip:port."
msgstr "代理服务器地址格式错误,格式:[socks5|http]://user:pass@ip:port。"
msgid "Proxy Server Settings"
msgstr "代理服务器设置"
msgid "Query DNS through specific dns server group, such as office, home."
msgstr "使用指定服务器组查询比如office, home。"
@@ -431,6 +446,12 @@ msgstr "设置所有域名的 TTL 值。"
msgid "Technical Support"
msgstr "技术支持"
msgid "Use Proxy"
msgstr "使用代理"
msgid "Use proxy to connect to upstream DNS server."
msgstr "使用代理连接上游DNS服务器。"
msgid "URL"
msgstr "URL"

View File

@@ -34,6 +34,7 @@ s.anonymous = true
s:tab("settings", translate("General Settings"))
s:tab("advanced", translate('Advanced Settings'))
s:tab("seconddns", translate("Second Server Settings"))
s:tab("proxy", translate("Proxy Server Settings"))
s:tab("custom", translate("Custom Settings"))
---- Eanble
@@ -312,6 +313,21 @@ o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end
----- Proxy server settings
o = s:taboption("proxy", Value, "proxy_server", translate("Proxy Server"), translate("Proxy Server URL, format: [socks5|http]://user:pass@ip:port."));
o.datatype = 'string';
function o.validate(self, value)
if (value == "") then
return true
end
if (not value:match("^http://") and not value:match("^socks5://")) then
return nil, translate("Proxy server URL format error, format: [socks5|http]://user:pass@ip:port.")
end
return value
end
----- custom settings
custom = s:taboption("custom", Value, "Custom Settings",
translate(""),

View File

@@ -133,6 +133,23 @@ o.default = ""
o.rempty = true
o.datatype = "uinteger"
---- use proxy
o = s:option(Flag, "use_proxy", translate("Use Proxy"), translate("Use proxy to connect to upstream DNS server."))
o.rmempty = true
o.default = o.disabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end
function o.validate(self, value, section)
if value == "1" then
local proxy = m.uci:get_first("smartdns", "smartdns", "proxy_server")
if proxy == nil or proxy == "" then
return nil, translate("Please set proxy server first.")
end
end
return value
end
---- other args
o = s:option(Value, "addition_arg", translate("Additional Server Args"), translate("Additional Args for upstream dns servers"))
o.default = ""

View File

@@ -301,6 +301,24 @@ msgstr "停用证书校验"
msgid "None"
msgstr "无"
msgid "Only socks5 proxy support udp server."
msgstr "仅SOCKS5代理支持UDP服务器。"
msgid "Please set proxy server first."
msgstr "请先设置代理服务器。"
msgid "Proxy Server"
msgstr "代理服务器"
msgid "Proxy Server URL, format: [socks5|http]://user:pass@ip:port."
msgstr "代理服务器地址,格式:[socks5|http]://user:pass@ip:port。"
msgid "Proxy server URL format error, format: [socks5|http]://user:pass@ip:port."
msgstr "代理服务器地址格式错误,格式:[socks5|http]://user:pass@ip:port。"
msgid "Proxy Server Settings"
msgstr "代理服务器设置"
msgid "Query DNS through specific dns server group, such as office, home."
msgstr "使用指定服务器组查询比如office, home。"
@@ -463,6 +481,12 @@ msgstr "设置所有域名的 TTL 值。"
msgid "Technical Support"
msgstr "技术支持"
msgid "Use Proxy"
msgstr "使用代理"
msgid "Use proxy to connect to upstream DNS server."
msgstr "使用代理连接上游DNS服务器。"
msgid "URL"
msgstr "URL"

View File

@@ -132,6 +132,7 @@ return view.extend({
s.tab("advanced", _('Advanced Settings'));
s.tab("seconddns", _("Second Server Settings"));
s.tab("files", _("Download Files Setting"), _("Download domain list files for domain-rule and include config files, please refresh the page after download to take effect."));
s.tab("proxy", _("Proxy Server Settings"));
s.tab("custom", _("Custom Settings"));
///////////////////////////////////////
@@ -444,6 +445,23 @@ return view.extend({
so.rmempty = true;
so.datatype = 'string';
///////////////////////////////////////
// Proxy server settings;
///////////////////////////////////////
o = s.taboption("proxy", form.Value, "proxy_server", _("Proxy Server"), _("Proxy Server URL, format: [socks5|http]://user:pass@ip:port."));
o.datatype = 'string';
o.validate = function (section_id, value) {
if (value == "") {
return true;
}
if (!value.match(/^(socks5|http):\/\//)) {
return _("Proxy server URL format error, format: [socks5|http]://user:pass@ip:port.");
}
return true;
}
///////////////////////////////////////
// custom settings;
///////////////////////////////////////
@@ -602,6 +620,32 @@ return view.extend({
o.rempty = true
o.datatype = "uinteger"
o.modalonly = true;
// use proxy
o = s.taboption("advanced", form.Flag, "use_proxy", _("Use Proxy"),
_("Use proxy to connect to upstream DNS server."))
o.default = o.disabled
o.modalonly = true;
o.optional = true;
o.rempty = true;
o.validate = function(section_id, value) {
var flag = this.formvalue(section_id);
if (flag == "0") {
return true;
}
var proxy_server = uci.sections("smartdns", "smartdns")[0].proxy_server;
var server_type = this.section.formvalue(section_id, "type");
if (proxy_server == "" || proxy_server == undefined) {
return _("Please set proxy server first.");
}
if (server_type == "udp" && !proxy_server.match(/^(socks5):\/\//)) {
return _("Only socks5 proxy support udp server.");
}
return true;
}
// other args
o = s.taboption("advanced", form.Value, "addition_arg", _("Additional Server Args"),

View File

@@ -184,6 +184,7 @@ load_server()
config_get spki_pin "$section" "spki_pin" ""
config_get addition_arg "$section" "addition_arg" ""
config_get set_mark "$section" "set_mark" ""
config_get_bool use_proxy "$section" "use_proxy" "0"
[ "$enabled" = "0" ] && return
@@ -216,6 +217,7 @@ load_server()
[ "$check_edns" = "0" ] || ADDITIONAL_ARGS="$ADDITIONAL_ARGS -check-edns"
[ -z "$spki_pin" ] || ADDITIONAL_ARGS="$ADDITIONAL_ARGS -spki-pin $spki_pin"
[ -z "$set_mark" ] || ADDITIONAL_ARGS="$ADDITIONAL_ARGS -set-mark $set_mark"
[ "$use_proxy" = "0" ] || ADDITIONAL_ARGS="$ADDITIONAL_ARGS -proxy default-proxy"
if [ -z "$port" ]; then
DNS_ADDRESS="$ip"
@@ -533,6 +535,9 @@ load_service()
config_get_bool bind_device "$section" "bind_device" "0"
config_get bind_device_name "$section" "bind_device_name" "${lan_device}"
[ ! -z "$bind_device_name" ] && [ "$bind_device" = "1" ] && device="${bind_device_name}"
config_get proxy_server "$section" "proxy_server" ""
[ -z "$proxy_server" ] || conf_append "proxy-server" "$proxy_server -name default-proxy"
config_get redirect "$section" "redirect" ""
config_get old_port "$section" "old_port" "0"