Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __enter__(self):
# compile the server
# NOTE empty filename support is a hack to support
# the current test_enet
if self.filename:
proc = run_process([CLANG_CC, path_from_root('tests', self.filename), '-o', 'server', '-DSOCKK=%d' % self.target_port] + shared.get_clang_native_args() + self.args, env=shared.get_clang_native_env(), stdout=PIPE, stderr=PIPE)
print('Socket server build: out:', proc.stdout or '', '/ err:', proc.stderr or '')
process = Popen([os.path.abspath('server')])
self.processes.append(process)
# start the websocket proxy
print('running websockify on %d, forward to tcp %d' % (self.listen_port, self.target_port), file=sys.stderr)
wsp = websockify.WebSocketProxy(verbose=True, listen_port=self.listen_port, target_host="127.0.0.1", target_port=self.target_port, run_once=True)
self.websockify = multiprocessing.Process(target=wsp.start_server)
self.websockify.start()
self.processes.append(self.websockify)
# Make sure both the actual server and the websocket proxy are running
for i in range(10):
try:
if self.do_server_check:
server_sock = socket.create_connection(('localhost', self.target_port), timeout=1)
server_sock.close()
proxy_sock = socket.create_connection(('localhost', self.listen_port), timeout=1)
proxy_sock.close()
break
except IOError:
time.sleep(1)
else:
clean_processes(self.processes)
websockify.ProxyRequestHandler.__init__(self, *args, **kwargs)
@property
def compute_rpcapi(self):
# Lazy load the rpcapi/ComputeAPI upon first use for this connection.
# This way, if we receive a TCP RST, we will not create a ComputeAPI
# object we won't use.
if not self._compute_rpcapi:
self._compute_rpcapi = compute_rpcapi.ComputeAPI()
return self._compute_rpcapi
def socket(self, *args, **kwargs):
return websockify.WebSocketServer.socket(*args, **kwargs)
class NovaWebSocketProxy(websockify.WebSocketProxy):
def __init__(self, *args, **kwargs):
""":param security_proxy: instance of
nova.console.securityproxy.base.SecurityProxy
Create a new web socket proxy, optionally using the
@security_proxy instance to negotiate security layer
with the compute node.
"""
self.security_proxy = kwargs.pop('security_proxy', None)
super(NovaWebSocketProxy, self).__init__(*args, **kwargs)
@staticmethod
def get_logger():
return LOG
def checkKill(self):
while True:
time.sleep(5)
if time.time()-self.lastPing>30:
websockify.logging.getLogger(websockify.WebSocketProxy.log_prefix).info('Client seems to be dead. No ping since 30sec. Killing now.')
os._exit(0)
def handle_pong(self, data):
def start_proxy():
try:
server = WebSocketProxy(RequestHandlerClass=CustomHandler,
**params)
except TypeError:
server = CustomHandler(**params)
server.start_server()
import os, sys, multiprocessing, time
from subprocess import Popen, PIPE, STDOUT
__rootpath__ = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def path_from_root(*pathelems):
return os.path.join(__rootpath__, *pathelems)
sys.path += [path_from_root('tools/'), path_from_root('tools/websockify')]
import websockify
def websockify_func(wsp):
wsp.start_server()
client = websockify.WebSocketProxy(verbose=True, listen_port=28785, target_host="127.0.0.1", target_port=28786, run_once=True)
client_process = multiprocessing.Process(target=websockify_func, args=(client,))
client_process.start()
print 'client on process', client_process.pid
server = websockify.WebSocketProxy(verbose=True, listen_port=28780, target_host="127.0.0.1", target_port=28781, run_once=True)
server_process = multiprocessing.Process(target=websockify_func, args=(server,))
server_process.start()
print 'server on process', server_process.pid
def relay_server(child):
child.communicate()
relay_child = Popen(['python', path_from_root('tools', 'socket_relay.py'), '28781', '28786'])
relay_process = multiprocessing.Process(target=relay_server, args=(relay_child,))
relay_process.start()
print 'relay on process', relay_process.pid
# Start proxying
try:
self.do_proxy(tsock)
except:
if tsock:
tsock.shutdown(socket.SHUT_RDWR)
tsock.close()
if self.verbose:
self.log_message(
"%s:%s: Closed target",
self.server.target_host, self.server.target_port)
raise
class OvirtWebSocketProxy(websockify.WebSocketProxy):
""""
Websocket proxy for usage with oVirt engine.
Leverages websocket.py by Joel Martin
"""
def __init__(self, *args, **kwargs):
self._ticketDecoder = kwargs.pop('ticketDecoder')
self._logger = kwargs.pop('logger')
super(OvirtWebSocketProxy, self).__init__(*args, **kwargs)
def get_logger(self):
return self._logger
class Daemon(service.Daemon):
def run_vnc():
while True:
try:
port = LibvirtConfig.websockify_listen_port()
host = LibvirtConfig.websockify_listen_host()
opts = {
'RequestHandlerClass': RequestHandler,
'target_cfg': sessions,
'listen_host': host,
'listen_port': port
}
log.info('Launching Websockify listening on %s:%s',
host, port)
server = websockify.WebSocketProxy(**opts)
server.start_server()
except:
log.exception('Failed to launch Websockify')
time.sleep(2)
def start_proxy():
server = WebSocketProxy(**params)
server.start_server()
raise exception.ValidationError(detail)
if not self.verify_origin_proto(access_url, origin_scheme):
detail = _("Origin header protocol does not match this host.")
raise exception.ValidationError(detail)
class ZunProxyRequestHandler(ZunProxyRequestHandlerBase,
websockify.ProxyRequestHandler):
def __init__(self, *args, **kwargs):
websockify.ProxyRequestHandler.__init__(self, *args, **kwargs)
def socket(self, *args, **kwargs):
return websockify.WebSocketServer.socket(*args, **kwargs)
class ZunWebSocketProxy(websockify.WebSocketProxy):
@staticmethod
def get_logger():
return LOG