diff --git a/share-via-http.py b/share-via-http.py index 6e6e2c4..a0fb06a 100644 --- a/share-via-http.py +++ b/share-via-http.py @@ -7,6 +7,8 @@ import http.server import socket import socketserver import qrcode +import random +import string def get_current_ip_address(): @@ -17,24 +19,50 @@ def get_current_ip_address(): return ip_address +# Function to generate a default username +def generate_default_username(): + return "user_" + "".join( + random.choices(string.ascii_lowercase + string.digits, k=8) + ) + + +# Function to generate a default password +def generate_default_password(): + return "".join( + random.choices(string.ascii_letters + string.digits + string.punctuation, k=12) + ) + + # Define the command-line arguments parser = argparse.ArgumentParser( description="Start a simple HTTP server with basic authentication." ) + parser.add_argument( - "--port", type=int, default=8000, help="Port to serve the directory over." + "--port", + type=int, + default=8000, + help="Port to serve the directory over. Defaults to 8000.", ) + parser.add_argument( - "--username", required=True, help="Username for basic authentication." + "--username", + default=generate_default_username(), + help="Username for basic authentication. Generates one if not set", ) + parser.add_argument( - "--password", required=True, help="Password for basic authentication." + "--password", + default=generate_default_password(), + help="Password for basic authentication. Generates one if not set", ) + parser.add_argument( "--directory", default=os.getcwd(), help="Directory to serve. Defaults to the current directory.", ) + args = parser.parse_args() # Expand the directory path (e.g., if it contains ~)