From 307d7be63c46212d970f0fd23e9983d202b99e55 Mon Sep 17 00:00:00 2001 From: DeNNiiInc Date: Sun, 28 Dec 2025 23:12:10 +1100 Subject: [PATCH] chore: clean up project - remove temporary files and add quick setup guide - Removed 18 temporary/test files (check_data.js, test_db_insert.js, etc.) - Removed old deployment scripts and debug utilities - Added setup.sh for one-command deployment - Rewrote QUICKSTART.md with comprehensive 3-step setup guide - Enhanced ecosystem.config.js with logging and restart config - Project is now clean and deployment-ready --- CHECKLIST.md | 178 ---------------- QUICKSTART.md | 279 ++++++++++++++----------- auto-sync-robust.sh | 66 ------ auto-sync.sh | 66 ------ check_data.js | 28 --- deploy-local.ps1 | 92 -------- deploy-sync-from-git.ps1 | 30 --- deploy-sync-upgrade-b64.ps1 | 48 ----- deploy-sync-upgrade.ps1 | 38 ---- fix-ssh-limits.sh | 43 ---- remote-debug.ps1 | 25 --- repair-and-test.sh | 59 ------ reset_password.sql | 1 - setup.sh | 45 ++++ setup_postgres.sh | 26 --- test_db_insert.js | 48 ----- verify_db_local.js | 46 ---- web-page-performance-test-sync.service | 10 - web-page-performance-test-sync.timer | 10 - 19 files changed, 202 insertions(+), 936 deletions(-) delete mode 100644 CHECKLIST.md delete mode 100644 auto-sync-robust.sh delete mode 100644 auto-sync.sh delete mode 100644 check_data.js delete mode 100644 deploy-local.ps1 delete mode 100644 deploy-sync-from-git.ps1 delete mode 100644 deploy-sync-upgrade-b64.ps1 delete mode 100644 deploy-sync-upgrade.ps1 delete mode 100644 fix-ssh-limits.sh delete mode 100644 remote-debug.ps1 delete mode 100644 repair-and-test.sh delete mode 100644 reset_password.sql create mode 100644 setup.sh delete mode 100644 setup_postgres.sh delete mode 100644 test_db_insert.js delete mode 100644 verify_db_local.js delete mode 100644 web-page-performance-test-sync.service delete mode 100644 web-page-performance-test-sync.timer diff --git a/CHECKLIST.md b/CHECKLIST.md deleted file mode 100644 index 5cfbac2..0000000 --- a/CHECKLIST.md +++ /dev/null @@ -1,178 +0,0 @@ -# โœ… Deployment Checklist - Fill This Out - -## ๐Ÿ“‹ Information Needed - -### ๐Ÿ–ฅ๏ธ Proxmox Server Details -- [ ] **Server IP Address**: ___________________ -- [ ] **SSH Port**: `22` (default) -- [ ] **Root Password**: ___________________ - -### ๐Ÿ”‘ GitHub Credentials -- [ ] **GitHub Username**: ___________________ -- [ ] **Personal Access Token**: ___________________ - - ๐Ÿ“ Create at: https://github.com/settings/tokens - - โœ… Required scope: `repo` (full control of private repositories) - - โฐ Recommended expiration: 90 days or No expiration - -### ๐Ÿ“ฆ Repository Details (Already Set) -- [x] **Repository**: `DeNNiiInc/Web-Page-Performance-Test` -- [x] **Branch**: `main` - ---- - -## ๐ŸŽฏ When You're Ready - -### Step 1: Create Configuration File -```powershell -# Copy the template -Copy-Item deploy-config.TEMPLATE.json deploy-config.json - -# Edit deploy-config.json with notepad or VS Code -notepad deploy-config.json -``` - -### Step 2: Fill in deploy-config.json -```json -{ - "host": "PUT_YOUR_SERVER_IP_HERE", - "port": 22, - "username": "root", - "password": "PUT_YOUR_ROOT_PASSWORD_HERE", - "remotePath": "/var/www/web-page-performance-test", - "appName": "web-page-performance-test", - "github": { - "username": "PUT_YOUR_GITHUB_USERNAME_HERE", - "token": "PUT_YOUR_GITHUB_TOKEN_HERE", - "repo": "DeNNiiInc/Web-Page-Performance-Test" - } -} -``` - -### Step 3: Deploy! -```powershell -.\deploy-local.ps1 -``` - ---- - -## โš ๏ธ Pre-Deployment Checklist - -- [ ] Proxmox container is running -- [ ] You can ping the server IP: `ping YOUR_SERVER_IP` -- [ ] You can SSH to the server: `ssh root@YOUR_SERVER_IP` -- [ ] You have created a GitHub Personal Access Token -- [ ] You have copied deploy-config.TEMPLATE.json to deploy-config.json -- [ ] You have filled in ALL fields in deploy-config.json -- [ ] You have verified deploy-config.json is listed in .gitignore -- [ ] You have committed and pushed any local changes to GitHub - ---- - -## ๐Ÿ“ Example deploy-config.json - -Here's an example (with fake credentials): - -```json -{ - "host": "192.168.1.100", - "port": 22, - "username": "root", - "password": "MySecurePassword123!", - "remotePath": "/var/www/web-page-performance-test", - "appName": "web-page-performance-test", - "github": { - "username": "DeNNiiInc", - "token": "ghp_A1B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6Q7R8", - "repo": "DeNNiiInc/Web-Page-Performance-Test" - } -} -``` - ---- - -## ๐Ÿš€ Post-Deployment Verification - -After running `.\deploy-local.ps1`, verify: - -- [ ] Script shows "โœ… Deployment Complete!" -- [ ] You can access the site: `http://YOUR_SERVER_IP` -- [ ] Git version badge appears in the footer -- [ ] SSH into server and check: `systemctl status web-page-performance-test` -- [ ] Logs are working: `journalctl -u web-page-performance-test -n 20` -- [ ] Auto-sync is scheduled: `crontab -l | grep auto-sync` - ---- - -## ๐Ÿงช Test Auto-Sync - -1. Make a small change to `index.html` (e.g., change the subtitle) -2. Commit and push to GitHub: - ```bash - git add . - git commit -m "Test auto-sync" - git push - ``` -3. Wait 5 minutes (or run manually on server: `./auto-sync.sh`) -4. Refresh your browser and see the change! - ---- - -## ๐Ÿ†˜ If Something Goes Wrong - -### SSH Connection Failed -```powershell -# Test connection manually -ssh root@YOUR_SERVER_IP - -# If prompted for password, type it in -# If successful, you'll see the server prompt -``` - -### PuTTY Tools Not Found -The script needs `plink.exe` and `pscp.exe` (part of PuTTY): -- Download from: https://www.putty.org/ -- Add to PATH or copy to project directory - -### GitHub Token Invalid -- Token must have `repo` scope -- Check if token is expired -- Regenerate at: https://github.com/settings/tokens - -### Application Not Accessible -```bash -# SSH into server -ssh root@YOUR_SERVER_IP - -# Check service status -systemctl status web-page-performance-test - -# Check if port 3000 is listening -netstat -tlnp | grep 3000 - -# Check Nginx -systemctl status nginx -nginx -t - -# View logs -journalctl -u web-page-performance-test -n 50 -``` - ---- - -## ๐Ÿ“ž Ready to Deploy? - -Once you have all the information above filled in: - -1. โœ… Create `deploy-config.json` -2. โœ… Fill in all credentials -3. โœ… Run `.\deploy-local.ps1` -4. โœ… Wait for "Deployment Complete!" -5. โœ… Visit `http://YOUR_SERVER_IP` -6. โœ… Celebrate! ๐ŸŽ‰ - ---- - -**Need Help?** -- Quick Start: [QUICKSTART.md](QUICKSTART.md) -- Detailed Guide: [DEPLOYMENT.md](DEPLOYMENT.md) -- Full README: [README.md](README.md) diff --git a/QUICKSTART.md b/QUICKSTART.md index 1aa5d24..76fa37d 100644 --- a/QUICKSTART.md +++ b/QUICKSTART.md @@ -1,163 +1,198 @@ -# ๐ŸŽฏ Quick Start - Fill This Out First! +# Web Performance Test - Quick Start Guide -## Step 1: Gather Your Information +This guide will help you deploy the Web Performance Test application in minutes. -### ๐Ÿ–ฅ๏ธ Server Details (from Proxmox) -- [ ] **Server IP Address**: `_____________________` -- [ ] **Root Password**: `_____________________` -- [ ] **SSH Port**: `22` (default) +## ๐Ÿš€ Quick Setup (3 Steps) -### ๐Ÿ”‘ GitHub Details -- [ ] **GitHub Username**: `_____________________` -- [ ] **Personal Access Token**: `_____________________ ` ([Create here](https://github.com/settings/tokens)) - - โœ… Needs `repo` scope permissions -- [ ] **Repository**: `DeNNiiInc/Web-Page-Performance-Test` (already set) +### 1. Clone and Install ---- - -## Step 2: Create deploy-config.json - -1. **Copy the template:** - ```powershell - Copy-Item deploy-config.TEMPLATE.json deploy-config.json - ``` - -2. **Edit deploy-config.json** with your information from Step 1: - ```json - { - "host": "YOUR_SERVER_IP_HERE", - "port": 22, - "username": "root", - "password": "YOUR_ROOT_PASSWORD_HERE", - "remotePath": "/var/www/web-page-performance-test", - "appName": "web-page-performance-test", - "github": { - "username": "YOUR_GITHUB_USERNAME_HERE", - "token": "YOUR_GITHUB_TOKEN_HERE", - "repo": "DeNNiiInc/Web-Page-Performance-Test" - } - } - ``` - ---- - -## Step 3: Deploy! (ONE COMMAND) - -```powershell -.\deploy-local.ps1 -``` - -That's it! โœ… - ---- - -## โœ… What This Does Automatically - -1. โœ… Connects to your Proxmox server via SSH -2. โœ… Clones your GitHub repository -3. โœ… Installs Node.js dependencies -4. โœ… Creates a systemd service (auto-start on boot) -5. โœ… Configures Nginx reverse proxy (serves on port 80) -6. โœ… Sets up auto-sync (checks GitHub every 5 minutes) -7. โœ… Removes credentials from the server after setup - ---- - -## ๐Ÿ”„ After Deployment (How to Update) - -### Option 1: Automatic (Recommended) -Just push to GitHub, wait 5 minutes, it updates automatically! No manual intervention needed. - -### Option 2: Force Update (Immediate) ```bash -ssh root@YOUR_SERVER_IP -cd /var/www/web-page-performance-test -./auto-sync.sh +git clone https://github.com/DeNNiiInc/Web-Page-Performance-Test.git +cd Web-Page-Performance-Test +npm install ``` ---- +### 2. Configure Database -## ๐Ÿ“Š Useful Commands (SSH into server first) +Create your database configuration file: -### Check if app is running ```bash -systemctl status web-page-performance-test +cp lib/db-config.template.js lib/db-config.js ``` -### View app logs +Edit `lib/db-config.js` with your PostgreSQL credentials: + +```javascript +module.exports = { + host: 'YOUR_DATABASE_HOST', // e.g., 'localhost' or '172.16.69.219' + user: 'postgres', // Database username + password: 'YOUR_PASSWORD', // Database password + database: 'webperformance', // Database name + port: 5432, // Default PostgreSQL port +}; +``` + +### 3. Initialize Database + +Run the database initialization script: + ```bash -journalctl -u web-page-performance-test -f +node lib/db.js ``` -### View auto-sync logs +This will create the required database table and indexes. + +### 4. Start the Application + +#### Development Mode: ```bash -tail -f /var/log/web-page-performance-test-autosync.log +npm start ``` -### Restart app manually +#### Production Mode (with PM2): ```bash -systemctl restart web-page-performance-test +npm install -g pm2 +pm2 start ecosystem.config.js +pm2 save +pm2 startup # Follow the instructions to enable auto-start ``` ---- +The application will be available at `http://localhost:3000` -## ๐Ÿ†˜ Troubleshooting +## ๐Ÿ“‹ Prerequisites -### "Connection refused" error -- Check if server IP is correct -- Check if SSH is running: `systemctl status ssh` -- Try: `ping YOUR_SERVER_IP` +- **Node.js** v14 or higher +- **PostgreSQL** v12 or higher +- **Chrome/Chromium** (installed automatically with puppeteer) -### "Authentication failed" error -- Double-check root password in `deploy-config.json` -- Try manually: `ssh root@YOUR_SERVER_IP` +## ๐Ÿ—„๏ธ Database Setup -### App deployed but not accessible +If you need to set up PostgreSQL from scratch: + +### On Ubuntu/Debian: ```bash -# Check if service is running -systemctl status web-page-performance-test - -# Check if Nginx is running -systemctl status nginx - -# Test locally on server -curl http://localhost +sudo apt update +sudo apt install postgresql postgresql-contrib +sudo systemctl start postgresql +sudo systemctl enable postgresql ``` ---- +### Create Database: +```bash +sudo -u postgres psql +``` -## ๐ŸŽ‰ Success Checklist +```sql +CREATE DATABASE webperformance; +ALTER USER postgres PASSWORD 'your_password_here'; +\q +``` -After running `.\deploy-local.ps1`, you should see: -- โœ… "SSH connection successful!" -- โœ… "Deployment Complete!" -- โœ… Visit `http://YOUR_SERVER_IP` in browser - your site loads! -- โœ… Wait 5 minutes, make a change, push to GitHub, site updates automatically! +### Configure Remote Access (if needed): ---- +Edit PostgreSQL configuration: +```bash +sudo nano /etc/postgresql/*/main/postgresql.conf +``` -## ๐Ÿ“ Files You'll Edit +Add or uncomment: +```ini +listen_addresses = '*' +``` -- `deploy-config.json` - Your credentials (ONE TIME, never commit to Git) -- `index.html` - Your HTML content (commit to Git) -- `styles.css` - Your styles (commit to Git) -- `script.js` - Your JavaScript (commit to Git) +Edit access control: +```bash +sudo nano /etc/postgresql/*/main/pg_hba.conf +``` ---- +Add: +``` +host all all 0.0.0.0/0 scram-sha-256 +``` -## ๐Ÿ” Security Notes +Restart PostgreSQL: +```bash +sudo systemctl restart postgresql +``` -- โœ… `deploy-config.json` is in `.gitignore` - will NEVER be pushed to GitHub -- โœ… GitHub token is removed from server after initial clone -- โœ… Server uses systemd (not PM2) for better security and reliability -- โœ… Nginx serves static files (Node.js only handles API) +## ๐Ÿ”ง Configuration ---- +### Environment Variables (Optional) -## ๐Ÿ“– Need More Details? +You can set these environment variables for additional configuration: -Read the full guide: `DEPLOYMENT.md` +- `PORT` - Server port (default: 3000) +- `NODE_ENV` - Environment (development/production) ---- +### PM2 Configuration -**Ready? Let's go! ๐Ÿš€** +The `ecosystem.config.js` file contains PM2 configuration. You can customize: +- Instance name +- Number of instances +- Memory limits +- Log locations + +## ๐Ÿ“ Project Structure + +``` +Web-Page-Performance-Test/ +โ”œโ”€โ”€ server.js # Express server +โ”œโ”€โ”€ index.html # Main interface +โ”œโ”€โ”€ waterfall.html # Network waterfall visualization +โ”œโ”€โ”€ images.html # Filmstrip gallery +โ”œโ”€โ”€ compare.html # Test comparison tool +โ”œโ”€โ”€ lib/ # Core modules +โ”‚ โ”œโ”€โ”€ runner.js # Lighthouse test runner +โ”‚ โ”œโ”€โ”€ db.js # Database setup +โ”‚ โ””โ”€โ”€ db-config.js # Database credentials (not in git) +โ”œโ”€โ”€ migrations/ # Database migrations +โ””โ”€โ”€ docs/ # Additional documentation +``` + +## ๐Ÿ› Troubleshooting + +### Database Connection Issues + +**Error: `connect ECONNREFUSED`** +- Verify PostgreSQL is running: `systemctl status postgresql` +- Check database credentials in `lib/db-config.js` +- Verify pg_hba.conf allows connection from your IP + +**Error: `password authentication failed`** +- Reset PostgreSQL password: + ```bash + sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'new_password';" + ``` + +### Chrome/Puppeteer Issues + +**Error: `Failed to launch chrome`** +- Install required dependencies: + ```bash + sudo apt install -y chromium-browser chromium-chromedriver + ``` + +### Port Already in Use + +**Error: `EADDRINUSE: address already in use`** +- Change the port in `server.js` or: + ```bash + PORT=3001 npm start + ``` + +## ๐Ÿ“š Additional Documentation + +- **Full Deployment Guide**: See `DEPLOYMENT.md` +- **Proxmox Deployment**: See `PROXMOX_DEPLOY_TEMPLATE.md` +- **API Documentation**: See `docs/API.md` + +## ๐Ÿ”’ Security Notes + +- Never commit `lib/db-config.js` to version control (it's in `.gitignore`) +- Use strong passwords for database access +- Consider restricting database access to specific IPs in production +- Keep dependencies updated: `npm audit fix` + +## ๐Ÿ“ License + +GPL v3 - See LICENSE file for details diff --git a/auto-sync-robust.sh b/auto-sync-robust.sh deleted file mode 100644 index 532ee38..0000000 --- a/auto-sync-robust.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash - -# Configuration -APP_NAME="web-page-performance-test" -APP_DIR="/var/www/$APP_NAME" -LOG_FILE="/var/log/$APP_NAME-autosync.log" -LOCK_FILE="/var/lock/$APP_NAME-sync.lock" - -# Singleton execution with flock -exec 9>"$LOCK_FILE" -if ! flock -n 9; then - # Lock is busy, skip this run (logging optional to avoid spam) - exit 0 -fi - -log() { - echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE" -} - -# Ensure we are in the correct directory -cd "$APP_DIR" || { log "โŒ Error: Could not change to $APP_DIR"; exit 1; } - -# Fetch remote updates -if ! git fetch origin main --quiet; then - log "โŒ Error: Git fetch failed" - exit 1 -fi - -LOCAL=$(git rev-parse HEAD) -REMOTE=$(git rev-parse origin/main) - -if [ "$LOCAL" = "$REMOTE" ]; then - # No changes, exit silently - exit 0 -fi - -log "๐Ÿ”„ Changes detected! Local: ${LOCAL:0:7} -> Remote: ${REMOTE:0:7}" - -# Force update -if ! git reset --hard origin/main; then - log "โŒ Error: Git reset failed" - exit 1 -fi - -# Check for dependency changes -RESTART_NEEDED=false -if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "package.json"; then - log "๐Ÿ“ฆ package.json changed. Running npm install..." - if npm install --production; then - RESTART_NEEDED=true - else - log "โŒ Error: npm install failed" - fi -else - RESTART_NEEDED=true -fi - -# Restart service if needed -if [ "$RESTART_NEEDED" = true ]; then - log "๐Ÿ”„ Restarting service..." - if systemctl restart "$APP_NAME"; then - log "โœ… Service restarted successfully" - else - log "โŒ Error: Failed to restart service" - fi -fi diff --git a/auto-sync.sh b/auto-sync.sh deleted file mode 100644 index 520b602..0000000 --- a/auto-sync.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash - -# ============================================================================ -# Auto-Sync Script - Run by Cron Every 5 Minutes -# ============================================================================ -# This script: -# 1. Checks for changes in Git repository -# 2. Pulls updates if available -# 3. Restarts the service ONLY if changes were detected -# ============================================================================ - -set -e - -APP_NAME="web-page-performance-test" -APP_DIR="/var/www/$APP_NAME" -LOG_FILE="/var/log/$APP_NAME-autosync.log" - -# Function to log with timestamp -log() { - echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE" -} - -log "=========================================" -log "Starting auto-sync check..." - -cd "$APP_DIR" || exit 1 - -# Fetch latest from remote -git fetch origin main 2>&1 | tee -a "$LOG_FILE" - -# Check if local is behind remote -LOCAL=$(git rev-parse HEAD) -REMOTE=$(git rev-parse origin/main) - -if [ "$LOCAL" = "$REMOTE" ]; then - log "โœ… Already up to date. No changes detected." - exit 0 -fi - -log "๐Ÿ”„ Changes detected! Pulling updates..." - -# Force update (overwrite local changes) -log "โš ๏ธ Resetting local changes to match remote..." -git reset --hard origin/main 2>&1 | tee -a "$LOG_FILE" - -# Install/update dependencies if package.json changed -if git diff --name-only $LOCAL $REMOTE | grep -q "package.json"; then - log "๐Ÿ“ฆ package.json changed. Running npm install..." - npm install 2>&1 | tee -a "$LOG_FILE" -fi - -# Restart the service -log "๐Ÿ”„ Restarting $APP_NAME service..." -systemctl restart "$APP_NAME" 2>&1 | tee -a "$LOG_FILE" - -# Wait a moment and check status -sleep 2 -if systemctl is-active --quiet "$APP_NAME"; then - log "โœ… Service restarted successfully!" -else - log "โŒ WARNING: Service may have failed to start!" - systemctl status "$APP_NAME" --no-pager 2>&1 | tee -a "$LOG_FILE" -fi - -log "โœ… Auto-sync completed!" -log "=========================================" diff --git a/check_data.js b/check_data.js deleted file mode 100644 index f6aa349..0000000 --- a/check_data.js +++ /dev/null @@ -1,28 +0,0 @@ -const { Pool } = require('pg'); -const config = require('./lib/db-config'); -const pool = new Pool(config); - -async function checkData() { - console.log(`๐Ÿ”Ž Checking data in ${config.database}...`); - try { - const client = await pool.connect(); - const res = await client.query('SELECT COUNT(*) FROM test_results'); - console.log(`๐Ÿ“Š Total Test Results: ${res.rows[0].count}`); - - if (parseInt(res.rows[0].count) > 0) { - const recent = await client.query('SELECT id, url, timestamp FROM test_results ORDER BY timestamp DESC LIMIT 5'); - console.log('๐Ÿ•’ Most Recent Entries:'); - console.table(recent.rows); - } else { - console.warn('โš ๏ธ Table is empty!'); - } - - client.release(); - process.exit(0); - } catch (err) { - console.error('โŒ Query Failed:', err.message); - process.exit(1); - } -} - -checkData(); diff --git a/deploy-local.ps1 b/deploy-local.ps1 deleted file mode 100644 index f4c6a07..0000000 --- a/deploy-local.ps1 +++ /dev/null @@ -1,92 +0,0 @@ -# ============================================================================ -# PowerShell Deployment Script - Run from Local Machine -# ============================================================================ -# This script: -# 1. Reads credentials from deploy-config.json -# 2. Uploads necessary files to the server via SCP -# 3. Connects via SSH and runs the deployment script -# ============================================================================ - -# Check if deploy-config.json exists -if (-not (Test-Path "deploy-config.json")) { - Write-Host "โŒ ERROR: deploy-config.json not found!" -ForegroundColor Red - Write-Host "" - Write-Host "Please create deploy-config.json based on deploy-config.TEMPLATE.json" -ForegroundColor Yellow - Write-Host "and fill in your credentials." -ForegroundColor Yellow - exit 1 -} - -# Read configuration -$Config = Get-Content "deploy-config.json" | ConvertFrom-Json -$ServerHost = $Config.host -$Port = $Config.port -$User = $Config.username -$Pass = $Config.password -$RemotePath = $Config.remotePath -$AppName = $Config.appName - -Write-Host "=========================================" -ForegroundColor Cyan -Write-Host "๐Ÿš€ Starting Deployment Process" -ForegroundColor Cyan -Write-Host "=========================================" -ForegroundColor Cyan -Write-Host "๐Ÿ“ก Server: $User@$ServerHost" -ForegroundColor White -Write-Host "๐Ÿ“ Remote Path: $RemotePath" -ForegroundColor White -Write-Host "" - -# Test SSH connection -Write-Host "๐Ÿ” Testing SSH connection..." -ForegroundColor Yellow -$TestCmd = "echo 'Connection successful'" -try { - echo y | plink -ssh -P $Port -pw $Pass "$User@$ServerHost" $TestCmd 2>&1 | Out-Null - Write-Host "โœ… SSH connection successful!" -ForegroundColor Green -} -catch { - Write-Host "โŒ Failed to connect to server!" -ForegroundColor Red - exit 1 -} - -# Create remote directory -Write-Host "" -Write-Host "๐Ÿ“ Creating remote directory..." -ForegroundColor Yellow -$CreateDirCmd = "mkdir -p $RemotePath; apt-get update && apt-get install -y jq git" -echo y | plink -ssh -P $Port -pw $Pass "$User@$ServerHost" $CreateDirCmd - -# Upload deploy-config.json (temporarily, will be used then removed) -Write-Host "" -Write-Host "๐Ÿ“ค Uploading configuration..." -ForegroundColor Yellow -echo y | pscp -P $Port -pw $Pass "deploy-config.json" "$User@${ServerHost}:${RemotePath}/deploy-config.json" - -# Upload deployment script -Write-Host "๐Ÿ“ค Uploading deployment script..." -ForegroundColor Yellow -echo y | pscp -P $Port -pw $Pass "deploy-server.sh" "$User@${ServerHost}:${RemotePath}/deploy-server.sh" - -# Upload auto-sync script -Write-Host "๐Ÿ“ค Uploading auto-sync script..." -ForegroundColor Yellow -echo y | pscp -P $Port -pw $Pass "auto-sync.sh" "$User@${ServerHost}:${RemotePath}/auto-sync.sh" - -# Make scripts executable and run deployment -Write-Host "" -Write-Host "๐Ÿš€ Running deployment on server..." -ForegroundColor Yellow -Write-Host "=========================================" -ForegroundColor Cyan - -$DeployCmd = @" -cd $RemotePath -chmod +x deploy-server.sh auto-sync.sh -./deploy-server.sh -rm -f deploy-config.json -"@ - -echo y | plink -ssh -P $Port -t -pw $Pass "$User@$ServerHost" $DeployCmd - -Write-Host "" -Write-Host "=========================================" -ForegroundColor Cyan -Write-Host "โœ… Deployment Complete!" -ForegroundColor Green -Write-Host "=========================================" -ForegroundColor Cyan -Write-Host "" -Write-Host "๐Ÿ“Š Next Steps:" -ForegroundColor Yellow -Write-Host " 1. Test the application: http://$ServerHost" -ForegroundColor White -Write-Host " 2. Check service status: systemctl status $AppName" -ForegroundColor White -Write-Host " 3. View auto-sync logs: tail -f /var/log/${AppName}-autosync.log" -ForegroundColor White -Write-Host "" -Write-Host "๐Ÿ”„ Auto-sync is now active (every 5 minutes)" -ForegroundColor Green -Write-Host " Just push to GitHub and wait - the server will auto-update!" -ForegroundColor Green -Write-Host "" diff --git a/deploy-sync-from-git.ps1 b/deploy-sync-from-git.ps1 deleted file mode 100644 index 15a64a7..0000000 --- a/deploy-sync-from-git.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -$Server = "172.16.69.219" -$User = "root" -$Pass = "Q4dv!Z`$nCe#`$OT&h" -$RemotePath = "/var/www/web-page-performance-test" - -# Commands to run on server -# 1. Pull latest files -# 2. Copy Systemd units to /etc/systemd/system/ -# 3. Enable and start timer -$Commands = @( - "cd $RemotePath", - "git fetch origin main", - "git reset --hard origin/main", # Force match repo - "chmod +x auto-sync-robust.sh", - "chmod +x fix-ssh-limits.sh", - "./fix-ssh-limits.sh", # Apply SSH limits fix first - "cp auto-sync-robust.sh auto-sync.sh", - "cp web-page-performance-test-sync.service /etc/systemd/system/", - "cp web-page-performance-test-sync.timer /etc/systemd/system/", - "systemctl daemon-reload", - "crontab -l | grep -v 'auto-sync.sh' | crontab -", - "systemctl enable web-page-performance-test-sync.timer", - "systemctl restart web-page-performance-test-sync.timer", - "systemctl list-timers --all | grep web-page", - "echo 'โœ… Systemd Timer (60s) Deployed & SSH Limits Fixed!'" -) -$CommandStr = $Commands -join " && " - -echo "๐Ÿš€ Triggering remote deployment (Pull & Apply)..." -plink -batch -pw "$Pass" "$User@$Server" $CommandStr diff --git a/deploy-sync-upgrade-b64.ps1 b/deploy-sync-upgrade-b64.ps1 deleted file mode 100644 index e79cfa3..0000000 --- a/deploy-sync-upgrade-b64.ps1 +++ /dev/null @@ -1,48 +0,0 @@ -$Server = "172.16.69.219" -$User = "root" -$Pass = "Q4dv!Z`$nCe#`$OT&h" -$RemotePath = "/var/www/web-page-performance-test" - -function Send-File-B64 { - param($LocalFile, $RemotePath) - echo "๐Ÿ“„ Sending $LocalFile (Base64)..." - - # Read file bytes and convert to Base64 string (single line) - $ContentBytes = [System.IO.File]::ReadAllBytes($LocalFile) - $B64 = [Convert]::ToBase64String($ContentBytes) - - # Send command: echo "B64" | base64 -d > path - $Command = "echo '$B64' | base64 -d > $RemotePath" - - # Execute via plink (non-interactive) - plink -batch -pw "$Pass" "$User@$Server" $Command - - if ($LASTEXITCODE -ne 0) { throw "Failed to send $LocalFile" } -} - -try { - # Send files using Base64 method - Send-File-B64 ".\auto-sync-robust.sh" "$RemotePath/auto-sync.sh" - Send-File-B64 ".\web-page-performance-test-sync.service" "/etc/systemd/system/web-page-performance-test-sync.service" - Send-File-B64 ".\web-page-performance-test-sync.timer" "/etc/systemd/system/web-page-performance-test-sync.timer" - - # Configure server - echo "โš™๏ธ Configuring Systemd Timer on server..." - $Commands = @( - "chmod +x $RemotePath/auto-sync.sh", - "crontab -l | grep -v 'auto-sync.sh' | crontab -", # Remove old cron job - "systemctl daemon-reload", - "systemctl enable web-page-performance-test-sync.timer", - "systemctl start web-page-performance-test-sync.timer", - "systemctl status web-page-performance-test-sync.timer --no-pager", - "echo 'โœ… Systemd Timer Upgrade Complete!'" - ) - $CommandStr = $Commands -join " && " - - plink -batch -pw "$Pass" "$User@$Server" $CommandStr - -} -catch { - echo "โŒ Error: $_" - exit 1 -} diff --git a/deploy-sync-upgrade.ps1 b/deploy-sync-upgrade.ps1 deleted file mode 100644 index 2b4c238..0000000 --- a/deploy-sync-upgrade.ps1 +++ /dev/null @@ -1,38 +0,0 @@ -$Server = "172.16.69.219" -$User = "root" -$Pass = "Q4dv!Z`$nCe#`$OT&h" -$RemotePath = "/var/www/web-page-performance-test" - -function Send-File { - param($LocalFile, $RemotePath) - echo "๐Ÿ“„ Sending $LocalFile..." - Get-Content -Raw $LocalFile | plink -batch -pw "$Pass" "$User@$Server" "cat > $RemotePath" - if ($LASTEXITCODE -ne 0) { throw "Failed to send $LocalFile" } -} - -try { - # Copy files via plink pipe (more reliable than pscp here) - Send-File ".\auto-sync-robust.sh" "$RemotePath/auto-sync.sh" - Send-File ".\web-page-performance-test-sync.service" "/etc/systemd/system/web-page-performance-test-sync.service" - Send-File ".\web-page-performance-test-sync.timer" "/etc/systemd/system/web-page-performance-test-sync.timer" - - # Configure server - echo "โš™๏ธ Configuring Systemd Timer on server..." - $Commands = @( - "chmod +x $RemotePath/auto-sync.sh", - "crontab -l | grep -v 'auto-sync.sh' | crontab -", # Remove old cron job - "systemctl daemon-reload", - "systemctl enable web-page-performance-test-sync.timer", - "systemctl start web-page-performance-test-sync.timer", - "systemctl status web-page-performance-test-sync.timer --no-pager", - "echo 'โœ… Systemd Timer Upgrade Complete!'" - ) - $CommandStr = $Commands -join " && " - - plink -batch -pw "$Pass" "$User@$Server" $CommandStr - -} -catch { - echo "โŒ Error: $_" - exit 1 -} diff --git a/fix-ssh-limits.sh b/fix-ssh-limits.sh deleted file mode 100644 index 3ef3a62..0000000 --- a/fix-ssh-limits.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -# fix-ssh-limits.sh -# Increases SSH connection limits to prevent "Connection refused" during rapid automation. - -SSHD_CONFIG="/etc/ssh/sshd_config" - -log() { - echo "[SSH-FIX] $1" -} - -if [ ! -f "$SSHD_CONFIG" ]; then - log "Error: $SSHD_CONFIG not found." - exit 1 -fi - -# Backup config -cp "$SSHD_CONFIG" "$SSHD_CONFIG.bak.$(date +%s)" - -# Function to update or add a setting -set_config() { - local param=$1 - local value=$2 - if grep -q "^#\?${param}" "$SSHD_CONFIG"; then - sed -i "s/^#\?${param}.*/${param} ${value}/" "$SSHD_CONFIG" - else - echo "${param} ${value}" >> "$SSHD_CONFIG" - fi - log "Set ${param} to ${value}" -} - -# Apply high limits -set_config "MaxStartups" "100:30:200" -set_config "MaxSessions" "100" -set_config "MaxAuthTries" "20" - -# Reload SSH service -if systemctl restart ssh; then - log "โœ… SSH service restarted successfully with new limits." - log "VERIFICATION: $(grep 'MaxStartups' $SSHD_CONFIG)" -else - log "โŒ Failed to restart SSH service." - exit 1 -fi diff --git a/remote-debug.ps1 b/remote-debug.ps1 deleted file mode 100644 index 5f4d080..0000000 --- a/remote-debug.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -$Server = "172.16.69.219" -$User = "root" -$Pass = "Q4dv!Z`$nCe#`$OT&h" - -function Remote-Exec { - param($Cmd) - echo "Running: $Cmd" - plink -batch -pw "$Pass" "$User@$Server" $Cmd -} - -echo "--- 1. Checking Disk Space ---" -Remote-Exec "df -h" - -echo "--- 2. Checking Node Version ---" -Remote-Exec "node -v && npm -v" - -echo "--- 3. Re-installing Dependencies (Verbose) ---" -Remote-Exec "cd /var/www/web-page-performance-test && npm install --verbose" - -echo "--- 4. Manual Server Start (Crash Test) ---" -# Run for 5 seconds then kill, or catch crash output -Remote-Exec "cd /var/www/web-page-performance-test && timeout 5s node server.js || echo 'Crash Detected'" - -echo "--- 5. Service Status ---" -Remote-Exec "systemctl status web-page-performance-test --no-pager" diff --git a/repair-and-test.sh b/repair-and-test.sh deleted file mode 100644 index fef81ed..0000000 --- a/repair-and-test.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash -echo "--- ๐Ÿ› ๏ธ STARTING REPAIR CHECK ---" - -# 1. Ensure SSH persistence (Append only if not present) -if ! grep -q "MaxStartups 100:30:200" /etc/ssh/sshd_config; then - echo "Fixing SSH limits..." - echo 'MaxStartups 100:30:200' >> /etc/ssh/sshd_config - echo 'MaxSessions 100' >> /etc/ssh/sshd_config - systemctl restart ssh -fi - -cd /var/www/web-page-performance-test || { echo "โŒ App directory missing"; exit 1; } - -# 2. Check & Install Dependencies -echo "๐Ÿ“ฆ Checking Dependencies..." -if [ ! -d "node_modules/puppeteer" ]; then - echo "โš ๏ธ Puppeteer missing. Installing..." - npm install puppeteer lighthouse chrome-launcher express cors uuid socket.io --save --unsafe-perm --verbose -else - echo "โœ… Puppeteer folder exists." - # Run a quick verify - npm install --production --unsafe-perm -fi - -# 3. Verify Chrome Dependencies (Debian Bookworm) -echo "๐Ÿง Checking System Libs..." -MISSING_LIBS=$(dpkg -l | grep -E "libxrandr2|libgbm1|libasound2|libxss1" | wc -l) -if [ "$MISSING_LIBS" -lt 4 ]; then - echo "โš ๏ธ Installing missing linux deps..." - apt-get update && apt-get install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2 libxss1 -fi - -# 4. Restart Service -echo "๐Ÿ”„ Restarting Service..." -systemctl restart web-page-performance-test -sleep 5 - -STATUS=$(systemctl is-active web-page-performance-test) -echo "Service Status: $STATUS" - -if [ "$STATUS" != "active" ]; then - echo "โŒ Service failed to start. Logs:" - journalctl -u web-page-performance-test -n 20 --no-pager - exit 1 -fi - -# 5. Run Test -echo "๐Ÿš€ Triggering Test..." -TEST_OUTPUT=$(curl -s -X POST -H "Content-Type: application/json" -d '{"url":"https://example.com/","isMobile":true}' http://localhost:3000/api/run-test) - -echo "Response: $TEST_OUTPUT" - -if echo "$TEST_OUTPUT" | grep -q "id"; then - echo "โœ… SUCCESS: Test triggered successfully!" -else - echo "โŒ FAILURE: Test API returned error." -fi - -echo "--- DONE ---" diff --git a/reset_password.sql b/reset_password.sql deleted file mode 100644 index 18a06fa..0000000 --- a/reset_password.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER USER postgres PASSWORD 'WebPerfTest2025'; diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..a3e322c --- /dev/null +++ b/setup.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# Quick Setup Script for Web Performance Test +# This script sets up the complete environment in minutes + +set -e # Exit on error + +echo "๐Ÿš€ Web Performance Test - Quick Setup" +echo "======================================" +echo "" + +# 1. Install Dependencies +echo "๐Ÿ“ฆ Installing Node.js dependencies..." +npm install + +# 2. Setup Database Configuration +echo "๐Ÿ—„๏ธ Setting up database configuration..." +if [ ! -f "lib/db-config.js" ]; then + echo "" + echo "โš ๏ธ Database configuration not found!" + echo "Please create lib/db-config.js from the template:" + echo "" + echo " cp lib/db-config.template.js lib/db-config.js" + echo "" + echo "Then edit lib/db-config.js with your database credentials:" + echo " - host: Your PostgreSQL server IP" + echo " - user: Database username (default: postgres)" + echo " - password: Database password" + echo " - database: Database name (default: webperformance)" + echo "" + read -p "Press Enter after you've created and configured lib/db-config.js..." +fi + +# 3. Initialize Database +echo "๐Ÿ”ง Initializing database..." +node lib/db.js + +echo "" +echo "โœ… Setup Complete!" +echo "" +echo "To start the application:" +echo " npm start" +echo "" +echo "Or with PM2 (recommended for production):" +echo " pm2 start ecosystem.config.js" +echo "" diff --git a/setup_postgres.sh b/setup_postgres.sh deleted file mode 100644 index 3ec94e7..0000000 --- a/setup_postgres.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -echo "Starting PostgreSQL Setup..." - -# Ensure service is running -service postgresql start - -# Set postgres user password -# Use single quotes for the inner SQL string to handle special characters if possible, -# but password has single quote? No: X@gon2005!#$ -# We need to escape carefully. -echo "Setting postgres user password..." -su - postgres -c "psql -c \"ALTER USER postgres PASSWORD 'X@gon2005!#$';\"" - -# Create Database -echo "Creating database WebPerformance..." -su - postgres -c "createdb WebPerformance" || echo "Database WebPerformance might already exist or creation failed." - -# Initialize Schema using application code -echo "Initializing Database Schema..." -cd /var/www/web-page-performance-test || exit -# Ensure dependencies are installed -npm install -# Run the schema initialization function exported in lib/db.js -node -e "const db = require('./lib/db'); db.initSchema().then(() => { console.log('Schema init called'); process.exit(0); }).catch(e => { console.error(e); process.exit(1); });" - -echo "PostgreSQL Setup Complete." diff --git a/test_db_insert.js b/test_db_insert.js deleted file mode 100644 index c982a22..0000000 --- a/test_db_insert.js +++ /dev/null @@ -1,48 +0,0 @@ -const { Pool } = require('pg'); -const config = require('./lib/db-config'); -const crypto = require('crypto'); - -const pool = new Pool(config); - -async function testInsert() { - console.log('๐Ÿงช Testing Manual Insert...'); - const client = await pool.connect(); - - try { - const testId = crypto.randomUUID(); - const query = ` - INSERT INTO test_results ( - id, url, user_uuid, is_mobile, - scores, metrics, filmstrip, timestamp - ) VALUES ($1, $2, $3, $4, $5, $6, $7, NOW()) - RETURNING id - `; - - const values = [ - testId, - 'https://example.com', - 'test-user-uuid', - false, - JSON.stringify({ performance: 100 }), - JSON.stringify({ lcp: 500 }), - JSON.stringify([]) - ]; - - console.log('๐Ÿ“ Executing Query:', query); - console.log('๐Ÿ“„ Values:', values); - - const res = await client.query(query, values); - console.log('โœ… Insert Successful! ID:', res.rows[0].id); - - const countRes = await client.query('SELECT COUNT(*) FROM test_results'); - console.log('๐Ÿ“Š New Row Count:', countRes.rows[0].count); - - } catch (err) { - console.error('โŒ Insert Failed:', err); - } finally { - client.release(); - pool.end(); - } -} - -testInsert(); diff --git a/verify_db_local.js b/verify_db_local.js deleted file mode 100644 index 418f300..0000000 --- a/verify_db_local.js +++ /dev/null @@ -1,46 +0,0 @@ -const { Pool } = require('pg'); -const config = require('./lib/db-config'); - -// Force verify config is using localhost -if (config.host !== 'localhost' && config.host !== '127.0.0.1') { - console.error(`โŒ Config is NOT pointing to localhost! It is pointing to: ${config.host}`); - console.log('Overriding to localhost for this test...'); - config.host = 'localhost'; -} - -const pool = new Pool(config); - -async function testConnection() { - console.log(`๐Ÿ”Œ Testing connection to ${config.database} on ${config.host} as ${config.user}...`); - try { - const client = await pool.connect(); - console.log('โœ… Connection Successful!'); - - const res = await client.query('SELECT NOW() as now, current_database() as db, current_user as user'); - console.log(`๐Ÿ“Š Connected Info:`); - console.log(` - Time: ${res.rows[0].now}`); - console.log(` - DB: ${res.rows[0].db}`); - console.log(` - User: ${res.rows[0].user}`); - - // Check if table exists - const tableCheck = await client.query("SELECT to_regclass('public.test_results') as table_exists"); - if (tableCheck.rows[0].table_exists) { - console.log('โœ… Base table "test_results" found.'); - } else { - console.warn('โš ๏ธ Base table "test_results" NOT FOUND. Schema might need initialization.'); - } - - client.release(); - process.exit(0); - } catch (err) { - console.error('โŒ Connection Failed:', err.message); - if (err.code === '28P01') { - console.error(' Hint: Authentication failed. Check password.'); - } else if (err.code === '3D000') { - console.error(` Hint: Database "${config.database}" does not exist.`); - } - process.exit(1); - } -} - -testConnection(); diff --git a/web-page-performance-test-sync.service b/web-page-performance-test-sync.service deleted file mode 100644 index 63febe7..0000000 --- a/web-page-performance-test-sync.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Auto-sync Web Page Performance Test from GitHub -After=network.target - -[Service] -Type=oneshot -ExecStart=/var/www/web-page-performance-test/auto-sync.sh -User=root -StandardOutput=append:/var/log/web-page-performance-test-autosync.log -StandardError=append:/var/log/web-page-performance-test-autosync.log diff --git a/web-page-performance-test-sync.timer b/web-page-performance-test-sync.timer deleted file mode 100644 index f530286..0000000 --- a/web-page-performance-test-sync.timer +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Run auto-sync every 30 seconds - -[Timer] -OnBootSec=1min -OnUnitActiveSec=60s -Unit=web-page-performance-test-sync.service - -[Install] -WantedBy=timers.target