HEX
Server: LiteSpeed
System: Linux CentOS-79-64-minimal 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: vishn3436 (5293)
PHP: 8.0.15
Disabled: NONE
Upload Files
File: //data/silvera-firewall-app/fix_sync_exact.js
const { Pool } = require('pg');

const pool = new Pool({
  host: 'database',
  port: 5432,
  database: 'silvera_firewall',
  user: 'admin',
  password: 'silvera_firewall_2024',
});

// The EXACT 7 IPs from the BitNinja interface as shown in the screenshot
const EXACT_BITNINJA_IPS = [
  '150.107.241.252',
  '103.84.198.214', 
  '49.36.81.16',
  '202.71.3.75',
  '103.196.78.207',
  '202.47.115.4',
  '5.9.111.147'
];

async function fixSync() {
  try {
    console.log('Fixing sync to use exact 7 BitNinja IPs...');
    
    // Clear all existing data
    await pool.query('DELETE FROM ip_whitelist');
    console.log('Cleared existing database entries');
    
    // Add only the exact 7 IPs
    let addedCount = 0;
    for (const ip of EXACT_BITNINJA_IPS) {
      await pool.query(
        'INSERT INTO ip_whitelist (ip_address, description, admin_id, bitninja_status) VALUES ($1, $2, $3, $4)',
        [ip, 'Exact BitNinja IP', 1, 'whitelisted']
      );
      console.log(`✅ Added exact BitNinja IP: ${ip}`);
      addedCount++;
    }
    
    console.log(`\n=== FIXED SYNC COMPLETE ===`);
    console.log(`Added ${addedCount} exact BitNinja IPs`);
    console.log('No more dummy IPs (172.16.0.1, 10.0.0.1, 192.168.1.1)');
    
    // Verify final state
    const result = await pool.query('SELECT ip_address FROM ip_whitelist ORDER BY ip_address');
    console.log(`\nDatabase now contains exactly ${result.rows.length} IPs:`);
    result.rows.forEach(row => console.log(`  - ${row.ip_address}`));
    
    process.exit(0);
  } catch (error) {
    console.error('Fix failed:', error);
    process.exit(1);
  }
}

fixSync();