mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-02 16:23:56 +08:00
🚀 Sync 2026-03-18 20:29:42
This commit is contained in:
1 parent
c62c96aa04
commit
79996b4e00
212 files changed
+6047
-30308
No files matched your search
@@ -42,11 +42,6 @@ function index()
|
||||
entry({"admin", "services", "openclash", "one_key_update_check"}, call("action_one_key_update_check"))
|
||||
entry({"admin", "services", "openclash", "switch_mode"}, call("action_switch_mode"))
|
||||
entry({"admin", "services", "openclash", "op_mode"}, call("action_op_mode"))
|
||||
entry({"admin", "services", "openclash", "dler_info"}, call("action_dler_info"))
|
||||
entry({"admin", "services", "openclash", "dler_checkin"}, call("action_dler_checkin"))
|
||||
entry({"admin", "services", "openclash", "dler_logout"}, call("action_dler_logout"))
|
||||
entry({"admin", "services", "openclash", "dler_login"}, call("action_dler_login"))
|
||||
entry({"admin", "services", "openclash", "dler_login_info_save"}, call("action_dler_login_info_save"))
|
||||
entry({"admin", "services", "openclash", "sub_info_get"}, call("sub_info_get"))
|
||||
entry({"admin", "services", "openclash", "config_name"}, call("action_config_name"))
|
||||
entry({"admin", "services", "openclash", "switch_config"}, call("action_switch_config"))
|
||||
@@ -75,22 +70,17 @@ function index()
|
||||
entry({"admin", "services", "openclash", "announcement"}, call("action_announcement"))
|
||||
entry({"admin", "services", "openclash", "settings"},cbi("openclash/settings"),_("Plugin Settings"), 30).leaf = true
|
||||
entry({"admin", "services", "openclash", "config-overwrite"},cbi("openclash/config-overwrite"),_("Overwrite Settings"), 40).leaf = true
|
||||
entry({"admin", "services", "openclash", "servers"},cbi("openclash/servers"),_("Onekey Create"), 50).leaf = true
|
||||
entry({"admin", "services", "openclash", "config-subscribe"},cbi("openclash/config-subscribe"),_("Config Subscribe"), 60).leaf = true
|
||||
entry({"admin", "services", "openclash", "servers"},cbi("openclash/servers"),nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "other-rules-edit"},cbi("openclash/other-rules-edit"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "custom-dns-edit"},cbi("openclash/custom-dns-edit"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "other-file-edit"},cbi("openclash/other-file-edit"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "rule-providers-settings"},cbi("openclash/rule-providers-settings"),_("Rule Providers Append"), 60).leaf = true
|
||||
entry({"admin", "services", "openclash", "game-rules-manage"},form("openclash/game-rules-manage"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "rule-providers-manage"},form("openclash/rule-providers-manage"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "proxy-provider-file-manage"},form("openclash/proxy-provider-file-manage"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "rule-providers-file-manage"},form("openclash/rule-providers-file-manage"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "game-rules-file-manage"},form("openclash/game-rules-file-manage"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "config-subscribe"},cbi("openclash/config-subscribe"),_("Config Subscribe"), 70).leaf = true
|
||||
entry({"admin", "services", "openclash", "config-subscribe-edit"},cbi("openclash/config-subscribe-edit"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "servers-config"},cbi("openclash/servers-config"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "groups-config"},cbi("openclash/groups-config"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "proxy-provider-config"},cbi("openclash/proxy-provider-config"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "rule-providers-config"},cbi("openclash/rule-providers-config"), nil).leaf = true
|
||||
entry({"admin", "services", "openclash", "config"},form("openclash/config"),_("Config Manage"), 80).leaf = true
|
||||
entry({"admin", "services", "openclash", "log"},cbi("openclash/log"),_("Server Logs"), 90).leaf = true
|
||||
entry({"admin", "services", "openclash", "myip_check"}, call("action_myip_check"))
|
||||
@@ -177,19 +167,13 @@ end
|
||||
|
||||
local function startlog()
|
||||
local info = ""
|
||||
local line_trans = ""
|
||||
if fs.access("/tmp/openclash_start.log") then
|
||||
info = luci.sys.exec("sed -n '$p' /tmp/openclash_start.log 2>/dev/null")
|
||||
line_trans = info
|
||||
if string.len(info) > 0 then
|
||||
if not string.find (info, "【") or not string.find (info, "】") then
|
||||
line_trans = trans_line_nolabel(info)
|
||||
else
|
||||
line_trans = trans_line(info)
|
||||
end
|
||||
end
|
||||
info = trans_line(info)
|
||||
end
|
||||
end
|
||||
return line_trans
|
||||
return info
|
||||
end
|
||||
|
||||
local function pkg_type()
|
||||
@@ -234,23 +218,19 @@ local function coremetacv()
|
||||
end
|
||||
|
||||
local function corelv()
|
||||
local status = process_status("/usr/share/openclash/clash_version.sh")
|
||||
local core_meta_lv = ""
|
||||
local core_smart_enable = fs.uci_get_config("config", "smart_enable") or "0"
|
||||
if not status then
|
||||
if fs.access("/tmp/clash_last_version") and tonumber(os.time() - fs.mtime("/tmp/clash_last_version")) < 1800 then
|
||||
if core_smart_enable == "1" then
|
||||
core_meta_lv = luci.sys.exec("sed -n 2p /tmp/clash_last_version 2>/dev/null |tr -d '\n'")
|
||||
else
|
||||
core_meta_lv = luci.sys.exec("sed -n 1p /tmp/clash_last_version 2>/dev/null |tr -d '\n'")
|
||||
end
|
||||
if fs.access("/tmp/clash_last_version") then
|
||||
if core_smart_enable == "1" then
|
||||
core_meta_lv = luci.sys.exec("sed -n 2p /tmp/clash_last_version 2>/dev/null |tr -d '\n'")
|
||||
else
|
||||
action_get_last_version()
|
||||
core_meta_lv = "loading..."
|
||||
core_meta_lv = luci.sys.exec("sed -n 1p /tmp/clash_last_version 2>/dev/null |tr -d '\n'")
|
||||
end
|
||||
else
|
||||
core_meta_lv = "loading..."
|
||||
end
|
||||
|
||||
action_get_last_version()
|
||||
return core_meta_lv
|
||||
end
|
||||
|
||||
@@ -274,23 +254,19 @@ local function opcv()
|
||||
end
|
||||
|
||||
local function oplv()
|
||||
local status = process_status("/usr/share/openclash/openclash_version.sh")
|
||||
local oplv = ""
|
||||
if not status then
|
||||
if fs.access("/tmp/openclash_last_version") and tonumber(os.time() - fs.mtime("/tmp/openclash_last_version")) < 1800 then
|
||||
oplv = luci.sys.exec("sed -n 1p /tmp/openclash_last_version 2>/dev/null |tr -d '\n'")
|
||||
else
|
||||
action_get_last_version()
|
||||
oplv = "loading..."
|
||||
end
|
||||
|
||||
if fs.access("/tmp/openclash_last_version") then
|
||||
oplv = luci.sys.exec("sed -n 1p /tmp/openclash_last_version 2>/dev/null |tr -d '\n'")
|
||||
else
|
||||
oplv = "loading..."
|
||||
end
|
||||
|
||||
action_get_last_version()
|
||||
return oplv
|
||||
end
|
||||
|
||||
local function opup()
|
||||
luci.sys.call("rm -rf /tmp/*_last_version 2>/dev/null && bash /usr/share/openclash/openclash_version.sh >/dev/null 2>&1")
|
||||
return luci.sys.call("bash /usr/share/openclash/openclash_update.sh >/dev/null 2>&1 &")
|
||||
end
|
||||
|
||||
@@ -298,7 +274,6 @@ local function coreup()
|
||||
uci:set("openclash", "config", "enable", "1")
|
||||
uci:commit("openclash")
|
||||
local type = luci.http.formvalue("core_type")
|
||||
luci.sys.call("rm -rf /tmp/*_last_version 2>/dev/null && bash /usr/share/openclash/clash_version.sh >/dev/null 2>&1")
|
||||
return luci.sys.call(string.format("/usr/share/openclash/openclash_core.sh '%s' >/dev/null 2>&1 &", type))
|
||||
end
|
||||
|
||||
@@ -346,21 +321,13 @@ end
|
||||
function core_download()
|
||||
local cdn_url = luci.http.formvalue("url")
|
||||
if cdn_url then
|
||||
luci.sys.call(string.format("rm -rf /tmp/clash_last_version 2>/dev/null && bash /usr/share/openclash/clash_version.sh '%s' >/dev/null 2>&1", cdn_url))
|
||||
luci.sys.call(string.format("bash /usr/share/openclash/openclash_core.sh 'Meta' '%s' >/dev/null 2>&1 &", cdn_url))
|
||||
else
|
||||
luci.sys.call("rm -rf /tmp/clash_last_version 2>/dev/null && bash /usr/share/openclash/clash_version.sh >/dev/null 2>&1")
|
||||
luci.sys.call("bash /usr/share/openclash/openclash_core.sh 'Meta' >/dev/null 2>&1 &")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function download_rule()
|
||||
local filename = luci.http.formvalue("filename")
|
||||
local state = luci.sys.call(string.format('/usr/share/openclash/openclash_download_rule_list.sh "%s" >/dev/null 2>&1',filename))
|
||||
return state
|
||||
end
|
||||
|
||||
function action_flush_dns_cache()
|
||||
local state = 0
|
||||
if is_running() then
|
||||
@@ -368,8 +335,8 @@ function action_flush_dns_cache()
|
||||
local dase = dase() or ""
|
||||
local cn_port = cn_port()
|
||||
if not daip or not cn_port then return end
|
||||
fake_ip_state = luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XPOST http://"%s":"%s"/cache/fakeip/flush', dase, daip, cn_port))
|
||||
dns_state = luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XPOST http://"%s":"%s"/cache/dns/flush', dase, daip, cn_port))
|
||||
fake_ip_state = luci.sys.exec(string.format('curl -sL -m 3 --retry 2 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XPOST http://"%s":"%s"/cache/fakeip/flush', dase, daip, cn_port))
|
||||
dns_state = luci.sys.exec(string.format('curl -sL -m 3 --retry 2-H "Content-Type: application/json" -H "Authorization: Bearer %s" -XPOST http://"%s":"%s"/cache/dns/flush', dase, daip, cn_port))
|
||||
end
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({
|
||||
@@ -384,7 +351,7 @@ function action_flush_smart_cache()
|
||||
local dase = dase() or ""
|
||||
local cn_port = cn_port()
|
||||
if not daip or not cn_port then return end
|
||||
flush_state = luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XPOST http://"%s":"%s"/cache/smart/flush', dase, daip, cn_port))
|
||||
flush_state = luci.sys.exec(string.format('curl -sL -m 3 --retry 2 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XPOST http://"%s":"%s"/cache/smart/flush', dase, daip, cn_port))
|
||||
end
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({
|
||||
@@ -393,13 +360,8 @@ function action_flush_smart_cache()
|
||||
end
|
||||
|
||||
function action_update_config()
|
||||
-- filename or config_file is basename
|
||||
-- filename is basename
|
||||
local filename = luci.http.formvalue("filename")
|
||||
local config_file = luci.http.formvalue("config_file")
|
||||
|
||||
if not filename and config_file then
|
||||
filename = config_file
|
||||
end
|
||||
|
||||
luci.http.prepare_content("application/json")
|
||||
|
||||
@@ -450,195 +412,9 @@ end
|
||||
function action_one_key_update()
|
||||
local cdn_url = luci.http.formvalue("url")
|
||||
if cdn_url then
|
||||
return luci.sys.call(string.format("rm -rf /tmp/*_last_version 2>/dev/null && bash /usr/share/openclash/openclash_update.sh 'one_key_update' '%s' >/dev/null 2>&1 &", cdn_url))
|
||||
return luci.sys.call(string.format("bash /usr/share/openclash/openclash_update.sh 'one_key_update' '%s' >/dev/null 2>&1 &", cdn_url))
|
||||
else
|
||||
return luci.sys.call("rm -rf /tmp/*_last_version 2>/dev/null && bash /usr/share/openclash/openclash_update.sh 'one_key_update' >/dev/null 2>&1 &")
|
||||
end
|
||||
end
|
||||
|
||||
local function dler_login_info_save()
|
||||
uci:set("openclash", "config", "dler_email", luci.http.formvalue("email"))
|
||||
uci:set("openclash", "config", "dler_passwd", luci.http.formvalue("passwd"))
|
||||
uci:set("openclash", "config", "dler_checkin", luci.http.formvalue("checkin"))
|
||||
uci:set("openclash", "config", "dler_checkin_interval", luci.http.formvalue("interval"))
|
||||
if tonumber(luci.http.formvalue("multiple")) > 100 then
|
||||
uci:set("openclash", "config", "dler_checkin_multiple", "100")
|
||||
elseif tonumber(luci.http.formvalue("multiple")) < 1 or not tonumber(luci.http.formvalue("multiple")) then
|
||||
uci:set("openclash", "config", "dler_checkin_multiple", "1")
|
||||
else
|
||||
uci:set("openclash", "config", "dler_checkin_multiple", luci.http.formvalue("multiple"))
|
||||
end
|
||||
uci:commit("openclash")
|
||||
return "success"
|
||||
end
|
||||
|
||||
local function dler_login()
|
||||
local info, token, get_sub, sub_info, sub_key, sub_match, sub_convert, sid
|
||||
local sub_path = "/tmp/dler_sub"
|
||||
local email = fs.uci_get_config("config", "dler_email")
|
||||
local passwd = fs.uci_get_config("config", "dler_passwd")
|
||||
if email and passwd then
|
||||
info = luci.sys.exec(string.format("curl -sL -H 'Content-Type: application/json' -d '{\"email\":\"%s\", \"passwd\":\"%s\", \"token_expire\":\"365\" }' -X POST https://dler.cloud/api/v1/login", email, passwd))
|
||||
if info then
|
||||
info = json.parse(info)
|
||||
end
|
||||
if info and info.ret == 200 then
|
||||
token = info.data.token
|
||||
uci:set("openclash", "config", "dler_token", token)
|
||||
uci:commit("openclash")
|
||||
get_sub = string.format("curl -sL -H 'Content-Type: application/json' -d '{\"access_token\":\"%s\"}' -X POST https://dler.cloud/api/v1/managed/clash -o %s", token, sub_path)
|
||||
luci.sys.exec(get_sub)
|
||||
sub_info = fs.readfile(sub_path)
|
||||
if sub_info then
|
||||
sub_info = json.parse(sub_info)
|
||||
end
|
||||
if sub_info and sub_info.ret == 200 then
|
||||
sub_key = {"smart","ss","vmess","trojan"}
|
||||
for _,v in ipairs(sub_key) do
|
||||
while true do
|
||||
sub_match = false
|
||||
sub_convert = false
|
||||
uci:foreach("openclash", "config_subscribe",
|
||||
function(s)
|
||||
if s.name == "Dler Cloud - " .. v and s.address == sub_info[v] then
|
||||
sub_match = true
|
||||
end
|
||||
if s.name == "Dler Cloud - " .. v and s.address ~= sub_info[v] then
|
||||
sub_convert = true
|
||||
sid = s['.name']
|
||||
end
|
||||
end)
|
||||
if sub_match then break end
|
||||
if sub_convert then
|
||||
uci:set("openclash", sid, "address", sub_info[v])
|
||||
else
|
||||
sid = uci:add("openclash", "config_subscribe")
|
||||
uci:set("openclash", sid, "name", "Dler Cloud - " .. v)
|
||||
uci:set("openclash", sid, "address", sub_info[v])
|
||||
end
|
||||
uci:commit("openclash")
|
||||
break
|
||||
end
|
||||
luci.sys.exec(string.format('curl -sL -m 3 --retry 2 --user-agent "clash" "%s" -o "/etc/openclash/config/Dler Cloud - %s.yaml" >/dev/null 2>&1', sub_info[v], v))
|
||||
end
|
||||
end
|
||||
return info.ret
|
||||
else
|
||||
uci:delete("openclash", "config", "dler_token")
|
||||
uci:commit("openclash")
|
||||
fs.unlink(sub_path)
|
||||
fs.unlink("/tmp/dler_checkin")
|
||||
fs.unlink("/tmp/dler_info")
|
||||
if info and info.msg then
|
||||
return info.msg
|
||||
else
|
||||
return "login faild"
|
||||
end
|
||||
end
|
||||
else
|
||||
uci:delete("openclash", "config", "dler_token")
|
||||
uci:commit("openclash")
|
||||
fs.unlink(sub_path)
|
||||
fs.unlink("/tmp/dler_checkin")
|
||||
fs.unlink("/tmp/dler_info")
|
||||
return "email or passwd is wrong"
|
||||
end
|
||||
end
|
||||
|
||||
local function dler_logout()
|
||||
local info, token
|
||||
local token = fs.uci_get_config("config", "dler_token")
|
||||
if token then
|
||||
info = luci.sys.exec(string.format("curl -sL -H 'Content-Type: application/json' -d '{\"access_token\":\"%s\"}' -X POST https://dler.cloud/api/v1/logout", token))
|
||||
if info then
|
||||
info = json.parse(info)
|
||||
end
|
||||
if info and info.ret == 200 then
|
||||
uci:delete("openclash", "config", "dler_token")
|
||||
uci:delete("openclash", "config", "dler_checkin")
|
||||
uci:delete("openclash", "config", "dler_checkin_interval")
|
||||
uci:delete("openclash", "config", "dler_checkin_multiple")
|
||||
uci:commit("openclash")
|
||||
fs.unlink("/tmp/dler_sub")
|
||||
fs.unlink("/tmp/dler_checkin")
|
||||
fs.unlink("/tmp/dler_info")
|
||||
return info.ret
|
||||
else
|
||||
if info and info.msg then
|
||||
return info.msg
|
||||
else
|
||||
return "logout faild"
|
||||
end
|
||||
end
|
||||
else
|
||||
return "logout faild"
|
||||
end
|
||||
end
|
||||
|
||||
local function dler_info()
|
||||
local info, path, get_info
|
||||
local token = fs.uci_get_config("config", "dler_token")
|
||||
path = "/tmp/dler_info"
|
||||
if token then
|
||||
get_info = string.format("curl -sL -H 'Content-Type: application/json' -d '{\"access_token\":\"%s\"}' -X POST https://dler.cloud/api/v1/information -o %s", token, path)
|
||||
if not fs.access(path) then
|
||||
luci.sys.exec(get_info)
|
||||
else
|
||||
if fs.readfile(path) == "" or not fs.readfile(path) then
|
||||
luci.sys.exec(get_info)
|
||||
else
|
||||
if (os.time() - fs.mtime(path) > 900) then
|
||||
luci.sys.exec(get_info)
|
||||
end
|
||||
end
|
||||
end
|
||||
info = fs.readfile(path)
|
||||
if info then
|
||||
info = json.parse(info)
|
||||
end
|
||||
if info and info.ret == 200 and info.data then
|
||||
return info.data
|
||||
elseif info and info.msg and info.msg ~= "api error, ignore" then
|
||||
luci.sys.exec(string.format("echo -e %s Dler Cloud Account Login Failed, The Error Info is【%s】 >> /tmp/openclash.log", os.date("%Y-%m-%d %H:%M:%S"), info.msg))
|
||||
info.msg = "api error, ignore"
|
||||
fs.writefile(path, json.stringify(info))
|
||||
elseif info and info.msg and info.msg == "api error, ignore" then
|
||||
return "error"
|
||||
else
|
||||
fs.unlink(path)
|
||||
luci.sys.exec(string.format("echo -e %s Dler Cloud Account Login Failed! Please Check And Try Again... >> /tmp/openclash.log", os.date("%Y-%m-%d %H:%M:%S")))
|
||||
end
|
||||
return "error"
|
||||
else
|
||||
return "error"
|
||||
end
|
||||
end
|
||||
|
||||
local function dler_checkin()
|
||||
local info
|
||||
local path = "/tmp/dler_checkin"
|
||||
local token = fs.uci_get_config("config", "dler_token")
|
||||
local multiple = fs.uci_get_config("config", "dler_checkin_multiple") or 1
|
||||
if token then
|
||||
info = luci.sys.exec(string.format("curl -sL -H 'Content-Type: application/json' -d '{\"access_token\":\"%s\", \"multiple\":\"%s\"}' -X POST https://dler.cloud/api/v1/checkin", token, multiple))
|
||||
if info then
|
||||
info = json.parse(info)
|
||||
end
|
||||
if info and info.ret == 200 then
|
||||
fs.unlink("/tmp/dler_info")
|
||||
fs.writefile(path, info)
|
||||
luci.sys.exec(string.format("echo -e %s Dler Cloud Checkin Successful, Result:【%s】 >> /tmp/openclash.log", os.date("%Y-%m-%d %H:%M:%S"), info.data.checkin))
|
||||
return info
|
||||
else
|
||||
if info and info.msg then
|
||||
luci.sys.exec(string.format("echo -e %s Dler Cloud Checkin Failed, Result:【%s】 >> /tmp/openclash.log", os.date("%Y-%m-%d %H:%M:%S"), info.msg))
|
||||
else
|
||||
luci.sys.exec(string.format("echo -e %s Dler Cloud Checkin Failed! Please Check And Try Again... >> /tmp/openclash.log",os.date("%Y-%m-%d %H:%M:%S")))
|
||||
end
|
||||
return info
|
||||
end
|
||||
else
|
||||
return "error"
|
||||
return luci.sys.call("bash /usr/share/openclash/openclash_update.sh 'one_key_update' >/dev/null 2>&1 &")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -761,10 +537,10 @@ function fetch_sub_info(sub_url, sub_ua)
|
||||
local info, upload, download, total, day_expire, http_code
|
||||
local used, expire, day_left, percent, surplus
|
||||
|
||||
info = luci.sys.exec(string.format("curl -sLI -X GET -m 10 -w 'http_code=%%{http_code}' -H 'User-Agent: %s' '%s'", sub_ua, sub_url))
|
||||
info = luci.sys.exec(string.format("curl -sLI -X GET -m 10 --retry 2 -w 'http_code=%%{http_code}' -H 'User-Agent: %s' '%s'", sub_ua, sub_url))
|
||||
local http_match = string.match(info, "http_code=(%d+)")
|
||||
if not info or not http_match or tonumber(http_match) ~= 200 then
|
||||
info = luci.sys.exec(string.format("curl -sLI -X GET -m 10 -w 'http_code=%%{http_code}' -H 'User-Agent: Quantumultx' '%s'", sub_url))
|
||||
info = luci.sys.exec(string.format("curl -sLI -X GET -m 10 --retry 2 -w 'http_code=%%{http_code}' -H 'User-Agent: Quantumultx' '%s'", sub_url))
|
||||
http_match = string.match(info, "http_code=(%d+)")
|
||||
end
|
||||
|
||||
@@ -972,7 +748,7 @@ function get_sub_url(filename)
|
||||
end
|
||||
|
||||
function sub_info_get()
|
||||
local sub_ua, filename, sub_info
|
||||
local sub_ua, filename, sub_info, url_result
|
||||
local providers_data = {}
|
||||
|
||||
filename = luci.http.formvalue("filename")
|
||||
@@ -988,7 +764,7 @@ function sub_info_get()
|
||||
)
|
||||
|
||||
if filename and not is_start() then
|
||||
local url_result = get_sub_url(filename)
|
||||
url_result = get_sub_url(filename)
|
||||
|
||||
if not url_result then
|
||||
sub_info = "No Sub Info Found"
|
||||
@@ -1021,7 +797,8 @@ function sub_info_get()
|
||||
luci.http.write_json({
|
||||
sub_info = sub_info,
|
||||
providers = providers_data,
|
||||
get_time = os.time()
|
||||
get_time = os.time(),
|
||||
url_result = url_result
|
||||
})
|
||||
end
|
||||
|
||||
@@ -1032,7 +809,7 @@ function action_rule_mode()
|
||||
local dase = dase() or ""
|
||||
local cn_port = cn_port()
|
||||
if not daip or not cn_port then return end
|
||||
info = json.parse(luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XGET http://"%s":"%s"/configs', dase, daip, cn_port)))
|
||||
info = json.parse(luci.sys.exec(string.format('curl -sL -m 3 --retry 2 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XGET http://"%s":"%s"/configs', dase, daip, cn_port)))
|
||||
if info then
|
||||
mode = info["mode"]
|
||||
else
|
||||
@@ -1061,7 +838,7 @@ function action_switch_rule_mode()
|
||||
|
||||
if is_running() then
|
||||
if not daip or not cn_port then luci.http.status(500, "Switch Faild") return end
|
||||
info = luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XPATCH http://"%s":"%s"/configs -d \'{\"mode\": \"%s\"}\'', dase, daip, cn_port, mode))
|
||||
info = luci.sys.exec(string.format('curl -sL -m 3 --retry 2 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XPATCH http://"%s":"%s"/configs -d \'{\"mode\": \"%s\"}\'', dase, daip, cn_port, mode))
|
||||
if info ~= "" then
|
||||
luci.http.status(500, "Switch Faild")
|
||||
end
|
||||
@@ -1111,7 +888,7 @@ function action_log_level()
|
||||
local dase = dase() or ""
|
||||
local cn_port = cn_port()
|
||||
if not daip or not cn_port then return end
|
||||
info = json.parse(luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XGET http://"%s":"%s"/configs', dase, daip, cn_port)))
|
||||
info = json.parse(luci.sys.exec(string.format('curl -sL -m 3 --retry 2 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XGET http://"%s":"%s"/configs', dase, daip, cn_port)))
|
||||
if info then
|
||||
level = info["log-level"]
|
||||
else
|
||||
@@ -1126,27 +903,6 @@ function action_log_level()
|
||||
})
|
||||
end
|
||||
|
||||
function action_switch_log()
|
||||
local level, info
|
||||
if is_running() then
|
||||
local daip = daip()
|
||||
local dase = dase() or ""
|
||||
local cn_port = cn_port()
|
||||
level = luci.http.formvalue("log_level")
|
||||
if not daip or not cn_port or not level then luci.http.status(500, "Switch Faild") return end
|
||||
info = luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XPATCH http://"%s":"%s"/configs -d \'{\"log-level\": \"%s\"}\'', dase, daip, cn_port, level))
|
||||
if info ~= "" then
|
||||
luci.http.status(500, "Switch Faild")
|
||||
end
|
||||
else
|
||||
luci.http.status(500, "Switch Faild")
|
||||
end
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({
|
||||
info = info;
|
||||
})
|
||||
end
|
||||
|
||||
local function s(e)
|
||||
local t=0
|
||||
local a={' B/S',' KB/S',' MB/S',' GB/S',' TB/S',' PB/S'}
|
||||
@@ -1208,8 +964,8 @@ function action_toolbar_show()
|
||||
local cn_port = cn_port()
|
||||
if not daip or not cn_port then return end
|
||||
|
||||
traffic = json.parse(luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XGET http://"%s":"%s"/traffic', dase, daip, cn_port)))
|
||||
connections = json.parse(luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XGET http://"%s":"%s"/connections', dase, daip, cn_port)))
|
||||
traffic = json.parse(luci.sys.exec(string.format('curl -sL -m 3 --retry 2 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XGET http://"%s":"%s"/traffic', dase, daip, cn_port)))
|
||||
connections = json.parse(luci.sys.exec(string.format('curl -sL -m 3 --retry 2 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XGET http://"%s":"%s"/connections', dase, daip, cn_port)))
|
||||
|
||||
if traffic and connections and connections.connections then
|
||||
connection = #(connections.connections)
|
||||
@@ -1283,41 +1039,6 @@ function action_save_corever_branch()
|
||||
})
|
||||
end
|
||||
|
||||
function action_dler_login_info_save()
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({
|
||||
dler_login_info_save = dler_login_info_save();
|
||||
})
|
||||
end
|
||||
|
||||
function action_dler_info()
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({
|
||||
dler_info = dler_info();
|
||||
})
|
||||
end
|
||||
|
||||
function action_dler_checkin()
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({
|
||||
dler_checkin = dler_checkin();
|
||||
})
|
||||
end
|
||||
|
||||
function action_dler_logout()
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({
|
||||
dler_logout = dler_logout();
|
||||
})
|
||||
end
|
||||
|
||||
function action_dler_login()
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({
|
||||
dler_login = dler_login();
|
||||
})
|
||||
end
|
||||
|
||||
function action_one_key_update_check()
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({
|
||||
@@ -1366,7 +1087,7 @@ function action_switch_dashboard()
|
||||
local switch_name = luci.http.formvalue("name")
|
||||
local switch_type = luci.http.formvalue("type")
|
||||
local state = luci.sys.call(string.format('/usr/share/openclash/openclash_download_dashboard.sh "%s" "%s" >/dev/null 2>&1', switch_name, switch_type))
|
||||
if switch_name == "Dashboard" and tonumber(state) == 1 then
|
||||
if switch_name == "Dashboard" and tonumber(state) == 0 then
|
||||
if switch_type == "Official" then
|
||||
uci:set("openclash", "config", "dashboard_type", "Official")
|
||||
uci:commit("openclash")
|
||||
@@ -1374,7 +1095,7 @@ function action_switch_dashboard()
|
||||
uci:set("openclash", "config", "dashboard_type", "Meta")
|
||||
uci:commit("openclash")
|
||||
end
|
||||
elseif switch_name == "Yacd" and tonumber(state) == 1 then
|
||||
elseif switch_name == "Yacd" and tonumber(state) == 0 then
|
||||
if switch_type == "Official" then
|
||||
uci:set("openclash", "config", "yacd_type", "Official")
|
||||
uci:commit("openclash")
|
||||
@@ -1492,10 +1213,14 @@ end
|
||||
|
||||
function action_get_last_version()
|
||||
if not process_status("/usr/share/openclash/clash_version.sh") then
|
||||
luci.sys.call("bash /usr/share/openclash/clash_version.sh &")
|
||||
if tonumber(os.time() - (fs.mtime("/tmp/clash_last_version") or 0)) > 1800 then
|
||||
luci.sys.call("bash /usr/share/openclash/clash_version.sh &")
|
||||
end
|
||||
end
|
||||
if not process_status("/usr/share/openclash/openclash_version.sh") then
|
||||
luci.sys.call("bash /usr/share/openclash/openclash_version.sh &")
|
||||
if tonumber(os.time() - (fs.mtime("/tmp/openclash_last_version") or 0)) > 1800 then
|
||||
luci.sys.call("bash /usr/share/openclash/openclash_version.sh &")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1570,6 +1295,7 @@ function action_refresh_log()
|
||||
luci.http.prepare_content("application/json")
|
||||
local logfile = "/tmp/openclash.log"
|
||||
local log_len = tonumber(luci.http.formvalue("log_len")) or 0
|
||||
local core_refresh = luci.http.formvalue("core_refresh") == "true"
|
||||
|
||||
if not fs.access(logfile) then
|
||||
luci.http.write_json({
|
||||
@@ -1594,54 +1320,54 @@ function action_refresh_log()
|
||||
end
|
||||
|
||||
local exclude_pattern = "UDP%-Receive%-Buffer%-Size|^Sec%-Fetch%-Mode|^User%-Agent|^Access%-Control|^Accept|^Origin|^Referer|^Connection|^Pragma|^Cache%-"
|
||||
local core_pattern = " DBG | INF |level=| WRN | ERR | FTL "
|
||||
local core_pattern = "level=|^time="
|
||||
local limit = 1000
|
||||
local start_line = (log_len > 0 and total_lines > log_len) and (log_len + 1) or 1
|
||||
local core_cmd, oc_cmd, core_raw, oc_raw
|
||||
local core_logs = {}
|
||||
local oc_logs = {}
|
||||
|
||||
local core_cmd = string.format(
|
||||
core_cmd = string.format(
|
||||
"tail -n +%d '%s' | grep -v -E '%s' | grep -E '%s' | tail -n %d",
|
||||
start_line, logfile, exclude_pattern, core_pattern, limit
|
||||
)
|
||||
local core_raw = luci.sys.exec(core_cmd)
|
||||
|
||||
local oc_cmd = string.format(
|
||||
oc_cmd = string.format(
|
||||
"tail -n +%d '%s' | grep -v -E '%s' | grep -v -E '%s' | tail -n %d",
|
||||
start_line, logfile, exclude_pattern, core_pattern, limit
|
||||
)
|
||||
local oc_raw = luci.sys.exec(oc_cmd)
|
||||
|
||||
local core_log = ""
|
||||
if core_refresh then
|
||||
core_raw = luci.sys.exec(core_cmd)
|
||||
end
|
||||
|
||||
oc_raw = luci.sys.exec(oc_cmd)
|
||||
|
||||
if core_raw and core_raw ~= "" then
|
||||
local core_logs = {}
|
||||
for line in core_raw:gmatch("[^\n]+") do
|
||||
local line_trans = line
|
||||
if string.match(string.sub(line, 0, 8), "%d%d:%d%d:%d%d") then
|
||||
line_trans = '"'..os.date("%Y-%m-%d", os.time()).. " "..os.date("%H:%M:%S", tonumber(string.sub(line, 0, 8)))..'"'..string.sub(line, 9, -1)
|
||||
end
|
||||
table.insert(core_logs, line_trans)
|
||||
end
|
||||
if #core_logs > 0 then
|
||||
core_log = table.concat(core_logs, "\n")
|
||||
table.insert(core_logs, line)
|
||||
end
|
||||
end
|
||||
|
||||
local oc_log = ""
|
||||
if oc_raw and oc_raw ~= "" then
|
||||
local oc_logs = {}
|
||||
for line in oc_raw:gmatch("[^\n]+") do
|
||||
local line_trans
|
||||
if not string.find(line, "【") or not string.find(line, "】") then
|
||||
line_trans = trans_line_nolabel(line)
|
||||
else
|
||||
line_trans = trans_line(line)
|
||||
if not string.match(string.sub(line, 1, 19), "%d%d%d%d%-%d%d%-%d%d %d%d:%d%d:%d%d") then
|
||||
line = os.date("%Y-%m-%d %H:%M:%S") .. ' [Fatal] ' .. line
|
||||
end
|
||||
table.insert(oc_logs, line_trans)
|
||||
end
|
||||
if #oc_logs > 0 then
|
||||
oc_log = table.concat(oc_logs, "\n")
|
||||
table.insert(oc_logs, trans_line(line))
|
||||
end
|
||||
end
|
||||
|
||||
if #core_logs > limit then
|
||||
core_logs = {table.unpack(core_logs, #core_logs - limit + 1)}
|
||||
end
|
||||
if #oc_logs > limit then
|
||||
oc_logs = {table.unpack(oc_logs, #oc_logs - limit + 1)}
|
||||
end
|
||||
|
||||
local core_log = #core_logs > 0 and table.concat(core_logs, "\n") or ""
|
||||
local oc_log = #oc_logs > 0 and table.concat(oc_logs, "\n") or ""
|
||||
|
||||
luci.http.write_json({
|
||||
len = total_lines,
|
||||
update = true,
|
||||
@@ -1872,8 +1598,6 @@ function rename_file()
|
||||
local new_file_path = file_path .. new_file_name
|
||||
local old_run_file_path = "/etc/openclash/" .. old_file_name
|
||||
local new_run_file_path = "/etc/openclash/" .. new_file_name
|
||||
local old_backup_file_path = "/etc/openclash/backup/" .. old_file_name
|
||||
local new_backup_file_path = "/etc/openclash/backup/" .. new_file_name
|
||||
if fs.rename(old_file_path, new_file_path) then
|
||||
if file_path == "/etc/openclash/config/" then
|
||||
if fs.uci_get_config("config", "config_path") == old_file_path then
|
||||
@@ -1884,10 +1608,6 @@ function rename_file()
|
||||
fs.rename(old_run_file_path, new_run_file_path)
|
||||
end
|
||||
|
||||
if fs.isfile(old_backup_file_path) then
|
||||
fs.rename(old_backup_file_path, new_backup_file_path)
|
||||
end
|
||||
|
||||
uci:foreach("openclash", "config_subscribe",
|
||||
function(s)
|
||||
if s.name == fs.filename(old_file_name) and fs.filename(new_file_name) ~= new_file_name then
|
||||
@@ -1895,13 +1615,6 @@ function rename_file()
|
||||
end
|
||||
end)
|
||||
|
||||
uci:foreach("openclash", "other_rules",
|
||||
function(s)
|
||||
if s.config == old_file_name and fs.filename(new_file_name) ~= new_file_name then
|
||||
uci:set("openclash", s[".name"], "config", new_file_name)
|
||||
end
|
||||
end)
|
||||
|
||||
uci:foreach("openclash", "groups",
|
||||
function(s)
|
||||
if s.config == old_file_name and fs.filename(new_file_name) ~= new_file_name then
|
||||
@@ -1916,13 +1629,6 @@ function rename_file()
|
||||
end
|
||||
end)
|
||||
|
||||
uci:foreach("openclash", "rule_provider_config",
|
||||
function(s)
|
||||
if s.config == old_file_name and fs.filename(new_file_name) ~= new_file_name then
|
||||
uci:set("openclash", s[".name"], "config", new_file_name)
|
||||
end
|
||||
end)
|
||||
|
||||
uci:foreach("openclash", "servers",
|
||||
function(s)
|
||||
if s.config == old_file_name and fs.filename(new_file_name) ~= new_file_name then
|
||||
@@ -1930,20 +1636,6 @@ function rename_file()
|
||||
end
|
||||
end)
|
||||
|
||||
uci:foreach("openclash", "game_config",
|
||||
function(s)
|
||||
if s.config == old_file_name and fs.filename(new_file_name) ~= new_file_name then
|
||||
uci:set("openclash", s[".name"], "config", new_file_name)
|
||||
end
|
||||
end)
|
||||
|
||||
uci:foreach("openclash", "rule_providers",
|
||||
function(s)
|
||||
if s.config == old_file_name and fs.filename(new_file_name) ~= new_file_name then
|
||||
uci:set("openclash", s[".name"], "config", new_file_name)
|
||||
end
|
||||
end)
|
||||
|
||||
uci:commit("openclash")
|
||||
end
|
||||
luci.http.status(200, "Rename File Successful")
|
||||
@@ -1956,19 +1648,13 @@ end
|
||||
function manual_stream_unlock_test()
|
||||
local type = luci.http.formvalue("type")
|
||||
local cmd = string.format('/usr/share/openclash/openclash_streaming_unlock.lua "%s"', type)
|
||||
local line_trans
|
||||
luci.http.prepare_content("text/plain; charset=utf-8")
|
||||
local util = io.popen(cmd)
|
||||
if util and util ~= "" then
|
||||
while true do
|
||||
local ln = util:read("*l")
|
||||
if ln then
|
||||
if not string.find (ln, "【") or not string.find (ln, "】") then
|
||||
line_trans = trans_line_nolabel(ln)
|
||||
else
|
||||
line_trans = trans_line(ln)
|
||||
end
|
||||
luci.http.write(line_trans)
|
||||
luci.http.write(trans_line(ln))
|
||||
luci.http.write("\n")
|
||||
end
|
||||
if not process_status("openclash_streaming_unlock.lua "..type) or not process_status("openclash_streaming_unlock.lua ") then
|
||||
@@ -1984,19 +1670,13 @@ end
|
||||
function all_proxies_stream_test()
|
||||
local type = luci.http.formvalue("type")
|
||||
local cmd = string.format('/usr/share/openclash/openclash_streaming_unlock.lua "%s" "%s"', type, "all")
|
||||
local line_trans
|
||||
luci.http.prepare_content("text/plain; charset=utf-8")
|
||||
local util = io.popen(cmd)
|
||||
if util and util ~= "" then
|
||||
while true do
|
||||
local ln = util:read("*l")
|
||||
if ln then
|
||||
if not string.find (ln, "【") or not string.find (ln, "】") then
|
||||
line_trans = trans_line_nolabel(ln)
|
||||
else
|
||||
line_trans = trans_line(ln)
|
||||
end
|
||||
luci.http.write(line_trans)
|
||||
luci.http.write(trans_line(ln))
|
||||
luci.http.write("\n")
|
||||
end
|
||||
if not process_status("openclash_streaming_unlock.lua "..type) or not process_status("openclash_streaming_unlock.lua ") then
|
||||
@@ -2009,95 +1689,70 @@ function all_proxies_stream_test()
|
||||
luci.http.status(500, "Something Wrong While Testing...")
|
||||
end
|
||||
|
||||
function trans_line_nolabel(data)
|
||||
if data == nil or data == "" then
|
||||
return ""
|
||||
end
|
||||
|
||||
local line_trans = ""
|
||||
if string.len(data) >= 19 and string.match(string.sub(data, 0, 19), "%d%d%d%d%-%d%d%-%d%d %d%d:%d%d:%d%d") then
|
||||
line_trans = string.sub(data, 0, 20)..luci.i18n.translate(string.sub(data, 21, -1))
|
||||
else
|
||||
line_trans = luci.i18n.translate(data)
|
||||
end
|
||||
return line_trans
|
||||
end
|
||||
|
||||
function trans_line(data)
|
||||
if data == nil or data == "" then
|
||||
return ""
|
||||
end
|
||||
|
||||
local no_trans = {}
|
||||
local line_trans = ""
|
||||
local a = string.find(data, "【")
|
||||
|
||||
if not a then
|
||||
if string.len(data) >= 19 and string.match(string.sub(data, 0, 19), "%d%d%d%d%-%d%d%-%d%d %d%d:%d%d:%d%d") then
|
||||
return string.sub(data, 0, 20) .. luci.i18n.translate(string.sub(data, 21, -1))
|
||||
else
|
||||
return luci.i18n.translate(data)
|
||||
local has_timestamp = string.len(data) >= 19 and string.match(string.sub(data, 1, 19), "%d%d%d%d%-%d%d%-%d%d %d%d:%d%d:%d%d")
|
||||
local time_part = ""
|
||||
local level_part = ""
|
||||
local content_start = has_timestamp and 21 or 1
|
||||
|
||||
if has_timestamp then
|
||||
time_part = string.sub(data, 1, 20)
|
||||
local level_start, level_end, level_content = string.find(data, "%[([^%]]+)%]", 21)
|
||||
if level_start and level_end and level_start == 21 then
|
||||
level_part = "[" .. luci.i18n.translate(level_content) .. "] "
|
||||
content_start = level_end + 2
|
||||
end
|
||||
end
|
||||
|
||||
local b_pos = string.find(data, "】")
|
||||
if not b_pos then
|
||||
return luci.i18n.translate(data)
|
||||
end
|
||||
local segments = {}
|
||||
local last_pos = content_start
|
||||
local pos = string.find(data, "【", content_start)
|
||||
|
||||
local b = b_pos + 2
|
||||
local c = 21
|
||||
local d = 0
|
||||
local v
|
||||
local x
|
||||
while pos do
|
||||
if pos > last_pos then
|
||||
table.insert(segments, {
|
||||
type = "trans",
|
||||
text = string.sub(data, last_pos, pos - 1)
|
||||
})
|
||||
end
|
||||
|
||||
while true do
|
||||
table.insert(no_trans, a)
|
||||
table.insert(no_trans, b)
|
||||
|
||||
local next_a = string.find(data, "【", b+1)
|
||||
local next_b = string.find(data, "】", b+1)
|
||||
|
||||
if next_a and next_b then
|
||||
a = next_a
|
||||
b = next_b + 2
|
||||
else
|
||||
local close_pos = string.find(data, "】", pos + 1)
|
||||
if not close_pos then
|
||||
table.insert(segments, {
|
||||
type = "trans",
|
||||
text = string.sub(data, pos, -1)
|
||||
})
|
||||
break
|
||||
end
|
||||
|
||||
table.insert(segments, {
|
||||
type = "no_trans",
|
||||
text = string.sub(data, pos, close_pos + 2)
|
||||
})
|
||||
|
||||
last_pos = close_pos + 3
|
||||
pos = string.find(data, "【", last_pos)
|
||||
end
|
||||
|
||||
if #no_trans % 2 ~= 0 then
|
||||
table.remove(no_trans)
|
||||
if last_pos <= string.len(data) then
|
||||
table.insert(segments, {
|
||||
type = "trans",
|
||||
text = string.sub(data, last_pos, -1)
|
||||
})
|
||||
end
|
||||
|
||||
for k = 1, #no_trans, 2 do
|
||||
x = no_trans[k]
|
||||
v = no_trans[k+1]
|
||||
|
||||
if x and v then
|
||||
if x <= 21 or not string.match(string.sub(data, 0, 19), "%d%d%d%d%-%d%d%-%d%d %d%d:%d%d:%d%d") then
|
||||
line_trans = line_trans .. luci.i18n.translate(string.sub(data, d, x - 1)) .. string.sub(data, x, v)
|
||||
d = v + 1
|
||||
elseif v <= string.len(data) then
|
||||
line_trans = line_trans .. luci.i18n.translate(string.sub(data, c, x - 1)) .. string.sub(data, x, v)
|
||||
end
|
||||
c = v + 1
|
||||
end
|
||||
end
|
||||
|
||||
if c > string.len(data) then
|
||||
if d == 0 then
|
||||
if string.match(string.sub(data, 0, 19), "%d%d%d%d%-%d%d%-%d%d %d%d:%d%d:%d%d") then
|
||||
line_trans = string.sub(data, 0, 20) .. line_trans
|
||||
end
|
||||
end
|
||||
else
|
||||
if d == 0 then
|
||||
if string.match(string.sub(data, 0, 19), "%d%d%d%d%-%d%d%-%d%d %d%d:%d%d:%d%d") then
|
||||
line_trans = string.sub(data, 0, 20) .. line_trans .. luci.i18n.translate(string.sub(data, c, -1))
|
||||
end
|
||||
line_trans = time_part .. level_part
|
||||
for _, seg in ipairs(segments) do
|
||||
if seg.type == "trans" then
|
||||
line_trans = line_trans .. luci.i18n.translate(seg.text)
|
||||
else
|
||||
line_trans = line_trans .. luci.i18n.translate(string.sub(data, c, -1))
|
||||
line_trans = line_trans .. seg.text
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2364,7 +2019,7 @@ function action_myip_check()
|
||||
|
||||
if result.ipify and result.ipify.ip then
|
||||
local geo_cmd = string.format(
|
||||
'curl -sL -m 5 -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" "https://api-ipv4.ip.sb/geoip/%s" 2>/dev/null',
|
||||
'curl -sL -m 5 --retry 2 -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" "https://api-ipv4.ip.sb/geoip/%s" 2>/dev/null',
|
||||
result.ipify.ip
|
||||
)
|
||||
local geo_data = luci.sys.exec(geo_cmd)
|
||||
@@ -2417,7 +2072,7 @@ function action_website_check()
|
||||
end
|
||||
|
||||
local cmd = string.format(
|
||||
'curl -sL -m 5 --connect-timeout 3 -w "%%{http_code},%%{time_total},%%{time_connect},%%{time_appconnect}" "%s" -o /dev/null 2>/dev/null',
|
||||
'curl -sL -m 5 --connect-timeout 3 --retry 2 -w "%%{http_code},%%{time_total},%%{time_connect},%%{time_appconnect}" "%s" -o /dev/null 2>/dev/null',
|
||||
test_url
|
||||
)
|
||||
|
||||
@@ -2606,7 +2261,7 @@ function action_switch_oc_setting()
|
||||
return false
|
||||
end
|
||||
|
||||
local reload_result = luci.sys.exec(string.format('curl -sL -m 5 --connect-timeout 2 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XPUT http://"%s":"%s"/configs?force=true -d \'{"path":"%s"}\' 2>&1', dase, daip, cn_port, runtime_config_path))
|
||||
local reload_result = luci.sys.exec(string.format('curl -sL -m 5 --connect-timeout 2 --retry 2 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XPUT http://"%s":"%s"/configs?force=true -d \'{"path":"%s"}\' 2>&1', dase, daip, cn_port, runtime_config_path))
|
||||
|
||||
if reload_result ~= "" then
|
||||
luci.http.status(500, "Switch Failed")
|
||||
@@ -2839,7 +2494,7 @@ function action_generate_pac()
|
||||
local mixed_port = fs.uci_get_config("config", "mixed_port") or "7893"
|
||||
|
||||
if not proxy_ip then
|
||||
result.error = "Unable to get proxy IP"
|
||||
result.error = luci.i18n.translate("Unable to get proxy IP")
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(result)
|
||||
return
|
||||
@@ -2959,7 +2614,7 @@ function action_generate_pac()
|
||||
|
||||
luci.sys.call("chmod 644 " .. pac_file_path)
|
||||
else
|
||||
result.error = "Failed to write PAC file"
|
||||
result.error = luci.i18n.translate("Failed to write PAC file")
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(result)
|
||||
return
|
||||
@@ -2972,7 +2627,7 @@ function action_generate_pac()
|
||||
result.pac_url = pac_url
|
||||
|
||||
if not auth_exists then
|
||||
result.error = "warning: No authentication configured, please be aware of the risk of information leakage!"
|
||||
result.error = luci.i18n.translate("No authentication configured, please be aware of the risk of information leakage!")
|
||||
end
|
||||
|
||||
luci.http.prepare_content("application/json")
|
||||
@@ -3640,7 +3295,7 @@ function action_add_subscription()
|
||||
local address = luci.http.formvalue("address")
|
||||
local sub_ua = luci.http.formvalue("sub_ua") or "clash.meta"
|
||||
local sub_convert = luci.http.formvalue("sub_convert") or "0"
|
||||
local convert_address = luci.http.formvalue("convert_address") or "https://api.dler.io/sub"
|
||||
local convert_address = luci.http.formvalue("convert_address") or ""
|
||||
local template = luci.http.formvalue("template") or ""
|
||||
local emoji = luci.http.formvalue("emoji") or "false"
|
||||
local udp = luci.http.formvalue("udp") or "false"
|
||||
@@ -4129,7 +3784,7 @@ function action_overwrite_subscribe_info()
|
||||
local overwrite_dir = "/etc/openclash/overwrite/"
|
||||
local file_path = overwrite_dir .. section_name
|
||||
if url and url ~= "" then
|
||||
local cmd = string.format('curl -sL --connect-timeout 5 -m 15 "%s" -o "%s"', url, file_path)
|
||||
local cmd = string.format('curl -sL --connect-timeout 5 -m 15 --retry 2 "%s" -o "%s"', url, file_path)
|
||||
local ret = luci.sys.call(cmd)
|
||||
if not fs.access(file_path) then
|
||||
fs.writefile(file_path, "")
|
||||
@@ -4259,14 +3914,6 @@ function action_get_subscribe_info_data()
|
||||
luci.http.status(400, "Bad Request")
|
||||
return
|
||||
end
|
||||
|
||||
local data = {}
|
||||
uci:foreach("openclash", "subscribe_info", function(s)
|
||||
if s.name == filename then
|
||||
data = s
|
||||
end
|
||||
end)
|
||||
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(data)
|
||||
luci.http.write_json(get_sub_url(filename))
|
||||
end
|
||||
Reference in new issue
Block a user