Statistics
| Branch: | Tag: | Revision:

root / vncauthproxy / client.py @ 75eed2cf

History | View | Annotate | Download (1.5 kB)

1
#!/usr/bin/env python
2
#
3
# Copyright (c) 2010-2011 Greek Research and Technology Network S.A.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19

    
20
import sys
21
import socket
22

    
23
try:
24
    import simplejson as json
25
except ImportError:
26
    import json
27

    
28
CTRL_SOCKET = "/var/run/vncauthproxy/ctrl.sock"
29

    
30
def request_forwarding(sport, daddr, dport, password):
31
    assert(len(password) > 0)
32
    req = {
33
        "source_port": int(sport),
34
        "destination_address": daddr,
35
        "destination_port": int(dport),
36
        "password": password
37
    }
38

    
39
    ctrl = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
40
    ctrl.connect(CTRL_SOCKET)
41
    ctrl.send(json.dumps(req))
42

    
43
    response = ctrl.recv(1024)
44
    res = json.loads(response)
45
    return res
46

    
47
if __name__ == '__main__':
48
    res = request_forwarding(*sys.argv[1:])
49
    if res['status'] == "OK":
50
        sys.exit(0)
51
    else:
52
        sys.exit(1)