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.ca/public_html/src/utils/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.ca/public_html/src/utils/connection.ts
/**
 * Connection utilities for handling localhost vs network IP access
 */

export const getServerUrl = () => {
  if (typeof window !== 'undefined') {
    // Client-side: use current window location
    return `${window.location.protocol}//${window.location.host}`;
  }
  
  // Server-side: determine from environment or default
  if (process.env.NEXTAUTH_URL) {
    return process.env.NEXTAUTH_URL;
  }
  
  // Auto-detect based on hostname setting
  const hostname = process.env.HOSTNAME || 'localhost';
  const port = process.env.PORT || 3000;
  const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
  
  if (hostname === '0.0.0.0') {
    // If listening on all interfaces, default to localhost for auth
    return `${protocol}://localhost:${port}`;
  }
  
  return `${protocol}://${hostname}:${port}`;
};

export const getWebSocketUrl = () => {
  if (typeof window !== 'undefined') {
    // Client-side: use current window location for WebSocket
    const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
    return `${protocol}//${window.location.host}/_ws`;
  }
  
  // Server-side fallback
  return 'ws://localhost:3000/_ws';
};

export const isLocalhost = () => {
  if (typeof window !== 'undefined') {
    return window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
  }
  return true;
};

export const getDisplayUrl = () => {
  if (typeof window !== 'undefined') {
    return window.location.href;
  }
  return getServerUrl();
};

/**
 * Checks if the current connection is using the network IP
 */
export const isNetworkConnection = () => {
  if (typeof window !== 'undefined') {
    const hostname = window.location.hostname;
    return hostname.startsWith('10.') || hostname.startsWith('192.') || hostname.startsWith('172.');
  }
  return false;
};

/**
 * Gets the appropriate connection info for display
 */
export const getConnectionInfo = () => {
  if (typeof window === 'undefined') {
    return {
      type: 'server',
      url: getServerUrl(),
      isNetwork: false
    };
  }
  
  const isNetwork = isNetworkConnection();
  const isLocal = isLocalhost();
  
  return {
    type: isNetwork ? 'network' : isLocal ? 'localhost' : 'other',
    url: window.location.href,
    hostname: window.location.hostname,
    isNetwork,
    isLocal
  };
}; 

CasperSecurity Mini