From cb27f6da71e434d7d1a6173240b8628cfa22cabe Mon Sep 17 00:00:00 2001 From: Jamil Bou Kheir Date: Fri, 9 Oct 2020 10:07:36 -0500 Subject: [PATCH] Checkpoint --- .tool-versions | 2 +- apps/fg_http/lib/fg_http/ecto_enums.ex | 2 +- apps/fg_http/lib/fg_http_web/error_helpers.ex | 4 +- .../live/new_device_live.html.leex | 4 +- .../templates/device/form.html.eex | 2 +- .../templates/device/index.html.eex | 2 +- .../templates/device/show.html.eex | 8 ++- .../templates/layout/flash.html.eex | 2 +- .../templates/password_reset/edit.html.eex | 69 ++++++++----------- .../templates/password_reset/new.html.eex | 40 +++++++---- .../fg_http_web/templates/rule/form.html.eex | 19 +++-- .../fg_http_web/templates/rule/index.html.eex | 21 +++--- .../fg_http_web/templates/rule/show.html.eex | 42 ++++++----- .../fg_http_web/templates/user/edit.html.eex | 2 +- .../fg_http_web/templates/user/show.html.eex | 2 +- .../lib/fg_http_web/views/rule_view.ex | 14 ++++ .../20200228145810_create_devices.exs | 1 + .../password_reset_controller_test.exs | 8 +-- .../controllers/rule_controller_test.exs | 2 +- 19 files changed, 135 insertions(+), 111 deletions(-) diff --git a/.tool-versions b/.tool-versions index 72b18096e..66317f66b 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,4 +1,4 @@ -elixir 1.11.0-rc.0-otp-23 +elixir 1.11.0-otp-23 erlang 23.1 nodejs 10.22.1 python 3.7.9 diff --git a/apps/fg_http/lib/fg_http/ecto_enums.ex b/apps/fg_http/lib/fg_http/ecto_enums.ex index 579ce3acd..f8a57bad6 100644 --- a/apps/fg_http/lib/fg_http/ecto_enums.ex +++ b/apps/fg_http/lib/fg_http/ecto_enums.ex @@ -1,7 +1,7 @@ import EctoEnum # We only allow dropping or accepting packets for now -defenum(RuleActionEnum, :action, [:drop, :accept]) +defenum(RuleActionEnum, :action, [:drop, :allow]) # See http://ipset.netfilter.org/iptables.man.html defenum(RuleProtocolEnum, :protocol, [ diff --git a/apps/fg_http/lib/fg_http_web/error_helpers.ex b/apps/fg_http/lib/fg_http_web/error_helpers.ex index 2c58540f4..462a395c6 100644 --- a/apps/fg_http/lib/fg_http_web/error_helpers.ex +++ b/apps/fg_http/lib/fg_http_web/error_helpers.ex @@ -22,7 +22,9 @@ defmodule FgHttpWeb.ErrorHelpers do Generates tag for inlined form input errors. """ def error_tag(form, field) do - Enum.map(Keyword.get_values(form.errors, field), fn error -> + values = Keyword.get_values(form.errors, field) + + Enum.map(values, fn error -> content_tag(:span, translate_error(error), class: "help-block") end) end diff --git a/apps/fg_http/lib/fg_http_web/live/new_device_live.html.leex b/apps/fg_http/lib/fg_http_web/live/new_device_live.html.leex index 428eceef2..19a201b34 100644 --- a/apps/fg_http/lib/fg_http_web/live/new_device_live.html.leex +++ b/apps/fg_http/lib/fg_http_web/live/new_device_live.html.leex @@ -37,7 +37,7 @@ Endpoint = <%= Application.fetch_env!(:fg_http, :vpn_endpoint) %>

- <%= link "Back to Devices", to: Routes.device_path(@socket, :index), class: "button" %> + <%= link "Back to Devices", to: Routes.device_path(@socket, :index) %>

<% else %>

Device connected!

@@ -53,7 +53,7 @@ Endpoint = <%= Application.fetch_env!(:fg_http, :vpn_endpoint) %>
<%= - link("Cancel and Go Back to Devices", to: Routes.device_path(@socket, :index), class: "button") + link("Cancel and Go Back to Devices", to: Routes.device_path(@socket, :index)) %>
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 408dade10..63441decd 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 @@ -21,7 +21,7 @@
- <%= link "Back", to: Routes.device_path(@conn, :index), class: "button" %> + <%= link "Back", to: Routes.device_path(@conn, :index) %>
<%= submit "Save", class: "button is-primary" %> 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 9306a90d4..aca62af6d 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 @@ -31,4 +31,4 @@
-<%= link "New Device", to: Routes.device_path(@conn, :new), class: "button is-primary" %> +<%= link "New Device", to: Routes.device_path(@conn, :new) %> diff --git a/apps/fg_http/lib/fg_http_web/templates/device/show.html.eex b/apps/fg_http/lib/fg_http_web/templates/device/show.html.eex index aa3ca03ae..c7318137a 100644 --- a/apps/fg_http/lib/fg_http_web/templates/device/show.html.eex +++ b/apps/fg_http/lib/fg_http_web/templates/device/show.html.eex @@ -2,10 +2,14 @@

Show Device

-
Name:
+
+ Name: +
<%= @device.name %>
-
Public key:
+
+ Public key: +
<%= @device.public_key %>
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 db4f34c00..5250ccc5c 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,5 +1,5 @@ <%= unless is_nil(get_flash(@conn, :info)) and is_nil(get_flash(@conn, :error)) do %> -
+
<%= if get_flash(@conn, :info) do %>
diff --git a/apps/fg_http/lib/fg_http_web/templates/password_reset/edit.html.eex b/apps/fg_http/lib/fg_http_web/templates/password_reset/edit.html.eex index 7865d567e..fd785c8d4 100644 --- a/apps/fg_http/lib/fg_http_web/templates/password_reset/edit.html.eex +++ b/apps/fg_http/lib/fg_http_web/templates/password_reset/edit.html.eex @@ -1,55 +1,42 @@ -

Edit Password

+
+
+

Reset Password

+
-<%= form_for @changeset, Routes.password_reset_path(@conn, :update, @password_reset.id), fn f -> %> - <%= hidden_input f, :reset_token %> + <%= form_for @changeset, Routes.password_reset_path(@conn, :update, @password_reset.id), fn f -> %> + <%= hidden_input f, :reset_token %> - <%= if @changeset.action do %> -
-

Oops, something went wrong! Please check the errors below.

-
- <% end %> + <%= if @changeset.action do %> +
+

Oops, something went wrong! Please check the errors below.

+
+ <% end %> -
-
- <%= label f, :password %> -
-
-

- <%= text_input f, :password, placeholder: "Password" %> -

-
-
-

+ <%= label(f, :password, class: "label") %> +

+ <%= password_input(f, :password, class: "input",placeholder: "New Password")%> +
+

<%= error_tag f, :password %>

-
-
-
-
- <%= label f, :password_confirmation %> -
-
-

- <%= text_input f, :password_confirmation, placeholder: "Password Confirmation" %> -

-
-
-

+ <%= label(f, :password_confirmation, class: "label") %> +

+ <%= password_input(f, :password_confirmation, class: "input",placeholder: "New Password")%> +
+

<%= error_tag f, :password_confirmation %>

-
-
-
- <%= submit "Submit" %> +
+
+ <%= submit "Submit", class: "button is-primary" %> +
+
+ <% end %>
-<% end %> - - - <%= link "Back", to: Routes.session_path(@conn, :new) %> - +
diff --git a/apps/fg_http/lib/fg_http_web/templates/password_reset/new.html.eex b/apps/fg_http/lib/fg_http_web/templates/password_reset/new.html.eex index 220f12cd1..2ab1c01e6 100644 --- a/apps/fg_http/lib/fg_http_web/templates/password_reset/new.html.eex +++ b/apps/fg_http/lib/fg_http_web/templates/password_reset/new.html.eex @@ -1,19 +1,29 @@ -

