From 1e1e5793dd4034c03db259abe45954eadb4c6c09 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 15 Dec 2024 17:00:25 +0000 Subject: [PATCH] chore: remove contrib/ directory It only contained proxy that some users ran in Termux to look at IMAP traffic. The same can be achieved with `socat`, e.g.: socat -v TCP-LISTEN:9999,bind=127.0.0.1 OPENSSL:nine.testrun.org:993 --- contrib/proxy.py | 80 ------------------------------------------------ 1 file changed, 80 deletions(-) delete mode 100644 contrib/proxy.py diff --git a/contrib/proxy.py b/contrib/proxy.py deleted file mode 100644 index 13e1b69784..0000000000 --- a/contrib/proxy.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python3 -# Examples: -# -# Original server that doesn't use SSL: -# ./proxy.py 8080 imap.nauta.cu 143 -# ./proxy.py 8081 smtp.nauta.cu 25 -# -# Original server that uses SSL: -# ./proxy.py 8080 testrun.org 993 --ssl -# ./proxy.py 8081 testrun.org 465 --ssl - -from datetime import datetime -import argparse -import selectors -import ssl -import socket -import socketserver - - -class Proxy(socketserver.ThreadingTCPServer): - allow_reuse_address = True - - def __init__(self, proxy_host, proxy_port, real_host, real_port, use_ssl): - self.real_host = real_host - self.real_port = real_port - self.use_ssl = use_ssl - super().__init__((proxy_host, proxy_port), RequestHandler) - - -class RequestHandler(socketserver.BaseRequestHandler): - - def handle(self): - print('{} - {} CONNECTED.'.format(datetime.now(), self.client_address)) - - total = 0 - real_server = (self.server.real_host, self.server.real_port) - with socket.create_connection(real_server) as sock: - if self.server.use_ssl: - context = ssl.create_default_context() - sock = context.wrap_socket( - sock, server_hostname=real_server[0]) - - forward = {self.request: sock, sock: self.request} - - sel = selectors.DefaultSelector() - sel.register(self.request, selectors.EVENT_READ, - self.client_address) - sel.register(sock, selectors.EVENT_READ, real_server) - - active = True - while active: - events = sel.select() - for key, mask in events: - print('\n{} - {} wrote:'.format(datetime.now(), key.data)) - data = key.fileobj.recv(1024) - received = len(data) - total += received - print(data) - print('{} Bytes\nTotal: {} Bytes'.format(received, total)) - if data: - forward[key.fileobj].sendall(data) - else: - print('\nCLOSING CONNECTION.\n\n') - forward[key.fileobj].close() - key.fileobj.close() - active = False - - -if __name__ == '__main__': - p = argparse.ArgumentParser(description='Simple Python Proxy') - p.add_argument( - "proxy_port", help="the port where the proxy will listen", type=int) - p.add_argument('host', help="the real host") - p.add_argument('port', help="the port of the real host", type=int) - p.add_argument("--ssl", help="use ssl to connect to the real host", - action="store_true") - args = p.parse_args() - - with Proxy('', args.proxy_port, args.host, args.port, args.ssl) as proxy: - proxy.serve_forever()