wip
This commit is contained in:
parent
3b2f1db4ce
commit
5c16964b76
47 changed files with 2080 additions and 1053 deletions
|
@ -8,42 +8,49 @@ from flask_login import UserMixin
|
|||
# User model has been moved to app.core.auth
|
||||
# Import it from there instead if needed: from app.core.auth import User
|
||||
|
||||
|
||||
class Port(db.Model):
|
||||
__tablename__ = 'ports'
|
||||
|
||||
__tablename__ = "ports"
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
app_id = db.Column(db.Integer, db.ForeignKey('apps.id', ondelete='CASCADE'), nullable=False)
|
||||
app_id = db.Column(
|
||||
db.Integer, db.ForeignKey("apps.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
port_number = db.Column(db.Integer, nullable=False)
|
||||
protocol = db.Column(db.String(10), default='TCP') # TCP, UDP, etc.
|
||||
protocol = db.Column(db.String(10), default="TCP") # TCP, UDP, etc.
|
||||
description = db.Column(db.String(200))
|
||||
|
||||
|
||||
# Relationship
|
||||
app = db.relationship('App', back_populates='ports')
|
||||
|
||||
app = db.relationship("App", back_populates="ports")
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Port {self.port_number}/{self.protocol}>'
|
||||
return f"<Port {self.port_number}/{self.protocol}>"
|
||||
|
||||
|
||||
class Server(db.Model):
|
||||
__tablename__ = 'servers'
|
||||
|
||||
__tablename__ = "servers"
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
hostname = db.Column(db.String(64), nullable=False)
|
||||
ip_address = db.Column(db.String(39), nullable=False) # IPv4 or IPv6
|
||||
subnet_id = db.Column(db.Integer, db.ForeignKey('subnets.id'), nullable=False)
|
||||
subnet_id = db.Column(db.Integer, db.ForeignKey("subnets.id"), nullable=False)
|
||||
documentation = db.Column(db.Text)
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
updated_at = db.Column(
|
||||
db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
|
||||
)
|
||||
|
||||
# Relationships
|
||||
subnet = db.relationship('Subnet', back_populates='servers')
|
||||
apps = db.relationship('App', back_populates='server', cascade='all, delete-orphan')
|
||||
|
||||
subnet = db.relationship("Subnet", back_populates="servers")
|
||||
apps = db.relationship("App", back_populates="server", cascade="all, delete-orphan")
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Server {self.hostname}>'
|
||||
return f"<Server {self.hostname}>"
|
||||
|
||||
|
||||
class Subnet(db.Model):
|
||||
__tablename__ = 'subnets'
|
||||
|
||||
__tablename__ = "subnets"
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
cidr = db.Column(db.String(18), unique=True, nullable=False) # e.g., 192.168.1.0/24
|
||||
location = db.Column(db.String(64))
|
||||
|
@ -51,43 +58,48 @@ class Subnet(db.Model):
|
|||
last_scanned = db.Column(db.DateTime)
|
||||
auto_scan = db.Column(db.Boolean, default=False)
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
updated_at = db.Column(
|
||||
db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
|
||||
)
|
||||
|
||||
# Relationships
|
||||
servers = db.relationship('Server', back_populates='subnet')
|
||||
|
||||
servers = db.relationship("Server", back_populates="subnet")
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Subnet {self.cidr}>'
|
||||
|
||||
return f"<Subnet {self.cidr}>"
|
||||
|
||||
@property
|
||||
def used_ips(self):
|
||||
"""Number of IPs used in this subnet (servers)"""
|
||||
return len(self.servers)
|
||||
|
||||
|
||||
# Getter and setter for active_hosts as JSON
|
||||
@property
|
||||
def active_hosts_list(self):
|
||||
if not self.active_hosts:
|
||||
return []
|
||||
return json.loads(self.active_hosts)
|
||||
|
||||
|
||||
@active_hosts_list.setter
|
||||
def active_hosts_list(self, hosts):
|
||||
self.active_hosts = json.dumps(hosts)
|
||||
|
||||
|
||||
class App(db.Model):
|
||||
__tablename__ = 'apps'
|
||||
|
||||
__tablename__ = "apps"
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(64), nullable=False)
|
||||
server_id = db.Column(db.Integer, db.ForeignKey('servers.id'), nullable=False)
|
||||
server_id = db.Column(db.Integer, db.ForeignKey("servers.id"), nullable=False)
|
||||
documentation = db.Column(db.Text)
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
updated_at = db.Column(
|
||||
db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
|
||||
)
|
||||
|
||||
# Relationships
|
||||
server = db.relationship('Server', back_populates='apps')
|
||||
ports = db.relationship('Port', back_populates='app', cascade='all, delete-orphan')
|
||||
|
||||
server = db.relationship("Server", back_populates="apps")
|
||||
ports = db.relationship("Port", back_populates="app", cascade="all, delete-orphan")
|
||||
|
||||
def __repr__(self):
|
||||
return f'<App {self.name}>'
|
||||
return f"<App {self.name}>"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue