summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/piztor/prober.py11
-rw-r--r--server/piztor/ptp_send.py23
-rw-r--r--server/piztor/server.py11
3 files changed, 36 insertions, 9 deletions
diff --git a/server/piztor/prober.py b/server/piztor/prober.py
index eed36f8..bb2bcd3 100644
--- a/server/piztor/prober.py
+++ b/server/piztor/prober.py
@@ -18,9 +18,10 @@ if len(argv) == 3:
token = user_auth(username, password)
-print "Client: " + username + "logged in"
+change_password(token, username, "ddd", "haha")
+#print "Client: " + username + "logged in"
#open_push_tunnel(token, username)
-for i in xrange(100):
- print "Client: " + username + " updateing"
- update_location(token, username, 123.456, 123.456)
-# sleep(5)
+#for i in xrange(100):
+# print "Client: " + username + " updateing"
+# update_location(token, username, 123.456, 123.456)
+## sleep(5)
diff --git a/server/piztor/ptp_send.py b/server/piztor/ptp_send.py
index 96f7726..42a566d 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 = "202.120.7.4" #"localhost"
+#host = "202.120.7.4"
+host = "localhost"
port = 2223
def pack_data(optcode, data):
@@ -86,6 +87,16 @@ 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
@@ -187,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))
diff --git a/server/piztor/server.py b/server/piztor/server.py
index 1d1adc9..d175d99 100644
--- a/server/piztor/server.py
+++ b/server/piztor/server.py
@@ -69,7 +69,7 @@ class _StatusCode:
sucess = 0x00
auth_fail = 0x01
insuf_lvl = 0x02
- wrong_pass = 0x02
+ wrong_pass = 0x03
class PushData(object):
from hashlib import sha256
@@ -646,7 +646,11 @@ class SetMarkerHandler(RequestHandler):
class ChangePasswordHandler(RequestHandler):
_optcode = _OptCode.change_password
- _max_tr_data_size = _MAX_AUTH_HEAD_SIZE
+ _max_tr_data_size = _MAX_AUTH_HEAD_SIZE + \
+ MAX_PASSWORD_SIZE + \
+ _SectionSize.PADDING + \
+ MAX_PASSWORD_SIZE + \
+ _SectionSize.PADDING
def handle(self, tr_data, conn):
self.check_size(tr_data)
@@ -687,7 +691,8 @@ class PTP(Protocol, TimeoutMixin):
UserLogoutHandler,
OpenPushTunnelHandler,
SendTextMessageHandler,
- SetMarkerHandler]
+ SetMarkerHandler,
+ ChangePasswordHandler]
handler_num = len(handlers)