Skip to content
Open

B #1

Show file tree
Hide file tree
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
104 changes: 104 additions & 0 deletions .claude/SessionStart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/bash
# SessionStart hook for Claude Code
# This script runs when a new Claude Code session starts

# Configure Maven settings for dependency downloads
echo "Configuring Maven settings..."

# Create .m2 directory if it doesn't exist
mkdir -p ~/.m2

# Create settings.xml with repo1.maven.org mirror and proxy configuration
cat > ~/.m2/settings.xml << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">

<proxies>
<proxy>
<id>local-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>127.0.0.1</host>
<port>3128</port>
</proxy>
</proxies>

<profiles>
<profile>
<id>repo-maven-org</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<activeProfiles>
<activeProfile>repo-maven-org</activeProfile>
</activeProfiles>

<mirrors>
<mirror>
<id>maven-central-mirror</id>
<name>Maven Central via repo1.maven.org</name>
<url>https://repo1.maven.org/maven2</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
</settings>
EOF

# Create .mvn directory and maven.config for HTTP client settings
mkdir -p .mvn
cat > .mvn/maven.config << 'EOFCONFIG'
-Daether.connector.http.supportWebDav=false
-Daether.connector.https.securityMode=insecure
-Dmaven.wagon.http.ssl.insecure=true
-Dmaven.wagon.http.ssl.allowall=true
EOFCONFIG

# Start the local proxy tunnel if not already running
if ! pgrep -f "local-proxy-tunnel.py" > /dev/null; then
echo "Starting local proxy tunnel..."
if [ -f ".claude/local-proxy-tunnel.py" ]; then
nohup python3 .claude/local-proxy-tunnel.py > /tmp/proxy-tunnel.log 2>&1 &
sleep 1
if pgrep -f "local-proxy-tunnel.py" > /dev/null; then
echo "Proxy tunnel started on 127.0.0.1:3128"
else
echo "Warning: Proxy tunnel failed to start. Check /tmp/proxy-tunnel.log"
fi
else
echo "Warning: .claude/local-proxy-tunnel.py not found. Maven may not be able to download dependencies."
echo "Run the proxy manually: python3 .claude/local-proxy-tunnel.py &"
fi
else
echo "Proxy tunnel already running on 127.0.0.1:3128"
fi

echo "Maven settings configured successfully at ~/.m2/settings.xml"
echo ".mvn/maven.config created for HTTP client settings"
echo "Using local proxy tunnel (127.0.0.1:3128) → upstream proxy"
166 changes: 166 additions & 0 deletions .claude/local-proxy-tunnel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#!/usr/bin/env python3
"""
Local HTTP/HTTPS proxy tunnel with proper CONNECT support.
"""
import os
import socket
import select
import threading
import sys
from urllib.parse import urlparse

# Parse the upstream proxy
proxy_url = os.getenv('https_proxy') or os.getenv('HTTPS_PROXY')
if not proxy_url:
print("Error: No proxy found in environment")
sys.exit(1)

parsed = urlparse(proxy_url)
UPSTREAM_HOST = parsed.hostname
UPSTREAM_PORT = parsed.port
UPSTREAM_USER = parsed.username
UPSTREAM_PASS = parsed.password

LOCAL_HOST = '127.0.0.1'
LOCAL_PORT = 3128

print(f"Upstream: {UPSTREAM_HOST}:{UPSTREAM_PORT}")

def forward_data(source, destination):
"""Forward data from source to destination"""
try:
while True:
data = source.recv(8192)
if not data:
break
destination.sendall(data)
except:
pass
finally:
try:
source.shutdown(socket.SHUT_RD)
destination.shutdown(socket.SHUT_WR)
except:
pass

def handle_client(client_sock):
"""Handle client connection"""
try:
# Read first line of request
request_line = b''
while b'\r\n' not in request_line:
chunk = client_sock.recv(1)
if not chunk:
return
request_line += chunk

# Connect to upstream proxy
upstream = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
upstream.connect((UPSTREAM_HOST, UPSTREAM_PORT))

# Check if this is a CONNECT request (HTTPS)
if request_line.startswith(b'CONNECT '):
# Read rest of headers
headers = request_line
while b'\r\n\r\n' not in headers:
chunk = client_sock.recv(1)
if not chunk:
return
headers += chunk

# Add proxy auth if needed
if UPSTREAM_USER and UPSTREAM_PASS:
import base64
auth = f"{UPSTREAM_USER}:{UPSTREAM_PASS}".encode()
auth_b64 = base64.b64encode(auth).decode()
auth_header = f"Proxy-Authorization: Basic {auth_b64}\r\n"
headers = headers.replace(b'\r\n\r\n', f'\r\n{auth_header}\r\n'.encode())

# Send CONNECT to upstream
upstream.sendall(headers)

# Read upstream response
response = b''
while b'\r\n\r\n' not in response:
chunk = upstream.recv(1)
if not chunk:
return
response += chunk

# Forward response to client
client_sock.sendall(response)

# Now bidirectionally forward all data
client_to_upstream = threading.Thread(
target=forward_data, args=(client_sock, upstream))
upstream_to_client = threading.Thread(
target=forward_data, args=(upstream, client_sock))

client_to_upstream.daemon = True
upstream_to_client.daemon = True

client_to_upstream.start()
upstream_to_client.start()

client_to_upstream.join()
upstream_to_client.join()
else:
# Regular HTTP request
# Read all headers
headers = request_line
while b'\r\n\r\n' not in headers:
chunk = client_sock.recv(1)
if not chunk:
return
headers += chunk

# Add proxy auth
if UPSTREAM_USER and UPSTREAM_PASS:
import base64
auth = f"{UPSTREAM_USER}:{UPSTREAM_PASS}".encode()
auth_b64 = base64.b64encode(auth).decode()
auth_header = f"Proxy-Authorization: Basic {auth_b64}\r\n"
headers = headers.replace(b'\r\n\r\n', f'\r\n{auth_header}\r\n'.encode())

upstream.sendall(headers)

# Forward data
while True:
data = upstream.recv(8192)
if not data:
break
client_sock.sendall(data)

except Exception as e:
print(f"Error: {e}")
finally:
try:
client_sock.close()
except:
pass
try:
upstream.close()
except:
pass

def main():
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind((LOCAL_HOST, LOCAL_PORT))
server.listen(10)

print(f"Listening on {LOCAL_HOST}:{LOCAL_PORT}")

try:
while True:
client, addr = server.accept()
t = threading.Thread(target=handle_client, args=(client,))
t.daemon = True
t.start()
except KeyboardInterrupt:
print("\nStopping...")
finally:
server.close()

if __name__ == '__main__':
main()
4 changes: 4 additions & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-Daether.connector.http.supportWebDav=false
-Daether.connector.https.securityMode=insecure
-Dmaven.wagon.http.ssl.insecure=true
-Dmaven.wagon.http.ssl.allowall=true
Loading