Rename fireguard -> cloudfire

This commit is contained in:
Jamil Bou Kheir
2021-06-28 08:44:03 -07:00
parent 92ea6e3a9a
commit cdb719fe74
345 changed files with 616 additions and 618 deletions

View File

@@ -16,7 +16,7 @@ Read this guide before opening a pull request.
## Prerequisites
You'll need the following software installed to develop for FireGuard:
You'll need the following software installed to develop for CloudFire:
- [Vagrant](vagrantup.com)
- [Ansible](ansible.com)
@@ -28,11 +28,11 @@ You'll need the following software installed to develop for FireGuard:
## Project Setup
1. Ensure Postgres is running with a superuser role of `fireguard`. E.g.
1. Ensure Postgres is running with a superuser role of `cloudfire`. E.g.
```
$ psql -h localhost -d postgres
> CREATE ROLE fireguard;
> CREATE ROLE cloudfire;
```
2. Install the language versions defined in `.tool-versions`:
```
@@ -42,7 +42,7 @@ You'll need the following software installed to develop for FireGuard:
3. Resolve dependencies
```
$ mix deps.get
$ npm install --prefix apps/fg_http/assets
$ npm install --prefix apps/cf_http/assets
```
4. Bootstrap DB
```

View File

@@ -1,12 +1,12 @@
![Test](https://github.com/CloudFire-LLC/fireguard/workflows/Test/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/CloudFire-LLC/fireguard/badge.svg?branch=master)](https://coveralls.io/github/CloudFire-LLC/fireguard?branch=master)
![Test](https://github.com/CloudFire-LLC/cloudfire/workflows/Test/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/CloudFire-LLC/cloudfire/badge.svg?branch=master)](https://coveralls.io/github/CloudFire-LLC/cloudfire?branch=master)
**Warning**: This project is under active development and is not secure at the moment.
Do not attempt to use this software in any production capacity until this notice is removed.
You have been warned.
# FireGuard
# CloudFire
1. [Intro](#intro)
2. [Architecture](#architecture)
@@ -16,11 +16,11 @@ You have been warned.
## Intro
FireGuard is a host-it-yourself VPN and firewall configurable through a Web UI.
CloudFire is a host-it-yourself VPN and firewall configurable through a Web UI.
It aims to be a simple way to setup a VPN and optional firewall for all your
devices.
Use FireGuard to:
Use CloudFire to:
- Set up your own VPN
- Block, inspect, or capture outgoing traffic from your phone / tablet /
@@ -28,19 +28,19 @@ Use FireGuard to:
## Architecture
FireGuard is written in the Elixir programming language and composed as an [Umbrella
CloudFire is written in the Elixir programming language and composed as an [Umbrella
project](https://elixir-lang.org/getting-started/mix-otp/dependencies-and-umbrella-projects.html)
consisting of three Elixir packages:
- [apps/fg_http](apps/fg_http): The Web Application
- [apps/fg_wall](apps/fg_wall): Firewall Management Process
- [apps/fg_vpn](apps/fg_vpn): WireGuard™ Management Process
- [apps/cf_http](apps/cf_http): The Web Application
- [apps/cf_wall](apps/cf_wall): Firewall Management Process
- [apps/cf_vpn](apps/cf_vpn): WireGuard™ Management Process
For now, FireGuard assumes these apps are all running on the same host.
For now, CloudFire assumes these apps are all running on the same host.
## Setup
Currently, the only supported method of running FireGuard is locally. MacOS and
Currently, the only supported method of running CloudFire is locally. MacOS and
Linux users shouldn't have any problems. Windows will Probably Work™.
You'll need recent versions of the following tools installed:
@@ -57,18 +57,18 @@ vagrant up
```
This will download the VM base box, provision it with dependencies, bootstrap
the FireGuard DB, launch the FireGuard Services, and print instructions for
the CloudFire DB, launch the CloudFire Services, and print instructions for
connecting to the Web UI.
## Creating Additional Users
FireGuard creates the first user for you upon installation and prints the
CloudFire creates the first user for you upon installation and prints the
credentials after `vagrant up` completes in the step above.
You may create additional users with the following command:
```bash
sudo -u fireguard /opt/fireguard/bin/fireguard rpc 'FgHttp.Users.create_user(
sudo -u cloudfire /opt/cloudfire/bin/cloudfire rpc 'CfHttp.Users.create_user(
email: "USER_EMAIL",
password: "USER_PASSWORD",
password_confirmation: "USER_PASSWORD"

2
Vagrantfile vendored
View File

@@ -7,7 +7,7 @@ Vagrant.configure('2') do |config|
end
config.vm.box = 'ubuntu/focal64'
config.vm.hostname = 'fireguard.local'
config.vm.hostname = 'cloudfire.local'
# Web
config.vm.network 'forwarded_port', guest: 8800, host: 8800, protocol: 'tcp'

View File

@@ -59,41 +59,41 @@
line: 'net.ipv6.conf.all.forwarding = 1'
- name: apply sysctl
shell: sysctl -p
- name: Build FireGuard
- name: Build CloudFire
hosts: all
tasks:
- name: Copy Project
shell: |
rsync --delete -avz --exclude '_build' --exclude 'deps' /vagrant/* /home/vagrant/fireguard/
rsync --delete -avz --exclude '_build' --exclude 'deps' /vagrant/* /home/vagrant/cloudfire/
- name: Compile Release
become: no
environment:
MIX_ENV: prod
shell: |
cd /home/vagrant/fireguard
cd /home/vagrant/cloudfire
scripts/build_release.sh
- name: Build Debian Package
become: no
shell: |
cd /home/vagrant/fireguard
cd /home/vagrant/cloudfire
scripts/build_deb.sh
- name: Install FireGuard deb
- name: Install CloudFire deb
become: yes
shell: |
cd /home/vagrant/fireguard
dpkg -i fireguard_amd64.deb
cd /home/vagrant/cloudfire
dpkg -i cloudfire_amd64.deb
- name: Enable systemd units
become: yes
shell: |
systemctl enable fireguard
systemctl enable cloudfire
- name: Start systemd units
become: yes
shell: |
systemctl start fireguard
systemctl start cloudfire
- name: Capture user credentials
become: yes
shell: |
journalctl -u fireguard
journalctl -u cloudfire
register: create_user
- name: Display user credentials
debug: msg="{{ create_user.stdout_lines }}"

View File

@@ -1,20 +1,20 @@
# FgCommon
# CfCommon
**TODO: Add description**
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `fg_common` to your list of dependencies in `mix.exs`:
by adding `cf_common` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:fg_common, "~> 0.1.0"}
{:cf_common, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/fg_common](https://hexdocs.pm/fg_common).
be found at [https://hexdocs.pm/cf_common](https://hexdocs.pm/cf_common).

View File

@@ -0,0 +1,5 @@
defmodule CfCommon do
@moduledoc """
Documentation for `CfCommon`.
"""
end

View File

@@ -1,4 +1,4 @@
defmodule FgCommon.FgCrypto do
defmodule CfCommon.CfCrypto do
@moduledoc """
Utilities for working with crypto functions
"""

View File

@@ -1,4 +1,4 @@
defmodule FgCommon.FgMap do
defmodule CfCommon.CfMap do
@moduledoc """
Utilities for working with Maps
"""

View File

@@ -1,4 +1,4 @@
defmodule FgCommon.FgNet do
defmodule CfCommon.CfNet do
@moduledoc """
Network utility functions.
"""

View File

@@ -1,4 +1,4 @@
defmodule FgCommon.CLI do
defmodule CfCommon.CLI do
@moduledoc """
Handles low-level CLI facilities.
"""
@@ -15,7 +15,7 @@ defmodule FgCommon.CLI do
{error, _} ->
raise """
Error executing command #{cmd} with error #{error}.
FireGuard cannot recover from this error.
CloudFire cannot recover from this error.
"""
end
end

View File

@@ -1,4 +1,4 @@
defmodule FgCommon.NameGenerator do
defmodule CfCommon.NameGenerator do
@moduledoc """
Generates random human-readable name
"""

View File

@@ -1,9 +1,9 @@
defmodule FgCommon.MixProject do
defmodule CfCommon.MixProject do
use Mix.Project
def project do
[
app: :fg_common,
app: :cf_common,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",

View File

@@ -0,0 +1,4 @@
defmodule CfCommonTest do
use ExUnit.Case
doctest CfCommon
end

View File

@@ -1,16 +1,16 @@
defmodule FgCommon.FgCryptoTest do
defmodule CfCommon.CfCryptoTest do
use ExUnit.Case, async: true
alias FgCommon.FgCrypto
alias CfCommon.CfCrypto
describe "rand_string" do
test "it returns a string of default length" do
assert 16 == String.length(FgCrypto.rand_string())
assert 16 == String.length(CfCrypto.rand_string())
end
test "it returns a string of proper length" do
for length <- [1, 32, 32_768] do
assert length == String.length(FgCrypto.rand_string(length))
assert length == String.length(CfCrypto.rand_string(length))
end
end
end

View File

@@ -1,13 +1,13 @@
defmodule FgCommon.FgMapTest do
defmodule CfCommon.CfMapTest do
use ExUnit.Case, async: true
alias FgCommon.FgMap
alias CfCommon.CfMap
describe "compact/1" do
@data %{foo: nil, bar: "hello"}
test "removes nil values" do
assert FgMap.compact(@data) == %{bar: "hello"}
assert CfMap.compact(@data) == %{bar: "hello"}
end
end
@@ -15,7 +15,7 @@ defmodule FgCommon.FgMapTest do
@data %{foo: "bar", bar: ""}
test "removes matched values" do
assert FgMap.compact(@data, "") == %{foo: "bar"}
assert CfMap.compact(@data, "") == %{foo: "bar"}
end
end
end

View File

@@ -1,19 +1,19 @@
defmodule FgCommon.FgNetTest do
defmodule CfCommon.CfNetTest do
use ExUnit.Case, async: true
alias FgCommon.FgNet
alias CfCommon.CfNet
describe "ip_type" do
test "it detects IPv4 addresses" do
assert FgNet.ip_type("127.0.0.1") == "IPv4"
assert CfNet.ip_type("127.0.0.1") == "IPv4"
end
test "it detects IPv6 addresses" do
assert FgNet.ip_type("::1") == "IPv6"
assert CfNet.ip_type("::1") == "IPv6"
end
test "it reports \"unknown\" for unknown type" do
assert FgNet.ip_type("invalid") == "unknown"
assert CfNet.ip_type("invalid") == "unknown"
end
end
end

View File

@@ -1,7 +1,7 @@
defmodule FgCommon.NameGeneratorTest do
defmodule CfCommon.NameGeneratorTest do
use ExUnit.Case, async: true
alias FgCommon.NameGenerator
alias CfCommon.NameGenerator
describe "generate/0" do
test "generates a name" do

3
apps/cf_http/README.md Normal file
View File

@@ -0,0 +1,3 @@
# CfHttp
Phoenix app for managing CloudFire.

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -1,6 +1,6 @@
defmodule FgHttp do
defmodule CfHttp do
@moduledoc """
FgHttp keeps the contexts that define your domain
CfHttp keeps the contexts that define your domain
and business logic.
Contexts are also responsible for managing your data, regardless

View File

@@ -1,4 +1,4 @@
defmodule FgHttp.Application do
defmodule CfHttp.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
@@ -7,32 +7,32 @@ defmodule FgHttp.Application do
def start(_type, _args) do
children =
case Application.get_env(:fg_http, :minimal) do
case Application.get_env(:cf_http, :minimal) do
true ->
[
FgHttp.Repo,
FgHttp.Vault
CfHttp.Repo,
CfHttp.Vault
]
_ ->
[
FgHttp.Repo,
FgHttp.Vault,
{Phoenix.PubSub, name: FgHttp.PubSub},
FgHttpWeb.Endpoint
CfHttp.Repo,
CfHttp.Vault,
{Phoenix.PubSub, name: CfHttp.PubSub},
CfHttpWeb.Endpoint
]
end
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: FgHttp.Supervisor]
opts = [strategy: :one_for_one, name: CfHttp.Supervisor]
Supervisor.start_link(children, opts)
end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
def config_change(changed, _new, removed) do
FgHttpWeb.Endpoint.config_change(changed, removed)
CfHttpWeb.Endpoint.config_change(changed, removed)
:ok
end
end

View File

@@ -1,11 +1,11 @@
defmodule FgHttp.Devices do
defmodule CfHttp.Devices do
@moduledoc """
The Devices context.
"""
import Ecto.Query, warn: false
alias FgCommon.NameGenerator
alias FgHttp.{Devices.Device, Repo, Users.User}
alias CfCommon.NameGenerator
alias CfHttp.{Devices.Device, Repo, Users.User}
def list_devices do
Repo.all(Device)

View File

@@ -1,4 +1,4 @@
defmodule FgHttp.Devices.Device do
defmodule CfHttp.Devices.Device do
@moduledoc """
Manages Device things
"""
@@ -6,14 +6,14 @@ defmodule FgHttp.Devices.Device do
use Ecto.Schema
import Ecto.Changeset
alias FgHttp.{Rules.Rule, Users.User}
alias CfHttp.{Rules.Rule, Users.User}
schema "devices" do
field :name, :string
field :public_key, :string
field :allowed_ips, :string
field :preshared_key, FgHttp.Encrypted.Binary
field :private_key, FgHttp.Encrypted.Binary
field :preshared_key, CfHttp.Encrypted.Binary
field :private_key, CfHttp.Encrypted.Binary
field :server_public_key, :string
field :remote_ip, EctoNetwork.INET
field :interface_address4, EctoNetwork.INET

View File

@@ -1,23 +1,23 @@
defmodule FgHttp.Email do
defmodule CfHttp.Email do
@moduledoc """
Handles Email for the app
"""
use Bamboo.Phoenix, view: FgHttpWeb.EmailView
alias FgHttp.Users.PasswordReset
use Bamboo.Phoenix, view: CfHttpWeb.EmailView
alias CfHttp.Users.PasswordReset
@from "noreply@#{Application.compile_env(:fg_http, FgHttpWeb.Endpoint)[:url][:host]}"
@from "noreply@#{Application.compile_env(:cf_http, CfHttpWeb.Endpoint)[:url][:host]}"
defp base_email(to) do
new_email()
|> put_html_layout({FgHttpWeb.LayoutView, "email.html"})
|> put_html_layout({CfHttpWeb.LayoutView, "email.html"})
|> from(@from)
|> to(to)
end
def password_reset(%PasswordReset{} = password_reset) do
base_email(password_reset.email)
|> subject("FireGuard password reset")
|> subject("CloudFire password reset")
|> assign(:reset_token, password_reset.reset_token)
|> render(:password_reset)
end

View File

@@ -0,0 +1,7 @@
defmodule CfHttp.Encrypted.Binary do
@moduledoc """
Configures how to encrpyt Binaries to the DB.
"""
use Cloak.Ecto.Binary, vault: CfHttp.Vault
end

View File

@@ -0,0 +1,7 @@
defmodule CfHttp.Mailer do
@moduledoc """
Mailer for the application
"""
use Bamboo.Mailer, otp_app: :cf_http
end

View File

@@ -1,12 +1,12 @@
defmodule FgHttp.PasswordResets do
defmodule CfHttp.PasswordResets do
@moduledoc """
The PasswordResets context.
"""
import Ecto.Query, warn: false
alias FgHttp.Repo
alias CfHttp.Repo
alias FgHttp.Users.PasswordReset
alias CfHttp.Users.PasswordReset
def get_password_reset(email: email) do
Repo.get_by(PasswordReset, email: email)

View File

@@ -1,12 +1,12 @@
defmodule FgHttp.Release do
defmodule CfHttp.Release do
@moduledoc """
Adds common tasks to the production app because Mix is not available.
"""
alias FgHttp.{Repo, Users, Users.User}
alias CfHttp.{Repo, Users, Users.User}
require Logger
@app :fg_http
@app :cf_http
def gen_secret(length) when length > 31 do
IO.puts(secret(length))
@@ -73,10 +73,10 @@ defmodule FgHttp.Release do
)
Logger.info(
"FireGuard user created! Save this information because it will NOT be shown again."
"CloudFire user created! Save this information because it will NOT be shown again."
)
Logger.info("Use this to log into the Web UI at #{FgHttpWeb.Endpoint.url()}.")
Logger.info("Use this to log into the Web UI at #{CfHttpWeb.Endpoint.url()}.")
Logger.info("Email: #{email}")
Logger.info("Password: #{password}")

View File

@@ -1,10 +1,10 @@
defmodule FgHttp.Repo do
defmodule CfHttp.Repo do
use Ecto.Repo,
otp_app: :fg_http,
otp_app: :cf_http,
adapter: Ecto.Adapters.Postgres
require Logger
import FgHttpWeb.Events
import CfHttpWeb.Events
def init(_) do
# Set firewall rules

View File

@@ -1,13 +1,13 @@
defmodule FgHttp.Rules do
defmodule CfHttp.Rules do
@moduledoc """
The Rules context.
"""
import Ecto.Query, warn: false
alias CfCommon.CfNet
alias EctoNetwork.INET
alias FgCommon.FgNet
alias FgHttp.{Devices.Device, Repo, Rules.Rule}
alias CfHttp.{Devices.Device, Repo, Rules.Rule}
def get_rule!(id), do: Repo.get!(Rule, id)
@@ -41,10 +41,10 @@ defmodule FgHttp.Rules do
device = Repo.preload(rule, :device).device
dest = decode(rule.destination)
# I pass INET.decode as a function to FgNet so that I don't need
# to include ecto_network as a dependency in FgCommon.
# I pass INET.decode as a function to CfNet so that I don't need
# to include ecto_network as a dependency in CfCommon.
source =
case FgNet.ip_type(dest) do
case CfNet.ip_type(dest) do
"IPv6" -> device.interface_address6
"IPv4" -> device.interface_address4
_ -> nil

View File

@@ -1,4 +1,4 @@
defmodule FgHttp.Rules.Rule do
defmodule CfHttp.Rules.Rule do
@moduledoc """
Not really sure what to write here. I'll update this later.
"""
@@ -6,7 +6,7 @@ defmodule FgHttp.Rules.Rule do
use Ecto.Schema
import Ecto.Changeset
alias FgHttp.{Devices.Device}
alias CfHttp.{Devices.Device}
@rule_dupe_msg "A rule with that IP/CIDR address already exists."

View File

@@ -1,12 +1,12 @@
defmodule FgHttp.Sessions do
defmodule CfHttp.Sessions do
@moduledoc """
The Sessions context.
"""
import Ecto.Query, warn: false
alias FgHttp.Repo
alias CfHttp.Repo
alias FgHttp.Users.Session
alias CfHttp.Users.Session
@doc """
Gets a single session.

View File

@@ -1,13 +1,13 @@
defmodule FgHttp.Users do
defmodule CfHttp.Users do
@moduledoc """
The Users context.
"""
import Ecto.Query, warn: false
alias FgHttp.Repo
alias CfHttp.Repo
alias FgCommon.FgCrypto
alias FgHttp.Users.User
alias CfCommon.CfCrypto
alias CfHttp.Users.User
# one hour
@sign_in_token_validity_secs 3600
@@ -41,7 +41,7 @@ defmodule FgHttp.Users do
def sign_in_keys do
%{
sign_in_token: FgCrypto.rand_string(),
sign_in_token: CfCrypto.rand_string(),
sign_in_token_created_at: DateTime.utc_now()
}
end

View File

@@ -1,4 +1,4 @@
defmodule FgHttp.Users.PasswordHelpers do
defmodule CfHttp.Users.PasswordHelpers do
@moduledoc """
Helpers for validating changesets with passwords
"""

View File

@@ -1,13 +1,13 @@
defmodule FgHttp.Users.PasswordReset do
defmodule CfHttp.Users.PasswordReset do
@moduledoc """
Schema for PasswordReset
"""
use Ecto.Schema
import Ecto.Changeset
import FgHttp.Users.PasswordHelpers
import CfHttp.Users.PasswordHelpers
alias FgCommon.FgCrypto
alias CfCommon.CfCrypto
@token_num_bytes 8
# 1 day
@@ -61,7 +61,7 @@ defmodule FgHttp.Users.PasswordReset do
def token_validity_secs, do: @token_validity_secs
defp generate_reset_token(%Ecto.Changeset{valid?: true} = changeset) do
put_change(changeset, :reset_token, FgCrypto.rand_token(@token_num_bytes))
put_change(changeset, :reset_token, CfCrypto.rand_token(@token_num_bytes))
end
defp clear_token_fields(

View File

@@ -1,11 +1,11 @@
defmodule FgHttp.Users.Session do
defmodule CfHttp.Users.Session do
@moduledoc """
Represents a Session
"""
use Ecto.Schema
import Ecto.Changeset
alias FgHttp.{Users, Users.User}
alias CfHttp.{Users, Users.User}
schema "users" do
field :email, :string

View File

@@ -1,14 +1,14 @@
defmodule FgHttp.Users.User do
defmodule CfHttp.Users.User do
@moduledoc """
Represents a User I guess
"""
use Ecto.Schema
import Ecto.Changeset
import FgHttp.Users.PasswordHelpers
import CfHttp.Users.PasswordHelpers
alias FgCommon.FgMap
alias FgHttp.Devices.Device
alias CfCommon.CfMap
alias CfHttp.Devices.Device
schema "users" do
field :email, :string
@@ -69,14 +69,14 @@ defmodule FgHttp.Users.User do
"current_password" => nil
} = attrs
) do
update_changeset(user, FgMap.compact(attrs))
update_changeset(user, CfMap.compact(attrs))
end
def update_changeset(
user,
%{"password" => "", "password_confirmation" => "", "current_password" => ""} = attrs
) do
update_changeset(user, FgMap.compact(attrs, ""))
update_changeset(user, CfMap.compact(attrs, ""))
end
def update_changeset(

View File

@@ -0,0 +1,7 @@
defmodule CfHttp.Vault do
@moduledoc """
Manages encrypted DB fields.
"""
use Cloak.Vault, otp_app: :cf_http
end

View File

@@ -1,12 +1,12 @@
defmodule FgHttpWeb do
defmodule CfHttpWeb do
@moduledoc """
The entrypoint for defining your web interface, such
as controllers, views, channels and so on.
This can be used in your application as:
use FgHttpWeb, :controller
use FgHttpWeb, :view
use CfHttpWeb, :controller
use CfHttpWeb, :view
The definitions below will be executed for every view,
controller, etc, so keep them short and clean, focused
@@ -19,20 +19,20 @@ defmodule FgHttpWeb do
def controller do
quote do
use Phoenix.Controller, namespace: FgHttpWeb
use Phoenix.Controller, namespace: CfHttpWeb
import Plug.Conn
import FgHttpWeb.Gettext
import CfHttpWeb.Gettext
import Phoenix.LiveView.Controller
alias FgHttpWeb.Router.Helpers, as: Routes
alias CfHttpWeb.Router.Helpers, as: Routes
end
end
def view do
quote do
use Phoenix.View,
root: "lib/fg_http_web/templates",
namespace: FgHttpWeb
root: "lib/cf_http_web/templates",
namespace: CfHttpWeb
# Import convenience functions from controllers
import Phoenix.Controller, only: [get_flash: 1, get_flash: 2, view_module: 1]
@@ -40,23 +40,23 @@ defmodule FgHttpWeb do
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
import FgHttpWeb.ErrorHelpers
import FgHttpWeb.Gettext
import CfHttpWeb.ErrorHelpers
import CfHttpWeb.Gettext
import Phoenix.LiveView.Helpers
alias FgHttpWeb.Router.Helpers, as: Routes
alias CfHttpWeb.Router.Helpers, as: Routes
def render_common(template, assigns \\ []) do
render(FgHttpWeb.CommonView, template, assigns)
render(CfHttpWeb.CommonView, template, assigns)
end
end
end
def live_view do
quote do
use Phoenix.LiveView, layout: {FgHttpWeb.LayoutView, "live.html"}
import FgHttpWeb.LiveHelpers
use Phoenix.LiveView, layout: {CfHttpWeb.LayoutView, "live.html"}
import CfHttpWeb.LiveHelpers
@events_module Application.compile_env(:fg_http, :events_module)
@events_module Application.compile_env(:cf_http, :events_module)
unquote(view_helpers())
end
@@ -82,7 +82,7 @@ defmodule FgHttpWeb do
def channel do
quote do
use Phoenix.Channel
import FgHttpWeb.Gettext
import CfHttpWeb.Gettext
end
end
@@ -97,9 +97,9 @@ defmodule FgHttpWeb do
# Import basic rendering functionality (render, render_layout, etc)
import Phoenix.View
import FgHttpWeb.ErrorHelpers
import FgHttpWeb.Gettext
alias FgHttpWeb.Router.Helpers, as: Routes
import CfHttpWeb.ErrorHelpers
import CfHttpWeb.Gettext
alias CfHttpWeb.Router.Helpers, as: Routes
end
end

View File

@@ -1,8 +1,8 @@
defmodule FgHttpWeb.UserSocket do
defmodule CfHttpWeb.UserSocket do
use Phoenix.Socket
## Channels
# channel "room:*", FgHttpWeb.RoomChannel
# channel "room:*", CfHttpWeb.RoomChannel
# Socket params are passed from the client and can
# be used to verify and authenticate a user. After
@@ -26,7 +26,7 @@ defmodule FgHttpWeb.UserSocket do
# Would allow you to broadcast a "disconnect" event and terminate
# all active sockets and channels for a given user:
#
# FgHttpWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
# CfHttpWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
#
# Returning `nil` makes this socket anonymous.
def id(_socket), do: nil

View File

@@ -1,10 +1,10 @@
defmodule FgHttpWeb.SessionController do
defmodule CfHttpWeb.SessionController do
@moduledoc """
Implements the CRUD for a Session
"""
alias FgHttp.Users
use FgHttpWeb, :controller
alias CfHttp.Users
use CfHttpWeb, :controller
# GET /sign_in/:token
def create(conn, %{"token" => token}) do

View File

@@ -1,10 +1,10 @@
defmodule FgHttpWeb.UserController do
defmodule CfHttpWeb.UserController do
@moduledoc """
Implements synchronous User requests.
"""
alias FgHttp.Users
use FgHttpWeb, :controller
alias CfHttp.Users
use CfHttpWeb, :controller
plug :redirect_unauthenticated

View File

@@ -1,20 +1,20 @@
defmodule FgHttpWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :fg_http
defmodule CfHttpWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :cf_http
# The session will be stored in the cookie and signed,
# this means its contents can be read but not tampered with.
# Set :encryption_salt if you would also like to encrypt it.
@session_options [
store: :cookie,
key: "_fg_http_key",
key: "_cf_http_key",
signing_salt: "Z9eq8iof"
]
if Application.get_env(:fg_http, :sql_sandbox) do
if Application.get_env(:cf_http, :sql_sandbox) do
plug Phoenix.Ecto.SQL.Sandbox
end
socket "/socket", FgHttpWeb.UserSocket,
socket "/socket", CfHttpWeb.UserSocket,
websocket: true,
longpoll: false
@@ -26,7 +26,7 @@ defmodule FgHttpWeb.Endpoint do
# when deploying your static files in production.
plug Plug.Static,
at: "/",
from: :fg_http,
from: :cf_http,
gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
@@ -36,7 +36,7 @@ defmodule FgHttpWeb.Endpoint do
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :fg_http
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :cf_http
end
plug Plug.RequestId
@@ -50,5 +50,5 @@ defmodule FgHttpWeb.Endpoint do
plug Plug.MethodOverride
plug Plug.Head
plug Plug.Session, @session_options
plug FgHttpWeb.Router
plug CfHttpWeb.Router
end

View File

@@ -1,9 +1,9 @@
defmodule FgHttpWeb.Events do
defmodule CfHttpWeb.Events do
@moduledoc """
Handles interfacing with other processes in the system.
"""
alias FgHttp.{Devices, Rules}
alias CfHttp.{Devices, Rules}
def create_device do
GenServer.call(vpn_pid(), :create_device)
@@ -30,10 +30,10 @@ defmodule FgHttpWeb.Events do
end
def vpn_pid do
:global.whereis_name(:fg_vpn_server)
:global.whereis_name(:cf_vpn_server)
end
def wall_pid do
:global.whereis_name(:fg_wall_server)
:global.whereis_name(:cf_wall_server)
end
end

View File

@@ -1,11 +1,11 @@
defmodule FgHttpWeb.Gettext do
defmodule CfHttpWeb.Gettext do
@moduledoc """
A module providing Internationalization with a gettext-based API.
By using [Gettext](https://hexdocs.pm/gettext),
your module gains a set of macros for translations, for example:
import FgHttpWeb.Gettext
import CfHttpWeb.Gettext
# Simple translation
gettext("Here is the string to translate")
@@ -20,5 +20,5 @@ defmodule FgHttpWeb.Gettext do
See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage.
"""
use Gettext, otp_app: :fg_http
use Gettext, otp_app: :cf_http
end

View File

@@ -1,10 +1,10 @@
defmodule FgHttpWeb.AccountLive.FormComponent do
defmodule CfHttpWeb.AccountLive.FormComponent do
@moduledoc """
Handles the edit account form.
"""
use FgHttpWeb, :live_component
use CfHttpWeb, :live_component
alias FgHttp.Users
alias CfHttp.Users
def update(assigns, socket) do
changeset = Users.change_user(assigns.user)

View File

@@ -1,6 +1,6 @@
<%= if @live_action == :edit do %>
<%= live_modal(
FgHttpWeb.AccountLive.FormComponent,
CfHttpWeb.AccountLive.FormComponent,
return_to: Routes.account_show_path(@socket, :show),
title: "Edit Account",
id: "user-#{@current_user.id}",

View File

@@ -1,10 +1,10 @@
defmodule FgHttpWeb.AccountLive.Show do
defmodule CfHttpWeb.AccountLive.Show do
@moduledoc """
Handles Account-related things.
"""
use FgHttpWeb, :live_view
use CfHttpWeb, :live_view
alias FgHttp.Users
alias CfHttp.Users
@impl true
def mount(params, session, socket) do

View File

@@ -1,10 +1,10 @@
defmodule FgHttpWeb.DeviceLive.FormComponent do
defmodule CfHttpWeb.DeviceLive.FormComponent do
@moduledoc """
Handles device form.
"""
use FgHttpWeb, :live_component
use CfHttpWeb, :live_component
alias FgHttp.Devices
alias CfHttp.Devices
def update(assigns, socket) do
changeset = Devices.change_device(assigns.device)

View File

@@ -1,10 +1,10 @@
defmodule FgHttpWeb.DeviceLive.Index do
defmodule CfHttpWeb.DeviceLive.Index do
@moduledoc """
Handles Device LiveViews.
"""
use FgHttpWeb, :live_view
use CfHttpWeb, :live_view
alias FgHttp.Devices
alias CfHttp.Devices
def mount(params, session, socket) do
{:ok, assign_defaults(params, session, socket, &load_data/2)}

View File

@@ -1,10 +1,10 @@
defmodule FgHttpWeb.DeviceLive.RuleListComponent do
defmodule CfHttpWeb.DeviceLive.RuleListComponent do
@moduledoc """
Manages the Allowlist view.
"""
use FgHttpWeb, :live_component
use CfHttpWeb, :live_component
alias FgHttp.Rules
alias CfHttp.Rules
@impl true
def update(assigns, socket) do

View File

@@ -1,6 +1,6 @@
<%= if @live_action == :edit do %>
<%= live_modal(
FgHttpWeb.DeviceLive.FormComponent,
CfHttpWeb.DeviceLive.FormComponent,
return_to: Routes.device_show_path(@socket, :show, @device),
title: "Edit #{@device.name}",
id: "device-#{@device.id}",
@@ -75,7 +75,7 @@
<div class="tile is-child box">
<%= live_component(
@socket,
FgHttpWeb.DeviceLive.RuleListComponent,
CfHttpWeb.DeviceLive.RuleListComponent,
title: "Allowlist",
id: :allowlist,
current_user: @current_user,
@@ -102,7 +102,7 @@ DNS = 1.1.1.1, 1.0.0.1
PublicKey = <%= @device.server_public_key %>
PresharedKey = <%= @device.preshared_key %>
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = <%= Application.fetch_env!(:fg_http, :vpn_endpoint) %></code></pre>
Endpoint = <%= Application.fetch_env!(:cf_http, :vpn_endpoint) %></code></pre>
<h6 class="is-6 title">
Or scan the QR code with your mobile phone:
</h6>
@@ -115,7 +115,7 @@ Endpoint = <%= Application.fetch_env!(:fg_http, :vpn_endpoint) %></code></pre>
<div class="tile is-child box">
<%= live_component(
@socket,
FgHttpWeb.DeviceLive.RuleListComponent,
CfHttpWeb.DeviceLive.RuleListComponent,
title: "Denylist",
id: :denylist,
current_user: @current_user,

View File

@@ -1,10 +1,10 @@
defmodule FgHttpWeb.DeviceLive.Show do
defmodule CfHttpWeb.DeviceLive.Show do
@moduledoc """
Handles Device LiveViews.
"""
use FgHttpWeb, :live_view
use CfHttpWeb, :live_view
alias FgHttp.Devices
alias CfHttp.Devices
@impl true
def mount(params, session, socket) do

View File

@@ -1,8 +1,8 @@
defmodule FgHttpWeb.ModalComponent do
defmodule CfHttpWeb.ModalComponent do
@moduledoc """
Wraps a component in a modal.
"""
use FgHttpWeb, :live_component
use CfHttpWeb, :live_component
@impl true
def render(assigns) do

View File

@@ -1,10 +1,10 @@
defmodule FgHttpWeb.PasswordResetLive.Edit do
defmodule CfHttpWeb.PasswordResetLive.Edit do
@moduledoc """
Handles PasswordReset Live Views.
"""
use FgHttpWeb, :live_view
use CfHttpWeb, :live_view
alias FgHttp.PasswordResets
alias CfHttp.PasswordResets
def mount(%{"reset_token" => reset_token}, _session, socket) do
changeset =

View File

@@ -1,10 +1,10 @@
defmodule FgHttpWeb.PasswordResetLive.New do
defmodule CfHttpWeb.PasswordResetLive.New do
@moduledoc """
Handles PasswordReset Live Views.
"""
use FgHttpWeb, :live_view
use CfHttpWeb, :live_view
alias FgHttp.{Email, Mailer, PasswordResets}
alias CfHttp.{Email, Mailer, PasswordResets}
def mount(_params, _session, socket) do
changeset = PasswordResets.new_password_reset()

View File

@@ -1,8 +1,8 @@
defmodule FgHttpWeb.RootLive.Index do
defmodule CfHttpWeb.RootLive.Index do
@moduledoc """
The Root view; redirects to devices or sign in based on session.
"""
use FgHttpWeb, :live_view
use CfHttpWeb, :live_view
def mount(_params, %{"user_id" => _user_id}, socket) do
{:ok, redirect(socket, to: Routes.device_index_path(socket, :index))}

View File

@@ -40,7 +40,7 @@
<hr>
<div class="level">
<%= unless Application.get_env(:fg_http, :disable_signup) do %>
<%= unless Application.get_env(:cf_http, :disable_signup) do %>
<%= live_redirect("Sign up", to: Routes.user_new_path(@socket, :new)) %>
<% end %>
<%= live_redirect("Forgot your password?", to: Routes.password_reset_new_path(@socket, :new)) %>

View File

@@ -1,11 +1,11 @@
defmodule FgHttpWeb.SessionLive.New do
defmodule CfHttpWeb.SessionLive.New do
@moduledoc """
Handles sign in.
"""
use FgHttpWeb, :live_view
use CfHttpWeb, :live_view
alias FgCommon.FgMap
alias FgHttp.{Sessions, Users}
alias CfCommon.CfMap
alias CfHttp.{Sessions, Users}
def mount(_params, _session, socket) do
changeset = Sessions.new_session()
@@ -69,10 +69,10 @@ defmodule FgHttpWeb.SessionLive.New do
end
defp signups_disabled? do
Application.fetch_env!(:fg_http, :disable_signup)
Application.fetch_env!(:cf_http, :disable_signup)
end
defp sign_in_params do
FgMap.stringify_keys(Users.sign_in_keys())
CfMap.stringify_keys(Users.sign_in_keys())
end
end

View File

@@ -1,10 +1,10 @@
defmodule FgHttpWeb.UserLive.New do
defmodule CfHttpWeb.UserLive.New do
@moduledoc """
LiveView for user sign up.
"""
use FgHttpWeb, :live_view
use CfHttpWeb, :live_view
alias FgHttp.Users
alias CfHttp.Users
def mount(_params, _session, socket) do
changeset = Users.new_user()

View File

@@ -1,10 +1,10 @@
defmodule FgHttpWeb.MockEvents do
defmodule CfHttpWeb.MockEvents do
@moduledoc """
A Mock module for testing external events
XXX: This is used because FgHttp tests will launch multiple FgVpn servers.
Instead, we should find a way to maintain a persistent link to one FgVpn server
inside FgHttp and use that for the tests.
XXX: This is used because CfHttp tests will launch multiple CfVpn servers.
Instead, we should find a way to maintain a persistent link to one CfVpn server
inside CfHttp and use that for the tests.
"""
def create_device do

View File

@@ -1,9 +1,9 @@
defmodule FgHttpWeb.Router do
defmodule CfHttpWeb.Router do
@moduledoc """
Main Application Router
"""
use FgHttpWeb, :router
use CfHttpWeb, :router
# View emails locally in development
if Mix.env() == :dev do
@@ -14,7 +14,7 @@ defmodule FgHttpWeb.Router do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, {FgHttpWeb.LayoutView, :root}
plug :put_root_layout, {CfHttpWeb.LayoutView, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
end
@@ -23,7 +23,7 @@ defmodule FgHttpWeb.Router do
plug :accepts, ["json"]
end
scope "/", FgHttpWeb do
scope "/", CfHttpWeb do
pipe_through :browser
live "/sign_in", SessionLive.New, :new

View File

@@ -1,5 +1,5 @@
<%= link(
"Click here to reset your password.",
to: Routes.password_reset_edit_url(FgHttpWeb.Endpoint, :edit, @reset_token)
to: Routes.password_reset_edit_url(CfHttpWeb.Endpoint, :edit, @reset_token)
)
%>

View File

@@ -1,3 +1,3 @@
Copy and paste the following URL into your browser to reset your password:
<%= Routes.password_reset_edit_url(FgHttpWeb.Endpoint, :edit, @reset_token) %>
<%= Routes.password_reset_edit_url(CfHttpWeb.Endpoint, :edit, @reset_token) %>

View File

@@ -1,6 +1,6 @@
<html>
<head>
<link rel="stylesheet" href="<%= Routes.static_path(FgHttpWeb.Endpoint, "/css/email.css") %>">
<link rel="stylesheet" href="<%= Routes.static_path(CfHttpWeb.Endpoint, "/css/email.css") %>">
</head>
<body>
<%= @inner_content %>

View File

@@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<%= csrf_meta_tag() %>
<%= live_title_tag assigns[:page_title] || "FireGuard" %>
<%= live_title_tag assigns[:page_title] || "CloudFire" %>
<link phx-track-static rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
<script defer phx-track-static type="text/javascript" src="<%= Routes.static_path(@conn, "/js/app.js") %>"></script>
</head>
@@ -14,7 +14,7 @@
<div class="container">
<div class="navbar-brand">
<h4 class="title is-4 navbar-item">
FireGuard
CloudFire
</h4>
</div>
<div class="navbar-menu">

View File

@@ -0,0 +1,3 @@
defmodule CfHttpWeb.EmailView do
use CfHttpWeb, :view
end

View File

@@ -1,4 +1,4 @@
defmodule FgHttpWeb.ErrorHelpers do
defmodule CfHttpWeb.ErrorHelpers do
@moduledoc """
Conveniences for translating and building error messages.
"""
@@ -51,9 +51,9 @@ defmodule FgHttpWeb.ErrorHelpers do
# should be written to the errors.po file. The :count option is
# set by Ecto and indicates we should also apply plural rules.
if count = opts[:count] do
Gettext.dngettext(FgHttpWeb.Gettext, "errors", msg, msg, count, opts)
Gettext.dngettext(CfHttpWeb.Gettext, "errors", msg, msg, count, opts)
else
Gettext.dgettext(FgHttpWeb.Gettext, "errors", msg, opts)
Gettext.dgettext(CfHttpWeb.Gettext, "errors", msg, opts)
end
end
end

View File

@@ -1,5 +1,5 @@
defmodule FgHttpWeb.ErrorView do
use FgHttpWeb, :view
defmodule CfHttpWeb.ErrorView do
use CfHttpWeb, :view
# If you want to customize a particular status code
# for a certain format, you may uncomment below.

View File

@@ -0,0 +1,3 @@
defmodule CfHttpWeb.LayoutView do
use CfHttpWeb, :view
end

View File

@@ -1,11 +1,11 @@
defmodule FgHttpWeb.LiveHelpers do
defmodule CfHttpWeb.LiveHelpers do
@moduledoc """
Helpers available to all LiveViews.
"""
import Phoenix.LiveView
import Phoenix.LiveView.Helpers
alias FgHttp.Users
alias FgHttpWeb.Router.Helpers, as: Routes
alias CfHttp.Users
alias CfHttpWeb.Router.Helpers, as: Routes
@doc """
Load user into socket assigns and call the callback function if provided.
@@ -41,6 +41,6 @@ defmodule FgHttpWeb.LiveHelpers do
def live_modal(component, opts) do
path = Keyword.fetch!(opts, :return_to)
modal_opts = [id: :modal, return_to: path, component: component, opts: opts]
live_component(FgHttpWeb.ModalComponent, modal_opts)
live_component(CfHttpWeb.ModalComponent, modal_opts)
end
end

View File

@@ -1,9 +1,9 @@
defmodule FgHttp.MixProject do
defmodule CfHttp.MixProject do
use Mix.Project
def project do
[
app: :fg_http,
app: :cf_http,
version: "0.1.7",
build_path: "../../_build",
config_path: "../../config/config.exs",
@@ -30,7 +30,7 @@ defmodule FgHttp.MixProject do
# Type `mix help compile.app` for more information.
def application do
[
mod: {FgHttp.Application, []},
mod: {CfHttp.Application, []},
extra_applications: [:logger, :runtime_tools]
]
end
@@ -44,7 +44,7 @@ defmodule FgHttp.MixProject do
# Type `mix help deps` for examples and options.
defp deps do
[
{:fg_common, in_umbrella: true},
{:cf_common, in_umbrella: true},
{:phoenix, "~> 1.5"},
# XXX: Remove this dependency when cloak supports OTP 24. See https://github.com/danielberkompas/cloak/issues/102
{:cloak, "~> 1.1"},

Some files were not shown because too many files have changed in this diff Show More