1 |
|
#!/usr/bin/env python
|
2 |
|
#
|
3 |
|
|
4 |
|
# Copyright (c) 2010 GRNET SA
|
5 |
|
#
|
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.
|
10 |
|
#
|
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.
|
15 |
|
#
|
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
|
19 |
|
# 02110-1301, USA.
|
20 |
|
|
21 |
|
import sys
|
22 |
|
import socket
|
23 |
|
|
24 |
|
try:
|
25 |
|
import simplejson as json
|
26 |
|
except ImportError:
|
27 |
|
import json
|
28 |
|
|
29 |
|
CTRL_SOCKET = "/tmp/vncproxy.sock"
|
30 |
|
|
31 |
|
def request_forwarding(sport, daddr, dport, password):
|
32 |
|
assert(len(password) > 0)
|
33 |
|
req = {
|
34 |
|
"source_port": int(sport),
|
35 |
|
"destination_address": daddr,
|
36 |
|
"destination_port": int(dport),
|
37 |
|
"password": password
|
38 |
|
}
|
39 |
|
|
40 |
|
ctrl = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
41 |
|
ctrl.connect(CTRL_SOCKET)
|
42 |
|
ctrl.send(json.dumps(req))
|
43 |
|
|
44 |
|
response = ctrl.recv(1024)
|
45 |
|
res = json.loads(response)
|
46 |
|
return res
|
47 |
|
|
48 |
|
if __name__ == '__main__':
|
49 |
|
res = request_forwarding(*sys.argv[1:])
|
50 |
|
if res['status'] == "OK":
|
51 |
|
sys.exit(0)
|
52 |
|
else:
|
53 |
|
sys.exit(1)
|