1
0
mirror of https://github.com/tmate-io/tmate-ssh-server.git synced 2020-11-18 19:53:51 -08:00

Let the proxy do the connection messages

This commit is contained in:
Nicolas Viennot 2016-01-22 23:14:35 -05:00
parent 13d12e82a6
commit db787b22ec
6 changed files with 38 additions and 26 deletions

View File

@ -10,7 +10,6 @@ static void tmate_header(struct tmate_session *session,
struct tmate_unpacker *uk)
{
char port_arg[16] = {0};
char *client_version = xstrdup("< 1.8.6");
char tmp[512];
session->client_protocol_version = unpack_int(uk);
@ -19,30 +18,33 @@ static void tmate_header(struct tmate_session *session,
}
if (session->client_protocol_version >= 3) {
free(client_version);
client_version = unpack_string(uk);
session->client_version = unpack_string(uk);
} else {
session->client_version = xstrdup("1.8.5");
}
tmate_notice("Daemon header: client version: %s, protocol version: %d",
client_version, session->client_protocol_version);
session->client_version, session->client_protocol_version);
#if 0
if (strcmp(client_version, TMATE_LATEST_VERSION))
tmate_notify_later(10, "A new version is available, please upgrade :)");
#endif
free(client_version);
if (tmate_has_proxy()) {
/* If we have a proxy, it takes care of all the following notificatons */
tmate_send_proxy_header(session);
return;
}
if (tmate_settings->ssh_port != 22)
sprintf(port_arg, " -p%d", tmate_settings->ssh_port);
sprintf(tmp, "ssh%s ro-%s@%s", port_arg, session->session_token_ro, tmate_settings->tmate_host);
tmate_notify("Remote session read only: %s (clear your screen if you share this)", tmp);
tmate_send_env("tmate_ssh_ro", tmp);
sprintf(tmp, "ssh%s %s@%s", port_arg, session->session_token_ro, tmate_settings->tmate_host);
tmate_notify("Note: clear your terminal before sharing readonly access");
tmate_notify("ssh session read only: %s", tmp);
sprintf(tmp, "ssh%s %s@%s", port_arg, session->session_token, tmate_settings->tmate_host);
tmate_notify("Remote session: %s", tmp);
tmate_send_env("tmate_ssh", tmp);
tmate_notify("ssh session: %s", tmp);
tmate_set_env("tmate_ssh_ro", tmp);
tmate_set_env("tmate_ssh", tmp);
tmate_send_client_ready();
}

View File

@ -61,7 +61,7 @@ void tmate_send_client_ready(void)
pack(int, TMATE_IN_READY);
}
void tmate_send_env(const char *name, const char *value)
void tmate_set_env(const char *name, const char *value)
{
if (tmate_session->client_protocol_version < 4)
return;

View File

@ -5,7 +5,7 @@
#define TMATE_MAX_MESSAGE_SIZE (17*1024)
enum tmate_control_out_msg_types {
TMATE_CTL_AUTH,
TMATE_CTL_HEADER,
TMATE_CTL_DEAMON_OUT_MSG,
TMATE_CTL_SNAPSHOT,
TMATE_CTL_CLIENT_JOIN,
@ -14,8 +14,9 @@ enum tmate_control_out_msg_types {
};
/*
[TMATE_CTL_AUTH, int: ctl_proto_version, string: ip_address, string: pubkey,
string: session_token, string: session_token_ro]
[TMATE_CTL_HEADER, int: ctl_proto_version, string: ip_address, string: pubkey,
string: session_token, string: session_token_ro, string: ssh_cmd_fmt]
string: client_version, int: client_protocol_version]
[TMATE_CTL_DEAMON_OUT_MSG, object: msg]
[TMATE_CTL_SNAPSHOT, [[int: pane_id, [int: cur_x, int: cur_y], int: mode,
[[string: line_utf8, [int: char_attr, ...]], ...], ...], ...]]

View File

@ -6,7 +6,7 @@
#include "tmate.h"
#include "tmate-protocol.h"
#define CONTROL_PROTOCOL_VERSION 1
#define CONTROL_PROTOCOL_VERSION 2
#define pack(what, ...) _pack(&tmate_session->proxy_encoder, what, __VA_ARGS__)
@ -242,16 +242,27 @@ void tmate_send_proxy_daemon_msg(__unused struct tmate_session *session,
void tmate_send_proxy_header(struct tmate_session *session)
{
char port_arg[16] = {0};
char ssh_cmd_fmt[512];
if (!tmate_has_proxy())
return;
pack(array, 6);
pack(int, TMATE_CTL_AUTH);
pack(array, 9);
pack(int, TMATE_CTL_HEADER);
pack(int, CONTROL_PROTOCOL_VERSION);
pack(string, session->ssh_client.ip_address);
pack(string, session->ssh_client.pubkey);
pack(string, session->session_token);
pack(string, session->session_token_ro);
if (tmate_settings->ssh_port != 22)
sprintf(port_arg, " -p%d", tmate_settings->ssh_port);
sprintf(ssh_cmd_fmt, "ssh%s %%s@%s", port_arg, tmate_settings->tmate_host);
pack(string, ssh_cmd_fmt);
pack(string, session->client_version);
pack(int, session->client_protocol_version);
}
static void on_proxy_decoder_read(void *userdata, struct tmate_unpacker *uk)

View File

@ -80,5 +80,4 @@ void tmate_daemon_init(struct tmate_session *session)
tmate_decoder_init(&session->daemon_decoder, on_daemon_decoder_read, session);
tmate_init_proxy(session, NULL);
tmate_send_proxy_header(session);
}

View File

@ -86,8 +86,6 @@ extern void unpack_array(struct tmate_unpacker *uk, struct tmate_unpacker *neste
/* tmate-daemon-encoder.c */
#define TMATE_LATEST_VERSION "1.8.10"
extern void printflike(1, 2) tmate_notify(const char *fmt, ...);
extern void printflike(2, 3) tmate_notify_later(int timeout, const char *fmt, ...);
@ -97,7 +95,7 @@ extern void tmate_client_pane_key(int pane_id, key_code key);
extern void tmate_client_cmd(int client_id, const char *cmd);
extern void tmate_client_set_active_pane(int client_id, int win_idx, int pane_id);
extern int tmate_should_exec_cmd_locally(const struct cmd_entry *cmd);
extern void tmate_send_env(const char *name, const char *value);
extern void tmate_set_env(const char *name, const char *value);
extern void tmate_send_client_ready(void);
extern void tmate_send_mc_obj(msgpack_object *obj);
@ -210,6 +208,7 @@ struct tmate_session {
struct tmate_encoder daemon_encoder;
struct tmate_decoder daemon_decoder;
const char *client_version;
int client_protocol_version;
struct event ev_notify_timer;