diff --git a/.DS_Store b/.DS_Store index a7ec040..f6d68b0 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/pf b/pf new file mode 100755 index 0000000..ebc8ac0 --- /dev/null +++ b/pf @@ -0,0 +1,75 @@ +#!/usr/bin/python3 +import socket +import threading +import select + +def forward(source, destination): + try: + while True: + ready, _, _ = select.select([source], [], [], 1) + if ready: + data = source.recv(4096) + if not data: + break + destination.sendall(data) + except (OSError, socket.error) as e: + print(f"Connection error: {e}") + finally: + try: + source.shutdown(socket.SHUT_RD) + except OSError: + pass + try: + destination.shutdown(socket.SHUT_WR) + except OSError: + pass + +def handle(client_socket, remote_host, remote_port): + try: + remote_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + remote_socket.connect((remote_host, remote_port)) + + thread1 = threading.Thread(target=forward, args=(client_socket, remote_socket)) + thread2 = threading.Thread(target=forward, args=(remote_socket, client_socket)) + + thread1.start() + thread2.start() + + thread1.join() + thread2.join() + except Exception as e: + print(f"Error in handle: {e}") + finally: + client_socket.close() + remote_socket.close() + +def create_forwarder(local_host, local_port, remote_host, remote_port): + server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + server_socket.bind((local_host, local_port)) + server_socket.listen(5) + + print(f"Forwarding {local_host}:{local_port} to {remote_host}:{remote_port}") + + while True: + try: + client_socket, address = server_socket.accept() + print(f"Received connection from {address}") + threading.Thread(target=handle, args=(client_socket, remote_host, remote_port)).start() + except Exception as e: + print(f"Error accepting connection: {e}") + +def main(): + listen_ip = '0.0.0.0' + + imap_thread = threading.Thread(target=create_forwarder, args=(listen_ip, 1143, '127.0.0.1', 1142)) + imap_thread.start() + + smtp_thread = threading.Thread(target=create_forwarder, args=(listen_ip, 1025, '127.0.0.1', 1024)) + smtp_thread.start() + + imap_thread.join() + smtp_thread.join() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/up b/up index 8825538..6ba5ebd 100755 --- a/up +++ b/up @@ -1,23 +1,69 @@ #!/bin/bash -# Navigate to your project directory -cd ~/workshop/sijapi +# Path to the file containing the list of repositories +REPOS_FILE=~/workshop/repos.txt -# Pull the latest changes from the repository -echo "Pulling from main branch..." -git pull origin main +# Check if the repos file exists +if [ ! -f "$REPOS_FILE" ]; then + echo "Error: $REPOS_FILE does not exist." + exit 1 +fi -# Add changes to the Git index (staging area) -echo "Adding all changes..." -git add . +# Read the repos file and process each directory +while IFS= read -r repo_path || [[ -n "$repo_path" ]]; do + # Trim whitespace + repo_path=$(echo "$repo_path" | xargs) -# Commit changes -echo "Committing changes..." -git commit -m "Auto-update: $(date)" + # Skip empty lines + [ -z "$repo_path" ] && continue -# Push changes to the remote repository -echo "Pushing all changes..." -git push origin main + # Expand tilde to home directory + repo_path="${repo_path/#\~/$HOME}" -echo "Update complete!" + # Check if the directory exists + if [ ! -d "$repo_path" ]; then + echo "Warning: Directory $repo_path does not exist. Skipping." + continue + fi + + echo "Processing repository: $repo_path" + + # Navigate to the project directory + cd "$repo_path" || { echo "Error: Unable to change to directory $repo_path"; continue; } + + # Check if it's a git repository + if [ ! -d .git ]; then + echo "Warning: $repo_path is not a git repository. Skipping." + continue + fi + + # Get the current branch + current_branch=$(git rev-parse --abbrev-ref HEAD) + + # Pull the latest changes from the repository + echo "Pulling from $current_branch branch..." + git pull origin "$current_branch" + + # Add changes to the Git index (staging area) + echo "Adding all changes..." + git add . + + # Check if there are changes to commit + if git diff-index --quiet HEAD --; then + echo "No changes to commit." + else + # Commit changes + echo "Committing changes..." + git commit -m "Auto-update: $(date)" + + # Push changes to the remote repository + echo "Pushing all changes..." + git push origin "$current_branch" + fi + + echo "Update complete for $repo_path!" + echo "----------------------------------------" +done < "$REPOS_FILE" + +echo "All repositories processed."