Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easier way to access the site #34

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions updog/__main__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,6 +14,12 @@
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):
Expand All @@ -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()

Expand Down Expand Up @@ -106,7 +117,8 @@ def home(path):
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)

Expand Down Expand Up @@ -177,6 +189,9 @@ def handler(signal, frame):
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)


Expand Down