diff --git a/Cargo.lock b/Cargo.lock index c95022b..9e2224e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1612,7 +1612,7 @@ dependencies = [ [[package]] name = "nostr" version = "0.42.1" -source = "git+https://github.com/frnandu/nostr?branch=nwc-notifications#d20f9695adcc308620b97ce3fa8f6203f1c0bc37" +source = "git+https://github.com/rust-nostr/nostr?rev=684c69528c3453b4515c0fadf56d72e25286fbf6#684c69528c3453b4515c0fadf56d72e25286fbf6" dependencies = [ "aes", "base64 0.22.1", @@ -1657,10 +1657,10 @@ dependencies = [ [[package]] name = "nostr-database" version = "0.42.0" -source = "git+https://github.com/frnandu/nostr?branch=nwc-notifications#d20f9695adcc308620b97ce3fa8f6203f1c0bc37" +source = "git+https://github.com/rust-nostr/nostr?rev=684c69528c3453b4515c0fadf56d72e25286fbf6#684c69528c3453b4515c0fadf56d72e25286fbf6" dependencies = [ "lru", - "nostr 0.42.1 (git+https://github.com/frnandu/nostr?branch=nwc-notifications)", + "nostr 0.42.1 (git+https://github.com/rust-nostr/nostr?rev=684c69528c3453b4515c0fadf56d72e25286fbf6)", "tokio", ] @@ -1677,15 +1677,15 @@ dependencies = [ [[package]] name = "nostr-relay-pool" version = "0.42.0" -source = "git+https://github.com/frnandu/nostr?branch=nwc-notifications#d20f9695adcc308620b97ce3fa8f6203f1c0bc37" +source = "git+https://github.com/rust-nostr/nostr?rev=684c69528c3453b4515c0fadf56d72e25286fbf6#684c69528c3453b4515c0fadf56d72e25286fbf6" dependencies = [ "async-utility", "async-wsocket", "atomic-destructor", "lru", "negentropy", - "nostr 0.42.1 (git+https://github.com/frnandu/nostr?branch=nwc-notifications)", - "nostr-database 0.42.0 (git+https://github.com/frnandu/nostr?branch=nwc-notifications)", + "nostr 0.42.1 (git+https://github.com/rust-nostr/nostr?rev=684c69528c3453b4515c0fadf56d72e25286fbf6)", + "nostr-database 0.42.0 (git+https://github.com/rust-nostr/nostr?rev=684c69528c3453b4515c0fadf56d72e25286fbf6)", "tokio", "tracing", ] @@ -1774,11 +1774,11 @@ dependencies = [ [[package]] name = "nwc" version = "0.42.0" -source = "git+https://github.com/frnandu/nostr?branch=nwc-notifications#d20f9695adcc308620b97ce3fa8f6203f1c0bc37" +source = "git+https://github.com/rust-nostr/nostr?rev=684c69528c3453b4515c0fadf56d72e25286fbf6#684c69528c3453b4515c0fadf56d72e25286fbf6" dependencies = [ "async-utility", - "nostr 0.42.1 (git+https://github.com/frnandu/nostr?branch=nwc-notifications)", - "nostr-relay-pool 0.42.0 (git+https://github.com/frnandu/nostr?branch=nwc-notifications)", + "nostr 0.42.1 (git+https://github.com/rust-nostr/nostr?rev=684c69528c3453b4515c0fadf56d72e25286fbf6)", + "nostr-relay-pool 0.42.0 (git+https://github.com/rust-nostr/nostr?rev=684c69528c3453b4515c0fadf56d72e25286fbf6)", "tracing", ] @@ -2221,7 +2221,7 @@ dependencies = [ "dotenv", "env_logger", "log", - "nostr 0.42.1 (git+https://github.com/frnandu/nostr?branch=nwc-notifications)", + "nostr 0.42.1 (git+https://github.com/rust-nostr/nostr?rev=684c69528c3453b4515c0fadf56d72e25286fbf6)", "nostr-relay-pool 0.42.0 (git+https://github.com/rust-nostr/nostr)", "nostr-sdk", "nwc", diff --git a/Cargo.toml b/Cargo.toml index 7a4a1a8..3beb36e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/Dockerfile b/Dockerfile index 84b75c4..62466d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/* @@ -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/* diff --git a/README.md b/README.md index ef9fab7..ae02d0a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/db.rs b/src/db.rs index 60183d6..bd0db64 100644 --- a/src/db.rs +++ b/src/db.rs @@ -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 { - 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) diff --git a/src/main.rs b/src/main.rs index 9395a81..e458af6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, }; @@ -610,25 +610,25 @@ async fn admin_delete_user( req: HttpRequest, pool: web::Data>, config: web::Data>, - path: web::Path, + 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) })) } } @@ -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()) }) diff --git a/static/admin.html b/static/admin.html index 32b5fb2..5addd91 100644 --- a/static/admin.html +++ b/static/admin.html @@ -300,7 +300,7 @@

Current Users

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