mirror of
https://github.com/TakeusV1/flask_ipam.git
synced 2026-10-13 17:15:33 +02:00
DEV V1.2
This commit is contained in:
1 parent
a9e8a70df5
commit
eefc23fad8
14 files changed
+404
-324
No files matched your search
@@ -10,6 +10,8 @@ from app.models import *
|
|||||||
from app.extensions import *
|
from app.extensions import *
|
||||||
|
|
||||||
from app.routes.r_base import base
|
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_auth import auth
|
||||||
from app.routes.r_adm import admin
|
from app.routes.r_adm import admin
|
||||||
|
|
||||||
@@ -30,6 +32,8 @@ def create_app():
|
|||||||
|
|
||||||
## BLUEPRINTS
|
## BLUEPRINTS
|
||||||
app.register_blueprint(base, url_prefix='/')
|
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(auth, url_prefix='/auth')
|
||||||
app.register_blueprint(admin, url_prefix='/admin')
|
app.register_blueprint(admin, url_prefix='/admin')
|
||||||
|
|
||||||
|
|||||||
+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.1'
|
app_version = 'V1.2'
|
||||||
app_release_date = '02/2025'
|
app_release_date = '02/2025'
|
||||||
app_url = "http://127.0.0.1"
|
app_url = "http://127.0.0.1"
|
||||||
|
|
||||||
|
|||||||
+5
-6
@@ -11,12 +11,6 @@ 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()])
|
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)])
|
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)])
|
username = StringField(validators=[DataRequired(),Length(max=128)])
|
||||||
password = PasswordField(validators=[DataRequired(),Length(max=128)])
|
password = PasswordField(validators=[DataRequired(),Length(max=128)])
|
||||||
@@ -30,3 +24,8 @@ 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 ?')
|
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()])
|
||||||
+8
-9
@@ -28,17 +28,16 @@ class Allocation(db.Model):
|
|||||||
|
|
||||||
class Inventory(db.Model):
|
class Inventory(db.Model):
|
||||||
id = db.Column(db.Integer(),primary_key=True,unique=True)
|
id = db.Column(db.Integer(),primary_key=True,unique=True)
|
||||||
ip_addr = db.Column(db.Text())
|
|
||||||
# Host Information
|
# Host Information
|
||||||
host_type = db.Column(db.Integer())
|
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))
|
host_desc = db.Column(db.String(64))
|
||||||
# Hardware Information
|
# Hardware Information
|
||||||
host_model = db.Column(db.String(32))
|
host_model = db.Column(db.String(64))
|
||||||
host_manufacturer = db.Column(db.String(32))
|
host_manufacturer = db.Column(db.String(64))
|
||||||
host_serialnumber = db.Column(db.String(32))
|
host_serialnumber = db.Column(db.String(64))
|
||||||
# Network Information
|
# Network Information
|
||||||
host_os = db.Column(db.String(32))
|
host_os = db.Column(db.String(64))
|
||||||
host_location = db.Column(db.String(32))
|
host_location = db.Column(db.String(64))
|
||||||
host_owner = db.Column(db.String(32))
|
host_owner = db.Column(db.String(64))
|
||||||
host_contact = db.Column(db.String(32))
|
host_contact = db.Column(db.String(64))
|
||||||
+4
-262
@@ -1,24 +1,21 @@
|
|||||||
from datetime import datetime
|
from flask import Blueprint, render_template, redirect, url_for
|
||||||
from flask import Blueprint, request, render_template, flash, redirect, url_for, session
|
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
from ipaddress import IPv4Network, IPv4Address
|
|
||||||
|
|
||||||
from app._config import app_version
|
from app._config import app_version
|
||||||
|
|
||||||
from app.extensions import *
|
from app.extensions import *
|
||||||
from app.models import *
|
from app.models import *
|
||||||
from app.forms import NewPrefixForm, NewAllocationForm, ChangeAllocationForm
|
|
||||||
|
|
||||||
base = Blueprint('base', __name__)
|
base = Blueprint('base', __name__)
|
||||||
|
|
||||||
@base.route('/',methods=['GET','POST'])
|
@base.route('/')
|
||||||
def home():
|
def home():
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
return redirect(url_for('base.dashboard'))
|
return redirect(url_for('base.dashboard'))
|
||||||
else:
|
else:
|
||||||
return redirect(url_for('auth.login'))
|
return redirect(url_for('auth.login'))
|
||||||
|
|
||||||
@base.route('/dashboard',methods=['GET','POST'])
|
@base.route('/dashboard')
|
||||||
@login_required
|
@login_required
|
||||||
def dashboard():
|
def dashboard():
|
||||||
|
|
||||||
@@ -42,261 +39,6 @@ def dashboard():
|
|||||||
db_inventory=db_inventory,
|
db_inventory=db_inventory,
|
||||||
available_alloc=available_alloc,
|
available_alloc=available_alloc,
|
||||||
db_users=db_users,
|
db_users=db_users,
|
||||||
|
Inventory=Inventory,
|
||||||
navcolor='dark'
|
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/<int:net_id>/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/<int:net_id>/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 <b>{db_network.network_address}/{db_network.prefix}</b> 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/<int:net_id>/allocations/<string:ipv4>/del_modal')
|
|
||||||
@login_required
|
|
||||||
def allocation_del_modal(net_id,ipv4):
|
|
||||||
modal = {
|
|
||||||
'title': 'Remove Allocation',
|
|
||||||
'body': f'Are you sure you want to remove <b>{ipv4}</b> 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/<int:net_id>/allocations/<string:ipv4>/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 <b>{db_alloc.ipv4}</b> 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/<int:net_id>/allocations/<string:ipv4>/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/<int:net_id>/allocations/<string:ipv4>/decom/<int:action>')
|
|
||||||
@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/<int:net_id>/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/<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:
|
|
||||||
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)
|
|
||||||
@@ -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/<int:item_type>', 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/<int:item_id>/<int: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'))
|
||||||
@@ -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('/<int:net_id>/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('/<int:net_id>/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 <b>{db_network.network_address}/{db_network.prefix}</b> 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('/<int:net_id>/allocations/<string:ipv4>/del_modal')
|
||||||
|
@login_required
|
||||||
|
def allocation_del_modal(net_id,ipv4):
|
||||||
|
modal = {
|
||||||
|
'title': 'Remove Allocation',
|
||||||
|
'body': f'Are you sure you want to remove <b>{ipv4}</b> 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('/<int:net_id>/allocations/<string:ipv4>/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 <b>{db_alloc.ipv4}</b> 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('/<int:net_id>/allocations/<string:ipv4>/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('/<int:net_id>/allocations/<string:ipv4>/decom/<int:action>')
|
||||||
|
@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('/<int:net_id>/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('/<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:
|
||||||
|
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)
|
||||||
@@ -10,16 +10,17 @@
|
|||||||
<a class="nav-link {% if is_dash %}active{% endif %}" href="{{ url_for('base.dashboard') }}"><i class="bi bi-house-door-fill"></i> Dashboard</a>
|
<a class="nav-link {% if is_dash %}active{% endif %}" href="{{ url_for('base.dashboard') }}"><i class="bi bi-house-door-fill"></i> Dashboard</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link {% if is_networks %}active{% endif %}" href="{{ url_for('base.networks') }}"><i class="bi bi-globe"></i> Network(s)</a>
|
<a class="nav-link {% if is_networks %}active{% endif %}" href="{{ url_for('network.networks') }}"><i class="bi bi-globe"></i> Network(s)</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item dropdown">
|
<li class="nav-item dropdown">
|
||||||
<a class="nav-link dropdown-toggle disabled" role="button" data-bs-toggle="dropdown" aria-expanded="false"><i class="bi bi-archive-fill"></i> Inventory</a>
|
<a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown" aria-expanded="false"><i class="bi bi-archive-fill"></i> Inventory</a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a class="dropdown-item" href="#"><i class="bi bi-pc-display"></i> Computers</a></li>
|
<li><a class="dropdown-item" href="{{ url_for('inventory.list_items',item_type=1) }}"><i class="bi bi-pc-display"></i> Computers</a></li>
|
||||||
<li><a class="dropdown-item" href="#"><i class="bi bi-server"></i> Servers</a></li>
|
<li><a class="dropdown-item" href="{{ url_for('inventory.list_items',item_type=2) }}"><i class="bi bi-server"></i> Servers</a></li>
|
||||||
<li><a class="dropdown-item" href="#"><i class="bi bi-server"></i> Virtual Machines</a></li>
|
<li><a class="dropdown-item" href="{{ url_for('inventory.list_items',item_type=3) }}"><i class="bi bi-server"></i> Virtual Machines</a></li>
|
||||||
<li><a class="dropdown-item" href="#"><i class="bi bi-ethernet"></i> Networks Devices</a></li>
|
<li><a class="dropdown-item" href="{{ url_for('inventory.list_items',item_type=4) }}"><i class="bi bi-ethernet"></i> Networks Devices</a></li>
|
||||||
<li><a class="dropdown-item" href="#"><i class="bi bi-collection"></i> Others</a></li>
|
<li><a class="dropdown-item" href="{{ url_for('inventory.list_items',item_type=0) }}"><i class="bi bi-collection"></i> Others</a></li>
|
||||||
|
<li><a class="dropdown-item" href="{{ url_for('inventory.add_item') }}"><i class="bi bi-plus-circle"></i> ADD NEW</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
{% if current_user.is_admin %}
|
{% if current_user.is_admin %}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<td>
|
<td>
|
||||||
{% if allocation.is_used %}
|
{% 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('network.allocation_edit_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
hx-target="#modal-edit"
|
hx-target="#modal-edit"
|
||||||
data-bs-toggle="modal"
|
data-bs-toggle="modal"
|
||||||
@@ -26,12 +26,12 @@
|
|||||||
> Edit
|
> Edit
|
||||||
</button>
|
</button>
|
||||||
{% if allocation.is_decom %}
|
{% if allocation.is_decom %}
|
||||||
<a href="{{ url_for('base.allocation_decom',action=2,net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}" class="btn btn-sm btn-outline-primary" style="padding-top:1px;padding-bottom:1px">Undecom</a>
|
<a href="{{ url_for('network.allocation_decom',action=2,net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}" class="btn btn-sm btn-outline-primary" style="padding-top:1px;padding-bottom:1px">Undecom</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{ url_for('base.allocation_decom',action=1,net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}" class="btn btn-sm btn-outline-warning" style="padding-top:1px;padding-bottom:1px">Decom</a>
|
<a href="{{ url_for('network.allocation_decom',action=1,net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}" class="btn btn-sm btn-outline-warning" style="padding-top:1px;padding-bottom:1px">Decom</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<button
|
<button
|
||||||
hx-get="{{ url_for('base.allocation_del_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}"
|
hx-get="{{ url_for('network.allocation_del_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
hx-target="#modal-del"
|
hx-target="#modal-del"
|
||||||
data-bs-toggle="modal"
|
data-bs-toggle="modal"
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
</button>
|
</button>
|
||||||
{% else %}
|
{% else %}
|
||||||
<button
|
<button
|
||||||
hx-get="{{ url_for('base.allocation_edit_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}"
|
hx-get="{{ url_for('network.allocation_edit_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
hx-target="#modal-edit"
|
hx-target="#modal-edit"
|
||||||
data-bs-toggle="modal"
|
data-bs-toggle="modal"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<input class="form-control" type="search"
|
<input class="form-control" type="search"
|
||||||
name="search" placeholder="Begin Typing To Search Users..."
|
name="search" placeholder="Begin Typing To Search Users..."
|
||||||
hx-post="{{ url_for('base.allocation_search',net_id=network.id) }}"
|
hx-post="{{ url_for('network.allocation_search',net_id=network.id) }}"
|
||||||
hx-trigger="input changed delay:500ms, keyup[key=='Enter']"
|
hx-trigger="input changed delay:500ms, keyup[key=='Enter']"
|
||||||
hx-target="#search-results"
|
hx-target="#search-results"
|
||||||
hx-indicator=".htmx-indicator"
|
hx-indicator=".htmx-indicator"
|
||||||
@@ -36,28 +36,6 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<!-- IPV4 FORM
|
|
||||||
<div class="col-3">
|
|
||||||
<div class="card p-4 shadow rounded-3">
|
|
||||||
<h2 class="text-center mb-4">Add IPv4</h2>
|
|
||||||
<form method="POST">
|
|
||||||
{{ form.csrf_token }}
|
|
||||||
<div class="mb-3">
|
|
||||||
<label class="form-label">IPv4</label>
|
|
||||||
{{ form.ipv4(class="form-control", placeholder=network.network_address) }}
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label class="form-label">Hostname</label>
|
|
||||||
{{ form.host_name(class="form-control", placeholder="example") }}
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label class="form-label">Description</label>
|
|
||||||
{{ form.host_desc(class="form-control", placeholder="webserver") }}
|
|
||||||
</div>
|
|
||||||
<button type="submit" class="btn btn-secondary w-100">Submit</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div> -->
|
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<nav>
|
<nav>
|
||||||
@@ -68,12 +46,6 @@
|
|||||||
{% if allocations.has_next %}
|
{% if allocations.has_next %}
|
||||||
<li class="page-item"><a class="page-link" href="?page={{next_page}}">Next</a></li>
|
<li class="page-item"><a class="page-link" href="?page={{next_page}}">Next</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<!--
|
|
||||||
{% for page in range(allocations.pages+1) %}
|
|
||||||
{% if page != 0%}
|
|
||||||
<li class="page-item"><a class="page-link {%if page==active_page%}active{%endif%}" href="?page={{page}}">{{page}}</a></li>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}-->
|
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<!-- NETWORKS -->
|
<!-- NETWORKS -->
|
||||||
<div class="col-3">
|
<div class="col-3">
|
||||||
<a href="{{ url_for('base.networks') }}" class="card text-bg-info mb-3 text-decoration-none">
|
<a href="{{ url_for('network.networks') }}" class="card text-bg-info mb-3 text-decoration-none">
|
||||||
<div class="card-header"><i class="bi bi-globe"></i> <b>Total Networks</b></div>
|
<div class="card-header"><i class="bi bi-globe"></i> <b>Total Networks</b></div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h1 class="card-title text-center">{{db_networks}}</h1>
|
<h1 class="card-title text-center">{{db_networks}}</h1>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- TOTAL IP -->
|
<!-- TOTAL IP -->
|
||||||
<div class="col-3">
|
<div class="col-3">
|
||||||
<a href="{{ url_for('base.networks') }}" class="card text-bg-secondary mb-3 text-decoration-none" style="margin-bottom:1vh;">
|
<a href="{{ url_for('network.networks') }}" class="card text-bg-secondary mb-3 text-decoration-none" style="margin-bottom:1vh;">
|
||||||
<div class="card-header"><i class="bi bi-broadcast-pin"></i> <b>Total Allocations</b></div>
|
<div class="card-header"><i class="bi bi-broadcast-pin"></i> <b>Total Allocations</b></div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h1 class="card-title text-center">{{db_allocations}} / {{ available_alloc }}</h1>
|
<h1 class="card-title text-center">{{db_allocations}} / {{ available_alloc }}</h1>
|
||||||
@@ -75,12 +75,17 @@
|
|||||||
});
|
});
|
||||||
/* Devices Chart */
|
/* Devices Chart */
|
||||||
const ctx1 = document.getElementById('deviceschart');
|
const ctx1 = document.getElementById('deviceschart');
|
||||||
|
var computers = JSON.parse('{{ Inventory.query.filter_by(host_type=1).count() | tojson }}');
|
||||||
|
var servers = JSON.parse('{{ Inventory.query.filter_by(host_type=2).count() | tojson }}');
|
||||||
|
var virtual_machines = JSON.parse('{{ Inventory.query.filter_by(host_type=3).count() | tojson }}');
|
||||||
|
var networks_devices = JSON.parse('{{ Inventory.query.filter_by(host_type=4).count() | tojson }}');
|
||||||
|
var others = JSON.parse('{{ Inventory.query.filter_by(host_type=0).count() | tojson }}');
|
||||||
new Chart(ctx1, {
|
new Chart(ctx1, {
|
||||||
type: 'doughnut',
|
type: 'doughnut',
|
||||||
data: {
|
data: {
|
||||||
labels: ['Computers', 'Servers', 'VM', 'Network Devices', 'Others'],
|
labels: ['Computers', 'Servers', 'VM', 'Network Devices', 'Others'],
|
||||||
datasets: [{
|
datasets: [{
|
||||||
data: [1, 1, 1, 1, 1],
|
data: [computers, servers, virtual_machines, networks_devices, others],
|
||||||
borderWidth: 2
|
borderWidth: 2
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
{% extends 'panel/_base.html' %}
|
||||||
|
{% block content %}
|
||||||
|
{% include 'panel/_nav.html' %}
|
||||||
|
{% include 'panel/_flash.html' %}
|
||||||
|
<div class="container" style="margin-top:5vh;">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4"></div>
|
||||||
|
<div class="col-4">
|
||||||
|
<div class="card p-4 shadow rounded-3">
|
||||||
|
<h2 class="text-center mb-4">Add Item</h2>
|
||||||
|
<form method="POST">
|
||||||
|
{{ form.csrf_token }}
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="subnet" class="form-label">Name</label>
|
||||||
|
{{ form.item_name(class="form-control", placeholder="Computer A") }}
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="prefix" class="form-label">Description</label>
|
||||||
|
{{ form.item_desc(class="form-control", placeholder="Computer A for IT support...") }}
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="description" class="form-label">Item Type</label>
|
||||||
|
{{ form.item_type(class="form-control") }}
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-secondary w-100">Submit</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-4"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{% extends 'panel/_base.html' %}
|
||||||
|
{% block content %}
|
||||||
|
{% include 'panel/_nav.html' %}
|
||||||
|
{% include 'panel/_flash.html' %}
|
||||||
|
<div class="container" style="margin-top:5vh;">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2"></div>
|
||||||
|
<div class="col-8">
|
||||||
|
<table class="table table-striped table-hover table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">ID</th>
|
||||||
|
<th scope="col">Hostname</th>
|
||||||
|
<th scope="col">Description</th>
|
||||||
|
<th scope="col">Type</th>
|
||||||
|
<th scope="col">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for item in item_list %}
|
||||||
|
<tr>
|
||||||
|
<td>{{item.id}}</td>
|
||||||
|
<td>{{item.host_name}}</td>
|
||||||
|
<td>{{item.host_desc}}</td>
|
||||||
|
<td>{{item.host_type}}</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ url_for('inventory.action_item',action=1,item_id=item.id) }}?page={{active_page}}" class="btn btn-sm btn-outline-danger" style="padding-top:1px;padding-bottom:1px">Delete</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="col-2"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -26,9 +26,9 @@
|
|||||||
<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) }}?page=1" class="btn btn-sm btn-outline-info" style="padding-top:1px;padding-bottom:1px">Allocations</a>
|
<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>
|
||||||
<button
|
<button
|
||||||
hx-get="{{ url_for('base.network_del_modal',net_id=network.id) }}"
|
hx-get="{{ url_for('network.network_del_modal',net_id=network.id) }}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
hx-target="#modal-get"
|
hx-target="#modal-get"
|
||||||
data-bs-toggle="modal"
|
data-bs-toggle="modal"
|
||||||
|
|||||||
Reference in new issue
Block a user