wip
This commit is contained in:
parent
3b2f1db4ce
commit
5c16964b76
47 changed files with 2080 additions and 1053 deletions
|
@ -3,51 +3,52 @@ from app.core.models import Subnet, Server, App, Port
|
|||
from app.core.auth import User # Import User from auth module
|
||||
import json
|
||||
|
||||
|
||||
def seed_database():
|
||||
"""Add sample data to the database"""
|
||||
# Create a default subnet if none exists
|
||||
if Subnet.query.count() == 0:
|
||||
subnet = Subnet(
|
||||
cidr='192.168.1.0/24',
|
||||
location='Office',
|
||||
cidr="192.168.1.0/24",
|
||||
location="Office",
|
||||
auto_scan=True,
|
||||
active_hosts=json.dumps([])
|
||||
active_hosts=json.dumps([]),
|
||||
)
|
||||
db.session.add(subnet)
|
||||
|
||||
|
||||
# Create a sample server
|
||||
server = Server(
|
||||
hostname='server1',
|
||||
ip_address='192.168.1.10',
|
||||
hostname="server1",
|
||||
ip_address="192.168.1.10",
|
||||
subnet=subnet,
|
||||
documentation='# Server 1\n\nThis is a sample server.'
|
||||
documentation="# Server 1\n\nThis is a sample server.",
|
||||
)
|
||||
db.session.add(server)
|
||||
|
||||
|
||||
# Create a sample app
|
||||
app = App(
|
||||
name='Web App',
|
||||
server=server,
|
||||
documentation='# Welcome to Web App\n\nThis is a sample application.'
|
||||
name="Web App",
|
||||
server=server,
|
||||
documentation="# Welcome to Web App\n\nThis is a sample application.",
|
||||
)
|
||||
db.session.add(app)
|
||||
|
||||
|
||||
# Add some ports
|
||||
ports = [
|
||||
Port(app=app, port_number=80, protocol='TCP', description='HTTP'),
|
||||
Port(app=app, port_number=443, protocol='TCP', description='HTTPS')
|
||||
Port(app=app, port_number=80, protocol="TCP", description="HTTP"),
|
||||
Port(app=app, port_number=443, protocol="TCP", description="HTTPS"),
|
||||
]
|
||||
db.session.add_all(ports)
|
||||
|
||||
|
||||
# Create a default user if none exists
|
||||
if User.query.count() == 0:
|
||||
admin = User(username='admin', email='admin@example.com', is_admin=True)
|
||||
admin.set_password('admin')
|
||||
admin = User(username="admin", email="admin@example.com", is_admin=True)
|
||||
admin.set_password("admin")
|
||||
db.session.add(admin)
|
||||
|
||||
|
||||
try:
|
||||
db.session.commit()
|
||||
print("Database seeded successfully")
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
print(f"Error seeding database: {e}")
|
||||
print(f"Error seeding database: {e}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue