wip
This commit is contained in:
parent
6dd38036e7
commit
097b3dbf09
34 changed files with 1719 additions and 520 deletions
|
@ -1,23 +1,49 @@
|
|||
from app.core.extensions import db
|
||||
from app.core.models import Subnet, Server, App
|
||||
from app.core.auth import User
|
||||
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():
|
||||
# Example seed data for network objects
|
||||
subnet = Subnet(cidr='192.168.1.0/24', location='Office', auto_scan=True)
|
||||
server = Server(hostname='server1', ip_address='192.168.1.10', subnet=subnet)
|
||||
app = App(name='Web App', server=server, documentation='# Welcome to Web App',
|
||||
_ports='[{"port": 80, "type": "tcp", "desc": "Web"}]')
|
||||
|
||||
"""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',
|
||||
auto_scan=True,
|
||||
active_hosts=json.dumps([])
|
||||
)
|
||||
db.session.add(subnet)
|
||||
|
||||
# Create a sample server
|
||||
server = Server(
|
||||
hostname='server1',
|
||||
ip_address='192.168.1.10',
|
||||
subnet=subnet,
|
||||
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.'
|
||||
)
|
||||
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')
|
||||
]
|
||||
db.session.add_all(ports)
|
||||
|
||||
# Create a default user if none exists
|
||||
if User.query.count() == 0:
|
||||
admin = User(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)
|
||||
|
||||
db.session.add(subnet)
|
||||
db.session.add(server)
|
||||
db.session.add(app)
|
||||
|
||||
try:
|
||||
db.session.commit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue