29 lines
879 B
Python
Executable File
29 lines
879 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import ldap
|
|
import getpass
|
|
import pprint
|
|
|
|
from sys import argv
|
|
|
|
MEMBER_FILTER = ('(|'
|
|
'(memberOf=cn=starving,ou=Group,dc=hackerspace,dc=pl)'
|
|
'(memberOf=cn=fatty,ou=Group,dc=hackerspace,dc=pl)'
|
|
'(memberOf=cn=potato,ou=Group,dc=hackerspace,dc=pl)'
|
|
')')
|
|
|
|
def get_target_cards(c):
|
|
cards = set()
|
|
for user, attrs in c.search_s('ou=People,dc=hackerspace,dc=pl',ldap.SCOPE_SUBTREE,'(&(mifareIDHash=*)%s)' % MEMBER_FILTER, ['mifareIDHash', 'uid']):
|
|
for h in attrs['mifareIDHash']:
|
|
cards.add(h.decode('ascii'))
|
|
return cards
|
|
|
|
if __name__ == "__main__":
|
|
c = ldap.initialize('ldap://ldap.hackerspace.pl')
|
|
c.start_tls_s()
|
|
c.simple_bind_s('uid=%s,ou=People,dc=hackerspace,dc=pl' % (getpass.getuser(),), getpass.getpass('LDAP password: '))
|
|
target = get_target_cards(c)
|
|
for h in target:
|
|
print(h)
|