@powerhousedao/ph-cli 2.5.0-dev.0 → 2.5.0-dev.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/ph-cli",
3
- "version": "2.5.0-dev.0",
3
+ "version": "2.5.0-dev.10",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",
@@ -20,7 +20,8 @@ else
20
20
  # =============================================================================
21
21
  # Package Installation
22
22
  # =============================================================================
23
- sudo apt install -y postgresql postgresql-contrib nginx
23
+ sudo apt install -y postgresql postgresql-contrib nginx libnginx-mod-http-brotli-static libnginx-mod-http-brotli-filter
24
+ sudo sed -i 's/# gzip_vary/gzip_vary/; s/# gzip_proxied/gzip_proxied/; s/# gzip_comp_level/gzip_comp_level/; s/# gzip_buffers/gzip_buffers/; s/# gzip_http_version/gzip_http_version/; s/# gzip_types/gzip_types/' /etc/nginx/nginx.conf
24
25
 
25
26
  # =============================================================================
26
27
  # Interactive Package Installation
@@ -112,6 +113,23 @@ EOF
112
113
  echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
113
114
  echo " SSL Configuration"
114
115
  echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
116
+
117
+ # Add compression settings to nginx.conf if not exists
118
+ if ! grep -q "brotli_comp_level" /etc/nginx/nginx.conf || ! grep -q "gzip_comp_level" /etc/nginx/nginx.conf; then
119
+ echo "Adding compression settings to nginx.conf..."
120
+ # Find the http block in nginx.conf
121
+ if ! grep -q "brotli_comp_level" /etc/nginx/nginx.conf; then
122
+ sudo sed -i '/http {/a \ # Brotli compression\n brotli on;\n brotli_comp_level 6;\n brotli_types text/plain text/css application/javascript application/json image/svg+xml application/xml+rss;\n brotli_static on;' /etc/nginx/nginx.conf
123
+ fi
124
+ if ! grep -q "gzip_comp_level" /etc/nginx/nginx.conf; then
125
+ sudo sed -i '/http {/a \ # Gzip compression\n gzip on;\n gzip_vary on;\n gzip_proxied any;\n gzip_comp_level 6;\n gzip_buffers 16 8k;\n gzip_http_version 1.1;\n gzip_types text/plain text/css application/javascript application/json image/svg+xml application/xml+rss;' /etc/nginx/nginx.conf
126
+ fi
127
+ else
128
+ echo "Compression settings already present in nginx.conf"
129
+ fi
130
+
131
+
132
+
115
133
  echo "Choose SSL configuration:"
116
134
  echo "1) Let's Encrypt certificates for domains"
117
135
  echo "2) Self-signed certificate for machine hostname"
@@ -129,104 +147,58 @@ EOF
129
147
  echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
130
148
  read -p "Enter Connect domain (e.g. connect.google.com): " connect_domain
131
149
  read -p "Enter Switchboard domain (e.g. switchboard.google.com): " switchboard_domain
150
+ read -p "Enter admin email for Let's Encrypt notifications: " admin_email
132
151
 
133
152
  echo "Using domains:"
134
153
  echo "Connect: $connect_domain"
135
154
  echo "Switchboard: $switchboard_domain"
136
155
 
137
- # Generate temporary SSL certificates
138
- echo "Generating temporary SSL certificates..."
139
- sudo mkdir -p /etc/nginx/ssl
140
- sudo openssl req -x509 -nodes -days 1 -newkey rsa:2048 \
141
- -keyout /etc/nginx/ssl/temp.key \
142
- -out /etc/nginx/ssl/temp.crt \
143
- -subj "/CN=$connect_domain" \
144
- -addext "subjectAltName = DNS:$connect_domain,DNS:$switchboard_domain"
145
-
146
- # Check if Nginx configuration already exists
147
- if [ -f "/etc/nginx/sites-available/$PROJECT_NAME" ]; then
148
- echo "Nginx configuration for $PROJECT_NAME already exists"
149
- read -p "Do you want to overwrite it? (y/n): " overwrite_nginx
150
- if [ "$overwrite_nginx" != "y" ]; then
151
- echo "Keeping existing Nginx configuration"
152
- else
153
- # Create Nginx configuration for domains
154
- echo "Creating Nginx configuration..."
155
- sudo tee /etc/nginx/sites-available/$PROJECT_NAME > /dev/null << EOF
156
- # Security headers
157
- add_header Strict-Transport-Security "max-age=63072000" always;
158
- add_header X-Frame-Options DENY;
159
- add_header X-Content-Type-Options nosniff;
160
- add_header X-XSS-Protection "1; mode=block";
161
-
156
+ # Create initial Nginx configuration for certbot
157
+ echo "Creating initial Nginx configuration..."
158
+ sudo tee /etc/nginx/sites-available/$PROJECT_NAME > /dev/null << EOF
162
159
  server {
163
160
  listen 80;
164
161
  server_name $connect_domain $switchboard_domain;
165
- return 301 https://\$host\$request_uri;
166
- }
167
-
168
- server {
169
- listen 443 ssl http2;
170
- server_name $connect_domain;
171
-
172
- ssl_certificate /etc/nginx/ssl/temp.crt;
173
- ssl_certificate_key /etc/nginx/ssl/temp.key;
174
-
175
- # SSL configuration
176
- ssl_protocols TLSv1.2 TLSv1.3;
177
- ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
178
- ssl_prefer_server_ciphers off;
179
- ssl_session_timeout 1d;
180
- ssl_session_cache shared:SSL:50m;
181
- ssl_session_tickets off;
182
- ssl_stapling on;
183
- ssl_stapling_verify on;
184
-
185
- if (\$http_x_forwarded_proto = "http") {
186
- return 301 https://\$server_name\$request_uri;
187
- }
188
162
 
189
163
  location / {
190
- root $PWD/.ph/connect-build/dist;
164
+ root /var/www/html/$PROJECT_NAME;
191
165
  try_files \$uri \$uri/ /index.html;
192
- add_header Cache-Control "no-cache";
193
- add_header X-Forwarded-Proto \$scheme;
194
- add_header X-Forwarded-Host \$host;
195
- add_header X-Forwarded-Port \$server_port;
196
166
  }
197
- }
198
167
 
