Statistics
| Branch: | Tag: | Revision:

root / vncauthproxy / client.py @ 75eed2cf

History | View | Annotate | Download (1.5 kB)

1 66d17b40 Apollon Oikonomopoulos
#!/usr/bin/env python
2 0c251ab5 Apollon Oikonomopoulos
#
3 7183f55d Faidon Liambotis
# Copyright (c) 2010-2011 Greek Research and Technology Network S.A.
4 0c251ab5 Apollon Oikonomopoulos
#
5 0c251ab5 Apollon Oikonomopoulos
# This program is free software; you can redistribute it and/or modify
6 0c251ab5 Apollon Oikonomopoulos
# it under the terms of the GNU General Public License as published by
7 0c251ab5 Apollon Oikonomopoulos
# the Free Software Foundation; either version 2 of the License, or
8 0c251ab5 Apollon Oikonomopoulos
# (at your option) any later version.
9 0c251ab5 Apollon Oikonomopoulos
#
10 0c251ab5 Apollon Oikonomopoulos
# This program is distributed in the hope that it will be useful, but
11 0c251ab5 Apollon Oikonomopoulos
# WITHOUT ANY WARRANTY; without even the implied warranty of
12 0c251ab5 Apollon Oikonomopoulos
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 0c251ab5 Apollon Oikonomopoulos
# General Public License for more details.
14 0c251ab5 Apollon Oikonomopoulos
#
15 0c251ab5 Apollon Oikonomopoulos
# You should have received a copy of the GNU General Public License
16 0c251ab5 Apollon Oikonomopoulos
# along with this program; if not, write to the Free Software
17 0c251ab5 Apollon Oikonomopoulos
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 0c251ab5 Apollon Oikonomopoulos
# 02110-1301, USA.
19 66d17b40 Apollon Oikonomopoulos
20 66d17b40 Apollon Oikonomopoulos
import sys
21 66d17b40 Apollon Oikonomopoulos
import socket
22 66d17b40 Apollon Oikonomopoulos
23 48b1400e Vangelis Koukis
try:
24 48b1400e Vangelis Koukis
    import simplejson as json
25 48b1400e Vangelis Koukis
except ImportError:
26 48b1400e Vangelis Koukis
    import json
27 48b1400e Vangelis Koukis
28 7183f55d Faidon Liambotis
CTRL_SOCKET = "/var/run/vncauthproxy/ctrl.sock"
29 66d17b40 Apollon Oikonomopoulos
30 66d17b40 Apollon Oikonomopoulos
def request_forwarding(sport, daddr, dport, password):
31 66d17b40 Apollon Oikonomopoulos
    assert(len(password) > 0)
32 48b1400e Vangelis Koukis
    req = {
33 48b1400e Vangelis Koukis
        "source_port": int(sport),
34 48b1400e Vangelis Koukis
        "destination_address": daddr,
35 48b1400e Vangelis Koukis
        "destination_port": int(dport),
36 48b1400e Vangelis Koukis
        "password": password
37 48b1400e Vangelis Koukis
    }
38 66d17b40 Apollon Oikonomopoulos
39 66d17b40 Apollon Oikonomopoulos
    ctrl = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
40 66d17b40 Apollon Oikonomopoulos
    ctrl.connect(CTRL_SOCKET)
41 48b1400e Vangelis Koukis
    ctrl.send(json.dumps(req))
42 48b1400e Vangelis Koukis
43 66d17b40 Apollon Oikonomopoulos
    response = ctrl.recv(1024)
44 48b1400e Vangelis Koukis
    res = json.loads(response)
45 48b1400e Vangelis Koukis
    return res
46 66d17b40 Apollon Oikonomopoulos
47 66d17b40 Apollon Oikonomopoulos
if __name__ == '__main__':
48 48b1400e Vangelis Koukis
    res = request_forwarding(*sys.argv[1:])
49 48b1400e Vangelis Koukis
    if res['status'] == "OK":
50 48b1400e Vangelis Koukis
        sys.exit(0)
51 48b1400e Vangelis Koukis
    else:
52 48b1400e Vangelis Koukis
        sys.exit(1)