Обновлена логика загрузки index.php

This commit is contained in:
2025-08-10 02:32:15 +03:00
parent 6b6fa15302
commit a35a1849b7

View File

@@ -314,55 +314,23 @@ echo "</html>";
EOF
}
if ! curl -f -s --max-time 10 --head "$DOWNLOAD_URL" >/dev/null 2>&1; then
find "$WEBROOT" -type f ! -name "db_config.php" -delete 2>/dev/null || true
if curl -f -L --max-time 30 -o "$WEBROOT/index.php" "$DOWNLOAD_URL" 2>/dev/null; then
if ! head -n 1 "$WEBROOT/index.php" | grep -q "<?php" && ! grep -q "<?php" "$WEBROOT/index.php" 2>/dev/null; then
create_fallback_index
log_error "Скачанный файл не является PHP-скриптом, создана резервная страница"
else
log_success "Файл index.php успешно загружен"
fi
else
find "$WEBROOT" -type f ! -name "db_config.php" -delete 2>/dev/null || true
if curl -f -L --max-time 30 -o "$TEMP_DOWNLOAD" "$DOWNLOAD_URL" 2>/dev/null; then
FILE_TYPE=$(file -b "$TEMP_DOWNLOAD" 2>/dev/null || echo "unknown")
if file "$TEMP_DOWNLOAD" | grep -qi "zip\|archive"; then
if unzip -q "$TEMP_DOWNLOAD" -d "$WEBROOT" 2>/dev/null; then
true
else
unzip -o "$TEMP_DOWNLOAD" -d "$WEBROOT" >/dev/null 2>&1 || create_fallback_index
fi
elif file "$TEMP_DOWNLOAD" | grep -qi "gzip"; then
if gunzip -c "$TEMP_DOWNLOAD" > "$WEBROOT/index.php" 2>/dev/null; then
true
else
create_fallback_index
fi
elif head -n 1 "$TEMP_DOWNLOAD" | grep -q "<?php\|<!DOCTYPE\|<html"; then
cp "$TEMP_DOWNLOAD" "$WEBROOT/index.php"
elif head -n 1 "$TEMP_DOWNLOAD" | grep -q "{"; then
create_fallback_index
else
if head -10 "$TEMP_DOWNLOAD" | grep -qi "error\|404\|403\|500\|<title"; then
create_fallback_index
else
cp "$TEMP_DOWNLOAD" "$WEBROOT/index.php"
fi
fi
rm -f "$TEMP_DOWNLOAD"
else
if curl -L -k --user-agent "Mozilla/5.0 (Linux) Setup Script" --max-time 30 -o "$TEMP_DOWNLOAD" "$DOWNLOAD_URL" 2>/dev/null; then
cp "$TEMP_DOWNLOAD" "$WEBROOT/downloaded_file"
rm -f "$TEMP_DOWNLOAD"
fi
create_fallback_index
fi
log_error "Не удалось загрузить файл с $DOWNLOAD_URL, создана резервная страница"
fi
chown $WEBSERVER_USER:$WEBSERVER_USER "$WEBROOT/index.php"
chmod 644 "$WEBROOT/index.php"
cat > "$WEBROOT/.htaccess" << 'EOF'
<Files "db_config.php">
Require all denied