root / util / vapclient.py @ 9a6eacb9
History | View | Annotate | Download (1.3 kB)
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 |
CTRL_SOCKET = "/tmp/vncproxy.sock"
|
25 |
|
26 |
def request_forwarding(sport, daddr, dport, password): |
27 |
sport = str(int(sport)) |
28 |
dport = str(int(dport)) |
29 |
assert(len(password) > 0) |
30 |
|
31 |
request = ":".join([sport, daddr, dport, password])
|
32 |
|
33 |
ctrl = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
34 |
|
35 |
ctrl.connect(CTRL_SOCKET) |
36 |
ctrl.send(request) |
37 |
response = ctrl.recv(1024)
|
38 |
if response == "OK\n": |
39 |
return True |
40 |
else:
|
41 |
return False |
42 |
|
43 |
if __name__ == '__main__': |
44 |
if not request_forwarding(*sys.argv[1:]): |
45 |
sys.exit(1)
|