Browse Source

* Added Default DNS

* Removed old code

* BREAKING CHANGES:
Create COLUMN dns on server table if you have running setup
pull/5/head
Per-Arne 5 years ago
parent
commit
c568aa3ff2
  1. 101
      wg_dashboard_backend/main.py
  2. 1
      wg_dashboard_backend/models.py
  3. 2
      wg_dashboard_backend/routers/v1/peer.py
  4. 1
      wg_dashboard_backend/schemas.py
  5. 9
      wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.html
  6. 1
      wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.ts
  7. 2
      wg_dashboard_frontend/src/app/page/dashboard/server/server.component.html

101
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)

1
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)

2
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,

1
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'] = []

9
wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.html

@ -50,6 +50,15 @@
</td>
</tr></table>
<table class="add-server-full-width" cellspacing="0"><tr>
<td>
<mat-form-field class="add-server-full-width">
<mat-label>Default DNS</mat-label>
<input formControlName="dns" matInput placeholder="8.8.8.8">
</mat-form-field>
</td>
</tr></table>
<p><b>Keys</b></p>
<p>
<mat-form-field class="add-server-full-width">

1
wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.ts

@ -44,6 +44,7 @@ export class AddServerComponent implements OnInit {
interface: new FormControl('', [Validators.required, Validators.minLength(3)]),
listen_port: new FormControl('', [Validators.required, NumberValidator.stringIsNumber]),
endpoint: new FormControl('', Validators.required),
dns: new FormControl(''),
private_key: new FormControl('' ),
public_key: new FormControl('' ),
shared_key: new FormControl('' ),

2
wg_dashboard_frontend/src/app/page/dashboard/server/server.component.html

@ -127,7 +127,7 @@
</td>
LOL {{peer !== selectedPeer}}
</tr>
<tr [hidden]="peer !== selectedPeer">
<td colspan="6">

Loading…
Cancel
Save