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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sqlx = { version = "0.7", features = ["sqlite", "runtime-tokio-native-tls"] }
dotenv = "0.15"
nostr = { git = "https://github.com/frnandu/nostr", branch = "nwc-notifications" }
nwc = { git = "https://github.com/frnandu/nostr", branch = "nwc-notifications", package = "nwc" }
nostr = { git = "https://github.com/rust-nostr/nostr", rev = "684c69528c3453b4515c0fadf56d72e25286fbf6" }
nwc = { git = "https://github.com/rust-nostr/nostr", rev = "684c69528c3453b4515c0fadf56d72e25286fbf6", package = "nwc" }
log = "0.4"
env_logger = "0.10"
rand = "0.8"
Expand Down
10 changes: 0 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# 1. Build dependencies with dummy main
FROM rust:1.86-slim as build-deps
WORKDIR /app
RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release && rm -rf src

# 2. Build actual application
FROM rust:1.86-slim as builder
WORKDIR /app
RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*
Expand All @@ -15,7 +6,6 @@ COPY src ./src
COPY static ./static
RUN cargo build --release

# 3. Runtime image
FROM debian:bookworm-slim
WORKDIR /app
RUN apt-get update && apt-get install -y ca-certificates libssl3 && rm -rf /var/lib/apt/lists/*
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# rustress

A minimal Lightning/Nostr server in Rust using SQLite.
A minimal LNurl/Nostr/Zap-receipt server in Rust using SQLite.

## Features
- LNURL-pay endpoint with NWC (Nostr Wallet Connect) integration
Expand Down
6 changes: 4 additions & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ pub async fn create_user(
Ok(rec)
}

pub async fn delete_user_by_username(
pub async fn delete_user_by_username_and_domain(
pool: &SqlitePool,
username: &str,
domain: &str,
) -> Result<bool, sqlx::Error> {
let result = sqlx::query(r#"DELETE FROM users WHERE username = ?"#)
let result = sqlx::query(r#"DELETE FROM users WHERE username = ? AND domain = ?"#)
.bind(username)
.bind(domain)
.execute(pool)
.await?;
Ok(result.rows_affected() > 0)
Expand Down
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tokio::time::{Duration, timeout};
mod db;

use crate::db::{
create_user, delete_user_by_username, get_all_users_with_secret, get_db_pool,
create_user, delete_user_by_username_and_domain, get_all_users_with_secret, get_db_pool,
get_invoice_by_payment_hash, get_user_by_username_and_domain, insert_invoice, mark_invoice_settled,
run_migrations, update_invoice_metadata_with_zap_receipt,
};
Expand Down Expand Up @@ -610,25 +610,25 @@ async fn admin_delete_user(
req: HttpRequest,
pool: web::Data<Arc<SqlitePool>>,
config: web::Data<Arc<AppConfig>>,
path: web::Path<String>,
path: web::Path<(String, String)>,
) -> impl Responder {
if !check_admin_auth(&req, &config.admin_password) {
return HttpResponse::Unauthorized()
.json(serde_json::json!({"status": "ERROR", "reason": "Authentication required"}));
}

let username = path.into_inner();
match delete_user_by_username(&pool, &username).await {
let (username, domain) = path.into_inner();
match delete_user_by_username_and_domain(&pool, &username, &domain).await {
Ok(deleted) => {
if deleted {
HttpResponse::Ok().json(serde_json::json!({
"status": "OK",
"message": format!("User '{}' deleted successfully", username)
"message": format!("User '{}'@'{}' deleted successfully", username, domain)
}))
} else {
HttpResponse::NotFound().json(serde_json::json!({
"status": "ERROR",
"reason": format!("User '{}' not found", username)
"reason": format!("User '{}'@'{}' not found", username, domain)
}))
}
}
Expand Down Expand Up @@ -689,7 +689,7 @@ async fn main() -> std::io::Result<()> {
.route("/admin/login", web::post().to(admin_login))
.route("/admin/users", web::get().to(admin_users))
.route("/admin/add", web::post().to(admin_add_user))
.route("/admin/{username}", web::delete().to(admin_delete_user))
.route("/admin/{username}/{domain}", web::delete().to(admin_delete_user))
// Serve static files
.service(fs::Files::new("/static", "static").show_files_listing())
})
Expand Down
2 changes: 1 addition & 1 deletion static/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ <h2>Current Users</h2>

try {
document.body.classList.add('loading');
const response = await fetch(`/admin/${username}`, {
const response = await fetch(`/admin/${username}/${domain}`, {
method: 'DELETE'
});

Expand Down