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.

50 lines
1.8 KiB

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