79 lines
2.6 KiB
Diff
79 lines
2.6 KiB
Diff
diff --git a/src/protocol.c b/src/protocol.c
|
|
index 3a53f96..6abb066 100644
|
|
--- a/src/protocol.c
|
|
+++ b/src/protocol.c
|
|
@@ -142,6 +142,24 @@ static char **build_env(struct pss_tty *pss) {
|
|
i++;
|
|
}
|
|
|
|
+ // Remote IPs
|
|
+ {
|
|
+ char tgt[255];
|
|
+ envp = xrealloc(envp, (++n) * sizeof(char *));
|
|
+ envp[i] = xmalloc(40);
|
|
+ snprintf(envp[i], 40, "TTYD_REMOTEHOST=%s", pss->address);
|
|
+ i++;
|
|
+
|
|
+ envp = xrealloc(envp, (++n) * sizeof(char *));
|
|
+ envp[i] = xmalloc(40);
|
|
+ snprintf(envp[i], 40, "TTYD_X_FORWARDED_FOR=%s", pss->hdr_fwd_for);
|
|
+ i++;
|
|
+
|
|
+ envp = xrealloc(envp, (++n) * sizeof(char *));
|
|
+ envp[i] = xmalloc(40);
|
|
+ snprintf(envp[i], 40, "TTYD_X_REAL_IP=%s", pss->hdr_real_ip);
|
|
+ }
|
|
+
|
|
envp[i] = NULL;
|
|
|
|
return envp;
|
|
@@ -149,7 +167,7 @@ static char **build_env(struct pss_tty *pss) {
|
|
|
|
static bool spawn_process(struct pss_tty *pss, uint16_t columns, uint16_t rows) {
|
|
pty_process *process = process_init((void *)pty_ctx_init(pss), server->loop, build_args(pss), build_env(pss));
|
|
- if (server->cwd != NULL) process->cwd = strdup(server->cwd);
|
|
+ if (server->cwd != NULL) process->cwd = strdup(server->cwd);
|
|
if (columns > 0) process->columns = columns;
|
|
if (rows > 0) process->rows = rows;
|
|
if (pty_spawn(process, process_read_cb, process_exit_cb) != 0) {
|
|
@@ -201,6 +219,16 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user,
|
|
|
|
switch (reason) {
|
|
case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION:
|
|
+
|
|
+ char tgt[254];
|
|
+ memset(tgt, 0, sizeof(tgt));
|
|
+ lws_hdr_copy(wsi, tgt, sizeof(tgt), WSI_TOKEN_X_FORWARDED_FOR);
|
|
+ snprintf(pss->hdr_fwd_for, sizeof(pss->hdr_fwd_for), "%s", tgt);
|
|
+
|
|
+ memset(tgt, 0, sizeof(tgt));
|
|
+ lws_hdr_copy(wsi, tgt, sizeof(tgt), WSI_TOKEN_HTTP_X_REAL_IP);
|
|
+ snprintf(pss->hdr_real_ip, sizeof(pss->hdr_real_ip), "%s", tgt);
|
|
+
|
|
if (server->once && server->client_count > 0) {
|
|
lwsl_warn("refuse to serve WS client due to the --once option.\n");
|
|
return 1;
|
|
@@ -245,7 +273,7 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user,
|
|
}
|
|
|
|
server->client_count++;
|
|
-
|
|
+
|
|
lws_get_peer_simple(lws_get_network_wsi(wsi), pss->address, sizeof(pss->address));
|
|
lwsl_notice("WS %s - %s, clients: %d\n", pss->path, pss->address, server->client_count);
|
|
break;
|
|
diff --git a/src/server.h b/src/server.h
|
|
index 4a659b0..a39717f 100644
|
|
--- a/src/server.h
|
|
+++ b/src/server.h
|
|
@@ -43,6 +43,8 @@ struct pss_tty {
|
|
char user[30];
|
|
char address[50];
|
|
char path[128];
|
|
+ char hdr_fwd_for[128];
|
|
+ char hdr_real_ip[128];
|
|
char **args;
|
|
int argc;
|
|
|
|
|