mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-09-13 20:04:45 +08:00
💐 Sync 2026-07-18 20:20:11
This commit is contained in:
@@ -29,22 +29,19 @@ module YAML
|
||||
secret = kwargs.delete(:secret)
|
||||
end
|
||||
|
||||
if secret && secret.to_s.strip != "" && yaml_content.include?("BEGIN AGE ENCRYPTED FILE")
|
||||
begin
|
||||
if yaml_content.include?("BEGIN AGE ENCRYPTED FILE")
|
||||
if secret && secret.to_s.strip != ""
|
||||
decrypted = decrypt_content_with_secret(secret.to_s, yaml_content)
|
||||
if decrypted && !decrypted.empty? && !decrypted.include?("BEGIN AGE ENCRYPTED FILE")
|
||||
processed = fix_short_id_quotes(decrypted)
|
||||
return load(processed, *args, **kwargs)
|
||||
else
|
||||
LOG_WARN("【%s】Decrypted content empty or still encrypted" % [filename])
|
||||
raise "Decrypted content empty or still encrypted: [#{filename}]"
|
||||
end
|
||||
rescue => e
|
||||
LOG_WARN("Decrypt attempt failed:【%s】" % [e.message])
|
||||
end
|
||||
end
|
||||
|
||||
if (secret.nil? || secret.to_s.strip == "") && yaml_content.include?("BEGIN AGE ENCRYPTED FILE")
|
||||
keys = find_age_keys_for_filename(filename)
|
||||
last_error = nil
|
||||
(keys[:secrets] || []).each do |sec|
|
||||
begin
|
||||
decrypted = decrypt_content_with_secret(sec, yaml_content)
|
||||
@@ -53,13 +50,12 @@ module YAML
|
||||
return load(processed, *args, **kwargs)
|
||||
end
|
||||
rescue => e
|
||||
LOG_WARN("Decrypt attempt failed for a found secret:【%s】" % [e.message])
|
||||
last_error = e.message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if yaml_content.include?("BEGIN AGE ENCRYPTED FILE")
|
||||
raise "Encrypted file: decryption failed for %s" % [filename]
|
||||
detail = last_error ? "#{last_error}" : ""
|
||||
raise "Encrypted file: decryption failed for [#{filename}]: [#{detail}]"
|
||||
end
|
||||
|
||||
processed_content = fix_short_id_quotes(yaml_content)
|
||||
@@ -67,59 +63,57 @@ module YAML
|
||||
end
|
||||
|
||||
def self.dump(obj, io = nil, **options)
|
||||
begin
|
||||
yaml_content = original_dump(obj, **options)
|
||||
processed = fix_short_id_quotes(yaml_content)
|
||||
public_key = nil
|
||||
fname = nil
|
||||
if options.key?(:public)
|
||||
public_key = options.delete(:public)
|
||||
yaml_content = original_dump(obj, **options)
|
||||
processed = fix_short_id_quotes(yaml_content)
|
||||
public_key = nil
|
||||
fname = nil
|
||||
if options.key?(:public)
|
||||
public_key = options.delete(:public)
|
||||
end
|
||||
|
||||
if (!public_key || public_key.to_s.strip == "")
|
||||
if options.key?(:filename)
|
||||
fname = options.delete(:filename)
|
||||
elsif io && io.respond_to?(:path)
|
||||
fname = io.path
|
||||
elsif io && io.respond_to?(:to_path)
|
||||
fname = io.to_path
|
||||
end
|
||||
|
||||
if (!public_key || public_key.to_s.strip == "")
|
||||
if options.key?(:filename)
|
||||
fname = options.delete(:filename)
|
||||
elsif io && io.respond_to?(:path)
|
||||
fname = io.path
|
||||
elsif io && io.respond_to?(:to_path)
|
||||
fname = io.to_path
|
||||
end
|
||||
|
||||
if fname && fname.to_s.strip != ""
|
||||
if fname && fname.to_s.strip != ""
|
||||
keys = find_age_keys_for_filename(fname)
|
||||
public_key = keys[:publics].first if keys[:publics] && !keys[:publics].empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if public_key && public_key.to_s.strip != ""
|
||||
begin
|
||||
encrypted = encrypt_content_with_public(public_key.to_s, processed)
|
||||
if encrypted && !encrypted.empty?
|
||||
if io.nil?
|
||||
return encrypted
|
||||
elsif io.respond_to?(:write)
|
||||
io.write(encrypted)
|
||||
return io
|
||||
else
|
||||
return encrypted
|
||||
end
|
||||
if public_key && public_key.to_s.strip != ""
|
||||
begin
|
||||
encrypted = encrypt_content_with_public(public_key.to_s, processed)
|
||||
if encrypted && !encrypted.empty?
|
||||
if io.nil?
|
||||
return encrypted
|
||||
elsif io.respond_to?(:write)
|
||||
io.write(encrypted)
|
||||
return io
|
||||
else
|
||||
return encrypted
|
||||
end
|
||||
rescue => e
|
||||
LOG_WARN("Encrypt attempt failed:【%s】" % [e.message])
|
||||
end
|
||||
rescue => e
|
||||
if io.respond_to?(:write)
|
||||
io.write(processed)
|
||||
end
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
if io.nil?
|
||||
processed
|
||||
elsif io.respond_to?(:write)
|
||||
io.write(processed)
|
||||
io
|
||||
else
|
||||
processed
|
||||
end
|
||||
rescue => e
|
||||
LOG_ERROR("Write file failed:【%s】" % [e.message])
|
||||
nil
|
||||
if io.nil?
|
||||
processed
|
||||
elsif io.respond_to?(:write)
|
||||
io.write(processed)
|
||||
io
|
||||
else
|
||||
processed
|
||||
end
|
||||
end
|
||||
|
||||
@@ -127,15 +121,19 @@ module YAML
|
||||
output = String.new
|
||||
IO.popen(cmd, 'r+', err: [:child, :out]) do |io|
|
||||
io.binmode
|
||||
writer_error = nil
|
||||
writer = Thread.new do
|
||||
begin
|
||||
input.bytesize.times do |i|
|
||||
chunk = input.byteslice(i * chunk_size, chunk_size)
|
||||
break if chunk.nil?
|
||||
io.write(chunk)
|
||||
end
|
||||
io.close_write
|
||||
input.bytesize.times do |i|
|
||||
chunk = input.byteslice(i * chunk_size, chunk_size)
|
||||
break if chunk.nil?
|
||||
io.write(chunk)
|
||||
end
|
||||
io.close_write
|
||||
rescue Errno::EPIPE
|
||||
# child exited before reading all input, not an error
|
||||
rescue => e
|
||||
writer_error = e
|
||||
end
|
||||
end
|
||||
|
||||
@@ -143,6 +141,7 @@ module YAML
|
||||
output << chunk
|
||||
end
|
||||
writer.join
|
||||
raise writer_error if writer_error
|
||||
end
|
||||
[output, $?]
|
||||
end
|
||||
@@ -157,43 +156,59 @@ module YAML
|
||||
end
|
||||
|
||||
def self.find_age_keys_for_filename(filename)
|
||||
begin
|
||||
basename = File.basename(filename)
|
||||
basename_no_ext = File.basename(filename, File.extname(filename))
|
||||
publics = []
|
||||
secrets = []
|
||||
basename = File.basename(filename)
|
||||
basename_no_ext = File.basename(filename, File.extname(filename))
|
||||
publics = []
|
||||
secrets = []
|
||||
|
||||
[basename, basename_no_ext].uniq.each do |n|
|
||||
cmd_public = ["/bin/sh", "-c", ". /usr/share/openclash/uci.sh; uci_get_age_public_keys \"$1\"", "sh", n]
|
||||
IO.popen(cmd_public, "r") do |io|
|
||||
io.each_line { |l| publics << l.strip unless l.nil? || l.strip == "" }
|
||||
end
|
||||
[basename, basename_no_ext].uniq.each do |n|
|
||||
cmd_public = ["/bin/sh", "-c", ". /usr/share/openclash/uci.sh; uci_get_age_public_keys \"$1\"", "sh", n]
|
||||
IO.popen(cmd_public, "r") do |io|
|
||||
io.each_line { |l| publics << l.strip unless l.nil? || l.strip == "" }
|
||||
end
|
||||
|
||||
cmd_secret = ["/bin/sh", "-c", ". /usr/share/openclash/uci.sh; uci_get_age_secret_keys \"$1\"", "sh", n]
|
||||
IO.popen(cmd_secret, "r") do |io|
|
||||
io.each_line { |l| secrets << l.strip unless l.nil? || l.strip == "" }
|
||||
end
|
||||
cmd_secret = ["/bin/sh", "-c", ". /usr/share/openclash/uci.sh; uci_get_age_secret_keys \"$1\"", "sh", n]
|
||||
IO.popen(cmd_secret, "r") do |io|
|
||||
io.each_line { |l| secrets << l.strip unless l.nil? || l.strip == "" }
|
||||
end
|
||||
{ publics: publics, secrets: secrets }
|
||||
rescue => e
|
||||
{ publics: [], secrets: [] }
|
||||
end
|
||||
{ publics: publics, secrets: secrets }
|
||||
end
|
||||
|
||||
def self.decrypt_content_with_secret(secret, content)
|
||||
# Clear injection-detection env vars to prevent OIX GuardStartup from
|
||||
# killing the child process (e.g. LD_PRELOAD set by opkg upgrade)
|
||||
cmd = ['/etc/openclash/core/clash_meta', 'age', 'decrypt', secret, '-', '-']
|
||||
out, status = popen_stream(cmd, content)
|
||||
status.success? ? out : nil
|
||||
rescue => e
|
||||
nil
|
||||
old_ld_preload = ENV.delete('LD_PRELOAD')
|
||||
old_ld_audit = ENV.delete('LD_AUDIT')
|
||||
old_dyld = ENV.delete('DYLD_INSERT_LIBRARIES')
|
||||
begin
|
||||
out, status = popen_stream(cmd, content)
|
||||
status.success? ? out : raise("age decrypt failed: #{out.to_s.strip}")
|
||||
rescue => e
|
||||
raise "age decrypt failed: #{e.message.strip}"
|
||||
ensure
|
||||
ENV['LD_PRELOAD'] = old_ld_preload if old_ld_preload
|
||||
ENV['LD_AUDIT'] = old_ld_audit if old_ld_audit
|
||||
ENV['DYLD_INSERT_LIBRARIES'] = old_dyld if old_dyld
|
||||
end
|
||||
end
|
||||
|
||||
def self.encrypt_content_with_public(public, content)
|
||||
cmd = ['/etc/openclash/core/clash_meta', 'age', 'encrypt', public, '-', '-']
|
||||
out, status = popen_stream(cmd, content)
|
||||
status.success? ? out : nil
|
||||
rescue => e
|
||||
nil
|
||||
old_ld_preload = ENV.delete('LD_PRELOAD')
|
||||
old_ld_audit = ENV.delete('LD_AUDIT')
|
||||
old_dyld = ENV.delete('DYLD_INSERT_LIBRARIES')
|
||||
begin
|
||||
out, status = popen_stream(cmd, content)
|
||||
status.success? ? out : raise("age encrypt failed: #{out.to_s.strip}")
|
||||
rescue => e
|
||||
raise "age encrypt failed: #{e.message.strip}"
|
||||
ensure
|
||||
ENV['LD_PRELOAD'] = old_ld_preload if old_ld_preload
|
||||
ENV['LD_AUDIT'] = old_ld_audit if old_ld_audit
|
||||
ENV['DYLD_INSERT_LIBRARIES'] = old_dyld if old_dyld
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
@@ -279,8 +294,7 @@ module YAML
|
||||
yaml_content
|
||||
end
|
||||
rescue => e
|
||||
LOG_ERROR("Fix short-id values type failed:【%s】" % [e.message])
|
||||
yaml_content
|
||||
raise "fix short-id values type failed: #{e.message}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -314,8 +328,7 @@ module YAML
|
||||
override
|
||||
end
|
||||
rescue => e
|
||||
LOG_ERROR("YAML overwrite failed:【key: %s, operation: %s, error: %s】" % [current_key, current_operation, e.message])
|
||||
base
|
||||
raise "key: [#{current_key}] - operation: [#{current_operation}], error: [#{e.message}]"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -385,8 +398,7 @@ module YAML
|
||||
target == condition
|
||||
end
|
||||
rescue => e
|
||||
LOG_ERROR("YAML overwrite failed:【(match value) => target: %s, condition: %s, error: %s】" % [target, condition, e.message])
|
||||
false
|
||||
raise "[match value] target: [#{target}] - condition: [#{condition}], error: [#{e.message}]"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -602,8 +614,7 @@ module YAML
|
||||
collection
|
||||
end
|
||||
rescue => e
|
||||
LOG_ERROR("YAML overwrite failed:【(batch update) => update_spec: %s, error: %s】" % [update_spec, e.message])
|
||||
collection
|
||||
raise "[batch update] update_spec: [#{update_spec}], error: [#{e.message}]"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -26,10 +26,11 @@ fi
|
||||
|
||||
if [ "$CORE_TYPE" = "Oix" ] || [ -n "$OIX_TOKEN" ]; then
|
||||
OIX_VERSION_URL="https://github.com/vernesong/mihomo-oix/releases/download/Pre-Alpha/version.txt"
|
||||
OIX_VERSION_P_URL="https://dl.dler.io/mihomo-oix/version.txt?tag=Pre-Alpha"
|
||||
if [ "$github_address_mod" != "0" ] && [ "$github_address_mod" != "https://cdn.jsdelivr.net/" ] && [ "$github_address_mod" != "https://fastly.jsdelivr.net/" ] && [ "$github_address_mod" != "https://testingcf.jsdelivr.net/" ]; then
|
||||
DOWNLOAD_URL="${github_address_mod}${OIX_VERSION_URL}"
|
||||
else
|
||||
DOWNLOAD_URL="$OIX_VERSION_URL"
|
||||
DOWNLOAD_URL="$OIX_VERSION_P_URL"
|
||||
fi
|
||||
else
|
||||
if [ "$github_address_mod" != "0" ]; then
|
||||
|
||||
@@ -70,6 +70,9 @@ config_test()
|
||||
config_download()
|
||||
{
|
||||
LOG_TIP "Config File【$name】Downloading User-Agent【$sub_ua】..."
|
||||
if [ -n "$sub_headers" ]; then
|
||||
LOG_TIP "Config File【$name】Custom Headers【$(echo "$sub_headers" | tr '\n' ',' | sed 's/,$//')】..."
|
||||
fi
|
||||
if [ -n "$subscribe_url_param" ] && [ -n "$c_address" ]; then
|
||||
LOG_INFO "Config File【$name】Downloading URL【$c_address$subscribe_url_param】..."
|
||||
DOWNLOAD_URL="${c_address}${subscribe_url_param}"
|
||||
@@ -79,7 +82,7 @@ if [ -z "$DOWNLOAD_URL" ]; then
|
||||
DOWNLOAD_URL="${subscribe_url}"
|
||||
fi
|
||||
DOWNLOAD_PARAM="$sub_ua"
|
||||
DOWNLOAD_FILE_CURL "$DOWNLOAD_URL" "$CFG_FILE" "$CONFIG_FILE" "$DOWNLOAD_PARAM" "$SECRET_KEY"
|
||||
DOWNLOAD_FILE_CURL "$DOWNLOAD_URL" "$CFG_FILE" "$CONFIG_FILE" "$DOWNLOAD_PARAM" "$SECRET_KEY" "$sub_headers"
|
||||
DOWNLOAD_RESULT=$?
|
||||
}
|
||||
|
||||
@@ -148,7 +151,11 @@ config_cus_up()
|
||||
rescue Exception => e
|
||||
YAML.LOG_ERROR('Filter Proxies Failed,【' + e.message + '】');
|
||||
ensure
|
||||
File.open('$CFG_FILE','w') {|f| YAML.dump(Value, f)};
|
||||
begin
|
||||
File.open('$CFG_FILE','w') {|f| YAML.dump(Value, f)};
|
||||
rescue Exception => e
|
||||
YAML.LOG_ERROR('Write file failed:【%s】' % [e.message])
|
||||
end
|
||||
end" 2>/dev/null >> $LOG_FILE
|
||||
fi
|
||||
fi
|
||||
@@ -219,7 +226,7 @@ config_download_direct()
|
||||
sed -i '/^ \{0,\}enhanced-mode:/d' "$CFG_FILE" >/dev/null 2>&1
|
||||
config_test
|
||||
if [ $? -ne 0 ]; then
|
||||
LOG_ERROR "Config File Tested Faild, Please Check The Log Infos!"
|
||||
LOG_ERROR "Config File Tested Failed, Please Check The Log Infos!"
|
||||
change_dns
|
||||
config_error
|
||||
return
|
||||
@@ -314,9 +321,19 @@ convert_custom_param()
|
||||
fi
|
||||
}
|
||||
|
||||
build_sub_headers()
|
||||
{
|
||||
if [ -z "$sub_headers" ]; then
|
||||
sub_headers="$1"
|
||||
else
|
||||
sub_headers="$sub_headers
|
||||
$1"
|
||||
fi
|
||||
}
|
||||
|
||||
sub_info_get()
|
||||
{
|
||||
local section="$1" subscribe_url template_path subscribe_url_param template_path_encode key_match_param key_ex_match_param c_address de_ex_keyword sub_ua append_custom_params SECRET_KEY DOWNLOAD_URL DOWNLOAD_PARAM
|
||||
local section="$1" subscribe_url template_path subscribe_url_param template_path_encode key_match_param key_ex_match_param c_address de_ex_keyword sub_ua sub_headers append_custom_params SECRET_KEY DOWNLOAD_URL DOWNLOAD_PARAM
|
||||
config_get_bool "enabled" "$section" "enabled" "1"
|
||||
config_get "name" "$section" "name" "config"
|
||||
config_get "sub_convert" "$section" "sub_convert" ""
|
||||
@@ -334,6 +351,7 @@ sub_info_get()
|
||||
config_get "custom_template_url" "$section" "custom_template_url" ""
|
||||
config_get "de_ex_keyword" "$section" "de_ex_keyword" ""
|
||||
config_get "sub_ua" "$section" "sub_ua" "clash-verge/v2.4.5"
|
||||
config_list_foreach "$section" "sub_headers" build_sub_headers
|
||||
SECRET_KEY=$(uci_get_age_secret_keys "$name")
|
||||
|
||||
CONFIG_FILE="/etc/openclash/config/$name.yaml"
|
||||
@@ -419,7 +437,7 @@ sub_info_get()
|
||||
sed -i -E 's/protocol-param: ([^,'"'"'"''}( *#)\n\r]+)/protocol-param: "\1"/g' "$CFG_FILE" 2>/dev/null
|
||||
config_test
|
||||
if [ $? -ne 0 ]; then
|
||||
LOG_ERROR "Config File Tested Faild, Please Check The Log Infos!"
|
||||
LOG_ERROR "Config File Tested Failed, Please Check The Log Infos!"
|
||||
LOG_ERROR "Config File【$name】Subscribed Failed, Trying to Download Without Agent..."
|
||||
config_download_direct
|
||||
return
|
||||
|
||||
@@ -63,9 +63,9 @@ else
|
||||
mkdir -p /tmp/etc/openclash/core
|
||||
fi
|
||||
|
||||
CORE_CV=$($meta_core_path -v 2>/dev/null |awk -F ' ' '{print $3}' |head -1)
|
||||
TMP_FILE="/tmp/clash_meta"
|
||||
TARGET_CORE_PATH="$meta_core_path"
|
||||
CORE_CV=$($TARGET_CORE_PATH -v 2>/dev/null |awk -F ' ' '{print $3}' |head -1)
|
||||
TMP_FILE="${TARGET_CORE_PATH}.new.$$"
|
||||
|
||||
if [ "$CORE_TYPE" = "Oix" ]; then
|
||||
CORE_URL_PATH=""
|
||||
@@ -88,10 +88,11 @@ if [ "$CORE_CV" != "$CORE_LV" ] || [ -z "$CORE_CV" ]; then
|
||||
LOG_TIP "【$CORE_TYPE】Core Downloading, Please Try to Download and Upload Manually If Fails"
|
||||
if [ "$CORE_TYPE" = "Oix" ]; then
|
||||
OIX_CORE_URL="https://github.com/vernesong/mihomo-oix/releases/download/Pre-Alpha/mihomo-${CPU_MODEL}-${CORE_LV}.gz"
|
||||
OIX_CORE_P_URL="https://dl.dler.io/mihomo-oix/mihomo-${CPU_MODEL}-${CORE_LV}.gz?tag=Pre-Alpha"
|
||||
if [ "$github_address_mod" != "0" ] && [ "$github_address_mod" != "https://cdn.jsdelivr.net/" ] && [ "$github_address_mod" != "https://fastly.jsdelivr.net/" ] && [ "$github_address_mod" != "https://testingcf.jsdelivr.net/" ]; then
|
||||
DOWNLOAD_URL="${github_address_mod}${OIX_CORE_URL}"
|
||||
else
|
||||
DOWNLOAD_URL="$OIX_CORE_URL"
|
||||
DOWNLOAD_URL="$OIX_CORE_P_URL"
|
||||
fi
|
||||
else
|
||||
if [ "$github_address_mod" != "0" ]; then
|
||||
@@ -149,7 +150,7 @@ if [ "$CORE_CV" != "$CORE_LV" ] || [ -z "$CORE_CV" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
mv "$TMP_FILE" "$TARGET_CORE_PATH" >/dev/null 2>&1
|
||||
mv -f "$TMP_FILE" "$TARGET_CORE_PATH" >/dev/null 2>&1
|
||||
|
||||
if [ "$?" == "0" ]; then
|
||||
LOG_TIP "【"$CORE_TYPE"】Core Update Successful!"
|
||||
|
||||
@@ -2,6 +2,22 @@
|
||||
. /usr/share/openclash/log.sh
|
||||
. /usr/share/openclash/openclash_etag.sh
|
||||
|
||||
DOWNLOAD_FAILURE_OUTPUT() {
|
||||
failure_exit_code="$1"
|
||||
failure_http_code="$2"
|
||||
failure_output="$3"
|
||||
|
||||
if [ -n "$failure_output" ]; then
|
||||
printf '%s' "$failure_output"
|
||||
elif [ -n "$failure_http_code" ] && [ "$failure_http_code" != "000" ]; then
|
||||
printf 'HTTP status %s' "$failure_http_code"
|
||||
elif [ -n "$failure_exit_code" ]; then
|
||||
printf 'curl exit code %s' "$failure_exit_code"
|
||||
else
|
||||
printf 'unknown error'
|
||||
fi
|
||||
}
|
||||
|
||||
DOWNLOAD_FILE_CURL() {
|
||||
[ -z "$1" ] || [ -z "$2" ] && return 1
|
||||
DOWNLOAD_URL=$1
|
||||
@@ -9,6 +25,7 @@ DOWNLOAD_FILE_CURL() {
|
||||
FILE_PATH=$3
|
||||
DOWNLOAD_UA=$4
|
||||
SECRET_KEY=$5
|
||||
CUSTOM_HEADERS=$6
|
||||
[ -z "$DOWNLOAD_UA" ] && DOWNLOAD_UA="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
|
||||
HEADER_TMP="/tmp/openclash_curl_header_$$"
|
||||
DOWNLOAD_TMP="${DOWNLOAD_PATH}.download.$$"
|
||||
@@ -25,6 +42,15 @@ DOWNLOAD_FILE_CURL() {
|
||||
|
||||
rm -f "$HEADER_TMP" "$DOWNLOAD_TMP"
|
||||
|
||||
set --
|
||||
if [ -n "$CUSTOM_HEADERS" ]; then
|
||||
while IFS= read -r hdr; do
|
||||
[ -n "$hdr" ] && set -- "$@" -H "$hdr"
|
||||
done <<EOF
|
||||
$CUSTOM_HEADERS
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [ "$SHOW_DOWNLOAD_PROGRESS" = "1" ] || [ "$SHOW_DOWNLOAD_PROGRESS" = "true" ]; then
|
||||
TEMP_LOG="/tmp/curl_log_$$"
|
||||
|
||||
@@ -37,23 +63,27 @@ DOWNLOAD_FILE_CURL() {
|
||||
-H "User-Agent: ${DOWNLOAD_UA}" \
|
||||
-H "X-Age-Public-Key: ${SECRET_KEY}" \
|
||||
-H "$ETAG_HEADER" \
|
||||
"$@" \
|
||||
"$DOWNLOAD_URL" -o "$DOWNLOAD_TMP" 2>"$TEMP_LOG"
|
||||
elif [ -n "$SECRET_KEY" ]; then
|
||||
curl -# -L --connect-timeout 30 -m 180 --speed-time 30 --speed-limit 1 --retry 2 \
|
||||
-D "$HEADER_TMP" \
|
||||
-H "User-Agent: ${DOWNLOAD_UA}" \
|
||||
-H "X-Age-Public-Key: ${SECRET_KEY}" \
|
||||
"$@" \
|
||||
"$DOWNLOAD_URL" -o "$DOWNLOAD_TMP" 2>"$TEMP_LOG"
|
||||
elif [ -n "$ETAG_HEADER" ]; then
|
||||
curl -# -L --connect-timeout 30 -m 180 --speed-time 30 --speed-limit 1 --retry 2 \
|
||||
-D "$HEADER_TMP" \
|
||||
-H "User-Agent: ${DOWNLOAD_UA}" \
|
||||
-H "$ETAG_HEADER" \
|
||||
"$@" \
|
||||
"$DOWNLOAD_URL" -o "$DOWNLOAD_TMP" 2>"$TEMP_LOG"
|
||||
else
|
||||
curl -# -L --connect-timeout 30 -m 180 --speed-time 30 --speed-limit 1 --retry 2 \
|
||||
-D "$HEADER_TMP" \
|
||||
-H "User-Agent: ${DOWNLOAD_UA}" \
|
||||
"$@" \
|
||||
"$DOWNLOAD_URL" -o "$DOWNLOAD_TMP" 2>"$TEMP_LOG"
|
||||
fi
|
||||
echo $? > "${TEMP_LOG}.exit"
|
||||
@@ -99,7 +129,8 @@ DOWNLOAD_FILE_CURL() {
|
||||
fi
|
||||
|
||||
if [ "$EXIR_CODE" -ne 0 ] || [ "$HTTP_CODE" != "200" ]; then
|
||||
LOG_OUT "【$DOWNLOAD_PATH】Download Failed:【$OUTPUT】"
|
||||
OUTPUT=$(DOWNLOAD_FAILURE_OUTPUT "$EXIR_CODE" "$HTTP_CODE" "${OUTPUT:-}")
|
||||
LOG_OUT "【${DOWNLOAD_PATH}】Download Failed:【${OUTPUT}】"
|
||||
rm -f "$HEADER_TMP" "$DOWNLOAD_TMP"
|
||||
SLOG_CLEAN
|
||||
return 1
|
||||
@@ -116,23 +147,28 @@ DOWNLOAD_FILE_CURL() {
|
||||
-H "User-Agent: ${DOWNLOAD_UA}" \
|
||||
-H "X-Age-Public-Key: ${SECRET_KEY}" \
|
||||
-H "$ETAG_HEADER" \
|
||||
"$@" \
|
||||
"$DOWNLOAD_URL" -o "$DOWNLOAD_TMP" 2>&1)
|
||||
elif [ -n "$SECRET_KEY" ]; then
|
||||
CURL_OUTPUT=$(curl -w "\n%{http_code}" -SsL --connect-timeout 30 -m 180 --speed-time 30 --speed-limit 1 --retry 2 \
|
||||
-D "$HEADER_TMP" \
|
||||
-H "User-Agent: ${DOWNLOAD_UA}" \
|
||||
-H "X-Age-Public-Key: ${SECRET_KEY}" \
|
||||
"$@" \
|
||||
"$DOWNLOAD_URL" -o "$DOWNLOAD_TMP" 2>&1)
|
||||
elif [ -n "$ETAG_HEADER" ]; then
|
||||
CURL_OUTPUT=$(curl -w "\n%{http_code}" -SsL --connect-timeout 30 -m 180 --speed-time 30 --speed-limit 1 --retry 2 \
|
||||
-D "$HEADER_TMP" \
|
||||
-H "User-Agent: ${DOWNLOAD_UA}" \
|
||||
-H "$ETAG_HEADER" \
|
||||
"$@" \
|
||||
"$DOWNLOAD_URL" -o "$DOWNLOAD_TMP" 2>&1)
|
||||
else
|
||||
CURL_OUTPUT=$(curl -w "\n%{http_code}" -SsL --connect-timeout 30 -m 180 --speed-time 30 --speed-limit 1 --retry 2 \
|
||||
-D "$HEADER_TMP" \
|
||||
-H "User-Agent: ${DOWNLOAD_UA}" "$DOWNLOAD_URL" -o "$DOWNLOAD_TMP" 2>&1)
|
||||
-H "User-Agent: ${DOWNLOAD_UA}" \
|
||||
"$@" \
|
||||
"$DOWNLOAD_URL" -o "$DOWNLOAD_TMP" 2>&1)
|
||||
fi
|
||||
EXIR_CODE=$?
|
||||
HTTP_CODE=$(echo "$CURL_OUTPUT" | tail -n1)
|
||||
@@ -149,7 +185,8 @@ DOWNLOAD_FILE_CURL() {
|
||||
|
||||
if [ "$EXIR_CODE" -ne 0 ] || [ "$HTTP_CODE" != "200" ]; then
|
||||
OUTPUT=$(echo "$CURL_OUTPUT" | sed '$d' | grep -a 'curl:' | tail -n 1)
|
||||
LOG_OUT "【$DOWNLOAD_PATH】Download Failed:【$OUTPUT】"
|
||||
OUTPUT=$(DOWNLOAD_FAILURE_OUTPUT "$EXIR_CODE" "$HTTP_CODE" "$OUTPUT")
|
||||
LOG_OUT "【${DOWNLOAD_PATH}】Download Failed:【${OUTPUT}】"
|
||||
rm -f "$HEADER_TMP" "$DOWNLOAD_TMP"
|
||||
SLOG_CLEAN
|
||||
return 1
|
||||
@@ -157,7 +194,7 @@ DOWNLOAD_FILE_CURL() {
|
||||
fi
|
||||
|
||||
if ! mv -f "$DOWNLOAD_TMP" "$DOWNLOAD_PATH"; then
|
||||
LOG_OUT "【$DOWNLOAD_PATH】Download Failed:【Unable to save download file】"
|
||||
LOG_OUT "【${DOWNLOAD_PATH}】Download Failed:【Unable to save download file】"
|
||||
rm -f "$HEADER_TMP" "$DOWNLOAD_TMP"
|
||||
SLOG_CLEAN
|
||||
return 1
|
||||
|
||||
@@ -418,6 +418,25 @@ cat >> "$DEBUG_LOG" <<-EOF
|
||||
\`\`\`
|
||||
EOF
|
||||
|
||||
if [ -n "$(command -v fw4)" ]; then
|
||||
cat >> "$DEBUG_LOG" <<-EOF
|
||||
|
||||
## NFTABLES 防火墙设置
|
||||
|
||||
\`\`\`bash
|
||||
# nft list chain inet fw4 (all chains)
|
||||
EOF
|
||||
for nft in "input" "forward" "dstnat" "srcnat" "nat_output" "mangle_prerouting" "mangle_output"; do
|
||||
nft list chain inet fw4 "$nft" >> "$DEBUG_LOG" 2>/dev/null && echo "" >> "$DEBUG_LOG"
|
||||
done >/dev/null 2>&1
|
||||
for nft in "openclash" "openclash_mangle" "openclash_mangle_output" "openclash_output" "openclash_post" "openclash_wan_input" "openclash_dns_hijack" "openclash_dns_redirect" "openclash_v6" "openclash_mangle_v6" "openclash_mangle_output_v6" "openclash_output_v6" "openclash_post_v6" "openclash_wan6_input"; do
|
||||
nft list chain inet fw4 "$nft" >> "$DEBUG_LOG" 2>/dev/null && echo "" >> "$DEBUG_LOG"
|
||||
done >/dev/null 2>&1
|
||||
echo "" >> "$DEBUG_LOG"
|
||||
cat >> "$DEBUG_LOG" <<-EOF
|
||||
\`\`\`
|
||||
EOF
|
||||
else
|
||||
cat >> "$DEBUG_LOG" <<-EOF
|
||||
|
||||
## IPTABLES 防火墙设置
|
||||
@@ -482,39 +501,63 @@ echo "" >> "$DEBUG_LOG"
|
||||
cat >> "$DEBUG_LOG" <<-EOF
|
||||
\`\`\`
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [ -n "$(command -v fw4)" ]; then
|
||||
cat >> "$DEBUG_LOG" <<-EOF
|
||||
|
||||
## NFTABLES 防火墙设置
|
||||
## NFT Sets 状态
|
||||
|
||||
\`\`\`bash
|
||||
# nft list chain inet fw4 (all chains)
|
||||
# nft list sets inet fw4
|
||||
EOF
|
||||
for nft in "input" "forward" "dstnat" "srcnat" "nat_output" "mangle_prerouting" "mangle_output"; do
|
||||
nft list chain inet fw4 "$nft" >> "$DEBUG_LOG" 2>/dev/null
|
||||
done >/dev/null 2>&1
|
||||
for nft in "openclash" "openclash_mangle" "openclash_mangle_output" "openclash_output" "openclash_post" "openclash_wan_input" "openclash_dns_hijack" "openclash_dns_redirect" "openclash_v6" "openclash_mangle_v6" "openclash_mangle_output_v6" "openclash_output_v6" "openclash_post_v6" "openclash_wan6_input"; do
|
||||
nft list chain inet fw4 "$nft" >> "$DEBUG_LOG" 2>/dev/null
|
||||
done >/dev/null 2>&1
|
||||
nft list sets inet fw4 2>/dev/null | sed -n '/^table inet fw4 {/,/^}/p' | awk '
|
||||
/elements = \{/ { in_el=1; el=0; trunc=0; indent=""; elem_indent=$0; sub(/[^[:space:]].*/, "", elem_indent); print; if (/[[:space:]]+\}[[:space:]]*$/) in_el=0; next }
|
||||
in_el && /\}/ { in_el=0; if (trunc) { print indent "..."; print elem_indent "}" } else print; next }
|
||||
in_el {
|
||||
if (!indent) { match($0, /^[[:space:]]*/); indent = substr($0, 1, RLENGTH) }
|
||||
n = split($0, a, ","); el += n
|
||||
if (el > 10 && !trunc) { trunc=1; next }
|
||||
if (trunc) next
|
||||
print
|
||||
}
|
||||
!in_el {
|
||||
print
|
||||
if (/^[[:space:]]+\}$/) print ""
|
||||
}
|
||||
' >> "$DEBUG_LOG"
|
||||
echo "" >> "$DEBUG_LOG"
|
||||
cat >> "$DEBUG_LOG" <<-EOF
|
||||
\`\`\`
|
||||
EOF
|
||||
fi
|
||||
|
||||
else
|
||||
cat >> "$DEBUG_LOG" <<-EOF
|
||||
|
||||
## IPSET状态
|
||||
|
||||
\`\`\`bash
|
||||
# ipset list -t
|
||||
# ipset list
|
||||
EOF
|
||||
ipset list -t >> "$DEBUG_LOG"
|
||||
for set in $(ipset list -n 2>/dev/null); do
|
||||
ipset list "$set" 2>/dev/null | awk -v max=10 '
|
||||
/^Members:/ { in_members=1; count=0; print; next }
|
||||
in_members {
|
||||
if (/^[[:space:]]*[^[:space:]]/) {
|
||||
count++
|
||||
if (count <= max) { print; next }
|
||||
else if (count == max+1) { print "..."; next }
|
||||
else { next }
|
||||
}
|
||||
}
|
||||
{ print }
|
||||
'
|
||||
echo ""
|
||||
done >> "$DEBUG_LOG" 2>/dev/null
|
||||
echo "" >> "$DEBUG_LOG"
|
||||
cat >> "$DEBUG_LOG" <<-EOF
|
||||
\`\`\`
|
||||
EOF
|
||||
fi
|
||||
|
||||
cat >> "$DEBUG_LOG" <<-EOF
|
||||
|
||||
@@ -631,7 +674,14 @@ cat >> "$DEBUG_LOG" <<-EOF
|
||||
|
||||
## DNS 解析文件
|
||||
|
||||
### **Dnsmasq 当前默认 resolv 文件:** \`$dnsmasq_default_resolvfile\`
|
||||
### **Dnsmasq 当前默认 resolv 文件**
|
||||
|
||||
\`\`\`bash
|
||||
EOF
|
||||
echo $dnsmasq_default_resolvfile >> "$DEBUG_LOG"
|
||||
echo "" >> "$DEBUG_LOG"
|
||||
cat >> "$DEBUG_LOG" <<-EOF
|
||||
\`\`\`
|
||||
EOF
|
||||
|
||||
if [ -s "/tmp/resolv.conf.auto" ]; then
|
||||
|
||||
@@ -14,6 +14,55 @@
|
||||
rm -rf "/tmp/lock/openclash_dashboard.lock" 2>/dev/null
|
||||
}
|
||||
|
||||
validate_dashboard_dir() {
|
||||
local dashboard_dir="$1"
|
||||
local index_file="${dashboard_dir%/}/index.html"
|
||||
local ref=""
|
||||
local asset=""
|
||||
local script_found=0
|
||||
|
||||
[ -s "$index_file" ] || return 1
|
||||
|
||||
while IFS= read -r ref; do
|
||||
[ -n "$ref" ] || continue
|
||||
ref="${ref%%#*}"
|
||||
ref="${ref%%\?*}"
|
||||
ref="${ref#./}"
|
||||
|
||||
case "$ref" in
|
||||
""|http://*|https://*|//*|/*|data:*|mailto:*) continue ;;
|
||||
esac
|
||||
|
||||
case "$ref" in
|
||||
*.js|*.css)
|
||||
asset="${dashboard_dir%/}/$ref"
|
||||
[ -s "$asset" ] || return 1
|
||||
[ "${ref##*.}" = "js" ] && script_found=1
|
||||
;;
|
||||
esac
|
||||
done <<-EOF
|
||||
$(grep -oE "(src|href)[[:space:]]*=[[:space:]]*['\"][^'\"]+['\"]" "$index_file" 2>/dev/null | sed "s/^[^=]*=[[:space:]]*['\"]//;s/['\"]$//")
|
||||
EOF
|
||||
|
||||
[ "$script_found" -eq 1 ]
|
||||
}
|
||||
|
||||
cleanup_dashboard_tmp() {
|
||||
rm -rf "$DASH_FILE_DIR" "$DASH_FILE_TMP" "$NEW_FILE_DIR" "$OLD_FILE_DIR" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
restore_old_dashboard() {
|
||||
rm -rf "$TARGET_FILE_DIR" >/dev/null 2>&1
|
||||
[ -d "$OLD_FILE_DIR" ] && mv "$OLD_FILE_DIR" "$TARGET_FILE_DIR" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
log_unzip_error() {
|
||||
LOG_OUT "Control Panel【$DASH_NAME - $DASH_TYPE】Unzip Error!" && SLOG_CLEAN
|
||||
cleanup_dashboard_tmp
|
||||
del_lock
|
||||
exit 2
|
||||
}
|
||||
|
||||
set_lock
|
||||
|
||||
DASH_NAME="$1"
|
||||
@@ -23,7 +72,6 @@
|
||||
github_address_mod=$(uci_get_config "github_address_mod" || echo 0)
|
||||
if [ "$DASH_NAME" == "Dashboard" ]; then
|
||||
UNPACK_FILE_DIR="/usr/share/openclash/ui/dashboard/"
|
||||
BACKUP_FILE_DIR="/usr/share/openclash/ui/dashboard_backup/"
|
||||
if [ "$DASH_TYPE" == "Official" ]; then
|
||||
DOWNLOAD_PATH="https://codeload.github.com/ayanamist/clash-dashboard/zip/refs/heads/gh-pages"
|
||||
FILE_PATH_INCLUDE="clash-dashboard-gh-pages"
|
||||
@@ -33,7 +81,6 @@
|
||||
fi
|
||||
elif [ "$DASH_NAME" == "Yacd" ]; then
|
||||
UNPACK_FILE_DIR="/usr/share/openclash/ui/yacd/"
|
||||
BACKUP_FILE_DIR="/usr/share/openclash/ui/yacd_backup/"
|
||||
if [ "$DASH_TYPE" == "Official" ]; then
|
||||
DOWNLOAD_PATH="https://codeload.github.com/haishanh/yacd/zip/refs/heads/gh-pages"
|
||||
FILE_PATH_INCLUDE="yacd-gh-pages"
|
||||
@@ -43,15 +90,17 @@
|
||||
fi
|
||||
elif [ "$DASH_NAME" == "Zashboard" ]; then
|
||||
UNPACK_FILE_DIR="/usr/share/openclash/ui/zashboard/"
|
||||
BACKUP_FILE_DIR="/usr/share/openclash/ui/zashboard_backup/"
|
||||
DOWNLOAD_PATH="https://codeload.github.com/Zephyruso/zashboard/zip/refs/heads/gh-pages-cdn-fonts"
|
||||
FILE_PATH_INCLUDE="zashboard-gh-pages-cdn-fonts"
|
||||
else
|
||||
UNPACK_FILE_DIR="/usr/share/openclash/ui/metacubexd/"
|
||||
BACKUP_FILE_DIR="/usr/share/openclash/ui/metacubexd_backup/"
|
||||
DOWNLOAD_PATH="https://codeload.github.com/MetaCubeX/metacubexd/zip/refs/heads/gh-pages"
|
||||
FILE_PATH_INCLUDE="metacubexd-gh-pages"
|
||||
fi
|
||||
TARGET_FILE_DIR="${UNPACK_FILE_DIR%/}"
|
||||
TARGET_PARENT_DIR="$(dirname "$TARGET_FILE_DIR")"
|
||||
NEW_FILE_DIR="${TARGET_PARENT_DIR}/.openclash_dashboard_new.$$"
|
||||
OLD_FILE_DIR="${TARGET_PARENT_DIR}/.openclash_dashboard_old.$$"
|
||||
|
||||
DOWNLOAD_FILE_CURL "$DOWNLOAD_PATH" "$DASH_FILE_DIR" "$UNPACK_FILE_DIR"
|
||||
DOWNLOAD_RESULT=$?
|
||||
@@ -59,44 +108,43 @@
|
||||
if [ "$DOWNLOAD_RESULT" -eq 0 ] && [ -s "$DASH_FILE_DIR" ]; then
|
||||
unzip -qt "$DASH_FILE_DIR" >/dev/null 2>&1
|
||||
if [ "$?" -eq "0" ]; then
|
||||
cp -rf "$UNPACK_FILE_DIR". "$BACKUP_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$UNPACK_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$DASH_FILE_TMP" "$NEW_FILE_DIR" "$OLD_FILE_DIR" >/dev/null 2>&1
|
||||
unzip -q "$DASH_FILE_DIR" -d "$DASH_FILE_TMP" >/dev/null 2>&1
|
||||
if [ "$?" -eq "0" ] && [ -d "$DASH_FILE_TMP$FILE_PATH_INCLUDE" ]; then
|
||||
cp -rf "$DASH_FILE_TMP$FILE_PATH_INCLUDE"/. "$UNPACK_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$DASH_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$BACKUP_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$DASH_FILE_TMP" >/dev/null 2>&1
|
||||
LOG_OUT "Control Panel【$DASH_NAME - $DASH_TYPE】Download Successful!" && SLOG_CLEAN
|
||||
del_lock
|
||||
exit 0
|
||||
mkdir -p "$NEW_FILE_DIR" >/dev/null 2>&1 || log_unzip_error
|
||||
cp -rf "$DASH_FILE_TMP$FILE_PATH_INCLUDE"/. "$NEW_FILE_DIR" >/dev/null 2>&1 || log_unzip_error
|
||||
validate_dashboard_dir "$NEW_FILE_DIR" || log_unzip_error
|
||||
|
||||
mkdir -p "$TARGET_PARENT_DIR" >/dev/null 2>&1 || log_unzip_error
|
||||
if [ -d "$TARGET_FILE_DIR" ]; then
|
||||
mv "$TARGET_FILE_DIR" "$OLD_FILE_DIR" >/dev/null 2>&1 || log_unzip_error
|
||||
fi
|
||||
if mv "$NEW_FILE_DIR" "$TARGET_FILE_DIR" >/dev/null 2>&1 && validate_dashboard_dir "$TARGET_FILE_DIR"; then
|
||||
cleanup_dashboard_tmp
|
||||
LOG_OUT "Control Panel【$DASH_NAME - $DASH_TYPE】Download Successful!" && SLOG_CLEAN
|
||||
del_lock
|
||||
exit 0
|
||||
else
|
||||
restore_old_dashboard
|
||||
log_unzip_error
|
||||
fi
|
||||
else
|
||||
LOG_OUT "Control Panel【$DASH_NAME - $DASH_TYPE】Unzip Error!" && SLOG_CLEAN
|
||||
cp -rf "$BACKUP_FILE_DIR". "$UNPACK_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$DASH_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$BACKUP_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$DASH_FILE_TMP" >/dev/null 2>&1
|
||||
del_lock
|
||||
exit 2
|
||||
log_unzip_error
|
||||
fi
|
||||
else
|
||||
LOG_OUT "Control Panel【$DASH_NAME - $DASH_TYPE】Unzip Error!" && SLOG_CLEAN
|
||||
cp -rf "$BACKUP_FILE_DIR". "$UNPACK_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$DASH_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$BACKUP_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$DASH_FILE_TMP" >/dev/null 2>&1
|
||||
del_lock
|
||||
exit 2
|
||||
log_unzip_error
|
||||
fi
|
||||
elif [ "$DOWNLOAD_RESULT" -eq 2 ]; then
|
||||
LOG_OUT "Control Panel【$DASH_NAME - $DASH_TYPE】Download Successful!" && SLOG_CLEAN
|
||||
del_lock
|
||||
exit 0
|
||||
if validate_dashboard_dir "$UNPACK_FILE_DIR"; then
|
||||
cleanup_dashboard_tmp
|
||||
LOG_OUT "Control Panel【$DASH_NAME - $DASH_TYPE】Download Successful!" && SLOG_CLEAN
|
||||
del_lock
|
||||
exit 0
|
||||
else
|
||||
log_unzip_error
|
||||
fi
|
||||
else
|
||||
cp -rf "$BACKUP_FILE_DIR". "$UNPACK_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$BACKUP_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$DASH_FILE_DIR" >/dev/null 2>&1
|
||||
rm -rf "$DASH_FILE_TMP" >/dev/null 2>&1
|
||||
cleanup_dashboard_tmp
|
||||
LOG_OUT "Control Panel【$DASH_NAME - $DASH_TYPE】Download Error!" && SLOG_CLEAN
|
||||
del_lock
|
||||
exit 1
|
||||
|
||||
@@ -53,23 +53,23 @@ function unlock_auto_select()
|
||||
local only_original = "only support homemade!"
|
||||
local no_unlock = "not support unlock!"
|
||||
local select_success = "unlock node auto selected successfully, the current selected is"
|
||||
local select_faild = "unlock node auto selected failed, no node available, rolled back to the"
|
||||
local test_faild = "unlock test faild!"
|
||||
local select_failed = "unlock node auto selected failed, no node available, rolled back to the"
|
||||
local test_failed = "unlock test failed!"
|
||||
local test_start = "Start auto select unlock proxy..."
|
||||
local original_no_select = "only support homemade! the type of group is not select, auto select could not work!"
|
||||
local no_unlock_no_select = "not support unlock! the type of group is not select, auto select could not work!"
|
||||
local faild_no_select = "unlock test faild! the type of group is not select, auto select could not work!"
|
||||
local failed_no_select = "unlock test failed! the type of group is not select, auto select could not work!"
|
||||
local original_test_start = "only support homemade! start auto select unlock proxy..."
|
||||
local no_unlock_test_start = "not support unlock! start auto select unlock proxy..."
|
||||
local faild_test_start = "unlock test faild! start auto select unlock proxy..."
|
||||
local failed_test_start = "unlock test failed! start auto select unlock proxy..."
|
||||
local area_i18 = ", area:"
|
||||
local select_faild_other_region = "unlock node auto selected failed, no node match the regex, rolled back to other full support node"
|
||||
local select_failed_other_region = "unlock node auto selected failed, no node match the regex, rolled back to other full support node"
|
||||
local other_region_unlock_test = ", but not match the regex!"
|
||||
local other_region_unlock_no_select = ", but not match the regex! the type of group is not select, auto select could not work!"
|
||||
local other_region_unlock_test_start = ", but not match the regex! start auto select unlock proxy..."
|
||||
local select_all_full_support = "unlock node test finished, rolled back to the full support node"
|
||||
local select_all_other_region = "unlock node test finished, no node match the regex, rolled back to other full support node"
|
||||
local select_all_faild = "unlock node test finished, no node available, rolled back to the"
|
||||
local select_all_failed = "unlock node test finished, no node available, rolled back to the"
|
||||
local no_nodes_filter = "no nodes name match the regex!"
|
||||
local select_success_no_old_region = "unlock node auto selected successfully, no node match the old region, rolled back to other full support node"
|
||||
local no_old_region_unlock_test = "full support but not match the old region!"
|
||||
@@ -222,9 +222,9 @@ function unlock_auto_select()
|
||||
delete_cache(type, get_group_now(info, value.now))
|
||||
else
|
||||
if not all_test then
|
||||
print(now..faild_test_start)
|
||||
print(now..failed_test_start)
|
||||
else
|
||||
print(now..test_faild)
|
||||
print(now..test_failed)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -351,7 +351,7 @@ function unlock_auto_select()
|
||||
end
|
||||
delete_cache(type, proxy)
|
||||
else
|
||||
print(now..test_faild)
|
||||
print(now..test_failed)
|
||||
end
|
||||
end
|
||||
break
|
||||
@@ -429,7 +429,7 @@ function unlock_auto_select()
|
||||
end
|
||||
delete_cache(type, value.all[i])
|
||||
else
|
||||
print(now..faild_no_select)
|
||||
print(now..failed_no_select)
|
||||
end
|
||||
break
|
||||
end
|
||||
@@ -482,15 +482,15 @@ function unlock_auto_select()
|
||||
end
|
||||
elseif #other_region_unlock > 0 then
|
||||
if not all_test then
|
||||
print(os.date("%Y-%m-%d %H:%M:%S").." [Info] "..gorup_i18.."【"..value.name.."】"..select_faild_other_region..group_now)
|
||||
print(os.date("%Y-%m-%d %H:%M:%S").." [Info] "..gorup_i18.."【"..value.name.."】"..select_failed_other_region..group_now)
|
||||
else
|
||||
print(os.date("%Y-%m-%d %H:%M:%S").." [Info] "..gorup_i18.."【"..value.name.."】"..select_all_other_region..group_now)
|
||||
end
|
||||
else
|
||||
if not all_test then
|
||||
print(os.date("%Y-%m-%d %H:%M:%S").." [Info] "..gorup_i18.."【"..value.name.."】"..select_faild..group_now)
|
||||
print(os.date("%Y-%m-%d %H:%M:%S").." [Info] "..gorup_i18.."【"..value.name.."】"..select_failed..group_now)
|
||||
else
|
||||
print(os.date("%Y-%m-%d %H:%M:%S").." [Info] "..gorup_i18.."【"..value.name.."】"..select_all_faild..group_now)
|
||||
print(os.date("%Y-%m-%d %H:%M:%S").." [Info] "..gorup_i18.."【"..value.name.."】"..select_all_failed..group_now)
|
||||
end
|
||||
end
|
||||
close_connections()
|
||||
@@ -503,7 +503,7 @@ function unlock_auto_select()
|
||||
else
|
||||
group_now = value.name.." ➟ "..proxy_default
|
||||
end
|
||||
print(os.date("%Y-%m-%d %H:%M:%S").." [Info] "..gorup_i18.."【"..value.name.."】"..select_faild.."【"..group_now.."】")
|
||||
print(os.date("%Y-%m-%d %H:%M:%S").." [Info] "..gorup_i18.."【"..value.name.."】"..select_failed.."【"..group_now.."】")
|
||||
end
|
||||
end
|
||||
elseif #nodes_filter(get_group_now(info, value.name), info) ~= 0 then
|
||||
@@ -542,7 +542,7 @@ function unlock_auto_select()
|
||||
print(now..no_unlock_no_select)
|
||||
end
|
||||
else
|
||||
print(now..faild_no_select)
|
||||
print(now..failed_no_select)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -179,7 +179,7 @@ if [ -n "$OP_CV" ] && [ -n "$OP_LV" ] && version_compare "$OP_CV" "$OP_LV" && [
|
||||
update_retry=$((update_retry + 1))
|
||||
run_with_timeout 30 apk update >/dev/null 2>&1
|
||||
apk_ret=$?
|
||||
rm -f /lib/apk/db/lock /tmp/apk.lock
|
||||
rm -f /lib/apk/db/lock
|
||||
if [ $apk_ret -eq 0 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
@@ -54,12 +54,12 @@ begin
|
||||
provider_config = YAML.load_file(path, secret: provider['age-secret-key']) rescue nil
|
||||
rescue Exception => e
|
||||
YAML.LOG_WARN('Set Proxies Address Skip: Failed【' + path + ': ' + e.message+'】')
|
||||
continue
|
||||
next
|
||||
end
|
||||
else
|
||||
if file_is_age_encrypted
|
||||
if name == 'oixCloud'
|
||||
YAML.LOG_TIP('Set Proxies Address Skip: Bypass【oixCloud】')
|
||||
YAML.LOG('Set Proxies Address Skip: Bypass【oixCloud】')
|
||||
else
|
||||
YAML.LOG_WARN('Set Proxies Address Skip: Failed【' + path + '】File is AGE encrypted but no secret key provided')
|
||||
end
|
||||
@@ -73,7 +73,7 @@ begin
|
||||
servers_to_process.push(p['server']) if p.key?('server')
|
||||
end
|
||||
end
|
||||
rescue Psych::SyntaxError, ArgumentError
|
||||
rescue StandardError
|
||||
if not provider.key?('age-secret-key') or provider['age-secret-key'].to_s.empty?
|
||||
if file_is_age_encrypted
|
||||
YAML.LOG_WARN('Failed to parse config file with Lua helper【' + path + '】File is AGE encrypted, cannot parse with Lua')
|
||||
@@ -313,7 +313,7 @@ fi
|
||||
if [ -f "$upnp_lease_file" ]; then
|
||||
#del
|
||||
if [ -n "$FW4" ]; then
|
||||
for i in `$(nft list chain inet fw4 openclash_upnp |grep "return")`
|
||||
nft list chain inet fw4 openclash_upnp 2>/dev/null |grep "return" |while read -r i
|
||||
do
|
||||
upnp_ip=$(echo "$i" |awk -F 'ip saddr ' '{print $2}' |awk '{print $1}')
|
||||
upnp_dp=$(echo "$i" |awk -F 'sport ' '{print $2}' |awk '{print $1}')
|
||||
@@ -326,7 +326,7 @@ fi
|
||||
fi
|
||||
done >/dev/null 2>&1
|
||||
else
|
||||
for i in `$(iptables -t mangle -nL openclash_upnp |grep "RETURN")`
|
||||
iptables -t mangle -nL openclash_upnp 2>/dev/null |grep "RETURN" |while read -r i
|
||||
do
|
||||
upnp_ip=$(echo "$i" |awk '{print $4}')
|
||||
upnp_dp=$(echo "$i" |awk -F 'spt:' '{print $2}')
|
||||
@@ -339,7 +339,7 @@ fi
|
||||
done >/dev/null 2>&1
|
||||
fi
|
||||
#add
|
||||
if [ -s "$upnp_lease_file" ] && [ -n "$(iptables --line-numbers -t nat -xnvL openclash_upnp 2>/dev/null)"] || [ -n "$(nft list chain inet fw4 openclash_upnp 2>/dev/null)"]; then
|
||||
if [ -s "$upnp_lease_file" ] && { { [ -z "$FW4" ] && [ -n "$(iptables --line-numbers -t mangle -xnvL openclash_upnp 2>/dev/null)" ]; } || { [ -n "$FW4" ] && [ -n "$(nft list chain inet fw4 openclash_upnp 2>/dev/null)" ]; }; }; then
|
||||
cat "$upnp_lease_file" |while read -r line
|
||||
do
|
||||
if [ -n "$line" ]; then
|
||||
@@ -408,59 +408,59 @@ fi
|
||||
if [ "$STREAM_AUTO_SELECT" -ne 0 ]; then
|
||||
if [ "$(expr "$STREAM_AUTO_SELECT" % "$stream_auto_select_interval")" -eq 0 ] || [ "$STREAM_AUTO_SELECT" -eq 1 ]; then
|
||||
if [ "$stream_auto_select_netflix" -eq 1 ]; then
|
||||
LOG_TIP "【Netflix】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【Netflix】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "Netflix" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_disney" -eq 1 ]; then
|
||||
LOG_TIP "【Disney Plus】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【Disney Plus】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "Disney Plus" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_google_not_cn" -eq 1 ]; then
|
||||
LOG_TIP "【Google Not CN】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【Google Not CN】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "Google" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_ytb" -eq 1 ]; then
|
||||
LOG_TIP "【YouTube Premium】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【YouTube Premium】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "YouTube Premium" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_prime_video" -eq 1 ]; then
|
||||
LOG_TIP "【Amazon Prime Video】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【Amazon Prime Video】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "Amazon Prime Video" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_hbo_max" -eq 1 ]; then
|
||||
LOG_TIP "【HBO Max】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【HBO Max】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "HBO Max" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_tvb_anywhere" -eq 1 ]; then
|
||||
LOG_TIP "【TVB Anywhere+】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【TVB Anywhere+】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "TVB Anywhere+" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_dazn" -eq 1 ]; then
|
||||
LOG_TIP "【DAZN】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【DAZN】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "DAZN" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_paramount_plus" -eq 1 ]; then
|
||||
LOG_TIP "【Paramount Plus】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【Paramount Plus】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "Paramount Plus" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_discovery_plus" -eq 1 ]; then
|
||||
LOG_TIP "【Discovery Plus】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【Discovery Plus】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "Discovery Plus" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_bilibili" -eq 1 ]; then
|
||||
LOG_TIP "【Bilibili】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【Bilibili】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "Bilibili" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_openai" -eq 1 ]; then
|
||||
LOG_TIP "【OpenAI】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【OpenAI】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "OpenAI" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_claude" -eq 1 ]; then
|
||||
LOG_TIP "【Claude】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【Claude】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "Claude" >> $LOG_FILE
|
||||
fi
|
||||
if [ "$stream_auto_select_gemini" -eq 1 ]; then
|
||||
LOG_TIP "【Gemini】Start Auto Select Unlock Proxy..."
|
||||
LOG_INFO "【Gemini】Start Auto Select Unlock Proxy..."
|
||||
/usr/share/openclash/openclash_streaming_unlock.lua "Gemini" >> $LOG_FILE
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -810,6 +810,10 @@ begin
|
||||
rescue Exception => e
|
||||
YAML.LOG_ERROR('Config File Overwrite Failed,【%s】' % [e.message])
|
||||
ensure
|
||||
File.open(config_file, 'w') { |f| YAML.dump(Value, f) }
|
||||
begin
|
||||
File.open(config_file, 'w') { |f| YAML.dump(Value, f) }
|
||||
rescue Exception => e
|
||||
YAML.LOG_ERROR('Write file failed:【%s】' % [e.message])
|
||||
end
|
||||
end
|
||||
" 2>/dev/null >> $LOG_FILE
|
||||
@@ -424,7 +424,11 @@ yml_other_set()
|
||||
rescue Exception => e
|
||||
YAML.LOG_ERROR('Config File Overwrite Failed,【%s】' % [e.message])
|
||||
ensure
|
||||
File.open('$2','w') {|f| YAML.dump(Value, f)};
|
||||
begin
|
||||
File.open('$2','w') {|f| YAML.dump(Value, f)};
|
||||
rescue Exception => e
|
||||
YAML.LOG_ERROR('Write file failed:【%s】' % [e.message])
|
||||
end
|
||||
end" 2>/dev/null >> $LOG_FILE
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user