Commit b9955b1a by César Galvis

feat: web server for PAC working

parent 6d6c1969
......@@ -32,5 +32,7 @@ Vagrant.configure("2") do |config|
config.vm.provision "shell", path: "src/scripts/ps/ChocolateyInstall.ps1"
## Install Chocolatey packages
config.vm.provision "shell", path: "src/scripts/ps/ChocolateyInstallPackages.ps1"
## Set up PAC
config.vm.provision "shell", path: "src/scripts/ps/PacScheduledTask.ps1"
end
function FindProxyForURL(url, host) {
// Only use proxy if the destination IP is 192.168.11.0/24
if (isInNet(host, "192.168.11.0", "255.255.255.0")) {
return "PROXY 192.168.56.10:3128";
}
// For everything else, connect directly
return "DIRECT";
}
\ No newline at end of file
# PAC (Proxy Auto-Config) scheduled task setup
# Bypass policy
Set-ExecutionPolicy Bypass -Force
# Create scheduled task
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -File C:\\vagrant\src\scripts\ps\PacSetup.ps1"
$Trigger = New-ScheduledTaskTrigger -AtStartup
$Principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
Register-ScheduledTask -TaskName "StartPACServer" -Action $Action -Trigger $Trigger -Principal $Principal -Settings $Settings
\ No newline at end of file
# PAC (Proxy Auto-Config) setup
# Create small web server
$listener = [System.Net.HttpListener]::new()
$listener.Prefixes.Add("http://*:8080/")
$listener.Start()
Write-Host "Serving proxy.pac on http://localhost:8080/proxy.pac"
while ($listener.IsListening) {
$context = $listener.GetContext()
$response = $context.Response
$buffer = [System.IO.File]::ReadAllBytes("C:\vagrant\src\config\proxy.pac")
$response.ContentLength64 = $buffer.Length
$response.OutputStream.Write($buffer, 0, $buffer.Length)
$response.OutputStream.Close()
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment