diff options
Diffstat (limited to 'server/piztor/ptp_send.py')
-rw-r--r-- | server/piztor/ptp_send.py | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/server/piztor/ptp_send.py b/server/piztor/ptp_send.py index 22f9842..6c3b476 100644 --- a/server/piztor/ptp_send.py +++ b/server/piztor/ptp_send.py @@ -24,7 +24,8 @@ class _SectionSize: LOCATION_ENTRY = USER_ID + LATITUDE + LONGITUDE PADDING = 1 -host = "localhost" #"localhost" +host = "202.120.7.4" +#host = "localhost" port = 2223 def pack_data(optcode, data): @@ -86,14 +87,26 @@ def gen_set_marker(token, username, lat, lng, deadline): data += pack("!ddL", lat, lng, deadline) return pack_data(0x07, data) +def gen_change_password(token, username, old_pass, new_pass): + data = pack("!32s", token) + data += username + data += chr(0) + data += old_pass + data += chr(0) + data += new_pass + data += chr(0) + return pack_data(0x08, data) + def send(data): received = bytes() + from time import time + begin = time() try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, port)) sock.sendall(data) while True: - rd, wr, err = select([sock], [], [], 10) + rd, wr, err = select([sock], [], []) if rd: buff = sock.recv(4096) if len(buff) == 0: @@ -102,7 +115,10 @@ def send(data): else: break finally: + print "closing" + sock.shutdown(1) sock.close() + print "Waited for {} seconds".format(str(time() - begin)) return received def user_auth(username, password): @@ -112,16 +128,15 @@ def user_auth(username, password): if pl != len(resp): logger.error("User authentication: incorrect packet length") print "status: " + str(status) - print "token: " + get_hex(token) - print get_hex(resp[38:]) +# print "token: " + get_hex(token) except error: logger.error("User authentication: can not parse the response") + print get_hex(resp) return token def update_location(token, username, lat, lng): resp = send(gen_update_location(token, username, lat, lng)) - print get_hex(resp) try: pl, optcode, status = unpack("!LBB", resp[:6]) if pl != len(resp): @@ -183,6 +198,16 @@ def set_marker(token, username, lat, lng, deadline): except error: logger.error("Set marker: can not parse the response") +def change_password(token, username, old_pass, new_pass): + resp = send(gen_change_password(token, username, old_pass, new_pass)) + try: + pl, optcode, status = unpack("!LBB", resp) + if pl != len(resp): + logger.error("Change password: incorrect packet length") + print "status: " + str(status) + except error: + logger.error("Change password: can not pase the response") + def open_push_tunnel(token, username): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, port)) |