mirror of
https://github.com/tsl0922/ttyd.git
synced 2025-12-23 04:14:18 +01:00
server: custom terminal type support
This commit is contained in:
@@ -89,6 +89,7 @@ OPTIONS:
|
|||||||
-r, --reconnect Time to reconnect for the client in seconds (default: 10)
|
-r, --reconnect Time to reconnect for the client in seconds (default: 10)
|
||||||
-R, --readonly Do not allow clients to write to the TTY
|
-R, --readonly Do not allow clients to write to the TTY
|
||||||
-t, --client-option Send option to client (format: key=value), repeat to add more options
|
-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
|
-O, --check-origin Do not allow websocket connection from different origin
|
||||||
-m, --max-clients Maximum clients to support (default: 0, no limit)
|
-m, --max-clients Maximum clients to support (default: 0, no limit)
|
||||||
-o, --once Accept only one client and exit on disconnection
|
-o, --once Accept only one client and exit on disconnection
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ Cross platform: macOS, Linux, FreeBSD/OpenBSD, OpenWrt/LEDE, Windows
|
|||||||
\-t, \-\-client\-option <key=value>
|
\-t, \-\-client\-option <key=value>
|
||||||
Send option to client (format: key=value), repeat to add more options
|
Send option to client (format: key=value), repeat to add more options
|
||||||
|
|
||||||
|
.PP
|
||||||
|
\-T, \-\-terminal\-type
|
||||||
|
Terminal type to report, default: xterm\-256color
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
\-O, \-\-check\-origin
|
\-O, \-\-check\-origin
|
||||||
Do not allow websocket connection from different origin
|
Do not allow websocket connection from different origin
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ ttyd 1 "September 2016" ttyd "User Manual"
|
|||||||
-t, --client-option <key=value>
|
-t, --client-option <key=value>
|
||||||
Send option to client (format: key=value), repeat to add more options
|
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
|
-O, --check-origin
|
||||||
Do not allow websocket connection from different origin
|
Do not allow websocket connection from different origin
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ thread_run_command(void *args) {
|
|||||||
lwsl_err("forkpty, error: %d (%s)\n", errno, strerror(errno));
|
lwsl_err("forkpty, error: %d (%s)\n", errno, strerror(errno));
|
||||||
break;
|
break;
|
||||||
case 0: /* child */
|
case 0: /* child */
|
||||||
if (setenv("TERM", "xterm-256color", true) < 0) {
|
if (setenv("TERM", server->terminal_type, true) < 0) {
|
||||||
perror("setenv");
|
perror("setenv");
|
||||||
pthread_exit((void *) 1);
|
pthread_exit((void *) 1);
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/server.c
11
src/server.c
@@ -64,7 +64,7 @@ static const struct option options[] = {
|
|||||||
{"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:I:aSC:K:A:Rt:Om:oBd:vh";
|
static const char *opt_string = "p:i:c:u:g:s:r:I:aSC:K:A:Rt:T:Om:oBd: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"
|
||||||
@@ -82,6 +82,7 @@ void print_help() {
|
|||||||
" -r, --reconnect Time to reconnect for the client in seconds (default: 10)\n"
|
" -r, --reconnect Time to reconnect for the client in seconds (default: 10)\n"
|
||||||
" -R, --readonly Do not allow clients to write to the TTY\n"
|
" -R, --readonly Do not allow clients to write to the TTY\n"
|
||||||
" -t, --client-option Send option to client (format: key=value), repeat to add more options\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"
|
" -O, --check-origin Do not allow websocket connection from different origin\n"
|
||||||
" -m, --max-clients Maximum clients to support (default: 0, no limit)\n"
|
" -m, --max-clients Maximum clients to support (default: 0, no limit)\n"
|
||||||
" -o, --once Accept only one client and exit on disconnection\n"
|
" -o, --once Accept only one client and exit on disconnection\n"
|
||||||
@@ -111,6 +112,7 @@ tty_server_new(int argc, char **argv, int start) {
|
|||||||
ts->client_count = 0;
|
ts->client_count = 0;
|
||||||
ts->reconnect = 10;
|
ts->reconnect = 10;
|
||||||
ts->sig_code = SIGHUP;
|
ts->sig_code = SIGHUP;
|
||||||
|
sprintf(ts->terminal_type, "%s", "xterm-256color");
|
||||||
get_sig_name(ts->sig_code, ts->sig_name, sizeof(ts->sig_name));
|
get_sig_name(ts->sig_code, ts->sig_name, sizeof(ts->sig_name));
|
||||||
if (start == argc)
|
if (start == argc)
|
||||||
return ts;
|
return ts;
|
||||||
@@ -353,6 +355,10 @@ main(int argc, char **argv) {
|
|||||||
strncpy(ca_path, optarg, sizeof(ca_path) - 1);
|
strncpy(ca_path, optarg, sizeof(ca_path) - 1);
|
||||||
ca_path[sizeof(ca_path) - 1] = '\0';
|
ca_path[sizeof(ca_path) - 1] = '\0';
|
||||||
break;
|
break;
|
||||||
|
case 'T':
|
||||||
|
strncpy(server->terminal_type, optarg, sizeof(server->terminal_type) - 1);
|
||||||
|
server->terminal_type[sizeof(server->terminal_type) - 1] = '\0';
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
@@ -436,8 +442,9 @@ main(int argc, char **argv) {
|
|||||||
if (server->credential != NULL)
|
if (server->credential != NULL)
|
||||||
lwsl_notice(" credential: %s\n", server->credential);
|
lwsl_notice(" credential: %s\n", server->credential);
|
||||||
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(" close signal: %s (%d)\n", server->sig_name, server->sig_code);
|
lwsl_notice(" close signal: %s (%d)\n", server->sig_name, server->sig_code);
|
||||||
|
lwsl_notice(" terminal type: %s\n", server->terminal_type);
|
||||||
|
lwsl_notice(" reconnect timeout: %ds\n", server->reconnect);
|
||||||
if (server->check_origin)
|
if (server->check_origin)
|
||||||
lwsl_notice(" check origin: true\n");
|
lwsl_notice(" check origin: true\n");
|
||||||
if (server->readonly)
|
if (server->readonly)
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ struct tty_server {
|
|||||||
int max_clients; // maximum clients to support
|
int max_clients; // maximum clients to support
|
||||||
bool once; // whether accept only one client and exit on disconnection
|
bool once; // whether accept only one client and exit on disconnection
|
||||||
char socket_path[255]; // UNIX domain socket path
|
char socket_path[255]; // UNIX domain socket path
|
||||||
|
char terminal_type[30]; // terminal type to report
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user