Checkpoint

This commit is contained in:
Jamil Bou Kheir
2020-10-09 10:07:36 -05:00
parent ecf4525916
commit cb27f6da71
19 changed files with 135 additions and 111 deletions

View File

@@ -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

View File

@@ -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, [

View File

@@ -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

View File

@@ -37,7 +37,7 @@ Endpoint = <%= Application.fetch_env!(:fg_http, :vpn_endpoint) %>
</h6>
<p>
<%= link "Back to Devices", to: Routes.device_path(@socket, :index), class: "button" %>
<%= link "Back to Devices", to: Routes.device_path(@socket, :index) %>
</p>
<% else %>
<h4 class="subtitle is-4">Device connected!</h4>
@@ -53,7 +53,7 @@ Endpoint = <%= Application.fetch_env!(:fg_http, :vpn_endpoint) %>
<div class="level">
<div class="level-left">
<%=
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))
%>
</div>
<div class="level-right">

View File

@@ -21,7 +21,7 @@
<div class="control">
<div class="level">
<div class="level-left">
<%= link "Back", to: Routes.device_path(@conn, :index), class: "button" %>
<%= link "Back", to: Routes.device_path(@conn, :index) %>
</div>
<div class="level-right">
<%= submit "Save", class: "button is-primary" %>

View File

@@ -31,4 +31,4 @@
</table>
</div>
<%= link "New Device", to: Routes.device_path(@conn, :new), class: "button is-primary" %>
<%= link "New Device", to: Routes.device_path(@conn, :new) %>

View File

@@ -2,10 +2,14 @@
<h3>Show Device</h3>
<dl>
<dt>Name:</dt>
<dt>
<strong>Name:</strong>
</dt>
<dd><%= @device.name %></dd>
<dt>Public key:</dt>
<dt>
<strong>Public key:</strong>
</dt>
<dd><%= @device.public_key %></dd>
</dl>

View File

@@ -1,5 +1,5 @@
<%= unless is_nil(get_flash(@conn, :info)) and is_nil(get_flash(@conn, :error)) do %>
<div class="container">
<div class="container flash-squeeze">
<%= if get_flash(@conn, :info) do %>
<div class="notification is-info">
<div class="flash-info">

View File

@@ -1,55 +1,42 @@
<h1>Edit Password</h1>
<div class="columns">
<div class="column is-4 is-offset-4">
<h3 class="title">Reset Password</h3>
<hr>
<%= 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 %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<div class="field is-horizontal">
<div class="field-label is-normal">
<%= label f, :password %>
</div>
<div class="field-body">
<div class="field">
<p class="control">
<%= text_input f, :password, placeholder: "Password" %>
</p>
</div>
<div class="field">
<p class="control">
<%= label(f, :password, class: "label") %>
<div class="control">
<%= password_input(f, :password, class: "input",placeholder: "New Password")%>
</div>
<p class="help is-danger">
<%= error_tag f, :password %>
</p>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-normal">
<%= label f, :password_confirmation %>
</div>
<div class="field-body">
<div class="field">
<p class="control">
<%= text_input f, :password_confirmation, placeholder: "Password Confirmation" %>
</p>
</div>
<div class="field">
<p class="control">
<%= label(f, :password_confirmation, class: "label") %>
<div class="control">
<%= password_input(f, :password_confirmation, class: "input",placeholder: "New Password")%>
</div>
<p class="help is-danger">
<%= error_tag f, :password_confirmation %>
</p>
</div>
</div>
</div>
<div>
<%= submit "Submit" %>
<div class="field">
<div class="control">
<%= submit "Submit", class: "button is-primary" %>
</div>
</div>
<% end %>
</div>
<% end %>
<span>
<%= link "Back", to: Routes.session_path(@conn, :new) %>
</span>
</div>

View File

@@ -1,19 +1,29 @@
<h1>Reset Password</h1>
<div class="columns">
<div class="column is-4 is-offset-4">
<h3 class="title">Request Password Reset Link</h3>
<hr>
<%= form_for @changeset, Routes.password_reset_path(@conn, :create), fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<%= form_for @changeset, Routes.password_reset_path(@conn, :create), fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<%= label f, :email %>
<%= text_input f, :email %>
<%= error_tag f, :email %>
<div class="field">
<%= label(f, :email, class: "label") %>
<div class="control">
<%= text_input(f, :email, class: "input") %>
</div>
<p class="help is-danger">
<%= error_tag f, :email %>
</p>
</div>
<div>
<%= submit "Submit" %>
<div class="level">
<%= link "Back", to: Routes.session_path(@conn, :new) %>
<%= submit "Submit", class: "button is-primary" %>
</div>
<% end %>
</div>
<% end %>
<span><%= link "Back", to: Routes.session_path(@conn, :new) %></span>
</div>

