mirror of
https://github.com/TakeusV1/flask_ipam.git
synced 2026-10-13 17:15:33 +02:00
V1.1
This commit is contained in:
1 parent
e5fbf15828
commit
4628df54e1
8 files changed
+163
-16
No files matched your search
+1
-1
@@ -8,7 +8,7 @@ app_debug = True
|
|||||||
app_maintenance = False
|
app_maintenance = False
|
||||||
|
|
||||||
app_name = 'takeus-ipam'
|
app_name = 'takeus-ipam'
|
||||||
app_version = 'V1.0'
|
app_version = 'V1.1'
|
||||||
app_release_date = '02/2025'
|
app_release_date = '02/2025'
|
||||||
app_url = "http://127.0.0.1"
|
app_url = "http://127.0.0.1"
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -28,4 +28,5 @@ class ChangePasswordForm(FlaskForm):
|
|||||||
|
|
||||||
class ChangeAllocationForm(FlaskForm):
|
class ChangeAllocationForm(FlaskForm):
|
||||||
hostname = StringField(validators=[Length(max=128)])
|
hostname = StringField(validators=[Length(max=128)])
|
||||||
description = StringField(validators=[Length(max=128)])
|
description = StringField(validators=[Length(max=128)])
|
||||||
|
is_special = SelectField(choices=[(0,'None'),(1,'DHCP'),(2,'Gateway')],validators=[DataRequired()],label='Special USE ?')
|
||||||
@@ -21,6 +21,8 @@ class Allocation(db.Model):
|
|||||||
hostname = db.Column(db.String(32))
|
hostname = db.Column(db.String(32))
|
||||||
description = db.Column(db.String(64))
|
description = db.Column(db.String(64))
|
||||||
is_used = db.Column(db.Boolean(),default=False)
|
is_used = db.Column(db.Boolean(),default=False)
|
||||||
|
is_dhcp = db.Column(db.Boolean(),default=False)
|
||||||
|
is_gateway = db.Column(db.Boolean(),default=False)
|
||||||
device_id = db.Column(db.Integer(),db.ForeignKey('inventory.id'))
|
device_id = db.Column(db.Integer(),db.ForeignKey('inventory.id'))
|
||||||
|
|
||||||
class Inventory(db.Model):
|
class Inventory(db.Model):
|
||||||
|
|||||||
+74
-6
@@ -129,11 +129,11 @@ def network_del_modal(net_id):
|
|||||||
@login_required
|
@login_required
|
||||||
def allocation_del_modal(net_id,ipv4):
|
def allocation_del_modal(net_id,ipv4):
|
||||||
modal = {
|
modal = {
|
||||||
'title': 'Delete Allocation',
|
'title': 'Remove Allocation',
|
||||||
'body': f'Are you sure you want to delete <b>{ipv4}</b> allocation ?',
|
'body': f'Are you sure you want to remove <b>{ipv4}</b> allocation ?',
|
||||||
'color': 'warning',
|
'color': 'warning',
|
||||||
'action': 'delete',
|
'action': 'delete',
|
||||||
'action_text': 'Delete',
|
'action_text': 'Remove',
|
||||||
'action_url': url_for('base.allocation_delete',net_id=net_id,ipv4=ipv4)
|
'action_url': url_for('base.allocation_delete',net_id=net_id,ipv4=ipv4)
|
||||||
}
|
}
|
||||||
return render_template('panel/_modal.html', modal=modal, net_id=net_id, ipv4=ipv4, old_page=request.args.get('page', type=int), pagination_active=True)
|
return render_template('panel/_modal.html', modal=modal, net_id=net_id, ipv4=ipv4, old_page=request.args.get('page', type=int), pagination_active=True)
|
||||||
@@ -148,6 +148,23 @@ def allocation_edit_modal(net_id, ipv4):
|
|||||||
if form.validate_on_submit() and request.method == 'POST':
|
if form.validate_on_submit() and request.method == 'POST':
|
||||||
db_alloc.hostname = str(form.hostname.data)
|
db_alloc.hostname = str(form.hostname.data)
|
||||||
db_alloc.description = str(form.description.data)
|
db_alloc.description = str(form.description.data)
|
||||||
|
db_alloc.is_used = True
|
||||||
|
# Special Allocation
|
||||||
|
if int(form.is_special.data) == 1:
|
||||||
|
# DHCP
|
||||||
|
db_alloc.is_dhcp == True
|
||||||
|
db_alloc.is_gateway == False
|
||||||
|
db_alloc.hostname = None
|
||||||
|
db_alloc.description = "DHCP Allocation"
|
||||||
|
elif int(form.is_special.data) == 2:
|
||||||
|
# Gateway
|
||||||
|
db_alloc.is_dhcp == False
|
||||||
|
db_alloc.is_gateway == True
|
||||||
|
else:
|
||||||
|
# None
|
||||||
|
db_alloc.is_dhcp == False
|
||||||
|
db_alloc.is_gateway == False
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("Allocation Updated", 'success')
|
flash("Allocation Updated", 'success')
|
||||||
return redirect(url_for('base.allocations',net_id=net_id,page=request.args.get('page', type=int)))
|
return redirect(url_for('base.allocations',net_id=net_id,page=request.args.get('page', type=int)))
|
||||||
@@ -163,12 +180,13 @@ def allocation_edit_modal(net_id, ipv4):
|
|||||||
return render_template('panel/_modal.html', modal=modal, form=form, old_page=request.args.get('page', type=int), pagination_active=True)
|
return render_template('panel/_modal.html', modal=modal, form=form, old_page=request.args.get('page', type=int), pagination_active=True)
|
||||||
|
|
||||||
## MODIFICATION ROUTES
|
## MODIFICATION ROUTES
|
||||||
|
@base.get('/network/<int:net_id>/allocations/<string:ipv4>/unallocate')
|
||||||
@base.get('/network/<int:net_id>/allocations/<string:ipv4>/delete')
|
|
||||||
@login_required
|
@login_required
|
||||||
def allocation_delete(net_id,ipv4):
|
def allocation_delete(net_id,ipv4):
|
||||||
db_alloc = Allocation.query.filter_by(net_id=net_id,ipv4=ipv4).first()
|
db_alloc = Allocation.query.filter_by(net_id=net_id,ipv4=ipv4).first()
|
||||||
db.session.delete(db_alloc)
|
db_alloc.is_used = False
|
||||||
|
db_alloc.hostname = None
|
||||||
|
db_alloc.description = None
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("Allocation Deleted", 'warning')
|
flash("Allocation Deleted", 'warning')
|
||||||
return redirect(url_for('base.allocations',net_id=net_id,page=request.args.get('page', type=int)))
|
return redirect(url_for('base.allocations',net_id=net_id,page=request.args.get('page', type=int)))
|
||||||
@@ -190,3 +208,53 @@ def network_delete(net_id):
|
|||||||
else:
|
else:
|
||||||
flash("Network Not Found", 'danger')
|
flash("Network Not Found", 'danger')
|
||||||
return redirect(url_for('base.networks'))
|
return redirect(url_for('base.networks'))
|
||||||
|
|
||||||
|
## HTMX SEARCH
|
||||||
|
@base.post('/network/<int:net_id>/allocations/search')
|
||||||
|
@login_required
|
||||||
|
def allocation_search(net_id):
|
||||||
|
search = str(request.form['search']).lower()
|
||||||
|
|
||||||
|
db_network = Network.query.filter_by(id=net_id).first()
|
||||||
|
db_alloc = Allocation.query.filter_by(net_id=net_id).all()
|
||||||
|
obj_list = []
|
||||||
|
|
||||||
|
# Advance Search
|
||||||
|
if '*' in search:
|
||||||
|
search = search.split("*")[1]
|
||||||
|
# AND
|
||||||
|
if ',' in search:
|
||||||
|
for alloc in db_alloc:
|
||||||
|
print(search.split(','))
|
||||||
|
if alloc.ipv4.lower() in search.split(','):
|
||||||
|
obj_list.append(alloc)
|
||||||
|
# BETWEEN
|
||||||
|
if '-' in search:
|
||||||
|
search = search.split('-')
|
||||||
|
if search[0].split('.')[-1] == '' or search[1].split('.')[-1] == '':
|
||||||
|
return "Invalid(s) Number(s)"
|
||||||
|
temp_1 = int(search[0].split('.')[-1])
|
||||||
|
temp_2 = int(search[1].split('.')[-1])
|
||||||
|
|
||||||
|
for alloc in db_alloc:
|
||||||
|
if int(alloc.ipv4.split('.')[-1]) <= temp_2 and int(alloc.ipv4.split('.')[-1]) >= temp_1:
|
||||||
|
obj_list.append(alloc)
|
||||||
|
# DHCP
|
||||||
|
print(search)
|
||||||
|
if 'dhcp' in search:
|
||||||
|
for alloc in db_alloc:
|
||||||
|
if alloc.is_dhcp:
|
||||||
|
obj_list.append(alloc)
|
||||||
|
else:
|
||||||
|
# BASIC SEARCH
|
||||||
|
for alloc in db_alloc:
|
||||||
|
if alloc.ipv4.lower().startswith(search):
|
||||||
|
obj_list.append(alloc)
|
||||||
|
elif alloc.hostname != None:
|
||||||
|
if alloc.hostname.lower().startswith(search):
|
||||||
|
obj_list.append(alloc)
|
||||||
|
elif alloc.description != None:
|
||||||
|
if alloc.description.lower().startswith(search):
|
||||||
|
obj_list.append(alloc)
|
||||||
|
|
||||||
|
return render_template('panel/_search-entry.html',db_alloc=obj_list,Inventory=Inventory,network=db_network)
|
||||||
@@ -9,11 +9,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<p>
|
<p>
|
||||||
{{ modal.body|safe }}<br><br>
|
{{ modal.body|safe }}<hr>
|
||||||
{% for entry in form %}
|
{% for entry in form %}
|
||||||
{% if entry.id != 'csrf_token' %}
|
{% if entry.id != 'csrf_token' %}
|
||||||
|
<div class="mb-3">
|
||||||
{{ entry.label(class="form-label") }}<br>
|
{{ entry.label(class="form-label") }}<br>
|
||||||
{{ entry(class="form-control") }}
|
{{ entry(class="form-control") }}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
{% for allocation in db_alloc %}
|
||||||
|
<tr>
|
||||||
|
<td><b>{{allocation.ipv4}}</b></td>
|
||||||
|
<td>{{allocation.hostname}}</td>
|
||||||
|
<td>{{allocation.description}}</td>
|
||||||
|
<td>
|
||||||
|
{% if Inventory.query.filter_by(id=allocation.device_id).first() %}
|
||||||
|
<a href="{{Inventory.query.filter_by(id=allocation.device_id).first().id}}" style="text-decoration:none;">link</a>
|
||||||
|
{% else %}
|
||||||
|
N/A
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if allocation.is_used %}
|
||||||
|
<button
|
||||||
|
hx-get="{{ url_for('base.allocation_edit_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}"
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#modal-edit"
|
||||||
|
data-bs-toggle="modal"
|
||||||
|
data-bs-target="#modal-edit"
|
||||||
|
class="btn btn-sm btn-outline-info"
|
||||||
|
style="padding-top:1px;padding-bottom:1px"
|
||||||
|
> Edit
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
hx-get="{{ url_for('base.allocation_del_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}"
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#modal-del"
|
||||||
|
data-bs-toggle="modal"
|
||||||
|
data-bs-target="#modal-del"
|
||||||
|
class="btn btn-sm btn-outline-warning"
|
||||||
|
style="padding-top:1px;padding-bottom:1px"
|
||||||
|
> Unallocate
|
||||||
|
</button>
|
||||||
|
{% else %}
|
||||||
|
<button
|
||||||
|
hx-get="{{ url_for('base.allocation_edit_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}"
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#modal-edit"
|
||||||
|
data-bs-toggle="modal"
|
||||||
|
data-bs-target="#modal-edit"
|
||||||
|
class="btn btn-sm btn-outline-success"
|
||||||
|
style="padding-top:1px;padding-bottom:1px"
|
||||||
|
> Allocate
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
@@ -4,8 +4,20 @@
|
|||||||
{% include 'panel/_flash.html' %}
|
{% include 'panel/_flash.html' %}
|
||||||
<div class="container" style="margin-top:5vh;">
|
<div class="container" style="margin-top:5vh;">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<!-- Search BAR -->
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="mb-3">
|
||||||
|
<input class="form-control" type="search"
|
||||||
|
name="search" placeholder="Begin Typing To Search Users..."
|
||||||
|
hx-post="{{ url_for('base.allocation_search',net_id=network.id) }}"
|
||||||
|
hx-trigger="input changed delay:500ms, keyup[key=='Enter']"
|
||||||
|
hx-target="#search-results"
|
||||||
|
hx-indicator=".htmx-indicator"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<!-- IPV4 TABLE -->
|
<!-- IPV4 TABLE -->
|
||||||
<div class="col-9">
|
<div class="col-12">
|
||||||
<table class="table table-striped table-hover table-sm">
|
<table class="table table-striped table-hover table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -16,7 +28,7 @@
|
|||||||
<th scope="col">Actions</th>
|
<th scope="col">Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody id="search-results">
|
||||||
{% for allocation in allocations %}
|
{% for allocation in allocations %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>{{allocation.ipv4}}</b></td>
|
<td><b>{{allocation.ipv4}}</b></td>
|
||||||
@@ -30,6 +42,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
{% if allocation.is_used %}
|
||||||
<button
|
<button
|
||||||
hx-get="{{ url_for('base.allocation_edit_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}"
|
hx-get="{{ url_for('base.allocation_edit_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
@@ -46,17 +59,29 @@
|
|||||||
hx-target="#modal-del"
|
hx-target="#modal-del"
|
||||||
data-bs-toggle="modal"
|
data-bs-toggle="modal"
|
||||||
data-bs-target="#modal-del"
|
data-bs-target="#modal-del"
|
||||||
class="btn btn-sm btn-outline-danger"
|
class="btn btn-sm btn-outline-warning"
|
||||||
style="padding-top:1px;padding-bottom:1px"
|
style="padding-top:1px;padding-bottom:1px"
|
||||||
> Delete
|
> Unallocate
|
||||||
</button>
|
</button>
|
||||||
|
{% else %}
|
||||||
|
<button
|
||||||
|
hx-get="{{ url_for('base.allocation_edit_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}"
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#modal-edit"
|
||||||
|
data-bs-toggle="modal"
|
||||||
|
data-bs-target="#modal-edit"
|
||||||
|
class="btn btn-sm btn-outline-success"
|
||||||
|
style="padding-top:1px;padding-bottom:1px"
|
||||||
|
> Allocate
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<!-- IPV4 FORM -->
|
<!-- IPV4 FORM
|
||||||
<div class="col-3">
|
<div class="col-3">
|
||||||
<div class="card p-4 shadow rounded-3">
|
<div class="card p-4 shadow rounded-3">
|
||||||
<h2 class="text-center mb-4">Add IPv4</h2>
|
<h2 class="text-center mb-4">Add IPv4</h2>
|
||||||
@@ -77,7 +102,7 @@
|
|||||||
<button type="submit" class="btn btn-secondary w-100">Submit</button>
|
<button type="submit" class="btn btn-secondary w-100">Submit</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> -->
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<nav>
|
<nav>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
<td>{{Allocation.query.filter_by(net_id=network.id,is_used=True).count()}} / {{network.hosts}} </td>
|
<td>{{Allocation.query.filter_by(net_id=network.id,is_used=True).count()}} / {{network.hosts}} </td>
|
||||||
<td><b>{{network.description}}</b></td>
|
<td><b>{{network.description}}</b></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ url_for('base.allocations',net_id=network.id) }}" class="btn btn-sm btn-outline-info" style="padding-top:1px;padding-bottom:1px">Allocations</a>
|
<a href="{{ url_for('base.allocations',net_id=network.id) }}?page=1" class="btn btn-sm btn-outline-info" style="padding-top:1px;padding-bottom:1px">Allocations</a>
|
||||||
<button
|
<button
|
||||||
hx-get="{{ url_for('base.network_del_modal',net_id=network.id) }}"
|
hx-get="{{ url_for('base.network_del_modal',net_id=network.id) }}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
|
|||||||
Reference in new issue
Block a user