Redbrick User management tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

  1. #!/usr/bin/python3
  2. import string
  3. import sys
  4. """
  5. -mak
  6. This simply takes the ldif generated by newyear_ldif.py
  7. and builds it into an ldapmodify formatted ldif.
  8. To be used with the ldap modify query below
  9. ldapmodify -x -D cn=root,ou=ldap,o=redbrick -y /etc/ldap.secret \
  10. -f [LDIF_FROM_THIS_SCRIPT]
  11. """
  12. years_paid = ''
  13. uid = ''
  14. # print modify ldif template
  15. def modifyTemplate(uid, years_paid, newbie, reserved):
  16. if uid != '' and years_paid != '' and reserved is False:
  17. modTemp = "dn: uid=" + uid.strip() + \
  18. "\nchangetype: modify\nreplace: years_paid\nyears_paid: " + \
  19. years_paid.strip() + "\n"
  20. if newbie == '1':
  21. modTemp += "-\nreplace: newbie\nnewbie: FALSE\n\n"
  22. else:
  23. modTemp += "\n"
  24. print(modTemp)
  25. # open ldif
  26. with open(sys.argv[1], 'r') as content:
  27. ldif = content.read()
  28. # split by user
  29. getdn = string.split(ldif, 'dn: uid=')
  30. for i in range(1, len(getdn)):
  31. thisdn = getdn[i].split('\n')
  32. newbie = 'NONE'
  33. reserved = False
  34. # split by users variables
  35. for j in range(0, len(thisdn)):
  36. x = thisdn[j].rstrip()
  37. uid = thisdn[0].rstrip()
  38. if 'reserved' in uid:
  39. reserved = True
  40. try:
  41. if x.startswith("years_paid:"):
  42. years_paid = str(int(x.split()[1])).strip()
  43. elif x.startswith("newbie:"):
  44. newbie = '1'
  45. except IndexError:
  46. break
  47. modifyTemplate(uid, years_paid, newbie, reserved)