yakit mitm config

This commit is contained in:
go0p
2026-08-06 15:11:35 +08:00
committed by go0p
parent 3166331cf3
commit 22f73e67e8
4 changed files with 94 additions and 3 deletions
+38
View File
@@ -132,6 +132,44 @@ class ProxyStore {
// 忽略接收者不存在的错误
});
}
async addAndEnableProxy(config) {
try {
// 先禁用所有其他代理
const existingConfigs = await this.getProxyConfigs();
for (const existingConfig of existingConfigs) {
if (existingConfig.enabled) {
await this.saveProxyConfigs([{
...existingConfig,
enabled: false
}]);
}
}
// 添加并启用新代理
await this.saveProxyConfigs([config]);
// 应用新代理
await chrome.proxy.settings.set({
value: {
mode: config.proxyType,
rules: {
singleProxy: {
scheme: config.scheme,
host: config.host,
port: config.port
}
}
},
scope: 'regular'
});
return { success: true };
} catch (error) {
console.error('Error in addAndEnableProxy:', error);
return { success: false, error };
}
}
}
export const proxyStore = new ProxyStore();
+3 -1
View File
@@ -28,10 +28,12 @@
"sidePanel",
"webRequest",
"declarativeNetRequest",
"webNavigation",
"tabs"
],
"host_permissions": [
"<all_urls>"
"<all_urls>",
"*://mitm/*"
],
"web_accessible_resources": [
+51 -1
View File
@@ -292,7 +292,54 @@ async function queueProxyLog(details, error = null) {
}
}
// 导出代理处理器设置函数
// 添加 URL 拦截处理
function setupUrlInterceptor() {
chrome.webNavigation.onBeforeNavigate.addListener(async (details) => {
try {
const url = new URL(details.url);
if (url.hostname === 'mitm') {
// 解析参数
const host = url.searchParams.get('host');
const port = parseInt(url.searchParams.get('port') || '0');
const scheme = url.searchParams.get('scheme');
if (host && port && scheme) {
// 创建新的代理配置
const newConfig = {
id: Date.now().toString(),
name: "Yakit MITM",
proxyType: 'fixed_servers',
scheme: scheme,
host: host,
port: port,
enabled: true
};
// 直接使用 proxyStore 实例的方法
const result = await proxyStore.addAndEnableProxy(newConfig);
if (result.success) {
// 重定向回 mitm 页面
chrome.tabs.update(details.tabId, {
url: "http://mitm/"
});
} else {
console.error('Failed to add and enable proxy:', result.error);
}
}
}
} catch (error) {
console.error('Error handling proxy URL:', error);
}
}, {
url: [{
hostEquals: 'mitm'
}]
});
}
// 修改 setupProxyHandlers 函数
export function setupProxyHandlers() {
// 设置代理错误处理和认证
ProxyAuth.setupErrorHandler();
@@ -301,6 +348,9 @@ export function setupProxyHandlers() {
// 设置代理请求监听器
setupProxyRequestListener();
// 设置 URL 拦截器
setupUrlInterceptor();
// 消息监听器
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
console.log("Proxy message:", msg);
+2 -1
View File
@@ -8,5 +8,6 @@ export const ProxyActionType = {
CLEAR_PROXY_LOGS: "CLEAR_PROXY_LOGS",
GET_PROXY_CONFIGS: "GET_PROXY_CONFIGS",
ADD_PROXY_CONFIG: "ADD_PROXY_CONFIG",
UPDATE_PROXY_CONFIG: "UPDATE_PROXY_CONFIG"
UPDATE_PROXY_CONFIG: "UPDATE_PROXY_CONFIG",
ADD_AND_ENABLE_PROXY: 'ADD_AND_ENABLE_PROXY'
};