mirror of
https://github.com/TakeusV1/flask_ipam.git
synced 2026-10-13 17:15:33 +02:00
V1.5
- BLACKLIST SYSTEM - FIXES
This commit is contained in:
1 parent
1f32755ade
commit
a2a86db788
4 files changed
+37
-3
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -202,6 +202,31 @@ def network_delete(net_id):
|
||||
flash("Network Not Found", 'danger')
|
||||
return redirect(url_for('network.networks'))
|
||||
|
||||
@network.get('/<int:net_id>/blacklist/<action>')
|
||||
@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('/<int:net_id>/allocations/search')
|
||||
@login_required
|
||||
|
||||
@@ -28,6 +28,11 @@
|
||||
<td>
|
||||
<a href="{{ url_for('network.allocations',net_id=network.id) }}?page=1" class="btn btn-sm btn-outline-info" style="padding-top:1px;padding-bottom:1px">Allocations</a>
|
||||
{% if current_user.is_reado == False %}
|
||||
{% if network.is_blacklisted %}
|
||||
<a href="{{ url_for('network.network_blacklist',net_id=network.id,action='unblacklist') }}" class="btn btn-sm btn-outline-warning" style="padding-top:1px;padding-bottom:1px">UnBlacklist</a>
|
||||
{% else %}
|
||||
<a href="{{ url_for('network.network_blacklist',net_id=network.id,action='blacklist') }}" class="btn btn-sm btn-outline-warning" style="padding-top:1px;padding-bottom:1px">Blacklist</a>
|
||||
{% endif %}
|
||||
<button
|
||||
hx-get="{{ url_for('network.network_del_modal',net_id=network.id) }}"
|
||||
hx-trigger="click"
|
||||
|
||||
Reference in new issue
Block a user