diff --git a/wg_dashboard_backend/migrations/versions/009_create_keep_alive.py b/wg_dashboard_backend/migrations/versions/009_create_keep_alive.py new file mode 100644 index 0000000..90b49cb --- /dev/null +++ b/wg_dashboard_backend/migrations/versions/009_create_keep_alive.py @@ -0,0 +1,21 @@ +from sqlalchemy import * +from migrate import * + + +def upgrade(migrate_engine): + try: + meta = MetaData(bind=migrate_engine) + server = Table('server', meta, autoload=True) + keep_alive = Column('keep_alive', Text) + keep_alive.create(server) + except: + pass + + +def downgrade(migrate_engine): + try: + meta = MetaData(bind=migrate_engine) + server = Table('server', meta, autoload=True) + server.c.keep_alive.drop() + except: + pass diff --git a/wg_dashboard_backend/models.py b/wg_dashboard_backend/models.py index 2fbc056..bdfbbc1 100644 --- a/wg_dashboard_backend/models.py +++ b/wg_dashboard_backend/models.py @@ -42,6 +42,7 @@ class WGServer(Base): endpoint = Column(sqlalchemy.String) dns = Column(sqlalchemy.String) allowed_ips = Column(sqlalchemy.String) + keep_alive = Column(sqlalchemy.String) read_only = Column(sqlalchemy.Integer, default=0) post_up = Column(sqlalchemy.String) @@ -64,6 +65,7 @@ class WGPeer(Base): shared_key = Column(sqlalchemy.Text) dns = Column(sqlalchemy.Text) allowed_ips = Column(sqlalchemy.String) + keep_alive = Column(sqlalchemy.String) read_only = Column(sqlalchemy.Integer, default=0) server_id = Column(Integer, sqlalchemy.ForeignKey('server.id', ondelete="CASCADE", onupdate="CASCADE")) diff --git a/wg_dashboard_backend/routers/v1/peer.py b/wg_dashboard_backend/routers/v1/peer.py index 77b8dd9..6f07958 100644 --- a/wg_dashboard_backend/routers/v1/peer.py +++ b/wg_dashboard_backend/routers/v1/peer.py @@ -65,6 +65,7 @@ def add_peer( peer.public_key = keys["public_key"] peer.allowed_ips = server.allowed_ips + peer.keep_alive = server.keep_alive # Set unnamed peer.name = "Unnamed" if not peer_add.name else peer_add.name diff --git a/wg_dashboard_backend/schemas.py b/wg_dashboard_backend/schemas.py index a540e35..6c9fb5b 100644 --- a/wg_dashboard_backend/schemas.py +++ b/wg_dashboard_backend/schemas.py @@ -132,6 +132,7 @@ class WGPeer(GenericModel): server_id: str dns: str = None allowed_ips: str = None + keep_alive: str = None configuration: str = None class Meta: @@ -170,6 +171,7 @@ class WGServer(GenericModel): post_down: str = None dns: str = None allowed_ips: str = None + keep_alive: str = None read_only: int = None peers: pydantic.typing.List['WGPeer'] = [] diff --git a/wg_dashboard_backend/templates/peer.j2 b/wg_dashboard_backend/templates/peer.j2 index a4b9b42..c7faf57 100644 --- a/wg_dashboard_backend/templates/peer.j2 +++ b/wg_dashboard_backend/templates/peer.j2 @@ -1,14 +1,11 @@ [Interface] Address = {{ data.peer.address }}/{{ data.server.subnet }}{%- if is_ipv6 -%},{{ data.peer.v6_address }}/{{ data.server.v6_subnet }}{%- endif %} PrivateKey = {{ data.peer.private_key }} -{% if data.peer.dns %} -DNS = {{ data.peer.dns }} -{% endif %} +{% if data.peer.dns %}DNS = {{ data.peer.dns }}{% endif %} [Peer] PublicKey = {{ data.server.public_key }} AllowedIPs = {{ data.peer.allowed_ips }} Endpoint = {{ data.server.endpoint }}:{{ data.server.listen_port }} -{% if data.peer.shared_key %} -PresharedKey = {{ data.peer.shared_key }} -{% endif %} +{% if data.peer.shared_key %}PresharedKey = {{ data.peer.shared_key }}{% endif %} +{% if data.peer.keep_alive %}PersistentKeepalive = {{data.peer.keep_alive}}{% endif %} diff --git a/wg_dashboard_frontend/src/app/interfaces/peer.ts b/wg_dashboard_frontend/src/app/interfaces/peer.ts index c96cb1d..2a913c7 100644 --- a/wg_dashboard_frontend/src/app/interfaces/peer.ts +++ b/wg_dashboard_frontend/src/app/interfaces/peer.ts @@ -7,6 +7,7 @@ export interface Peer { shared_key: string; dns: string; allowed_ips: string; + keep_alive: string; name: string; configuration: string; stats: { 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 2197971..af13857 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 @@ -116,6 +116,14 @@ +
Keys
diff --git a/wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.ts b/wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.ts index 7c13f81..f14309e 100644 --- a/wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.ts +++ b/wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.ts @@ -45,6 +45,7 @@ export class AddServerComponent implements OnInit { defaultDNS = this.defaultIPv4Address + ",8.8.8.8" defaultIPv6Address = "fd42:42:42::1" defaultAllowedIPs = "0.0.0.0/0, ::/0" + defaultPersistentKeepalive = "0" serverForm: FormGroup = null; @@ -62,6 +63,7 @@ export class AddServerComponent implements OnInit { endpoint: new FormControl('', Validators.required), dns: new FormControl(this.defaultDNS), allowed_ips: new FormControl(this.defaultAllowedIPs), + keep_alive: new FormControl(this.defaultPersistentKeepalive), private_key: new FormControl('' ), public_key: new FormControl('' ), post_up: new FormControl(''), diff --git a/wg_dashboard_frontend/src/app/page/dashboard/peer/peer.component.html b/wg_dashboard_frontend/src/app/page/dashboard/peer/peer.component.html index bfca94a..da7af02 100644 --- a/wg_dashboard_frontend/src/app/page/dashboard/peer/peer.component.html +++ b/wg_dashboard_frontend/src/app/page/dashboard/peer/peer.component.html @@ -40,6 +40,13 @@ +
+
Keys