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/fix-language-switching.js
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

// Priority files to fix (most critical ones)
const priorityFiles = [
  'src/pages/_error.tsx',
  'src/pages/404.tsx',
  'src/components/Footer.tsx',
  'src/components/LayoutWithSidebar.tsx',
  'src/components/CookieConsent.tsx',
  'src/pages/auth/forgot-password.tsx',
  'src/pages/auth/reset-password.tsx'
];

// Language switcher template
const languageSwitcherTemplate = `
  const [language, setLanguage] = useState<'fr' | 'en'>('fr');

  const handleLanguageToggle = () => {
    const newLang = language === 'fr' ? 'en' : 'fr';
    setLanguage(newLang);
  };
`;

// Import statements to add
const importsToAdd = [
  "import { useState } from 'react';"
];

// Function to add language state management
function addLanguageState(filePath) {
  try {
    let content = fs.readFileSync(filePath, 'utf8');
    
    // Check if already has language state
    if (content.includes('const [language, setLanguage]')) {
      console.log(`   āš ļø  ${filePath} already has language state`);
      return false;
    }

    // Add useState import if not present
    if (!content.includes("import { useState }")) {
      const importMatch = content.match(/import React[^;]*;/);
      if (importMatch) {
        content = content.replace(importMatch[0], importMatch[0] + '\nimport { useState } from \'react\';');
      } else {
        // Add at the top if no React import
        content = 'import { useState } from \'react\';\n' + content;
      }
    }

    // Add language state after component declaration
    const componentMatch = content.match(/(const\s+\w+\s*:\s*React\.FC\s*=\s*\(\)\s*=>\s*{)/);
    if (componentMatch) {
      content = content.replace(componentMatch[0], componentMatch[0] + languageSwitcherTemplate);
    } else {
      // Try alternative component patterns
      const altMatch = content.match(/(const\s+\w+\s*=\s*\(\)\s*=>\s*{)/);
      if (altMatch) {
        content = content.replace(altMatch[0], altMatch[0] + languageSwitcherTemplate);
      }
    }

    fs.writeFileSync(filePath, content);
    console.log(`   āœ… Added language state to ${filePath}`);
    return true;
  } catch (error) {
    console.log(`   āŒ Error adding language state to ${filePath}: ${error.message}`);
    return false;
  }
}

// Function to convert hard-coded language links to dynamic ones
function convertLanguageLinks(filePath) {
  try {
    let content = fs.readFileSync(filePath, 'utf8');
    let modified = false;

    // Convert hard-coded language switcher links
    const languageLinkPatterns = [
      // EN link to /en
      {
        pattern: /<Link[^>]*href=["']\/en["'][^>]*>.*?EN.*?<\/Link>/gs,
        replacement: '<button onClick={handleLanguageToggle} className="text-white hover:text-gray-200 transition-colors">EN</button>'
      },
      // FR link to /
      {
        pattern: /<Link[^>]*href=["']\/["'][^>]*>.*?FR.*?<\/Link>/gs,
        replacement: '<button onClick={handleLanguageToggle} className="text-white hover:text-gray-200 transition-colors">FR</button>'
      }
    ];

    languageLinkPatterns.forEach(({ pattern, replacement }) => {
      if (content.match(pattern)) {
        content = content.replace(pattern, replacement);
        modified = true;
        console.log(`   šŸ”„ Converted language switcher links in ${filePath}`);
      }
    });

    // Convert hard-coded page links to dynamic ones
    const pageLinkPatterns = [
      // French page links (excluding /en/ paths)
      {
        pattern: /href=["']\/(?!en\/)([^"']*)["']/g,
        replacement: (match, path) => {
          if (path === '') return 'href="/"'; // Keep root path as is
          return `href={language === 'en' ? '/en/${path}' : '/${path}'}`;
        }
      },
      // English page links
      {
        pattern: /href=["']\/en\/([^"']*)["']/g,
        replacement: (match, path) => {
          return `href={language === 'en' ? '/en/${path}' : '/${path}'}`;
        }
      }
    ];

    pageLinkPatterns.forEach(({ pattern, replacement }) => {
      const newContent = content.replace(pattern, replacement);
      if (newContent !== content) {
        content = newContent;
        modified = true;
        console.log(`   šŸ”„ Converted page links in ${filePath}`);
      }
    });

    if (modified) {
      fs.writeFileSync(filePath, content);
      console.log(`   āœ… Updated ${filePath}`);
      return true;
    }

    return false;
  } catch (error) {
    console.log(`   āŒ Error converting links in ${filePath}: ${error.message}`);
    return false;
  }
}

// Function to make content dynamic based on language
function makeContentDynamic(filePath) {
  try {
    let content = fs.readFileSync(filePath, 'utf8');
    let modified = false;

    // Simple content patterns to make dynamic
    const contentPatterns = [
      // Common French/English text pairs
      {
        fr: 'Accueil',
        en: 'Home',
        pattern: /Accueil/g
      },
      {
        fr: 'ƀ propos',
        en: 'About',
        pattern: /ƀ propos/g
      },
      {
        fr: 'Contact',
        en: 'Contact',
        pattern: /Contact/g
      },
      {
        fr: 'Retour',
        en: 'Back',
        pattern: /Retour/g
      }
    ];

    contentPatterns.forEach(({ fr, en, pattern }) => {
      if (content.match(pattern)) {
        content = content.replace(pattern, `{language === 'fr' ? '${fr}' : '${en}'}`);
        modified = true;
      }
    });

    if (modified) {
      fs.writeFileSync(filePath, content);
      console.log(`   āœ… Made content dynamic in ${filePath}`);
      return true;
    }

    return false;
  } catch (error) {
    console.log(`   āŒ Error making content dynamic in ${filePath}: ${error.message}`);
    return false;
  }
}

function main() {
  console.log('šŸ”§ Fixing language switching issues...\n');

  let totalFixed = 0;
  let totalErrors = 0;

  priorityFiles.forEach(filePath => {
    if (fs.existsSync(filePath)) {
      console.log(`\nšŸ“„ Processing ${filePath}:`);
      
      let fileFixed = false;
      
      // Step 1: Add language state management
      if (addLanguageState(filePath)) {
        fileFixed = true;
      }
      
      // Step 2: Convert hard-coded links
      if (convertLanguageLinks(filePath)) {
        fileFixed = true;
      }
      
      // Step 3: Make content dynamic
      if (makeContentDynamic(filePath)) {
        fileFixed = true;
      }
      
      if (fileFixed) {
        totalFixed++;
      } else {
        console.log(`   āš ļø  No changes needed for ${filePath}`);
      }
    } else {
      console.log(`\nāŒ File not found: ${filePath}`);
      totalErrors++;
    }
  });

  console.log('\nšŸ“‹ SUMMARY:');
  console.log(`   - Files processed: ${priorityFiles.length}`);
  console.log(`   - Files fixed: ${totalFixed}`);
  console.log(`   - Errors: ${totalErrors}`);
  
  if (totalFixed > 0) {
    console.log('\nāœ… Language switching issues fixed!');
    console.log('šŸ’” Next steps:');
    console.log('   1. Test the language switching on the fixed pages');
    console.log('   2. Run the scan script again to check remaining issues');
    console.log('   3. Fix remaining files if needed');
  }
}

if (require.main === module) {
  main();
}

module.exports = { addLanguageState, convertLanguageLinks, makeContentDynamic }; 

CasperSecurity Mini