Additional Clean Up, Favicons, etc.

This commit is contained in:
2026-04-15 22:03:19 -05:00
parent 105d897c64
commit 4e1fb5e5ec
17 changed files with 887 additions and 9 deletions

35
app.py
View File

@@ -1,3 +1,19 @@
# Icolotl Index Webserver
# Copyright (C) 2026 Morgana <morgana@icolotl.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import json
from hashlib import scrypt
from os import urandom
@@ -6,6 +22,7 @@ from colorsys import rgb_to_hsv
from flask import Flask, render_template, request, redirect, url_for, session, abort
from flask_pymongo import PyMongo
from werkzeug.exceptions import HTTPException
from bson import ObjectId
import bson.json_util as bson
import requests
@@ -42,8 +59,10 @@ def partition(predicate, iterable):
@app.context_processor
def inject_data():
ddata = db.domains.find_one({"id": request.endpoint})
return dict(hue=ddata["quad"])
if request.endpoint:
ddata = db.domains.find_one({"id": request.endpoint})
return {"hue": ddata.get("quad", "ade")}
return {"hue": "ade"}
@app.before_request
@@ -54,7 +73,7 @@ def apply_checks():
ddata = db.domains.find_one_or_404({"id": request.endpoint})
udata = db.users.find_one({"id": username}) if username else None
if not can_access(ddata, udata):
abort(401)
abort(403 if udata else 401)
def can_access(ddata, udata) -> bool:
@@ -126,6 +145,11 @@ def help():
return render_template("help.html")
@app.route("/license")
def license():
return render_template("license.html")
@app.post("/login")
def login():
username = request.form.get("username")
@@ -443,3 +467,8 @@ def lighting():
return render_template("lighting.html", ldatas=result)
except requests.exceptions.ConnectionError:
abort(500)
@app.errorhandler(HTTPException)
def handle_error(error):
return render_template("error.html", error=error), error.code