-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrestore_https.sh
More file actions
187 lines (168 loc) · 5.82 KB
/
Copy pathrestore_https.sh
File metadata and controls
187 lines (168 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# Orbitra HTTPS Configuration Recovery Script
# Restores full Nginx config with HTTPS blocks for domains with SSL
set -e
echo "Orbitra HTTPS Configuration Recovery"
echo "====================================="
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root (use sudo)"
exit 1
fi
# Check if orbitra directory exists
if [ ! -d "/var/www/orbitra" ]; then
echo "ERROR: /var/www/orbitra not found"
exit 1
fi
# Check if database exists
if [ ! -f "/var/www/orbitra/orbitra_db.sqlite" ]; then
echo "ERROR: Database not found"
exit 1
fi
echo "Checking for SSL certificates..."
# Find all domains with SSL certificates
SSL_DOMAINS=()
for cert_dir in /etc/letsencrypt/live/*/; do
if [ -d "$cert_dir" ]; then
domain=$(basename "$cert_dir")
if [ "$domain" != "README" ] && [ -f "$cert_dir/fullchain.pem" ]; then
SSL_DOMAINS+=("$domain")
fi
fi
done
if [ ${#SSL_DOMAINS[@]} -eq 0 ]; then
echo "No SSL certificates found. Only HTTP config will be generated."
HAS_SSL=false
else
echo "Found SSL certificates for domains:"
for domain in "${SSL_DOMAINS[@]}"; do
echo " - $domain"
done
HAS_SSL=true
fi
# Get PHP version
PHP_V=$(php -v | head -n 1 | cut -d " " -f 2 | cut -f1-2 -d".")
PHP_FPM_SOCK="/var/run/php/php${PHP_V}-fpm.sock"
# Get all domains from database (fallback)
ALL_DOMAINS=$(sqlite3 /var/www/orbitra/orbitra_db.sqlite "SELECT name FROM domains WHERE name IS NOT NULL AND name != '' ORDER BY name" 2>/dev/null || echo "")
echo "Generating Nginx configuration..."
# Generate config file
CONFIG_FILE="/etc/nginx/sites-available/orbitra"
# Write HTTP server block
{
echo "# Auto-generated by Orbitra - DO NOT EDIT MANUALLY"
echo ""
echo "server {"
echo " listen 80 default_server;"
echo " server_name _;"
# Add domains from database
if [ -n "$ALL_DOMAINS" ]; then
echo "$ALL_DOMAINS" | while read -r domain; do
if [ -n "$domain" ]; then
echo " server_name _ $domain;"
fi
done
fi
echo " root /var/www/orbitra;"
echo " index index.php admin.php index.html;"
echo ""
echo " # Access to React/Vite static files"
echo " location /frontend/dist/ {"
echo " alias /var/www/orbitra/frontend/dist/;"
echo " try_files \$uri \$uri/ /frontend/dist/index.html;"
echo " }"
echo ""
echo " # Router handling (API and clicks)"
echo " location / {"
echo " try_files \$uri \$uri/ /index.php?\$query_string;"
echo " }"
echo ""
echo " # Allow large file uploads for Geo DB"
echo " client_max_body_size 256m;"
echo ""
echo " # PHP processing"
echo " location ~ \.php$ {"
echo " include snippets/fastcgi-php.conf;"
echo " fastcgi_pass unix:$PHP_FPM_SOCK;"
echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;"
echo " include fastcgi_params;"
echo " }"
echo ""
echo " # Deny access to SQLite DB and configurations"
echo " location ~ \.sqlite$ {"
echo " deny all;"
echo " }"
echo " location ~ /\. {"
echo " deny all;"
echo " }"
echo "}"
} > "$CONFIG_FILE"
# Append HTTPS server blocks for domains with SSL
if [ "$HAS_SSL" = true ]; then
for domain in "${SSL_DOMAINS[@]}"; do
{
echo ""
echo "server {"
echo " listen 443 ssl;"
echo " server_name $domain;"
echo ""
echo " # SSL certificates"
echo " ssl_certificate /etc/letsencrypt/live/$domain/fullchain.pem;"
echo " ssl_certificate_key /etc/letsencrypt/live/$domain/privkey.pem;"
echo " include /etc/letsencrypt/options-ssl-nginx.conf;"
echo " ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;"
echo ""
echo " root /var/www/orbitra;"
echo " index index.php admin.php index.html;"
echo ""
echo " # Access to React/Vite static files"
echo " location /frontend/dist/ {"
echo " alias /var/www/orbitra/frontend/dist/;"
echo " try_files \$uri \$uri/ /frontend/dist/index.html;"
echo " }"
echo ""
echo " # Router handling (API and clicks)"
echo " location / {"
echo " try_files \$uri \$uri/ /index.php?\$query_string;"
echo " }"
echo ""
echo " # Allow large file uploads for Geo DB"
echo " client_max_body_size 256m;"
echo ""
echo " # PHP processing"
echo " location ~ \.php$ {"
echo " include snippets/fastcgi-php.conf;"
echo " fastcgi_pass unix:$PHP_FPM_SOCK;"
echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;"
echo " include fastcgi_params;"
echo " }"
echo ""
echo " # Deny access to SQLite DB and configurations"
echo " location ~ \.sqlite$ {"
echo " deny all;"
echo " }"
echo " location ~ /\. {"
echo " deny all;"
echo " }"
echo "}"
} >> "$CONFIG_FILE"
done
fi
# Test and reload Nginx
echo "Testing Nginx configuration..."
nginx -t
echo "Reloading Nginx..."
systemctl reload nginx
echo ""
echo "✅ HTTPS configuration restored successfully!"
echo ""
if [ "$HAS_SSL" = true ]; then
echo "HTTPS enabled for domains:"
for domain in "${SSL_DOMAINS[@]}"; do
echo " https://$domain"
done
fi
echo ""
echo "Test your campaign:"
echo " curl -I https://orbitra.net.ru/t6wa4f"
echo ""