4 # Copyright (c) 2010 GRNET SA
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 from django
.utils
import simplejson
as json
26 CTRL_SOCKET
= "/tmp/vncproxy.sock"
29 def request_forwarding(server
, daddr
, dport
, password
, sport
=None, tls
=False):
31 Ask TVAP/VNCAP for a forwarding port.
33 The control socket on TVAP wants a JSON dictionary containing at least the
34 destination port and address, and VNC password. It optionally can accept a
35 requested source port, whether WebSockets should be used, and whether TLS
36 (SSL/WSS) should be used.
55 request
["sport"] = sport
57 request
= json
.dumps(request
)
59 ctrl
= socket
.socket(socket
.AF_INET
, socket
.SOCK_STREAM
)
60 ctrl
.connect((host
, port
))
61 ctrl
.send("%s\r\n" % request
)
62 response
= ctrl
.recv(1024).strip()
65 if response
.startswith("FAIL"):
75 def request_ssh(proxy
, sport
, daddr
, dport
, password
, command
):
77 Ask TVAP/VNCAP for an SSH port.
81 if not password
or not command
:
92 request
["sport"] = sport
94 request
= json
.dumps(request
)
96 ctrl
= socket
.socket(socket
.AF_INET
, socket
.SOCK_STREAM
)
97 ctrl
.connect((host
, port
))
98 ctrl
.send("%s\r\n" % request
)
99 response
= ctrl
.recv(1024).strip()
102 if response
.startswith("FAIL"):
107 if __name__
== '__main__':
108 print request_forwarding(sys
.argv
[1].split(":"), *sys
.argv
[2:])