View File

@@ -60,6 +60,11 @@
<p class="help is-danger">
<%= error_tag f, :priority %>
</p>
<p class="help is-info">
<span class="help-block">
Higher numbers indicate higher priority.
</span>
</p>
</div>
<div class="field">
@@ -72,17 +77,9 @@
</p>
</div>
<div class="field">
<div class="control">
<div class="level">
<div class="level-left">
<%= link "Back", to: Routes.device_rule_path(@conn, :index, @device), class: "button" %>
</div>
<div class="level-right">
<%= submit "Save", class: "button is-primary" %>
</div>
</div>
</div>
<div class="level">
<%= link "Back", to: Routes.device_rule_path(@conn, :index, @device) %>
<%= submit "Save", class: "button is-primary" %>
</div>
<% end %>
</div>

View File

@@ -9,7 +9,7 @@
<th>Port Number</th>
<th>Protocol</th>
<th>Priority</th>
<th>Enabled</th>
<th>Status</th>
<th></th>
</tr>
@@ -19,10 +19,10 @@
<tr>
<td><%= rule.action %></td>
<td><%= rule.destination %></td>
<td><%= rule.port_number %></td>
<td><%= port_number_helper(rule) %></td>
<td><%= rule.protocol %></td>
<td><%= rule.priority %></td>
<td><%= rule.enabled %></td>
<td><%= status_helper(rule) %></td>
<td class="has-text-right">
<span><%= link "Show", to: Routes.rule_path(@conn, :show, rule) %></span>
|
@@ -36,8 +36,13 @@
</table>
</div>
<%=
link "New Rule",
to: Routes.device_rule_path(@conn, :new, @device),
class: "button is-primary"
%>
<div class="level">
<%=
link "Back to Devices",
to: Routes.device_path(@conn, :index)
%>
<%=
link "New Rule",
to: Routes.device_rule_path(@conn, :new, @device)
%>
</div>

View File

@@ -1,28 +1,32 @@
<div class="content">
<h3>Show Rule</h3>
<div class="columns">
<div class="column is-4">
<div class="content">
<h3>Show Rule</h3>
<dl>
<dt><strong>Action:</strong></dt>
<dd><%= @rule.action %></dd>
<dl>
<dt><strong>Action:</strong></dt>
<dd><%= @rule.action %></dd>
<dt><strong>Destination:</strong></dt>
<dd><%= @rule.destination %></dd>
<dt><strong>Destination:</strong></dt>
<dd><%= @rule.destination %></dd>
<dt><strong>Port Number:</strong></dt>
<dd><%= @rule.port_number %></dd>
<dt><strong>Port Number:</strong></dt>
<dd><%= port_number_helper(@rule) %></dd>
<dt><strong>Protocol:</strong></dt>
<dd><%= @rule.protocol %></dd>
<dt><strong>Protocol:</strong></dt>
<dd><%= @rule.protocol %></dd>
<dt><strong>Priority:</strong></dt>
<dd><%= @rule.priority %></dd>
<dt><strong>Priority:</strong></dt>
<dd><%= @rule.priority %></dd>
<dt><strong>Enabled:</strong></dt>
<dd><%= @rule.enabled %></dd>
</dl>
<dt><strong>Enabled:</strong></dt>
<dd><%= @rule.enabled %></dd>
</dl>
<div class="level">
<%= 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" %>
<div class="level">
<%= link "Back", to: Routes.device_rule_path(@conn, :index, @rule.device_id) %>
<%= link "Edit", to: Routes.rule_path(@conn, :edit, @rule) %>
</div>
</div>
</div>
</div>

View File

@@ -55,7 +55,7 @@
<div class="control">
<div class="level">
<div class="level-left">
<%= link "Back", to: Routes.user_path(@conn, :show), class: "button" %>
<%= link "Back", to: Routes.user_path(@conn, :show) %>
</div>
<div class="level-right">
<%= submit "Save", class: "button is-primary" %>

View File

@@ -14,7 +14,7 @@
</dl>
<div class="level">
<%= 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,

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"