✨ default username and password
This commit is contained in:
parent
830f04d710
commit
eff7d1c887
1 changed files with 31 additions and 3 deletions
|
@ -7,6 +7,8 @@ import http.server
|
||||||
import socket
|
import socket
|
||||||
import socketserver
|
import socketserver
|
||||||
import qrcode
|
import qrcode
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
|
|
||||||
def get_current_ip_address():
|
def get_current_ip_address():
|
||||||
|
@ -17,24 +19,50 @@ def get_current_ip_address():
|
||||||
return 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
|
# Define the command-line arguments
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Start a simple HTTP server with basic authentication."
|
description="Start a simple HTTP server with basic authentication."
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
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(
|
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(
|
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(
|
parser.add_argument(
|
||||||
"--directory",
|
"--directory",
|
||||||
default=os.getcwd(),
|
default=os.getcwd(),
|
||||||
help="Directory to serve. Defaults to the current directory.",
|
help="Directory to serve. Defaults to the current directory.",
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Expand the directory path (e.g., if it contains ~)
|
# Expand the directory path (e.g., if it contains ~)
|
||||||
|
|
Loading…
Reference in a new issue