mirror of
https://github.com/TakeusV1/flask_ipam.git
synced 2026-10-13 17:15:33 +02:00
V1.0
This commit is contained in:
1 parent
602bb7d706
commit
9f9f90422a
7 files changed
+71
-22
No files matched your search
+2
-2
@@ -8,11 +8,11 @@ class LoginForm(FlaskForm):
|
|||||||
|
|
||||||
class NewPrefixForm(FlaskForm):
|
class NewPrefixForm(FlaskForm):
|
||||||
subnet = StringField(validators=[DataRequired(),IPAddress(ipv4=True),Length(max=128)])
|
subnet = StringField(validators=[DataRequired(),IPAddress(ipv4=True),Length(max=128)])
|
||||||
prefix = IntegerField(validators=[DataRequired(),NumberRange(min=0,max=32)])
|
prefix = IntegerField(validators=[DataRequired(),NumberRange(min=20,max=32)])
|
||||||
description = StringField(validators=[Length(max=128)])
|
description = StringField(validators=[Length(max=128)])
|
||||||
|
|
||||||
class NewAllocationForm(FlaskForm):
|
class NewAllocationForm(FlaskForm):
|
||||||
ipv4 = StringField(validators=[DataRequired(),IPAddress(ipv4=True),Length(max=128)])
|
ipv4 = StringField(validators=[DataRequired(),IPAddress(ipv4=True),Length(max=128)])
|
||||||
host_name = StringField(validators=[DataRequired(),Length(max=128)])
|
host_name = StringField(validators=[Length(max=128)])
|
||||||
host_desc = StringField(validators=[Length(max=128)])
|
host_desc = StringField(validators=[Length(max=128)])
|
||||||
#host_type = SelectField(choices=[(0,'None'),(1,'Computer'),(2,'Server'),(3,'Virtual Machine'),(4,'Network Device'),(5,'Other')],validators=[DataRequired()])
|
#host_type = SelectField(choices=[(0,'None'),(1,'Computer'),(2,'Server'),(3,'Virtual Machine'),(4,'Network Device'),(5,'Other')],validators=[DataRequired()])
|
||||||
+1
-1
@@ -18,7 +18,7 @@ class Network(db.Model):
|
|||||||
class Allocation(db.Model):
|
class Allocation(db.Model):
|
||||||
ipv4 = db.Column(db.String(16),primary_key=True,unique=True)
|
ipv4 = db.Column(db.String(16),primary_key=True,unique=True)
|
||||||
net_id = db.Column(db.Integer(),db.ForeignKey('network.id'))
|
net_id = db.Column(db.Integer(),db.ForeignKey('network.id'))
|
||||||
hostname = db.Column(db.String(32),unique=True)
|
hostname = db.Column(db.String(32))
|
||||||
description = db.Column(db.String(64))
|
description = db.Column(db.String(64))
|
||||||
device_id = db.Column(db.Integer(),db.ForeignKey('inventory.id'))
|
device_id = db.Column(db.Integer(),db.ForeignKey('inventory.id'))
|
||||||
|
|
||||||
|
|||||||
+14
-15
@@ -45,14 +45,15 @@ def networks():
|
|||||||
elif form.errors:
|
elif form.errors:
|
||||||
flash(form.errors, 'danger')
|
flash(form.errors, 'danger')
|
||||||
|
|
||||||
return render_template('panel/networks.html', title="Prefixes", is_networks=True, app_version=app_version, prefixes=networks, form=form)
|
return render_template('panel/networks.html', title="Prefixes", is_networks=True, app_version=app_version, prefixes=networks, form=form, Allocation=Allocation)
|
||||||
|
|
||||||
@base.route('/network/<int:net_id>/allocations',methods=['GET','POST'])
|
@base.route('/network/<int:net_id>/allocations',methods=['GET','POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def allocations(net_id):
|
def allocations(net_id):
|
||||||
|
|
||||||
db_allocations = Allocation.query.filter_by(net_id=net_id).all()
|
active_page = request.args.get('page', type=int)
|
||||||
db_network = Network.query.filter_by(id=net_id).first()
|
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=15 )
|
||||||
|
|
||||||
form = NewAllocationForm()
|
form = NewAllocationForm()
|
||||||
if request.method == 'POST' and form.validate_on_submit():
|
if request.method == 'POST' and form.validate_on_submit():
|
||||||
@@ -60,24 +61,22 @@ def allocations(net_id):
|
|||||||
# Check if IPv4 Address is already allocated
|
# Check if IPv4 Address is already allocated
|
||||||
if Allocation.query.filter_by(ipv4=str(form.ipv4.data)).first() != None:
|
if Allocation.query.filter_by(ipv4=str(form.ipv4.data)).first() != None:
|
||||||
flash("IPv4 Address Already Allocated", 'danger')
|
flash("IPv4 Address Already Allocated", 'danger')
|
||||||
return redirect(url_for('base.allocations',net_id=net_id))
|
return redirect(url_for('base.allocations', net_id=net_id, page=active_page))
|
||||||
# Check if IPv4 Address is in the Network
|
# Check if IPv4 Address is in the Network
|
||||||
if IPv4Address(form.ipv4.data) in network.hosts():
|
if IPv4Address(form.ipv4.data) in network.hosts():
|
||||||
add_alloc = Allocation(ipv4=str(form.ipv4.data), net_id=db_network.id, hostname=str(form.host_name.data), description=str(form.host_desc.data))
|
add_alloc = Allocation(ipv4=str(form.ipv4.data), net_id=db_network.id, hostname=str(form.host_name.data), description=str(form.host_desc.data))
|
||||||
# Add Inventory if Host Type is not None
|
|
||||||
##if int(form.host_type.data) != 0:
|
|
||||||
## add_inv = Inventory(ip_addr=str(form.ipv4.data)+',',host_type=form.host_type.data,host_name=form.host_name.data,host_desc=form.host_desc.data)
|
|
||||||
## db.session.add(add_inv)
|
|
||||||
##
|
|
||||||
## mod_alloc = Allocation.query.filter_by(ipv4=str(form.ipv4.data)).first()
|
|
||||||
## mod_alloc.device_id = add_inv.id
|
|
||||||
db.session.add(add_alloc)
|
db.session.add(add_alloc)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(url_for('base.allocations',net_id=net_id))
|
flash("Allocation Added", 'success')
|
||||||
|
return redirect(url_for('base.allocations', net_id=net_id, page=active_page))
|
||||||
|
# If not in Network
|
||||||
flash("Invalid IPv4 Address", 'danger')
|
flash("Invalid IPv4 Address", 'danger')
|
||||||
return redirect(url_for('base.allocations',net_id=net_id))
|
return redirect(url_for('base.allocations', net_id=net_id, page=active_page))
|
||||||
|
# If Form Errors
|
||||||
|
elif form.errors:
|
||||||
|
flash(form.errors, 'danger')
|
||||||
|
|
||||||
return render_template('panel/allocations.html', title="Allocations", is_networks=True, app_version=app_version, form=form, allocations=db_allocations, network=db_network, Inventory=Inventory)
|
return render_template('panel/allocations.html', title="Allocations", is_networks=True, app_version=app_version, form=form, allocations=db_allocations, network=db_network, Inventory=Inventory, active_page=active_page)
|
||||||
|
|
||||||
## MODAL ROUTES
|
## MODAL ROUTES
|
||||||
|
|
||||||
@@ -92,7 +91,7 @@ def allocation_del_modal(net_id,ipv4):
|
|||||||
'action_text': 'Delete',
|
'action_text': 'Delete',
|
||||||
'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)
|
return render_template('panel/_modal.html', modal=modal, net_id=net_id, ipv4=ipv4, old_page=request.args.get('page', type=int))
|
||||||
|
|
||||||
@base.get('/network/<int:net_id>/del_modal')
|
@base.get('/network/<int:net_id>/del_modal')
|
||||||
@login_required
|
@login_required
|
||||||
@@ -117,7 +116,7 @@ def allocation_delete(net_id,ipv4):
|
|||||||
db.session.delete(db_alloc)
|
db.session.delete(db_alloc)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("Allocation Deleted", 'warning')
|
flash("Allocation Deleted", 'warning')
|
||||||
return redirect(url_for('base.allocations',net_id=net_id))
|
return redirect(url_for('base.allocations',net_id=net_id,page=request.args.get('page', type=int)))
|
||||||
|
|
||||||
@base.get('/network/<int:net_id>/delete')
|
@base.get('/network/<int:net_id>/delete')
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
{% if modal.action == 'delete' %}
|
{% if modal.action == 'delete' %}
|
||||||
<a href="{{modal.action_url}}" class="btn btn-{{modal.color}}">{{modal.action_text}}</a>
|
<a href="{{modal.action_url}}?page={{old_page}}" class="btn btn-{{modal.color}}">{{modal.action_text}}</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<button type="button" class="btn btn-primary">Save changes</button>
|
<button type="button" class="btn btn-primary">Save changes</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<a href="" class="btn btn-sm btn-outline-info" style="padding-top:1px;padding-bottom:1px">edit</a>
|
<a href="" class="btn btn-sm btn-outline-info" style="padding-top:1px;padding-bottom:1px">edit</a>
|
||||||
<button
|
<button
|
||||||
hx-get="{{ url_for('base.allocation_del_modal',net_id=network.id,ipv4=allocation.ipv4) }}"
|
hx-get="{{ url_for('base.allocation_del_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
hx-target="#modal-get"
|
hx-target="#modal-get"
|
||||||
data-bs-toggle="modal"
|
data-bs-toggle="modal"
|
||||||
@@ -73,6 +73,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<nav class="d-flex flex-row justify-content-center align-items-center">
|
||||||
|
<ul class="pagination">
|
||||||
|
{% for page in allocations.iter_pages() %}
|
||||||
|
<li class="page-item"><a class="page-link" href="?page={{page}}">{{page}}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
<!-- MODAL -->
|
<!-- MODAL -->
|
||||||
<div id="modal-get"
|
<div id="modal-get"
|
||||||
class="modal modal-blur fade"
|
class="modal modal-blur fade"
|
||||||
|
|||||||
@@ -1,5 +1,48 @@
|
|||||||
{% extends 'panel/_base.html' %}
|
{% extends 'panel/_base.html' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% include 'panel/_nav.html' %}
|
{% include 'panel/_nav.html' %}
|
||||||
|
<div class="container" style="margin-top:5vh;">
|
||||||
|
<div class="row">
|
||||||
|
<!-- NETWORKS -->
|
||||||
|
<div class="col-3">
|
||||||
|
<div class="card text-bg-info mb-3">
|
||||||
|
<div class="card-header"><i class="bi bi-globe"></i> Total Networks</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Primary card title</h5>
|
||||||
|
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- TOTAL IP -->
|
||||||
|
<div class="col-3">
|
||||||
|
<div class="card text-bg-primary mb-3">
|
||||||
|
<div class="card-header"><i class="bi bi-broadcast-pin"></i> Total Allocations</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Primary card title</h5>
|
||||||
|
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- TOTAL Inventory -->
|
||||||
|
<div class="col-3">
|
||||||
|
<div class="card text-bg-secondary mb-3">
|
||||||
|
<div class="card-header"><i class="bi bi-archive"></i> Total Inventory</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Primary card title</h5>
|
||||||
|
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- Total Users -->
|
||||||
|
<div class="col-3">
|
||||||
|
<div class="card text-bg-secondary mb-3">
|
||||||
|
<div class="card-header"><i class="bi bi-people"></i> Total Users</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Primary card title</h5>
|
||||||
|
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
<th scope="row">{{network.id}}</th>
|
<th scope="row">{{network.id}}</th>
|
||||||
<td>{{network.network_address}}</td>
|
<td>{{network.network_address}}</td>
|
||||||
<td>{{network.prefix}}</td>
|
<td>{{network.prefix}}</td>
|
||||||
<td>X / {{network.hosts}} </td>
|
<td>{{Allocation.query.filter_by(net_id=network.id).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) }}" class="btn btn-sm btn-outline-info" style="padding-top:1px;padding-bottom:1px">Allocations</a>
|
||||||
|
|||||||
Reference in new issue
Block a user