admin scripts
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.

48 lines
1.5 KiB

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