|
|
@@ -3,7 +3,8 @@
|
|
|
* Login is the native Cloudron OIDC driver in chat_login.c (username,
|
|
|
* password, optional TOTP) or a pasted session cookie. The session cookie is
|
|
|
* kept in a uhttp cookie jar and saved with the server address in a small
|
|
|
- * config file (/share/chat.cfg by default, or the path given as argument).
|
|
|
+ * config file: /data/CHAT.CFG on an installed disk, /share/chat.cfg when
|
|
|
+ * there is no persistent /data mount, or the path given as argument.
|
|
|
* The password is never stored.
|
|
|
*
|
|
|
* Everything else is the Chat REST API over uhttp: the channel and DM
|
|
|
@@ -25,7 +26,8 @@
|
|
|
#include <stdlib.h>
|
|
|
#include <string.h>
|
|
|
|
|
|
-#define DEFAULT_CFG "/share/chat.cfg"
|
|
|
+#define DEFAULT_CFG_DATA "/data/CHAT.CFG"
|
|
|
+#define DEFAULT_CFG_SHARE "/share/chat.cfg"
|
|
|
#define RESP_CAP (512u * 1024u)
|
|
|
#define JSON_NODES 16384u
|
|
|
#define JSON_SCAP (RESP_CAP + 2u * JSON_NODES)
|
|
|
@@ -108,6 +110,7 @@ static enum modal modal = MODAL_NONE;
|
|
|
static int action, action_arg;
|
|
|
|
|
|
static char cfg_path[CHAT_PATH_MAX];
|
|
|
+static int cfg_is_default;
|
|
|
static char server[CHAT_SERVER_MAX];
|
|
|
static char server_host[UHTTP_HOST_MAX];
|
|
|
static int server_secure;
|
|
|
@@ -342,6 +345,19 @@ static int write_file(const char *path, const char *buf, unsigned int len)
|
|
|
return u_syscall3(SYS_WRITE_FILE, (int)path, (int)buf, (int)len);
|
|
|
}
|
|
|
|
|
|
+/* The persistent data volume wins when it is mounted and writable; the
|
|
|
+ * volatile /share is the fallback (live USB, or a board without /data). */
|
|
|
+static const char *default_cfg_path(void)
|
|
|
+{
|
|
|
+ struct sys_mount m;
|
|
|
+ unsigned int i;
|
|
|
+
|
|
|
+ for (i = 0; u_syscall2(SYS_LIST_MOUNTS, (int)i, (int)&m) == 1; i++)
|
|
|
+ if (strcmp(m.name, "data") == 0 && !m.ro)
|
|
|
+ return DEFAULT_CFG_DATA;
|
|
|
+ return DEFAULT_CFG_SHARE;
|
|
|
+}
|
|
|
+
|
|
|
static int set_server(const char *s)
|
|
|
{
|
|
|
char norm[CHAT_SERVER_MAX];
|
|
|
@@ -1311,8 +1327,16 @@ static void load_config(void)
|
|
|
{
|
|
|
static char buf[CHAT_COOKIE_MAX + CHAT_SERVER_MAX + 256];
|
|
|
char srv[CHAT_SERVER_MAX];
|
|
|
- int n = read_file(cfg_path, buf, sizeof(buf));
|
|
|
+ int n, migrated = 0;
|
|
|
|
|
|
+ n = read_file(cfg_path, buf, sizeof(buf));
|
|
|
+ /* First start on a persistent volume: carry a session that an older
|
|
|
+ * build saved in /share into /data once. */
|
|
|
+ if (n <= 0 && cfg_is_default &&
|
|
|
+ strcmp(cfg_path, DEFAULT_CFG_DATA) == 0) {
|
|
|
+ n = read_file(DEFAULT_CFG_SHARE, buf, sizeof(buf));
|
|
|
+ migrated = n > 0;
|
|
|
+ }
|
|
|
ngui_input_set(&cfg_in, cfg_path);
|
|
|
if (n <= 0 || chat_config_parse(buf, (unsigned int)n, srv, sizeof(srv),
|
|
|
saved_cookie,
|
|
|
@@ -1328,6 +1352,8 @@ static void load_config(void)
|
|
|
return;
|
|
|
uhttp_jar_import(&jar, server_host, server_secure, saved_cookie);
|
|
|
saved_jar_changes = jar.changes;
|
|
|
+ if (migrated)
|
|
|
+ save_config();
|
|
|
check_session(1);
|
|
|
}
|
|
|
|
|
|
@@ -2461,7 +2487,12 @@ void _start(const char *arg)
|
|
|
pass_in.secret = 1;
|
|
|
totp_in.placeholder = "123456";
|
|
|
cookie_in.placeholder = "connect.sid=...";
|
|
|
- s_copy(cfg_path, arg && arg[0] ? arg : DEFAULT_CFG, sizeof(cfg_path));
|
|
|
+ if (arg && arg[0]) {
|
|
|
+ s_copy(cfg_path, arg, sizeof(cfg_path));
|
|
|
+ } else {
|
|
|
+ s_copy(cfg_path, default_cfg_path(), sizeof(cfg_path));
|
|
|
+ cfg_is_default = 1;
|
|
|
+ }
|
|
|
ngui_set_focus(&ui, ID_SERVER);
|
|
|
last_input_ms = 0;
|
|
|
|