docker. basic auth.
This commit is contained in:
parent
6a1c7a36d8
commit
54054b4f6d
6 changed files with 58 additions and 11 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue