diff --git a/apps/fg_http/lib/fg_http/rules/rule.ex b/apps/fg_http/lib/fg_http/rules/rule.ex
index 13bb981c7..3d944008d 100644
--- a/apps/fg_http/lib/fg_http/rules/rule.ex
+++ b/apps/fg_http/lib/fg_http/rules/rule.ex
@@ -13,7 +13,7 @@ defmodule FgHttp.Rules.Rule do
field :action, RuleActionEnum, default: "drop"
field :priority, :integer, default: 0
field :enabled, :boolean, default: true
- field :port, :string
+ field :port_number, :integer
field :protocol, RuleProtocolEnum, default: "all"
belongs_to :device, Device
@@ -23,7 +23,17 @@ defmodule FgHttp.Rules.Rule do
def changeset(rule, attrs) do
rule
- |> cast(attrs, [:device_id, :priority, :action, :destination, :port, :protocol, :enabled])
+ |> cast(attrs, [
+ :device_id,
+ :priority,
+ :action,
+ :destination,
+ :port_number,
+ :protocol,
+ :enabled
+ ])
|> validate_required([:device_id, :priority, :action, :destination, :protocol, :enabled])
+ |> validate_number(:priority, greater_than_or_equal_to: 0, less_than_or_equal_to: 100)
+ |> validate_number(:port_number, greater_than_or_equal_to: 0, less_than_or_equal_to: 65_535)
end
end
diff --git a/apps/fg_http/lib/fg_http_web/templates/device/edit.html.eex b/apps/fg_http/lib/fg_http_web/templates/device/edit.html.eex
index f25354674..1e6a79836 100644
--- a/apps/fg_http/lib/fg_http_web/templates/device/edit.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/device/edit.html.eex
@@ -1,5 +1,5 @@
-
Edit Device
+
+
Edit Device
-<%= render "form.html", Map.put(assigns, :action, Routes.device_path(@conn, :update, @device)) %>
-
-<%= link "Back", to: Routes.device_path(@conn, :index) %>
+ <%= render "form.html", Map.put(assigns, :action, Routes.device_path(@conn, :update, @device)) %>
+
diff --git a/apps/fg_http/lib/fg_http_web/templates/device/form.html.eex b/apps/fg_http/lib/fg_http_web/templates/device/form.html.eex
index 7cd82cf71..408dade10 100644
--- a/apps/fg_http/lib/fg_http_web/templates/device/form.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/device/form.html.eex
@@ -2,7 +2,7 @@
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
-
+
Oops, something went wrong! Please check the errors below.
<% end %>
@@ -12,14 +12,21 @@
<%= text_input f, :name, class: "input" %>
-
+
<%= error_tag f, :name %>
- <%= submit "Save", class: "button is-primary" %>
+
+
+ <%= link "Back", to: Routes.device_path(@conn, :index), class: "button" %>
+
+
+ <%= submit "Save", class: "button is-primary" %>
+
+
<% end %>
diff --git a/apps/fg_http/lib/fg_http_web/templates/device/index.html.eex b/apps/fg_http/lib/fg_http_web/templates/device/index.html.eex
index 0617ee191..9306a90d4 100644
--- a/apps/fg_http/lib/fg_http_web/templates/device/index.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/device/index.html.eex
@@ -1,32 +1,34 @@
-
Listing Devices
+
+
Listing Devices
-
-
-
- | Name |
- Rules |
- Public key |
- Last IP |
- |
-
-
-
- <%= for device <- @devices do %>
-
- | <%= device.name %> |
- <%= link rules_title(device), to: Routes.device_rule_path(@conn, :index, device) %> |
- <%= device.public_key %> |
- <%= device.last_ip || "Never connected" %> |
-
- <%= link "Show", to: Routes.device_path(@conn, :show, device) %>
- |
- <%= link "Edit", to: Routes.device_path(@conn, :edit, device) %>
- |
- <%= link "Delete", to: Routes.device_path(@conn, :delete, device), method: :delete, data: [confirm: "Are you sure?"] %>
- |
-
- <% end %>
-
-
+
+
+
+ | Name |
+ Rules |
+ Public key |
+ Last IP |
+ |
+
+
+
+ <%= for device <- @devices do %>
+
+ | <%= device.name %> |
+ <%= link rules_title(device), to: Routes.device_rule_path(@conn, :index, device) %> |
+ <%= device.public_key %> |
+ <%= device.last_ip || "Never connected" %> |
+
+ <%= link "Show", to: Routes.device_path(@conn, :show, device) %>
+ |
+ <%= link "Edit", to: Routes.device_path(@conn, :edit, device) %>
+ |
+ <%= link "Delete", to: Routes.device_path(@conn, :delete, device), method: :delete, data: [confirm: "Are you sure?"] %>
+ |
+
+ <% end %>
+
+
+
<%= link "New Device", to: Routes.device_path(@conn, :new), class: "button is-primary" %>
diff --git a/apps/fg_http/lib/fg_http_web/templates/device/new.html.eex b/apps/fg_http/lib/fg_http_web/templates/device/new.html.eex
index f25ccc25a..f1fe663cd 100644
--- a/apps/fg_http/lib/fg_http_web/templates/device/new.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/device/new.html.eex
@@ -1,11 +1,13 @@
-
New Device
+
+
New Device
-<%= if @changeset.action do %>
-
- The following errors occurred when creating this Device:
+ <%= if @changeset.action do %>
+
+ The following errors occurred when creating this Device:
- <%= aggregated_errors(@changeset) %>
-
-<% end %>
+ <%= aggregated_errors(@changeset) %>
+
+ <% end %>
-<%= live_render(@conn, FgHttpWeb.NewDeviceLive, session: %{"user_id" => @session.id}) %>
+ <%= live_render(@conn, FgHttpWeb.NewDeviceLive, session: %{"user_id" => @session.id}) %>
+
diff --git a/apps/fg_http/lib/fg_http_web/templates/layout/flash.html.eex b/apps/fg_http/lib/fg_http_web/templates/layout/flash.html.eex
index 61c7117b0..db4f34c00 100644
--- a/apps/fg_http/lib/fg_http_web/templates/layout/flash.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/layout/flash.html.eex
@@ -1,16 +1,18 @@
<%= unless is_nil(get_flash(@conn, :info)) and is_nil(get_flash(@conn, :error)) do %>
-
- <%= if get_flash(@conn, :info) do %>
+ <%= if get_flash(@conn, :info) do %>
+
<%= get_flash(@conn, :info) %>
- <% end %>
- <%= if get_flash(@conn, :error) do %>
+
+ <% end %>
+ <%= if get_flash(@conn, :error) do %>
+
<%= get_flash(@conn, :error) %>
- <% end %>
-
+
+ <% end %>
<% end %>
diff --git a/apps/fg_http/lib/fg_http_web/templates/rule/edit.html.eex b/apps/fg_http/lib/fg_http_web/templates/rule/edit.html.eex
index 179b5f2ba..0fff9ba15 100644
--- a/apps/fg_http/lib/fg_http_web/templates/rule/edit.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/rule/edit.html.eex
@@ -1,5 +1,5 @@
-
Edit Rule
+
+
Edit Rule
-<%= render "form.html", Map.put(assigns, :action, Routes.rule_path(@conn, :update, @rule)) %>
-
-<%= link "Back", to: Routes.device_rule_path(@conn, :index, @rule.device_id) %>
+ <%= render "form.html", Map.put(assigns, :action, Routes.rule_path(@conn, :update, @rule)) %>
+
diff --git a/apps/fg_http/lib/fg_http_web/templates/rule/form.html.eex b/apps/fg_http/lib/fg_http_web/templates/rule/form.html.eex
index cc12b6c5b..b225c00bb 100644
--- a/apps/fg_http/lib/fg_http_web/templates/rule/form.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/rule/form.html.eex
@@ -2,11 +2,21 @@
<%= form_for @changeset, @action, [], fn f -> %>
<%= if @changeset.action do %>
-
+
Oops, something went wrong! Please check the errors below.
<% end %>
+
+ <%= label f, :action, class: "label" %>
+
+ <%= select f, :action, action_options_for_select() %>
+
+
+ <%= error_tag f, :action %>
+
+
+
<%= label f, :destination, class: "label" %>
@@ -17,18 +27,18 @@
placeholder: "IPv4/6 CIDR range or address"
%>
-
+
<%= error_tag f, :destination %>
- <%= label f, :port, class: "label" %>
+ <%= label f, :port_number, class: "label" %>
- <%= text_input f, :port, class: "input", placeholder: "1 - 65535" %>
+ <%= text_input f, :port_number, class: "input", placeholder: "1 - 65535" %>
-
- <%= error_tag f, :port %>
+
+ <%= error_tag f, :port_number %>
@@ -37,7 +47,7 @@
<%= select f, :protocol, protocol_options_for_select() %>
-
+
<%= error_tag f, :protocol %>
@@ -47,7 +57,7 @@
<%= text_input f, :priority, class: "input" %>
-
+
<%= error_tag f, :priority %>
@@ -57,7 +67,7 @@
<%= checkbox f, :enabled, class: "checkbox" %>
Enabled
-
+
<%= error_tag f, :enabled %>
diff --git a/apps/fg_http/lib/fg_http_web/templates/rule/index.html.eex b/apps/fg_http/lib/fg_http_web/templates/rule/index.html.eex
index cbac5cd0e..8caaeb0e6 100644
--- a/apps/fg_http/lib/fg_http_web/templates/rule/index.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/rule/index.html.eex
@@ -1,39 +1,40 @@
-Listing Rules for Device <%= @device.name %>
+
+
Listing Rules for Device <%= @device.name %>
-
+
+
+
+ | Action |
+ Destination |
+ Port Number |
+ Protocol |
+ Priority |
+ Enabled |
-
-
- | Action |
- Destination |
- Port |
- Protocol |
- Priority |
- Enabled |
-
- |
-
-
-<%= for rule <- @rules do %>
-
-
- | <%= rule.action %> |
- <%= rule.destination %> |
- <%= rule.port %> |
- <%= rule.protocol %> |
- <%= rule.priority %> |
- <%= rule.enabled %> |
-
- <%= link "Show", to: Routes.rule_path(@conn, :show, rule) %>
- |
- <%= link "Edit", to: Routes.rule_path(@conn, :edit, rule) %>
- |
- <%= link "Delete", to: Routes.rule_path(@conn, :delete, rule), method: :delete, data: [confirm: "Are you sure?"] %>
- |
-
-<% end %>
-
-
+ |
+
+
+ <%= for rule <- @rules do %>
+
+
+ | <%= rule.action %> |
+ <%= rule.destination %> |
+ <%= rule.port_number %> |
+ <%= rule.protocol %> |
+ <%= rule.priority %> |
+ <%= rule.enabled %> |
+
+ <%= link "Show", to: Routes.rule_path(@conn, :show, rule) %>
+ |
+ <%= link "Edit", to: Routes.rule_path(@conn, :edit, rule) %>
+ |
+ <%= link "Delete", to: Routes.rule_path(@conn, :delete, rule), method: :delete, data: [confirm: "Are you sure?"] %>
+ |
+
+ <% end %>
+
+
+
<%=
link "New Rule",
diff --git a/apps/fg_http/lib/fg_http_web/templates/rule/new.html.eex b/apps/fg_http/lib/fg_http_web/templates/rule/new.html.eex
index c86bb53d5..c10694867 100644
--- a/apps/fg_http/lib/fg_http_web/templates/rule/new.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/rule/new.html.eex
@@ -1,3 +1,5 @@
-New Rule for Device <%= @device.name %>
+
+
New Rule for Device <%= @device.name %>
-<%= render "form.html", Map.put(assigns, :action, Routes.device_rule_path(@conn, :create, @device)) %>
+ <%= render "form.html", Map.put(assigns, :action, Routes.device_rule_path(@conn, :create, @device)) %>
+
diff --git a/apps/fg_http/lib/fg_http_web/templates/rule/show.html.eex b/apps/fg_http/lib/fg_http_web/templates/rule/show.html.eex
index 2d417847e..a27759284 100644
--- a/apps/fg_http/lib/fg_http_web/templates/rule/show.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/rule/show.html.eex
@@ -2,22 +2,22 @@
Show Rule
- - Action:
+ - Action:
- <%= @rule.action %>
- - Destination:
+ - Destination:
- <%= @rule.destination %>
- - Port:
- - <%= @rule.port %>
+ - Port Number:
+ - <%= @rule.port_number %>
- - Protocol:
+ - Protocol:
- <%= @rule.protocol %>
- - Priority
+ - Priority:
- <%= @rule.priority %>
- - Enabled:
+ - Enabled:
- <%= @rule.enabled %>
diff --git a/apps/fg_http/lib/fg_http_web/templates/session/new.html.eex b/apps/fg_http/lib/fg_http_web/templates/session/new.html.eex
index eb38f009c..8812f8f39 100644
--- a/apps/fg_http/lib/fg_http_web/templates/session/new.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/session/new.html.eex
@@ -15,7 +15,7 @@
<%= text_input(f, :email, class: "input") %>
-
+
<%= error_tag f, :email %>
@@ -25,7 +25,7 @@
<%= password_input(f, :password, class: "input") %>
-
+
<%= error_tag f, :password %>
diff --git a/apps/fg_http/lib/fg_http_web/templates/user/edit.html.eex b/apps/fg_http/lib/fg_http_web/templates/user/edit.html.eex
index 6348ddb93..f9c17e5dd 100644
--- a/apps/fg_http/lib/fg_http_web/templates/user/edit.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/user/edit.html.eex
@@ -1,59 +1,69 @@
-Edit Account
- <%= form_for @changeset, Routes.user_path(@conn, :update), fn f -> %>
- <%= if @changeset.action do %>
+
+
Edit Account
+
+ <%= form_for @changeset, Routes.user_path(@conn, :update), fn f -> %>
+ <%= if @changeset.action do %>
+
+
Oops, something went wrong! Please check the errors below.
+
+ <% end %>
+
+
+ <%= label f, :email, class: "label" %>
+
+
+ <%= text_input f, :email, class: "input" %>
+
+
+ <%= error_tag f, :email %>
+
-
Oops, something went wrong! Please check the errors below.
+
+
+ <%= label f, :password, class: "label" %>
+
+ <%= password_input f, :password, class: "input password" %>
+
+
+ <%= error_tag f, :password %>
+
+
+
+
+ <%= label f, :password_confirmation, class: "label" %>
+
+ <%= password_input f, :password_confirmation, class: "input password" %>
+
+
+ <%= error_tag f, :password_confirmation %>
+
+
+
+
+ <%= label f, :current_password, class: "label" %>
+ <%= password_input f, :current_password, class: "input password" %>
+
+
+ <%= error_tag f, :current_password %>
+
+
+
+
+
+
+
+ <%= link "Back", to: Routes.user_path(@conn, :show), class: "button" %>
+
+
+ <%= submit "Save", class: "button is-primary" %>
+
+
+
<% end %>
-
-
- <%= label f, :email, class: "label" %>
-
-
- <%= text_input f, :email, class: "input" %>
-
-
- <%= error_tag f, :email %>
-
-
-
-
- <%= label f, :password, class: "label" %>
-
- <%= password_input f, :password, class: "input password" %>
-
-
- <%= error_tag f, :password %>
-
-
-
-
- <%= label f, :password_confirmation, class: "label" %>
-
- <%= password_input f, :password_confirmation, class: "input password" %>
-
-
- <%= error_tag f, :password_confirmation %>
-
-
-
-
- <%= label f, :current_password, class: "label" %>
- <%= password_input f, :current_password, class: "input password" %>
-
-
- <%= error_tag f, :current_password %>
-
-
-
-
-
- <%= submit "Save", class: "button is-primary" %>
-
-
- <% end %>
+
diff --git a/apps/fg_http/lib/fg_http_web/templates/user/new.html.eex b/apps/fg_http/lib/fg_http_web/templates/user/new.html.eex
index 4aeff7bdf..9d7e41f5e 100644
--- a/apps/fg_http/lib/fg_http_web/templates/user/new.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/user/new.html.eex
@@ -16,7 +16,7 @@
<%= text_input(f, :email, class: "input") %>
-
+
<%= error_tag f, :email %>
@@ -26,7 +26,7 @@
<%= password_input(f, :password, class: "input") %>
-
+
<%= error_tag f, :password %>
@@ -36,7 +36,7 @@
<%= password_input(f, :password_confirmation, class: "input") %>
-
+
<%= error_tag f, :password_confirmation %>
diff --git a/apps/fg_http/lib/fg_http_web/templates/user/show.html.eex b/apps/fg_http/lib/fg_http_web/templates/user/show.html.eex
index be1e33b88..aad645841 100644
--- a/apps/fg_http/lib/fg_http_web/templates/user/show.html.eex
+++ b/apps/fg_http/lib/fg_http_web/templates/user/show.html.eex
@@ -1,5 +1,5 @@
-
+
Your Account
@@ -14,7 +14,7 @@
- <%= link("Edit", to: Routes.user_path(@conn, :edit), class: "button is-primary") %>
+ <%= link("Change Password", to: Routes.user_path(@conn, :edit), class: "button is-primary") %>
<%= link "Delete your account",
to: Routes.user_path(@conn, :delete),
method: :delete,
diff --git a/apps/fg_http/lib/fg_http_web/views/device_view.ex b/apps/fg_http/lib/fg_http_web/views/device_view.ex
index 135f88fe1..b298b1c2a 100644
--- a/apps/fg_http/lib/fg_http_web/views/device_view.ex
+++ b/apps/fg_http/lib/fg_http_web/views/device_view.ex
@@ -12,6 +12,6 @@ defmodule FgHttpWeb.DeviceView do
end
defp reverse_concat(word, number) do
- "#{number}" <> "#{word}"
+ "#{number} " <> "#{word}"
end
end
diff --git a/apps/fg_http/lib/fg_http_web/views/rule_view.ex b/apps/fg_http/lib/fg_http_web/views/rule_view.ex
index 9e5c6c4e8..381515560 100644
--- a/apps/fg_http/lib/fg_http_web/views/rule_view.ex
+++ b/apps/fg_http/lib/fg_http_web/views/rule_view.ex
@@ -4,4 +4,8 @@ defmodule FgHttpWeb.RuleView do
def protocol_options_for_select do
RuleProtocolEnum.__enum_map__()
end
+
+ def action_options_for_select do
+ RuleActionEnum.__enum_map__()
+ end
end
diff --git a/apps/fg_http/priv/repo/migrations/20200228154815_create_rules.exs b/apps/fg_http/priv/repo/migrations/20200228154815_create_rules.exs
index 6ecb22209..1fc9af1ca 100644
--- a/apps/fg_http/priv/repo/migrations/20200228154815_create_rules.exs
+++ b/apps/fg_http/priv/repo/migrations/20200228154815_create_rules.exs
@@ -11,7 +11,7 @@ defmodule FgHttp.Repo.Migrations.CreateRules do
add :action, RuleActionEnum.type(), default: "drop", null: false
add :priority, :integer, default: 0, null: false
add :enabled, :boolean, default: false, null: false
- add :port, :string
+ add :port_number, :integer
add :device_id, references(:devices, on_delete: :delete_all), null: false
timestamps(type: :utc_datetime_usec)
diff --git a/apps/fg_http/test/fg_http_web/controllers/rule_controller_test.exs b/apps/fg_http/test/fg_http_web/controllers/rule_controller_test.exs
index 5b5b1f684..4deb258a4 100644
--- a/apps/fg_http/test/fg_http_web/controllers/rule_controller_test.exs
+++ b/apps/fg_http/test/fg_http_web/controllers/rule_controller_test.exs
@@ -5,7 +5,7 @@ defmodule FgHttpWeb.RuleControllerTest do
@valid_create_attrs %{
destination: "1.1.1.1",
- port: "53",
+ port_number: 53,
protocol: "udp",
action: "accept"
}