Merge pull request #114 from n00zJS6tl0/dev

Ускорение перебора test_domain() и фикс итогов (к сожалению навайбкожено)
This commit is contained in:
Luna River
2026-02-06 09:29:54 +03:00
committed by GitHub
2 changed files with 52 additions and 37 deletions

View File

@@ -151,7 +151,7 @@ configure_zapret_conf() {
if [[ -d /opt/zapret/zapret.cfgs ]]; then
echo "Проверяю наличие на обновление конфигураций..."
manage_service stop
cd /opt/zapret/zapret.cfgs && git checkout main && git fetch origin main && git restore .
cd /opt/zapret.installer && git fetch origin && git checkout -B main origin/main && git reset --hard origin/main
manage_service start
sleep 2
fi
@@ -195,7 +195,7 @@ configure_zapret_list() {
if [[ -d /opt/zapret/zapret.cfgs ]]; then
echo "Проверяю наличие на обновление конфигураций..."
manage_service stop
cd /opt/zapret/zapret.cfgs && git checkout main && git fetch origin main && git restore .
cd /opt/zapret.installer && git fetch origin && git checkout -B main origin/main && git reset --hard origin/main
manage_service start
sleep 2
fi
@@ -456,38 +456,53 @@ search_in_zapret_exc() {
test_domain() {
local domain="$1"
local results=()
domain=$(echo "$domain" | sed 's/#.*//' | xargs)
[[ -z "$domain" ]] && return
# Временный файл для хранения результатов
local r_file="$(mktemp)"
# FAIL - результат по-умолчанию для ping http tls1.2 tls1.3 (построчно)
echo -en "FAIL\nFAIL\nFAIL\nFAIL" > "$r_file"
# Таймауты
local t_ping=2
local t_http=5
if [[ "$domain" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
test_ip "$domain"
else
ping_result=$(ping -c 2 -W 2 "$domain" 2>/dev/null | grep -E "rtt min/avg/max/mdev" | awk -F'/' '{print $5}')
if [[ -n "$ping_result" ]]; then
results+=("${ping_result}ms")
else
results+=("FAIL")
fi
http_result=$(timeout 5 curl -s -o /dev/null -w "%{http_code}" "http://$domain" 2>/dev/null || echo "FAIL")
if [[ "$http_result" =~ ^[0-9]+$ ]]; then
results+=("HTTP:$http_result")
else
results+=("FAIL")
fi
tls12_result=$(timeout 5 curl -s -o /dev/null -w "%{http_code}" --tlsv1.2 "https://$domain" 2>/dev/null || echo "FAIL")
if [[ "$tls12_result" =~ ^[0-9]+$ ]]; then
results+=("TLS1.2:$tls12_result")
else
results+=("FAIL")
fi
tls13_result=$(timeout 5 curl -s -o /dev/null -w "%{http_code}" --tlsv1.3 "https://$domain" 2>/dev/null || echo "FAIL")
if [[ "$tls13_result" =~ ^[0-9]+$ ]]; then
results+=("TLS1.3:$tls13_result")
else
results+=("FAIL")
fi
# Асинхронно запустим ping, http и https.
# sed запишет результат строго в указанную строку
{
result=$(ping -c 2 -W $t_ping "$domain" 2>/dev/null | grep -E "rtt min/avg/max/mdev" | awk -F'/' '{print $5}')
if [[ -n "$result" ]]; then
sed -i "1c\\${result}ms" "$r_file"
fi
} &
{
result=$(curl -m $t_http -s -o /dev/null -w "%{http_code}" "http://$domain" 2>/dev/null || echo "FAIL")
if [[ "$result" =~ ^[0-9]+$ ]]; then
sed -i "2c\\HTTP:$result" "$r_file"
fi
} &
# https будет синхронным - в обоих случаях подключение идет по одному и тому же порту (443)
# и будет некорректно запускать оба подключения одновременно.
{
result=$(curl -m $t_http -s -o /dev/null -w "%{http_code}" --tlsv1.2 "https://$domain" 2>/dev/null || echo "FAIL")
if [[ "$result" =~ ^[0-9]+$ ]]; then
sed -i "3c\\TLS1.2:$result" "$r_file"
fi
result=$(curl -m $t_http -s -o /dev/null -w "%{http_code}" --tlsv1.3 "https://$domain" 2>/dev/null || echo "FAIL")
if [[ "$result" =~ ^[0-9]+$ ]]; then
sed -i "4c\\TLS1.3:$result" "$r_file"
fi
} &
fi
echo "${results[@]}"
# Ждем окончания всех запросов, объединяем строки с результатами в одну, удаляем временный файл
wait
echo $(paste -sd ' ' "$r_file")
rm -f "$r_file"
}
test_ip() {
@@ -728,8 +743,8 @@ check_conf() {
echo -e "\e[42m\e[30m║ ИТОГОВЫЙ РЕЗУЛЬТАТ ║\e[0m"
echo -e "\e[42m\e[30m╠══════════════════════════════════════════════════════════════════════════╣\e[0m"
echo -e "\e[42m\e[30m║ ║\e[0m"
printf "\e[42m\e[30m║ Лучшая стратегия: %-52s ║\n\e[0m" "$best_config"
printf "\e[42m\e[30m║ Доступно доменов/IP: %-3d из %-3d (%.1f%%) ║\n\e[0m" "$best_available" "$total_domains" $(echo "scale=1; $best_available * 100 / $total_domains" | bc)
printf "\e[42m\e[30m║ Лучшая стратегия: %-50s ║\n\e[0m" "$best_config"
printf "\e[42m\e[30m║ Доступно доменов/IP: %-52s ║\n\e[0m" "$best_available из $total_domains ($(echo "scale=1; $best_available * 100 / $total_domains" | bc)%)"
echo -e "\e[42m\e[30m║ ║\e[0m"
echo -e "\e[42m\e[30m╚══════════════════════════════════════════════════════════════════════════╝\e[0m"
echo ""

View File

@@ -260,7 +260,7 @@ update_zapret() {
yes "" | ./install_easy.sh
sed -i '238s/ask_yes_no Y/ask_yes_no N/' /opt/zapret/common/installer.sh
else
cd /opt/zapret/ && git checkout master && git fetch origin master && git restore . || error_exit "не удалось обновить zapret с помощью git. Попробуйте снова, вероятно это сетевая ошибка. Если не помогло - переустановите zapret."
cd /opt/zapret && git fetch origin && git checkout -B master origin/master && git reset --hard origin/master || error_exit "не удалось обновить zapret с помощью git. Попробуйте снова, вероятно это сетевая ошибка. Если не помогло - переустановите zapret."
echo -e "Репозиторий запрета был обновлен."
fi
else
@@ -273,10 +273,10 @@ update_zapret() {
fi
if [[ -d /opt/zapret/zapret.cfgs ]]; then
cd /opt/zapret/zapret.cfgs && git checkout main && git fetch origin main && git restore .
cd /opt/zapret.cfgs && git fetch origin && git checkout -B main origin/main && git reset --hard origin/main
fi
if [[ -d /opt/zapret.installer/ ]]; then
cd /opt/zapret.installer/ && git checkout main && git fetch origin main && git restore .
cd /opt/zapret.installer && git fetch origin && git checkout -B main origin/main && git reset --hard origin/main
rm -f /bin/zapret
ln -s /opt/zapret.installer/zapret-control.sh /bin/zapret || error_exit "не удалось создать символическую ссылку"
fi
@@ -305,10 +305,10 @@ update_zapret() {
update_script() {
if [[ -d /opt/zapret/zapret.cfgs ]]; then
cd /opt/zapret/zapret.cfgs && git checkout main && git fetch origin main && git restore .
cd /opt/zapret.cfgs && git fetch origin && git checkout -B main origin/main && git reset --hard origin/main
fi
if [[ -d /opt/zapret.installer/ ]]; then
cd /opt/zapret.installer/ && git checkout main && git fetch origin main && git restore .
cd /opt/zapret.installer && git fetch origin && git checkout -B main origin/main && git reset --hard origin/main
fi
rm -f /bin/zapret
ln -s /opt/zapret.installer/zapret-control.sh /bin/zapret || error_exit "не удалось создать символическую ссылку"
@@ -318,10 +318,10 @@ update_script() {
update_installed_script() {
if [[ -d /opt/zapret/zapret.cfgs ]]; then
cd /opt/zapret/zapret.cfgs && git checkout main && git fetch origin main && git restore .
cd /opt/zapret.cfgs && git fetch origin && git checkout -B main origin/main && git reset --hard origin/main
fi
if [[ -d /opt/zapret.installer/ ]]; then
cd /opt/zapret.installer/ && git checkout main && git fetch origin main && git restore .
cd /opt/zapret.installer && git fetch origin && git checkout -B main origin/main && git reset --hard origin/main
rm -f /bin/zapret
ln -s /opt/zapret.installer/zapret-control.sh /bin/zapret || error_exit "не удалось создать символическую ссылку"
manage_service restart