--client-option, -t Send option to client (format: key=value), repeat to add more options
--check-origin, -O Do not allow websocket connection from different origin
--once, -o Accept only one client and exit on disconnection
+ --browser, -B Open terminal with the default system browser
--index, -I Custom index.html path
--ssl, -S Enable SSL
--ssl-cert, -C SSL certificate file path
{"readonly", no_argument, NULL, 'R'},
{"check-origin", no_argument, NULL, 'O'},
{"once", no_argument, NULL, 'o'},
+ {"browser", no_argument, NULL, 'B'},
{"debug", required_argument, NULL, 'd'},
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, 0, 0}
};
-static const char *opt_string = "p:i:c:u:g:s:r:I:aSC:K:A:Rt:Ood:vh";
+static const char *opt_string = "p:i:c:u:g:s:r:I:aSC:K:A:Rt:OoBd:vh";
void print_help() {
fprintf(stderr, "ttyd is a tool for sharing terminal over the web\n\n"
" --client-option, -t Send option to client (format: key=value), repeat to add more options\n"
" --check-origin, -O Do not allow websocket connection from different origin\n"
" --once, -o Accept only one client and exit on disconnection\n"
+ " --browser, -B Open terminal with the default system browser\n"
" --index, -I Custom index.html path\n"
" --ssl, -S Enable SSL\n"
" --ssl-cert, -C SSL certificate file path\n"
int debug_level = LLL_ERR | LLL_WARN | LLL_NOTICE;
char iface[128] = "";
+ bool browser = false;
bool ssl = false;
char cert_path[1024] = "";
char key_path[1024] = "";
case 'o':
server->once = true;
break;
+ case 'B':
+ browser = true;
+ break;
case 'p':
info.port = atoi(optarg);
if (info.port < 0) {
lwsl_notice("listening on socket %s\n", server->socket_path);
} else {
lwsl_notice("listening on port %d\n", info.port);
+ if (browser) {
+ char url[30];
+ sprintf(url, "%s://localhost:%d", ssl ? "https" : "http", info.port);
+ open_uri(url);
+ }
}
// libwebsockets main loop
#include <string.h>
#include <signal.h>
+#if defined(_WIN32) || defined(__CYGWIN__)
+#include <windows.h>
+#include <shellapi.h>
+#endif
+
void *
xmalloc(size_t size) {
if (size == 0)
return -1;
}
+int
+open_uri(char *uri) {
+#ifdef __APPLE__
+ char command[256];
+ sprintf(command, "open %s > /dev/null 2>&1", uri);
+ return system(command);
+#elif defined(_WIN32) || defined(__CYGWIN__)
+ return ShellExecute(0, 0, uri, 0, 0 , SW_SHOW) > 32 ? 0 : 1;
+#else
+ // check if X server is running
+ if (system("xset -q > /dev/null 2>&1"))
+ return 1;
+ char command[256];
+ sprintf(command, "xdg-open %s > /dev/null 2>&1", uri);
+ return system(command);
+#endif
+}
+
// https://github.com/darkk/redsocks/blob/master/base64.c
char *
base64_encode(const unsigned char *buffer, size_t length) {