[Libwebsockets] using unix or tcp sockets?

Per Bothner per at bothner.com
Tue Aug 29 20:22:14 CEST 2017


Here is a design that uses plain http:/ws: for local terminals,
and ssh tunnels for remote tunnels.  Does this make sense?

** LOCAL CONNECTIONS

When server starts, it generates a random KEY, starts an http server on
some available PORT, and writes the following to /tmp/domterm-$UID.html
(only readable by user $UID):
   <script>
   var domterm_port = PORT;
   var doterm_key = KEY;
   var domterm_pid = PID; /* of server */
   location = "http://localhost:"+domterm_port+"/?key="+encode(domterm_key);
   </script>

When 'domterm' (client) wants to create a new terminal,
it checks if /tmp/domterm-$UID.html exists (and if
the contained PID is alive) - if not it starts the server.
The client then opens a browser window on file:/tmp/domterm-$UID.html
(Note this avoids secret information on the command-line,
where it could be inspected by 'ps'.)
The browser re-directs to the server listening on PORT.
The server checks that the supplied KEY matches, and
sets up the ws: connection.

To handle other commands, such as connecting to an existing session,
we need a slightly more complex protocol: The client can encode
request information in the hash part #OPTIONS - for example:
   file:/tmp/domterm-$UID.html#attach-session=SESSION_NAME
The redirection in /tmp/domterm-$UID.html needs to move the hash #OPTIONS
to some other part of the URL it sends to the server, perhaps a
query string ?OPTIONS.

** REMOTE CONNECTIONS

$ domterm remote HOST COMMAND ....
Create local server, if need be.
Use ssh to connect to remote HOST and if necessary start server
(check for HOST:/tmp/domterm-$UID.html).  Get (remote) PORT and KEY.
Create domain socket /tmp/domterm-HOST-UID.socket
Set up ssh fowarding from /tmp/domterm-HOST-UID.socket to HOST:PORT
Server creates local session as a proxy to /tmp/domterm-HOST-UID.socket.
Client opens browser on /tmp/domterm-$UID.html#remote=HOST
or something like that.
-- 
	--Per Bothner
per at bothner.com   http://per.bothner.com/



More information about the Libwebsockets mailing list