v0.0.40 - Add interactive index whitelist prompt after transport selection — users can restrict nostr_index values without CLI flags

This commit is contained in:
Laan Tungir
2026-07-11 13:46:23 -04:00
parent 922a45ce3a
commit 10208e5fac

View File

@@ -503,8 +503,8 @@ int socket_name_random(char *out, size_t out_len);
/* Version information (auto-updated by build/version tooling) */ /* Version information (auto-updated by build/version tooling) */
#define NSIGNER_VERSION_MAJOR 0 #define NSIGNER_VERSION_MAJOR 0
#define NSIGNER_VERSION_MINOR 0 #define NSIGNER_VERSION_MINOR 0
#define NSIGNER_VERSION_PATCH 39 #define NSIGNER_VERSION_PATCH 40
#define NSIGNER_VERSION "v0.0.39" #define NSIGNER_VERSION "v0.0.40"
/* NSIGNER_HEADERLESS_DECLS_END */ /* NSIGNER_HEADERLESS_DECLS_END */
@@ -1671,6 +1671,59 @@ static int prompt_transport_selection(void) {
return selected; return selected;
} }
/*
* Interactive index whitelist prompt.
* Shown after transport selection when no --allow-index flag was given.
* Returns a malloc'd spec string (caller must free), or NULL for "all".
*/
static char *prompt_index_whitelist(void) {
char input[256];
for (;;) {
tui_render_content_screen(NULL, "Index whitelist — restrict which nostr_index values this session can access");
printf("Enter allowed indices, or press Enter for 'all' (no restriction):\n\n");
printf(" Examples:\n");
printf(" all (default — allow all indices)\n");
printf(" 0 (only index 0)\n");
printf(" 0,1,3 (specific indices)\n");
printf(" 0-3 (range 0 through 3)\n");
printf(" 0,2-3,7 (mixed list and ranges)\n");
printf("\n Enter = all\n");
printf("> ");
fflush(stdout);
if (read_line_stdin(input, sizeof(input)) != 0) {
return NULL;
}
/* Trim trailing whitespace */
{
size_t len = strlen(input);
while (len > 0 && (input[len-1] == '\n' || input[len-1] == '\r' ||
input[len-1] == ' ' || input[len-1] == '\t')) {
input[--len] = '\0';
}
}
if (input[0] == '\0') {
/* Enter pressed — default to "all" */
return NULL;
}
/* Validate by parsing into a temp whitelist */
{
server_ctx_t tmp;
memset(&tmp, 0, sizeof(tmp));
if (server_set_index_whitelist(&tmp, input) != 0) {
printf("Invalid spec: '%s'. Try again or press Enter for 'all'.\n", input);
continue;
}
}
return strdup(input);
}
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
mnemonic_state_t mnemonic; mnemonic_state_t mnemonic;
role_table_t role_table; role_table_t role_table;
@@ -1969,6 +2022,14 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
/* Index whitelist prompt (only if --allow-index wasn't given on CLI) */
if (allow_index_spec == NULL) {
char *wl_spec = prompt_index_whitelist();
if (wl_spec != NULL) {
allow_index_spec = wl_spec; /* will be freed at program exit */
}
}
/* Persistent listeners — configure from menu selection */ /* Persistent listeners — configure from menu selection */
multi_listen = 1; multi_listen = 1;