This commit is contained in:
Jamil Bou Kheir
2021-09-05 07:36:39 +00:00
parent fc602293e1
commit 0ad76746a7
3 changed files with 11 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ defmodule FzHttp.Devices.Device do
field :private_key, FzHttp.Encrypted.Binary
field :server_public_key, :string
field :remote_ip, EctoNetwork.INET
field :octet_sequence, :integer, read_after_writes: true
field :interface_address4, EctoNetwork.INET
field :interface_address6, EctoNetwork.INET
field :last_seen_at, :utc_datetime_usec
@@ -30,6 +31,7 @@ defmodule FzHttp.Devices.Device do
|> cast(attrs, [
:allowed_ips,
:remote_ip,
:octet_sequence,
:interface_address4,
:interface_address6,
:server_public_key,

View File

@@ -26,6 +26,11 @@
</dt>
<dd><%= @device.name %></dd>
<dt>
<strong>Interface IP:</strong>
</dt>
<dd>10.3.2.<%= @device.octet_sequence %></dd>
<dt>
<strong>Public key:</strong>
</dt>
@@ -77,7 +82,7 @@
<pre><code id="wg-conf">
[Interface]
PrivateKey = <%= @device.private_key %>
Address = 172.16.99.1/24
Address = 10.3.2.<%= @device.octet_sequence %>
DNS = 1.1.1.1, 1.0.0.1
[Peer]

View File

@@ -10,6 +10,8 @@ defmodule FzHttp.Repo.Migrations.CreateDevices do
add :private_key, :bytea, null: false
add :server_public_key, :string, null: false
add :remote_ip, :inet
# XXX: Rework this in app code
add :octet_sequence, :serial
add :interface_address4, :inet
add :interface_address6, :inet
add :last_seen_at, :utc_datetime_usec
@@ -23,5 +25,6 @@ defmodule FzHttp.Repo.Migrations.CreateDevices do
create unique_index(:devices, [:private_key])
create unique_index(:devices, [:preshared_key])
create unique_index(:devices, [:user_id, :name])
create unique_index(:devices, [:octet_sequence])
end
end