luci-app-passwall: sync with upstream source

This commit is contained in:
CN_SZTL 2020-02-20 17:05:01 +08:00
parent 1b740072b3
commit fe88274b52
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
10 changed files with 79 additions and 153 deletions

View File

@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-passwall
PKG_VERSION:=3.5
PKG_RELEASE:=16
PKG_RELEASE:=17
PKG_DATA:=20200220
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

View File

@ -13,9 +13,9 @@ LEDE_BOARD = nil
DISTRIB_TARGET = nil
function uci_get_type(type, config, default)
value = uci:get(appname, "@" .. type .. "[0]", config) or sys.exec(
"echo -n `uci -q get " .. appname .. ".@" .. type .. "[0]." ..
config .. "`")
local value = uci:get_first(appname, type, config, default) or sys.exec(
"echo -n `uci -q get " .. appname .. ".@" .. type ..
"[0]." .. config .. "`")
if (value == nil or value == "") and (default and default ~= "") then
value = default
end
@ -23,10 +23,9 @@ function uci_get_type(type, config, default)
end
function uci_get_type_id(id, config, default)
value = uci:get(appname, id, config) or
sys.exec(
"echo -n `uci -q get " .. appname .. "." .. id .. "." ..
config .. "`")
local value = uci:get(appname, id, config, default) or
sys.exec("echo -n `uci -q get " .. appname .. "." .. id ..
"." .. config .. "`")
if (value == nil or value == "") and (default and default ~= "") then
value = default
end
@ -175,7 +174,9 @@ function get_api_json(url)
-- function(chunk) output[#output + 1] = chunk end)
-- local json_content = util.trim(table.concat(output))
local json_content = luci.sys.exec(wget .. " --no-check-certificate --timeout=10 -t 1 -O- " .. url)
local json_content = luci.sys.exec(wget ..
" --no-check-certificate --timeout=10 -t 1 -O- " ..
url)
if json_content == "" then return {} end

View File

@ -31,7 +31,7 @@ o = s:option(Value, "testing_time", translate("How often is a diagnosis made"),
o.default = "3"
---- TCP Node
local tcp_node_num = api.uci_get_type("global_other", "tcp_node_num", 1)
local tcp_node_num = tonumber(api.uci_get_type("global_other", "tcp_node_num", 1))
for i = 1, tcp_node_num, 1 do
o = s:option(DynamicList, "tcp_node" .. i,
"TCP " .. i .. " " .. translate("List of backup nodes"),

View File

@ -37,7 +37,7 @@ table.sort(key_table)
m = Map(appname)
local status_use_big_icon = api.uci_get_type("global_other",
"status_use_big_icon", 1)
if status_use_big_icon and status_use_big_icon == "1" then
if status_use_big_icon and tonumber(status_use_big_icon) == 1 then
m:append(Template("passwall/global/status"))
else
m:append(Template("passwall/global/status2"))
@ -54,7 +54,7 @@ o = s:option(Flag, "enabled", translate("Main switch"))
o.rmempty = false
---- TCP Node
local tcp_node_num = api.uci_get_type("global_other", "tcp_node_num", 1)
local tcp_node_num = tonumber(api.uci_get_type("global_other", "tcp_node_num", 1))
for i = 1, tcp_node_num, 1 do
if i == 1 then
o = s:option(ListValue, "tcp_node" .. i, translate("TCP Node"),
@ -68,7 +68,7 @@ for i = 1, tcp_node_num, 1 do
end
---- UDP Node
local udp_node_num = api.uci_get_type("global_other", "udp_node_num", 1)
local udp_node_num = tonumber(api.uci_get_type("global_other", "udp_node_num", 1))
for i = 1, udp_node_num, 1 do
if i == 1 then
o = s:option(ListValue, "udp_node" .. i, translate("UDP Node"),
@ -85,7 +85,7 @@ for i = 1, udp_node_num, 1 do
end
---- Socks5 Node
local socks5_node_num = api.uci_get_type("global_other", "socks5_node_num", 1)
local socks5_node_num = tonumber(api.uci_get_type("global_other", "socks5_node_num", 1))
for i = 1, socks5_node_num, 1 do
if i == 1 then
o = s:option(ListValue, "socks5_node" .. i, translate("Socks5 Node"),
@ -100,7 +100,7 @@ for i = 1, socks5_node_num, 1 do
for _, key in pairs(key_table) do o:value(key, n[key]) end
end
if tonumber(api.uci_get_type("global_other", "wangejibadns", 0)) == 1 then
if api.uci_get_type("global_other", "wangejibadns", "0") == "1" then
o = s:option(Value, "up_china_dns", translate("China DNS Server") .. "(UDP)",
translate(
"If you want to work with other DNS acceleration services, use the default.<br />Example: 127.0.0.1#6053 ,Represents DNS on using 127.0.0.1 the 6053 port. such as SmartDNS, AdGuard Home...<br />Only use two at most, english comma separation, If you do not fill in the # and the following port, you are using port 53.<br />If you use custom, unless you know what you're doing, setting it up incorrectly can cause your stuck to crash !"))
@ -123,7 +123,7 @@ o = s:option(ListValue, "dns_mode", translate("DNS Mode"), translate(
"if has problem, please try another mode.<br />if you use no patterns are used, DNS of wan will be used by default as upstream of dnsmasq."))
o.rmempty = false
o:reset_values()
if is_finded("chinadns-ng") and tonumber(api.uci_get_type("global_other", "wangejibadns", 0)) == 1 then o:value("chinadns-ng", "ChinaDNS-NG") end
if is_finded("chinadns-ng") and api.uci_get_type("global_other", "wangejibadns", "0") == "1" then o:value("chinadns-ng", "ChinaDNS-NG") end
if is_installed("pdnsd") or is_installed("pdnsd-alt") or is_finded("pdnsd") then
o:value("pdnsd", "pdnsd")
end

View File

@ -178,8 +178,8 @@ o.rmempty = false
---- Hide Menu
o = s:option(Button, "hide", translate("Hide Menu"),
translate(
"After the hidden to the display, input example in the address bar: ") ..
"http://192.168.1.1/cgi-bin/luci/admin/vpn/passwall/show")
"After the hidden to the display, input example in the address bar:") ..
" http://192.168.1.1/cgi-bin/luci/admin/vpn/passwall/show")
o.inputstyle = "remove"
function o.write(e, e)
luci.http.redirect(luci.dispatcher.build_url("admin", "vpn", "passwall",

View File

@ -35,52 +35,6 @@ table td, .table .td {
<script type="text/javascript">
//<![CDATA[
var ajax = {
post: function(url, data, fn_success, fn_timeout) {
var xhr = new XMLHttpRequest();
var code = ajax.encode(data);
xhr.open("POST", url, true);
xhr.timeout = 1000;
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.ontimeout = function() {
fn_timeout(xhr);
}
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 304)) {
var json = null;
if (xhr.getResponseHeader("Content-Type") == "application/json") {
try {
json = eval('(' + xhr.responseText + ')');
}
catch(e) {
json = null;
}
}
fn_success(xhr, json);
}
};
xhr.send(code);
},
encode: function(obj) {
obj = obj ? obj : { };
obj['_'] = Math.random();
if (typeof obj == 'object')
{
var code = '';
var self = this;
for (var k in obj)
code += (code ? '&' : '') +
k + '=' + encodeURIComponent(obj[k]);
return code;
}
return obj;
}
}
var section = "";
function open_set_node_div(cbi_id) {
section = cbi_id;
@ -139,15 +93,12 @@ table td, .table .td {
}
/* 自动Ping */
var auto_ping_value = document.getElementsByClassName('auto_ping_value');
var index = 0;
function auto_ping() {
if (index >= auto_ping_value.length) {
return;
}
var is_ping = auto_ping_value[index].getAttribute("ping");
if (is_ping == null) {
var cbi_id = auto_ping_value[index].getAttribute("cbiid");
const auto_ping_value = document.getElementsByClassName('auto_ping_value');
const xhr = (index) => {
return new Promise((res) => {
const dom = auto_ping_value[index];
if (!dom) res()
var cbi_id = dom.getAttribute("cbiid");
<% if compact_display_nodes and tonumber(compact_display_nodes) == 1 then %>
var remarks = document.getElementById("cbid.passwall." + cbi_id + ".remarks").value;
var address = null;
@ -162,67 +113,38 @@ table td, .table .td {
var port = document.getElementById("cbid.passwall." + cbi_id + ".port").value;
<% end %>
if ((address != null && address != "") && (port != null && port != "")) {
ajax.post('<%=dsp.build_url("admin/vpn/passwall/ping_node")%>', {
index: index,
address: address,
port: port
},
function(x, result) {
if(x && x.status == 200) {
for(var i = 0; i < auto_ping_value.length; i++) {
var obj = auto_ping_value[i];
var obj_cbi_id = obj.getAttribute("cbiid");
<% if compact_display_nodes and tonumber(compact_display_nodes) == 1 then %>
var obj_remarks = document.getElementById("cbid.passwall." + obj_cbi_id + ".remarks").value;
var obj_address = null;
var obj_port = null;
if (obj_remarks.lastIndexOf("") != -1 && obj_remarks.lastIndexOf("") != -1) {
var obj_address_full = obj_remarks.substring(obj_remarks.lastIndexOf("") + 1, obj_remarks.lastIndexOf(""));
obj_address = obj_address_full.substring(0, obj_address_full.lastIndexOf(":"));
obj_port = obj_address_full.substring(obj_address_full.lastIndexOf(":") + 1);
}
<% else %>
var obj_address = document.getElementById("cbid.passwall." + obj_cbi_id + ".address").value;
var obj_port = document.getElementById("cbid.passwall." + obj_cbi_id + ".port").value;
<% end %>
if (address == obj_address && port == obj_port) {
auto_ping_value[i].setAttribute("ping", "1");
if (result.ping == null || result.ping.trim() == "") {
auto_ping_value[i].innerHTML = "<font style='color:red'><%:Timeout%></font>";
} else {
var ping = parseInt(result.ping);
if (ping < 100)
auto_ping_value[i].innerHTML = "<font style='color:green'>" + result.ping + " ms" + "</font>";
else if (ping < 200)
auto_ping_value[i].innerHTML = "<font style='color:#fb9a05'>" + result.ping + " ms" + "</font>";
else if (ping >= 200)
auto_ping_value[i].innerHTML = "<font style='color:red'>" + result.ping + " ms" + "</font>";
}
}
}
}
index++;
auto_ping();
},
function(x) {
auto_ping_value[index].innerHTML = "<font style='color:red'><%:Timeout%></font>";
index++;
auto_ping();
},
);
} else {
index++;
auto_ping();
XHR.get('<%=dsp.build_url("admin/vpn/passwall/ping_node")%>', {
index,
address: address,
port: port
},
(x, result) => {
if (result.ping == null || result.ping.trim() == "") {
auto_ping_value[result.index].innerHTML = "<font style='color:red'><%:Timeout%></font>";
} else {
var ping = parseInt(result.ping);
if (ping < 100)
auto_ping_value[result.index].innerHTML = "<font style='color:green'>" + result.ping + " ms" + "</font>";
else if (ping < 200)
auto_ping_value[result.index].innerHTML = "<font style='color:#fb9a05'>" + result.ping + " ms" + "</font>";
else if (ping >= 200)
auto_ping_value[result.index].innerHTML = "<font style='color:red'>" + result.ping + " ms" + "</font>";
}
res();
});
}
}
else {
index++;
auto_ping();
})
}
let task = -1;
const auto_ping_thread = () => {
task = task + 1
if (auto_ping_value[task]) {
xhr(task).then(auto_ping_thread);
}
}
auto_ping();
for (let i = 0; i < 3; i++) {
auto_ping_thread()
}
//添加"应用"按钮到"修改"按钮前
var edit_btn = document.getElementsByClassName("cbi-button cbi-button-edit");

View File

@ -805,7 +805,7 @@ msgstr "状态信息显示IP111"
msgid "Hide Menu"
msgstr "隐藏菜单"
msgid "After the hidden to the display, input example in the address bar: "
msgid "After the hidden to the display, input example in the address bar:"
msgstr "当你隐藏后想再次显示,地址栏输入例:"
msgid "Can't determine ARCH, or ARCH not supported."

View File

@ -836,8 +836,7 @@ add_dnsmasq() {
conf-dir=$TMP_DNSMASQ_PATH
EOF
cp -rf /var/dnsmasq.d/dnsmasq-$CONFIG.conf $DNSMASQ_PATH/dnsmasq-$CONFIG.conf
/etc/init.d/dnsmasq restart >/dev/null 2>&1 &
echolog "dnsmasq生成配置文件并重启服务。"
echolog "dnsmasq生成配置文件。"
}
gen_redsocks_config() {
@ -1123,8 +1122,9 @@ start() {
add_dnsmasq
source $APP_PATH/iptables.sh start
start_crontab
rm -f "$LOCK_FILE"
/etc/init.d/dnsmasq restart >/dev/null 2>&1 &
echolog "运行完成!\n"
rm -f "$LOCK_FILE"
return 0
}

View File

@ -198,7 +198,8 @@ filter_vpsip() {
if [ -n "$isip" ]; then
ipset -! add $IPSET_VPSIPLIST $isip >/dev/null 2>&1 &
else
echo "$server" | sed -e "/^$/d" | sed "s/^/ipset=&\//g" | sed "s/$/\/&vpsiplist/g" | sort | awk '{if ($0!=line) print;line=$0}' >> $TMP_DNSMASQ_PATH/vpsiplist_host.conf
has=$(cat $TMP_DNSMASQ_PATH/vpsiplist_host.conf | grep "$server")
[ -z "$has" ] && echo "$server" | sed -e "/^$/d" | sed "s/^/ipset=&\//g" | sed "s/$/\/&vpsiplist/g" | sort | awk '{if ($0!=line) print;line=$0}' >> $TMP_DNSMASQ_PATH/vpsiplist_host.conf
fi
}
}

View File

@ -21,7 +21,6 @@ local nodeResult = setmetatable({}, { __index = cache }) -- update result
local name = 'passwall'
local uciType = 'nodes'
local ucic = luci.model.uci.cursor()
local api = require "luci.model.cbi.passwall.api.api"
local arg2 = arg[2]
local log = function(...)
@ -41,22 +40,25 @@ end
-- 分割字符串
local function split(full, sep)
full = full:gsub("%z", "") -- 这里不是很清楚 有时候结尾带个\0
local off, result = 1, {}
while true do
local nStart, nEnd = full:find(sep, off)
if not nEnd then
local res = ssub(full, off, slen(full))
if #res > 0 then -- 过滤掉 \0
tinsert(result, res)
if full then
full = full:gsub("%z", "") -- 这里不是很清楚 有时候结尾带个\0
local off, result = 1, {}
while true do
local nStart, nEnd = full:find(sep, off)
if not nEnd then
local res = ssub(full, off, slen(full))
if #res > 0 then -- 过滤掉 \0
tinsert(result, res)
end
break
else
tinsert(result, ssub(full, off, nStart - 1))
off = nEnd + 1
end
break
else
tinsert(result, ssub(full, off, nStart - 1))
off = nEnd + 1
end
return result
end
return result
return {}
end
-- urlencode
local function get_urlencode(c)
@ -299,7 +301,7 @@ local function truncate_nodes()
for i = 1, tcp_node_num, 1 do
local node = ucic:get_first(name, "global", "tcp_node"..i, nil)
if node and node ~= "nil" then
local is_sub_node = api.uci_get_type_id(node, "is_sub", "0")
local is_sub_node = ucic:get(name, node, "is_sub", "0")
if is_sub_node == "1" then
is_stop = 1
ucic:set(name, ucic:get_first(name, 'global'), "tcp_node"..i, "nil")
@ -310,7 +312,7 @@ local function truncate_nodes()
for i = 1, udp_node_num, 1 do
local node = ucic:get_first(name, "global", "udp_node"..i, nil)
if node and node ~= "nil" then
local is_sub_node = api.uci_get_type_id(node, "is_sub", "0")
local is_sub_node = ucic:get(name, node, "is_sub", "0")
if is_sub_node == "1" then
is_stop = 1
ucic:set(name, ucic:get_first(name, 'global'), "udp_node"..i, "nil")
@ -321,7 +323,7 @@ local function truncate_nodes()
for i = 1, socks5_node_num, 1 do
local node = ucic:get_first(name, "global", "socks5_node"..i, nil)
if node and node ~= "nil" then
local is_sub_node = api.uci_get_type_id(node, "is_sub", "0")
local is_sub_node = ucic:get(name, node, "is_sub", "0")
if is_sub_node == "1" then
is_stop = 1
ucic:set(name, ucic:get_first(name, 'global'), "socks5_node"..i, "nil")