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.

50 lines
1.3 KiB

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