mirror of
https://github.com/tsl0922/ttyd.git
synced 2025-12-23 04:14:18 +01:00
Add support for the --readonly option
This commit is contained in:
@@ -65,6 +65,7 @@ OPTIONS:
|
|||||||
--gid, -g Group id to run with
|
--gid, -g Group id to run with
|
||||||
--signal, -s Signal to send to the command when exit it (default: SIGHUP)
|
--signal, -s Signal to send to the command when exit it (default: SIGHUP)
|
||||||
--reconnect, -r Time to reconnect for the client in seconds (default: 10)
|
--reconnect, -r Time to reconnect for the client in seconds (default: 10)
|
||||||
|
--readonly, -R Do not allow clients to write to the TTY
|
||||||
--once, -o Accept only one client and exit on disconnection
|
--once, -o Accept only one client and exit on disconnection
|
||||||
--ssl, -S Enable ssl
|
--ssl, -S Enable ssl
|
||||||
--ssl-cert, -C Ssl certificate file path
|
--ssl-cert, -C Ssl certificate file path
|
||||||
|
|||||||
@@ -258,6 +258,8 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason,
|
|||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case INPUT:
|
case INPUT:
|
||||||
|
if (server->readonly)
|
||||||
|
return 0;
|
||||||
if (write(client->pty, client->buffer + 1, client->len - 1) < client->len - 1) {
|
if (write(client->pty, client->buffer + 1, client->len - 1) < client->len - 1) {
|
||||||
lwsl_err("write INPUT to pty\n");
|
lwsl_err("write INPUT to pty\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -33,13 +33,14 @@ static const struct option options[] = {
|
|||||||
{"ssl-cert", required_argument, NULL, 'C'},
|
{"ssl-cert", required_argument, NULL, 'C'},
|
||||||
{"ssl-key", required_argument, NULL, 'K'},
|
{"ssl-key", required_argument, NULL, 'K'},
|
||||||
{"ssl-ca", required_argument, NULL, 'A'},
|
{"ssl-ca", required_argument, NULL, 'A'},
|
||||||
|
{"readonly", no_argument, NULL, 'R'},
|
||||||
{"once", no_argument, NULL, 'o'},
|
{"once", no_argument, NULL, 'o'},
|
||||||
{"debug", required_argument, NULL, 'd'},
|
{"debug", required_argument, NULL, 'd'},
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"version", no_argument, NULL, 'v'},
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{NULL, 0, 0, 0}
|
{NULL, 0, 0, 0}
|
||||||
};
|
};
|
||||||
static const char *opt_string = "p:i:c:u:g:s:r:aSC:K:A:od:vh";
|
static const char *opt_string = "p:i:c:u:g:s:r:aSC:K:A:Rod:vh";
|
||||||
|
|
||||||
void print_help() {
|
void print_help() {
|
||||||
fprintf(stderr, "ttyd is a tool for sharing terminal over the web\n\n"
|
fprintf(stderr, "ttyd is a tool for sharing terminal over the web\n\n"
|
||||||
@@ -55,6 +56,7 @@ void print_help() {
|
|||||||
" --gid, -g Group id to run with\n"
|
" --gid, -g Group id to run with\n"
|
||||||
" --signal, -s Signal to send to the command when exit it (default: SIGHUP)\n"
|
" --signal, -s Signal to send to the command when exit it (default: SIGHUP)\n"
|
||||||
" --reconnect, -r Time to reconnect for the client in seconds (default: 10)\n"
|
" --reconnect, -r Time to reconnect for the client in seconds (default: 10)\n"
|
||||||
|
" --readonly, -R Do not allow clients to write to the TTY\n"
|
||||||
" --once, -o Accept only one client and exit on disconnection\n"
|
" --once, -o Accept only one client and exit on disconnection\n"
|
||||||
" --ssl, -S Enable ssl\n"
|
" --ssl, -S Enable ssl\n"
|
||||||
" --ssl-cert, -C Ssl certificate file path\n"
|
" --ssl-cert, -C Ssl certificate file path\n"
|
||||||
@@ -202,6 +204,9 @@ main(int argc, char **argv) {
|
|||||||
case 'd':
|
case 'd':
|
||||||
debug_level = atoi(optarg);
|
debug_level = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'R':
|
||||||
|
server->readonly = true;
|
||||||
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
server->once = true;
|
server->once = true;
|
||||||
break;
|
break;
|
||||||
@@ -322,6 +327,8 @@ main(int argc, char **argv) {
|
|||||||
lwsl_notice(" start command: %s\n", server->command);
|
lwsl_notice(" start command: %s\n", server->command);
|
||||||
lwsl_notice(" reconnect timeout: %ds\n", server->reconnect);
|
lwsl_notice(" reconnect timeout: %ds\n", server->reconnect);
|
||||||
lwsl_notice(" close signal: %s (%d)\n", server->sig_name, server->sig_code);
|
lwsl_notice(" close signal: %s (%d)\n", server->sig_name, server->sig_code);
|
||||||
|
if (server->readonly)
|
||||||
|
lwsl_notice(" readonly: true\n");
|
||||||
if (server->once)
|
if (server->once)
|
||||||
lwsl_notice(" once: true\n");
|
lwsl_notice(" once: true\n");
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ struct tty_server {
|
|||||||
char **argv; // command with arguments
|
char **argv; // command with arguments
|
||||||
int sig_code; // close signal
|
int sig_code; // close signal
|
||||||
char *sig_name; // human readable signal string
|
char *sig_name; // human readable signal string
|
||||||
|
bool readonly; // whether not allow clients to write to the TTY
|
||||||
bool once; // whether accept only one client and exit on disconnection
|
bool once; // whether accept only one client and exit on disconnection
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user