Skip to content

Commit

Permalink
Merge pull request #1908 from yaklang/song/feat/mitmFromPlugin
Browse files Browse the repository at this point in the history
Song/feat/mitm from plugin
  • Loading branch information
luoluoTH authored Aug 13, 2024
2 parents 81ff8f9 + 5e1905b commit 638e18c
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3415,19 +3415,18 @@ export const HTTPFlowTable = React.memo<HTTPFlowTableProp>((props) => {
selectTypeList = ["mitm"]
}
}
const newParams = {...params, SourceType: selectTypeList.join(",")}
getHTTPFlowsFieldGroup(true, (t: FiltersItemProps[]) => {
let tagsList: string[] = []
mitmHasParamsNamesArr.forEach((item) => {
if (t.findIndex((ele) => ele.label === item) !== -1) {
tagsList.push(item)
}
})
setTagsFilter(tagsList)
newParams.Tags = tagsList
const newParams = {...params, SourceType: selectTypeList.join(","), FromPlugin: mitmHasParamsNames}
if (JSON.stringify(params.SourceType?.split(",") || [""]) === JSON.stringify(selectTypeList)) {
setParams(newParams)
emiter.emit("onHistorySourceTypeToMitm", newParams.SourceType)
})
setTimeout(() => {
updateData()
}, 20)
} else {
setParams(newParams)
setTimeout(() => {
emiter.emit("onHistorySourceTypeToMitm", newParams.SourceType)
}, 20)
}
})

