From eefc23fad8ff476074f4358ae84fc14deae7d9d6 Mon Sep 17 00:00:00 2001 From: Takeus <68923554+TakeusV1@users.noreply.github.com> Date: Mon, 17 Feb 2025 16:20:21 +0100 Subject: [PATCH] DEV V1.2 --- app/__init__.py | 4 + app/_config.py | 2 +- app/forms.py | 13 +- app/models.py | 17 +- app/routes/r_base.py | 268 +----------------------- app/routes/r_inventory.py | 42 ++++ app/routes/r_networks.py | 247 ++++++++++++++++++++++ app/templates/panel/_nav.html | 15 +- app/templates/panel/_table-alloc.html | 10 +- app/templates/panel/allocations.html | 30 +-- app/templates/panel/dashboard.html | 11 +- app/templates/panel/inventory_add.html | 32 +++ app/templates/panel/inventory_view.html | 37 ++++ app/templates/panel/networks.html | 4 +- 14 files changed, 406 insertions(+), 326 deletions(-) create mode 100644 app/routes/r_inventory.py create mode 100644 app/routes/r_networks.py create mode 100644 app/templates/panel/inventory_add.html create mode 100644 app/templates/panel/inventory_view.html diff --git a/app/__init__.py b/app/__init__.py index 2f6494c..1bdfd1d 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -10,6 +10,8 @@ from app.models import * from app.extensions import * from app.routes.r_base import base +from app.routes.r_networks import network +from app.routes.r_inventory import inventory from app.routes.r_auth import auth from app.routes.r_adm import admin @@ -30,6 +32,8 @@ def create_app(): ## BLUEPRINTS app.register_blueprint(base, url_prefix='/') + app.register_blueprint(network, url_prefix='/network') + app.register_blueprint(inventory, url_prefix='/inventory') app.register_blueprint(auth, url_prefix='/auth') app.register_blueprint(admin, url_prefix='/admin') diff --git a/app/_config.py b/app/_config.py index 6052792..23d5935 100644 --- a/app/_config.py +++ b/app/_config.py @@ -8,7 +8,7 @@ app_debug = True app_maintenance = False app_name = 'takeus-ipam' -app_version = 'V1.1' +app_version = 'V1.2' app_release_date = '02/2025' app_url = "http://127.0.0.1" diff --git a/app/forms.py b/app/forms.py index 36dcce2..6534572 100644 --- a/app/forms.py +++ b/app/forms.py @@ -11,13 +11,7 @@ class NewPrefixForm(FlaskForm): prefix = SelectField(choices=[(30,'/30'),(29,'/29'),(28,'/28'),(27,'/27'),(26,'/26'),(25,'/25'),(24,'/24'),(23,'/23'),(22,'/22')],validators=[DataRequired()]) description = StringField(validators=[Length(max=128)]) -class NewAllocationForm(FlaskForm): - ipv4 = StringField(validators=[DataRequired(),IPAddress(ipv4=True),Length(max=128)]) - host_name = 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()]) - -class NewUserForm (FlaskForm): +class NewUserForm(FlaskForm): username = StringField(validators=[DataRequired(),Length(max=128)]) password = PasswordField(validators=[DataRequired(),Length(max=128)]) is_admin = SelectField(choices=[(0,'No'),(1,'Yes')],validators=[DataRequired()]) @@ -30,3 +24,8 @@ class ChangeAllocationForm(FlaskForm): hostname = 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 ?') + +class NewInventoryItem(FlaskForm): + item_name = StringField(validators=[DataRequired(),Length(max=128)]) + item_desc = PasswordField(validators=[Length(max=128)]) + item_type = SelectField(choices=[(1,'Computer'),(2,'Server'),(3,'Virtual Machine'), (4,'Network Device'), (0,'Other')],validators=[DataRequired()]) \ No newline at end of file diff --git a/app/models.py b/app/models.py index f7842f4..8366b87 100644 --- a/app/models.py +++ b/app/models.py @@ -28,17 +28,16 @@ class Allocation(db.Model): class Inventory(db.Model): id = db.Column(db.Integer(),primary_key=True,unique=True) - ip_addr = db.Column(db.Text()) # Host Information host_type = db.Column(db.Integer()) - host_name = db.Column(db.String(32)) + host_name = db.Column(db.String(64)) host_desc = db.Column(db.String(64)) # Hardware Information - host_model = db.Column(db.String(32)) - host_manufacturer = db.Column(db.String(32)) - host_serialnumber = db.Column(db.String(32)) + host_model = db.Column(db.String(64)) + host_manufacturer = db.Column(db.String(64)) + host_serialnumber = db.Column(db.String(64)) # Network Information - host_os = db.Column(db.String(32)) - host_location = db.Column(db.String(32)) - host_owner = db.Column(db.String(32)) - host_contact = db.Column(db.String(32)) \ No newline at end of file + host_os = db.Column(db.String(64)) + host_location = db.Column(db.String(64)) + host_owner = db.Column(db.String(64)) + host_contact = db.Column(db.String(64)) \ No newline at end of file diff --git a/app/routes/r_base.py b/app/routes/r_base.py index cef2f08..ee157b3 100644 --- a/app/routes/r_base.py +++ b/app/routes/r_base.py @@ -1,24 +1,21 @@ -from datetime import datetime -from flask import Blueprint, request, render_template, flash, redirect, url_for, session +from flask import Blueprint, render_template, redirect, url_for from flask_login import login_required, current_user -from ipaddress import IPv4Network, IPv4Address from app._config import app_version from app.extensions import * from app.models import * -from app.forms import NewPrefixForm, NewAllocationForm, ChangeAllocationForm base = Blueprint('base', __name__) -@base.route('/',methods=['GET','POST']) +@base.route('/') def home(): if current_user.is_authenticated: return redirect(url_for('base.dashboard')) else: return redirect(url_for('auth.login')) -@base.route('/dashboard',methods=['GET','POST']) +@base.route('/dashboard') @login_required def dashboard(): @@ -42,261 +39,6 @@ def dashboard(): db_inventory=db_inventory, available_alloc=available_alloc, db_users=db_users, + Inventory=Inventory, navcolor='dark' - ) - -@base.route('/network',methods=['GET','POST']) -@login_required -def networks(): - networks = Network.query.all() - form = NewPrefixForm() - if request.method == 'POST' and form.validate_on_submit(): - try: - network = IPv4Network(f"{str(form.subnet.data)}/{str(form.prefix.data)}", False) - - add_net = Network(network_address=str(network.network_address),prefix=network.prefixlen,hosts=network.num_addresses-2,description=str(form.description.data)) - db.session.add(add_net) - db.session.commit() - - for ip in network.hosts(): - db.session.add(Allocation(ipv4=str(ip), net_id=add_net.id)) - - db.session.commit() - return redirect(url_for('base.networks')) - - except: - flash("Invalid Subnet or Prefix", 'danger') - 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, Allocation=Allocation, navcolor='dark') - -@base.route('/network//allocations',methods=['GET','POST']) -@login_required -def allocations(net_id): - - active_page = request.args.get('page', type=int) - if active_page == None: - active_page = 1 - - next_page = active_page+1 - prev_page = active_page-1 - - if request.args.get('items', type=int) != None: - session['items'] = request.args.get('items', type=int) - try: - if session['items'] == None: - session['items'] = 15 - except: - session['items'] = 15 - - 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'] ) - - form = NewAllocationForm() - ##if request.method == 'POST' and form.validate_on_submit(): - ## network = IPv4Network(f"{str(db_network.network_address)}/{str(db_network.prefix)}") - # 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, 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)) - ## db.session.add(add_alloc) - ## db.session.commit() - ## 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, 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, active_page=active_page, next_page=next_page, prev_page=prev_page, navcolor='dark') - -## MODAL ROUTES - -@base.get('/network//del_modal') -@login_required -def network_del_modal(net_id): - db_network = Network.query.filter_by(id=net_id).first() - modal = { - 'title': 'Delete Network', - 'body': f'Are you sure you want to delete {db_network.network_address}/{db_network.prefix} network ?', - 'color': 'danger', - 'action': 'delete', - 'action_text': 'Delete', - 'action_url': url_for('base.network_delete',net_id=net_id) - } - return render_template('panel/_modal.html', modal=modal, net_id=net_id) - -@base.get('/network//allocations//del_modal') -@login_required -def allocation_del_modal(net_id,ipv4): - modal = { - 'title': 'Remove Allocation', - 'body': f'Are you sure you want to remove {ipv4} allocation ?', - 'color': 'warning', - 'action': 'delete', - 'action_text': 'Remove', - '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) - - -@base.route('/network//allocations//edit_modal', methods=['GET','POST']) -@login_required -def allocation_edit_modal(net_id, ipv4): - db_alloc = Allocation.query.filter_by(ipv4=ipv4).first() - - form = ChangeAllocationForm() - if form.validate_on_submit() and request.method == 'POST': - db_alloc.hostname = str(form.hostname.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() - flash("Allocation Updated", 'success') - return redirect(url_for('base.allocations',net_id=net_id,page=request.args.get('page', type=int))) - - modal = { - 'title': 'Update Allocation', - 'body': f'Change informations for {db_alloc.ipv4} allocation.', - 'color': 'primary', - 'modal_type': 'form', - 'action_text': 'Save', - 'form_url': url_for('base.allocation_edit_modal',net_id=db_alloc.net_id,ipv4=db_alloc.ipv4), - } - old_page = request.args.get('page', type=int) - if old_page == 0: - old_page = 1 - return render_template('panel/_modal.html', modal=modal, form=form, old_page=old_page, pagination_active=True) - -## MODIFICATION ROUTES -@base.get('/network//allocations//unallocate') -@login_required -def allocation_delete(net_id,ipv4): - db_alloc = Allocation.query.filter_by(net_id=net_id,ipv4=ipv4).first() - db_alloc.is_used = False - db_alloc.hostname = None - db_alloc.description = None - db_alloc.is_dhcp = False - db_alloc.is_gateway = False - db.session.commit() - flash("Allocation Removed", 'warning') - return redirect(url_for('base.allocations',net_id=net_id,page=request.args.get('page', type=int))) - -@base.get('/network//allocations//decom/') -@login_required -def allocation_decom(net_id,ipv4,action): - db_alloc = Allocation.query.filter_by(net_id=net_id,ipv4=ipv4).first() - if action == 1: - db_alloc.is_decom = True - else: - db_alloc.is_decom = False - db.session.commit() - return redirect(url_for('base.allocations',net_id=net_id,page=request.args.get('page', type=int))) - -@base.get('/network//delete') -@login_required -def network_delete(net_id): - db_network = Network.query.filter_by(id=net_id).first() - db_alloc = Allocation.query.filter_by(net_id=db_network.id).all() - - if db_network != None: - if db_alloc != None: - for alloc in db_alloc: - db.session.delete(alloc) - - db.session.delete(db_network) - db.session.commit() - flash("Network Deleted", 'warning') - return redirect(url_for('base.networks')) - else: - flash("Network Not Found", 'danger') - return redirect(url_for('base.networks')) - -## HTMX SEARCH -@base.post('/network//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: - 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 - if 'dhcp' in search: - for alloc in db_alloc: - if alloc.is_dhcp: - obj_list.append(alloc) - - ## GATEWAY - if 'gateway' in search: - for alloc in db_alloc: - if alloc.is_gateway: - obj_list.append(alloc) - - ## DECOM - if 'decom' in search: - for alloc in db_alloc: - if alloc.is_decom: - obj_list.append(alloc) - - ## DECOM - if 'used' in search: - for alloc in db_alloc: - if alloc.is_used: - 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/_table-alloc.html',allocations=obj_list,Inventory=Inventory,network=db_network) \ No newline at end of file + ) \ No newline at end of file diff --git a/app/routes/r_inventory.py b/app/routes/r_inventory.py new file mode 100644 index 0000000..2afa9e6 --- /dev/null +++ b/app/routes/r_inventory.py @@ -0,0 +1,42 @@ +from datetime import datetime +from flask import Blueprint, request, render_template, flash, redirect, url_for, session +from flask_login import login_required, current_user +from ipaddress import IPv4Network, IPv4Address + +from app._config import app_version + +from app.extensions import * +from app.models import * +from app.forms import NewInventoryItem + +inventory = Blueprint('inventory', __name__) + +@inventory.route('/add', methods=['GET','POST']) +@login_required +def add_item(): + form = NewInventoryItem() + if form.validate_on_submit() and request.method == 'POST': + add_net = Inventory(host_type=int(form.item_type.data),host_name=str(form.item_name.data),host_desc=str(form.item_desc.data)) + db.session.add(add_net) + db.session.commit() + flash("Item ADDED", 'success') + + return render_template('panel/inventory_add.html', title='ADD ITEM', form=form) + +@inventory.route('/list/', methods=['GET','POST']) +@login_required +def list_items(item_type): + db_items = Inventory.query.filter_by(host_type=item_type).all() + return render_template('panel/inventory_view.html', Title='View Items', item_list=db_items) + +@inventory.route('/action//', methods=['GET','POST']) +@login_required +def action_item(item_id,action): + + if action == 1: + db_item = Inventory.query.filter_by(id=item_id).first() + + db.session.delete(db_item) + db.session.commit() + + return redirect(url_for('base.dashboard')) \ No newline at end of file diff --git a/app/routes/r_networks.py b/app/routes/r_networks.py new file mode 100644 index 0000000..81a980d --- /dev/null +++ b/app/routes/r_networks.py @@ -0,0 +1,247 @@ +from datetime import datetime +from flask import Blueprint, request, render_template, flash, redirect, url_for, session +from flask_login import login_required, current_user +from ipaddress import IPv4Network, IPv4Address + +from app._config import app_version + +from app.extensions import * +from app.models import * +from app.forms import NewPrefixForm, ChangeAllocationForm + +network = Blueprint('network', __name__) + +@network.route('/',methods=['GET','POST']) +@login_required +def networks(): + networks = Network.query.all() + form = NewPrefixForm() + if request.method == 'POST' and form.validate_on_submit(): + try: + network = IPv4Network(f"{str(form.subnet.data)}/{str(form.prefix.data)}", False) + + add_net = Network(network_address=str(network.network_address),prefix=network.prefixlen,hosts=network.num_addresses-2,description=str(form.description.data)) + db.session.add(add_net) + db.session.commit() + + for ip in network.hosts(): + db.session.add(Allocation(ipv4=str(ip), net_id=add_net.id)) + + db.session.commit() + return redirect(url_for('network.networks')) + + except: + flash("Invalid Subnet or Prefix", 'danger') + return redirect(url_for('network.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, Allocation=Allocation, navcolor='dark') + +@network.route('//allocations',methods=['GET','POST']) +@login_required +def allocations(net_id): + + active_page = request.args.get('page', type=int) + if active_page == None: + active_page = 1 + + next_page = active_page+1 + prev_page = active_page-1 + + if request.args.get('items', type=int) != None: + session['items'] = request.args.get('items', type=int) + try: + if session['items'] == None: + session['items'] = 15 + except: + session['items'] = 15 + + 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, allocations=db_allocations, network=db_network, Inventory=Inventory, active_page=active_page, next_page=next_page, prev_page=prev_page, navcolor='dark') + +## MODAL ROUTES + +@network.get('//del_modal') +@login_required +def network_del_modal(net_id): + db_network = Network.query.filter_by(id=net_id).first() + modal = { + 'title': 'Delete Network', + 'body': f'Are you sure you want to delete {db_network.network_address}/{db_network.prefix} network ?', + 'color': 'danger', + 'action': 'delete', + 'action_text': 'Delete', + 'action_url': url_for('network.network_delete',net_id=net_id) + } + return render_template('panel/_modal.html', modal=modal, net_id=net_id) + +@network.get('//allocations//del_modal') +@login_required +def allocation_del_modal(net_id,ipv4): + modal = { + 'title': 'Remove Allocation', + 'body': f'Are you sure you want to remove {ipv4} allocation ?', + 'color': 'warning', + 'action': 'delete', + 'action_text': 'Remove', + 'action_url': url_for('network.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) + + +@network.route('//allocations//edit_modal', methods=['GET','POST']) +@login_required +def allocation_edit_modal(net_id, ipv4): + db_alloc = Allocation.query.filter_by(ipv4=ipv4).first() + + form = ChangeAllocationForm() + if form.validate_on_submit() and request.method == 'POST': + db_alloc.hostname = str(form.hostname.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() + flash("Allocation Updated", 'success') + return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int))) + + modal = { + 'title': 'Update Allocation', + 'body': f'Change informations for {db_alloc.ipv4} allocation.', + 'color': 'primary', + 'modal_type': 'form', + 'action_text': 'Save', + 'form_url': url_for('network.allocation_edit_modal',net_id=db_alloc.net_id,ipv4=db_alloc.ipv4), + } + old_page = request.args.get('page', type=int) + if old_page == 0: + old_page = 1 + return render_template('panel/_modal.html', modal=modal, form=form, old_page=old_page, pagination_active=True) + +## MODIFICATION ROUTES +@network.get('//allocations//unallocate') +@login_required +def allocation_delete(net_id,ipv4): + db_alloc = Allocation.query.filter_by(net_id=net_id,ipv4=ipv4).first() + db_alloc.is_used = False + db_alloc.hostname = None + db_alloc.description = None + db_alloc.is_dhcp = False + db_alloc.is_gateway = False + db.session.commit() + flash("Allocation Removed", 'warning') + return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int))) + +@network.get('//allocations//decom/') +@login_required +def allocation_decom(net_id,ipv4,action): + db_alloc = Allocation.query.filter_by(net_id=net_id,ipv4=ipv4).first() + if action == 1: + db_alloc.is_decom = True + else: + db_alloc.is_decom = False + db.session.commit() + return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int))) + +@network.get('//delete') +@login_required +def network_delete(net_id): + db_network = Network.query.filter_by(id=net_id).first() + db_alloc = Allocation.query.filter_by(net_id=db_network.id).all() + + if db_network != None: + if db_alloc != None: + for alloc in db_alloc: + db.session.delete(alloc) + + db.session.delete(db_network) + db.session.commit() + flash("Network Deleted", 'warning') + return redirect(url_for('network.networks')) + else: + flash("Network Not Found", 'danger') + return redirect(url_for('network.networks')) + +## HTMX SEARCH +@network.post('//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: + 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 + if 'dhcp' in search: + for alloc in db_alloc: + if alloc.is_dhcp: + obj_list.append(alloc) + + ## GATEWAY + if 'gateway' in search: + for alloc in db_alloc: + if alloc.is_gateway: + obj_list.append(alloc) + + ## DECOM + if 'decom' in search: + for alloc in db_alloc: + if alloc.is_decom: + obj_list.append(alloc) + + ## DECOM + if 'used' in search: + for alloc in db_alloc: + if alloc.is_used: + 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/_table-alloc.html',allocations=obj_list,Inventory=Inventory,network=db_network) \ No newline at end of file diff --git a/app/templates/panel/_nav.html b/app/templates/panel/_nav.html index fb48d65..1bf5304 100644 --- a/app/templates/panel/_nav.html +++ b/app/templates/panel/_nav.html @@ -10,16 +10,17 @@ Dashboard {% if current_user.is_admin %} diff --git a/app/templates/panel/_table-alloc.html b/app/templates/panel/_table-alloc.html index f09d178..3ab57c3 100644 --- a/app/templates/panel/_table-alloc.html +++ b/app/templates/panel/_table-alloc.html @@ -16,7 +16,7 @@ {% if allocation.is_used %} {% if allocation.is_decom %} - Undecom + Undecom {% else %} - Decom + Decom {% endif %} + + + +
+ + +{% endblock %} \ No newline at end of file diff --git a/app/templates/panel/inventory_view.html b/app/templates/panel/inventory_view.html new file mode 100644 index 0000000..db86070 --- /dev/null +++ b/app/templates/panel/inventory_view.html @@ -0,0 +1,37 @@ +{% extends 'panel/_base.html' %} +{% block content %} +{% include 'panel/_nav.html' %} +{% include 'panel/_flash.html' %} +
+
+
+
+ + + + + + + + + + + + {% for item in item_list %} + + + + + + + + {% endfor %} + +
IDHostnameDescriptionTypeActions
{{item.id}}{{item.host_name}}{{item.host_desc}}{{item.host_type}} + Delete +
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/app/templates/panel/networks.html b/app/templates/panel/networks.html index 96922e6..5f7204a 100644 --- a/app/templates/panel/networks.html +++ b/app/templates/panel/networks.html @@ -26,9 +26,9 @@ {{Allocation.query.filter_by(net_id=network.id,is_used=True).count()}} / {{network.hosts}} {{network.description}} -
Allocations + Allocations