-o, --once Accept only one client and exit on disconnection
-B, --browser Open terminal with the default system browser
-I, --index Custom index.html path
+ -b, --base-path Expected base path for requests coming from a reverse proxy (eg: /mounted/here)
-6, --ipv6 Enable IPv6 support
-S, --ssl Enable SSL
-C, --ssl-cert SSL certificate file path
p = buffer + LWS_PRE;
end = p + sizeof(buffer) - LWS_PRE;
- if (strncmp(pss->path, "/token", 6) == 0) {
+ if (strcmp(pss->path, endpoints.token) == 0) {
const char *credential = server->credential != NULL ? server->credential : "";
size_t n = sprintf(buf, "{\"token\": \"%s\"}", credential);
if (lws_add_http_header_status(wsi, HTTP_STATUS_OK, &p, end))
break;
}
- if (strcmp(pss->path, "/") != 0) {
+ if (strcmp(pss->path, endpoints.index) != 0) {
lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL);
goto try_to_reuse;
}
lwsl_warn("refuse to serve WS client due to the --max-clients option.\n");
return 1;
}
- if (lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_GET_URI) <= 0 || strcmp(buf, WS_PATH) != 0) {
+ if (lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_GET_URI) <= 0 || strcmp(buf, endpoints.ws) != 0) {
lwsl_warn("refuse to serve WS client for illegal ws path: %s\n", buf);
return 1;
}
volatile bool force_exit = false;
struct lws_context *context;
struct server *server;
+struct endpoints endpoints = {"/ws", "/", "/token"};
// websocket protocols
static const struct lws_protocols protocols[] = {
{"gid", required_argument, NULL, 'g'},
{"signal", required_argument, NULL, 's'},
{"index", required_argument, NULL, 'I'},
+ {"base-path", required_argument, NULL, 'b'},
{"ipv6", no_argument, NULL, '6'},
{"ssl", no_argument, NULL, 'S'},
{"ssl-cert", required_argument, NULL, 'C'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, 0, 0}
};
-static const char *opt_string = "p:i:c:u:g:s:I:6aSC:K:A:Rt:T:Om:oBd:vh";
+static const char *opt_string = "p:i:c:u:g:s:I:b:6aSC:K:A:Rt:T:Om:oBd:vh";
void print_help() {
fprintf(stderr, "ttyd is a tool for sharing terminal over the web\n\n"
" -o, --once Accept only one client and exit on disconnection\n"
" -B, --browser Open terminal with the default system browser\n"
" -I, --index Custom index.html path\n"
+ " -b, --base-path Expected base path for requests coming from a reverse proxy (eg: /mounted/here)\n"
#ifdef LWS_WITH_IPV6
" -6, --ipv6 Enable IPv6 support\n"
#endif
return -1;
}
break;
+ case 'b': {
+ char path[128];
+ strncpy(path, optarg, 128);
+ size_t len = strlen(path);
+ #define sc(f) \
+ strncpy(path + len, endpoints.f, 128 - len); \
+ endpoints.f = strdup(path);
+ sc(ws) sc(index) sc(token)
+ #undef sc
+ }
+ break;
case '6':
info.options &= ~(LWS_SERVER_OPTION_DISABLE_IPV6);
break;