199
- server {
200
- listen 443 ssl http2;
201
- server_name $switchboard_domain;
202
-
203
- ssl_certificate /etc/nginx/ssl/temp.crt;
204
- ssl_certificate_key /etc/nginx/ssl/temp.key;
205
-
206
- location / {
207
- proxy_pass http://localhost:4001;
208
- proxy_http_version 1.1;
209
- proxy_set_header Upgrade \$http_upgrade;
210
- proxy_set_header Connection 'upgrade';
211
- proxy_set_header Host \$host;
212
- proxy_cache_bypass \$http_upgrade;
213
- proxy_set_header X-Real-IP \$remote_addr;
214
- proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
215
- proxy_set_header X-Forwarded-Proto \$scheme;
168
+ location /.well-known/acme-challenge/ {
169
+ root /var/www/html;
216
170
  }
217
171
  }
218
172
  EOF
219
- fi
220
- else
221
- # Create Nginx configuration for domains
222
- echo "Creating Nginx configuration..."
223
- sudo tee /etc/nginx/sites-available/$PROJECT_NAME > /dev/null << EOF
224
- # Security headers
225
- add_header Strict-Transport-Security "max-age=63072000" always;
226
- add_header X-Frame-Options DENY;
227
- add_header X-Content-Type-Options nosniff;
228
- add_header X-XSS-Protection "1; mode=block";
229
173
 
174
+ # Enable the site
175
+ sudo ln -sf /etc/nginx/sites-available/$PROJECT_NAME /etc/nginx/sites-enabled/
176
+ sudo rm -f /etc/nginx/sites-enabled/default
177
+
178
+ # Test Nginx configuration
179
+ sudo nginx -t
180
+
181
+ # Restart Nginx to apply changes
182
+ sudo systemctl restart nginx
183
+
184
+ # Obtain SSL certificates
185
+ echo "Obtaining SSL certificates..."
186
+ sudo certbot --nginx -d $connect_domain --non-interactive --agree-tos --email $admin_email --redirect
187
+ sudo certbot --nginx -d $switchboard_domain --non-interactive --agree-tos --email $admin_email --redirect
188
+
189
+ # Wait for certbot to finish and certificates to be installed
190
+ sleep 5
191
+
192
+ # Check if certificates were installed
193
+ if [ ! -f "/etc/letsencrypt/live/$connect_domain/fullchain.pem" ] || [ ! -f "/etc/letsencrypt/live/$switchboard_domain/fullchain.pem" ]; then
194
+ echo "Error: SSL certificates were not installed properly"
195
+ echo "Please check the certbot logs at /var/log/letsencrypt/letsencrypt.log"
196
+ exit 1
197
+ fi
198
+
199
+ # Update Nginx configuration with proper SSL settings
200
+ echo "Updating Nginx configuration with SSL settings..."
201
+ sudo tee /etc/nginx/sites-available/$PROJECT_NAME > /dev/null << EOF
230
202
  server {
231
203
  listen 80;
232
204
  server_name $connect_domain $switchboard_domain;
@@ -234,11 +206,12 @@ server {
234
206
  }
235
207
 
236
208
  server {
237
- listen 443 ssl http2;
209
+ listen 443 ssl;
210
+ http2 on;
238
211
  server_name $connect_domain;
239
212
 
240
- ssl_certificate /etc/nginx/ssl/temp.crt;
241
- ssl_certificate_key /etc/nginx/ssl/temp.key;
213
+ ssl_certificate /etc/letsencrypt/live/$connect_domain/fullchain.pem;
214
+ ssl_certificate_key /etc/letsencrypt/live/$connect_domain/privkey.pem;
242
215
 
243
216
  # SSL configuration
244
217
  ssl_protocols TLSv1.2 TLSv1.3;
@@ -249,6 +222,14 @@ server {
249
222
  ssl_session_tickets off;
250
223
  ssl_stapling on;
251
224
  ssl_stapling_verify on;
225
+ resolver 8.8.8.8 8.8.4.4 valid=300s;
226
+ resolver_timeout 5s;
227
+
228
+ # Security headers
229
+ add_header Strict-Transport-Security "max-age=63072000" always;
230
+ add_header X-Frame-Options DENY;
231
+ add_header X-Content-Type-Options nosniff;
232
+ add_header X-XSS-Protection "1; mode=block";
252
233
 
253
234
  if (\$http_x_forwarded_proto = "http") {
254
235
  return 301 https://\$server_name\$request_uri;
@@ -262,14 +243,37 @@ server {
262
243
  add_header X-Forwarded-Host \$host;
263
244
  add_header X-Forwarded-Port \$server_port;
264
245
  }
246
+
247
+ location /.well-known/acme-challenge/ {
248
+ root /var/www/html;
249
+ }
265
250
  }
266
251
 
267
252
  server {
268
- listen 443 ssl http2;
253
+ listen 443 ssl;
254
+ http2 on;
269
255
  server_name $switchboard_domain;
270
256
 
271
- ssl_certificate /etc/nginx/ssl/temp.crt;
272
- ssl_certificate_key /etc/nginx/ssl/temp.key;
257
+ ssl_certificate /etc/letsencrypt/live/$switchboard_domain/fullchain.pem;
258
+ ssl_certificate_key /etc/letsencrypt/live/$switchboard_domain/privkey.pem;
259
+
260
+ # SSL configuration
261
+ ssl_protocols TLSv1.2 TLSv1.3;
262
+ ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
263
+ ssl_prefer_server_ciphers off;
264
+ ssl_session_timeout 1d;
265
+ ssl_session_cache shared:SSL:50m;
266
+ ssl_session_tickets off;
267
+ ssl_stapling on;
268
+ ssl_stapling_verify on;
269
+ resolver 8.8.8.8 8.8.4.4 valid=300s;
270
+ resolver_timeout 5s;
271
+
272
+ # Security headers
273
+ add_header Strict-Transport-Security "max-age=63072000" always;
274
+ add_header X-Frame-Options DENY;
275
+ add_header X-Content-Type-Options nosniff;
276
+ add_header X-XSS-Protection "1; mode=block";
273
277
 
274
278
  location / {
275
279
  proxy_pass http://localhost:4001;
@@ -282,23 +286,20 @@ server {
282
286
  proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
283
287
  proxy_set_header X-Forwarded-Proto \$scheme;
284
288
  }
289
+
290
+ location /.well-known/acme-challenge/ {
291
+ root /var/www/html;
292
+ }
285
293
  }
286
294
  EOF
287
- fi
288
295
 
289
- # Enable the site
290
- sudo ln -sf /etc/nginx/sites-available/$PROJECT_NAME /etc/nginx/sites-enabled/
291
- sudo rm -f /etc/nginx/sites-enabled/default
296
+ # Test and reload Nginx configuration
297
+ sudo nginx -t && sudo systemctl reload nginx
292
298
 
293
- # Test Nginx configuration
294
- sudo nginx -t
295
-
296
- # Obtain SSL certificates
297
- echo "Obtaining SSL certificates..."
298
- sudo certbot --nginx -d $connect_domain -d $switchboard_domain --non-interactive --agree-tos --email admin@$connect_domain
299
-
300
- # Remove temporary certificates
301
- sudo rm -f /etc/nginx/ssl/temp.*
299
+ # Set up automatic renewal
300
+ echo "Setting up automatic certificate renewal..."
301
+ sudo systemctl enable certbot.timer
302
+ sudo systemctl start certbot.timer
302
303
 
303
304
  else
304
305
  # Get machine hostname
@@ -315,12 +316,6 @@ EOF
315
316
  # Create Nginx configuration for self-signed
316
317
  echo "Creating Nginx configuration..."
317
318
  sudo tee /etc/nginx/sites-available/$PROJECT_NAME > /dev/null << EOF
318
- # Security headers
319
- add_header Strict-Transport-Security "max-age=63072000" always;
320
- add_header X-Frame-Options DENY;
321
- add_header X-Content-Type-Options nosniff;
322
- add_header X-XSS-Protection "1; mode=block";
323
-
324
319
  server {
325
320
  listen 80;
326
321
  server_name $hostname;
@@ -328,7 +323,8 @@ server {
328
323
  }
329
324
 
330
325
  server {
331
- listen 443 ssl http2;
326
+ listen 443 ssl;
327
+ http2 on;
332
328
  server_name $hostname;
333
329
 
334
330
  ssl_certificate /etc/ssl/certs/$hostname.crt;
@@ -1,2 +1,2 @@
1
- export declare const version = "2.5.0-dev.0";
1
+ export declare const version = "2.5.0-dev.10";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,gBAAgB,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,iBAAiB,CAAC"}
@@ -1,3 +1,3 @@
1
1
  // This file is auto-generated. DO NOT EDIT.
2
- export const version = "2.5.0-dev.0";
2
+ export const version = "2.5.0-dev.10";
3
3
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC"}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAC"}