luci: fix bug
This commit is contained in:
parent
b1d695f5a9
commit
1e93848cc9
@ -16,6 +16,24 @@ DISTRIB_TARGET = nil
|
||||
LOG_FILE = "/tmp/log/" .. appname .. ".log"
|
||||
CACHE_PATH = "/tmp/etc/" .. appname .. "_tmp"
|
||||
|
||||
function exec_call(cmd)
|
||||
local process = io.popen(cmd .. '; echo -e "\n$?"')
|
||||
local lines = {}
|
||||
local result = ""
|
||||
local return_code
|
||||
for line in process:lines() do
|
||||
lines[#lines + 1] = line
|
||||
end
|
||||
process:close()
|
||||
if #lines > 0 then
|
||||
return_code = lines[#lines]
|
||||
for i = 1, #lines - 1 do
|
||||
result = result .. lines[i] .. ((i == #lines - 1) and "" or "\n")
|
||||
end
|
||||
end
|
||||
return tonumber(return_code), trim(result)
|
||||
end
|
||||
|
||||
function base64Decode(text)
|
||||
local raw = text
|
||||
if not text then return '' end
|
||||
@ -39,11 +57,7 @@ function curl_base(url, file, args)
|
||||
args[#args + 1] = "-o " .. file
|
||||
end
|
||||
local cmd = string.format('curl %s "%s"', table_join(args), url)
|
||||
if file then
|
||||
return luci.sys.call(cmd .. " > /dev/null")
|
||||
else
|
||||
return trim(luci.sys.exec(cmd))
|
||||
end
|
||||
return exec_call(cmd)
|
||||
end
|
||||
|
||||
function curl_proxy(url, file, args)
|
||||
@ -55,15 +69,15 @@ function curl_proxy(url, file, args)
|
||||
tmp_args[#tmp_args + 1] = "-x socks5h://" .. socks_server
|
||||
return curl_base(url, file, tmp_args)
|
||||
end
|
||||
return nil
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
function curl_logic(url, file, args)
|
||||
local result = curl_proxy(url, file, args)
|
||||
if not result then
|
||||
result = curl_base(url, file, args)
|
||||
local return_code, result = curl_proxy(url, file, args)
|
||||
if not return_code or return_code ~= 0 then
|
||||
return_code, result = curl_base(url, file, args)
|
||||
end
|
||||
return result
|
||||
return return_code, result
|
||||
end
|
||||
|
||||
function url(...)
|
||||
@ -628,9 +642,9 @@ end
|
||||
|
||||
function get_api_json(url)
|
||||
local jsonc = require "luci.jsonc"
|
||||
local json_content = curl_logic(url, nil, curl_args)
|
||||
if json_content == "" then return {} end
|
||||
return jsonc.parse(json_content) or {}
|
||||
local return_code, content = curl_logic(url, nil, curl_args)
|
||||
if return_code ~= 0 or content == "" then return {} end
|
||||
return jsonc.parse(content) or {}
|
||||
end
|
||||
|
||||
function common_to_check(api_url, local_version, match_file_name)
|
||||
|
@ -63,7 +63,8 @@ function to_download(url, size)
|
||||
end
|
||||
end
|
||||
|
||||
result = api.curl_logic(url, tmp_file, api.curl_args) == 0
|
||||
local return_code, result = api.curl_logic(url, tmp_file, api.curl_args)
|
||||
result = return_code == 0
|
||||
|
||||
if not result then
|
||||
api.exec("/bin/rm", {"-f", tmp_file})
|
||||
|
@ -63,7 +63,8 @@ function to_download(url, size)
|
||||
end
|
||||
end
|
||||
|
||||
result = api.curl_logic(url, tmp_file, api.curl_args) == 0
|
||||
local return_code, result = api.curl_logic(url, tmp_file, api.curl_args)
|
||||
result = return_code == 0
|
||||
|
||||
if not result then
|
||||
api.exec("/bin/rm", {"-f", tmp_file})
|
||||
|
@ -71,7 +71,8 @@ function to_download(url, size)
|
||||
end
|
||||
end
|
||||
|
||||
result = api.curl_logic(url, tmp_file, api.curl_args) == 0
|
||||
local return_code, result = api.curl_logic(url, tmp_file, api.curl_args)
|
||||
result = return_code == 0
|
||||
|
||||
if not result then
|
||||
api.exec("/bin/rm", {"-f", tmp_file})
|
||||
|
@ -69,7 +69,8 @@ function to_download(url, size)
|
||||
end
|
||||
end
|
||||
|
||||
result = api.curl_logic(url, tmp_file, api.curl_args) == 0
|
||||
local return_code, result = api.curl_logic(url, tmp_file, api.curl_args)
|
||||
result = return_code == 0
|
||||
|
||||
if not result then
|
||||
api.exec("/bin/rm", {"-f", tmp_file})
|
||||
|
@ -69,7 +69,8 @@ function to_download(url, size)
|
||||
end
|
||||
end
|
||||
|
||||
result = api.curl_logic(url, tmp_file, api.curl_args) == 0
|
||||
local return_code, result = api.curl_logic(url, tmp_file, api.curl_args)
|
||||
result = return_code == 0
|
||||
|
||||
if not result then
|
||||
api.exec("/bin/rm", {"-f", tmp_file})
|
||||
|
@ -924,7 +924,7 @@ start_redir() {
|
||||
|
||||
start_socks() {
|
||||
tcp_node_socks=1
|
||||
tcp_node_socks_port=$(config_t_get global tcp_node_socks_port 1070)
|
||||
tcp_node_socks_port=$(get_new_port $(config_t_get global tcp_node_socks_port 1070))
|
||||
tcp_node_http_port=$(config_t_get global tcp_node_http_port 0)
|
||||
[ "$tcp_node_http_port" != "0" ] && tcp_node_http=1
|
||||
[ "$SOCKS_ENABLED" = "1" ] && {
|
||||
|
@ -66,13 +66,8 @@ local function curl(url, file, valifile)
|
||||
if valifile then
|
||||
args[#args + 1] = "--dump-header " .. valifile
|
||||
end
|
||||
local result = api.curl_logic(url, nil, args)
|
||||
|
||||
if file then
|
||||
return tonumber(trim(result))
|
||||
else
|
||||
return trim(result)
|
||||
end
|
||||
local return_code, result = api.curl_logic(url, nil, args)
|
||||
return tonumber(result)
|
||||
end
|
||||
|
||||
--check excluded domain
|
||||
@ -246,7 +241,7 @@ end
|
||||
local function fetch_geoip()
|
||||
--请求geoip
|
||||
xpcall(function()
|
||||
local json_str = curl(geoip_api)
|
||||
local json_str = api.curl_logic(geoip_api)
|
||||
local json = jsonc.parse(json_str)
|
||||
if json.tag_name and json.assets then
|
||||
for _, v in ipairs(json.assets) do
|
||||
@ -297,7 +292,7 @@ end
|
||||
local function fetch_geosite()
|
||||
--请求geosite
|
||||
xpcall(function()
|
||||
local json_str = curl(geosite_api)
|
||||
local json_str = api.curl_logic(geosite_api)
|
||||
local json = jsonc.parse(json_str)
|
||||
if json.tag_name and json.assets then
|
||||
for _, v in ipairs(json.assets) do
|
||||
|
@ -837,8 +837,8 @@ local function curl(url, file, ua)
|
||||
local args = {
|
||||
"-skL", "--retry 3", "--connect-timeout 3", '--user-agent "' .. ua .. '"'
|
||||
}
|
||||
local result = api.curl_logic(url, file, args)
|
||||
return result
|
||||
local return_code, result = api.curl_logic(url, file, args)
|
||||
return return_code
|
||||
end
|
||||
|
||||
local function truncate_nodes(add_from)
|
||||
|
Loading…
Reference in New Issue
Block a user