Skip to content

Commit

Permalink
#3592 remove unused tcp-proxy feature
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jul 22, 2022
1 parent b1fbf61 commit 3cd21fb
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 96 deletions.
6 changes: 1 addition & 5 deletions fs/etc/xpra/conf.d/50_server_network.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ ssl = auto


########################################################################
# html / tcp-proxy:

# Where to send non xpra clients:
# (can be used to share the port with a web server)
#tcp-proxy = 127.0.0.1:80
# html

# Respond to HTTP requests on the TCP ports (requires bind-tcp):
#html = no
Expand Down
8 changes: 0 additions & 8 deletions fs/share/man/man1/xpra.1
Original file line number Diff line number Diff line change
Expand Up @@ -1039,15 +1039,7 @@ xpra will not try to start a new one and it will just attach to it.
.TP
.SS Options for start, start-desktop, upgrade, shadow
.TP
\fB--tcp-proxy\fP=\fIHOST:PORT\fP
Specifies the address to which non-xpra packets will be forwarded.
This can be used to share the same TCP port with another
TCP servers, usually a web server.
xpra clients will connect as usual, but any client that does not
speak the xpra protocol will be forwarded to the alternative
server.

.TP
\fB--html\fP=\fIon\fP|\fIoff\fP|\fIauto\fP|\fIwebrootpath\fP
Respond to HTTP requests on the TCP port(s) and local sockets.
This requires at least one TCP or local socket to be configured
Expand Down
3 changes: 1 addition & 2 deletions xpra/net/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,7 @@ def gibberish(self, msg, data):


#delegates to invalid_header()
#(so this can more easily be intercepted and overriden
# see tcp-proxy)
#(so this can more easily be intercepted and overriden)
def invalid_header(self, proto, data, msg="invalid packet header"):
self._invalid_header(proto, data, msg)

Expand Down
2 changes: 0 additions & 2 deletions xpra/net/rfb/rfb_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ def invalid(self, msg, data):


