This commit is contained in:
Kush Shah 2021-06-16 11:03:33 -04:00 committed by GitHub
commit 1b7e99ca5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 4 deletions

View File

@ -1,6 +1,8 @@
import os
import signal
import argparse
import socket
from flask import Flask, render_template, send_file, redirect, request, send_from_directory, url_for, abort
from flask_httpauth import HTTPBasicAuth
@ -12,6 +14,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 +39,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 +117,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)
@ -177,6 +189,9 @@ def main():
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=0))
run_simple("0.0.0.0", int(args.port), app, ssl_context=ssl_context)