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/public_html/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.quebec/public_html/server-simple.js
// Simple HTTP Server for lavocat.quebec
// Serves Next.js static export files
require('dotenv').config({ path: '.env.production' });

const http = require('http');
const fs = require('fs');
const path = require('path');
const WebSocket = require('ws');

const port = process.env.PORT || 3443;
const hostname = process.env.HOSTNAME || '0.0.0.0';

// Global variables for WebSocket management
global.wsClients = new Map();
global.wsRoomSubscriptions = new Map();
global.wsUserPresence = new Map();

// MIME types
const mimeTypes = {
  '.html': 'text/html',
  '.js': 'application/javascript',
  '.css': 'text/css',
  '.json': 'application/json',
  '.png': 'image/png',
  '.jpg': 'image/jpeg',
  '.jpeg': 'image/jpeg',
  '.gif': 'image/gif',
  '.svg': 'image/svg+xml',
  '.ico': 'image/x-icon',
  '.woff': 'font/woff',
  '.woff2': 'font/woff2',
  '.ttf': 'font/ttf',
  '.eot': 'application/vnd.ms-fontobject',
  '.otf': 'font/otf',
  '.webp': 'image/webp',
  '.mp4': 'video/mp4',
  '.webm': 'video/webm',
  '.mp3': 'audio/mpeg',
  '.wav': 'audio/wav',
  '.pdf': 'application/pdf',
  '.zip': 'application/zip',
  '.txt': 'text/plain',
  '.xml': 'application/xml',
  '.map': 'application/json'
};

// Create HTTP server
const server = http.createServer((req, res) => {
  let filePath = req.url === '/' ? '/index.html' : req.url;
  
  // Remove query string
  filePath = filePath.split('?')[0];
  
  // Map to export directory
  const fullPath = path.join(__dirname, '.next/export', filePath);
  
  // Debug logging
  console.log(`📥 Request: ${req.url} -> ${filePath} -> ${fullPath}`);
  
  // Get file extension
  const extname = path.extname(fullPath);
  const contentType = mimeTypes[extname] || 'application/octet-stream';
  
  // Read file
  fs.readFile(fullPath, (err, content) => {
    if (err) {
      if (err.code === 'ENOENT') {
        console.log(`❌ File not found: ${fullPath}`);
        // File not found, serve index.html for SPA routing
        fs.readFile(path.join(__dirname, '.next/export/index.html'), (err, content) => {
          if (err) {
            console.log(`❌ Error loading index.html: ${err.message}`);
            res.writeHead(500);
            res.end('Error loading index.html');
          } else {
            console.log(`✅ Serving index.html for SPA routing`);
            res.writeHead(200, { 'Content-Type': 'text/html' });
            res.end(content);
          }
        });
      } else {
        console.log(`❌ Server error: ${err.message}`);
        res.writeHead(500);
        res.end('Server error');
      }
    } else {
      console.log(`✅ Serving file: ${fullPath} (${contentType})`);
      res.writeHead(200, { 'Content-Type': contentType });
      res.end(content);
    }
  });
});

// WebSocket server
const wss = new WebSocket.Server({ 
  server,
  path: '/_ws'
});

console.log('🚀 WebSocket server initialized for production');

// WebSocket connection handling
wss.on('connection', (ws, req) => {
  console.log('✅ WebSocket connection established');
  
  // Message handling
  ws.on('message', (data) => {
    try {
      const message = JSON.parse(data.toString());
      console.log('📨 WebSocket message received:', message.type);
      
      // Handle different message types
      switch (message.type) {
        case 'JOIN_ROOM': {
          const { chatRoomId } = message.data;
          if (chatRoomId) {
            if (!global.wsRoomSubscriptions.has(chatRoomId)) {
              global.wsRoomSubscriptions.set(chatRoomId, new Set());
            }
            global.wsRoomSubscriptions.get(chatRoomId).add(ws);
            console.log(`User joined room ${chatRoomId}`);
          }
          break;
        }
        
        case 'LEAVE_ROOM': {
          const { chatRoomId } = message.data;
          if (chatRoomId && global.wsRoomSubscriptions.has(chatRoomId)) {
            global.wsRoomSubscriptions.get(chatRoomId).delete(ws);
            console.log(`User left room ${chatRoomId}`);
          }
          break;
        }
        
        case 'CHAT_MESSAGE': {
          const { chatRoomId } = message.data;
          if (chatRoomId && global.wsRoomSubscriptions.has(chatRoomId)) {
            const outboundMessage = JSON.stringify(message);
            global.wsRoomSubscriptions.get(chatRoomId).forEach(clientWs => {
              if (clientWs.readyState === WebSocket.OPEN) {
                clientWs.send(outboundMessage);
              }
            });
          }
          break;
        }
        
        case 'ping': {
          ws.send(JSON.stringify({ type: 'pong' }));
          break;
        }
      }
    } catch (error) {
      console.error('WebSocket message error:', error);
    }
  });

  // Connection close handling
  ws.on('close', (code, reason) => {
    console.log(`🔌 WebSocket connection closed - Code: ${code}, Reason: ${reason}`);
  });

  // Error handling
  ws.on('error', (error) => {
    console.error('❌ WebSocket error:', error);
  });
});

// Heartbeat interval
const interval = setInterval(() => {
  wss.clients.forEach((ws) => {
    if (ws.isAlive === false) {
      return ws.terminate();
    }
    ws.isAlive = false;
    ws.ping();
  });
}, 30000);

wss.on('close', () => {
  clearInterval(interval);
});

// Start server
server.listen(port, hostname, () => {
  console.log(`🚀 Simple HTTP server running on http://${hostname}:${port}`);
  console.log(`🌐 Domain: lavocat.quebec (HTTPS handled by DirectAdmin)`);
  console.log(`📊 Environment: Production`);
  console.log(`🔌 WebSocket endpoint: ws://${hostname}:${port}/_ws`);
  console.log(`📁 Serving static files from: .next/export`);
});

CasperSecurity Mini