#delegates to invalid_header()
#(so this can more easily be intercepted and overriden
# see tcp-proxy)
def invalid_header(self, proto, data, msg=""):
log("invalid_header%s", (proto, data, msg))
self._invalid_header(proto, data, msg)
Expand Down
2 changes: 0 additions & 2 deletions xpra/scripts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ def may_create_user_config(xpra_conf_filename=DEFAULT_XPRA_CONF_FILENAME):
"desktop-scaling" : str,
"refresh-rate" : str,
"display" : str,
"tcp-proxy" : str,
"download-path" : str,
"open-command" : str,
"remote-logging" : str,
Expand Down Expand Up @@ -975,7 +974,6 @@ def get_defaults():
"desktop-scaling" : "on",
"refresh-rate" : "auto",
"display" : "",
"tcp-proxy" : "",
"download-path" : get_download_dir(),
"open-command" : " ".join(OPEN_COMMAND),
"remote-logging" : "both",
Expand Down
3 changes: 1 addition & 2 deletions xpra/scripts/fdproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class XpraProxy:
"""
This is the proxy command that runs
when one uses the hidden subcommand
"xpra _proxy" or when forwarding data
using the tcp-proxy option.
"xpra _proxy".
It simply forwards stdin/stdout to
the server socket.
"""
Expand Down
4 changes: 0 additions & 4 deletions xpra/scripts/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,10 +966,6 @@ def dcsv(v):
dest="systemd_run_args", default=defaults.systemd_run_args,
help="Command line arguments passed to systemd-run. Default: '%default'.")
legacy_bool_parse("html")
group.add_option("--tcp-proxy", action="store",
dest="tcp_proxy", default=defaults.tcp_proxy,
metavar="HOST:PORT",
help="The address to which non-xpra packets will be forwarded. Default: '%default'.")
group.add_option("--http-scripts", action="store",
dest="http_scripts", default=defaults.http_scripts,
metavar="off|all|SCRIPTS",
Expand Down
76 changes: 5 additions & 71 deletions xpra/server/server_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ def __init__(self):
#networking bits:
self._socket_info = {}
self._potential_protocols = []
self._tcp_proxy_clients = []
self._tcp_proxy = ""
self._rfb_upgrade = 0
self._ssl_attributes = {}
self._accept_timeout = SOCKET_TIMEOUT + 1
Expand Down Expand Up @@ -451,7 +449,6 @@ def do_run(self):

def cleanup(self):
self.stop_splash_process()
self.stop_tcp_proxy_clients()
self.cancel_touch_timer()
self.mdns_cleanup()
self.cleanup_all_protocols()
Expand Down Expand Up @@ -584,8 +581,7 @@ def save_uuid(self):


def init_html_proxy(self, opts):
httplog("init_html_proxy(..) options: tcp_proxy=%s, html='%s'", opts.tcp_proxy, opts.html)
self._tcp_proxy = opts.tcp_proxy
httplog(f"init_html_proxy(..) options: html={opts.html!r}")
#opts.html can contain a boolean, "auto" or the path to the webroot
www_dir = None
if opts.html and os.path.isabs(opts.html):
Expand Down Expand Up @@ -647,10 +643,6 @@ def init_html_proxy(self, opts):
for d in get_user_conf_dirs():
self._http_headers_dirs.append(os.path.join(d, "http-headers"))
self._http_headers_dirs.append(os.path.abspath(os.path.join(self._www_dir, "../http-headers")))
if self._html and self._tcp_proxy:
httplog.warn("Warning: the built in html server is enabled,")
httplog.warn(" disabling the tcp-proxy option")
self._tcp_proxy = False
if opts.http_scripts.lower() not in FALSE_OPTIONS:
script_options = {
"/Status" : self.http_status_request,
Expand Down Expand Up @@ -1195,7 +1187,7 @@ def ssl_wrap():

if socktype in ("tcp", "unix-domain", "named-pipe") and peek_data:
#see if the packet data is actually xpra or something else
#that we need to handle via a tcp proxy, ssl wrapper or the websocket adapter:
#that we need to handle via an ssl wrapper or the websocket adapter:
try:
cont, conn, peek_data = self.may_wrap_socket(conn, socktype, socket_info, socket_options, peek_data)
netlog("may_wrap_socket(..)=(%s, %s, %r)", cont, conn, ellipsizer(peek_data))
Expand Down Expand Up @@ -1457,16 +1449,11 @@ def conn_err(msg):
return False, None, None
self.start_http_socket(socktype, conn, socket_options, is_ssl, peek_data)
return False, conn, None
if self._tcp_proxy and not is_ssl:
netlog.info("New tcp proxy connection received from %s", frominfo)
t = start_thread(self.start_tcp_proxy, "tcp-proxy-for-%s" % frominfo, daemon=True, args=(conn, conn.remote))
netlog("may_wrap_socket handling via tcp proxy thread %s", t)
return False, conn, None
return True, conn, peek_data

def invalid_header(self, proto, data, msg=""):
netlog("invalid header: %s, input_packetcount=%s, tcp_proxy=%s, html=%s, ssl=%s",
ellipsizer(data), proto.input_packetcount, self._tcp_proxy, self._html, bool(self._ssl_attributes))
netlog("invalid header: %s, input_packetcount=%s, html=%s, ssl=%s",
ellipsizer(data), proto.input_packetcount, self._html, bool(self._ssl_attributes))
if data==b"RFB " and self._rfb_upgrade>0:
netlog("RFB header, trying to upgrade protocol")
self.cancel_upgrade_to_rfb_timer(proto)
Expand Down Expand Up @@ -1679,62 +1666,9 @@ def send_http_response(self, handler, content, content_type="text/plain"):
return content


def start_tcp_proxy(self, conn, frominfo):
proxylog("start_tcp_proxy(%s, %s)", conn, frominfo)
#connect to web server:
try:
host, port = self._tcp_proxy.split(":", 1)
port = int(port)
except ValueError as e:
proxylog.error("Error: invalid tcp proxy value '%s'", self._tcp_proxy)
proxylog.error(" %s", e)
conn.close()
return
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(10)
sock.connect((host, int(port)))
sock.settimeout(None)
tcp_server_connection = SocketConnection(sock, sock.getsockname(), sock.getpeername(),
"tcp-proxy-for-%s" % frominfo, "tcp")
except Exception as e:
proxylog("start_tcp_proxy(%s, %s)", conn, frominfo, exc_info=True)
proxylog.error("Error: failed to connect to TCP proxy endpoint: %s:%s", host, port)
proxylog.error(" %s", e)
conn.close()
return
proxylog("proxy connected to tcp server at %s:%s : %s", host, port, tcp_server_connection)
sock.settimeout(self._socket_timeout)

#we can use blocking sockets for the client:
conn.settimeout(None)
#but not for the server, which could deadlock on exit:
sock.settimeout(1)

#now start forwarding:
from xpra.scripts.fdproxy import XpraProxy #pylint: disable=import-outside-toplevel
p = XpraProxy(frominfo, conn, tcp_server_connection, self.tcp_proxy_quit)
self._tcp_proxy_clients.append(p)
proxylog.info("client connection from %s forwarded to proxy server on %s:%s", frominfo, host, port)
p.start_threads()


def stop_tcp_proxy_clients(self):
tpc = tuple(self._tcp_proxy_clients)
netlog("stop_tcp_proxy_clients() stopping %s tcp proxy clients: %s", len(tpc), tpc)
self._tcp_proxy_clients = []
for p in tpc:
p.quit()

def tcp_proxy_quit(self, proxy):
proxylog("tcp_proxy_quit(%s)", proxy)
if proxy in self._tcp_proxy_clients:
self._tcp_proxy_clients.remove(proxy)

def is_timedout(self, protocol):
#subclasses may override this method (ServerBase does)
v = not protocol.is_closed() and protocol in self._potential_protocols and \
protocol not in self._tcp_proxy_clients
v = not protocol.is_closed() and protocol in self._potential_protocols
netlog("is_timedout(%s)=%s", protocol, v)
return v

Expand Down

0 comments on commit 3cd21fb

Please sign in to comment.