LILiK login and user managment web interface
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.

45 lines
1.7 KiB

  1. def ldap_path(entry, *arg):
  2. if arg:
  3. return "%s,%s"%(ldap_path(entry), ldap_path(arg))
  4. else:
  5. if type(entry) == tuple:
  6. return ldap_path(*entry)
  7. if entry.find(',') != -1:
  8. print(entry)
  9. raise Exception('Warning: ldap query injection detected')
  10. return entry
  11. def clean_user_name(user_name):
  12. return clean_value(user_name.rstrip('lilik.it'))
  13. def clean_value(value):
  14. '''
  15. TODO:
  16. search_filter: the filter of the search request. It must conform to the LDAP
  17. filter syntax specified in RFC4515. If the search filter contains the
  18. following characters you must use the relevant escape ASCII sequence, as per
  19. RFC4515 (section 3):
  20. * -> \\2A, ( -> \\28, ) -> \\29, \ -> \\5C, chr(0) -> \\00.
  21. '''
  22. return value
  23. class DictDiffer(object):
  24. """
  25. Calculate the difference between two dictionaries as:
  26. (1) items added
  27. (2) items removed
  28. (3) keys same in both but changed values
  29. (4) keys same in both and unchanged values
  30. """
  31. def __init__(self, current_dict, past_dict):
  32. self.current_dict, self.past_dict = current_dict, past_dict
  33. self.set_current, self.set_past = set(current_dict.keys()), set(past_dict.keys())
  34. self.intersect = self.set_current.intersection(self.set_past)
  35. def added(self):
  36. return self.set_current - self.intersect
  37. def removed(self):
  38. return self.set_past - self.intersect
  39. def changed(self):
  40. return set(o for o in self.intersect if self.past_dict[o] != self.current_dict[o])
  41. def unchanged(self):
  42. return set(o for o in self.intersect if self.past_dict[o] == self.current_dict[o])