1
Offline regression tests / windows (3.11) (push) Canceled after 0s
Offline regression tests / windows (3.12) (push) Canceled after 0s
Offline regression tests / windows (3.13) (push) Canceled after 0s

This commit is contained in:
listik committed 2026-10-23 23:38:37 +03:00
1 parent 3ae4e18211
commit 730adb3ff2
9 files changed
+206 -33

No files matched your search

+66 -7
View File
@@ -14,16 +14,28 @@ NGINX_SITE="/etc/nginx/sites-available/crypto-scam-app"
NGINX_ENABLED="/etc/nginx/sites-enabled/crypto-scam-app"
SERVICE_FILE="/etc/systemd/system/crypto-scam.service"
DOMAIN="${1:-}"
EMAIL="${2:-}"
MODE="certbot"
EMAIL=""
PUBLIC_URL=""
if [[ "${2:-}" == "--tls-proxy" ]]; then
MODE="tls-proxy"
PUBLIC_URL="${3:-}"
else
EMAIL="${2:-}"
fi
if [[ ! "$DOMAIN" =~ ^[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ ]]; then
echo "Укажите домен, уже направленный DNS-записями на этот сервер: $0 example.com admin@example.com" >&2
exit 2
fi
if [[ ! "$EMAIL" =~ ^[^[:space:]@]+@[^[:space:]@]+\.[^[:space:]@]+$ ]]; then
if [[ "$MODE" == "certbot" && ! "$EMAIL" =~ ^[^[:space:]@]+@[^[:space:]@]+\.[^[:space:]@]+$ ]]; then
echo "Укажите email для уведомлений Let's Encrypt: $0 example.com admin@example.com" >&2
exit 2
fi
if [[ "$MODE" == "tls-proxy" && ! "$PUBLIC_URL" =~ ^https://$DOMAIN:[0-9]{1,5}$ ]]; then
echo "Для TLS-шлюза укажите внешний HTTPS URL с портом, например: $0 zdfn.my.to --tls-proxy https://zdfn.my.to:25590" >&2
exit 2
fi
if [[ -e "$NGINX_SITE" ]] && ! grep -q 'Managed by Crypto Scam deploy.sh' "$NGINX_SITE"; then
echo "$NGINX_SITE уже занят другой конфигурацией; не перезаписываю его." >&2
exit 3
@@ -51,7 +63,11 @@ fi
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y nginx certbot python3-certbot-nginx python3-venv python3-tk python3-cryptography rsync apache2-utils
PACKAGES=(nginx python3-venv python3-tk python3-cryptography rsync apache2-utils)
if [[ "$MODE" == "certbot" ]]; then
PACKAGES+=(certbot python3-certbot-nginx)
fi
apt-get install -y "${PACKAGES[@]}"
if ! id "$SERVICE_USER" >/dev/null 2>&1; then
useradd --system --home-dir "$DATA_DIR" --create-home --shell /usr/sbin/nologin "$SERVICE_USER"
@@ -87,6 +103,7 @@ chmod -R u=rwX,g=,o= "$DATA_DIR"
# Managed by Crypto Scam deploy.sh
cat > "$SERVICE_FILE" <<EOF
# Managed by Crypto Scam deploy.sh
[Unit]
Description=Crypto Scam multi-user web simulator
After=network-online.target
@@ -100,6 +117,7 @@ WorkingDirectory=$APP_DIR
Environment=PYTHONUNBUFFERED=1
Environment=PYTHONDONTWRITEBYTECODE=1
Environment=CRYPTO_SCAM_PUBLIC_HOST=$DOMAIN
Environment=CRYPTO_SCAM_PUBLIC_PORT=$(if [[ "$MODE" == "tls-proxy" ]]; then printf '%s' "${PUBLIC_URL##*:}"; else printf '443'; fi)
Environment=CRYPTO_SCAM_MASTER_KEY_FILE=/etc/crypto-scam/master.key
UMask=0077
ExecStart=$APP_DIR/.venv/bin/python -B web_proxy.py
@@ -130,8 +148,38 @@ chown root:www-data /etc/nginx/crypto-scam/htpasswd
chmod 0640 /etc/nginx/crypto-scam/htpasswd
unset GATE_PASSWORD
if [[ "$MODE" == "tls-proxy" ]]; then
# TLS terminates at the hosting gateway; it must proxy HTTPS-only traffic to this private HTTP listener.
# Do not expose a separate plaintext route from the internet to container port 80 in this mode.
# Managed by Crypto Scam deploy.sh
cat > "$NGINX_SITE" <<EOF
# Managed by Crypto Scam deploy.sh
server {
listen 80;
listen [::]:80;
server_name $DOMAIN;
auth_basic "Crypto Scam server access";
auth_basic_user_file /etc/nginx/crypto-scam/htpasswd;
client_max_body_size 128k;
location / {
proxy_pass http://127.0.0.1:8765;
proxy_http_version 1.1;
proxy_set_header Host \$host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header Connection "";
proxy_read_timeout 75s;
proxy_send_timeout 75s;
}
}
EOF
else
# Managed by Crypto Scam deploy.sh
cat > "$NGINX_SITE" <<EOF
# Managed by Crypto Scam deploy.sh
cat > "$NGINX_SITE" <<EOF
server {
listen 80;
listen [::]:80;
@@ -139,13 +187,17 @@ server {
location / { return 404; }
}
EOF
fi
ln -sfn "$NGINX_SITE" /etc/nginx/sites-enabled/crypto-scam-app
nginx -t
systemctl reload nginx
certbot certonly --nginx --non-interactive --agree-tos --email "$EMAIL" -d "$DOMAIN"
if [[ "$MODE" == "certbot" ]]; then
certbot certonly --nginx --non-interactive --agree-tos --email "$EMAIL" -d "$DOMAIN"
# Managed by Crypto Scam deploy.sh
cat > "$NGINX_SITE" <<EOF
# Managed by Crypto Scam deploy.sh
cat > "$NGINX_SITE" <<EOF
server {
listen 80;
listen [::]:80;
@@ -179,12 +231,19 @@ server {
}
}
EOF
fi
nginx -t
systemctl reload nginx
systemctl restart crypto-scam.service
echo
echo "Готово: https://$DOMAIN"
if [[ "$MODE" == "tls-proxy" ]]; then
echo "Готово после настройки TLS-шлюза: $PUBLIC_URL"
echo "Шлюз должен передавать Host=$DOMAIN и проксировать HTTPS на http://192.168.144.115:80."
else
echo "Готово: https://$DOMAIN"
fi
echo "Сначала браузер спросит общий Basic Auth пароль, затем откроется форма входа Crypto Scam."
echo "Статус сервера: systemctl status crypto-scam nginx"
echo "Логи: journalctl -u crypto-scam -f"