Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Env file
.env

# Certbot files
/data/certbot/

# The directory Mix will write compiled artifacts to.
/_build/

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ BOOKMARK_ARCHIVE_DELAY=1000
$ docker login -u bookmarkorg -p <registry-password>
```

4. Optional: You can use HTTPS on localhost in port 4001. If you are using Google Chrome, open `chrome://flags/#allow-insecure-localhost` to enable the use of self-signed certificates on localhost.

## Basic Commands: Development

Run the app:
Expand Down
18 changes: 14 additions & 4 deletions assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -969,11 +969,21 @@ body {
}
}




/***************************************** Bulk Archives **************************************/

@media screen and (max-width: 350px) {.responsive-form {width: auto;}}
@media screen and (min-width: 350px) {.responsive-form {width: 300px;}}
@media screen and (min-width: 550px) {.responsive-form {width: 500px;}}
@media screen and (min-width: 550px) {.responsive-form {width: 500px;}}


/******************************************** Withdraw *****************************************/

@media screen and (max-width: 350px) {
.donate-button.scan{ width: auto; }
.donate-button.withdraw{ width: auto; margin-top: 50px;}
}

@media screen and (min-width: 350px) {
.donate-button.scan{ width: auto; margin-bottom: 10px; padding-left: auto;}
.donate-button.withdraw{ width: 100%;}
}
17 changes: 15 additions & 2 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,20 @@ import QrScanner from "../vendor/qr-scanner.min.js"

