From 1f32755adef4e532d6563111fa7b1494c8699cc5 Mon Sep 17 00:00:00 2001 From: Takeus <68923554+TakeusV1@users.noreply.github.com> Date: Tue, 17 Jun 2025 09:45:52 +0200 Subject: [PATCH 1/2] V1.5 - Rewrite theme system - Fixes --- app/_config.py | 5 ++--- app/models.py | 1 + app/routes/r_auth.py | 2 +- app/routes/r_base.py | 15 +++++++++++---- app/routes/r_inventory.py | 5 ++--- app/routes/r_networks.py | 6 +++--- app/templates/auth/_base.html | 6 +++--- app/templates/panel/_base.html | 6 +++--- app/templates/panel/_nav.html | 15 +++++++++++++-- setup.py | 1 + 10 files changed, 40 insertions(+), 22 deletions(-) diff --git a/app/_config.py b/app/_config.py index b8393eb..dd3ddb8 100644 --- a/app/_config.py +++ b/app/_config.py @@ -10,12 +10,11 @@ app_debug = True app_maintenance = False app_name = 'takeus-ipam' -app_version = 'V1.4' +app_version = 'V1.5' app_release_date = '04/2025' app_url = "http://0.0.0.0" -app_theme = 'default' # default, lumen, simplex, zephyr - +app_theme = ['default', 'lumen', 'simplex', 'zephyr'] class Configuration: # replace SECRET_KEY with value from "openssl rand -hex 32" or similar for STATIC sessions # With actual configuration, every application restart, user have to re-login... diff --git a/app/models.py b/app/models.py index e5675b1..234bd3a 100644 --- a/app/models.py +++ b/app/models.py @@ -7,6 +7,7 @@ class User(UserMixin, db.Model): password = db.Column(db.String(32)) is_admin = db.Column(db.Boolean(),default=False) is_reado = db.Column(db.Boolean(),default=False) + ui_theme = db.Column(db.String(16)) dat_last = db.Column(db.DateTime()) class Network(db.Model): diff --git a/app/routes/r_auth.py b/app/routes/r_auth.py index 646cd4a..de2e826 100644 --- a/app/routes/r_auth.py +++ b/app/routes/r_auth.py @@ -31,7 +31,7 @@ def login(): flash("Bad username or password !", 'danger') return render_template("auth/login.html", title="Login", form=form, bad_password=True) - return render_template('auth/login.html', title="Login", form=form, app_theme=app_theme) + return render_template('auth/login.html', title="Login", form=form) @auth.route("/change",methods=['GET','POST']) @login_required diff --git a/app/routes/r_base.py b/app/routes/r_base.py index 0722587..552d95c 100644 --- a/app/routes/r_base.py +++ b/app/routes/r_base.py @@ -28,7 +28,6 @@ def dashboard(): for available_ip in Network.query.all(): available_alloc += int(available_ip.hosts) - print(app_theme) return render_template( 'panel/dashboard.html', title="Dashboard", @@ -41,6 +40,14 @@ def dashboard(): available_alloc=available_alloc, db_users=db_users, Inventory=Inventory, - navcolor='dark', - app_theme=app_theme - ) \ No newline at end of file + navcolor='dark' + ) + +@base.route("/theme/",methods=['GET','POST']) +@login_required +def change_theme(name): + if name in app_theme: + current_user.ui_theme = name + db.session.commit() + return redirect(url_for('base.dashboard')) + return 'Invalid theme name', 400 \ No newline at end of file diff --git a/app/routes/r_inventory.py b/app/routes/r_inventory.py index a35b757..3ddde7c 100644 --- a/app/routes/r_inventory.py +++ b/app/routes/r_inventory.py @@ -4,7 +4,6 @@ from flask_login import login_required, current_user from app.extensions import * from app.models import * from app.forms import NewInventoryItem, ChangeInventoryItem -from app._config import app_theme inventory = Blueprint('inventory', __name__) @@ -21,7 +20,7 @@ def add_item(): db.session.commit() flash("Item ADDED", 'success') - return render_template('panel/inventory_add.html', title='ADD ITEM', form=form, navcolor='success', app_theme=app_theme) + return render_template('panel/inventory_add.html', title='ADD ITEM', form=form, navcolor='success') @inventory.route('/list/', methods=['GET','POST']) @login_required @@ -44,7 +43,7 @@ def list_items(item_type): else: title = 'All' - return render_template('panel/inventory_view.html', title=title, item_list=db_items, current_page=item_type, navcolor='success', app_theme=app_theme) + return render_template('panel/inventory_view.html', title=title, item_list=db_items, current_page=item_type, navcolor='success') @inventory.route('/action//', methods=['GET','POST']) @login_required diff --git a/app/routes/r_networks.py b/app/routes/r_networks.py index 60a3875..d735d5b 100644 --- a/app/routes/r_networks.py +++ b/app/routes/r_networks.py @@ -2,7 +2,7 @@ from flask import Blueprint, request, render_template, flash, redirect, url_for, from flask_login import login_required, current_user from ipaddress import IPv4Network, IPv4Address -from app._config import app_version, app_theme +from app._config import app_version from app.extensions import * from app.models import * @@ -36,7 +36,7 @@ def networks(): elif form.errors: flash(form.errors, 'danger') - return render_template('panel/networks.html', title="Prefixes", is_networks=True, app_version=app_version, app_theme=app_theme, prefixes=networks, form=form, Allocation=Allocation, navcolor='dark') + return render_template('panel/networks.html', title="Prefixes", is_networks=True, app_version=app_version, prefixes=networks, form=form, Allocation=Allocation, navcolor='dark') @network.route('//allocations',methods=['GET','POST']) @login_required @@ -60,7 +60,7 @@ def allocations(net_id): db_network = Network.query.filter_by(id=net_id).first() db_allocations = db.paginate(db.select(Allocation).filter_by(net_id=net_id), per_page=session['items'] ) - return render_template('panel/allocations.html', title="Allocations", is_networks=True, app_version=app_version, app_theme=app_theme, allocations=db_allocations, network=db_network, Inventory=Inventory, active_page=active_page, next_page=next_page, prev_page=prev_page, navcolor='dark') + return render_template('panel/allocations.html', title="Allocations", is_networks=True, app_version=app_version, allocations=db_allocations, network=db_network, Inventory=Inventory, active_page=active_page, next_page=next_page, prev_page=prev_page, navcolor='dark') ## MODAL ROUTES diff --git a/app/templates/auth/_base.html b/app/templates/auth/_base.html index 73ef36b..9ab98d7 100644 --- a/app/templates/auth/_base.html +++ b/app/templates/auth/_base.html @@ -11,11 +11,11 @@ - {% if app_theme == 'zephyr'%} + {% if current_user.ui_theme == 'zephyr'%} - {% elif app_theme == 'lumen' %} + {% elif current_user.ui_theme == 'lumen' %} - {% elif app_theme == 'simplex' %} + {% elif current_user.ui_theme == 'simplex' %} {% else %} diff --git a/app/templates/panel/_base.html b/app/templates/panel/_base.html index 0c9f96b..dde604a 100644 --- a/app/templates/panel/_base.html +++ b/app/templates/panel/_base.html @@ -11,11 +11,11 @@ - {% if app_theme == 'zephyr' %} + {% if current_user.ui_theme == 'zephyr' %} - {% elif app_theme == 'lumen' %} + {% elif current_user.ui_theme == 'lumen' %} - {% elif app_theme == 'simplex' %} + {% elif current_user.ui_theme == 'simplex' %} {% else %} diff --git a/app/templates/panel/_nav.html b/app/templates/panel/_nav.html index 6acd304..2ee8c38 100644 --- a/app/templates/panel/_nav.html +++ b/app/templates/panel/_nav.html @@ -30,8 +30,19 @@ {% endif %} -
- logout +
+
+ + +
+ logout
diff --git a/setup.py b/setup.py index e0e64b9..7143b76 100755 --- a/setup.py +++ b/setup.py @@ -14,6 +14,7 @@ class User(db.Model): password = db.Column(db.String(32)) is_admin = db.Column(db.Boolean(),default=False) is_reado = db.Column(db.Boolean(),default=False) + ui_theme = db.Column(db.String(16)) dat_last = db.Column(db.DateTime()) with app.app_context(): From a2a86db7889a772845cf478359506e406e084db7 Mon Sep 17 00:00:00 2001 From: Takeus <68923554+TakeusV1@users.noreply.github.com> Date: Tue, 17 Jun 2025 13:21:10 +0200 Subject: [PATCH 2/2] V1.5 - BLACKLIST SYSTEM - FIXES --- app/models.py | 2 ++ app/routes/r_base.py | 8 +++++--- app/routes/r_networks.py | 25 +++++++++++++++++++++++++ app/templates/panel/networks.html | 5 +++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/models.py b/app/models.py index 234bd3a..f3c7f4b 100644 --- a/app/models.py +++ b/app/models.py @@ -12,10 +12,12 @@ class User(UserMixin, db.Model): class Network(db.Model): id = db.Column(db.Integer(),primary_key=True,unique=True) + vlan_id = db.Column(db.Integer(),unique=True) prefix = db.Column(db.Integer()) network_address = db.Column(db.String(16),unique=True) hosts = db.Column(db.Integer()) description = db.Column(db.String(32)) + is_blacklisted = db.Column(db.Boolean(),default=False) class Allocation(db.Model): ipv4 = db.Column(db.String(16),primary_key=True,unique=True) diff --git a/app/routes/r_base.py b/app/routes/r_base.py index 552d95c..b958441 100644 --- a/app/routes/r_base.py +++ b/app/routes/r_base.py @@ -20,13 +20,15 @@ def home(): def dashboard(): db_networks = Network.query.count() - db_allocations = Allocation.query.filter_by(is_used=True).count() db_inventory = Inventory.query.count() db_users = User.query.count() available_alloc = 0 + db_allocations = 0 - for available_ip in Network.query.all(): - available_alloc += int(available_ip.hosts) + for network in Network.query.all(): + if network.is_blacklisted == False: + available_alloc += int(network.hosts) + db_allocations += Allocation.query.filter_by(net_id=network.id, is_used=True).count() return render_template( 'panel/dashboard.html', diff --git a/app/routes/r_networks.py b/app/routes/r_networks.py index d735d5b..21194e6 100644 --- a/app/routes/r_networks.py +++ b/app/routes/r_networks.py @@ -202,6 +202,31 @@ def network_delete(net_id): flash("Network Not Found", 'danger') return redirect(url_for('network.networks')) +@network.get('//blacklist/') +@login_required +def network_blacklist(net_id, action): + if current_user.is_reado: + return abort(403) + + db_network = Network.query.filter_by(id=net_id).first() + + if db_network == None: + flash("Network Not Found", 'danger') + return redirect(url_for('network.networks')) + + if action == 'blacklist': + db_network.is_blacklisted = True + db.session.commit() + flash("Network Blacklisted", 'warning') + + elif action == 'unblacklist': + db_network.is_blacklisted = False + db.session.commit() + flash("Network Unblacklisted", 'success') + + + return redirect(url_for('network.networks')) + ## HTMX SEARCH @network.post('//allocations/search') @login_required diff --git a/app/templates/panel/networks.html b/app/templates/panel/networks.html index ba83102..dee7207 100644 --- a/app/templates/panel/networks.html +++ b/app/templates/panel/networks.html @@ -28,6 +28,11 @@ Allocations {% if current_user.is_reado == False %} + {% if network.is_blacklisted %} + UnBlacklist + {% else %} + Blacklist + {% endif %}