This commit is contained in:
Takeus committed 2025-02-04 23:13:32 +01:00
1 parent 602bb7d706
commit 9f9f90422a
7 files changed
+74 -25

No files matched your search

+17 -18
View File
@@ -44,15 +44,16 @@ def networks():
return redirect(url_for('base.networks'))
elif form.errors:
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'])
@login_required
def allocations(net_id):
db_allocations = Allocation.query.filter_by(net_id=net_id).all()
db_network = Network.query.filter_by(id=net_id).first()
active_page = request.args.get('page', type=int)
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()
if request.method == 'POST' and form.validate_on_submit():
@@ -60,24 +61,22 @@ def allocations(net_id):
# Check if IPv4 Address is already allocated
if Allocation.query.filter_by(ipv4=str(form.ipv4.data)).first() != None:
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
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 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
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))
db.session.add(add_alloc)
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')
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
@@ -92,7 +91,7 @@ def allocation_del_modal(net_id,ipv4):
'action_text': 'Delete',
'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')
@login_required
@@ -117,7 +116,7 @@ def allocation_delete(net_id,ipv4):
db.session.delete(db_alloc)
db.session.commit()
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')
@login_required