Created
May 6, 2024 04:11
-
-
Save Erotemic/94b1e0a84f304b879913e58bb09efb92 to your computer and use it in GitHub Desktop.
Attempt to log in a PAC file (not working)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/66514500/how-do-i-configure-a-python-server-for-post | |
# Run a test server on port 8000 | |
python -c 'if 1: | |
from http.server import BaseHTTPRequestHandler, HTTPServer | |
class handler(BaseHTTPRequestHandler): | |
def do_GET(self): | |
self.send_response(200) | |
self.send_header("Content-type", "text/html") | |
self.end_headers() | |
message = "Hello, World! Here is a GET response" | |
self.wfile.write(bytes(message, "utf8")) | |
def do_POST(self): | |
print("GOT POST") | |
self.send_response(200) | |
self.send_header("Content-type","text/html") | |
self.end_headers() | |
file_length = int(self.headers["Content-Length"]) | |
input_bytes = self.rfile.read(file_length) | |
print(input_bytes) | |
print(self.__dict__) | |
print(self.headers.__dict__) | |
message = "Hello, World! Here is a POST response" | |
self.wfile.write(bytes(message, "utf8")) | |
print("FINISHED RESPONDING TO POST") | |
with HTTPServer(("", 8000), handler) as server: | |
server.serve_forever() | |
' | |
# --- different terminal | |
# Send the above server a test message | |
curl -H 'Content-Type: application/json' \ | |
-d '{ "title":"foo","body":"bar", "id": 1}' \ | |
-X POST \ | |
0.0.0.0:8000 | |
# Write a PAC file that attempt to do some sort of logging | |
echo ' | |
function FindProxyForURL(url, host) | |
{ | |
var socks_proxy = "SOCKS 127.0.0.1:8080"; | |
// Attempt to log that this function was used | |
fetch("0.0.0.0:8000", { | |
method: "POST", | |
body: JSON.stringify({ | |
userId: 1, | |
title: "Fix my bugs", | |
completed: false | |
}), | |
headers: { | |
"Content-type": "application/json; charset=UTF-8" | |
} | |
}); | |
if (shExpMatch(host, "*.google.com")) { | |
return socks_proxy; | |
} | |
return "DIRECT"; | |
} | |
' > "$HOME"/.config/custom_proxy/proxy.pac | |
# Manual step: point to PAC file in firefox | |
# TODO: can this be scripted with Ubuntu's 24.04 default snap firefox? | |
# Point to PAC file in the system settings | |
gsettings set org.gnome.system.proxy autoconfig-url "file:///home/joncrall/.config/custom_proxy/proxy.pac" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment