回滚代码
This commit is contained in:
parent
d11390e453
commit
021738a8bb
9
proxy/config.ini
Normal file
9
proxy/config.ini
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[proxy]
|
||||||
|
target_host = superstar.geelytravel.com
|
||||||
|
target_port = 443
|
||||||
|
target_protocol = https
|
||||||
|
; target_host = zentao.sunyard.com.cn
|
||||||
|
; target_port = 9788
|
||||||
|
; target_protocol = http
|
||||||
|
b_host = localhost
|
||||||
|
b_port = 8080
|
||||||
@ -3,12 +3,25 @@ import socket
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
import configparser
|
||||||
|
import os
|
||||||
|
|
||||||
# Configuration
|
# Configuration from config.ini
|
||||||
TARGET_HOST = "zentao.sunyard.com.cn"
|
CONFIG_FILE = os.path.join(os.path.dirname(__file__), 'config.ini')
|
||||||
TARGET_PORT = 9788
|
|
||||||
B_HOST = "localhost"
|
def load_config():
|
||||||
B_PORT = 8080
|
config = configparser.ConfigParser()
|
||||||
|
config.read(CONFIG_FILE)
|
||||||
|
|
||||||
|
target_host = config.get('proxy', 'target_host', fallback='zentao.sunyard.com.cn')
|
||||||
|
target_port = config.getint('proxy', 'target_port', fallback=9788)
|
||||||
|
target_protocol = config.get('proxy', 'target_protocol', fallback='http').lower()
|
||||||
|
b_host = config.get('proxy', 'b_host', fallback='localhost')
|
||||||
|
b_port = config.getint('proxy', 'b_port', fallback=8080)
|
||||||
|
|
||||||
|
return target_host, target_port, target_protocol, b_host, b_port
|
||||||
|
|
||||||
|
TARGET_HOST, TARGET_PORT, TARGET_PROTOCOL, B_HOST, B_PORT = load_config()
|
||||||
|
|
||||||
# Global lock for socket write operations
|
# Global lock for socket write operations
|
||||||
socket_write_lock = threading.Lock()
|
socket_write_lock = threading.Lock()
|
||||||
@ -69,9 +82,9 @@ def modify_request_headers(request_data):
|
|||||||
line_str = line
|
line_str = line
|
||||||
|
|
||||||
if line_str.startswith("Origin:"):
|
if line_str.startswith("Origin:"):
|
||||||
new_lines.append("Origin: http://%s:%d" % (TARGET_HOST, TARGET_PORT))
|
new_lines.append("Origin: %s://%s:%d" % (TARGET_PROTOCOL, TARGET_HOST, TARGET_PORT))
|
||||||
elif line_str.startswith("Referer:"):
|
elif line_str.startswith("Referer:"):
|
||||||
new_lines.append("Referer: http://%s:%d/" % (TARGET_HOST, TARGET_PORT))
|
new_lines.append("Referer: %s://%s:%d/" % (TARGET_PROTOCOL, TARGET_HOST, TARGET_PORT))
|
||||||
elif line_str.startswith("Host:"):
|
elif line_str.startswith("Host:"):
|
||||||
new_lines.append("Host: %s:%d" % (TARGET_HOST, TARGET_PORT))
|
new_lines.append("Host: %s:%d" % (TARGET_HOST, TARGET_PORT))
|
||||||
elif line_str.lower().startswith("connection:"):
|
elif line_str.lower().startswith("connection:"):
|
||||||
@ -90,7 +103,7 @@ def modify_request_headers(request_data):
|
|||||||
modified_data = "\r\n".join(new_lines)
|
modified_data = "\r\n".join(new_lines)
|
||||||
|
|
||||||
if path.startswith("/"):
|
if path.startswith("/"):
|
||||||
new_path = "http://%s:%d%s" % (TARGET_HOST, TARGET_PORT, path)
|
new_path = "%s://%s:%d%s" % (TARGET_PROTOCOL, TARGET_HOST, TARGET_PORT, path)
|
||||||
if method and modified_data:
|
if method and modified_data:
|
||||||
modified_data = modified_data.replace(path, new_path, 1)
|
modified_data = modified_data.replace(path, new_path, 1)
|
||||||
|
|
||||||
@ -111,7 +124,7 @@ def handle_request(request_data):
|
|||||||
if "\r\n\r\n" in modified_data:
|
if "\r\n\r\n" in modified_data:
|
||||||
body_size = len(modified_data) - modified_data.find("\r\n\r\n") - 4
|
body_size = len(modified_data) - modified_data.find("\r\n\r\n") - 4
|
||||||
|
|
||||||
log_info("System", "Request: %s %s%s - Body: %d bytes - ID: %s" % (method, "http://" + TARGET_HOST + ":" + str(TARGET_PORT), path, body_size, request_id))
|
log_info("System", "Request: %s %s://%s:%d%s - Body: %d bytes - ID: %s" % (method, TARGET_PROTOCOL, TARGET_HOST, TARGET_PORT, path, body_size, request_id))
|
||||||
|
|
||||||
target_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
target_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
target_sock.settimeout(30)
|
target_sock.settimeout(30)
|
||||||
@ -282,7 +295,7 @@ def main():
|
|||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
print(" Proxy Client (Run on Computer A)")
|
print(" Proxy Client (Run on Computer A)")
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
print("Target website:", TARGET_HOST, ":", TARGET_PORT)
|
print("Target website:", TARGET_PROTOCOL, "://", TARGET_HOST, ":", TARGET_PORT)
|
||||||
print("Device B address:", B_HOST, ":", B_PORT)
|
print("Device B address:", B_HOST, ":", B_PORT)
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user