Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to stop intercepting powershell #125

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions src/interceptors/terminal/terminal-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,31 @@ export const getFishShellScript = (callbackUrl: string, env: { [name: string]: s
echo 'HTTP Toolkit interception enabled'
`;

export const getPowerShellScript = (callbackUrl: string, env: { [name: string]: string }) => `${
_.map(env, (value, key) => ` $Env:${key} = "${value.replace(/"/g, '`"')}"`).join('\n')
export const getPowerShellScript = (callbackUrl: string, env: { [name: string]: string }) => `
$HTTPTOOLKIT_envVars = Get-ChildItem Env:

${
_.map(env, (value, key) => ` $Env:${key} = "${value.replace(/"/g, '`"')}"`).join('\n')
}

function Stop-Intercepting {

#Remove every env
$currentEnvVars = Get-ChildItem Env:
foreach ($envVar in $currentEnvVars) {
[System.Environment]::SetEnvironmentVariable($envVar.Name, $null)
}

#Set the old env variables
foreach ($var in $HTTPTOOLKIT_envVars) {
[System.Environment]::SetEnvironmentVariable($var.Name, $var.Value)
}

#Revert these two back to the default values
$PSDefaultParameterValues.Remove("invoke-webrequest:proxy")
$PSDefaultParameterValues.Remove("invoke-webrequest:SkipCertificateCheck")

Write-Host 'HTTP Toolkit interception disabled'
}

# We add a few special hooks just for Invoke-WebRequest.
Expand All @@ -137,7 +160,8 @@ export const getPowerShellScript = (callbackUrl: string, env: { [name: string]:
# Let the HTTP Toolkit app know this ran succesfully
Start-Job -ScriptBlock { Invoke-WebRequest "${callbackUrl}" -NoProxy -Method 'POST' } | out-null

Write-Host 'HTTP Toolkit interception enabled'
Write-Host "HTTP Toolkit interception enabled\`nTo stop intercepting type " -NoNewline
Write-Host "Stop-Intercepting" -ForegroundColor Red
`;

// Find the relevant user shell config file, add the above line to it, so that
Expand Down