From: Shuanglei Tao Date: Tue, 9 May 2023 10:41:54 +0000 (+0800) Subject: server: replace --readonly with --writable X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=f8efcddb0b615de7086fdb3c5f452d1ee42f32a3;p=ttyd.git server: replace --readonly with --writable --- diff --git a/Dockerfile b/Dockerfile index 03603f4..649bc32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,4 @@ EXPOSE 7681 WORKDIR /root ENTRYPOINT ["/usr/bin/tini", "--"] -CMD ["ttyd", "bash"] +CMD ["ttyd", "-W", "bash"] diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 844b53c..41378a1 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -8,4 +8,4 @@ EXPOSE 7681 WORKDIR /root ENTRYPOINT ["/sbin/tini", "--"] -CMD ["ttyd", "bash"] +CMD ["ttyd", "-W", "bash"] diff --git a/README.md b/README.md index 1dcd6cb..34dad77 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ OPTIONS: -g, --gid Group id to run with -s, --signal Signal to send to the command when exit it (default: 1, SIGHUP) -a, --url-arg Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar) - -R, --readonly Do not allow clients to write to the TTY + -W, --writable Allow clients to write to the TTY (readonly by default) -t, --client-option Send option to client (format: key=value), repeat to add more options -T, --terminal-type Terminal type to report, default: xterm-256color -O, --check-origin Do not allow websocket connection from different origin diff --git a/man/ttyd.1 b/man/ttyd.1 index 729b548..11d9dd7 100644 --- a/man/ttyd.1 +++ b/man/ttyd.1 @@ -78,8 +78,8 @@ Cross platform: macOS, Linux, FreeBSD/OpenBSD, OpenWrt/LEDE, Windows Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar) .PP --R, --readonly - Do not allow clients to write to the TTY +-R, --writable + Allow clients to write to the TTY (readonly by default) .PP -t, --client-option diff --git a/man/ttyd.man.md b/man/ttyd.man.md index 1e59d13..8ff9c42 100644 --- a/man/ttyd.man.md +++ b/man/ttyd.man.md @@ -50,8 +50,8 @@ ttyd 1 "September 2016" ttyd "User Manual" -a, --url-arg Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar) - -R, --readonly - Do not allow clients to write to the TTY + -W, --writable + Allow clients to write to the TTY (readonly by default) -t, --client-option Send option to client (format: key=value), repeat to add more options, see **CLIENT OPTIONS** for details diff --git a/src/protocol.c b/src/protocol.c index cc0945b..3a53f96 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -306,7 +306,7 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user, switch (command) { case INPUT: - if (server->readonly) break; + if (!server->writable) break; int err = pty_write(pss->process, pty_buf_init(pss->buffer + 1, pss->len - 1)); if (err) { lwsl_err("uv_write: %s (%s)\n", uv_err_name(err), uv_strerror(err)); diff --git a/src/server.c b/src/server.c index 318932d..541f8d4 100644 --- a/src/server.c +++ b/src/server.c @@ -71,7 +71,7 @@ static const struct option options[] = {{"port", required_argument, NULL, 'p'}, {"ssl-key", required_argument, NULL, 'K'}, {"ssl-ca", required_argument, NULL, 'A'}, {"url-arg", no_argument, NULL, 'a'}, - {"readonly", no_argument, NULL, 'R'}, + {"writable", no_argument, NULL, 'W'}, {"terminal-type", required_argument, NULL, 'T'}, {"client-option", required_argument, NULL, 't'}, {"check-origin", no_argument, NULL, 'O'}, @@ -82,7 +82,7 @@ static const struct option options[] = {{"port", required_argument, NULL, 'p'}, {"version", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, 0, 0}}; -static const char *opt_string = "p:i:U:c:H:u:g:s:w:I:b:P:6aSC:K:A:Rt:T:Om:oBd:vh"; +static const char *opt_string = "p:i:U:c:H:u:g:s:w:I:b:P:6aSC:K:A:Wt:T:Om:oBd:vh"; static void print_help() { // clang-format off @@ -102,7 +102,7 @@ static void print_help() { " -s, --signal Signal to send to the command when exit it (default: 1, SIGHUP)\n" " -w, --cwd Working directory to be set for the child program\n" " -a, --url-arg Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar)\n" - " -R, --readonly Do not allow clients to write to the TTY\n" + " -W, --writable Allow clients to write to the TTY (readonly by default)\n" " -t, --client-option Send option to client (format: key=value), repeat to add more options\n" " -T, --terminal-type Terminal type to report, default: xterm-256color\n" " -O, --check-origin Do not allow websocket connection from different origin\n" @@ -148,10 +148,10 @@ static void print_config() { if (server->auth_header != NULL) lwsl_notice(" auth header: %s\n", server->auth_header); if (server->check_origin) lwsl_notice(" check origin: true\n"); if (server->url_arg) lwsl_notice(" allow url arg: true\n"); - if (server->readonly) lwsl_notice(" readonly: true\n"); if (server->max_clients > 0) lwsl_notice(" max clients: %d\n", server->max_clients); if (server->once) lwsl_notice(" once: true\n"); if (server->index != NULL) lwsl_notice(" custom index.html: %s\n", server->index); + if (!server->writable) lwsl_notice("The --writable option is not set, will start in readonly mode"); } static struct server *server_new(int argc, char **argv, int start) { @@ -324,7 +324,7 @@ int main(int argc, char **argv) { info.max_http_header_data = 65535; int debug_level = LLL_ERR | LLL_WARN | LLL_NOTICE; - char iface[128] = "127.0.0.1"; + char iface[128] = ""; char socket_owner[128] = ""; bool browser = false; bool ssl = false; @@ -354,8 +354,8 @@ int main(int argc, char **argv) { case 'a': server->url_arg = true; break; - case 'R': - server->readonly = true; + case 'W': + server->writable = true; break; case 'O': server->check_origin = true; diff --git a/src/server.h b/src/server.h index 794965a..4a659b0 100644 --- a/src/server.h +++ b/src/server.h @@ -74,7 +74,7 @@ struct server { int sig_code; // close signal char sig_name[20]; // human readable signal string bool url_arg; // allow client to send cli arguments in URL - bool readonly; // whether not allow clients to write to the TTY + bool writable; // whether clients to write to the TTY bool check_origin; // whether allow websocket connection from different origin int max_clients; // maximum clients to support bool once; // whether accept only one client and exit on disconnection