updated palworld config and added webpages for simple restore
This commit is contained in:
1 parent
01d5a95476
commit
dcdc4265cb
7 files changed
+346
-1
No files matched your search
@@ -0,0 +1,74 @@
|
||||
import os
|
||||
|
||||
import docker
|
||||
from flask import Flask, render_template, redirect, url_for, Blueprint
|
||||
from flask_basicauth import BasicAuth
|
||||
|
||||
app_base = Flask(__name__)
|
||||
|
||||
CONTAINER_NAME = os.environ["CONTAINER_NAME"]
|
||||
|
||||
app_base.config["BASIC_AUTH_USERNAME"] = os.environ["USERNAME"]
|
||||
app_base.config["BASIC_AUTH_PASSWORD"] = os.environ["PASSWORD"]
|
||||
app_base.config["BASIC_AUTH_FORCE"] = True
|
||||
|
||||
basic_auth = BasicAuth(app_base)
|
||||
|
||||
client = docker.from_env()
|
||||
|
||||
palworld_bp = Blueprint('palworld', __name__, template_folder="templates", url_prefix="/palworld")
|
||||
|
||||
|
||||
|
||||
def get_container():
|
||||
try:
|
||||
return client.containers.get(CONTAINER_NAME)
|
||||
except docker.errors.NotFound:
|
||||
return None
|
||||
|
||||
|
||||
@palworld_bp.route("/")
|
||||
def index():
|
||||
container = get_container()
|
||||
|
||||
if container is None:
|
||||
return f"Container '{CONTAINER_NAME}' not found.", 404
|
||||
|
||||
try:
|
||||
container.reload()
|
||||
running = container.status == "running"
|
||||
except:
|
||||
return "There was an issue reading container state", 500
|
||||
|
||||
return render_template(
|
||||
"index.html",
|
||||
running=running,
|
||||
container_name=CONTAINER_NAME,
|
||||
)
|
||||
|
||||
|
||||
@palworld_bp.route("/toggle", methods=["POST"])
|
||||
def toggle():
|
||||
try:
|
||||
container = get_container()
|
||||
|
||||
if container is None:
|
||||
return f"Container '{CONTAINER_NAME}' not found.", 404
|
||||
|
||||
container.reload()
|
||||
|
||||
if container.status == "running":
|
||||
container.stop()
|
||||
else:
|
||||
container.start()
|
||||
except docker.errors.APIError as err:
|
||||
return f"There was an issue managing containers\n {err}", 500
|
||||
|
||||
|
||||
return redirect(url_for("palworld.index"))
|
||||
|
||||
app_base.register_blueprint(palworld_bp)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app_base.run(host="0.0.0.0", port=5000)
|
||||
Reference in new issue
Block a user