| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| import type { HttpProxyServerHandle } from "@/mitm/inspector/httpProxyServer";
|
| import type { PreviousState } from "@/mitm/inspector/systemProxyConfig";
|
|
|
|
|
|
|
| let httpProxyHandle: HttpProxyServerHandle | null = null;
|
|
|
| export function getHttpProxyHandle(): HttpProxyServerHandle | null {
|
| return httpProxyHandle;
|
| }
|
|
|
| export function setHttpProxyHandle(handle: HttpProxyServerHandle | null): void {
|
| httpProxyHandle = handle;
|
| }
|
|
|
|
|
|
|
| interface SystemProxyState {
|
| applied: boolean;
|
| port: number | null;
|
| guardUntil: string | null;
|
| previousState: PreviousState | null;
|
| }
|
|
|
| let systemProxyState: SystemProxyState = {
|
| applied: false,
|
| port: null,
|
| guardUntil: null,
|
| previousState: null,
|
| };
|
|
|
| let guardTimer: ReturnType<typeof setTimeout> | null = null;
|
|
|
| export function getSystemProxyState(): Readonly<SystemProxyState> {
|
| return { ...systemProxyState };
|
| }
|
|
|
| export function setSystemProxyApplied(
|
| port: number,
|
| previousState: PreviousState,
|
| guardMinutes: number
|
| ): void {
|
| if (guardTimer) clearTimeout(guardTimer);
|
|
|
| const guardUntil = new Date(Date.now() + guardMinutes * 60_000).toISOString();
|
| systemProxyState = { applied: true, port, guardUntil, previousState };
|
|
|
| guardTimer = setTimeout(
|
| () => {
|
|
|
|
|
| import("@/mitm/inspector/systemProxyConfig").then(({ revert }) => {
|
| const ps = systemProxyState.previousState;
|
| systemProxyState = { applied: false, port: null, guardUntil: null, previousState: null };
|
| if (ps) revert(ps).catch(() => {});
|
| }).catch(() => {});
|
| },
|
| guardMinutes * 60_000
|
| );
|
| }
|
|
|
| export function clearSystemProxy(): void {
|
| if (guardTimer) {
|
| clearTimeout(guardTimer);
|
| guardTimer = null;
|
| }
|
| systemProxyState = { applied: false, port: null, guardUntil: null, previousState: null };
|
| }
|
|
|
|
|
|
|
| let tlsInterceptEnabled = process.env.INSPECTOR_TLS_INTERCEPT === "true";
|
|
|
| export function isTlsInterceptEnabled(): boolean {
|
| return tlsInterceptEnabled;
|
| }
|
|
|
| export function setTlsIntercept(enabled: boolean): void {
|
| tlsInterceptEnabled = enabled;
|
| }
|
|
|