summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomek Dubrownik <t.dubrownik@gmail.com>2012-01-05 18:32:58 +0100
committerTomek Dubrownik <t.dubrownik@gmail.com>2012-01-05 18:32:58 +0100
commit8747af607a1a82257004b99a8e95f9cc2bae9fac (patch)
tree2dc1125572205529ffe021bc456d4563bb5ba49d
parent511296b8d91f84f20f0250a4cf4248cc56455dbc (diff)
downloaddoorman-8747af607a1a82257004b99a8e95f9cc2bae9fac.tar.gz
doorman-8747af607a1a82257004b99a8e95f9cc2bae9fac.tar.bz2
doorman-8747af607a1a82257004b99a8e95f9cc2bae9fac.tar.xz
doorman-8747af607a1a82257004b99a8e95f9cc2bae9fac.zip
testing
-rwxr-xr-xadmin/doorman_add9
-rwxr-xr-xadmin/doorman_scan6
-rw-r--r--admin/lib/actions.py13
-rw-r--r--admin/lib/command.py4
-rw-r--r--admin/lib/csvstore.py4
-rw-r--r--admin/lib/proto.py2
-rw-r--r--admin/lib/storage.py10
7 files changed, 23 insertions, 25 deletions
diff --git a/admin/doorman_add b/admin/doorman_add
index f4167f2..248d0e8 100755
--- a/admin/doorman_add
+++ b/admin/doorman_add
@@ -12,17 +12,16 @@ if __name__ == '__main__':
url = argv[2] if len(argv) > 2 else None
uname = argv[1]
token = get_token()
- pin = get_pin()
proto = Proto(url)
print 'Please swipe token'
frame = scan(token=token, proto=proto)
- assert(frame.command == 'S')
+ assert(frame.command.upper() == 'S')
if frame.uid:
print >> stderr, 'E: Token already in use (user %d)' % frame.uid
exit(1)
- status = add(token, frame.mid, pin, proto=proto)
- if status.command == 'C':
- add_user(uname, frame.mid, status.uid)
+ status = add(token, frame.hash, proto=proto)
+ if status.command.upper() == 'C':
+ add_user(uname, frame.hash, status.uid)
print 'User %s added successfully (uid=%d)' % (uname, status.uid)
else:
print >> stderr, 'Unknown error:', str(status)
diff --git a/admin/doorman_scan b/admin/doorman_scan
index 7e93582..9919f83 100755
--- a/admin/doorman_scan
+++ b/admin/doorman_scan
@@ -13,6 +13,6 @@ if __name__ == '__main__':
proto = Proto(url)
print 'Please swipe token'
c = scan(token, proto=proto)
- assert(c.command == 'S')
- print 'CardID: %x, UID: %x, Username: %s' % \
- (c.mid, c.uid, get_card(c.mid)[1])
+ assert(c.command.upper() == 'S')
+ print 'Hash: %s, UID: %x, Username: %s' % \
+ (c.hash, c.uid, get_card(c.hash)[1])
diff --git a/admin/lib/actions.py b/admin/lib/actions.py
index c6b5840..12f45a3 100644
--- a/admin/lib/actions.py
+++ b/admin/lib/actions.py
@@ -3,21 +3,20 @@ from command import Command
def scan(token, url=None, proto=None):
proto = proto or Proto(url)
- proto.send(Command(command='G', mid=0, uid=0, token=token))
+ proto.send(Command(command='G', uid=0, hash=0, token=token))
return proto.recv()
-def add(token, mid, pin, uid=0, url=None, proto=None):
+def add(token, hash, uid=0, url=None, proto=None):
proto = proto or Proto(url)
- proto.send(Command(command='A', mid=mid, uid=uid,
- pin=''.join(chr(i + ord('0')) for i in pin), token=token))
+ proto.send(Command(command='A', hash=hash, uid=uid, token=token))
return proto.recv()
def revoke_uid(token, uid, url=None, proto=None):
proto = proto or Proto(url)
- proto.send(Command(command='R', mid=0, uid=uid, token=token))
+ proto.send(Command(command='R', hash=0, uid=uid, token=token))
return proto.recv()
-def revoke_mid(token, mid, url=None, proto=None):
+def revoke_hash(token, hash, url=None, proto=None):
proto = proto or Proto(url)
- proto.send(Command(command='R', mid=mid, uid=0, token=token))
+ proto.send(Command(command='R', hash=hash, uid=0, token=token))
return proto.recv()
diff --git a/admin/lib/command.py b/admin/lib/command.py
index 6d6be4a..00e88cd 100644
--- a/admin/lib/command.py
+++ b/admin/lib/command.py
@@ -63,11 +63,9 @@ Command = frame('Command', [
Const('$'),
Char('command', cmd_bytes),
Const(','),
- Hex('mid', mid_bytes),
- Const(','),
Hex('uid', uid_bytes),
Const(','),
- Char('pin', pin_bytes),
+ Char('hash', hash_bytes),
Const(','),
Char('token', token_bytes),
])
diff --git a/admin/lib/csvstore.py b/admin/lib/csvstore.py
index 317d6e2..8bb8965 100644
--- a/admin/lib/csvstore.py
+++ b/admin/lib/csvstore.py
@@ -1,3 +1,4 @@
+from sys import stderr
from UserDict import IterableUserDict
from StringIO import StringIO
@@ -10,7 +11,8 @@ class Storage(IterableUserDict):
try:
stored = {x[0]: [x[1], x[2]]
for x in csv.reader(StringIO(self.encapsulation.data))}
- except IOError:
+ except IOError as e:
+ print >>stderr, e
stored = {}
IterableUserDict.__init__(self, stored)
def sync(self):
diff --git a/admin/lib/proto.py b/admin/lib/proto.py
index f22be30..b74af1b 100644
--- a/admin/lib/proto.py
+++ b/admin/lib/proto.py
@@ -26,5 +26,5 @@ class Proto(object):
line = self.fd.readline()
cmd = Command.from_str(line)
if cmd.command == 'E':
- raise RemoteException(cmd.mid, cmd.uid)
+ raise RemoteException(cmd.hash, cmd.uid)
return cmd
diff --git a/admin/lib/storage.py b/admin/lib/storage.py
index 1d5b992..d68c868 100644
--- a/admin/lib/storage.py
+++ b/admin/lib/storage.py
@@ -27,15 +27,15 @@ to_hex = lambda v: '%x' % v
from_hex = lambda v: int(v, 16)
dehex = lambda s: int(s.translate(None, 'xXlL'), 16)
-get_card = lambda mid: storage.get(to_hex(mid), nobody)
+get_card = lambda h: storage.get(h, nobody)
cards_for_user = lambda name: map(lambda (k,v): from_hex(k),
filter(lambda (k,(u,n)): n == name, storage.iteritems()))
-def add_user(username, mid, uid):
- storage[to_hex(mid)] = (uid, username)
+def add_user(username, hash, uid):
+ storage[hash] = (uid, username)
-def del_card(mid):
- return storage.pop(to_hex(mid), nobody)
+def del_card(hash):
+ return storage.pop(hash, nobody)
def del_filter(f):
cards = map(lambda (k,v): k, filter(f, storage.iteritems()))