Compare commits
135 Commits
095747e89b
...
feature/no
| Author | SHA1 | Date | |
|---|---|---|---|
|
011386fb8d
|
|||
|
4d77f5d38c
|
|||
|
64de4deddd
|
|||
|
8f7994d82e
|
|||
|
a7d0e71ab6
|
|||
|
27d9f73c61
|
|||
|
ed3de8b16f
|
|||
|
d7b4c67953
|
|||
| 7489d4a32f | |||
|
ac77e5b7c1
|
|||
|
e544c28105
|
|||
|
4909dac5c2
|
|||
| 3cf4348695 | |||
|
af3da0a26c
|
|||
|
2d32320c7d
|
|||
|
fc2bec6246
|
|||
|
5addd25186
|
|||
|
215d178e69
|
|||
|
5474bf66e7
|
|||
|
ef2a37e2bf
|
|||
|
0e3180602c
|
|||
|
15e2f9b962
|
|||
|
4ae10c9b53
|
|||
| 45137e0cfe | |||
|
717fe93104
|
|||
|
fdac789ccb
|
|||
|
9355dab6b6
|
|||
|
f3676949d2
|
|||
|
79952b73c5
|
|||
| 17c419403e | |||
|
6d06312a5c
|
|||
|
acb399b0b7
|
|||
|
bf20b6467e
|
|||
|
b91d90d75c
|
|||
|
3284bbf6ca
|
|||
|
171b84ee81
|
|||
|
54b01dd282
|
|||
|
e08ea64f47
|
|||
|
8cc2c9554f
|
|||
| 32dff9c67f | |||
|
126b8b20e0
|
|||
|
5abf69f356
|
|||
|
210a69bd9b
|
|||
|
bbed3cd367
|
|||
|
7943da0f17
|
|||
| 620167eedf | |||
|
e077debfc2
|
|||
|
531b2c3002
|
|||
|
6d2bc729b8
|
|||
|
2630ec2af4
|
|||
| daed5c1eea | |||
| 2e9429bb32 | |||
|
37c15c7a62
|
|||
|
01ecea74ff
|
|||
|
f401a03590
|
|||
|
fff6dea100
|
|||
|
48ab96dda9
|
|||
|
7ac3130c18
|
|||
|
cbfa148051
|
|||
|
87d900b627
|
|||
|
926dc06294
|
|||
|
00b73b06d7
|
|||
|
0daac33915
|
|||
|
0e472bc311
|
|||
| 40b34d0935 | |||
|
61cb8f4941
|
|||
|
433ac4dc8e
|
|||
|
62fe0d8fac
|
|||
|
2a675fd135
|
|||
|
c2c3ebc2e1
|
|||
|
5a5c316c14
|
|||
| f0d5457ec1 | |||
|
5588e3b3e8
|
|||
|
8949d76d26
|
|||
| 8bc9bbdc33 | |||
| d6d09b57b8 | |||
|
1685d6ecf8
|
|||
|
5348a229a6
|
|||
|
bad3b7a2be
|
|||
|
b541e95bb7
|
|||
|
3f43fe8101
|
|||
|
231dfc8404
|
|||
|
eeb9b0a331
|
|||
|
08e783d185
|
|||
|
fa5dc8ca46
|
|||
|
bc34e9c5e0
|
|||
| f388bd0237 | |||
|
48041630ca
|
|||
|
2d1ff29eca
|
|||
| 46fa42e387 | |||
|
c6c5d80fb4
|
|||
|
c0f4e7925e
|
|||
|
49d24990b4
|
|||
|
619bd954b7
|
|||
|
e27c64b5f1
|
|||
|
b36baf26eb
|
|||
|
adedaa5f7b
|
|||
|
596ed7fccc
|
|||
|
5685e1b7bc
|
|||
|
c3b82fc2a9
|
|||
|
77e2fe5792
|
|||
|
bc43082839
|
|||
|
b09225543b
|
|||
|
f2507409a3
|
|||
|
46b4723999
|
|||
|
3f90a011c4
|
|||
|
3ba333e802
|
|||
| d9dff3e872 | |||
| 6ddeacb779 | |||
|
78aff3d796
|
|||
|
8f600f44bd
|
|||
|
819ecf6ad8
|
|||
|
945eaba5e1
|
|||
|
22d362e1a0
|
|||
|
d4e67a830c
|
|||
|
670b2da1ef
|
|||
|
ed5c5b3081
|
|||
| 4ee6bfddfa | |||
|
8b60890061
|
|||
|
0367450c4b
|
|||
|
e6f5623c7f
|
|||
| 367f566ccb | |||
|
80e69df75c
|
|||
|
02af69b055
|
|||
|
5d459e7e7d
|
|||
| 51a3cb60ec | |||
| 43c57c128f | |||
|
5a3adba603
|
|||
|
3715cb518b
|
|||
|
2c9ecc1fef
|
|||
|
4217ba52e0
|
|||
|
de20931d30
|
|||
|
8de0a2e26e
|
|||
|
06521d1c34
|
|||
|
38b3d68fd5
|
@@ -29,6 +29,7 @@
|
||||
|
||||
#
|
||||
# Service Integrations
|
||||
# (sorted alphabetically by service name)
|
||||
#
|
||||
|
||||
# BTCPAY_PUBLIC_URL='https://btcpay.example.com'
|
||||
@@ -58,8 +59,13 @@
|
||||
# LNDHUB_PG_PASSWORD=''
|
||||
|
||||
# MASTODON_PUBLIC_URL='https://kosmos.social'
|
||||
# MASTODON_ADDRESS_DOMAIN='https://kosmos.org'
|
||||
|
||||
# MEDIAWIKI_PUBLIC_URL='https://wiki.kosmos.org'
|
||||
|
||||
# NOSTR_PRIVATE_KEY='123456abcdef...'
|
||||
# NOSTR_PUBLIC_KEY='123456abcdef...'
|
||||
# NOSTR_RELAY_URL='wss://nostr.kosmos.org'
|
||||
|
||||
# RS_STORAGE_URL='https://storage.kosmos.org'
|
||||
# RS_REDIS_URL='redis://localhost:6379/2'
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
PRIMARY_DOMAIN=kosmos.org
|
||||
AKKOUNTS_DOMAIN=accounts.kosmos.org
|
||||
|
||||
REDIS_URL='redis://localhost:6379/0'
|
||||
|
||||
@@ -11,10 +12,15 @@ DISCOURSE_CONNECT_SECRET='discourse_connect_ftw'
|
||||
|
||||
EJABBERD_API_URL='http://xmpp.example.com/api'
|
||||
|
||||
MASTODON_PUBLIC_URL='http://example.social'
|
||||
|
||||
LNDHUB_API_URL='http://localhost:3026'
|
||||
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'
|
||||
LNDHUB_PUBLIC_KEY='024cd3be18617f39cf645851e3ba63f51fc13f0bb09e3bb25e6fd4de556486d946'
|
||||
|
||||
NOSTR_PRIVATE_KEY='7c3ef7e448505f0615137af38569d01807d3b05b5005d5ecf8aaafcd40323cea'
|
||||
NOSTR_PUBLIC_KEY='bdd76ce2934b2f591f9fad2ebe9da18f20d2921de527494ba00eeaa0a0efadcf'
|
||||
|
||||
RS_STORAGE_URL='https://storage.kosmos.org'
|
||||
RS_REDIS_URL='redis://localhost:6379/1'
|
||||
|
||||
|
||||
13
Dockerfile
13
Dockerfile
@@ -1,18 +1,11 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM debian:bullseye-slim as base
|
||||
FROM ruby:3.3.4
|
||||
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
|
||||
# TODO Remove when upstream Ruby works properly on Apple silicon
|
||||
RUN apt update && apt install -y build-essential wget autoconf libpq-dev pkg-config
|
||||
RUN wget https://github.com/postmodern/ruby-install/releases/download/v0.9.3/ruby-install-0.9.3.tar.gz \
|
||||
&& tar -xzvf ruby-install-0.9.3.tar.gz \
|
||||
&& cd ruby-install-0.9.3/ \
|
||||
&& make install
|
||||
RUN ruby-install -p https://github.com/ruby/ruby/pull/9371.diff ruby 3.3.0
|
||||
ENV PATH="/opt/rubies/ruby-3.3.0/bin:${PATH}"
|
||||
RUN apt-get update -qq && apt-get install -y --no-install-recommends curl \
|
||||
ldap-utils tini libvips
|
||||
|
||||
RUN apt-get install -y --no-install-recommends curl ldap-utils tini libvips
|
||||
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
|
||||
RUN apt-get update && apt-get install -y nodejs
|
||||
|
||||
|
||||
4
Gemfile
4
Gemfile
@@ -61,8 +61,8 @@ gem "sentry-rails"
|
||||
# Services
|
||||
gem 'discourse_api'
|
||||
gem "lnurl"
|
||||
gem 'manifique'
|
||||
gem 'nostr'
|
||||
gem 'manifique', '~> 1.1.0'
|
||||
gem 'nostr', '~> 0.6.0'
|
||||
|
||||
group :development, :test do
|
||||
# Use sqlite3 as the database for Active Record
|
||||
|
||||
12
Gemfile.lock
12
Gemfile.lock
@@ -155,7 +155,7 @@ GEM
|
||||
ruby2_keywords
|
||||
e2mmap (0.1.0)
|
||||
ecdsa (1.2.0)
|
||||
ecdsa_ext (0.5.0)
|
||||
ecdsa_ext (0.5.1)
|
||||
ecdsa (~> 1.2.0)
|
||||
erubi (1.12.0)
|
||||
et-orbi (1.2.7)
|
||||
@@ -245,7 +245,7 @@ GEM
|
||||
net-imap
|
||||
net-pop
|
||||
net-smtp
|
||||
manifique (1.0.1)
|
||||
manifique (1.1.0)
|
||||
faraday (~> 2.9.0)
|
||||
faraday-follow_redirects (= 0.3.0)
|
||||
nokogiri (~> 1.16.0)
|
||||
@@ -278,9 +278,9 @@ GEM
|
||||
racc (~> 1.4)
|
||||
nokogiri (1.16.0-x86_64-linux)
|
||||
racc (~> 1.4)
|
||||
nostr (0.5.0)
|
||||
nostr (0.6.0)
|
||||
bech32 (~> 1.4)
|
||||
bip-schnorr (~> 0.6)
|
||||
bip-schnorr (~> 0.7)
|
||||
ecdsa (~> 1.2)
|
||||
event_emitter (~> 0.2)
|
||||
faye-websocket (~> 0.11)
|
||||
@@ -515,9 +515,9 @@ DEPENDENCIES
|
||||
listen (~> 3.2)
|
||||
lnurl
|
||||
lockbox
|
||||
manifique
|
||||
manifique (~> 1.1.0)
|
||||
net-ldap
|
||||
nostr
|
||||
nostr (~> 0.6.0)
|
||||
pagy (~> 6.0, >= 6.0.2)
|
||||
pg (~> 1.5)
|
||||
puma (~> 4.1)
|
||||
|
||||
@@ -42,6 +42,11 @@
|
||||
focus:ring-red-500 focus:ring-opacity-75;
|
||||
}
|
||||
|
||||
.btn-outline-purple {
|
||||
@apply border-2 border-purple-500 hover:bg-purple-100
|
||||
focus:ring-purple-400 focus:ring-opacity-75;
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
@apply bg-gray-100 hover:bg-gray-200 text-gray-400
|
||||
focus:ring-gray-300 focus:ring-opacity-75;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@layer components {
|
||||
.services > div > a {
|
||||
background-image: linear-gradient(110deg, rgba(255,255,255,0.99) 0, rgba(255,255,255,0.88) 100%);
|
||||
background-image: linear-gradient(110deg, rgba(255,255,255,0.99) 20%, rgba(255,255,255,0.88) 100%);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
) do %>
|
||||
<%= method("#{@type}_field").call :setting, @key,
|
||||
value: Setting.public_send(@key),
|
||||
placeholder: @placeholder,
|
||||
data: {
|
||||
:'default-value' => Setting.get_field(@key)[:default]
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
module FormElements
|
||||
class FieldsetResettableSettingComponent < ViewComponent::Base
|
||||
def initialize(tag: "li", key:, type: :text, title:, description: nil)
|
||||
def initialize(tag: "li", key:, type: :text, title:, description: nil, placeholder: nil)
|
||||
@tag = tag
|
||||
@positioning = :vertical
|
||||
@title = title
|
||||
@@ -10,6 +10,7 @@ module FormElements
|
||||
@key = key.to_sym
|
||||
@type = type
|
||||
@resettable = is_resettable?(@key)
|
||||
@placeholder = placeholder
|
||||
end
|
||||
|
||||
def is_resettable?(key)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<div class="flex flex-col">
|
||||
<label class="font-bold mb-1"><%= @title %></label>
|
||||
<% if @description.present? %>
|
||||
<p class="text-gray-500"><%= @descripton %></p>
|
||||
<p class="text-gray-500"><%= @description %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="relative ml-4 inline-flex flex-shrink-0">
|
||||
|
||||
@@ -12,7 +12,7 @@ module FormElements
|
||||
@enabled = enabled
|
||||
@input_enabled = input_enabled
|
||||
@title = title
|
||||
@descripton = description
|
||||
@description = description
|
||||
@button_text = @enabled ? "Switch off" : "Switch on"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,4 +9,12 @@ class Admin::Settings::RegistrationsController < Admin::SettingsController
|
||||
success: "Settings saved"
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def setting_params
|
||||
params.require(:setting).permit([
|
||||
:reserved_usernames, default_services: []
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,11 +9,12 @@ class Admin::SettingsController < Admin::BaseController
|
||||
changed_keys = []
|
||||
|
||||
setting_params.keys.each do |key|
|
||||
next if setting_params[key].nil? ||
|
||||
(Setting.send(key).to_s == setting_params[key].strip)
|
||||
next if clean_param(key).nil? ||
|
||||
(Setting.send(key).to_s == clean_param(key))
|
||||
|
||||
changed_keys.push(key)
|
||||
setting = Setting.new(var: key)
|
||||
setting.value = setting_params[key].strip
|
||||
setting.value = clean_param(key)
|
||||
unless setting.valid?
|
||||
@errors.merge!(setting.errors)
|
||||
end
|
||||
@@ -24,7 +25,7 @@ class Admin::SettingsController < Admin::BaseController
|
||||
end
|
||||
|
||||
changed_keys.each do |key|
|
||||
Setting.send("#{key}=", setting_params[key].strip)
|
||||
Setting.send("#{key}=", clean_param(key))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,4 +38,12 @@ class Admin::SettingsController < Admin::BaseController
|
||||
def setting_params
|
||||
params.require(:setting).permit(Setting.editable_keys.map(&:to_sym))
|
||||
end
|
||||
|
||||
def clean_param(key)
|
||||
if Setting.get_field(key)[:type] == :string
|
||||
setting_params[key].strip
|
||||
else
|
||||
setting_params[key]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -63,4 +63,9 @@ class ApplicationController < ActionController::Base
|
||||
@fetch_balance_retried = true
|
||||
lndhub_fetch_balance
|
||||
end
|
||||
|
||||
def nostr_event_from_params
|
||||
params.permit!
|
||||
params[:signed_event].to_h.symbolize_keys
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
class LnurlpayController < ApplicationController
|
||||
before_action :check_service_available
|
||||
before_action :find_user
|
||||
before_action :set_cors_access_control_headers
|
||||
|
||||
MIN_SATS = 10
|
||||
MAX_SATS = 1_000_000
|
||||
MAX_COMMENT_CHARS = 100
|
||||
|
||||
# GET /.well-known/lnurlp/:username
|
||||
def index
|
||||
render json: {
|
||||
res = {
|
||||
status: "OK",
|
||||
callback: "https://#{Setting.accounts_domain}/lnurlpay/#{@user.cn}/invoice",
|
||||
tag: "payRequest",
|
||||
@@ -16,8 +18,16 @@ class LnurlpayController < ApplicationController
|
||||
metadata: metadata(@user.address),
|
||||
commentAllowed: MAX_COMMENT_CHARS
|
||||
}
|
||||
|
||||
if Setting.nostr_enabled?
|
||||
res[:allowsNostr] = true
|
||||
res[:nostrPubkey] = Setting.nostr_public_key
|
||||
end
|
||||
|
||||
render json: res
|
||||
end
|
||||
|
||||
# GET /.well-known/keysend/:username
|
||||
def keysend
|
||||
http_status :not_found and return unless Setting.lndhub_keysend_enabled?
|
||||
|
||||
@@ -32,8 +42,9 @@ class LnurlpayController < ApplicationController
|
||||
}
|
||||
end
|
||||
|
||||
# GET /lnurlpay/:username/invoice
|
||||
def invoice
|
||||
amount = params[:amount].to_i / 1000 # msats
|
||||
amount = params[:amount].to_i / 1000 # msats to sats
|
||||
comment = params[:comment] || ""
|
||||
address = @user.address
|
||||
|
||||
@@ -42,53 +53,109 @@ class LnurlpayController < ApplicationController
|
||||
return
|
||||
end
|
||||
|
||||
if !valid_comment?(comment)
|
||||
render json: { status: "ERROR", reason: "Comment too long" }
|
||||
return
|
||||
if params[:nostr].present? && Setting.nostr_enabled?
|
||||
handle_zap_request amount, params[:nostr], params[:lnurl]
|
||||
else
|
||||
handle_pay_request address, amount, comment
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_cors_access_control_headers
|
||||
headers['Access-Control-Allow-Origin'] = "*"
|
||||
headers['Access-Control-Allow-Headers'] = "*"
|
||||
headers['Access-Control-Allow-Methods'] = "GET"
|
||||
end
|
||||
|
||||
memo = "To #{address}"
|
||||
memo = "#{memo}: \"#{comment}\"" if comment.present?
|
||||
def check_service_available
|
||||
http_status :not_found unless Setting.lndhub_enabled?
|
||||
end
|
||||
|
||||
payment_request = @user.ln_create_invoice({
|
||||
amount: amount, # we create invoices in sats
|
||||
memo: memo,
|
||||
description_hash: Digest::SHA2.hexdigest(metadata(address)),
|
||||
})
|
||||
def find_user
|
||||
@user = User.where(cn: params[:username], ou: Setting.primary_domain).first
|
||||
http_status :not_found if @user.nil?
|
||||
end
|
||||
|
||||
render json: {
|
||||
status: "OK",
|
||||
successAction: {
|
||||
tag: "message",
|
||||
message: "Sats received. Thank you!"
|
||||
},
|
||||
routes: [],
|
||||
pr: payment_request
|
||||
}
|
||||
end
|
||||
def metadata(address)
|
||||
"[[\"text/identifier\",\"#{address}\"],[\"text/plain\",\"Sats for #{address}\"]]"
|
||||
end
|
||||
|
||||
private
|
||||
def valid_amount?(amount_in_sats)
|
||||
amount_in_sats <= MAX_SATS && amount_in_sats >= MIN_SATS
|
||||
end
|
||||
|
||||
def find_user
|
||||
@user = User.where(cn: params[:username], ou: Setting.primary_domain).first
|
||||
http_status :not_found if @user.nil?
|
||||
end
|
||||
def valid_comment?(comment)
|
||||
comment.length <= MAX_COMMENT_CHARS
|
||||
end
|
||||
|
||||
def metadata(address)
|
||||
"[[\"text/identifier\", \"#{address}\"], [\"text/plain\", \"Send sats, receive thanks.\"]]"
|
||||
end
|
||||
def handle_pay_request(address, amount, comment)
|
||||
if !valid_comment?(comment)
|
||||
render json: { status: "ERROR", reason: "Comment too long" }
|
||||
return
|
||||
end
|
||||
|
||||
def valid_amount?(amount_in_sats)
|
||||
amount_in_sats <= MAX_SATS && amount_in_sats >= MIN_SATS
|
||||
end
|
||||
desc = "To #{address}"
|
||||
desc = "#{desc}: \"#{comment}\"" if comment.present?
|
||||
|
||||
def valid_comment?(comment)
|
||||
comment.length <= MAX_COMMENT_CHARS
|
||||
end
|
||||
invoice = LndhubManager::CreateUserInvoice.call(
|
||||
user: @user, payload: {
|
||||
amount: amount, # sats
|
||||
description: desc,
|
||||
description_hash: Digest::SHA256.hexdigest(metadata(address)),
|
||||
}
|
||||
)
|
||||
|
||||
private
|
||||
render json: {
|
||||
status: "OK",
|
||||
successAction: {
|
||||
tag: "message",
|
||||
message: "Sats received. Thank you!"
|
||||
},
|
||||
routes: [],
|
||||
pr: invoice["payment_request"]
|
||||
}
|
||||
end
|
||||
|
||||
def check_service_available
|
||||
http_status :not_found unless Setting.lndhub_enabled?
|
||||
end
|
||||
def nostr_event_from_payload(nostr_param)
|
||||
event_obj = JSON.parse(nostr_param).transform_keys(&:to_sym)
|
||||
Nostr::Event.new(**event_obj)
|
||||
rescue => e
|
||||
return nil
|
||||
end
|
||||
|
||||
def valid_zap_request?(amount, event, lnurl)
|
||||
NostrManager::VerifyZapRequest.call(
|
||||
amount: amount, event: event, lnurl: lnurl
|
||||
)
|
||||
end
|
||||
|
||||
def handle_zap_request(amount, nostr_param, lnurl_param)
|
||||
event = nostr_event_from_payload(nostr_param)
|
||||
|
||||
unless event.present? && valid_zap_request?(amount*1000, event, lnurl_param)
|
||||
render json: { status: "ERROR", reason: "Invalid zap request" }
|
||||
return
|
||||
end
|
||||
|
||||
# TODO might want to use the existing invoice and zap record if there are
|
||||
# multiple calls with the same zap request
|
||||
|
||||
desc = "Zap for #{@user.address}"
|
||||
desc = "#{desc}: \"#{event.content}\"" if event.content.present?
|
||||
|
||||
invoice = LndhubManager::CreateUserInvoice.call(
|
||||
user: @user, payload: {
|
||||
amount: amount, # sats
|
||||
description: desc,
|
||||
description_hash: Digest::SHA256.hexdigest(event.to_json),
|
||||
}
|
||||
)
|
||||
|
||||
@user.zaps.create! request: event,
|
||||
payment_request: invoice["payment_request"],
|
||||
amount: amount
|
||||
|
||||
render json: { status: "OK", pr: invoice["payment_request"] }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ class Services::ChatController < Services::BaseController
|
||||
before_action :require_service_available
|
||||
|
||||
def show
|
||||
@service_enabled = current_user.services_enabled.include?(:xmpp)
|
||||
@service_enabled = current_user.service_enabled?(:ejabberd)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -3,7 +3,7 @@ class Services::MastodonController < Services::BaseController
|
||||
before_action :require_service_available
|
||||
|
||||
def show
|
||||
@service_enabled = current_user.services_enabled.include?(:mastodon)
|
||||
@service_enabled = current_user.service_enabled?(:mastodon)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -5,11 +5,10 @@ class Services::RemotestorageController < Services::BaseController
|
||||
|
||||
# Dashboard
|
||||
def show
|
||||
# unless current_user.services_enabled.include?(:remotestorage)
|
||||
# unless current_user.service_enabled?(:remotestorage)
|
||||
# redirect_to service_remotestorage_info_path
|
||||
# end
|
||||
@rs_auths = current_user.remote_storage_authorizations
|
||||
# TODO sort by app name
|
||||
# @rs_apps_connected = current_user.remote_storage_authorizations.any?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -3,13 +3,18 @@ class Services::RsAuthsController < Services::BaseController
|
||||
before_action :require_feature_enabled
|
||||
before_action :require_service_available
|
||||
# before_action :require_service_enabled
|
||||
before_action :find_rs_auth
|
||||
before_action :find_rs_auth, only: [:destroy, :launch_app]
|
||||
|
||||
def index
|
||||
@rs_auths = current_user.remote_storage_authorizations
|
||||
# TODO sort by app name?
|
||||
end
|
||||
|
||||
def destroy
|
||||
@auth.destroy!
|
||||
|
||||
respond_to do |format|
|
||||
format.html do redirect_to services_storage_url, flash: {
|
||||
format.html do redirect_to apps_services_storage_url, flash: {
|
||||
success: 'App authorization revoked'
|
||||
}
|
||||
end
|
||||
|
||||
@@ -12,7 +12,11 @@ class SettingsController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
if @settings_section == "experiments"
|
||||
case @settings_section
|
||||
when "lightning"
|
||||
@notifications_enabled = @user.preferences[:lightning_notify_sats_received] != "disabled" ||
|
||||
@user.preferences[:lightning_notify_zap_received] != "disabled"
|
||||
when "nostr"
|
||||
session[:shared_secret] ||= SecureRandom.base64(12)
|
||||
end
|
||||
end
|
||||
@@ -87,40 +91,39 @@ class SettingsController < ApplicationController
|
||||
end
|
||||
|
||||
def set_nostr_pubkey
|
||||
signed_event = nostr_event_params[:signed_event].to_h.symbolize_keys
|
||||
is_valid_id = NostrManager::ValidateId.call(event: signed_event)
|
||||
is_valid_sig = NostrManager::VerifySignature.call(event: signed_event)
|
||||
is_correct_content = signed_event[:content] == "Connect my public key to #{current_user.address} (confirmation #{session[:shared_secret]})"
|
||||
signed_event = Nostr::Event.new(**nostr_event_from_params)
|
||||
|
||||
unless is_valid_id && is_valid_sig && is_correct_content
|
||||
is_valid_sig = signed_event.verify_signature
|
||||
is_valid_auth = NostrManager::VerifyAuth.call(
|
||||
event: signed_event,
|
||||
challenge: session[:shared_secret]
|
||||
)
|
||||
|
||||
unless is_valid_sig && is_valid_auth
|
||||
flash[:alert] = "Public key could not be verified"
|
||||
http_status :unprocessable_entity and return
|
||||
end
|
||||
|
||||
pubkey_taken = User.all_except(current_user).where(
|
||||
ou: current_user.ou, nostr_pubkey: signed_event[:pubkey]
|
||||
).any?
|
||||
user_with_pubkey = LdapManager::FetchUserByNostrKey.call(pubkey: signed_event.pubkey)
|
||||
|
||||
if pubkey_taken
|
||||
if user_with_pubkey.present? && (user_with_pubkey != current_user)
|
||||
flash[:alert] = "Public key already in use for a different account"
|
||||
http_status :unprocessable_entity and return
|
||||
end
|
||||
|
||||
current_user.update! nostr_pubkey: signed_event[:pubkey]
|
||||
LdapManager::UpdateNostrKey.call(dn: current_user.dn, pubkey: signed_event.pubkey)
|
||||
session[:shared_secret] = nil
|
||||
|
||||
flash[:success] = "Public key verification successful"
|
||||
http_status :ok
|
||||
rescue
|
||||
flash[:alert] = "Public key could not be verified"
|
||||
http_status :unprocessable_entity and return
|
||||
end
|
||||
|
||||
# DELETE /settings/nostr_pubkey
|
||||
def remove_nostr_pubkey
|
||||
current_user.update! nostr_pubkey: nil
|
||||
# TODO require current pubkey or password to delete
|
||||
LdapManager::UpdateNostrKey.call(dn: current_user.dn, pubkey: nil)
|
||||
|
||||
redirect_to setting_path(:experiments), flash: {
|
||||
redirect_to setting_path(:nostr), flash: {
|
||||
success: 'Public key removed from account'
|
||||
}
|
||||
end
|
||||
@@ -134,8 +137,8 @@ class SettingsController < ApplicationController
|
||||
def set_settings_section
|
||||
@settings_section = params[:section]
|
||||
allowed_sections = [
|
||||
:profile, :account, :xmpp, :email, :lightning, :remotestorage,
|
||||
:experiments
|
||||
:profile, :account, :xmpp, :email,
|
||||
:lightning, :remotestorage, :nostr
|
||||
]
|
||||
|
||||
unless allowed_sections.include?(@settings_section.to_sym)
|
||||
@@ -148,11 +151,9 @@ class SettingsController < ApplicationController
|
||||
end
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:display_name, :avatar, preferences: [
|
||||
:lightning_notify_sats_received,
|
||||
:remotestorage_notify_auth_created,
|
||||
:xmpp_exchange_contacts_with_invitees
|
||||
])
|
||||
params.require(:user).permit(
|
||||
:display_name, :avatar, preferences: UserPreferences.pref_keys
|
||||
)
|
||||
end
|
||||
|
||||
def email_params
|
||||
@@ -163,12 +164,6 @@ class SettingsController < ApplicationController
|
||||
params.require(:user).permit(:current_password)
|
||||
end
|
||||
|
||||
def nostr_event_params
|
||||
params.permit(signed_event: [
|
||||
:id, :pubkey, :created_at, :kind, :tags, :content, :sig
|
||||
])
|
||||
end
|
||||
|
||||
def generate_email_password
|
||||
characters = [('a'..'z'), ('A'..'Z'), (0..9)].map(&:to_a).flatten
|
||||
SecureRandom.random_bytes(16).each_byte.map { |b| characters[b % characters.length] }.join
|
||||
|
||||
62
app/controllers/users/sessions_controller.rb
Normal file
62
app/controllers/users/sessions_controller.rb
Normal file
@@ -0,0 +1,62 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Users::SessionsController < Devise::SessionsController
|
||||
# before_action :configure_sign_in_params, only: [:create]
|
||||
|
||||
# GET /resource/sign_in
|
||||
def new
|
||||
session[:shared_secret] = SecureRandom.base64(12)
|
||||
super
|
||||
end
|
||||
|
||||
# POST /resource/sign_in
|
||||
# def create
|
||||
# super
|
||||
# end
|
||||
|
||||
# DELETE /resource/sign_out
|
||||
# def destroy
|
||||
# super
|
||||
# end
|
||||
|
||||
# POST /users/nostr_login
|
||||
def nostr_login
|
||||
signed_event = Nostr::Event.new(**nostr_event_from_params)
|
||||
|
||||
is_valid_sig = signed_event.verify_signature
|
||||
is_valid_auth = NostrManager::VerifyAuth.call(
|
||||
event: signed_event,
|
||||
challenge: session[:shared_secret]
|
||||
)
|
||||
|
||||
session[:shared_secret] = nil
|
||||
|
||||
unless is_valid_sig && is_valid_auth
|
||||
flash[:alert] = "Login verification failed"
|
||||
http_status :unauthorized and return
|
||||
end
|
||||
|
||||
user = LdapManager::FetchUserByNostrKey.call(pubkey: signed_event.pubkey)
|
||||
|
||||
if user.present?
|
||||
set_flash_message!(:notice, :signed_in)
|
||||
sign_in("user", user)
|
||||
render json: { redirect_url: after_sign_in_path_for(user) }, status: :ok
|
||||
else
|
||||
flash[:alert] = "Failed to find your account. Nostr login may be disabled."
|
||||
http_status :unauthorized
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_flash_message(key, kind, options = {})
|
||||
# Hide flash message after redirecting from a signin route while logged in
|
||||
super unless key == :alert && kind == "already_authenticated"
|
||||
end
|
||||
|
||||
# If you have extra params to permit, append them to the sanitizer.
|
||||
# def configure_sign_in_params
|
||||
# devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
|
||||
# end
|
||||
end
|
||||
@@ -1,20 +1,19 @@
|
||||
class WebfingerController < ApplicationController
|
||||
class WebfingerController < WellKnownController
|
||||
before_action :allow_cross_origin_requests, only: [:show]
|
||||
|
||||
layout false
|
||||
|
||||
def show
|
||||
resource = params[:resource]
|
||||
|
||||
if resource && @useraddress = resource.match(/acct:(.+)/)&.[](1)
|
||||
@username, @org = @useraddress.split("@")
|
||||
@username, @domain = @useraddress.split("@")
|
||||
|
||||
unless Rails.env.development?
|
||||
# Allow different domains (e.g. localhost:3000) in development only
|
||||
head 404 and return unless @org == Setting.primary_domain
|
||||
head 404 and return unless @domain == Setting.primary_domain
|
||||
end
|
||||
|
||||
unless User.where(cn: @username.downcase, ou: Setting.primary_domain).any?
|
||||
unless @user = User.where(ou: Setting.primary_domain)
|
||||
.find_by(cn: @username.downcase)
|
||||
head 404 and return
|
||||
end
|
||||
|
||||
@@ -28,22 +27,60 @@ class WebfingerController < ApplicationController
|
||||
private
|
||||
|
||||
def webfinger
|
||||
links = [];
|
||||
jrd = {
|
||||
subject: "acct:#{@user.address}",
|
||||
aliases: [],
|
||||
links: []
|
||||
}
|
||||
|
||||
# TODO check if storage service is enabled for user, not just globally
|
||||
links << remotestorage_link if Setting.remotestorage_enabled
|
||||
if Setting.mastodon_enabled && @user.service_enabled?(:mastodon)
|
||||
# https://docs.joinmastodon.org/spec/webfinger/
|
||||
jrd[:aliases] += mastodon_aliases
|
||||
jrd[:links] += mastodon_links
|
||||
end
|
||||
|
||||
{ "links" => links }
|
||||
if Setting.remotestorage_enabled && @user.service_enabled?(:remotestorage)
|
||||
# https://datatracker.ietf.org/doc/draft-dejong-remotestorage/
|
||||
jrd[:links] << remotestorage_link
|
||||
end
|
||||
|
||||
jrd
|
||||
end
|
||||
|
||||
def mastodon_aliases
|
||||
[
|
||||
"#{Setting.mastodon_public_url}/@#{@user.cn}",
|
||||
"#{Setting.mastodon_public_url}/users/#{@user.cn}"
|
||||
]
|
||||
end
|
||||
|
||||
def mastodon_links
|
||||
[
|
||||
{
|
||||
rel: "http://webfinger.net/rel/profile-page",
|
||||
type: "text/html",
|
||||
href: "#{Setting.mastodon_public_url}/@#{@user.cn}"
|
||||
},
|
||||
{
|
||||
rel: "self",
|
||||
type: "application/activity+json",
|
||||
href: "#{Setting.mastodon_public_url}/users/#{@user.cn}"
|
||||
},
|
||||
{
|
||||
rel: "http://ostatus.org/schema/1.0/subscribe",
|
||||
template: "#{Setting.mastodon_public_url}/authorize_interaction?uri={uri}"
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
def remotestorage_link
|
||||
auth_url = new_rs_oauth_url(@username)
|
||||
auth_url = new_rs_oauth_url(@username, host: Setting.accounts_domain)
|
||||
storage_url = "#{Setting.rs_storage_url}/#{@username}"
|
||||
|
||||
{
|
||||
"rel" => "http://tools.ietf.org/id/draft-dejong-remotestorage",
|
||||
"href" => storage_url,
|
||||
"properties" => {
|
||||
rel: "http://tools.ietf.org/id/draft-dejong-remotestorage",
|
||||
href: storage_url,
|
||||
properties: {
|
||||
"http://remotestorage.io/spec/version" => "draft-dejong-remotestorage-13",
|
||||
"http://tools.ietf.org/html/rfc6749#section-4.2" => auth_url,
|
||||
"http://tools.ietf.org/html/rfc6750#section-2.3" => nil, # access token via a HTTP query parameter
|
||||
@@ -52,10 +89,4 @@ class WebfingerController < ApplicationController
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def allow_cross_origin_requests
|
||||
return unless Rails.env.development?
|
||||
headers['Access-Control-Allow-Origin'] = "*"
|
||||
headers['Access-Control-Allow-Methods'] = "GET"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,45 +2,76 @@ class WebhooksController < ApplicationController
|
||||
skip_forgery_protection
|
||||
|
||||
before_action :authorize_request
|
||||
before_action :process_payload
|
||||
|
||||
def lndhub
|
||||
begin
|
||||
payload = JSON.parse(request.body.read, symbolize_names: true)
|
||||
head :no_content and return unless payload[:type] == "incoming"
|
||||
rescue
|
||||
head :unprocessable_entity and return
|
||||
@user = User.find_by!(ln_account: @payload[:user_login])
|
||||
|
||||
if @zap = @user.zaps.find_by(payment_request: @payload[:payment_request])
|
||||
settled_at = Time.parse(@payload[:settled_at])
|
||||
zap_receipt = NostrManager::CreateZapReceipt.call(
|
||||
zap: @zap,
|
||||
paid_at: settled_at.to_i,
|
||||
preimage: @payload[:preimage]
|
||||
)
|
||||
@zap.update! settled_at: settled_at, receipt: zap_receipt.to_h
|
||||
NostrManager::PublishZapReceipt.call(zap: @zap)
|
||||
end
|
||||
|
||||
user = User.find_by!(ln_account: payload[:user_login])
|
||||
notify = user.preferences[:lightning_notify_sats_received]
|
||||
case notify
|
||||
when "xmpp"
|
||||
notify_xmpp(user.address, payload[:amount], payload[:memo])
|
||||
when "email"
|
||||
NotificationMailer.with(user: user, amount_sats: payload[:amount])
|
||||
.lightning_sats_received.deliver_later
|
||||
end
|
||||
send_notifications
|
||||
|
||||
head :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# TODO refactor into mailer-like generic class/service
|
||||
def notify_xmpp(address, amt_sats, memo)
|
||||
payload = {
|
||||
type: "normal",
|
||||
from: Setting.xmpp_notifications_from_address,
|
||||
to: address,
|
||||
subject: "Sats received!",
|
||||
body: "#{helpers.number_with_delimiter amt_sats} sats received in your Lightning wallet:\n> #{memo}"
|
||||
}
|
||||
XmppSendMessageJob.perform_later(payload)
|
||||
end
|
||||
|
||||
def authorize_request
|
||||
if !ENV['WEBHOOKS_ALLOWED_IPS'].split(',').include?(request.remote_ip)
|
||||
head :forbidden and return
|
||||
end
|
||||
end
|
||||
|
||||
def process_payload
|
||||
@payload = JSON.parse(request.body.read, symbolize_names: true)
|
||||
unless @payload[:type] == "incoming" &&
|
||||
@payload[:state] == "settled"
|
||||
head :no_content and return
|
||||
end
|
||||
rescue
|
||||
head :unprocessable_entity and return
|
||||
end
|
||||
|
||||
def send_notifications
|
||||
return if @payload[:amount] < @user.preferences[:lightning_notify_min_sats]
|
||||
|
||||
if @user.preferences[:lightning_notify_only_with_message]
|
||||
return if @payload[:memo].blank?
|
||||
end
|
||||
|
||||
target = @zap.present? ? @user.preferences[:lightning_notify_zap_received] :
|
||||
@user.preferences[:lightning_notify_sats_received]
|
||||
|
||||
case target
|
||||
when "xmpp"
|
||||
notify_xmpp
|
||||
when "email"
|
||||
notify_email
|
||||
end
|
||||
end
|
||||
|
||||
# TODO refactor into mailer-like generic class/service
|
||||
def notify_xmpp
|
||||
XmppSendMessageJob.perform_later({
|
||||
type: "normal",
|
||||
from: Setting.xmpp_notifications_from_address,
|
||||
to: @user.address,
|
||||
subject: "Sats received!",
|
||||
body: "#{helpers.number_with_delimiter @payload[:amount]} sats received in your Lightning wallet:\n> #{@payload[:memo]}"
|
||||
})
|
||||
end
|
||||
|
||||
def notify_email
|
||||
NotificationMailer.with(user: @user, amount_sats: @payload[:amount])
|
||||
.lightning_sats_received.deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,16 +1,47 @@
|
||||
class WellKnownController < ApplicationController
|
||||
before_action :require_nostr_enabled, only: [ :nostr ]
|
||||
before_action :allow_cross_origin_requests, only: [ :nostr ]
|
||||
|
||||
layout false
|
||||
|
||||
def nostr
|
||||
http_status :unprocessable_entity and return if params[:name].blank?
|
||||
domain = request.headers["X-Forwarded-Host"].presence || Setting.primary_domain
|
||||
@user = User.where(cn: params[:name], ou: domain).first
|
||||
http_status :not_found and return if @user.nil? || @user.nostr_pubkey.blank?
|
||||
relay_url = Setting.nostr_relay_url.presence
|
||||
|
||||
if params[:name] == "_"
|
||||
if domain == Setting.primary_domain
|
||||
# pubkey for the primary domain without a username (e.g. kosmos.org)
|
||||
res = { names: { "_": Setting.nostr_public_key_primary_domain.presence || Setting.nostr_public_key } }
|
||||
else
|
||||
# pubkey for the akkounts domain without a username (e.g. accounts.kosmos.org)
|
||||
res = { names: { "_": Setting.nostr_public_key } }
|
||||
end
|
||||
|
||||
res[:relays] = { "_" => [ relay_url ] } if relay_url
|
||||
else
|
||||
@user = User.where(cn: params[:name], ou: domain).first
|
||||
http_status :not_found and return if @user.nil? || @user.nostr_pubkey.blank?
|
||||
|
||||
res = { names: { @user.cn => @user.nostr_pubkey } }
|
||||
res[:relays] = { @user.nostr_pubkey => [ relay_url ] } if relay_url
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
names: { "#{@user.cn}": @user.nostr_pubkey }
|
||||
}.to_json
|
||||
render json: res.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def require_nostr_enabled
|
||||
http_status :not_found unless Setting.nostr_enabled?
|
||||
end
|
||||
|
||||
def allow_cross_origin_requests
|
||||
headers['Access-Control-Allow-Origin'] = "*"
|
||||
headers['Access-Control-Allow-Methods'] = "GET"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
module DashboardHelper
|
||||
end
|
||||
@@ -1,2 +0,0 @@
|
||||
module DonationsHelper
|
||||
end
|
||||
@@ -1,2 +0,0 @@
|
||||
module InvitationsHelper
|
||||
end
|
||||
@@ -1,2 +0,0 @@
|
||||
module LnurlpayHelper
|
||||
end
|
||||
12
app/helpers/services_helper.rb
Normal file
12
app/helpers/services_helper.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module ServicesHelper
|
||||
|
||||
def service_human_name(key, category = :external)
|
||||
SERVICES[category][key][:name] || key.to_s
|
||||
end
|
||||
|
||||
def service_display_name(key, category = :external)
|
||||
SERVICES[category][key][:display_name] ||
|
||||
service_human_name(key, category)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,2 +0,0 @@
|
||||
module SettingsHelper
|
||||
end
|
||||
@@ -1,2 +0,0 @@
|
||||
module SignupHelper
|
||||
end
|
||||
@@ -1,2 +0,0 @@
|
||||
module UsersHelper
|
||||
end
|
||||
@@ -1,2 +0,0 @@
|
||||
module WalletHelper
|
||||
end
|
||||
@@ -1,2 +0,0 @@
|
||||
module WelcomeHelper
|
||||
end
|
||||
53
app/javascript/controllers/nostr_login_controller.js
Normal file
53
app/javascript/controllers/nostr_login_controller.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
// Connects to data-controller="nostr-login"
|
||||
export default class extends Controller {
|
||||
static targets = [ "loginForm", "loginButton" ]
|
||||
static values = { site: String, sharedSecret: String }
|
||||
|
||||
connect() {
|
||||
if (window.nostr) {
|
||||
this.loginButtonTarget.disabled = false
|
||||
this.loginFormTarget.classList.remove("hidden")
|
||||
}
|
||||
}
|
||||
|
||||
async login () {
|
||||
this.loginButtonTarget.disabled = true
|
||||
|
||||
try {
|
||||
// Auth based on NIP-42
|
||||
const signedEvent = await window.nostr.signEvent({
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
kind: 22242,
|
||||
tags: [
|
||||
["site", this.siteValue],
|
||||
["challenge", this.sharedSecretValue]
|
||||
],
|
||||
content: ""
|
||||
})
|
||||
|
||||
const res = await fetch("/users/nostr_login", {
|
||||
method: "POST", credentials: "include", headers: {
|
||||
"Accept": "application/json", 'Content-Type': 'application/json',
|
||||
"X-CSRF-Token": this.csrfToken
|
||||
}, body: JSON.stringify({ signed_event: signedEvent })
|
||||
})
|
||||
|
||||
if (res.status === 200) {
|
||||
res.json().then(r => { window.location.href = r.redirect_url })
|
||||
} else {
|
||||
window.location.reload()
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Unable to authenticate:', error.message)
|
||||
} finally {
|
||||
this.loginButtonTarget.disabled = false
|
||||
}
|
||||
}
|
||||
|
||||
get csrfToken () {
|
||||
const element = document.head.querySelector('meta[name="csrf-token"]')
|
||||
return element.getAttribute("content")
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,34 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
import { Nostrify } from "nostrify"
|
||||
|
||||
// Connects to data-controller="settings--nostr-pubkey"
|
||||
export default class extends Controller {
|
||||
static targets = [ "noExtension", "setPubkey", "pubkeyBech32Input" ]
|
||||
static values = { userAddress: String, pubkeyHex: String, sharedSecret: String }
|
||||
static targets = [
|
||||
"noExtension",
|
||||
"setPubkey", "pubkeyBech32Input",
|
||||
"relayList", "relayListStatus",
|
||||
"profileStatusNip05", "profileStatusLud16"
|
||||
]
|
||||
static values = {
|
||||
userAddress: String,
|
||||
pubkeyHex: String,
|
||||
site: String,
|
||||
sharedSecret: String
|
||||
}
|
||||
|
||||
connect () {
|
||||
if (window.nostr) {
|
||||
if (this.hasSetPubkeyTarget) {
|
||||
this.setPubkeyTarget.disabled = false
|
||||
}
|
||||
|
||||
if (this.pubkeyHexValue) {
|
||||
this.discoverUserOnNostr().then(() => {
|
||||
this.renderRelayStatus()
|
||||
this.renderProfileNip05Status()
|
||||
this.renderProfileLud16Status()
|
||||
})
|
||||
}
|
||||
} else {
|
||||
this.noExtensionTarget.classList.remove("hidden")
|
||||
}
|
||||
@@ -19,11 +38,15 @@ export default class extends Controller {
|
||||
this.setPubkeyTarget.disabled = true
|
||||
|
||||
try {
|
||||
// Auth based on NIP-42
|
||||
const signedEvent = await window.nostr.signEvent({
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
kind: 1,
|
||||
tags: [],
|
||||
content: `Connect my public key to ${this.userAddressValue} (confirmation ${this.sharedSecretValue})`
|
||||
kind: 22242,
|
||||
tags: [
|
||||
["site", this.siteValue],
|
||||
["challenge", this.sharedSecretValue]
|
||||
],
|
||||
content: ""
|
||||
})
|
||||
|
||||
const res = await fetch("/settings/set_nostr_pubkey", {
|
||||
@@ -40,8 +63,172 @@ export default class extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
async discoverUserOnNostr () {
|
||||
this.nip65Relays = await this.findUserRelays()
|
||||
this.profile = await this.findUserProfile()
|
||||
}
|
||||
|
||||
async findUserRelays () {
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
const filters = [{ kinds: [10002], authors: [this.pubkeyHexValue], limit: 1 }]
|
||||
const messages = []
|
||||
|
||||
for await (const msg of this.discoveryPool.req(filters, { signal })) {
|
||||
if (msg[0] === 'EVENT') {
|
||||
if (!messages.find(m => m.id === msg[2].id)) {
|
||||
messages.push(msg[2])
|
||||
}
|
||||
}
|
||||
if (msg[0] === 'EOSE') { break }
|
||||
}
|
||||
|
||||
// Close the relay subscription
|
||||
controller.abort()
|
||||
if (messages.length === 0) { return messages }
|
||||
|
||||
const sortedMessages = messages.sort((a, b) => a.createdAt - b.createdAt)
|
||||
const newestMessage = messages[messages.length - 1]
|
||||
|
||||
return newestMessage.tags.filter(t => t[0] === 'r')
|
||||
.map(t => { return { url: t[1], marker: t[2] } })
|
||||
}
|
||||
|
||||
async findUserProfile () {
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
const filters = [{ kinds: [0], authors: [this.pubkeyHexValue], limit: 1 }]
|
||||
const messages = []
|
||||
|
||||
for await (const msg of this.discoveryPool.req(filters, { signal })) {
|
||||
if (msg[0] === 'EVENT') {
|
||||
if (!messages.find(m => m.id === msg[2].id)) {
|
||||
messages.push(msg[2])
|
||||
}
|
||||
}
|
||||
if (msg[0] === 'EOSE') { break }
|
||||
}
|
||||
|
||||
// Close the relay subscription
|
||||
controller.abort()
|
||||
if (messages.length === 0) { return null }
|
||||
|
||||
const sortedMessages = messages.sort((a, b) => a.createdAt - b.createdAt)
|
||||
const newestMessage = messages[messages.length - 1]
|
||||
|
||||
return JSON.parse(newestMessage.content)
|
||||
}
|
||||
|
||||
renderRelayStatus () {
|
||||
let showStatus
|
||||
|
||||
if (this.nip65Relays.length > 0) {
|
||||
if (this.relaysContainAccountsRelay) {
|
||||
showStatus = 'green'
|
||||
} else {
|
||||
showStatus = 'orange'
|
||||
}
|
||||
} else {
|
||||
showStatus = 'red'
|
||||
}
|
||||
// showStatus = 'red'
|
||||
|
||||
this.relayListStatusTarget
|
||||
.querySelector(`.status-${showStatus}`)
|
||||
.classList.remove("hidden")
|
||||
}
|
||||
|
||||
renderProfileNip05Status () {
|
||||
let showStatus
|
||||
|
||||
if (this.profile?.nip05) {
|
||||
if (this.profile.nip05 === this.userAddressValue) {
|
||||
showStatus = 'green'
|
||||
} else {
|
||||
showStatus = 'red'
|
||||
}
|
||||
} else {
|
||||
showStatus = 'orange'
|
||||
}
|
||||
|
||||
this.profileStatusNip05Target
|
||||
.querySelector(`.status-${showStatus}`)
|
||||
.classList.remove("hidden")
|
||||
}
|
||||
|
||||
renderProfileLud16Status () {
|
||||
let showStatus
|
||||
|
||||
if (this.profile?.lud16) {
|
||||
if (this.profile.lud16 === this.userAddressValue) {
|
||||
showStatus = 'green'
|
||||
} else {
|
||||
showStatus = 'red'
|
||||
}
|
||||
} else {
|
||||
showStatus = 'orange'
|
||||
}
|
||||
|
||||
this.profileStatusLud16Target
|
||||
.querySelector(`.status-${showStatus}`)
|
||||
.classList.remove("hidden")
|
||||
}
|
||||
|
||||
// renderRelayList (relays) {
|
||||
// const html = relays.map(relay => `
|
||||
// <li class="flex items-center justify-between p-2 border-b">
|
||||
// <span>${relay.url}</span>
|
||||
// <button
|
||||
// data-action="click->list#handleItemClick"
|
||||
// data-item="${relay.url}"
|
||||
// class="bg-blue-500 text-white px-3 py-1 rounded">
|
||||
// Action
|
||||
// </button>
|
||||
// </li>
|
||||
// `).join("")
|
||||
//
|
||||
// this.relayListTarget.innerHTML = html
|
||||
// }
|
||||
|
||||
get csrfToken () {
|
||||
const element = document.head.querySelector('meta[name="csrf-token"]')
|
||||
return element.getAttribute("content")
|
||||
}
|
||||
|
||||
// Used to find a user's profile and relays
|
||||
get discoveryRelays () {
|
||||
return [
|
||||
'ws://localhost:4777',
|
||||
'wss://nostr.kosmos.org',
|
||||
'wss://purplepag.es',
|
||||
// 'wss://relay.nostr.band',
|
||||
// 'wss://njump.me',
|
||||
// 'wss://relay.damus.io',
|
||||
// 'wss://nos.lol',
|
||||
// 'wss://eden.nostr.land',
|
||||
// 'wss://relay.snort.social',
|
||||
// 'wss://nostr.wine',
|
||||
// 'wss://relay.primal.net',
|
||||
// 'wss://nostr.bitcoiner.social',
|
||||
]
|
||||
}
|
||||
|
||||
get discoveryPool () {
|
||||
if (!this._discoveryPool) {
|
||||
this._discoveryPool = new Nostrify.NPool({
|
||||
open: (url) => new Nostrify.NRelay1(url),
|
||||
reqRouter: async (filters) => new Map(
|
||||
this.discoveryRelays.map(relayUrl => [ relayUrl, filters ])
|
||||
),
|
||||
eventRouter: async (event) => [],
|
||||
})
|
||||
}
|
||||
|
||||
return this._discoveryPool
|
||||
}
|
||||
|
||||
get relaysContainAccountsRelay () {
|
||||
// TODO use URL from view/settings
|
||||
return !!this.nip65Relays.find(r => r.url.match('wss://nostr.kosmos.org'))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class CreateLdapUserJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(username, domain, email, hashed_pw)
|
||||
def perform(username:, domain:, email:, hashed_pw:, confirmed: false)
|
||||
dn = "cn=#{username},ou=#{domain},cn=users,dc=kosmos,dc=org"
|
||||
attr = {
|
||||
objectclass: ["top", "account", "person", "extensibleObject"],
|
||||
@@ -12,6 +12,10 @@ class CreateLdapUserJob < ApplicationJob
|
||||
userPassword: hashed_pw
|
||||
}
|
||||
|
||||
if confirmed
|
||||
attr[:serviceEnabled] = Setting.default_services
|
||||
end
|
||||
|
||||
ldap_client.add(dn: dn, attributes: attr)
|
||||
end
|
||||
|
||||
|
||||
7
app/jobs/nostr_publish_event_job.rb
Normal file
7
app/jobs/nostr_publish_event_job.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class NostrPublishEventJob < ApplicationJob
|
||||
queue_as :nostr
|
||||
|
||||
def perform(event:, relay_url:)
|
||||
NostrManager::PublishEvent.call(event: event, relay_url: relay_url)
|
||||
end
|
||||
end
|
||||
@@ -2,8 +2,8 @@ class XmppExchangeContactsJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(inviter, invitee)
|
||||
return unless inviter.services_enabled.include?("xmpp") &&
|
||||
invitee.services_enabled.include?("xmpp") &&
|
||||
return unless inviter.service_enabled?(:ejabberd) &&
|
||||
invitee.service_enabled?(:ejabberd) &&
|
||||
inviter.preferences[:xmpp_exchange_contacts_with_invitees]
|
||||
|
||||
ejabberd = EjabberdApiClient.new
|
||||
|
||||
24
app/models/concerns/settings/btcpay_settings.rb
Normal file
24
app/models/concerns/settings/btcpay_settings.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
module Settings
|
||||
module BtcpaySettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :btcpay_api_url, type: :string,
|
||||
default: ENV["BTCPAY_API_URL"].presence
|
||||
|
||||
field :btcpay_enabled, type: :boolean,
|
||||
default: ENV["BTCPAY_API_URL"].present?
|
||||
|
||||
field :btcpay_public_url, type: :string,
|
||||
default: ENV["BTCPAY_PUBLIC_URL"].presence
|
||||
|
||||
field :btcpay_store_id, type: :string,
|
||||
default: ENV["BTCPAY_STORE_ID"].presence
|
||||
|
||||
field :btcpay_auth_token, type: :string,
|
||||
default: ENV["BTCPAY_AUTH_TOKEN"].presence
|
||||
|
||||
field :btcpay_publish_wallet_balances, type: :boolean, default: true
|
||||
end
|
||||
end
|
||||
end
|
||||
16
app/models/concerns/settings/discourse_settings.rb
Normal file
16
app/models/concerns/settings/discourse_settings.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
module Settings
|
||||
module DiscourseSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :discourse_public_url, type: :string,
|
||||
default: ENV["DISCOURSE_PUBLIC_URL"].presence
|
||||
|
||||
field :discourse_enabled, type: :boolean,
|
||||
default: ENV["DISCOURSE_PUBLIC_URL"].present?
|
||||
|
||||
field :discourse_connect_secret, type: :string,
|
||||
default: ENV["DISCOURSE_CONNECT_SECRET"].presence
|
||||
end
|
||||
end
|
||||
end
|
||||
13
app/models/concerns/settings/drone_ci_settings.rb
Normal file
13
app/models/concerns/settings/drone_ci_settings.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Settings
|
||||
module DroneCiSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :droneci_public_url, type: :string,
|
||||
default: ENV["DRONECI_PUBLIC_URL"].presence
|
||||
|
||||
field :droneci_enabled, type: :boolean,
|
||||
default: ENV["DRONECI_PUBLIC_URL"].present?
|
||||
end
|
||||
end
|
||||
end
|
||||
19
app/models/concerns/settings/ejabberd_settings.rb
Normal file
19
app/models/concerns/settings/ejabberd_settings.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Settings
|
||||
module EjabberdSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :ejabberd_enabled, type: :boolean,
|
||||
default: ENV["EJABBERD_API_URL"].present?
|
||||
|
||||
field :ejabberd_api_url, type: :string,
|
||||
default: ENV["EJABBERD_API_URL"].presence
|
||||
|
||||
field :ejabberd_admin_url, type: :string,
|
||||
default: ENV["EJABBERD_ADMIN_URL"].presence
|
||||
|
||||
field :ejabberd_buddy_roster, type: :string,
|
||||
default: "Buddies"
|
||||
end
|
||||
end
|
||||
end
|
||||
28
app/models/concerns/settings/email_settings.rb
Normal file
28
app/models/concerns/settings/email_settings.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module Settings
|
||||
module EmailSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :email_enabled, type: :boolean,
|
||||
default: ENV["EMAIL_SMTP_HOST"].present?
|
||||
|
||||
# field :email_smtp_host, type: :string,
|
||||
# default: ENV["EMAIL_SMTP_HOST"].presence
|
||||
#
|
||||
# field :email_smtp_port, type: :string,
|
||||
# default: ENV["EMAIL_SMTP_PORT"].presence || 587
|
||||
#
|
||||
# field :email_smtp_enable_starttls, type: :string,
|
||||
# default: ENV["EMAIL_SMTP_PORT"].presence || true
|
||||
#
|
||||
# field :email_auth_method, type: :string,
|
||||
# default: ENV["EMAIL_AUTH_METHOD"].presence || "plain"
|
||||
#
|
||||
# field :email_imap_host, type: :string,
|
||||
# default: ENV["EMAIL_IMAP_HOST"].presence
|
||||
#
|
||||
# field :email_imap_port, type: :string,
|
||||
# default: ENV["EMAIL_IMAP_PORT"].presence || 993
|
||||
end
|
||||
end
|
||||
end
|
||||
34
app/models/concerns/settings/general_settings.rb
Normal file
34
app/models/concerns/settings/general_settings.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
module Settings
|
||||
module GeneralSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :primary_domain, type: :string,
|
||||
default: ENV["PRIMARY_DOMAIN"].presence
|
||||
|
||||
field :accounts_domain, type: :string,
|
||||
default: ENV["AKKOUNTS_DOMAIN"].presence
|
||||
|
||||
#
|
||||
# Internal services
|
||||
#
|
||||
|
||||
field :redis_url, type: :string,
|
||||
default: ENV["REDIS_URL"] || "redis://localhost:6379/0"
|
||||
|
||||
field :s3_enabled, type: :boolean,
|
||||
default: ENV["S3_ENABLED"] && ENV["S3_ENABLED"].to_s != "false"
|
||||
|
||||
field :sentry_enabled, type: :boolean, readonly: true,
|
||||
default: ENV["SENTRY_DSN"].present?
|
||||
|
||||
#
|
||||
# Registrations
|
||||
#
|
||||
|
||||
field :reserved_usernames, type: :array, default: %w[
|
||||
account accounts donations mail webmaster support
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
13
app/models/concerns/settings/gitea_settings.rb
Normal file
13
app/models/concerns/settings/gitea_settings.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Settings
|
||||
module GiteaSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :gitea_public_url, type: :string,
|
||||
default: ENV["GITEA_PUBLIC_URL"].presence
|
||||
|
||||
field :gitea_enabled, type: :boolean,
|
||||
default: ENV["GITEA_PUBLIC_URL"].present?
|
||||
end
|
||||
end
|
||||
end
|
||||
25
app/models/concerns/settings/lightning_network_settings.rb
Normal file
25
app/models/concerns/settings/lightning_network_settings.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Settings
|
||||
module LightningNetworkSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :lndhub_api_url, type: :string,
|
||||
default: ENV["LNDHUB_API_URL"].presence
|
||||
|
||||
field :lndhub_enabled, type: :boolean,
|
||||
default: ENV["LNDHUB_API_URL"].present?
|
||||
|
||||
field :lndhub_admin_token, type: :string,
|
||||
default: ENV["LNDHUB_ADMIN_TOKEN"].presence
|
||||
|
||||
field :lndhub_admin_enabled, type: :boolean,
|
||||
default: ENV["LNDHUB_ADMIN_UI"] || false
|
||||
|
||||
field :lndhub_public_key, type: :string,
|
||||
default: (ENV["LNDHUB_PUBLIC_KEY"] || "")
|
||||
|
||||
field :lndhub_keysend_enabled, type: :boolean,
|
||||
default: -> { self.lndhub_public_key.present? }
|
||||
end
|
||||
end
|
||||
end
|
||||
16
app/models/concerns/settings/mastodon_settings.rb
Normal file
16
app/models/concerns/settings/mastodon_settings.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
module Settings
|
||||
module MastodonSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :mastodon_public_url, type: :string,
|
||||
default: ENV["MASTODON_PUBLIC_URL"].presence
|
||||
|
||||
field :mastodon_enabled, type: :boolean,
|
||||
default: ENV["MASTODON_PUBLIC_URL"].present?
|
||||
|
||||
field :mastodon_address_domain, type: :string,
|
||||
default: ENV["MASTODON_ADDRESS_DOMAIN"].presence || self.primary_domain
|
||||
end
|
||||
end
|
||||
end
|
||||
13
app/models/concerns/settings/media_wiki_settings.rb
Normal file
13
app/models/concerns/settings/media_wiki_settings.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Settings
|
||||
module MediaWikiSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :mediawiki_public_url, type: :string,
|
||||
default: ENV["MEDIAWIKI_PUBLIC_URL"].presence
|
||||
|
||||
field :mediawiki_enabled, type: :boolean,
|
||||
default: ENV["MEDIAWIKI_PUBLIC_URL"].present?
|
||||
end
|
||||
end
|
||||
end
|
||||
25
app/models/concerns/settings/nostr_settings.rb
Normal file
25
app/models/concerns/settings/nostr_settings.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Settings
|
||||
module NostrSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :nostr_enabled, type: :boolean,
|
||||
default: ENV["NOSTR_PRIVATE_KEY"].present?
|
||||
|
||||
field :nostr_private_key, type: :string,
|
||||
default: ENV["NOSTR_PRIVATE_KEY"].presence
|
||||
|
||||
field :nostr_public_key, type: :string,
|
||||
default: ENV["NOSTR_PUBLIC_KEY"].presence
|
||||
|
||||
field :nostr_public_key_primary_domain, type: :string,
|
||||
default: ENV["NOSTR_PUBLIC_KEY_PRIMARY_DOMAIN"].presence
|
||||
|
||||
field :nostr_relay_url, type: :string,
|
||||
default: ENV["NOSTR_RELAY_URL"].presence
|
||||
|
||||
field :nostr_zaps_relay_limit, type: :integer,
|
||||
default: 12
|
||||
end
|
||||
end
|
||||
end
|
||||
9
app/models/concerns/settings/open_collective_settings.rb
Normal file
9
app/models/concerns/settings/open_collective_settings.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
module Settings
|
||||
module OpenCollectiveSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :opencollective_enabled, type: :boolean, default: true
|
||||
end
|
||||
end
|
||||
end
|
||||
16
app/models/concerns/settings/remote_storage_settings.rb
Normal file
16
app/models/concerns/settings/remote_storage_settings.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
module Settings
|
||||
module RemoteStorageSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :remotestorage_enabled, type: :boolean,
|
||||
default: ENV["RS_STORAGE_URL"].present?
|
||||
|
||||
field :rs_storage_url, type: :string,
|
||||
default: ENV["RS_STORAGE_URL"].presence
|
||||
|
||||
field :rs_redis_url, type: :string,
|
||||
default: ENV["RS_REDIS_URL"] || "redis://localhost:6379/1"
|
||||
end
|
||||
end
|
||||
end
|
||||
11
app/models/concerns/settings/xmpp_settings.rb
Normal file
11
app/models/concerns/settings/xmpp_settings.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
module Settings
|
||||
module XmppSettings
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
field :xmpp_default_rooms, type: :array, default: []
|
||||
field :xmpp_autojoin_default_rooms, type: :boolean, default: false
|
||||
field :xmpp_notifications_from_address, type: :string, default: primary_domain
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,208 +2,30 @@
|
||||
class Setting < RailsSettings::Base
|
||||
cache_prefix { "v1" }
|
||||
|
||||
field :primary_domain, type: :string,
|
||||
default: ENV["PRIMARY_DOMAIN"].presence
|
||||
Dir[Rails.root.join('app', 'models', 'concerns', 'settings', '*.rb')].each do |file|
|
||||
require file
|
||||
end
|
||||
|
||||
field :accounts_domain, type: :string,
|
||||
default: ENV["AKKOUNTS_DOMAIN"].presence
|
||||
include Settings::GeneralSettings
|
||||
include Settings::BtcpaySettings
|
||||
include Settings::DiscourseSettings
|
||||
include Settings::DroneCiSettings
|
||||
include Settings::EjabberdSettings
|
||||
include Settings::EmailSettings
|
||||
include Settings::GiteaSettings
|
||||
include Settings::LightningNetworkSettings
|
||||
include Settings::MastodonSettings
|
||||
include Settings::MediaWikiSettings
|
||||
include Settings::NostrSettings
|
||||
include Settings::OpenCollectiveSettings
|
||||
include Settings::RemoteStorageSettings
|
||||
include Settings::XmppSettings
|
||||
|
||||
#
|
||||
# Internal services
|
||||
#
|
||||
def self.available_services
|
||||
known_services = SERVICES[:external].keys
|
||||
known_services.select {|s| Setting.send "#{s}_enabled?" }
|
||||
end
|
||||
|
||||
field :redis_url, type: :string,
|
||||
default: ENV["REDIS_URL"] || "redis://localhost:6379/0"
|
||||
|
||||
field :s3_enabled, type: :boolean,
|
||||
default: ENV["S3_ENABLED"] && ENV["S3_ENABLED"].to_s != "false"
|
||||
|
||||
#
|
||||
# Registrations
|
||||
#
|
||||
|
||||
field :reserved_usernames, type: :array, default: %w[
|
||||
account accounts donations mail webmaster support
|
||||
]
|
||||
|
||||
#
|
||||
# XMPP
|
||||
#
|
||||
|
||||
field :xmpp_default_rooms, type: :array, default: []
|
||||
field :xmpp_autojoin_default_rooms, type: :boolean, default: false
|
||||
field :xmpp_notifications_from_address, type: :string, default: primary_domain
|
||||
|
||||
#
|
||||
# Sentry
|
||||
#
|
||||
|
||||
field :sentry_enabled, type: :boolean, readonly: true,
|
||||
default: ENV["SENTRY_DSN"].present?
|
||||
|
||||
#
|
||||
# BTCPay Server
|
||||
#
|
||||
|
||||
field :btcpay_api_url, type: :string,
|
||||
default: ENV["BTCPAY_API_URL"].presence
|
||||
|
||||
field :btcpay_enabled, type: :boolean,
|
||||
default: ENV["BTCPAY_API_URL"].present?
|
||||
|
||||
field :btcpay_public_url, type: :string,
|
||||
default: ENV["BTCPAY_PUBLIC_URL"].presence
|
||||
|
||||
field :btcpay_store_id, type: :string,
|
||||
default: ENV["BTCPAY_STORE_ID"].presence
|
||||
|
||||
field :btcpay_auth_token, type: :string,
|
||||
default: ENV["BTCPAY_AUTH_TOKEN"].presence
|
||||
|
||||
field :btcpay_publish_wallet_balances, type: :boolean, default: true
|
||||
|
||||
#
|
||||
# Discourse
|
||||
#
|
||||
|
||||
field :discourse_public_url, type: :string,
|
||||
default: ENV["DISCOURSE_PUBLIC_URL"].presence
|
||||
|
||||
field :discourse_enabled, type: :boolean,
|
||||
default: ENV["DISCOURSE_PUBLIC_URL"].present?
|
||||
|
||||
field :discourse_connect_secret, type: :string,
|
||||
default: ENV["DISCOURSE_CONNECT_SECRET"].presence
|
||||
|
||||
#
|
||||
# Drone CI
|
||||
#
|
||||
|
||||
field :droneci_public_url, type: :string,
|
||||
default: ENV["DRONECI_PUBLIC_URL"].presence
|
||||
|
||||
field :droneci_enabled, type: :boolean,
|
||||
default: ENV["DRONECI_PUBLIC_URL"].present?
|
||||
|
||||
#
|
||||
# ejabberd
|
||||
#
|
||||
|
||||
field :ejabberd_enabled, type: :boolean,
|
||||
default: ENV["EJABBERD_API_URL"].present?
|
||||
|
||||
field :ejabberd_api_url, type: :string,
|
||||
default: ENV["EJABBERD_API_URL"].presence
|
||||
|
||||
field :ejabberd_admin_url, type: :string,
|
||||
default: ENV["EJABBERD_ADMIN_URL"].presence
|
||||
|
||||
field :ejabberd_buddy_roster, type: :string,
|
||||
default: "Buddies"
|
||||
|
||||
#
|
||||
# Gitea
|
||||
#
|
||||
|
||||
field :gitea_public_url, type: :string,
|
||||
default: ENV["GITEA_PUBLIC_URL"].presence
|
||||
|
||||
field :gitea_enabled, type: :boolean,
|
||||
default: ENV["GITEA_PUBLIC_URL"].present?
|
||||
|
||||
#
|
||||
# Lightning Network
|
||||
#
|
||||
|
||||
field :lndhub_api_url, type: :string,
|
||||
default: ENV["LNDHUB_API_URL"].presence
|
||||
|
||||
field :lndhub_enabled, type: :boolean,
|
||||
default: ENV["LNDHUB_API_URL"].present?
|
||||
|
||||
field :lndhub_admin_token, type: :string,
|
||||
default: ENV["LNDHUB_ADMIN_TOKEN"].presence
|
||||
|
||||
field :lndhub_admin_enabled, type: :boolean,
|
||||
default: ENV["LNDHUB_ADMIN_UI"] || false
|
||||
|
||||
field :lndhub_public_key, type: :string,
|
||||
default: (ENV["LNDHUB_PUBLIC_KEY"] || "")
|
||||
|
||||
field :lndhub_keysend_enabled, type: :boolean,
|
||||
default: -> { self.lndhub_public_key.present? }
|
||||
|
||||
#
|
||||
# Mastodon
|
||||
#
|
||||
|
||||
field :mastodon_public_url, type: :string,
|
||||
default: ENV["MASTODON_PUBLIC_URL"].presence
|
||||
|
||||
field :mastodon_enabled, type: :boolean,
|
||||
default: ENV["MASTODON_PUBLIC_URL"].present?
|
||||
|
||||
field :mastodon_address_domain, type: :string,
|
||||
default: ENV["MASTODON_ADDRESS_DOMAIN"].presence || self.primary_domain
|
||||
|
||||
#
|
||||
# MediaWiki
|
||||
#
|
||||
|
||||
field :mediawiki_public_url, type: :string,
|
||||
default: ENV["MEDIAWIKI_PUBLIC_URL"].presence
|
||||
|
||||
field :mediawiki_enabled, type: :boolean,
|
||||
default: ENV["MEDIAWIKI_PUBLIC_URL"].present?
|
||||
|
||||
#
|
||||
# Nostr
|
||||
#
|
||||
|
||||
field :nostr_enabled, type: :boolean, default: false
|
||||
|
||||
#
|
||||
# OpenCollective
|
||||
#
|
||||
|
||||
field :opencollective_enabled, type: :boolean, default: true
|
||||
|
||||
#
|
||||
# RemoteStorage
|
||||
#
|
||||
|
||||
field :remotestorage_enabled, type: :boolean,
|
||||
default: ENV["RS_STORAGE_URL"].present?
|
||||
|
||||
field :rs_storage_url, type: :string,
|
||||
default: ENV["RS_STORAGE_URL"].presence
|
||||
|
||||
field :rs_redis_url, type: :string,
|
||||
default: ENV["RS_REDIS_URL"] || "redis://localhost:6379/1"
|
||||
|
||||
|
||||
#
|
||||
# E-Mail Service
|
||||
#
|
||||
|
||||
field :email_enabled, type: :boolean,
|
||||
default: ENV["EMAIL_SMTP_HOST"].present?
|
||||
|
||||
# field :email_smtp_host, type: :string,
|
||||
# default: ENV["EMAIL_SMTP_HOST"].presence
|
||||
#
|
||||
# field :email_smtp_port, type: :string,
|
||||
# default: ENV["EMAIL_SMTP_PORT"].presence || 587
|
||||
#
|
||||
# field :email_smtp_enable_starttls, type: :string,
|
||||
# default: ENV["EMAIL_SMTP_PORT"].presence || true
|
||||
#
|
||||
# field :email_auth_method, type: :string,
|
||||
# default: ENV["EMAIL_AUTH_METHOD"].presence || "plain"
|
||||
#
|
||||
# field :email_imap_host, type: :string,
|
||||
# default: ENV["EMAIL_IMAP_HOST"].presence
|
||||
#
|
||||
# field :email_imap_port, type: :string,
|
||||
# default: ENV["EMAIL_IMAP_PORT"].presence || 993
|
||||
field :default_services, type: :array,
|
||||
default: self.available_services
|
||||
end
|
||||
|
||||
@@ -17,16 +17,15 @@ class User < ApplicationRecord
|
||||
has_one :invitation, inverse_of: :invitee, foreign_key: 'invited_user_id'
|
||||
has_one :inviter, through: :invitation, source: :user
|
||||
has_many :invitees, through: :invitations
|
||||
|
||||
has_many :donations, dependent: :nullify
|
||||
has_many :remote_storage_authorizations
|
||||
has_many :zaps
|
||||
|
||||
has_one :lndhub_user, class_name: "LndhubUser", inverse_of: "user",
|
||||
primary_key: "ln_account", foreign_key: "login"
|
||||
|
||||
has_many :accounts, through: :lndhub_user
|
||||
|
||||
has_many :remote_storage_authorizations
|
||||
|
||||
#
|
||||
# Validations
|
||||
#
|
||||
@@ -50,8 +49,6 @@ class User < ApplicationRecord
|
||||
validates_length_of :display_name, minimum: 3, maximum: 35, allow_blank: true,
|
||||
if: -> { defined?(@display_name) }
|
||||
|
||||
validates_uniqueness_of :nostr_pubkey, allow_blank: true
|
||||
|
||||
validate :acceptable_avatar
|
||||
|
||||
#
|
||||
@@ -95,9 +92,7 @@ class User < ApplicationRecord
|
||||
LdapManager::UpdateEmail.call(dn: self.dn, address: self.email)
|
||||
else
|
||||
# E-Mail from signup confirmed (i.e. account activation)
|
||||
|
||||
# TODO Make configurable, only activate globally enabled services
|
||||
enable_service %w[ discourse gitea mediawiki xmpp ]
|
||||
enable_default_services
|
||||
|
||||
# TODO enable in development when we have easy setup of ejabberd etc.
|
||||
return if Rails.env.development? || !Setting.ejabberd_enabled?
|
||||
@@ -135,7 +130,7 @@ class User < ApplicationRecord
|
||||
|
||||
def mastodon_address
|
||||
return nil unless Setting.mastodon_enabled?
|
||||
"#{self.cn}@#{Setting.mastodon_address_domain}"
|
||||
"#{self.cn.gsub("-", "_")}@#{Setting.mastodon_address_domain}"
|
||||
end
|
||||
|
||||
def valid_attribute?(attribute_name)
|
||||
@@ -143,10 +138,8 @@ class User < ApplicationRecord
|
||||
self.errors[attribute_name].blank?
|
||||
end
|
||||
|
||||
def ln_create_invoice(payload)
|
||||
lndhub = Lndhub.new
|
||||
lndhub.authenticate self
|
||||
lndhub.addinvoice payload
|
||||
def enable_default_services
|
||||
enable_service Setting.default_services
|
||||
end
|
||||
|
||||
def dn
|
||||
@@ -163,30 +156,8 @@ class User < ApplicationRecord
|
||||
@display_name ||= ldap_entry[:display_name]
|
||||
end
|
||||
|
||||
def avatar
|
||||
@avatar_base64 ||= LdapManager::FetchAvatar.call(cn: cn)
|
||||
end
|
||||
|
||||
def services_enabled
|
||||
ldap_entry[:service] || []
|
||||
end
|
||||
|
||||
def enable_service(service)
|
||||
current_services = services_enabled
|
||||
new_services = Array(service).map(&:to_s)
|
||||
services = (current_services + new_services).uniq
|
||||
ldap.replace_attribute(dn, :service, services)
|
||||
end
|
||||
|
||||
def disable_service(service)
|
||||
current_services = services_enabled
|
||||
disabled_services = Array(service).map(&:to_s)
|
||||
services = (current_services - disabled_services).uniq
|
||||
ldap.replace_attribute(dn, :service, services)
|
||||
end
|
||||
|
||||
def disable_all_services
|
||||
ldap.delete_attribute(dn,:service)
|
||||
def nostr_pubkey
|
||||
@nostr_pubkey ||= ldap_entry[:nostr_key]
|
||||
end
|
||||
|
||||
def nostr_pubkey_bech32
|
||||
@@ -194,6 +165,36 @@ class User < ApplicationRecord
|
||||
Nostr::PublicKey.new(nostr_pubkey).to_bech32
|
||||
end
|
||||
|
||||
def avatar
|
||||
@avatar_base64 ||= LdapManager::FetchAvatar.call(cn: cn)
|
||||
end
|
||||
|
||||
def services_enabled
|
||||
ldap_entry[:services_enabled] || []
|
||||
end
|
||||
|
||||
def service_enabled?(name)
|
||||
services_enabled.map(&:to_sym).include?(name.to_sym)
|
||||
end
|
||||
|
||||
def enable_service(service)
|
||||
current_services = services_enabled
|
||||
new_services = Array(service).map(&:to_s)
|
||||
services = (current_services + new_services).uniq.sort
|
||||
ldap.replace_attribute(dn, :serviceEnabled, services)
|
||||
end
|
||||
|
||||
def disable_service(service)
|
||||
current_services = services_enabled
|
||||
disabled_services = Array(service).map(&:to_s)
|
||||
services = (current_services - disabled_services).uniq.sort
|
||||
ldap.replace_attribute(dn, :serviceEnabled, services)
|
||||
end
|
||||
|
||||
def disable_all_services
|
||||
ldap.delete_attribute(dn,:service)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ldap
|
||||
|
||||
@@ -26,4 +26,8 @@ class UserPreferences
|
||||
end
|
||||
hash.stringify_keys!.to_h
|
||||
end
|
||||
|
||||
def self.pref_keys
|
||||
DEFAULT_PREFS.keys.map(&:to_sym)
|
||||
end
|
||||
end
|
||||
|
||||
20
app/models/zap.rb
Normal file
20
app/models/zap.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
class Zap < ApplicationRecord
|
||||
belongs_to :user
|
||||
|
||||
scope :settled, -> { where.not(settled_at: nil) }
|
||||
scope :unpaid, -> { where(settled_at: nil) }
|
||||
|
||||
def request_event
|
||||
nostr_event_from_hash(request)
|
||||
end
|
||||
|
||||
def receipt_event
|
||||
nostr_event_from_hash(receipt)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def nostr_event_from_hash(hash)
|
||||
Nostr::Event.new(**hash.symbolize_keys)
|
||||
end
|
||||
end
|
||||
@@ -35,11 +35,15 @@ class CreateAccount < ApplicationService
|
||||
@invitation.update! invited_user_id: user_id, used_at: DateTime.now
|
||||
end
|
||||
|
||||
# TODO move to confirmation
|
||||
# (and/or add email_confirmed to entry and use in login filter)
|
||||
def add_ldap_document
|
||||
hashed_pw = Devise.ldap_auth_password_builder.call(@password)
|
||||
CreateLdapUserJob.perform_later(@username, @domain, @email, hashed_pw)
|
||||
CreateLdapUserJob.perform_later(
|
||||
username: @username,
|
||||
domain: @domain,
|
||||
email: @email,
|
||||
hashed_pw: hashed_pw,
|
||||
confirmed: @confirmed
|
||||
)
|
||||
end
|
||||
|
||||
def create_lndhub_account(user)
|
||||
|
||||
@@ -9,7 +9,7 @@ module LdapManager
|
||||
attributes = %w{ jpegPhoto }
|
||||
filter = Net::LDAP::Filter.eq("cn", @cn)
|
||||
|
||||
entry = ldap_client.search(base: treebase, filter: filter, attributes: attributes).first
|
||||
entry = client.search(base: treebase, filter: filter, attributes: attributes).first
|
||||
entry.try(:jpegPhoto) ? entry.jpegPhoto.first : nil
|
||||
end
|
||||
end
|
||||
|
||||
18
app/services/ldap_manager/fetch_user_by_nostr_key.rb
Normal file
18
app/services/ldap_manager/fetch_user_by_nostr_key.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module LdapManager
|
||||
class FetchUserByNostrKey < LdapManagerService
|
||||
def initialize(pubkey:)
|
||||
@ou = Setting.primary_domain
|
||||
@pubkey = pubkey
|
||||
end
|
||||
|
||||
def call
|
||||
treebase = "ou=#{@ou},cn=users,#{ldap_suffix}"
|
||||
attributes = %w{ cn }
|
||||
filter = Net::LDAP::Filter.eq("nostrKey", @pubkey)
|
||||
|
||||
entry = client.search(base: treebase, filter: filter, attributes: attributes).first
|
||||
|
||||
User.find_by cn: entry.cn, ou: @ou unless entry.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
16
app/services/ldap_manager/update_nostr_key.rb
Normal file
16
app/services/ldap_manager/update_nostr_key.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
module LdapManager
|
||||
class UpdateNostrKey < LdapManagerService
|
||||
def initialize(dn:, pubkey:)
|
||||
@dn = dn
|
||||
@pubkey = pubkey
|
||||
end
|
||||
|
||||
def call
|
||||
if @pubkey.present?
|
||||
replace_attribute @dn, :nostrKey, @pubkey
|
||||
else
|
||||
delete_attribute @dn, :nostrKey
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,2 @@
|
||||
class LdapManagerService < LdapService
|
||||
def suffix
|
||||
@suffix ||= ENV["LDAP_SUFFIX"] || "dc=kosmos,dc=org"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,41 +1,47 @@
|
||||
class LdapService < ApplicationService
|
||||
def initialize
|
||||
@suffix = ENV["LDAP_SUFFIX"] || "dc=kosmos,dc=org"
|
||||
def modify(dn, operations=[])
|
||||
client.modify dn: dn, operations: operations
|
||||
client.get_operation_result.code
|
||||
end
|
||||
|
||||
def add_attribute(dn, attr, values)
|
||||
ldap_client.add_attribute dn, attr, values
|
||||
client.add_attribute dn, attr, values
|
||||
client.get_operation_result.code
|
||||
end
|
||||
|
||||
def replace_attribute(dn, attr, values)
|
||||
ldap_client.replace_attribute dn, attr, values
|
||||
client.replace_attribute dn, attr, values
|
||||
client.get_operation_result.code
|
||||
end
|
||||
|
||||
def delete_attribute(dn, attr)
|
||||
ldap_client.delete_attribute dn, attr
|
||||
client.delete_attribute dn, attr
|
||||
client.get_operation_result.code
|
||||
end
|
||||
|
||||
def add_entry(dn, attrs, interactive=false)
|
||||
puts "Adding entry: #{dn}" if interactive
|
||||
res = ldap_client.add dn: dn, attributes: attrs
|
||||
puts res.inspect if interactive && !res
|
||||
res
|
||||
puts "Add entry: #{dn}" if interactive
|
||||
client.add dn: dn, attributes: attrs
|
||||
client.get_operation_result.code
|
||||
end
|
||||
|
||||
def delete_entry(dn, interactive=false)
|
||||
puts "Deleting entry: #{dn}" if interactive
|
||||
res = ldap_client.delete dn: dn
|
||||
puts res.inspect if interactive && !res
|
||||
res
|
||||
puts "Delete entry: #{dn}" if interactive
|
||||
client.delete dn: dn
|
||||
client.get_operation_result.code
|
||||
end
|
||||
|
||||
def delete_all_entries!
|
||||
def delete_all_users!
|
||||
delete_all_entries!(objectclass: "person")
|
||||
end
|
||||
|
||||
def delete_all_entries!(objectclass: "*")
|
||||
if Rails.env.production?
|
||||
raise "Mass deletion of entries not allowed in production"
|
||||
end
|
||||
|
||||
filter = Net::LDAP::Filter.eq("objectClass", "*")
|
||||
entries = ldap_client.search(base: @suffix, filter: filter, attributes: %w{dn})
|
||||
filter = Net::LDAP::Filter.eq("objectClass", objectclass)
|
||||
entries = client.search(base: ldap_suffix, filter: filter, attributes: %w{dn})
|
||||
entries.sort_by!{ |e| e.dn.length }.reverse!
|
||||
|
||||
entries.each do |e|
|
||||
@@ -45,18 +51,18 @@ class LdapService < ApplicationService
|
||||
|
||||
def fetch_users(args={})
|
||||
if args[:ou]
|
||||
treebase = "ou=#{args[:ou]},cn=users,#{@suffix}"
|
||||
treebase = "ou=#{args[:ou]},cn=users,#{ldap_suffix}"
|
||||
else
|
||||
treebase = ldap_config["base"]
|
||||
end
|
||||
|
||||
attributes = %w[
|
||||
dn cn uid mail displayName admin service
|
||||
mailRoutingAddress mailpassword
|
||||
dn cn uid mail displayName admin serviceEnabled
|
||||
mailRoutingAddress mailpassword nostrKey
|
||||
]
|
||||
filter = Net::LDAP::Filter.eq("uid", args[:uid] || "*")
|
||||
|
||||
entries = ldap_client.search(base: treebase, filter: filter, attributes: attributes)
|
||||
entries = client.search(base: treebase, filter: filter, attributes: attributes)
|
||||
entries.sort_by! { |e| e.cn[0] }
|
||||
entries = entries.collect do |e|
|
||||
{
|
||||
@@ -64,9 +70,10 @@ class LdapService < ApplicationService
|
||||
mail: e.try(:mail) ? e.mail.first : nil,
|
||||
display_name: e.try(:displayName) ? e.displayName.first : nil,
|
||||
admin: e.try(:admin) ? 'admin' : nil,
|
||||
service: e.try(:service),
|
||||
services_enabled: e.try(:serviceEnabled),
|
||||
email_maildrop: e.try(:mailRoutingAddress),
|
||||
email_password: e.try(:mailpassword)
|
||||
email_password: e.try(:mailpassword),
|
||||
nostr_key: e.try(:nostrKey) ? e.nostrKey.first : nil
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -75,9 +82,9 @@ class LdapService < ApplicationService
|
||||
attributes = %w{dn ou description}
|
||||
filter = Net::LDAP::Filter.eq("objectClass", "organizationalUnit")
|
||||
# filter = Net::LDAP::Filter.eq("objectClass", "*")
|
||||
treebase = "cn=users,#{@suffix}"
|
||||
treebase = "cn=users,#{ldap_suffix}"
|
||||
|
||||
entries = ldap_client.search(base: treebase, filter: filter, attributes: attributes)
|
||||
entries = client.search(base: treebase, filter: filter, attributes: attributes)
|
||||
|
||||
entries.sort_by! { |e| e.ou[0] }
|
||||
|
||||
@@ -91,10 +98,10 @@ class LdapService < ApplicationService
|
||||
end
|
||||
|
||||
def add_organization(ou, description, interactive=false)
|
||||
dn = "ou=#{ou},cn=users,#{@suffix}"
|
||||
dn = "ou=#{ou},cn=users,#{ldap_suffix}"
|
||||
|
||||
aci = <<-EOS
|
||||
(target="ldap:///cn=*,ou=#{ou},cn=users,#{@suffix}")(targetattr="cn || sn || uid || mail || userPassword || nsRole || objectClass") (version 3.0; acl "service-#{ou.gsub(".", "-")}-read-search"; allow (read,search) userdn="ldap:///uid=service,ou=#{ou},cn=applications,#{@suffix}";)
|
||||
(target="ldap:///cn=*,ou=#{ou},cn=users,#{ldap_suffix}")(targetattr="cn || sn || uid || userPassword || mail || mailRoutingAddress || serviceEnabled || nostrKey || nsRole || objectClass") (version 3.0; acl "service-#{ou.gsub(".", "-")}-read-search"; allow (read,search) userdn="ldap:///uid=service,ou=#{ou},cn=applications,#{ldap_suffix}";)
|
||||
EOS
|
||||
|
||||
attrs = {
|
||||
@@ -115,22 +122,22 @@ class LdapService < ApplicationService
|
||||
delete_all_entries!
|
||||
|
||||
user_read_aci = <<-EOS
|
||||
(target="ldap:///#{@suffix}")(targetattr="*") (version 3.0; acl "user-read-search-own-attributes"; allow (read,search) userdn="ldap:///self";)
|
||||
(target="ldap:///#{ldap_suffix}")(targetattr="*") (version 3.0; acl "user-read-search-own-attributes"; allow (read,search) userdn="ldap:///self";)
|
||||
EOS
|
||||
|
||||
add_entry @suffix, {
|
||||
add_entry ldap_suffix, {
|
||||
dc: "kosmos", objectClass: ["top", "domain"], aci: user_read_aci
|
||||
}, true
|
||||
|
||||
add_entry "cn=users,#{@suffix}", {
|
||||
add_entry "cn=users,#{ldap_suffix}", {
|
||||
cn: "users", objectClass: ["top", "organizationalRole"]
|
||||
}, true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ldap_client
|
||||
ldap_client ||= Net::LDAP.new host: ldap_config['host'],
|
||||
def client
|
||||
client ||= Net::LDAP.new host: ldap_config['host'],
|
||||
port: ldap_config['port'],
|
||||
# TODO has to be :simple_tls if TLS is enabled
|
||||
# encryption: ldap_config['ssl'],
|
||||
@@ -144,4 +151,8 @@ class LdapService < ApplicationService
|
||||
def ldap_config
|
||||
ldap_config ||= YAML.load(ERB.new(File.read("#{Rails.root}/config/ldap.yml")).result)[Rails.env]
|
||||
end
|
||||
|
||||
def ldap_suffix
|
||||
@ldap_suffix ||= ENV["LDAP_SUFFIX"] || "dc=kosmos,dc=org"
|
||||
end
|
||||
end
|
||||
|
||||
13
app/services/lndhub_manager/create_user_invoice.rb
Normal file
13
app/services/lndhub_manager/create_user_invoice.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module LndhubManager
|
||||
class CreateUserInvoice < LndhubV2
|
||||
def initialize(user:, payload:)
|
||||
@user = user
|
||||
@payload = payload
|
||||
end
|
||||
|
||||
def call
|
||||
authenticate @user
|
||||
create_invoice @payload
|
||||
end
|
||||
end
|
||||
end
|
||||
25
app/services/nostr_manager/create_zap_receipt.rb
Normal file
25
app/services/nostr_manager/create_zap_receipt.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module NostrManager
|
||||
class CreateZapReceipt < NostrManagerService
|
||||
def initialize(zap:, paid_at:, preimage:)
|
||||
@zap, @paid_at, @preimage = zap, paid_at, preimage
|
||||
end
|
||||
|
||||
def call
|
||||
request_tags = parse_tags(@zap.request_event.tags)
|
||||
|
||||
site_user.create_event(
|
||||
kind: 9735,
|
||||
created_at: @paid_at,
|
||||
content: "",
|
||||
tags: [
|
||||
["p", request_tags[:p].first],
|
||||
["e", request_tags[:e]&.first],
|
||||
["a", request_tags[:a]&.first],
|
||||
["bolt11", @zap.payment_request],
|
||||
["preimage", @preimage],
|
||||
["description", @zap.request_event.to_json]
|
||||
].reject { |t| t[1].nil? }
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
50
app/services/nostr_manager/publish_event.rb
Normal file
50
app/services/nostr_manager/publish_event.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
module NostrManager
|
||||
class PublishEvent < NostrManagerService
|
||||
def initialize(event:, relay_url:)
|
||||
relay_name = URI.parse(relay_url).host
|
||||
@relay = Nostr::Relay.new(url: relay_url, name: relay_name)
|
||||
|
||||
if event.is_a?(Nostr::Event)
|
||||
@event = event
|
||||
else
|
||||
@event = Nostr::Event.new(**event.symbolize_keys)
|
||||
end
|
||||
|
||||
@client = Nostr::Client.new
|
||||
end
|
||||
|
||||
def call
|
||||
client, relay, event = @client, @relay, @event
|
||||
log_prefix = "[nostr][#{relay.name}]"
|
||||
|
||||
thread = Thread.new do
|
||||
client.on :connect do
|
||||
puts "#{log_prefix} Publishing #{event.id}..."
|
||||
client.publish event
|
||||
end
|
||||
|
||||
client.on :error do |e|
|
||||
puts "#{log_prefix} Error: #{e}"
|
||||
puts "#{log_prefix} Closing thread..."
|
||||
thread.exit
|
||||
end
|
||||
|
||||
client.on :message do |m|
|
||||
puts "#{log_prefix} Message: #{m}"
|
||||
msg = JSON.parse(m) rescue []
|
||||
if msg[0] == "OK" && msg[1] == event.id && msg[2]
|
||||
puts "#{log_prefix} Event published. Closing thread..."
|
||||
else
|
||||
puts "#{log_prefix} Unexpected message from relay. Closing thread..."
|
||||
end
|
||||
thread.exit
|
||||
end
|
||||
|
||||
puts "#{log_prefix} Connecting to #{relay.url}..."
|
||||
client.connect relay
|
||||
end
|
||||
|
||||
thread.join
|
||||
end
|
||||
end
|
||||
end
|
||||
24
app/services/nostr_manager/publish_zap_receipt.rb
Normal file
24
app/services/nostr_manager/publish_zap_receipt.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
module NostrManager
|
||||
class PublishZapReceipt < NostrManagerService
|
||||
def initialize(zap:, delayed: true)
|
||||
@zap, @delayed = zap, delayed
|
||||
end
|
||||
|
||||
def call
|
||||
tags = parse_tags(@zap.request_event.tags)
|
||||
relays = tags[:relays].take(Setting.nostr_zaps_relay_limit)
|
||||
|
||||
if Setting.nostr_relay_url.present?
|
||||
relays << Setting.nostr_relay_url
|
||||
end
|
||||
|
||||
relays.uniq.each do |relay_url|
|
||||
if @delayed
|
||||
NostrPublishEventJob.perform_later(event: @zap.receipt, relay_url: relay_url)
|
||||
else
|
||||
NostrManager::PublishEvent.call(event: @zap.receipt_event, relay_url: relay_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,11 +0,0 @@
|
||||
module NostrManager
|
||||
class ValidateId < NostrManagerService
|
||||
def initialize(event:)
|
||||
@event = Nostr::Event.new(**event)
|
||||
end
|
||||
|
||||
def call
|
||||
@event.id == Digest::SHA256.hexdigest(JSON.generate(@event.serialize))
|
||||
end
|
||||
end
|
||||
end
|
||||
18
app/services/nostr_manager/verify_auth.rb
Normal file
18
app/services/nostr_manager/verify_auth.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module NostrManager
|
||||
class VerifyAuth < NostrManagerService
|
||||
def initialize(event:, challenge:)
|
||||
@event = event
|
||||
@challenge_expected = challenge
|
||||
@site_expected = Setting.accounts_domain
|
||||
end
|
||||
|
||||
def call
|
||||
tags = parse_tags(@event.tags)
|
||||
site_given = tags[:site].first
|
||||
challenge_given = tags[:challenge].first
|
||||
|
||||
site_given == @site_expected &&
|
||||
challenge_given == @challenge_expected
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,17 +0,0 @@
|
||||
module NostrManager
|
||||
class VerifySignature < NostrManagerService
|
||||
def initialize(event:)
|
||||
@event = Nostr::Event.new(**event)
|
||||
end
|
||||
|
||||
def call
|
||||
Schnorr.check_sig!(
|
||||
[@event.id].pack('H*'),
|
||||
[@event.pubkey].pack('H*'),
|
||||
[@event.sig].pack('H*')
|
||||
)
|
||||
rescue Schnorr::InvalidSignatureError
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
51
app/services/nostr_manager/verify_zap_request.rb
Normal file
51
app/services/nostr_manager/verify_zap_request.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
module NostrManager
|
||||
class VerifyZapRequest < NostrManagerService
|
||||
def initialize(amount:, event:, lnurl: nil)
|
||||
@amount, @event, @lnurl = amount, event, lnurl
|
||||
end
|
||||
|
||||
# https://github.com/nostr-protocol/nips/blob/27fef638e2460139cc9078427a0aec0ce4470517/57.md#appendix-d-lnurl-server-zap-request-validation
|
||||
def call
|
||||
tags = parse_tags(@event.tags)
|
||||
|
||||
@event.verify_signature &&
|
||||
@event.kind == 9734 &&
|
||||
tags.present? &&
|
||||
valid_p_tag?(tags[:p]) &&
|
||||
valid_e_tag?(tags[:e]) &&
|
||||
valid_a_tag?(tags[:a]) &&
|
||||
valid_amount_tag?(tags[:amount]) &&
|
||||
valid_lnurl_tag?(tags[:lnurl])
|
||||
end
|
||||
|
||||
def valid_p_tag?(tag)
|
||||
return false unless tag.present? && tag.length == 1
|
||||
key = Nostr::PublicKey.new(tag.first) rescue nil
|
||||
key.present?
|
||||
end
|
||||
|
||||
def valid_e_tag?(tag)
|
||||
return true unless tag.present?
|
||||
# TODO validate format of event ID properly
|
||||
tag.length == 1 && tag.first.is_a?(String)
|
||||
end
|
||||
|
||||
def valid_a_tag?(tag)
|
||||
return true unless tag.present?
|
||||
# TODO validate format of event coordinate properly
|
||||
tag.length == 1 && tag.first.is_a?(String)
|
||||
end
|
||||
|
||||
def valid_amount_tag?(tag)
|
||||
return true unless tag.present?
|
||||
amount = tag.first
|
||||
amount.is_a?(String) && amount.to_i == @amount
|
||||
end
|
||||
|
||||
def valid_lnurl_tag?(tag)
|
||||
return true unless tag.present?
|
||||
# TODO validate lnurl matching recipient's lnurlp
|
||||
tag.first.is_a?(String)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,22 @@
|
||||
require "nostr"
|
||||
|
||||
class NostrManagerService < ApplicationService
|
||||
def parse_tags(tags)
|
||||
out = {}
|
||||
tags.each do |tag|
|
||||
out[tag[0].to_sym] = tag[1, tag.length]
|
||||
end
|
||||
out
|
||||
end
|
||||
|
||||
def site_keypair
|
||||
Nostr::KeyPair.new(
|
||||
private_key: Nostr::PrivateKey.new(Setting.nostr_private_key),
|
||||
public_key: Nostr::PublicKey.new(Setting.nostr_public_key)
|
||||
)
|
||||
end
|
||||
|
||||
def site_user
|
||||
Nostr::User.new(keypair: site_keypair)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
<tr>
|
||||
<td class="overflow-ellipsis font-mono"><%= invitation.token %></td>
|
||||
<td><%= invitation.used_at.strftime("%Y-%m-%d (%H:%M UTC)") %></td>
|
||||
<td><%= link_to invitation.user.address, admin_user_path(invitation.user.address), class: "ks-text-link" %></td>
|
||||
<td><%= link_to invitation.invitee.address, admin_user_path(invitation.invitee.address), class: "ks-text-link" %></td>
|
||||
<td><%= link_to invitation.user.cn, admin_user_path(invitation.user.cn), class: "ks-text-link" %></td>
|
||||
<td><%= link_to invitation.invitee.cn, admin_user_path(invitation.invitee.cn), class: "ks-text-link" %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<% if user = @users.find{ |u| u[2] == account.login } %>
|
||||
<%= link_to "#{user[0]}@#{user[1]}", admin_user_path("#{user[0]}@#{user[1]}"), class: "ks-text-link" %>
|
||||
<%= link_to user[0], admin_user_path(user[0]), class: "ks-text-link" %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= number_with_delimiter account.balance.to_i.to_s %></td>
|
||||
|
||||
@@ -9,18 +9,36 @@
|
||||
<%= render partial: "admin/settings/errors", locals: { errors: @errors } %>
|
||||
<% end %>
|
||||
|
||||
<label class="block">
|
||||
<p class="font-bold mb-1">Reserved usernames</p>
|
||||
<p class="text-gray-500">
|
||||
These usernames cannot be registered as accounts:
|
||||
</p>
|
||||
<%= f.text_area :reserved_usernames,
|
||||
value: Setting.reserved_usernames.join("\n"),
|
||||
class: "h-44 mb-2" %>
|
||||
<p class="text-sm text-gray-500">
|
||||
One username per line
|
||||
</p>
|
||||
</label>
|
||||
<ul role="list">
|
||||
<%= render FormElements::FieldsetComponent.new(
|
||||
title: "Reserved usernames",
|
||||
description: "These usernames cannot be registered as accounts."
|
||||
) do %>
|
||||
<%= f.text_area :reserved_usernames,
|
||||
value: Setting.reserved_usernames.join("\n"),
|
||||
class: "h-44 w-60" %>
|
||||
<p class="text-sm text-gray-500">
|
||||
One username per line
|
||||
</p>
|
||||
<% end %>
|
||||
<li>
|
||||
<p class="font-bold mb-1">Default services</p>
|
||||
<p class="text-gray-500">
|
||||
These services are enabled for new users by default after signup.
|
||||
</p>
|
||||
<div class="flex flex-wrap gap-x-6 gap-y-2">
|
||||
<% Setting.available_services.each do |option| %>
|
||||
<div class="md:inline-block">
|
||||
<%= f.check_box :default_services,
|
||||
{ multiple: true, checked: Setting.default_services.include?(option),
|
||||
class: "h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-600 mr-0.5" },
|
||||
option, nil %>
|
||||
<%= f.label "default_services_#{option.parameterize}", service_human_name(option) %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
||||
@@ -7,4 +7,37 @@
|
||||
title: "Enable Nostr integration (experimental)",
|
||||
description: "Allow adding nostr pubkeys and resolve user addresses via NIP-05"
|
||||
) %>
|
||||
<% if Setting.nostr_enabled? %>
|
||||
<%= render FormElements::FieldsetResettableSettingComponent.new(
|
||||
key: :nostr_private_key,
|
||||
type: :password,
|
||||
title: "Private key",
|
||||
description: "The private key of the accounts service, used when publishing events (e.g. zap receipts)"
|
||||
) %>
|
||||
<%= render FormElements::FieldsetResettableSettingComponent.new(
|
||||
key: :nostr_public_key,
|
||||
title: "Public key",
|
||||
description: "The corresponding public key of the accounts service"
|
||||
) %>
|
||||
<%= render FormElements::FieldsetResettableSettingComponent.new(
|
||||
key: :nostr_public_key_primary_domain,
|
||||
title: "Public key for primary domain (NIP-05)",
|
||||
description: "(optional) A different pubkey to announce for the _@#{Setting.primary_domain} Nostr address"
|
||||
) %>
|
||||
<%= render FormElements::FieldsetResettableSettingComponent.new(
|
||||
key: :nostr_relay_url,
|
||||
title: "Relay URL",
|
||||
description: "Websockets URL of a relay associated with #{Setting.primary_domain}"
|
||||
) %>
|
||||
</ul>
|
||||
</section>
|
||||
<section>
|
||||
<h3>Zaps</h3>
|
||||
<ul role="list">
|
||||
<%= render FormElements::FieldsetResettableSettingComponent.new(
|
||||
key: :nostr_zaps_relay_limit,
|
||||
title: "Relay limit",
|
||||
description: "The maximum number of relays to publish zap receipts to"
|
||||
) %>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<h3>RemoteStorage</h3>
|
||||
<p class="text-red-600 mb-8">Feature currently in development.</p>
|
||||
<ul role="list">
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
form: f,
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<th>Invited by</th>
|
||||
<td>
|
||||
<% if @user.inviter %>
|
||||
<%= link_to @user.inviter.address, admin_user_path(@user.inviter.address), class: 'ks-text-link' %>
|
||||
<%= link_to @user.inviter.cn, admin_user_path(@user.inviter.cn), class: 'ks-text-link' %>
|
||||
<% else %>—<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -78,7 +78,7 @@
|
||||
<% if @user.invitees.length > 0 %>
|
||||
<ul class="mb-0">
|
||||
<% @user.invitees.order(cn: :asc).each do |invitee| %>
|
||||
<li class="leading-none mb-2 last:mb-0"><%= link_to invitee.address, admin_user_path(invitee.address), class: 'ks-text-link' %></li>
|
||||
<li class="leading-none mb-2 last:mb-0"><%= link_to invitee.cn, admin_user_path(invitee.cn), class: 'ks-text-link' %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% else %>—<% end %>
|
||||
@@ -124,6 +124,19 @@
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% if Setting.email_enabled %>
|
||||
<tr>
|
||||
<td>E-Mail</td>
|
||||
<td>
|
||||
<%= render FormElements::ToggleComponent.new(
|
||||
enabled: Flipper.enabled?(:email, current_user),
|
||||
input_enabled: false
|
||||
) %>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% if Setting.gitea_enabled %>
|
||||
<tr>
|
||||
<td>Gitea</td>
|
||||
@@ -171,7 +184,7 @@
|
||||
<td>XMPP (ejabberd)</td>
|
||||
<td>
|
||||
<%= render FormElements::ToggleComponent.new(
|
||||
enabled: @services_enabled.include?("xmpp"),
|
||||
enabled: @services_enabled.include?("ejabberd"),
|
||||
input_enabled: false
|
||||
) %>
|
||||
</td>
|
||||
@@ -182,6 +195,33 @@
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% if Setting.nostr_enabled %>
|
||||
<tr>
|
||||
<td>Nostr</td>
|
||||
<td>
|
||||
<%= render FormElements::ToggleComponent.new(
|
||||
enabled: @user.nostr_pubkey.present?,
|
||||
input_enabled: false
|
||||
) %>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<%= link_to "Open profile", "https://njump.me/#{@user.nostr_pubkey_bech32}", class: "btn-sm btn-gray" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% if Setting.remotestorage_enabled %>
|
||||
<tr>
|
||||
<td>remoteStorage</td>
|
||||
<td>
|
||||
<%= render FormElements::ToggleComponent.new(
|
||||
enabled: Flipper.enabled?(:remotestorage, current_user) && @services_enabled.include?("remotestorage"),
|
||||
input_enabled: false
|
||||
) %>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
<p>
|
||||
There's something to do for everyone, especially non-programmers! For
|
||||
example, we need more help with graphics, UI/UX design, and
|
||||
content/copywriting. We also need moderators for social media. And beta
|
||||
testers for our software. The list doesn't end there.
|
||||
content/copywriting. Also, testing any of our software and reporting
|
||||
issues you encounter along the way is very valuable.
|
||||
</p>
|
||||
<p>
|
||||
A good way to get started is to join one of our
|
||||
@@ -43,7 +43,7 @@
|
||||
</p>
|
||||
<p>
|
||||
We have run two 6-month trials so far, with the next trial period
|
||||
starting sometime in Q1 2024. Watch your email for notifications about it!
|
||||
starting sometime soon. Watch your email for notifications about it!
|
||||
</p>
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<div class="services grid grid-cols-1 sm:grid-cols-2 gap-4 sm:gap-6">
|
||||
<% if Setting.ejabberd_enabled? %>
|
||||
<div class="border border-gray-300 rounded-md hover:border-gray-400
|
||||
bg-cover bg-[center_top_-50px] bg-no-repeat
|
||||
bg-[length:86%] bg-[center_top_-40px] bg-no-repeat
|
||||
bg-[url(/img/logos/icon_xmpp.svg)]">
|
||||
<%= link_to services_chat_path,
|
||||
class: "block h-full px-6 py-6 rounded-md" do %>
|
||||
@@ -18,7 +18,7 @@
|
||||
<% end %>
|
||||
<% if Setting.mastodon_enabled? %>
|
||||
<div class="border border-gray-300 rounded-md hover:border-gray-400
|
||||
bg-[length:80%] bg-[right_top_-30px] bg-no-repeat
|
||||
bg-[length:88%] bg-[center_top_-40px] bg-no-repeat
|
||||
bg-[url(/img/logos/icon_mastodon.svg)]">
|
||||
<%= link_to services_mastodon_path, class: "block h-full px-6 py-6 rounded-md" do %>
|
||||
<h3 class="mb-3.5">Mastodon</h3>
|
||||
@@ -30,7 +30,9 @@
|
||||
<% end %>
|
||||
<% if Setting.email_enabled? &&
|
||||
Flipper.enabled?(:email, current_user) %>
|
||||
<div class="border border-gray-300 rounded-md hover:border-gray-400">
|
||||
<div class="border border-gray-300 rounded-md hover:border-gray-400
|
||||
bg-[length:90%] bg-[center_top_-160px] bg-no-repeat
|
||||
bg-[url(/img/logos/icon_mail.svg)]">
|
||||
<%= link_to services_email_path, class: "block h-full px-6 py-6 rounded-md" do %>
|
||||
<h3 class="mb-3.5">E-Mail</h3>
|
||||
<p class="text-gray-600">
|
||||
@@ -39,15 +41,16 @@
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if Setting.discourse_enabled? %>
|
||||
<% if Setting.remotestorage_enabled? &&
|
||||
Flipper.enabled?(:remotestorage, current_user) %>
|
||||
<div class="border border-gray-300 rounded-md hover:border-gray-400
|
||||
bg-[length:95%] bg-center bg-no-repeat
|
||||
bg-[url(/img/logos/icon_discourse.svg)]">
|
||||
<%= link_to "#{Setting.discourse_public_url}/session/sso?return_path=/",
|
||||
bg-[length:80%] bg-[center_top_-156px] bg-no-repeat
|
||||
bg-[url(/img/logos/icon_remotestorage.svg)]">
|
||||
<%= link_to services_storage_path,
|
||||
class: "block h-full px-6 py-6 rounded-md" do %>
|
||||
<h3 class="mb-3.5">Discourse</h3>
|
||||
<h3 class="mb-3.5">Storage</h3>
|
||||
<p class="text-gray-600">
|
||||
Kosmos community forums and user support/help site
|
||||
Sync your data between apps and devices
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -65,21 +68,22 @@
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if Setting.remotestorage_enabled? &&
|
||||
Flipper.enabled?(:remotestorage, current_user) %>
|
||||
<div class="border border-gray-300 rounded-md hover:border-gray-400">
|
||||
<%= link_to services_storage_path,
|
||||
<% if Setting.discourse_enabled? %>
|
||||
<div class="border border-gray-300 rounded-md hover:border-gray-400
|
||||
bg-[length:80%] bg-center bg-no-repeat
|
||||
bg-[url(/img/logos/icon_discourse.svg)]">
|
||||
<%= link_to "#{Setting.discourse_public_url}/session/sso?return_path=/",
|
||||
class: "block h-full px-6 py-6 rounded-md" do %>
|
||||
<h3 class="mb-3.5">Storage</h3>
|
||||
<h3 class="mb-3.5">Discourse</h3>
|
||||
<p class="text-gray-600">
|
||||
Sync your data between apps and devices
|
||||
Community forums and support/help site
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if Setting.gitea_enabled? %>
|
||||
<div class="border border-gray-300 rounded-md hover:border-gray-400
|
||||
bg-cover bg-center bg-no-repeat
|
||||
bg-[length:92%] bg-center bg-no-repeat
|
||||
bg-[url(/img/logos/icon_gitea.png)]">
|
||||
<%= link_to Setting.gitea_public_url,
|
||||
class: "block h-full px-6 py-6 rounded-md" do %>
|
||||
@@ -92,7 +96,7 @@
|
||||
<% end %>
|
||||
<% if Setting.droneci_enabled? %>
|
||||
<div class="border border-gray-300 rounded-md hover:border-gray-400
|
||||
bg-cover bg-[center_top_-70px] bg-no-repeat
|
||||
bg-[length:86%] bg-[center_top_-60px] bg-no-repeat
|
||||
bg-[url(/img/logos/icon_droneci.svg)]">
|
||||
<%= link_to Setting.droneci_public_url,
|
||||
class: "block h-full px-6 py-6 rounded-md" do %>
|
||||
|
||||
@@ -55,4 +55,27 @@
|
||||
<%= f.submit "Log in", class: 'btn-md btn-blue w-full', tabindex: "4" %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<div data-controller="nostr-login"
|
||||
data-nostr-login-target="loginForm"
|
||||
data-nostr-login-site-value="<%= Setting.accounts_domain %>"
|
||||
data-nostr-login-shared-secret-value="<%= session[:shared_secret] %>"
|
||||
class="hidden">
|
||||
<div class="relative my-6">
|
||||
<div class="absolute inset-0 flex items-center" aria-hidden="true">
|
||||
<div class="w-full border-t border-gray-200"></div>
|
||||
</div>
|
||||
<div class="relative flex justify-center">
|
||||
<span class="bg-white px-2 text-sm text-gray-500 italic">or</span>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<button disabled tabindex="5"
|
||||
class="w-full btn-md btn-gray text-purple-600"
|
||||
data-nostr-login-target="loginButton"
|
||||
data-action="nostr-login#login">
|
||||
Log in with Nostr
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
6
app/views/icons/_nostrich-head.html.erb
Normal file
6
app/views/icons/_nostrich-head.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg width="24" height="24" class="icon-nostrich-head <%= custom_class %>" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M3.03377 4.84648C2.38935 5.60878 1.88639 6.49681 1.5799 7.4713C3.32454 7.07836 5.64286 6.98406 6.95527 6.88189C7.36392 5.20013 8.52701 3.91915 10.476 4.0056C11.3169 4.04489 12.0556 4.58714 12.5664 5.42017C12.9436 5.01937 13.4466 4.75218 14.1146 4.65787C14.1617 4.65787 14.2639 4.65001 14.3425 4.65001C12.9593 3.14114 10.9868 2.18237 8.77849 2.18237C8.3777 2.18237 7.98476 2.22167 7.59183 2.28454C7.51324 2.28454 7.41108 2.30026 7.27748 2.33169C7.26962 2.33169 7.2539 2.33169 7.24604 2.33169C7.23818 2.33169 7.23032 2.33169 7.21461 2.33169C5.69001 2.70105 4.54264 2.40242 3.89037 1.51438C3.81964 1.42008 3.54458 1.00357 3.45814 0.272705C2.97876 0.767805 2.66441 1.58511 2.9316 2.45743C3.14379 3.149 3.54458 3.51836 3.97681 3.73054C3.31668 3.76984 2.76657 3.6441 2.21646 3.22759C1.89425 2.98396 1.68992 2.71677 1.352 2.01734C1.03765 2.51244 1.06909 3.06255 1.13195 3.34547C1.21054 3.72268 1.40701 4.14706 1.65849 4.39068C2.04357 4.76789 2.59368 4.85434 3.04162 4.84648H3.03377Z" fill="currentColor"/>
|
||||
<path d="M10.4837 11.3458C11.4602 11.3458 12.2519 9.99116 12.2519 8.32016C12.2519 6.64917 11.4602 5.29456 10.4837 5.29456C9.50711 5.29456 8.71545 6.64917 8.71545 8.32016C8.71545 9.99116 9.50711 11.3458 10.4837 11.3458Z" fill="currentColor"/>
|
||||
<path d="M14.3737 10.615C15.1376 10.615 15.7569 9.53831 15.7569 8.21019C15.7569 6.88207 15.1376 5.80542 14.3737 5.80542C13.6099 5.80542 12.9906 6.88207 12.9906 8.21019C12.9906 9.53831 13.6099 10.615 14.3737 10.615Z" fill="currentColor"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.52542 23.9833C7.53337 23.6314 7.66454 22.5232 8.7864 20.3047C9.2815 19.3381 10.4053 18.0021 11.2462 17.2791C11.6941 16.8862 12.1421 16.5561 12.5822 16.2496C12.8101 16.116 13.0222 15.9745 13.2266 15.8252C16.9076 13.5684 20.157 14.0396 22.8528 14.4306L22.9321 14.4421C22.9321 14.4421 23.5765 12.5246 20.9203 11.5344C19.4743 11 17.7689 10.5677 16.3465 10.2691C16.1422 10.6385 15.8828 10.9528 15.5763 11.1886C15.5721 11.1917 15.5678 11.195 15.5634 11.1983C15.3354 11.3696 14.795 11.7757 13.816 11.6601C13.313 11.5972 12.9279 11.3929 12.6215 11.0943C12.1028 11.9509 11.3562 12.5088 10.4917 12.5874C8.09483 12.7918 6.88458 10.7799 6.806 8.55591C5.00635 8.7288 2.55443 9.83688 1.24988 10.4813L1.25662 22.0396C2.92115 22.6846 5.41819 23.4807 7.52542 23.9833Z" fill="currentColor"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.4 KiB |
3
app/views/icons/_nostrich-n.html.erb
Normal file
3
app/views/icons/_nostrich-n.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg width="24" height="24" class="icon-nostrich-n <%= custom_class %>" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M24 10.4604V23.135C24 23.6117 23.6161 23.9985 23.1429 23.9985H12.8578C12.3847 23.9985 12.0008 23.6117 12.0008 23.135V20.7746C12.0476 17.8812 12.3515 15.1096 12.9894 13.8487C13.3718 13.0904 14.0021 12.6777 14.7262 12.4569C16.0942 12.0426 18.4947 12.3259 19.5135 12.2772C19.5135 12.2772 22.5912 12.4005 22.5912 10.6447C22.5912 9.23147 21.2156 9.34264 21.2156 9.34264C19.6994 9.38223 18.5446 9.27868 17.7963 8.98173C16.5432 8.48528 16.5009 7.57462 16.4963 7.27005C16.4343 3.75228 11.2858 3.33046 6.74939 4.20305C1.78976 5.1533 6.80381 12.3152 6.80381 21.8756V23.1518C6.79474 23.6208 6.41834 24 5.94974 24H0.857089C0.383951 24 0 23.6132 0 23.1365V1.21523C0 0.738579 0.383951 0.351777 0.857089 0.351777H5.64439C6.11753 0.351777 6.50148 0.738579 6.50148 1.21523C6.50148 1.92335 7.29206 2.31777 7.86345 1.90508C9.58519 0.662437 11.7952 0 14.2682 0C19.8083 0 23.997 3.25279 23.997 10.4604H24ZM14.8033 7.88832C14.8033 6.86802 13.9825 6.04112 12.9697 6.04112C11.9569 6.04112 11.1361 6.86802 11.1361 7.88832C11.1361 8.90863 11.9569 9.73553 12.9697 9.73553C13.9825 9.73553 14.8033 8.90863 14.8033 7.88832Z" fill="currentColor"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
3
app/views/icons/_nostrich.html.erb
Normal file
3
app/views/icons/_nostrich.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" class="icon-nostrich <%= custom_class %>" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M17.7084 10.1607C18.1683 13.3466 14.8705 14.0207 12.9733 13.9618C12.8515 13.958 12.7366 14.0173 12.6647 14.1157C12.4684 14.384 12.1547 14.7309 11.9125 14.7309C11.6405 14.7309 11.3957 15.254 11.284 15.5795C11.2723 15.6137 11.3059 15.6452 11.3403 15.634C14.345 14.6584 15.5241 14.3238 16.032 14.4178C16.4421 14.4937 17.209 15.8665 17.5413 16.5434C16.7155 16.5909 16.4402 15.8507 16.2503 15.7178C16.0985 15.6116 16.0415 16.0974 16.032 16.3536C15.8517 16.2587 15.6239 16.1259 15.6049 15.7178C15.5859 15.3098 15.3771 15.4142 15.2157 15.4332C15.0544 15.4521 12.5769 16.2493 12.2067 16.3536C11.8366 16.458 11.4094 16.6004 11.0582 16.8471C10.4697 17.1318 10.09 16.9325 9.98561 16.4485C9.90208 16.0614 10.4444 14.8701 10.726 14.3229C10.3779 14.4526 9.65529 14.7158 9.54898 14.7309C9.44588 14.7457 8.13815 15.7552 7.43879 16.3038C7.398 16.3358 7.37174 16.3827 7.36236 16.4336C7.25047 17.0416 6.89335 17.2118 6.27423 17.5303C5.77602 17.7867 4.036 20.4606 3.14127 21.9041C3.0794 22.0039 2.9886 22.0806 2.8911 22.1461C2.32279 22.5276 1.74399 23.4985 1.50923 23.9737C1.17511 23.0095 1.61048 22.1802 1.86993 21.886C1.75602 21.7873 1.49341 21.8449 1.37634 21.886C1.69907 20.7757 2.82862 20.7757 2.79066 20.7757C2.99948 20.5954 5.44842 17.0938 5.50538 16.9325C5.56187 16.7725 5.46892 16.0242 6.69975 15.6139C6.7193 15.6073 6.73868 15.5984 6.75601 15.5873C7.71493 14.971 8.43427 13.9774 8.67571 13.5542C7.39547 13.4662 5.92943 12.7525 5.16289 12.294C4.99765 12.1952 4.8224 12.1092 4.63108 12.0875C3.58154 11.9687 2.53067 12.6401 2.10723 13.0228C1.93258 12.7799 2.12938 12.0739 2.24961 11.7513C1.82437 11.6905 1.19916 12.308 0.939711 12.6243C0.658747 12.184 0.904907 11.397 1.06311 11.0585C0.501179 11.0737 0.120232 11.3306 0 11.4571C0.465109 7.99343 4.02275 9.00076 4.06259 9.04675C3.87275 8.84937 3.88857 8.59126 3.92021 8.48688C6.0749 8.54381 7.08105 8.18321 7.71702 7.81313C12.7288 5.01374 14.8882 6.73133 15.6856 7.1631C16.4829 7.59487 17.9304 7.77042 18.9318 7.37187C20.1278 6.83097 19.9478 5.43673 19.7054 4.90461C19.4397 4.32101 17.9399 3.51438 17.4084 2.49428C16.8768 1.47418 17.34 0.233672 17.9558 0.0607684C18.5425 -0.103972 18.9615 0.0876835 19.2831 0.378128C19.4974 0.571763 20.0994 0.710259 20.3509 0.800409C20.6024 0.890558 21.0201 1.00918 20.9964 1.08035C20.9726 1.15152 20.5699 1.14202 20.5075 1.14202C20.3794 1.14202 20.2275 1.161 20.3794 1.23217C20.5575 1.30439 20.8263 1.40936 20.955 1.47846C20.9717 1.48744 20.9683 1.51084 20.95 1.51577C20.0765 1.75085 19.2966 1.26578 18.7183 1.82526C18.1298 2.39463 19.3827 2.83114 20.0282 3.51438C20.6736 4.19762 21.3381 5.01372 20.8065 6.87365C20.395 8.31355 18.6703 9.53781 17.7795 10.0167C17.7282 10.0442 17.7001 10.1031 17.7084 10.1607Z" fill="currentColor"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.8 KiB |
@@ -100,6 +100,14 @@
|
||||
["Website", "https://www.thunderbird.net"]
|
||||
]
|
||||
) %>
|
||||
<%= render AppInfoComponent.new(
|
||||
name: "Geary",
|
||||
description: "Built around conversations, for the GNOME desktop",
|
||||
icon_path: "/img/logos/icon_geary.png",
|
||||
links: [
|
||||
["Website", "https://wiki.gnome.org/Apps/Geary"]
|
||||
]
|
||||
) %>
|
||||
</div>
|
||||
<div id="apps-windows" class="hidden grid grid-cols-1 gap-6"
|
||||
data-tabs-target="panel">
|
||||
|
||||
@@ -98,7 +98,17 @@
|
||||
description: "The official Web app",
|
||||
icon_path: "/img/logos/icon_mastodon-2.svg",
|
||||
links: [
|
||||
["Launch", "https://kosmos.social"]
|
||||
["Launch", "https://kosmos.social"],
|
||||
["GitHub", "https://github.com/mastodon/mastodon"]
|
||||
]
|
||||
) %>
|
||||
<%= render AppInfoComponent.new(
|
||||
name: "Phanpy",
|
||||
description: " A slick, feature-rich Web app for mobile and desktop",
|
||||
icon_path: "/img/logos/icon_phanpy.svg",
|
||||
links: [
|
||||
["Launch", "https://phanpy.social"],
|
||||
["GitHub", "https://github.com/cheeaun/phanpy"]
|
||||
]
|
||||
) %>
|
||||
<%= render AppInfoComponent.new(
|
||||
@@ -150,6 +160,15 @@
|
||||
["Google Play", "https://play.google.com/store/apps/details?id=org.joinmastodon.android.sk"]
|
||||
]
|
||||
) %>
|
||||
<%= render AppInfoComponent.new(
|
||||
name: "Phanpy",
|
||||
description: " A slick, feature-rich Web app for mobile and desktop",
|
||||
icon_path: "/img/logos/icon_phanpy.svg",
|
||||
links: [
|
||||
["Launch", "https://phanpy.social"],
|
||||
["GitHub", "https://github.com/cheeaun/phanpy"]
|
||||
]
|
||||
) %>
|
||||
</div>
|
||||
<div class="hidden grid grid-cols-1 gap-6" data-tabs-target="panel">
|
||||
<%= render AppInfoComponent.new(
|
||||
@@ -180,6 +199,15 @@
|
||||
["App Store", "https://apps.apple.com/app/mammoth-for-mastodon/id1667573899"]
|
||||
]
|
||||
) %>
|
||||
<%= render AppInfoComponent.new(
|
||||
name: "Phanpy",
|
||||
description: " A slick, feature-rich Web app for mobile and desktop",
|
||||
icon_path: "/img/logos/icon_phanpy.svg",
|
||||
links: [
|
||||
["Launch", "https://phanpy.social"],
|
||||
["GitHub", "https://github.com/cheeaun/phanpy"]
|
||||
]
|
||||
) %>
|
||||
</div>
|
||||
<div class="hidden grid grid-cols-1 gap-6" data-tabs-target="panel">
|
||||
<%= render AppInfoComponent.new(
|
||||
|
||||
@@ -2,15 +2,162 @@
|
||||
|
||||
<%= render MainSimpleComponent.new do %>
|
||||
<section>
|
||||
<h3 class="mb-10">Connected Apps</h3>
|
||||
<% if @rs_auths.any? %>
|
||||
<div class="w-full grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-y-10 gap-x-12">
|
||||
<% @rs_auths.each do |auth| %>
|
||||
<%= render RsAuthComponent.new(auth: auth) %>
|
||||
<% end %>
|
||||
<p class="mb-6">
|
||||
Store and synchronize your app data across different devices.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<%= render partial: "shared/tabnav_remotestorage" %>
|
||||
|
||||
<section>
|
||||
<h3>Your Storage Address</h3>
|
||||
<p class="mb-6">
|
||||
In order to connect an app to your storage account, give it your address:
|
||||
</p>
|
||||
<p data-controller="clipboard" class="flex items-center gap-1 sm:w-2/5">
|
||||
<img src="/img/logos/icon_remotestorage.svg" class="inline-block h-6 w-6 mr-1">
|
||||
<input type="text" id="user_address" class="grow"
|
||||
value=<%= current_user.address %> disabled="disabled"
|
||||
data-clipboard-target="source" />
|
||||
<button id="copy-user-address" class="btn-md btn-icon btn-outline shrink-0"
|
||||
data-clipboard-target="trigger" data-action="clipboard#copy"
|
||||
title="Copy to clipboard">
|
||||
<span class="content-initial">
|
||||
<%= render partial: "icons/copy", locals: { custom_class: "text-blue-600 h-4 w-4 inline" } %>
|
||||
</span>
|
||||
<span class="content-active hidden">
|
||||
<%= render partial: "icons/check", locals: { custom_class: "text-blue-600 h-4 w-4 inline" } %>
|
||||
</span>
|
||||
</button>
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h3>Compatible Apps</h3>
|
||||
<p>
|
||||
Your Storage account is based on a new open standard called
|
||||
<a href="https://remotestorage.io" target="_blank">
|
||||
<img src="/img/logos/icon_remotestorage.svg" class="h-4 w-4 inline">
|
||||
<strong>remoteStorage</strong>
|
||||
</a>, which is not yet widely supported. Look
|
||||
for the remoteStorage icon, or check the Sync settings in apps.
|
||||
</p>
|
||||
<p>
|
||||
If you want your favorite apps to support syncing data with your own
|
||||
Storage account, let the developers know! All relevant information is
|
||||
available on the <a href="https://remotestorage.io"
|
||||
target="_blank" class="ks-text-link">remoteStorage website</a>.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h3>Recommended Apps</h3>
|
||||
<div data-controller="tabs"
|
||||
data-tabs-active-tab-class="-mb-px border-gray-200 border-l border-t border-r rounded-t text-indigo-600 hover:text-indigo-600"
|
||||
data-tabs-inactive-tab-class="text-gray-500 hover:text-gray-700"
|
||||
class="mb-12">
|
||||
<select data-action="tabs#change" data-tabs-target="select"
|
||||
class="block w-full mb-8 sm:hidden">
|
||||
<option>Productivity</option>
|
||||
<option>Bookmarks</option>
|
||||
<option>Reading</option>
|
||||
<option>File sharing</option>
|
||||
<option>Learning</option>
|
||||
</select>
|
||||
<ul class="hidden sm:flex list-reset mb-8 border-gray-200 border-b">
|
||||
<li class="mr-2" data-tabs-target="tab" data-action="click->tabs#change:prevent">
|
||||
<a href="#" class="bg-white inline-block py-2 px-4 font-semibold no-underline">
|
||||
Productivity
|
||||
</a>
|
||||
</li>
|
||||
<li class="mr-2" data-tabs-target="tab" data-action="click->tabs#change:prevent">
|
||||
<a href="#" class="bg-white inline-block py-2 px-4 font-semibold no-underline">
|
||||
Bookmarks
|
||||
</a>
|
||||
</li>
|
||||
<li class="mr-2" data-tabs-target="tab" data-action="click->tabs#change:prevent">
|
||||
<a href="#" class="bg-white inline-block py-2 px-4 font-semibold no-underline">
|
||||
Reading
|
||||
</a>
|
||||
</li>
|
||||
<li class="mr-2" data-tabs-target="tab" data-action="click->tabs#change:prevent">
|
||||
<a href="#" class="bg-white inline-block py-2 px-4 font-semibold no-underline">
|
||||
File sharing
|
||||
</a>
|
||||
</li>
|
||||
<li class="mr-2" data-tabs-target="tab" data-action="click->tabs#change:prevent">
|
||||
<a href="#" class="bg-white inline-block py-2 px-4 font-semibold no-underline">
|
||||
Learning
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="hidden grid grid-cols-1 gap-6" data-tabs-target="panel">
|
||||
<%= render AppInfoComponent.new(
|
||||
name: "Hyperdraft",
|
||||
description: "Create text notes and (optionally) turn them into a website",
|
||||
icon_path: "/img/app_icons/hyperdraft.png",
|
||||
links: [
|
||||
["Website", "https://hyperdraft.rosano.ca"],
|
||||
]
|
||||
) %>
|
||||
<%= render AppInfoComponent.new(
|
||||
name: "Notes Together",
|
||||
description: "A powerful note-taking app, with support for attaching images and other files",
|
||||
icon_path: "/img/app_icons/notes-together.png",
|
||||
links: [
|
||||
["Web App", "https://notestogether.hominidsoftware.com"],
|
||||
]
|
||||
) %>
|
||||
<%= render AppInfoComponent.new(
|
||||
name: "Papiers",
|
||||
description: "A simple note-taking app",
|
||||
icon_path: "/img/app_icons/papiers.png",
|
||||
links: [
|
||||
["Web App", "https://papiers.gitlab.io"],
|
||||
]
|
||||
) %>
|
||||
</div>
|
||||
<div class="hidden grid grid-cols-1 gap-6" data-tabs-target="panel">
|
||||
<%= render AppInfoComponent.new(
|
||||
name: "Webmarks",
|
||||
description: "Archive your bookmarks in your remote storage",
|
||||
icon_path: "/img/app_icons/webmarks.png",
|
||||
links: [
|
||||
["Web App", "https://webmarks.5apps.com"],
|
||||
]
|
||||
) %>
|
||||
</div>
|
||||
<div class="hidden grid grid-cols-1 gap-6" data-tabs-target="panel">
|
||||
<%= render AppInfoComponent.new(
|
||||
name: "Pétrolette",
|
||||
description: "A news aggregator that syncs with your remote storage",
|
||||
icon_path: "/img/app_icons/petrolette.png",
|
||||
links: [
|
||||
["Web App", "https://petrolette.space"],
|
||||
]
|
||||
) %>
|
||||
</div>
|
||||
<div class="hidden grid grid-cols-1 gap-6" data-tabs-target="panel">
|
||||
<%= render AppInfoComponent.new(
|
||||
name: "Sharesome",
|
||||
description: "Quickly and easily share files from your remote storage",
|
||||
icon_path: "/img/app_icons/sharesome.png",
|
||||
links: [
|
||||
["Web App", "https://sharesome.5apps.com"],
|
||||
]
|
||||
) %>
|
||||
</div>
|
||||
<div class="hidden grid grid-cols-1 gap-6" data-tabs-target="panel">
|
||||
<%= render AppInfoComponent.new(
|
||||
name: "Kommit",
|
||||
description: "Create flashcards and learn them with spaced-repetition",
|
||||
icon_path: "/img/app_icons/kommit.png",
|
||||
links: [
|
||||
["Website", "https://kommit.rosano.ca"],
|
||||
]
|
||||
) %>
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<p>No apps connected yet.</p>
|
||||
<% end %>
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
33
app/views/services/rs_auths/index.html.erb
Normal file
33
app/views/services/rs_auths/index.html.erb
Normal file
@@ -0,0 +1,33 @@
|
||||
<%= render HeaderComponent.new(title: "Storage") %>
|
||||
|
||||
<%= render MainSimpleComponent.new do %>
|
||||
<section>
|
||||
<p class="mb-6">
|
||||
Store and synchronize your app data across different devices.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<%= render partial: "shared/tabnav_remotestorage" %>
|
||||
|
||||
<section>
|
||||
<% if @rs_auths.any? %>
|
||||
<div class="w-full grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-y-10 gap-x-12 mt-4">
|
||||
<% @rs_auths.each do |auth| %>
|
||||
<%= render RsAuthComponent.new(auth: auth) %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="text-center">
|
||||
<p class="mt-4 mb-12 inline-flex align-center items-center">
|
||||
<%= image_tag("/img/illustrations/undraw_friends_r511.svg", class: 'h-48') %>
|
||||
</p>
|
||||
<h3>
|
||||
No apps connected
|
||||
</h3>
|
||||
<p class="text-gray-500">
|
||||
When connected, your apps will show up here.
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
</section>
|
||||
<% end %>
|
||||
@@ -1,89 +0,0 @@
|
||||
<section>
|
||||
<h3>Nostr</h3>
|
||||
<h4 class="mb-0">Public Key</h4>
|
||||
<div data-controller="settings--nostr-pubkey"
|
||||
data-settings--nostr-pubkey-user-address-value="<%= current_user.address %>"
|
||||
data-settings--nostr-pubkey-shared-secret-value="<%= session[:shared_secret] %>"
|
||||
data-settings--nostr-pubkey-pubkey-hex-value="<%= current_user.nostr_pubkey %>">
|
||||
|
||||
<p class="<%= current_user.nostr_pubkey.present? ? '' : 'hidden' %> mt-2 flex gap-1">
|
||||
<input type="text" value="<%= current_user.nostr_pubkey_bech32 %>" disabled
|
||||
data-settings--nostr-pubkey-target="pubkeyBech32Input"
|
||||
name="nostr_public_key" class="relative grow" />
|
||||
<%= link_to nostr_pubkey_settings_path,
|
||||
class: 'btn-md btn-outline text-red-700 relative shrink-0',
|
||||
data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' } do %>
|
||||
Remove
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
<% if current_user.nostr_pubkey.present? %>
|
||||
<div class="rounded-md bg-blue-50 p-4">
|
||||
<div class="flex">
|
||||
<div class="flex-shrink-0">
|
||||
<svg class="h-5 w-5 text-blue-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
||||
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3 flex-1">
|
||||
<p class="text-sm text-blue-800">
|
||||
Your user address <strong><%= current_user.address %></strong> is
|
||||
also a Nostr address now. Use your favorite Nostr app, or for
|
||||
example <a href="http://metadata.nostr.com" target="_blank"
|
||||
class="underline">metadata.nostr.com</a>, to add this
|
||||
<strong>NIP-05</strong> address to your public profile.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<p class="my-4">
|
||||
If you use any apps on the Nostr network, you can verify your public key
|
||||
with us in order to enable Nostr-specific features for your account.
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<div data-settings--nostr-pubkey-target="noExtension"
|
||||
class="hidden rounded-md bg-blue-50 p-4">
|
||||
<div class="flex">
|
||||
<div class="flex-shrink-0">
|
||||
<svg class="h-5 w-5 text-blue-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
||||
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3">
|
||||
<h3 class="mb-0 text-sm font-bold text-blue-800">
|
||||
No browser extension found
|
||||
</h3>
|
||||
<div class="mt-2 mb-0 text-sm text-blue-800">
|
||||
<p>
|
||||
We recommend Alby, which you can also use for your Lightning
|
||||
Wallet.
|
||||
</p>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<div class="-mx-2 -my-1.5 flex">
|
||||
<a href="https://getalby.com" target="_blank"
|
||||
class="rounded-md bg-blue-50 px-2 py-1.5 text-sm
|
||||
font-bold text-blue-800 hover:bg-blue-100
|
||||
focus:outline-none focus:ring-2 focus:ring-blue-600
|
||||
focus:ring-offset-2 focus:ring-offset-blue-50">
|
||||
Get Alby
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% unless current_user.nostr_pubkey.present? %>
|
||||
<p class="mt-8">
|
||||
<button class="btn-md btn-gray w-full sm:w-auto" disabled
|
||||
data-settings--nostr-pubkey-target="setPubkey"
|
||||
data-action="settings--nostr-pubkey#setPubkey">
|
||||
Get public key from browser extension
|
||||
</button>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
</section>
|
||||
@@ -5,7 +5,7 @@
|
||||
<%= render FormElements::FieldsetComponent.new(
|
||||
positioning: :horizontal,
|
||||
title: "Sats received",
|
||||
description: "Notify me when sats are sent to my Lightning Address"
|
||||
description: "Notify me when sats are sent to my Lightning account"
|
||||
) do %>
|
||||
<% f.fields_for :preferences do |p| %>
|
||||
<%= p.select :lightning_notify_sats_received, options_for_select([
|
||||
@@ -15,6 +15,38 @@
|
||||
], selected: @user.preferences[:lightning_notify_sats_received]) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if @user.nostr_pubkey.present? %>
|
||||
<%= render FormElements::FieldsetComponent.new(
|
||||
positioning: :horizontal,
|
||||
title: "Zap received",
|
||||
description: "Notify me when someone zaps me on Nostr"
|
||||
) do %>
|
||||
<% f.fields_for :preferences do |p| %>
|
||||
<%= p.select :lightning_notify_zap_received, options_for_select([
|
||||
["off", "disabled"],
|
||||
["Chat (Jabber)", "xmpp"],
|
||||
["E-Mail", "email"]
|
||||
], selected: @user.preferences[:lightning_notify_zap_received]) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if @notifications_enabled %>
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
field_name: "user[preferences][lightning_notify_only_with_message]",
|
||||
enabled: @user.preferences[:lightning_notify_only_with_message],
|
||||
title: "Ignore transactions without message",
|
||||
description: "Only send notifications when there is a message attached to the payment"
|
||||
) %>
|
||||
<%= render FormElements::FieldsetComponent.new(
|
||||
title: "Minimum amount",
|
||||
description: "Only send notifications when amount is higher than this"
|
||||
) do %>
|
||||
<%= f.number_field :lightning_notify_min_sats,
|
||||
name: "user[preferences][lightning_notify_min_sats]",
|
||||
class: "w-full",
|
||||
value: @user.preferences[:lightning_notify_min_sats].to_i %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</section>
|
||||
<section>
|
||||
|
||||
184
app/views/settings/_nostr.html.erb
Normal file
184
app/views/settings/_nostr.html.erb
Normal file
@@ -0,0 +1,184 @@
|
||||
<div data-controller="settings--nostr-pubkey"
|
||||
data-settings--nostr-pubkey-user-address-value="<%= current_user.address %>"
|
||||
data-settings--nostr-pubkey-site-value="<%= Setting.accounts_domain %>"
|
||||
data-settings--nostr-pubkey-shared-secret-value="<%= session[:shared_secret] %>"
|
||||
data-settings--nostr-pubkey-pubkey-hex-value="<%= current_user.nostr_pubkey %>">
|
||||
<section>
|
||||
<h3>Nostr</h3>
|
||||
<h4 class="mb-0">
|
||||
Public Key
|
||||
</h4>
|
||||
<p class="<%= current_user.nostr_pubkey.present? ? '' : 'hidden' %> mt-2 flex gap-x-1">
|
||||
<input type="text" value="<%= current_user.nostr_pubkey_bech32 %>" disabled
|
||||
data-settings--nostr-pubkey-target="pubkeyBech32Input"
|
||||
name="nostr_public_key" class="w-full" />
|
||||
<%= link_to nostr_pubkey_settings_path,
|
||||
class: 'btn-md btn-outline relative grow-0 shrink-0 text-red-700',
|
||||
data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' } do %>
|
||||
Remove
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
<% if current_user.nostr_pubkey.present? %>
|
||||
<!-- <div> -->
|
||||
<!-- Pubkey present -->
|
||||
<!-- </div> -->
|
||||
<% else %>
|
||||
<p class="my-4">
|
||||
Verify your Nostr public key with us in order to enable Nostr-specific
|
||||
features for your account.
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<div data-settings--nostr-pubkey-target="noExtension"
|
||||
class="hidden rounded-md bg-blue-50 p-4">
|
||||
<div class="flex">
|
||||
<div class="flex-shrink-0">
|
||||
<svg class="h-5 w-5 text-blue-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
||||
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3">
|
||||
<h3 class="mb-0 text-sm font-bold text-blue-800">
|
||||
No browser extension found
|
||||
</h3>
|
||||
<div class="mt-2 mb-0 text-sm text-blue-800">
|
||||
<p>
|
||||
We recommend Alby, which you can also use a wallet for your
|
||||
Lightning account.
|
||||
</p>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<div class="-mx-2 -my-1.5 flex">
|
||||
<a href="https://getalby.com" target="_blank"
|
||||
class="rounded-md bg-blue-50 px-2 py-1.5 text-sm
|
||||
font-bold text-blue-800 hover:bg-blue-100
|
||||
focus:outline-none focus:ring-2 focus:ring-blue-600
|
||||
focus:ring-offset-2 focus:ring-offset-blue-50">
|
||||
Get Alby
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% unless current_user.nostr_pubkey.present? %>
|
||||
<p class="mt-8">
|
||||
<button class="btn-md btn-gray w-full sm:w-auto" disabled
|
||||
data-settings--nostr-pubkey-target="setPubkey"
|
||||
data-action="settings--nostr-pubkey#setPubkey">
|
||||
Get public key from browser extension
|
||||
</button>
|
||||
</p>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
<% if current_user.nostr_pubkey.present? %>
|
||||
<section>
|
||||
<h3>Profile</h3>
|
||||
<div data-settings--nostr-pubkey-target="profileStatus" class="mb-4">
|
||||
<p class="status-green hidden flex gap-x-4 items-center">
|
||||
<span class="inline-block h-6 w-6 grow-0 text-emerald-500 %>">
|
||||
<%= render "icons/check-circle" %>
|
||||
</span>
|
||||
<span>
|
||||
You already have a profile for your public key
|
||||
</span>
|
||||
</p>
|
||||
<p class="status-orange hidden flex gap-x-4 items-center">
|
||||
<span class="inline-block h-6 w-6 grow-0 text-amber-500 %>">
|
||||
<%= render "icons/alert-octagon" %>
|
||||
</span>
|
||||
<span>
|
||||
<strong><%= current_user.address %></strong> is not set as your Nostr address
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<div data-settings--nostr-pubkey-target="profileStatusNip05" class="mb-4">
|
||||
<p class="status-green hidden flex gap-x-4 items-center">
|
||||
<span class="inline-block h-6 w-6 grow-0 text-emerald-500 %>">
|
||||
<%= render "icons/check-circle" %>
|
||||
</span>
|
||||
<span>
|
||||
<strong><%= current_user.address %></strong> is set as your Nostr address
|
||||
</span>
|
||||
</p>
|
||||
<p class="status-orange hidden flex gap-x-4 items-center">
|
||||
<span class="inline-block h-6 w-6 grow-0 text-amber-500 %>">
|
||||
<%= render "icons/alert-octagon" %>
|
||||
</span>
|
||||
<span>
|
||||
<strong><%= current_user.address %></strong> is not set as your Nostr address
|
||||
</span>
|
||||
</p>
|
||||
<p class="status-red hidden flex gap-x-4 items-center">
|
||||
<span class="inline-block h-6 w-6 grow-0 text-amber-500 %>">
|
||||
<%= render "icons/alert-octagon" %>
|
||||
</span>
|
||||
<span>
|
||||
Your profile's Nostr address is not set to <strong><%= current_user.address %></strong> yet
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<div data-settings--nostr-pubkey-target="profileStatusLud16">
|
||||
<p class="status-green hidden flex gap-x-4 items-center">
|
||||
<span class="inline-block h-6 w-6 grow-0 text-emerald-500 %>">
|
||||
<%= render "icons/check-circle" %>
|
||||
</span>
|
||||
<span>
|
||||
<strong><%= current_user.address %></strong> is set as your Lightning address
|
||||
</span>
|
||||
</p>
|
||||
<p class="status-orange hidden flex gap-x-4 items-center">
|
||||
<span class="inline-block h-6 w-6 grow-0 text-amber-500 %>">
|
||||
<%= render "icons/alert-octagon" %>
|
||||
</span>
|
||||
<span>
|
||||
<strong><%= current_user.address %></strong> is not set as your Lightning address yet
|
||||
</span>
|
||||
</p>
|
||||
<p class="status-red hidden flex gap-x-4 items-center">
|
||||
<span class="inline-block h-6 w-6 grow-0 text-amber-500 %>">
|
||||
<%= render "icons/alert-octagon" %>
|
||||
</span>
|
||||
<span>
|
||||
Your profile's Lightning address is not set to <strong><%= current_user.address %></strong> yet
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h3>Relays</h3>
|
||||
<div data-settings--nostr-pubkey-target="relayListStatus">
|
||||
<p class="status-green hidden flex gap-x-4 items-center">
|
||||
<span class="inline-block h-6 w-6 grow-0 text-emerald-500 %>">
|
||||
<%= render "icons/check-circle" %>
|
||||
</span>
|
||||
<span>
|
||||
You have a relay list, and the Kosmos relay is part of it
|
||||
</span>
|
||||
</p>
|
||||
<p class="status-orange hidden flex gap-x-4 items-center">
|
||||
<span class="inline-block h-6 w-6 grow-0 text-amber-500 %>">
|
||||
<%= render "icons/alert-octagon" %>
|
||||
</span>
|
||||
<span>
|
||||
The Kosmos relay is missing from your relay list
|
||||
</span>
|
||||
</p>
|
||||
<p class="status-red hidden flex gap-x-4 items-center">
|
||||
<span class="inline-block h-6 w-6 grow-0 text-amber-500 %>">
|
||||
<%= render "icons/alert-octagon" %>
|
||||
</span>
|
||||
<span>
|
||||
We could not find a relay list for your public key
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<ul data-settings--nostr-pubkey-target="relayList">
|
||||
</ul>
|
||||
</section>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -34,7 +34,7 @@
|
||||
<% end %>
|
||||
<% if Setting.nostr_enabled %>
|
||||
<%= render SidenavLinkComponent.new(
|
||||
name: "Experiments", path: setting_path(:experiments), icon: "science",
|
||||
active: @settings_section.to_s == "experiments"
|
||||
name: "Nostr", path: setting_path(:nostr), icon: "nostrich-head",
|
||||
active: @settings_section.to_s == "nostr"
|
||||
) %>
|
||||
<% end %>
|
||||
|
||||
14
app/views/shared/_tabnav_remotestorage.html.erb
Normal file
14
app/views/shared/_tabnav_remotestorage.html.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<section>
|
||||
<div class="border-b border-gray-200">
|
||||
<nav class="-mb-px flex" aria-label="Tabs">
|
||||
<%= render TabnavLinkComponent.new(
|
||||
name: "Info", path: services_storage_path,
|
||||
active: current_page?(services_storage_path)
|
||||
) %>
|
||||
<%= render TabnavLinkComponent.new(
|
||||
name: "Connected Apps", path: apps_services_storage_path,
|
||||
active: current_page?(apps_services_storage_path)
|
||||
) %>
|
||||
</nav>
|
||||
</div>
|
||||
</section>
|
||||
@@ -1,3 +1,6 @@
|
||||
lightning_notify_sats_received: disabled # or xmpp, email
|
||||
remotestorage_notify_auth_created: email # or xmpp, email
|
||||
lightning_notify_sats_received: email
|
||||
lightning_notify_zap_received: disabled
|
||||
lightning_notify_min_sats: 0
|
||||
lightning_notify_only_with_message: false
|
||||
remotestorage_notify_auth_created: email
|
||||
xmpp_exchange_contacts_with_invitees: true
|
||||
|
||||
@@ -6,3 +6,4 @@ pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
|
||||
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
|
||||
pin_all_from "app/javascript/controllers", under: "controllers"
|
||||
pin "tailwindcss-stimulus-components" # @4.0.3
|
||||
pin "nostrify"
|
||||
|
||||
@@ -27,7 +27,6 @@ Devise.setup do |config|
|
||||
config.ldap_auth_password_builder = Proc.new() { |new_password|
|
||||
salt = SecureRandom.hex(32)
|
||||
hashed_pw = Base64.strict_encode64(Digest::SHA512.digest(new_password + salt) + salt)
|
||||
puts '{SSHA512}' + hashed_pw
|
||||
'{SSHA512}' + hashed_pw
|
||||
}
|
||||
|
||||
|
||||
2
config/initializers/service_details.rb
Normal file
2
config/initializers/service_details.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
config_path = Rails.root.join('config', 'services.yml')
|
||||
SERVICES = YAML.load_file(config_path).deep_symbolize_keys.with_indifferent_access
|
||||
@@ -1,7 +1,14 @@
|
||||
require 'sidekiq/web'
|
||||
|
||||
Rails.application.routes.draw do
|
||||
devise_for :users, controllers: { confirmations: 'users/confirmations' }
|
||||
devise_for :users, controllers: {
|
||||
confirmations: 'users/confirmations',
|
||||
sessions: 'users/sessions'
|
||||
}
|
||||
|
||||
devise_scope :user do
|
||||
post 'users/nostr_login', to: 'users/sessions#nostr_login'
|
||||
end
|
||||
|
||||
get 'welcome', to: 'welcome#index'
|
||||
get 'check_your_email', to: 'welcome#check_your_email'
|
||||
@@ -41,7 +48,8 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
resource :storage, controller: 'remotestorage', only: [:show] do
|
||||
resources :rs_auths, only: [:destroy] do
|
||||
get :apps, to: "rs_auths#index"
|
||||
resources :rs_auths, only: [:index, :destroy] do
|
||||
member do
|
||||
get :revoke, to: 'rs_auths#destroy'
|
||||
get :launch_app
|
||||
|
||||
30
config/services.yml
Normal file
30
config/services.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
internal:
|
||||
btcpay:
|
||||
name: BTCPay Server
|
||||
postgres:
|
||||
name: PostgreSQL
|
||||
sentry:
|
||||
name: Sentry
|
||||
external:
|
||||
discourse:
|
||||
name: Discourse
|
||||
droneci:
|
||||
name: Drone CI
|
||||
ejabberd:
|
||||
display_name: Chat
|
||||
email:
|
||||
name: E-Mail
|
||||
gitea:
|
||||
name: Gitea
|
||||
lndhub:
|
||||
name: LNDHub
|
||||
display_name: Lightning Network
|
||||
mastodon:
|
||||
name: Mastodon
|
||||
mediawiki:
|
||||
name: MediaWiki
|
||||
nostr:
|
||||
name: Nostr
|
||||
remotestorage:
|
||||
name: remoteStorage
|
||||
display_name: Storage
|
||||
@@ -2,3 +2,5 @@
|
||||
:queues:
|
||||
- default
|
||||
- mailers
|
||||
- remotestorage
|
||||
- nostr
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user