summaryrefslogtreecommitdiff
path: root/clients/ui.c
diff options
context:
space:
mode:
authorAnders Betts <anders.betts@gmail.com>2026-09-23 11:36:11 +0200
committerAnders Betts <anders.betts@gmail.com>2026-09-23 11:36:11 +0200
commit1abb7649b930d35d1f5a76fd72856659b1ee8275 (patch)
tree50d1d3dd905056b75749e22a58e7247e4a4bb0e2 /clients/ui.c
parent71a702f375750829c634b552217c9925d549828b (diff)
downloadbokf-1abb7649b930d35d1f5a76fd72856659b1ee8275.tar.gz
bokf-1abb7649b930d35d1f5a76fd72856659b1ee8275.zip
web: bokftui in the browser (ttyd + bokfweb login gate); per-user login limitv0.1.69
New image bokf-web (Dockerfile target "web", compose service "web" on 127.0.0.1:8790): Caddy routing with forward_auth, the bokfweb login gate (C, authenticates with bokfd's session.open, per-address limit, cookie + terminal handle, one login handed to the TUI via /redeem) and ttyd running bokftui in web mode in an isolated throwaway HOME. TLS stays with the host's reverse proxy. BOKF_WEB=1 blocks every local file and viewer path in the TUI. bokfd's login limiter is now per user name instead of one global counter (5 wrong guesses from anyone locked out everybody), and a full counter table no longer disables it. The cross build and deploy.sh build and ship both images. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'clients/ui.c')
-rw-r--r--clients/ui.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/clients/ui.c b/clients/ui.c
index 2eb2dfe..99ad213 100644
--- a/clients/ui.c
+++ b/clients/ui.c
@@ -338,6 +338,8 @@ static void expand_path(const char *in, char *out, size_t n)
Returns a malloc'd path, or NULL on cancel. */
char *file_browser(struct app *a, const char *start_dir)
{
+ if (ui_web_block("Välj fil"))
+ return NULL;
if (g_quit)
return NULL;
char dir[1024];
@@ -478,6 +480,27 @@ static void safe_fname(const char *in, char *out, size_t n)
out[o] = '\0';
}
+int ui_web_mode(void)
+{
+ static int mode = -1;
+ if (mode < 0) {
+ const char *v = getenv("BOKF_WEB");
+ mode = v && strcmp(v, "1") == 0;
+ }
+ return mode;
+}
+
+int ui_web_block(const char *title)
+{
+ if (!ui_web_mode())
+ return 0;
+ tui_message(title,
+ "Inte tillgängligt i webbversionen ännu: filer kan inte\n"
+ "laddas upp, sparas eller öppnas härifrån.\n"
+ "Använd bokftui på datorn för det.");
+ return 1;
+}
+
/* Open a saved file with xdg-open when a desktop session is present;
otherwise (or on fork failure) show where it was saved. */
static void open_saved(const char *path, const char *title)
@@ -507,6 +530,8 @@ static void open_saved(const char *path, const char *title)
static void save_cache_and_open(const unsigned char *data, size_t n,
const char *filename, const char *title)
{
+ if (ui_web_block(title))
+ return;
char dir[512], path[700], safe[600];
pdf_cache_dir(dir, sizeof dir);
safe_fname(filename, safe, sizeof safe);
@@ -614,6 +639,8 @@ void attachment_download(struct app *a, int64_t att_id)
tui_message("Underlag", "Kunde inte avkoda innehållet.");
goto done;
}
+ if (ui_web_block("Underlag"))
+ goto done;
const char *home = getenv("HOME");
char def[600], dl[512];
snprintf(dl, sizeof dl, "%s/Downloads", home && *home ? home : ".");