Reset Password

+
+
+

Request Password Reset Link

+
-<%= form_for @changeset, Routes.password_reset_path(@conn, :create), fn f -> %> - <%= if @changeset.action do %> -
-

Oops, something went wrong! Please check the errors below.

-
- <% end %> + <%= form_for @changeset, Routes.password_reset_path(@conn, :create), fn f -> %> + <%= if @changeset.action do %> +
+

Oops, something went wrong! Please check the errors below.

+
+ <% end %> - <%= label f, :email %> - <%= text_input f, :email %> - <%= error_tag f, :email %> +
+ <%= label(f, :email, class: "label") %> +
+ <%= text_input(f, :email, class: "input") %> +
+

+ <%= error_tag f, :email %> +

+
-
- <%= submit "Submit" %> +
+ <%= link "Back", to: Routes.session_path(@conn, :new) %> + <%= submit "Submit", class: "button is-primary" %> +
+ <% end %>
-<% end %> - -<%= link "Back", to: Routes.session_path(@conn, :new) %> +
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 b225c00bb..f4bb5cab9 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 @@ -60,6 +60,11 @@

<%= error_tag f, :priority %>

+

+ + Higher numbers indicate higher priority. + +

@@ -72,17 +77,9 @@

-
-
-
-
- <%= link "Back", to: Routes.device_rule_path(@conn, :index, @device), class: "button" %> -
-
- <%= submit "Save", class: "button is-primary" %> -
-
-
+
+ <%= link "Back", to: Routes.device_rule_path(@conn, :index, @device) %> + <%= submit "Save", class: "button is-primary" %>
<% end %>
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 8caaeb0e6..36dab0e16 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 @@ -9,7 +9,7 @@ Port Number Protocol Priority - Enabled + Status @@ -19,10 +19,10 @@ <%= rule.action %> <%= rule.destination %> - <%= rule.port_number %> + <%= port_number_helper(rule) %> <%= rule.protocol %> <%= rule.priority %> - <%= rule.enabled %> + <%= status_helper(rule) %> <%= link "Show", to: Routes.rule_path(@conn, :show, rule) %> | @@ -36,8 +36,13 @@
-<%= - link "New Rule", - to: Routes.device_rule_path(@conn, :new, @device), - class: "button is-primary" -%> +
+ <%= + link "Back to Devices", + to: Routes.device_path(@conn, :index) + %> + <%= + link "New Rule", + to: Routes.device_rule_path(@conn, :new, @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 a27759284..cc7096337 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 @@ -1,28 +1,32 @@ -
-

Show Rule

+
+
+
+

Show Rule

-
-
Action:
-
<%= @rule.action %>
+
+
Action:
+
<%= @rule.action %>
-
Destination:
-
<%= @rule.destination %>
+
Destination:
+
<%= @rule.destination %>
-
Port Number:
-
<%= @rule.port_number %>
+
Port Number:
+
<%= port_number_helper(@rule) %>
-
Protocol:
-
<%= @rule.protocol %>
+
Protocol:
+
<%= @rule.protocol %>
-
Priority:
-
<%= @rule.priority %>
+
Priority:
+
<%= @rule.priority %>
-
Enabled:
-
<%= @rule.enabled %>
-
+
Enabled:
+
<%= @rule.enabled %>
+
-
- <%= link "Edit", to: Routes.rule_path(@conn, :edit, @rule), class: "button is-primary" %> - <%= link "Back", to: Routes.device_rule_path(@conn, :index, @rule.device_id), class: "button is-danger" %> +
+ <%= link "Back", to: Routes.device_rule_path(@conn, :index, @rule.device_id) %> + <%= link "Edit", to: Routes.rule_path(@conn, :edit, @rule) %> +
+
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 f9c17e5dd..344f556c8 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 @@ -55,7 +55,7 @@
- <%= link "Back", to: Routes.user_path(@conn, :show), class: "button" %> + <%= link "Back", to: Routes.user_path(@conn, :show) %>
<%= submit "Save", class: "button is-primary" %> 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 aad645841..96a706ef3 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 @@ -14,7 +14,7 @@
- <%= link("Change Password", to: Routes.user_path(@conn, :edit), class: "button is-primary") %> + <%= link("Change Email or Password", to: Routes.user_path(@conn, :edit)) %> <%= link "Delete your account", to: Routes.user_path(@conn, :delete), method: :delete, 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 381515560..7891808e3 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 @@ -8,4 +8,18 @@ defmodule FgHttpWeb.RuleView do def action_options_for_select do RuleActionEnum.__enum_map__() end + + def port_number_helper(rule) when is_nil(rule.port_number) do + "-" + end + + def port_number_helper(rule), do: rule.port_number + + def status_helper(rule) do + if rule.enabled do + "Enabled" + else + "Disabled" + end + end end diff --git a/apps/fg_http/priv/repo/migrations/20200228145810_create_devices.exs b/apps/fg_http/priv/repo/migrations/20200228145810_create_devices.exs index d1c8d6b8e..6fcb7b592 100644 --- a/apps/fg_http/priv/repo/migrations/20200228145810_create_devices.exs +++ b/apps/fg_http/priv/repo/migrations/20200228145810_create_devices.exs @@ -14,5 +14,6 @@ defmodule FgHttp.Repo.Migrations.CreateDevices do create index(:devices, [:user_id]) create unique_index(:devices, [:public_key]) + create unique_index(:devices, [:name]) end end diff --git a/apps/fg_http/test/fg_http_web/controllers/password_reset_controller_test.exs b/apps/fg_http/test/fg_http_web/controllers/password_reset_controller_test.exs index 8e2eef9be..f7fc11072 100644 --- a/apps/fg_http/test/fg_http_web/controllers/password_reset_controller_test.exs +++ b/apps/fg_http/test/fg_http_web/controllers/password_reset_controller_test.exs @@ -9,7 +9,7 @@ defmodule FgHttpWeb.PasswordResetControllerTest do describe "new password_reset" do test "renders form", %{unauthed_conn: conn} do conn = get(conn, Routes.password_reset_path(conn, :new)) - assert html_response(conn, 200) =~ "Reset Password" + assert html_response(conn, 200) =~ "Request Password Reset Link" end end @@ -28,7 +28,7 @@ defmodule FgHttpWeb.PasswordResetControllerTest do password_reset: @invalid_create_attrs ) - assert html_response(conn, 200) =~ "Reset Password" + assert html_response(conn, 200) =~ "Request Password Reset Link" assert get_flash(conn, :error) == "Email not found." end end @@ -43,7 +43,7 @@ defmodule FgHttpWeb.PasswordResetControllerTest do Routes.password_reset_path(conn, :edit, password_reset.reset_token) ) - assert html_response(conn, 200) =~ "Edit Password" + assert html_response(conn, 200) =~ "Reset Password" end end @@ -107,7 +107,7 @@ defmodule FgHttpWeb.PasswordResetControllerTest do ) assert get_flash(conn, :error) == "Error updating password." - assert html_response(conn, 200) =~ "Edit Password" + assert html_response(conn, 200) =~ "Reset Password" end end 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 4deb258a4..d03de7def 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 @@ -7,7 +7,7 @@ defmodule FgHttpWeb.RuleControllerTest do destination: "1.1.1.1", port_number: 53, protocol: "udp", - action: "accept" + action: "allow" } @invalid_create_attrs %{ destination: "problem"