Files
seabox_fanyi_application/setup_global_proxy.js
2025-09-18 15:14:14 +08:00

147 lines
5.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 全局代理快速配置脚本
// 这个脚本可以帮助您快速设置全局代理配置
const { app } = require('electron');
const path = require('path');
// 您的代理配置
const PROXY_CONFIG = {
proxyStatus: "true", // 启用代理
proxyType: "socks5", // 代理类型http, https, socks4, socks5
proxyIp: "143.20.228.192", // 代理IP
proxyPort: "3306", // 代理端口
userVerifyStatus: "true", // 启用认证
username: "mNrz1aEg", // 用户名
password: "3xV3dBYB" // 密码
};
async function setupGlobalProxy() {
console.log('🔧 开始配置全局代理...\n');
try {
// 这里需要在Electron应用启动后调用
// 因为需要访问app.sdb数据库
console.log('📋 代理配置信息:');
console.log(` 状态: ${PROXY_CONFIG.proxyStatus === "true" ? "启用" : "禁用"}`);
console.log(` 类型: ${PROXY_CONFIG.proxyType.toUpperCase()}`);
console.log(` 地址: ${PROXY_CONFIG.proxyIp}:${PROXY_CONFIG.proxyPort}`);
console.log(` 认证: ${PROXY_CONFIG.userVerifyStatus === "true" ? "启用" : "禁用"}`);
console.log(` 用户: ${PROXY_CONFIG.username}`);
console.log(` 密码: ${'*'.repeat(PROXY_CONFIG.password.length)}\n`);
// 检查是否存在全局代理配置
const existingConfig = await app.sdb.selectOne("global_proxy_config");
if (existingConfig) {
console.log('📝 更新现有的全局代理配置...');
await app.sdb.update("global_proxy_config", PROXY_CONFIG);
console.log('✅ 全局代理配置更新成功!');
} else {
console.log('📝 创建新的全局代理配置...');
await app.sdb.insert("global_proxy_config", PROXY_CONFIG);
console.log('✅ 全局代理配置创建成功!');
}
console.log('\n🎯 配置完成!请重启应用以应用新的代理设置。');
console.log('\n📋 验证步骤:');
console.log(' 1. 重启应用');
console.log(' 2. 打开任意平台WhatsApp/Telegram/TikTok');
console.log(' 3. 查看控制台日志,应该看到代理配置成功的消息');
console.log(' 4. 测试网络连接');
} catch (error) {
console.error('❌ 配置全局代理失败:', error);
console.error('💡 请确保在Electron应用启动后调用此函数');
}
}
// 验证当前全局代理配置
async function verifyGlobalProxy() {
console.log('🔍 验证当前全局代理配置...\n');
try {
const config = await app.sdb.selectOne("global_proxy_config");
if (!config) {
console.log('❌ 未找到全局代理配置');
return false;
}
console.log('📋 当前全局代理配置:');
console.log(` ID: ${config.id}`);
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(` 密码: ${config.password ? "✅ 已设置" : "❌ 未设置"}`);
// 检查配置完整性
const isValid = config.proxyStatus === "true" &&
config.proxyIp &&
config.proxyPort &&
config.proxyType;
if (isValid) {
console.log('\n✅ 全局代理配置有效');
return true;
} else {
console.log('\n❌ 全局代理配置无效或不完整');
return false;
}
} catch (error) {
console.error('❌ 验证全局代理配置失败:', error);
return false;
}
}
// 清除全局代理配置
async function clearGlobalProxy() {
console.log('🧹 清除全局代理配置...\n');
try {
await app.sdb.update("global_proxy_config", {
proxyStatus: "false",
proxyType: "http",
proxyIp: "",
proxyPort: "",
userVerifyStatus: "false",
username: "",
password: ""
});
console.log('✅ 全局代理配置已清除');
} catch (error) {
console.error('❌ 清除全局代理配置失败:', error);
}
}
// 导出函数
module.exports = {
setupGlobalProxy,
verifyGlobalProxy,
clearGlobalProxy,
PROXY_CONFIG
};
// 如果直接运行此文件
if (require.main === module) {
console.log('⚠️ 这个脚本需要在Electron应用启动后调用');
console.log('💡 请在应用的控制台中运行以下命令:');
console.log('');
console.log(' const { setupGlobalProxy } = require("./setup_global_proxy.js");');
console.log(' setupGlobalProxy();');
console.log('');
console.log('🔧 或者直接在全局代理设置页面手动配置:');
console.log(` 代理协议: ${PROXY_CONFIG.proxyType.toUpperCase()}`);
console.log(` 主机地址: ${PROXY_CONFIG.proxyIp}`);
console.log(` 端口号: ${PROXY_CONFIG.proxyPort}`);
console.log(` 启用认证: 是`);
console.log(` 用户名: ${PROXY_CONFIG.username}`);
console.log(` 密码: ${PROXY_CONFIG.password}`);
}