Skip to content

Commit

Permalink
feat: 首页劫持跳转问题 (#1808)
Browse files Browse the repository at this point in the history
* feat: 首页劫持跳转问题

* pref: 逻辑调整
  • Loading branch information
song-xiao-lin authored Jul 12, 2024
1 parent 1190de4 commit b303e16
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 29 deletions.
10 changes: 10 additions & 0 deletions app/main/handlers/mitm.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ module.exports = (win, getClient) => {
}
})

// host port
ipcMain.handle("mitm-host-port", (e, host, port) => {
if (stream) {
stream.write({
host,
port,
})
}
})

// 开始调用 MITM,设置 stream
let isFirstData = true
ipcMain.handle("mitm-start-call", (e, host, port, downstreamProxy, enableHttp2, ForceDisableKeepAlive,certificates, extra) => {
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/src/main/src/assets/icon/outline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5343,7 +5343,7 @@ const OutlineModScanPortData = () => (
d='M13.5 6H14.5C15.6046 6 16.5 6.89543 16.5 8V13C16.5 14.1046 15.6046 15 14.5 15H3.5C2.39543 15 1.5 14.1046 1.5 13V8C1.5 6.89543 2.39543 6 3.5 6H4.5'
stroke='currentColor'
strokeLinecap='round'
stroke-linejoin='round'
strokeLinejoin='round'
/>
<path
d='M13.5 6V4.75C13.5 4.19772 13.0523 3.75 12.5 3.75H12M4.5 6V4.75C4.5 4.19772 4.94772 3.75 5.5 3.75H6'
Expand Down
4 changes: 4 additions & 0 deletions app/renderer/src/main/src/pages/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import {YakitEmpty} from "@/components/yakitUI/YakitEmpty/YakitEmpty"
import {YakitResizeBox} from "@/components/yakitUI/YakitResizeBox/YakitResizeBox"
import ReactResizeDetector from "react-resize-detector"
import {SolidBorderDocumentTextIcon} from "@/assets/icon/colors"
import {CONST_DEFAULT_ENABLE_INITIAL_PLUGIN} from "../mitm/MITMPage"
const {ipcRenderer} = window.require("electron")

interface ToolInfo {
Expand Down Expand Up @@ -380,6 +381,9 @@ const Home: React.FC<HomeProp> = (props) => {
form.setFieldsValue({port: "8083"})
}
})
getRemoteValue(CONST_DEFAULT_ENABLE_INITIAL_PLUGIN).then((a) => {
form.setFieldsValue({enableInitialPlugin: !!a})
})

updateProjectDbSize()
undateHistoryData()
Expand Down
40 changes: 40 additions & 0 deletions app/renderer/src/main/src/pages/mitm/MITMPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ import {YakitSelect} from "@/components/yakitUI/YakitSelect/YakitSelect"
import emiter from "@/utils/eventBus/eventBus"
import {YakitRoute} from "@/enums/yakitRoute"
import {apiDownloadPluginOther, apiQueryYakScript} from "../plugins/utils"
import {setRemoteValue} from "@/utils/kv"
import {MITMConsts} from "./MITMConsts"
import { onSetRemoteValuesBase } from "@/components/yakitUI/utils"
import { CacheDropDownGV } from "@/yakitGV"
const {ipcRenderer} = window.require("electron")

export interface MITMPageProp {}
Expand Down Expand Up @@ -350,6 +354,32 @@ export const MITMPage: React.FC<MITMPageProp> = (props) => {
// .catch((e) => yakitFailed("获取规则列表失败:" + e))
// })

useEffect(() => {
const onChangeAddrAndEnableInitialPlugin = (values) => {
try {
const valObj = JSON.parse(values) || {}
setAddr(`http://${valObj.host}:${valObj.port} 或 socks5://${valObj.host}:${valObj.port}`)
setHost(valObj.host)
setPort(valObj.port)
setEnableInitialMITMPlugin(valObj.enableInitialPlugin)
if (!valObj.enableInitialPlugin) {
emiter.emit("onClearMITMHackPlugin")
}
setRemoteValue(MITMConsts.MITMDefaultPort, `${valObj.port}`)
onSetRemoteValuesBase({
cacheHistoryDataKey: CacheDropDownGV.MITMDefaultHostHistoryList,
newValue: valObj.host,
isCacheDefaultValue: true
})
setRemoteValue(CONST_DEFAULT_ENABLE_INITIAL_PLUGIN, valObj.enableInitialPlugin ? "true" : "")
} catch (error) {}
}
emiter.on("onChangeAddrAndEnableInitialPlugin", onChangeAddrAndEnableInitialPlugin)
return () => {
emiter.off("onChangeAddrAndEnableInitialPlugin", onChangeAddrAndEnableInitialPlugin)
}
}, [])

return (
<>
<div
Expand Down Expand Up @@ -516,6 +546,16 @@ export const MITMServer: React.FC<MITMServerProps> = React.memo((props) => {
}
})

useEffect(() => {
const onClearMITMHackPlugin = () => {
onSelectAllHijacking(false)
}
emiter.on("onClearMITMHackPlugin", onClearMITMHackPlugin)
return () => {
emiter.off("onClearMITMHackPlugin", onClearMITMHackPlugin)
}
}, [])

const onEnableMITMPluginMode = useMemoizedFn((checked: boolean) => {
enableMITMPluginMode(listNames)
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {Ref, useEffect, useImperativeHandle, useRef, useState} from "reac
import {Divider, Form, Modal, notification, Typography} from "antd"
import emiter from "@/utils/eventBus/eventBus"
import ChromeLauncherButton from "@/pages/mitm/MITMChromeLauncher"
import {failed, info} from "@/utils/notification"
import {failed, info, yakitNotify} from "@/utils/notification"
import {useHotkeys} from "react-hotkeys-hook"
import {useGetState, useLatest, useMemoizedFn} from "ahooks"
import {ExecResultLog} from "@/pages/invoker/batch/ExecMessageViewer"
Expand Down Expand Up @@ -93,18 +93,19 @@ export const MITMServerHijacking: React.FC<MITMServerHijackingProp> = (props) =>
const info = initPageInfo()?.immediatelyLaunchedInfo
if (info && status !== "idle") {
removePagesDataCacheById(YakitRoute.HTTPHacker, YakitRoute.HTTPHacker)
stop().then(() => {
setTimeout(() => {
emiter.emit(
"onExecStartMITM",
JSON.stringify({
host: info.host,
port: info.port,
enableInitialPlugin: info.enableInitialPlugin
})
)
}, 300)
ipcRenderer.invoke("IsChromeLaunched").then((e) => {
if (e) {
ipcRenderer.invoke("mitm-host-port", info.host, info.port)
}
})
emiter.emit(
"onChangeAddrAndEnableInitialPlugin",
JSON.stringify({
host: info.host,
port: info.port,
enableInitialPlugin: info.enableInitialPlugin
})
)
}
}, [initPageInfo()?.immediatelyLaunchedInfo, status])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import emiter from "@/utils/eventBus/eventBus"
import {PageNodeItemProps, usePageInfo} from "@/store/pageInfo"
import {shallow} from "zustand/shallow"
import {YakitRoute} from "@/enums/yakitRoute"
import {onSetRemoteValuesBase} from "@/components/yakitUI/utils"
const MITMFormAdvancedConfiguration = React.lazy(() => import("./MITMFormAdvancedConfiguration"))
const ChromeLauncherButton = React.lazy(() => import("../MITMChromeLauncher"))

Expand Down Expand Up @@ -219,21 +220,6 @@ export const MITMServerStartForm: React.FC<MITMServerStartFormProp> = React.memo
const nowTime: string = Math.floor(new Date().getTime() / 1000).toString()
setRemoteValue(MITMConsts.MITMStartTimeStamp, nowTime)
})
const beforeExecStartMITM = (values) => {
if (props.status === "idle") {
try {
const valObj = JSON.parse(values) || {}
form.setFieldsValue({...valObj})
} catch (error) {}
execStartMITM(form.getFieldsValue())
}
}
useEffect(() => {
emiter.on("onExecStartMITM", beforeExecStartMITM)
return () => {
emiter.off("onExecStartMITM", beforeExecStartMITM)
}
}, [])

useEffect(() => {
const info = initPageInfo()?.immediatelyLaunchedInfo
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/src/main/src/utils/eventBus/events/mitm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export type MitmEventProps = {
onSetFilterWhiteListEvent: string
/** 是否开启替换规则 */
onOpenRepRuleEvent: string
onExecStartMITM: string
onChangeAddrAndEnableInitialPlugin: string
onClearMITMHackPlugin?: string
}

0 comments on commit b303e16

Please sign in to comment.