191 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			191 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| // 局部代理配置调试脚本
 | ||
| // 帮助检查和设置局部代理配置
 | ||
| 
 | ||
| const { app } = require('electron');
 | ||
| 
 | ||
| // 您的局部代理配置
 | ||
| const LOCAL_PROXY_CONFIG = {
 | ||
|   proxyStatus: "true",           // 启用代理
 | ||
|   proxyType: "socks5",          // 代理类型
 | ||
|   proxyIp: "143.20.228.192",    // 代理IP
 | ||
|   proxyPort: "3306",            // 代理端口
 | ||
|   userVerifyStatus: "true",     // 启用认证
 | ||
|   username: "mNrz1aEg",         // 用户名
 | ||
|   password: "3xV3dBYB"          // 密码
 | ||
| };
 | ||
| 
 | ||
| // 检查所有代理配置
 | ||
| async function checkAllProxyConfigs() {
 | ||
|   console.log('🔍 检查所有代理配置...\n');
 | ||
|   
 | ||
|   try {
 | ||
|     // 1. 检查全局代理配置
 | ||
|     const globalConfig = await app.sdb.selectOne("global_proxy_config");
 | ||
|     console.log('📋 全局代理配置:');
 | ||
|     if (globalConfig) {
 | ||
|       console.log(`   状态: ${globalConfig.proxyStatus === "true" ? "✅ 启用" : "❌ 禁用"}`);
 | ||
|       console.log(`   IP: ${globalConfig.proxyIp || "未设置"}`);
 | ||
|       console.log(`   端口: ${globalConfig.proxyPort || "未设置"}`);
 | ||
|     } else {
 | ||
|       console.log('   ❌ 未找到全局代理配置');
 | ||
|     }
 | ||
|     
 | ||
|     // 2. 检查所有局部代理配置
 | ||
|     const allProxyConfigs = await app.sdb.selectAll("proxy_config");
 | ||
|     console.log('\n📋 所有局部代理配置:');
 | ||
|     if (allProxyConfigs && allProxyConfigs.length > 0) {
 | ||
|       allProxyConfigs.forEach((config, index) => {
 | ||
|         console.log(`   配置 ${index + 1}:`);
 | ||
|         console.log(`     ID: ${config.id}`);
 | ||
|         console.log(`     partitionId: ${config.partitionId || "未设置"}`);
 | ||
|         console.log(`     状态: ${config.proxyStatus === "true" ? "✅ 启用" : "❌ 禁用"}`);
 | ||
|         console.log(`     类型: ${config.proxyType || "未设置"}`);
 | ||
|         console.log(`     IP: ${config.proxyIp || "未设置"}`);
 | ||
|         console.log(`     端口: ${config.proxyPort || "未设置"}`);
 | ||
|         console.log(`     认证: ${config.userVerifyStatus === "true" ? "✅ 启用" : "❌ 禁用"}`);
 | ||
|         console.log(`     用户名: ${config.username || "未设置"}`);
 | ||
|         console.log('');
 | ||
|       });
 | ||
|     } else {
 | ||
|       console.log('   ❌ 未找到任何局部代理配置');
 | ||
|     }
 | ||
|     
 | ||
|     // 3. 检查会话列表
 | ||
|     const sessions = await app.sdb.selectAll("session_list");
 | ||
|     console.log('📋 当前会话列表:');
 | ||
|     if (sessions && sessions.length > 0) {
 | ||
|       sessions.forEach((session, index) => {
 | ||
|         console.log(`   会话 ${index + 1}:`);
 | ||
|         console.log(`     partitionId: ${session.partitionId}`);
 | ||
|         console.log(`     platform: ${session.platform}`);
 | ||
|         console.log(`     windowStatus: ${session.windowStatus}`);
 | ||
|         console.log('');
 | ||
|       });
 | ||
|     } else {
 | ||
|       console.log('   ❌ 未找到任何会话');
 | ||
|     }
 | ||
|     
 | ||
|   } catch (error) {
 | ||
|     console.error('❌ 检查代理配置失败:', error);
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| // 为指定的partitionId设置局部代理配置
 | ||
| async function setupLocalProxy(partitionId) {
 | ||
|   console.log(`🔧 为 ${partitionId} 设置局部代理配置...\n`);
 | ||
|   
 | ||
|   try {
 | ||
|     // 检查是否已存在配置
 | ||
|     const existingConfig = await app.sdb.selectOne("proxy_config", { partitionId });
 | ||
|     
 | ||
|     const configData = {
 | ||
|       partitionId,
 | ||
|       ...LOCAL_PROXY_CONFIG
 | ||
|     };
 | ||
|     
 | ||
|     if (existingConfig) {
 | ||
|       console.log('📝 更新现有的局部代理配置...');
 | ||
|       await app.sdb.update("proxy_config", configData, { id: existingConfig.id });
 | ||
|       console.log('✅ 局部代理配置更新成功!');
 | ||
|     } else {
 | ||
|       console.log('📝 创建新的局部代理配置...');
 | ||
|       await app.sdb.insert("proxy_config", configData);
 | ||
|       console.log('✅ 局部代理配置创建成功!');
 | ||
|     }
 | ||
|     
 | ||
|     console.log('\n📋 配置详情:');
 | ||
|     console.log(`   partitionId: ${partitionId}`);
 | ||
|     console.log(`   状态: ${LOCAL_PROXY_CONFIG.proxyStatus === "true" ? "启用" : "禁用"}`);
 | ||
|     console.log(`   类型: ${LOCAL_PROXY_CONFIG.proxyType.toUpperCase()}`);
 | ||
|     console.log(`   地址: ${LOCAL_PROXY_CONFIG.proxyIp}:${LOCAL_PROXY_CONFIG.proxyPort}`);
 | ||
|     console.log(`   认证: ${LOCAL_PROXY_CONFIG.userVerifyStatus === "true" ? "启用" : "禁用"}`);
 | ||
|     console.log(`   用户: ${LOCAL_PROXY_CONFIG.username}`);
 | ||
|     console.log(`   密码: ${'*'.repeat(LOCAL_PROXY_CONFIG.password.length)}`);
 | ||
|     
 | ||
|   } catch (error) {
 | ||
|     console.error('❌ 设置局部代理配置失败:', error);
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| // 清除指定partitionId的局部代理配置
 | ||
| async function clearLocalProxy(partitionId) {
 | ||
|   console.log(`🧹 清除 ${partitionId} 的局部代理配置...\n`);
 | ||
|   
 | ||
|   try {
 | ||
|     const existingConfig = await app.sdb.selectOne("proxy_config", { partitionId });
 | ||
|     
 | ||
|     if (existingConfig) {
 | ||
|       await app.sdb.update("proxy_config", {
 | ||
|         proxyStatus: "false",
 | ||
|         proxyType: "http",
 | ||
|         proxyIp: "",
 | ||
|         proxyPort: "",
 | ||
|         userVerifyStatus: "false",
 | ||
|         username: "",
 | ||
|         password: ""
 | ||
|       }, { id: existingConfig.id });
 | ||
|       
 | ||
|       console.log('✅ 局部代理配置已清除');
 | ||
|     } else {
 | ||
|       console.log('⚠️  未找到该partitionId的代理配置');
 | ||
|     }
 | ||
|     
 | ||
|   } catch (error) {
 | ||
|     console.error('❌ 清除局部代理配置失败:', error);
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| // 确保全局代理配置为空
 | ||
| async function ensureGlobalProxyDisabled() {
 | ||
|   console.log('🔧 确保全局代理配置为空...\n');
 | ||
|   
 | ||
|   try {
 | ||
|     const globalConfig = await app.sdb.selectOne("global_proxy_config");
 | ||
|     
 | ||
|     if (globalConfig) {
 | ||
|       await app.sdb.update("global_proxy_config", {
 | ||
|         proxyStatus: "false",
 | ||
|         proxyType: "http",
 | ||
|         proxyIp: "",
 | ||
|         proxyPort: "",
 | ||
|         userVerifyStatus: "false",
 | ||
|         username: "",
 | ||
|         password: ""
 | ||
|       });
 | ||
|       console.log('✅ 全局代理配置已禁用');
 | ||
|     } else {
 | ||
|       console.log('⚠️  未找到全局代理配置');
 | ||
|     }
 | ||
|     
 | ||
|   } catch (error) {
 | ||
|     console.error('❌ 禁用全局代理配置失败:', error);
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| // 导出函数
 | ||
| module.exports = {
 | ||
|   checkAllProxyConfigs,
 | ||
|   setupLocalProxy,
 | ||
|   clearLocalProxy,
 | ||
|   ensureGlobalProxyDisabled,
 | ||
|   LOCAL_PROXY_CONFIG
 | ||
| };
 | ||
| 
 | ||
| // 如果直接运行此文件
 | ||
| if (require.main === module) {
 | ||
|   console.log('⚠️  这个脚本需要在Electron应用启动后调用');
 | ||
|   console.log('💡 请在应用的控制台中运行以下命令:');
 | ||
|   console.log('');
 | ||
|   console.log('   // 检查所有配置');
 | ||
|   console.log('   const debug = require("./debug_local_proxy.js");');
 | ||
|   console.log('   debug.checkAllProxyConfigs();');
 | ||
|   console.log('');
 | ||
|   console.log('   // 确保全局代理禁用');
 | ||
|   console.log('   debug.ensureGlobalProxyDisabled();');
 | ||
|   console.log('');
 | ||
|   console.log('   // 为特定会话设置局部代理(替换为实际的partitionId)');
 | ||
|   console.log('   debug.setupLocalProxy("您的partitionId");');
 | ||
|   console.log('');
 | ||
|   console.log('🔍 或者先运行 checkAllProxyConfigs() 查看当前所有配置');
 | ||
| }
 | 