// mitm页面带参数插件跳转过来
Expand Down
42 changes: 26 additions & 16 deletions app/renderer/src/main/src/pages/mitm/MITMPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const MITMPage: React.FC<MITMPageProp> = (props) => {
const [statusCards, setStatusCards] = useState<StatusCardProps[]>([])
const [downstreamProxyStr, setDownstreamProxyStr] = useState<string>("")
const [showPluginHistoryList, setShowPluginHistoryList] = useState<string[]>([])
const [tempShowPluginHistory, setTempShowPluginHistory] = useState<string>("")
// 检测当前劫持状态
useEffect(() => {
// 用于启动 MITM 开始之后,接受开始成功之后的第一个消息,如果收到,则认为说 MITM 启动成功了
Expand Down Expand Up @@ -342,6 +343,8 @@ export const MITMPage: React.FC<MITMPageProp> = (props) => {
onIsHasParams={setIsHasParams}
showPluginHistoryList={showPluginHistoryList}
setShowPluginHistoryList={setShowPluginHistoryList}
tempShowPluginHistory={tempShowPluginHistory}
setTempShowPluginHistory={setTempShowPluginHistory}
/>
)
}
Expand Down Expand Up @@ -456,6 +459,8 @@ interface MITMServerProps {
onIsHasParams: (isHasParams: boolean) => void
showPluginHistoryList: string[]
setShowPluginHistoryList: (l: string[]) => void
tempShowPluginHistory?: string
setTempShowPluginHistory?: (t: string) => void
}
export const MITMServer: React.FC<MITMServerProps> = React.memo((props) => {
const {
Expand All @@ -469,7 +474,9 @@ export const MITMServer: React.FC<MITMServerProps> = React.memo((props) => {
isHasParams,
onIsHasParams = () => {},
showPluginHistoryList,
setShowPluginHistoryList
tempShowPluginHistory,
setShowPluginHistoryList,
setTempShowPluginHistory
} = props

const [openTabsFlag, setOpenTabsFlag] = useState<boolean>(true)
Expand Down Expand Up @@ -503,24 +510,24 @@ export const MITMServer: React.FC<MITMServerProps> = React.memo((props) => {
() => {
if (status === "idle") {
const CHECK_CACHE_LIST_DATA = "CHECK_CACHE_LIST_DATA"
getRemoteValue(CHECK_CACHE_LIST_DATA)
.then((data: string) => {
getRemoteValue(CONST_DEFAULT_ENABLE_INITIAL_PLUGIN).then((is) => {
if (!!data && !!is) {
const cacheData: string[] = JSON.parse(data)
if (cacheData.length) {
onIsHasParams(false)
}
getRemoteValue(CHECK_CACHE_LIST_DATA).then((data: string) => {
getRemoteValue(CONST_DEFAULT_ENABLE_INITIAL_PLUGIN).then((is) => {
if (!!data && !!is) {
const cacheData: string[] = JSON.parse(data)
if (cacheData.length) {
onIsHasParams(false)
} else {
if (noParamsCheckList.length) {
onIsHasParams(false)
} else {
onIsHasParams(true)
}
onIsHasParams(true)
}
})
} else {
if (noParamsCheckList.length) {
onIsHasParams(false)
} else {
onIsHasParams(true)
}
}
})

})
}
},
[status, noParamsCheckList],
Expand Down Expand Up @@ -779,7 +786,9 @@ export const MITMServer: React.FC<MITMServerProps> = React.memo((props) => {
onSetOpenTabsFlag={setOpenTabsFlag}
onSetLoadedPluginLen={setLoadedPluginLen}
showPluginHistoryList={showPluginHistoryList}
tempShowPluginHistory={tempShowPluginHistory}
setShowPluginHistoryList={setShowPluginHistoryList}
setTempShowPluginHistory={setTempShowPluginHistory}
/>
)
}
Expand Down Expand Up @@ -818,6 +827,7 @@ export const MITMServer: React.FC<MITMServerProps> = React.memo((props) => {
loadedPluginLen={loadedPluginLen}
onSelectAll={onSelectAll}
setShowPluginHistoryList={setShowPluginHistoryList}
setTempShowPluginHistory={setTempShowPluginHistory}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface MITMHijackedContentProps {
loadedPluginLen: number
onSelectAll: (e: boolean) => void
setShowPluginHistoryList: (l: string[]) => void
setTempShowPluginHistory?: (t: string) => void
}

const MITMHijackedContent: React.FC<MITMHijackedContentProps> = React.memo((props) => {
Expand All @@ -48,7 +49,8 @@ const MITMHijackedContent: React.FC<MITMHijackedContentProps> = React.memo((prop
downstreamProxyStr,
loadedPluginLen,
onSelectAll,
setShowPluginHistoryList
setShowPluginHistoryList,
setTempShowPluginHistory
} = props
// 自动转发 与 劫持响应的自动设置
const [autoForward, setAutoForward, getAutoForward] = useGetState<"manual" | "log" | "passive">("log")
Expand Down Expand Up @@ -295,6 +297,7 @@ const MITMHijackedContent: React.FC<MITMHijackedContentProps> = React.memo((prop
forward()
}
setShowPluginHistoryList([])
setTempShowPluginHistory && setTempShowPluginHistory("")
setSourceType("mitm")
} catch (e) {
console.info(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import styles from "./MITMServerHijacking.module.scss"
import classNames from "classnames"
import {RemoteGV} from "@/yakitGV"
import {YakitRadioButtons} from "@/components/yakitUI/YakitRadioButtons/YakitRadioButtons"
import emiter from "@/utils/eventBus/eventBus"

const {ipcRenderer} = window.require("electron")

Expand Down Expand Up @@ -62,6 +63,8 @@ interface MITMPluginHijackContentProps {
onSetLoadedPluginLen: (s: number) => void
showPluginHistoryList: string[]
setShowPluginHistoryList: (l: string[]) => void
tempShowPluginHistory?: string
setTempShowPluginHistory?: (t: string) => void
}
const HotLoadDefaultData: YakScript = {
Id: 0,
Expand Down Expand Up @@ -108,6 +111,8 @@ export const MITMPluginHijackContent: React.FC<MITMPluginHijackContentProps> = (
onSetLoadedPluginLen,
showPluginHistoryList,
setShowPluginHistoryList,
tempShowPluginHistory = "",
setTempShowPluginHistory
} = props

const [curTabKey, setCurTabKey] = useState<tabKeys>("all")
Expand Down Expand Up @@ -147,6 +152,11 @@ export const MITMPluginHijackContent: React.FC<MITMPluginHijackContentProps> = (
// 是否允许获取默认勾选值
const isDefaultCheck = useRef<boolean>(false)

const tempShowPluginHistoryRef = useRef<string>(tempShowPluginHistory)
useEffect(() => {
tempShowPluginHistoryRef.current = tempShowPluginHistory
}, [tempShowPluginHistory])

// 初始化加载 hooks,设置定时更新 hooks 状态
useEffect(() => {
updateHooks()
Expand Down Expand Up @@ -222,6 +232,10 @@ export const MITMPluginHijackContent: React.FC<MITMPluginHijackContentProps> = (
}
}
})
if (tempShowPluginHistoryRef.current && hasParamsCheckArr.includes(tempShowPluginHistoryRef.current)) {
setShowPluginHistoryList([tempShowPluginHistoryRef.current])
emiter.emit("onHasParamsJumpHistory", [tempShowPluginHistoryRef.current].join(","))
}
setHasParamsCheckList([...hasParamsCheckArr])
setNoParamsCheckList([...noParamsCheckArr])
})
Expand Down Expand Up @@ -499,6 +513,7 @@ export const MITMPluginHijackContent: React.FC<MITMPluginHijackContentProps> = (
hasParamsCheckList={hasParamsCheckList}
showPluginHistoryList={showPluginHistoryList}
setShowPluginHistoryList={setShowPluginHistoryList}
setTempShowPluginHistory={setTempShowPluginHistory}
curTabKey={curTabKey}
/>
)}
Expand Down Expand Up @@ -590,6 +605,7 @@ export const MITMPluginHijackContent: React.FC<MITMPluginHijackContentProps> = (
showPluginHistoryList={showPluginHistoryList}
setShowPluginHistoryList={setShowPluginHistoryList}
curTabKey={curTabKey}
setTempShowPluginHistory={setTempShowPluginHistory}
/>
</YakitSpin>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ interface MITMPluginLocalListProps {
isHasParams: boolean
showPluginHistoryList?: string[]
setShowPluginHistoryList?: (l: string[]) => void
setTempShowPluginHistory?: (t: string) => void
hasParamsCheckList: string[]
curTabKey?: string
}
Expand Down Expand Up @@ -122,6 +123,7 @@ export const MITMPluginLocalList: React.FC<MITMPluginLocalListProps> = React.mem
isHasParams,
showPluginHistoryList = [],
setShowPluginHistoryList = () => {},
setTempShowPluginHistory,
hasParamsCheckList,
curTabKey = ""
} = props
Expand Down Expand Up @@ -272,6 +274,7 @@ export const MITMPluginLocalList: React.FC<MITMPluginLocalListProps> = React.mem
showPluginHistoryList={showPluginHistoryList}
setShowPluginHistoryList={setShowPluginHistoryList}
hasParamsCheckList={hasParamsCheckList}
setTempShowPluginHistory={setTempShowPluginHistory}
// 劫持启动前
defaultPlugins={noParamsCheckList}
setDefaultPlugins={setNoParamsCheckList}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export interface MITMServerHijackingProp {
onIsHasParams: (isHasParams: boolean) => void
showPluginHistoryList: string[]
setShowPluginHistoryList: (l: string[]) => void
tempShowPluginHistory: string
setTempShowPluginHistory: (t: string) => void
}

const {ipcRenderer} = window.require("electron")
Expand Down Expand Up @@ -82,7 +84,9 @@ export const MITMServerHijacking: React.FC<MITMServerHijackingProp> = (props) =>
isHasParams,
onIsHasParams,
showPluginHistoryList,
setShowPluginHistoryList
setShowPluginHistoryList,
tempShowPluginHistory,
setTempShowPluginHistory
} = props

const {queryPagesDataById, removePagesDataCacheById} = usePageInfo(
Expand Down Expand Up @@ -142,6 +146,7 @@ export const MITMServerHijacking: React.FC<MITMServerHijackingProp> = (props) =>
.then(() => {
onIsHasParams(false)
setShowPluginHistoryList([])
setTempShowPluginHistory("")
setStatus("idle")
resolve("ok")
})
Expand Down Expand Up @@ -252,6 +257,8 @@ export const MITMServerHijacking: React.FC<MITMServerHijackingProp> = (props) =>
downstreamProxyStr={downstreamProxyStr}
showPluginHistoryList={showPluginHistoryList}
setShowPluginHistoryList={setShowPluginHistoryList}
tempShowPluginHistory={tempShowPluginHistory}
setTempShowPluginHistory={setTempShowPluginHistory}
/>
</div>
<React.Suspense fallback={<div>loading...</div>}>
Expand Down
21 changes: 19 additions & 2 deletions app/renderer/src/main/src/pages/mitm/MITMYakScriptLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const MITMYakScriptLoader = React.memo((p: MITMYakScriptLoaderProps) => {
showEditor,
showPluginHistoryList = [],
setShowPluginHistoryList = () => {},
setTempShowPluginHistory,
hasParamsCheckList,
curTabKey
} = p
Expand Down Expand Up @@ -127,12 +128,15 @@ export const MITMYakScriptLoader = React.memo((p: MITMYakScriptLoaderProps) => {
const saveParams: CustomPluginExecuteFormValue = {...values}
const saveParasmArr: YakExecutorParam[] = []
Object.keys(saveParams).forEach((key) => {
saveParasmArr.push({Key: key, Value: saveParams[key]})
if (saveParams[key] !== false) {
saveParasmArr.push({Key: key, Value: saveParams[key]})
}
})
setRemoteValue("mitm_has_params_" + i.ScriptName, JSON.stringify(saveParasmArr))
if (submitFlag) {
clearMITMPluginCache()
onSubmitYakScriptId(script.Id, saveParasmArr)
setTempShowPluginHistory && setTempShowPluginHistory(i.ScriptName)
}
m.destroy()
}
Expand Down Expand Up @@ -223,12 +227,24 @@ export const MITMYakScriptLoader = React.memo((p: MITMYakScriptLoaderProps) => {
[style["history-icon-light"]]: showPluginHistoryList.includes(i.ScriptName)
})}
onClick={() => {
// 多个
// let arr = [...showPluginHistoryList]
// if (arr.includes(i.ScriptName)) {
// arr = arr.filter((item) => item !== i.ScriptName)
// } else {
// arr.push(i.ScriptName)
// }

// 单个
let arr = [...showPluginHistoryList]
if (arr.includes(i.ScriptName)) {
arr = arr.filter((item) => item !== i.ScriptName)
} else {
arr.push(i.ScriptName)
arr = [i.ScriptName]
}

setTempShowPluginHistory && setTempShowPluginHistory("")

setShowPluginHistoryList(arr)
emiter.emit("onHasParamsJumpHistory", arr.join(","))
}}
Expand Down Expand Up @@ -343,6 +359,7 @@ export interface MITMYakScriptLoaderProps {
showEditor: boolean
showPluginHistoryList?: string[]
setShowPluginHistoryList?: (l: string[]) => void
setTempShowPluginHistory?: (l: string) => void
hasParamsCheckList: string[]
curTabKey: string
}
Expand Down

0 comments on commit 638e18c

Please sign in to comment.