docker. basic auth.
This commit is contained in:
parent
6a1c7a36d8
commit
54054b4f6d
6 changed files with 58 additions and 11 deletions
|
@ -3,7 +3,7 @@ FROM python:3.9-alpine
|
|||
RUN mkdir -p /app
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk add tzdata --no-cache
|
||||
RUN apk add tzdata build-base libffi-dev py3-cffi --no-cache
|
||||
|
||||
ENV TZ=America/New_York
|
||||
ENV VIRTUAL_ENV=/app/env
|
||||
|
|
|
@ -31,4 +31,20 @@ pushover.enabled = false
|
|||
# your specific pushover token
|
||||
pushover.token =
|
||||
# your specific pushover user key
|
||||
pushover.user_key =
|
||||
pushover.user_key =
|
||||
|
||||
[WEB]
|
||||
# should we enable the webserver which is just a simple, simple, simple webui to view the logs
|
||||
web.enabled = false
|
||||
# the port to run on
|
||||
web.port = 9547
|
||||
# the app root / web folder / root / many other names . MUST contain a trailing '/'
|
||||
web.app_root = /
|
||||
# should this served up on http or https
|
||||
web.ssl = true
|
||||
# should we use basic auth
|
||||
web.basic_auth = true
|
||||
# basic auth username
|
||||
web.basic_auth.username = admin
|
||||
# basic auth password
|
||||
web.basic_auth.password = admin
|
|
@ -4,4 +4,6 @@ urllib3==1.26.9
|
|||
sqlalchemy==1.4.36
|
||||
sqlalchemy_utils==0.38.2
|
||||
python-dateutil==2.8.2
|
||||
Flask==2.1.2
|
||||
Flask==2.1.2
|
||||
Flask-BasicAuth==0.2.0
|
||||
pyopenssl==22.0.0
|
|
@ -75,7 +75,12 @@ class ConfigReader(ConfigParser):
|
|||
},
|
||||
'WEB': {
|
||||
'web.enabled': 'false',
|
||||
'web.port': '9647'
|
||||
'web.app_root': '/',
|
||||
'web.port': '9647',
|
||||
'web.ssl': 'true',
|
||||
'web.basic_auth': 'true',
|
||||
'web.basic_auth.username': 'admin',
|
||||
'web.basic_auth.password': 'p@ssw0rd'
|
||||
}
|
||||
}
|
||||
deprecated_values = {
|
||||
|
|
|
@ -14,7 +14,7 @@ console_output.setLevel(logging.INFO)
|
|||
console_format = logging.Formatter(log_format)
|
||||
console_output.setFormatter(console_format)
|
||||
|
||||
info_log_file = RotatingFileHandler('../config/info.log', maxBytes=10000, backupCount=10)
|
||||
info_log_file = RotatingFileHandler('../config/info.log', maxBytes=100000, backupCount=10)
|
||||
info_log_file.setLevel(logging.INFO)
|
||||
info_log_format = logging.Formatter(log_format)
|
||||
info_log_file.setFormatter(info_log_format)
|
||||
|
|
36
src/run.py
36
src/run.py
|
@ -2,6 +2,8 @@ import threading
|
|||
from random import randint
|
||||
from time import sleep
|
||||
|
||||
from flask_basicauth import BasicAuth
|
||||
|
||||
import log
|
||||
from ConfigReader import ConfigReader, ConfigException
|
||||
from SteamGifts import SteamGifts, SteamGiftsException
|
||||
|
@ -14,9 +16,17 @@ logger = log.get_logger(__name__)
|
|||
|
||||
class WebServerThread(threading.Thread):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, config):
|
||||
Thread.__init__(self)
|
||||
self.exc = None
|
||||
self.config = config
|
||||
self.port = config['WEB'].getint('web.port')
|
||||
self.ssl = config['WEB'].getboolean('web.ssl')
|
||||
self.enabled = config['WEB'].getboolean('web.enabled')
|
||||
self.app_root = config['WEB'].get('web.app_root')
|
||||
self.basic_auth = config['WEB'].getboolean('web.basic_auth')
|
||||
self.basic_auth_username = config['WEB'].get('web.basic_auth.username')
|
||||
self.basic_auth_password = config['WEB'].get('web.basic_auth.password')
|
||||
|
||||
def run_webserver(self):
|
||||
from flask import Flask
|
||||
|
@ -24,17 +34,24 @@ class WebServerThread(threading.Thread):
|
|||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/")
|
||||
if self.basic_auth:
|
||||
app.config['BASIC_AUTH_USERNAME'] = self.basic_auth_username
|
||||
app.config['BASIC_AUTH_PASSWORD'] = self.basic_auth_password
|
||||
|
||||
app.config['BASIC_AUTH_FORCE'] = self.basic_auth
|
||||
basic_auth = BasicAuth(app)
|
||||
|
||||
@app.route(f"{self.app_root}")
|
||||
def config():
|
||||
with open('../config/config.ini', 'r') as f:
|
||||
content = f.read()
|
||||
return render_template('configuration.html', config=content)
|
||||
|
||||
@app.route("/log")
|
||||
@app.route(f"{self.app_root}log")
|
||||
def logs():
|
||||
return render_template('log.html')
|
||||
|
||||
@app.route("/stream")
|
||||
@app.route(f"{self.app_root}stream")
|
||||
def stream():
|
||||
def generate():
|
||||
with open('../config/info.log') as f:
|
||||
|
@ -44,7 +61,14 @@ class WebServerThread(threading.Thread):
|
|||
|
||||
return app.response_class(generate(), mimetype='text/plain')
|
||||
|
||||
app.run(port=9647, host="0.0.0.0")
|
||||
if self.enabled:
|
||||
logger.info("Webserver Enabled. Running")
|
||||
if self.ssl:
|
||||
app.run(port=self.port, host="0.0.0.0", ssl_context='adhoc')
|
||||
else:
|
||||
app.run(port=self.port, host="0.0.0.0")
|
||||
else:
|
||||
logger.info("Webserver NOT Enabled.")
|
||||
|
||||
def run(self):
|
||||
# Variable that stores the exception, if raised by someFunction
|
||||
|
@ -151,7 +175,7 @@ def run():
|
|||
g.setName("Giveaway Enterer")
|
||||
g.start()
|
||||
|
||||
w = WebServerThread()
|
||||
w = WebServerThread(config)
|
||||
w.setName("WebServer")
|
||||
# if the giveaway thread dies then this daemon thread will die by definition
|
||||
w.setDaemon(True)
|
||||
|
|
Loading…
Reference in a new issue