Werkzeug version (2.0.1) now shows the ip of the server being run. given this information a QR code pointing to the address is displayed on the terminal
This commit is contained in:
kush5683 2021-06-16 10:54:07 -04:00
parent 28a1ac1612
commit eb86e98ca7
1 changed files with 18 additions and 5 deletions

View File

@ -2,6 +2,7 @@ import os
import signal
import argparse
from flask import Flask, render_template, send_file, redirect, request, send_from_directory, url_for, abort
from flask_httpauth import HTTPBasicAuth
from werkzeug.utils import secure_filename
@ -12,6 +13,12 @@ from updog.utils.path import is_valid_subpath, is_valid_upload_path, get_parent_
from updog.utils.output import error, info, warn, success
from updog import version as VERSION
# added to print QRcode for given address from get_interface_ip
import socket
import pyqrcode
from werkzeug.serving import get_interface_ip
from pyqrcode import QRCode
def read_write_directory(directory):
if os.path.exists(directory):
@ -31,9 +38,12 @@ def parse_arguments():
'[Default=.]')
parser.add_argument('-p', '--port', type=int, default=9090,
help='Port to serve [Default=9090]')
parser.add_argument('--password', type=str, default='', help='Use a password to access the page. (No username)')
parser.add_argument('--ssl', action='store_true', help='Use an encrypted connection')
parser.add_argument('--version', action='version', version='%(prog)s v'+VERSION)
parser.add_argument('--password', type=str, default='',
help='Use a password to access the page. (No username)')
parser.add_argument('--ssl', action='store_true',
help='Use an encrypted connection')
parser.add_argument('--version', action='version',
version='%(prog)s v'+VERSION)
args = parser.parse_args()
@ -106,7 +116,8 @@ def main():
if os.path.exists(requested_path):
# Read the files
try:
directory_files = process_files(os.scandir(requested_path), base_directory)
directory_files = process_files(
os.scandir(requested_path), base_directory)
except PermissionError:
abort(403, 'Read Permission Denied: ' + requested_path)
@ -176,7 +187,9 @@ def main():
ssl_context = None
if args.ssl:
ssl_context = 'adhoc'
QR_link = f"http://{get_interface_ip(socket.AF_INET)}:{args.port}/"
QR_encoding = pyqrcode.create(QR_link)
print(QR_encoding.terminal(quiet_zone=1))
run_simple("0.0.0.0", int(args.port), app, ssl_context=ssl_context)