-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
executable file
·67 lines (61 loc) · 1.63 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
import sys
if not '..' in sys.path:
sys.path.append('..')
if not '/Users/ramsay/python' in sys.path:
sys.path.append('/Users/ramsay/python')
import cgi, cgitb, os, Cookie, re
import socket
import ports
from useful import *
def checkCookie():
cookie = Cookie.SimpleCookie()
cookie_string = os.environ.get('HTTP_COOKIE')
if cookie_string:
cookie.load(cookie_string)
return cookie
def checkPOST(field):
if field in POST:
x = POST[field]
if isinstance(x, tuple):
x = list(x)
if isinstance(x, list):
x = "&".join(map(lambda i: i.value, x))
else:
x = x.value
return x.strip()
else:
return ""
def checkSESSION(field):
if SESSION and field in SESSION:
x = SESSION[field].value
if isinstance(x, tuple):
x = x[0]
return x.strip()
else:
return ""
def tsvPOST():
return "\n".join(["%s\t%s"%(x, checkPOST(x)) for x in POST])
def checklockfile(f):
try:
return open(f).read() == ""
except:
return False
def askserver(msg, port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = 'localhost' # The remote host
while not checklockfile("../locked%s"%(port)):
port += 1
ports.log(port, "askserver(%s, %s)"%(port, msg))
s.connect((host, port))
ports.log(port, "connected(%s, %s)"%(host, port))
s.sendall(msg)
wholething = ""
while True:
data = str(s.recv(1024))
if len(data) > 0:
wholething += str(data)
else:
break
s.close()
return wholething