Browse Source

Make PersistentKeepalive configurable

pull/52/head
rezor92 4 years ago
parent
commit
3d9882a19a
  1. 21
      wg_dashboard_backend/migrations/versions/009_create_keep_alive.py
  2. 2
      wg_dashboard_backend/models.py
  3. 1
      wg_dashboard_backend/routers/v1/peer.py
  4. 2
      wg_dashboard_backend/schemas.py
  5. 9
      wg_dashboard_backend/templates/peer.j2
  6. 1
      wg_dashboard_frontend/src/app/interfaces/peer.ts
  7. 8
      wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.html
  8. 2
      wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.ts
  9. 7
      wg_dashboard_frontend/src/app/page/dashboard/peer/peer.component.html

21
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

2
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"))

1
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

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

9
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 %}

1
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: {

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

@ -116,6 +116,14 @@
</mat-form-field>
</td>
</tr>
<tr>
<td>
<mat-form-field class="add-server-full-width">
<mat-label>Default PersistentKeepalive interval</mat-label>
<input formControlName="keep_alive" matInput [placeholder]="defaultPersistentKeepalive">
</mat-form-field>
</td>
</tr>
</table>
<p><b>Keys</b></p>

2
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(''),

7
wg_dashboard_frontend/src/app/page/dashboard/peer/peer.component.html

@ -40,6 +40,13 @@
</mat-form-field>
</p>
<p>
<mat-form-field class="full-width">
<mat-label>PersistentKeepalive interval</mat-label>
<input [disabled]="!peer._edit" name="keep_alive" [(ngModel)]="peer.keep_alive" matInput>
</mat-form-field>
</p>
<p>Keys</p>
<p>

Loading…
Cancel
Save