Files
litterbox/litterbox.py
T

48 lines
1.4 KiB
Python
Raw Normal View History

2024-12-27 05:02:19 -08:00
import os
2025-01-06 05:38:54 -08:00
import sys
2024-12-27 05:02:19 -08:00
import ctypes
2025-01-06 05:38:54 -08:00
import argparse
from app import create_app, setup_logging
2024-12-27 05:02:19 -08:00
def is_running_as_admin():
"""Check if the script is running with administrative privileges."""
try:
return ctypes.windll.shell32.IsUserAnAdmin() != 0
except AttributeError:
2025-01-06 05:38:54 -08:00
return os.geteuid() == 0
2024-12-27 05:02:19 -08:00
2025-01-06 05:38:54 -08:00
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--debug', action='store_true', help='Enable debug mode')
2025-08-31 22:10:42 +03:00
parser.add_argument('--ip', type=str, help='Specify host IP address (e.g., --ip 192.168.1.120)')
2025-01-06 05:38:54 -08:00
args = parser.parse_args()
2025-08-31 22:10:42 +03:00
2024-12-27 05:02:19 -08:00
if not is_running_as_admin():
2025-01-06 05:38:54 -08:00
print("[!] This script requires administrative privileges. Please run as administrator.")
sys.exit(1)
2025-08-31 22:10:42 +03:00
2025-01-06 05:38:54 -08:00
app = create_app()
2025-08-31 22:10:42 +03:00
# Set host IP if provided
if args.ip:
app.config['application']['host'] = args.ip
print(f"[+] Host IP set to: {args.ip}")
2025-01-06 05:38:54 -08:00
# Enable debug mode based on the `--debug` flag
if args.debug:
app.config['DEBUG'] = True
app.config['application']['debug'] = True # Optional if your custom config also uses it
2025-08-31 22:10:42 +03:00
2025-01-06 05:38:54 -08:00
# Set up logging based on the debug mode
setup_logging(app)
2025-08-31 22:10:42 +03:00
2025-01-06 05:38:54 -08:00
# Run the app
2024-12-27 05:02:19 -08:00
app.run(
host=app.config['application']['host'],
port=app.config['application']['port'],
2025-01-06 05:38:54 -08:00
debug=app.config['DEBUG'] # Flask debug mode
2024-12-27 05:02:19 -08:00
)
2025-01-06 05:38:54 -08:00
if __name__ == '__main__':
2025-08-31 22:10:42 +03:00
main()