T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/lavocat.quebec/private_html/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.quebec/private_html/scripts/deploy-directadmin.sh
#!/bin/bash

# Production Deployment Script for lavocat.quebec (DirectAdmin + Node.js + MySQL)
# This script prepares and deploys the application to production without sudo

set -e  # Exit on any error

echo "🚀 Starting production deployment for lavocat.quebec (DirectAdmin + MySQL)..."

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Configuration
DOMAIN="lavocat.quebec"
PROJECT_NAME="liberte-meme-en-cellule"
DEPLOY_DIR="/home/gositeme/domains/lavocat.quebec/public_html"
BACKUP_DIR="/home/gositeme/backups/lavocat.quebec"
LOG_DIR="/home/gositeme/logs/lavocat-quebec"
USER="gositeme"

# Function to print colored output
print_status() {
    echo -e "${BLUE}[INFO]${NC} $1"
}

print_success() {
    echo -e "${GREEN}[SUCCESS]${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}[WARNING]${NC} $1"
}

print_error() {
    echo -e "${RED}[ERROR]${NC} $1"
}

# Check if running as correct user
if [[ $USER != "gositeme" ]]; then
   print_error "This script should be run as gositeme user"
   exit 1
fi

# Check if Node.js is installed
if ! command -v node &> /dev/null; then
    print_error "Node.js is not installed. Please install Node.js first."
    exit 1
fi

# Check Node.js version
NODE_VERSION=$(node --version)
print_status "Node.js version: $NODE_VERSION"

# Create backup
print_status "Creating backup of current deployment..."
if [ -d "$DEPLOY_DIR" ]; then
    BACKUP_NAME="backup-$(date +%Y%m%d-%H%M%S)"
    mkdir -p "$BACKUP_DIR"
    cp -r "$DEPLOY_DIR" "$BACKUP_DIR/$BACKUP_NAME"
    print_success "Backup created: $BACKUP_DIR/$BACKUP_NAME"
else
    print_warning "No existing deployment found, skipping backup"
fi

# Create deployment directory
print_status "Creating deployment directory..."
mkdir -p "$DEPLOY_DIR"

# Copy project files
print_status "Copying project files..."
cp -r . "$DEPLOY_DIR/"
cd "$DEPLOY_DIR"

# Install dependencies
print_status "Installing production dependencies..."
npm ci --only=production

# Generate Prisma client
print_status "Generating Prisma client..."
npx prisma generate

# Run database migrations
print_status "Running database migrations..."
npx prisma migrate deploy

# Build the application
print_status "Building the application..."
npm run build:production

# Create production environment file
print_status "Setting up production environment..."
if [ ! -f ".env.production" ]; then
    print_error "Production environment file not found!"
    print_status "Please create .env.production with your production settings"
    exit 1
fi

# Create directories
print_status "Creating necessary directories..."
mkdir -p "$BACKUP_DIR"
mkdir -p "$LOG_DIR"
mkdir -p "$DEPLOY_DIR/public/uploads"

# Create PM2 ecosystem file for process management
print_status "Creating PM2 configuration..."
cat > ecosystem.config.js <<EOF
module.exports = {
  apps: [{
    name: 'lavocat-quebec',
    script: 'server-production.js',
    cwd: '$DEPLOY_DIR',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '1G',
    env: {
      NODE_ENV: 'production',
      PORT: 3000,
      HTTPS_PORT: 3443
    },
    error_file: '$LOG_DIR/err.log',
    out_file: '$LOG_DIR/out.log',
    log_file: '$LOG_DIR/combined.log',
    time: true
  }]
};
EOF

# Create startup script
print_status "Creating startup script..."
cat > start-production.sh <<EOF
#!/bin/bash
cd $DEPLOY_DIR
export NODE_ENV=production
export PORT=3000
export HTTPS_PORT=3443
node --max-old-space-size=4096 --expose-gc server-production.js
EOF

chmod +x start-production.sh

# Create stop script
print_status "Creating stop script..."
cat > stop-production.sh <<EOF
#!/bin/bash
pkill -f "server-production.js" || true
EOF

chmod +x stop-production.sh

# Create restart script
print_status "Creating restart script..."
cat > restart-production.sh <<EOF
#!/bin/bash
./stop-production.sh
sleep 2
./start-production.sh
EOF

chmod +x restart-production.sh

# Create .htaccess for Apache proxy
print_status "Creating .htaccess for Apache proxy..."
cat > .htaccess <<EOF
RewriteEngine On

# Proxy to Node.js application
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:3000/\$1 [P,L]

# WebSocket support
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/_ws(.*)$ ws://127.0.0.1:3443/_ws\$1 [P,L]

# Security headers
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff
Header always set X-XSS-Protection "1; mode=block"
Header always set Referrer-Policy "strict-origin-when-cross-origin"

# Cache static files
<FilesMatch "\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$">
    ExpiresActive On
    ExpiresDefault "access plus 1 year"
    Header set Cache-Control "public, immutable"
</FilesMatch>

# Enable compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
EOF

# Start the application
print_status "Starting the application..."
./stop-production.sh
sleep 2
./start-production.sh &

# Wait for service to start
sleep 5

# Check if service is running
if pgrep -f "server-production.js" > /dev/null; then
    print_success "Service is running successfully!"
    print_status "Process ID: $(pgrep -f 'server-production.js')"
else
    print_error "Service failed to start!"
    print_status "Check logs in: $LOG_DIR"
    exit 1
fi

# Create log rotation script
print_status "Setting up log rotation..."
cat > rotate-logs.sh <<EOF
#!/bin/bash
# Rotate logs daily
cd $LOG_DIR
if [ -f "out.log" ]; then
    mv out.log "out-\$(date +%Y%m%d).log"
fi
if [ -f "err.log" ]; then
    mv err.log "err-\$(date +%Y%m%d).log"
fi
if [ -f "combined.log" ]; then
    mv combined.log "combined-\$(date +%Y%m%d).log"
fi
# Keep only last 30 days of logs
find . -name "*.log" -mtime +30 -delete
EOF

chmod +x rotate-logs.sh

print_success "Deployment completed successfully!"
print_status "Your application is now running at: https://lavocat.quebec"
print_status "Application directory: $DEPLOY_DIR"
print_status "Log directory: $LOG_DIR"
print_status "Backup directory: $BACKUP_DIR"
print_status ""
print_status "Management commands:"
print_status "  Start: ./start-production.sh"
print_status "  Stop: ./stop-production.sh"
print_status "  Restart: ./restart-production.sh"
print_status "  View logs: tail -f $LOG_DIR/combined.log"
print_status "  Backup DB: npm run backup:database"
print_status "  Rotate logs: ./rotate-logs.sh" 

CasperSecurity Mini