let Hooks = {};
Hooks.ScanCode = {
mounted() {
async mounted() {
const btn = document.getElementById("scan-btn");

if (await QrScanner.hasCamera()) {
showScanButton();
}

function showScanButton() {
var scanButton = document.getElementById('scan-btn');
scanButton.removeAttribute('hidden');
var withdrawButton = document.getElementById('withdraw-btn');
withdrawButton.style.width = '66%';
}

btn.addEventListener("click", () => {
this.pushEvent("scan-btn-clicked");
});
Expand All @@ -43,7 +54,9 @@ Hooks.ScanCode = {
video,
result => {
qrScanner.stop();
this.pushEvent("modal-closed", result);
qr_data = result["data"]
console.log("QR data: ", qr_data)
this.pushEvent("modal-closed", qr_data);
}, {
highlightScanRegion: true,
highlightCodeOutline: true,
Expand Down
17 changes: 7 additions & 10 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,13 @@ config :bookmark, BookmarkWeb.Endpoint,
#
# Note that this task requires Erlang/OTP 20 or later.
# Run `mix help phx.gen.cert` for more information.
#
# The `http:` config above can be replaced with:
#
# https: [
# port: 4001,
# cipher_suite: :strong,
# keyfile: "priv/cert/selfsigned_key.pem",
# certfile: "priv/cert/selfsigned.pem"
# ],
#
config :bookmark, BookmarkWeb.Endpoint,
https: [
port: 4001,
cipher_suite: :strong,
keyfile: "priv/cert/selfsigned_key.pem",
certfile: "priv/cert/selfsigned.pem"
]
# If desired, both `http:` and `https:` keys can be
# configured to run both http and https servers on
# different ports.
Expand Down
37 changes: 37 additions & 0 deletions data/nginx/app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
upstream bookmark {
server bookmark-app:4000;
}

server {
listen 80;
listen [::]:80;

server_name alpha.bookmark.org;
server_tokens off;

location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

location / {
return 301 https://$host$request_uri;
}
}

server {
listen 443 default_server ssl http2;
listen [::]:443 ssl http2;

server_name alpha.bookmark.org;

ssl_certificate /etc/letsencrypt/live/alpha.bookmark.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/alpha.bookmark.org/privkey.pem;

location / {
proxy_pass http://bookmark;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}

21 changes: 20 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
version: "3.9"
services:
nginx:
image: nginx:1.15-alpine
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
ports:
- "80:80"
- "443:443"
volumes:
- ./data/nginx:/etc/nginx/conf.d
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot

certbot:
image: certbot/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
volumes:
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot

bookmark:
image: bookmarkorg/bookmark:latest
container_name: bookmark-app
restart: on-failure
environment:
OPENAI_API_KEY: ${OPENAI_API_KEY}
BOOKMARK_ARCHIVE_DELAY: ${BOOKMARK_ARCHIVE_DELAY}
PHX_HOST: alpha.bookmark.org
MIX_ENV: prod
depends_on:
- bookmark-db
- archivebox
ports:
- '80:4000'
- '4000:4000'
env_file:
- base.env
volumes:
Expand Down
84 changes: 84 additions & 0 deletions init-letsencrypt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

# IMPORTANT:
# Don't forget to check and configure the `domains` and `email` variables before running this script.
# You can run it, with `chmod +x init-letsencrypt.sh` and `sudo ./init-letsencrypt.sh`

if ! [ -x "$(command -v docker)" ]; then
echo 'Error: docker compose is not installed.' >&2
exit 1
fi

domains=(alpha.bookmark.org)
rsa_key_size=4096
data_path="./data/certbot"
email="" # Adding a valid address is strongly recommended
staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits

if [ -d "$data_path" ]; then
read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision
if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then
exit
fi
fi


if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then
echo "### Downloading recommended TLS parameters ..."
mkdir -p "$data_path/conf"
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf"
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem"
echo
fi

echo "### Creating dummy certificate for $domains ..."
path="/etc/letsencrypt/live/$domains"
mkdir -p "$data_path/conf/live/$domains"
docker compose run --rm --entrypoint "\
openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\
-keyout '$path/privkey.pem' \
-out '$path/fullchain.pem' \
-subj '/CN=localhost'" certbot
echo


echo "### Starting nginx ..."
docker compose up --force-recreate -d nginx
echo

echo "### Deleting dummy certificate for $domains ..."
docker compose run --rm --entrypoint "\
rm -Rf /etc/letsencrypt/live/$domains && \
rm -Rf /etc/letsencrypt/archive/$domains && \
rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot
echo


echo "### Requesting Let's Encrypt certificate for $domains ..."
#Join $domains to -d args
domain_args=""
for domain in "${domains[@]}"; do
domain_args="$domain_args -d $domain"
done

# Select appropriate email arg
case "$email" in
"") email_arg="--register-unsafely-without-email" ;;
*) email_arg="--email $email" ;;
esac

# Enable staging mode if needed
if [ $staging != "0" ]; then staging_arg="--staging"; fi

docker compose run --rm --entrypoint "\
certbot certonly --webroot -w /var/www/certbot \
$staging_arg \
$email_arg \
$domain_args \
--rsa-key-size $rsa_key_size \
--agree-tos \
--force-renewal" certbot
echo

echo "### Reloading nginx ..."
docker compose exec nginx nginx -s reload
2 changes: 1 addition & 1 deletion lib/bookmark/withdrawals.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Bookmark.Withdrawals do
headers: [{:x_api_key, key}],
method: :post,
body: body,
receive_timeout: 30_000
receive_timeout: 60_000
) do
{:ok, response} ->
case response.status do
Expand Down
4 changes: 2 additions & 2 deletions lib/bookmark_web/live/withdrawals.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ defmodule BookmarkWeb.WithdrawalsLive do

<form phx-submit="pay">
<input class="donate-button" id="bolt_invoice" type="text" value={@invoice} placeholder="Paste BOLT-11 invoice (ln...)" name="bolt11_invoice" style="height: 66px; background-color: white; border-radius: 13px; margin-bottom: 13px; float: left; "/>
<button class="donate-button" style="color: lightgray; width: 30%; float: left; margin-right: 13px; " type="button" id="scan-btn" phx-hook="ScanCode">Scan QR</button>
<button class="donate-button" style="width: 66%">Withdraw</button>
<button class="donate-button scan" style="color: lightgray; float: left; margin-right: 13px; " type="button" id="scan-btn" phx-hook="ScanCode" hidden>Scan QR</button>
<button class="donate-button withdraw" style="margin-top: 50px;" id="withdraw-btn">Withdraw</button>
</form>

<%= if @show_modal do %>
Expand Down
22 changes: 22 additions & 0 deletions priv/cert/selfsigned.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-----BEGIN CERTIFICATE-----
MIIDfDCCAmSgAwIBAgIIfq3YHHWBHR8wDQYJKoZIhvcNAQELBQAwQzEaMBgGA1UE
CgwRUGhvZW5peCBGcmFtZXdvcmsxJTAjBgNVBAMMHFNlbGYtc2lnbmVkIHRlc3Qg
Y2VydGlmaWNhdGUwHhcNMjMwNjI2MDAwMDAwWhcNMjQwNjI2MDAwMDAwWjBDMRow
GAYDVQQKDBFQaG9lbml4IEZyYW1ld29yazElMCMGA1UEAwwcU2VsZi1zaWduZWQg
dGVzdCBjZXJ0aWZpY2F0ZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
AL3eFZsvAiEnbhEwaS+RqppkyTQpwADD/U97qPYt4BFjC3lOHBfh+aamwrkaBvpL
eGbvnlm77ihP2sqSPNwstEKcyBR7xJleif3EX0NOE2b8SHZVx420NznUoHdfnwUa
fa7TkzhoTiGA7wdsnipWV+9Cn0U4v/sWqUTxvjXYQLT3UAaUITd7QiZLjZu8/sP5
cK1sjx3J/NjrM1jXjYwcHLpFj7cG0P4nF4wZqBnudKb2zB2A4bJ/lGvlhUF/5GeA
cXoCk4n+gDvVHOX1ucyU0vtP5GhsJAVBsiURQJfMZxAF6jKrlxKUMlSlAZyX3FCp
XjWrsKsK+RkxcttAYyq4PoECAwEAAaN0MHIwDAYDVR0TAQH/BAIwADAOBgNVHQ8B
Af8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMB0GA1UdDgQW
BBTZmMlASFS8Lwu3hBQRJm9qUF9fyTAUBgNVHREEDTALgglsb2NhbGhvc3QwDQYJ
KoZIhvcNAQELBQADggEBAI4K2dvGkSJjum6vnnk+y9843KsAh3mjLloMFUmZ/lox
0tpNO48Z+eWcj6Qepd92cVv80wDsykLRvKVG1DNgI0XfrCD9CL1TvH9gDQU07113
S+S6yTcQnMZ/5Krj7ZcMrnqI1w8elqJE1AbrubOvfizU00Yk5ppU28X1QTz+NU0D
NvQS6jlpaX48Id52/bhRp4p3ne/1nH+7IT+1WGA7paLcoAfxm7KVX28DDKScU6iP
mw0/+h7TYenbOTjRnaxW6R92fE3l6ViLbInTUN0okCqUnnF3ptV4WO6ATOkxnuPu
kCTMDuA0qC9ho69t9nwLSTMuW28RH7Kcp6mX8xr56GI=
-----END CERTIFICATE-----

28 changes: 28 additions & 0 deletions priv/cert/selfsigned_key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAvd4Vmy8CISduETBpL5GqmmTJNCnAAMP9T3uo9i3gEWMLeU4c
F+H5pqbCuRoG+kt4Zu+eWbvuKE/aypI83Cy0QpzIFHvEmV6J/cRfQ04TZvxIdlXH
jbQ3OdSgd1+fBRp9rtOTOGhOIYDvB2yeKlZX70KfRTi/+xapRPG+NdhAtPdQBpQh
N3tCJkuNm7z+w/lwrWyPHcn82OszWNeNjBwcukWPtwbQ/icXjBmoGe50pvbMHYDh
sn+Ua+WFQX/kZ4BxegKTif6AO9Uc5fW5zJTS+0/kaGwkBUGyJRFAl8xnEAXqMquX
EpQyVKUBnJfcUKleNauwqwr5GTFy20BjKrg+gQID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