diff --git a/wg_dashboard_backend/main.py b/wg_dashboard_backend/main.py index a32fe81..e0d3a99 100644 --- a/wg_dashboard_backend/main.py +++ b/wg_dashboard_backend/main.py @@ -98,106 +98,5 @@ async def shutdown(): pass - if __name__ == "__main__": - - """async def main(): - if not script.wireguard.is_installed(): - print("NOT INSTALLED!") - exit(0) - await database.connect() - - # TODO - GUI EVENT - Create new WG interface and post to backend - wg_interface_in = dict( - address="10.0.100.1/24", - listen_port=5192, - interface="wg0", - endpoint=None, - private_key=None, - public_key=None, - shared_key=None, - post_up=None, - post_down=None, - peers=[] - ) - - wg_interface = schemas.WGServer(**wg_interface_in) - - sess = SessionLocal() - - if not db.wireguard.server_add(sess, wg_interface): - print("Already exists. error") - - # Public/Private key - private_key, public_key = script.wireguard.generate_keys() - wg_interface.private_key = private_key - wg_interface.public_key = public_key - db.wireguard.server_key_pair_set(sess, wg_interface) - - # Shared key - shared_key = script.wireguard.generate_psk() - wg_interface.shared_key = shared_key - db.wireguard.server_preshared_key(sess, wg_interface) - - # Post UP - wg_interface.post_up = "echo 'LOL2'" - db.wireguard.server_post_up_set(sess, wg_interface) - - # Post DOWN - wg_interface.post_down = "echo 'LOL'" - db.wireguard.server_post_down_set(sess, wg_interface) - - # Listen port - wg_interface.listen_port = 5192 - if not db.wireguard.server_listen_port_set(sess, wg_interface): - print("FAILED!") - - # Address - wg_interface.address = "10.0.100.1/24" - db.wireguard.server_ip_address_set(sess, wg_interface) - - # Endpoint - wg_interface.endpoint = "10.0.0.135" - db.wireguard.server_endpoint_set(sess, wg_interface) - - # TODO - Creates peer - wg_peer_in = dict( - server="wg0" - ) - - # CReate schema instance - wg_peer = schemas.WGPeer(**wg_peer_in) - - # Insert initial peer - wg_peer = db.wireguard.peer_insert(sess, wg_peer) - print(wg_peer) - - # Set DNS of peer - wg_peer.dns = ["sysx.no"] - wg_peer = db.wireguard.peer_dns_set(sess, wg_peer) - - # Update priv_pub key - wg_peer = db.wireguard.peer_key_pair_generate(sess, wg_peer) - - print(wg_peer) - - all_peers = db.wireguard.peer_get(sess, wg_interface) - print(all_peers) - - db.wireguard.peer_generate_config(sess, wg_peer) - print("-----") - db_interface = db.wireguard.server_query_get_by_interface(sess, wg_interface.interface).one() - db.wireguard.server_generate_config(sess, wg_interface.from_orm(db_interface)) - - if script.wireguard.is_running(db_interface): - script.wireguard.stop_interface(db_interface) - script.wireguard.start_interface(db_interface) - # script.wireguard.stop_interface(db_interface) - - if script.wireguard.is_running(db_interface): - script.wireguard.add_peer(wg_interface, wg_peer) - script.wireguard.remove_peer(wg_interface, wg_peer) - - db.wireguard.start_client(sess, wg_peer)""" - uvicorn.run("__main__:app", reload=True) diff --git a/wg_dashboard_backend/models.py b/wg_dashboard_backend/models.py index 1869381..4de51c4 100644 --- a/wg_dashboard_backend/models.py +++ b/wg_dashboard_backend/models.py @@ -27,6 +27,7 @@ class WGServer(Base): public_key = Column(sqlalchemy.String) shared_key = Column(sqlalchemy.String) endpoint = Column(sqlalchemy.String) + dns = Column(sqlalchemy.String) post_up = Column(sqlalchemy.String) post_down = Column(sqlalchemy.String) diff --git a/wg_dashboard_backend/routers/v1/peer.py b/wg_dashboard_backend/routers/v1/peer.py index e845b66..dbef6fc 100644 --- a/wg_dashboard_backend/routers/v1/peer.py +++ b/wg_dashboard_backend/routers/v1/peer.py @@ -54,7 +54,7 @@ def add_peer( # Set unnamed peer.name = "Unnamed" - peer.dns = server.endpoint + peer.dns = server.dns peer.configuration = script.wireguard.generate_config(dict( peer=peer, diff --git a/wg_dashboard_backend/schemas.py b/wg_dashboard_backend/schemas.py index 8730465..f37fa9e 100644 --- a/wg_dashboard_backend/schemas.py +++ b/wg_dashboard_backend/schemas.py @@ -153,6 +153,7 @@ class WGServer(GenericModel): configuration: str = None post_up: str = None post_down: str = None + dns: str = None peers: pydantic.typing.List['WGPeer'] = [] diff --git a/wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.html b/wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.html index 897a5be..0f6202c 100644 --- a/wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.html +++ b/wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.html @@ -50,6 +50,15 @@ +
+ |
+
Keys