-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aktualisiere IP-Listenansicht und Leayout Ändere IP-Listenansicht, um…
… eine scrollbare Tabelle mit sticky Header zu ermöglichen. Passe die Höhe der Tabelle an die Bildschirmgröße an. Aktualisiere das Layout, um die Lücken zwischen den Menüpunkten zu entfernen.
- Loading branch information
Showing
10 changed files
with
232 additions
and
34 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,32 @@ | ||
from flask import Flask | ||
import secrets | ||
from routes import atlas, settings | ||
|
||
import os | ||
from database import db | ||
|
||
atlasapp = Flask(__name__, static_folder="static", template_folder="templates") | ||
atlasapp.secret_key = secrets.token_hex(16) | ||
|
||
# ? Blueprints | ||
atlasapp.register_blueprint(atlas.bp_atlas) | ||
atlasapp.register_blueprint(settings.bp_settings) | ||
# Configure the database URI | ||
database_dir = os.path.join(os.getcwd(), "database") | ||
if not os.path.exists(database_dir): | ||
os.makedirs(database_dir) | ||
atlasapp.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join( | ||
database_dir, "ip_atlas.db" | ||
) | ||
atlasapp.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False | ||
|
||
|
||
# Register the blueprints | ||
from routes.atlas import bp_atlas | ||
from routes.settings import bp_settings | ||
|
||
atlasapp.register_blueprint(bp_atlas) | ||
atlasapp.register_blueprint(bp_settings) | ||
|
||
# Initialize SQLAlchemy with the Flask app | ||
db.init_app(atlasapp) | ||
|
||
if __name__ == "__main__": | ||
with atlasapp.app_context(): | ||
from models import * | ||
|
||
db.create_all() | ||
atlasapp.run(debug=True, host="0.0.0.0", port=5000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from flask_sqlalchemy import SQLAlchemy | ||
|
||
db = SQLAlchemy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
from database import db | ||
from sqlalchemy.orm import relationship | ||
from sqlalchemy.orm import validates | ||
import ipaddress | ||
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey | ||
from datetime import datetime | ||
|
||
|
||
class Host(db.Model): | ||
__tablename__ = "hosts" | ||
id = Column(Integer, primary_key=True, autoincrement=True) | ||
hostname = Column(String, unique=True, nullable=False, index=True) | ||
ipv4 = Column(String, nullable=False, index=True) | ||
ipv6 = Column(String, index=True) | ||
cidr = Column(Integer) | ||
deleted = Column(Boolean, default=False) | ||
ports = relationship("Port", back_populates="host") | ||
tags = relationship("HostTag", back_populates="host") | ||
|
||
@validates("ipv4", "ipv6") | ||
def validate_ip(self, key, address): | ||
if address: | ||
try: | ||
ip_obj = ipaddress.ip_address(address) | ||
if (key == "ipv4" and ip_obj.version != 4) or ( | ||
key == "ipv6" and ip_obj.version != 6 | ||
): | ||
raise ValueError(f"Invalid {key} address: {address}") | ||
return str(ip_obj) | ||
except ValueError: | ||
raise ValueError(f"Invalid {key} address: {address}") | ||
return address | ||
|
||
|
||
class Tag(db.Model): | ||
__tablename__ = "tags" | ||
id = Column(Integer, primary_key=True, autoincrement=True) | ||
tag_name = Column(String, unique=True, nullable=False, index=True) | ||
deleted = Column(Boolean, default=False) | ||
hosts = relationship("HostTag", back_populates="tag") | ||
|
||
|
||
class HostTag(db.Model): | ||
__tablename__ = "host_tags" | ||
host_id = Column(Integer, ForeignKey("hosts.id"), primary_key=True) | ||
tag_id = Column(Integer, ForeignKey("tags.id"), primary_key=True) | ||
host = relationship("Host", back_populates="tags") | ||
tag = relationship("Tag", back_populates="hosts") | ||
|
||
|
||
class Port(db.Model): | ||
__tablename__ = "ports" | ||
id = Column(Integer, primary_key=True, autoincrement=True) | ||
host_id = Column(Integer, ForeignKey("hosts.id")) | ||
port_number = Column(Integer, nullable=False) | ||
deleted = Column(Boolean, default=False) | ||
host = relationship("Host", back_populates="ports") | ||
|
||
|
||
class AuditLog(db.Model): | ||
__tablename__ = "audit_logs" | ||
id = Column(Integer, primary_key=True, autoincrement=True) | ||
action_type = Column(String, nullable=False) | ||
table_name = Column(String, nullable=False) | ||
record_id = Column(Integer, nullable=False) | ||
timestamp = Column(DateTime, default=datetime.utcnow) | ||
user = Column(String, nullable=False) | ||
|
||
|
||
class Statistics(db.Model): | ||
__tablename__ = "statistics" | ||
id = Column(Integer, primary_key=True, autoincrement=True) | ||
stat_key = Column(String, nullable=False, index=True) | ||
stat_value = Column(Integer, nullable=False) | ||
last_updated = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) | ||
|
||
|
||
class DiscoveredDevice(db.Model): | ||
__tablename__ = "discovered_devices" | ||
id = Column(Integer, primary_key=True, autoincrement=True) | ||
mac_address = Column(String, nullable=False, index=True) | ||
ipv4 = Column(String, nullable=False, index=True) | ||
ipv6 = Column(String, index=True) | ||
hostname = Column(String, index=True) | ||
first_seen = Column(DateTime, default=datetime.utcnow) | ||
last_seen = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) | ||
deleted = Column(Boolean, default=False) | ||
vendor = Column(String) | ||
ignore = Column(Boolean, default=False) | ||
|
||
@validates("ipv4", "ipv6") | ||
def validate_ip(self, key, address): | ||
if address: | ||
try: | ||
ip_obj = ipaddress.ip_address(address) | ||
if (key == "ipv4" and ip_obj.version != 4) or ( | ||
key == "ipv6" and ip_obj.version != 6 | ||
): | ||
raise ValueError(f"Invalid {key} address: {address}") | ||
return str(ip_obj) | ||
except ValueError: | ||
raise ValueError(f"Invalid {key} address: {address}") | ||
return address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,50 @@ | ||
from helper import writeJson | ||
from faker import Faker | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker | ||
from models import db, Host, Tag, Port, HostTag | ||
import random | ||
from app import atlasapp | ||
|
||
# Assuming your database URI is stored in a variable or directly provided | ||
DATABASE_URI = atlasapp.config["SQLALCHEMY_DATABASE_URI"] | ||
engine = create_engine(DATABASE_URI) | ||
Session = sessionmaker(bind=engine) | ||
|
||
fake = Faker() | ||
|
||
|
||
def generate_test_data(num_hosts=50): | ||
session = Session() | ||
for i in range(1, num_hosts + 1): | ||
hostname = f"Host{i}" | ||
ipv4 = fake.ipv4_private(network=False, address_class=None) | ||
tags = [fake.word(), fake.word(), "test"] | ||
ipv6 = fake.ipv6(network=False) | ||
ports = [fake.random_int(min=1, max=65535) for _ in range(2)] | ||
writeJson(hostname, ipv4, tags, ipv6, ports) | ||
ports_numbers = [fake.random_int(min=1, max=65535) for _ in range(2)] | ||
|
||
# Create Host instance | ||
host = Host(hostname=hostname, ipv4=ipv4, ipv6=ipv6) | ||
session.add(host) | ||
session.commit() # Commit to assign an ID to the host | ||
|
||
# Create Port instances | ||
for port_number in ports_numbers: | ||
port = Port(host_id=host.id, port_number=port_number) | ||
session.add(port) | ||
|
||
# Create and associate Tags | ||
tags = [fake.word(), fake.word(), "test"] | ||
for tag_name in tags: | ||
tag = session.query(Tag).filter_by(tag_name=tag_name).first() | ||
if not tag: | ||
tag = Tag(tag_name=tag_name) | ||
session.add(tag) | ||
session.commit() # Commit to assign an ID to the tag | ||
|
||
# Create association between host and tag | ||
host_tag = HostTag(host_id=host.id, tag_id=tag.id) | ||
session.add(host_tag) | ||
|
||
session.commit() | ||
|
||
|
||
generate_test_data() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.