Changeset 8076
- Timestamp:
- Sep 12, 2018, 8:54:10 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
n4d-server-plugins/trunk/fuentes/server-install-files/usr/share/n4d/python-plugins/Golem.py
r8027 r8076 396 396 ret=self.delete_student(item.properties["uid"],delete_data) 397 397 ret_list.append(item.properties["uid"] +":"+ret) 398 398 399 400 self.ldap.set_xid("Students",20000) 401 399 402 return ret_list 400 403 … … 413 416 ret_list.append(item.properties["uid"] +":"+ret) 414 417 418 self.ldap.set_xid("Teachers",5000) 419 415 420 return ret_list 416 421 … … 513 518 514 519 result=self.ldap.add_to_group_type(group,uid) 515 516 520 user_info={} 517 521 user_info["uid"]=uid 518 519 path=self.ldap.get_dn(uid) 520 521 if path.find("ou=Students")!=-1: 522 user_info["profile"]="students" 523 if path.find("ou=Teachers")!=-1: 524 user_info["profile"]="teachers" 525 if path.find("ou=Other")!=-1: 526 user_info["profile"]="others" 527 528 529 530 self.peter_pan.execute_python_dir('/usr/share/n4d/hooks/golem',('add_to_group'),{'group':{'cn':group},'user':user_info}) 531 #return must be "true" (string) 532 522 try: 523 path=self.ldap.get_dn(uid) 524 525 if path.find("ou=Students")!=-1: 526 user_info["profile"]="students" 527 if path.find("ou=Teachers")!=-1: 528 user_info["profile"]="teachers" 529 if path.find("ou=Other")!=-1: 530 user_info["profile"]="others" 531 532 533 534 self.peter_pan.execute_python_dir('/usr/share/n4d/hooks/golem',('add_to_group'),{'group':{'cn':group},'user':user_info}) 535 #return must be "true" (string) 536 except: 537 pass 538 533 539 return result 534 540 … … 555 561 surname=unicode(surname).encode("utf8") 556 562 result=self.ldap.change_student_name(uid,name) 557 #print result558 563 result2=self.ldap.change_student_surname(uid,surname) 559 #print result2560 564 if result==result2 and result=="true": 561 565 … … 671 675 672 676 def add_group(self,properties): 677 673 678 properties["description"]=unicode(properties["description"]).encode("utf8") 674 679 result=self.ldap.add_group(properties) … … 677 682 self.create_group_folder(properties["cn"]) 678 683 except Exception as e: 679 print(e)684 return result 680 685 681 686 try: … … 689 694 def get_students_passwords(self): 690 695 691 list = self.ldap.get_students_passwords()692 693 return self.quicksort( list)696 slist = self.ldap.get_students_passwords() 697 698 return self.quicksort(slist) 694 699 695 700 #def get_students_passwords 701 702 def get_teachers_passwords_encrypted(self): 703 704 tlist= self.ldap.get_teachers_passwords() 705 706 return self.quicksort(tlist) 707 708 #def get_teachers_passwords_encrypted 709 696 710 697 711 def get_teachers_passwords(self): 698 699 ret=self.light_get_user_list() 700 712 713 ret=self.ldap.get_teachers_passwords() 701 714 tmp_teachers={} 702 703 for item in ret: 704 705 if item[-1]=="teachers": 706 teacher={} 707 teacher["uid"]=item[1] 708 teacher["cn"]=item[3] 709 teacher["sn"]=item[4] 710 teacher["passwd"]="#! UNKNOWN PASSWORD !#" 711 tmp_teachers[item[1]]=teacher 715 for teacher in ret: 716 tmp_teachers[teacher["uid"]]=teacher 712 717 713 718 … … 715 720 716 721 final_ret=[] 717 718 722 for item in ret2: 719 723 if item["uid"] in tmp_teachers: … … 724 728 final_ret.append(tmp_teachers[item]) 725 729 726 727 730 return final_ret 728 731 729 732 #def get_teachers_passwords 730 733 731 def get_all_passwords(self,force_teachers=True): 734 735 def get_all_passwords(self,force_teachers=False): 736 732 737 slist=self.ldap.get_students_passwords() 733 if not force_teachers: 734 list2=self.pw.get_passwords() 735 else: 736 list2=self.get_teachers_passwords() 738 list2=self.get_teachers_passwords() 739 737 740 for item in list2: 738 741 slist.append(item) 742 739 743 return self.quicksort(slist) 740 744 … … 972 976 973 977 user_list=self.get_user_list("*") 974 pwd_list=self.get_all_passwords(True) 978 slist=self.get_students_passwords() 979 tlist=self.get_teachers_passwords_encrypted() 980 pwd_list=self.quicksort(slist+tlist) 981 975 982 groups=self.get_available_groups() 976 983 … … 995 1002 else: 996 1003 continue 997 998 1004 exported_users[item["uid"]]={} 999 1005 exported_users[item["uid"]]["profile"]=profile … … 1015 1021 exported_users[item["uid"]]["sambaLMPassword"]=item["sambaLMPassword"] 1016 1022 1023 1024 tmp_pwd=self.get_teachers_passwords() 1025 1026 for teacher in tmp_pwd: 1027 if teacher["uid"] in exported_users: 1028 exported_users[teacher["uid"]]["known_password"]=teacher["passwd"] 1029 1017 1030 exported={} 1018 1031 exported["groups"]=exported_groups … … 1022 1035 1023 1036 except Exception as e: 1024 1025 1037 return [False,str(e)] 1026 1038 … … 1029 1041 #def export_llum_info 1030 1042 1043 1031 1044 def import_llum_info(self,exported_info): 1045 1046 def sort_users_by_uidNumber(dic_a): 1047 1048 new_dic={} 1049 new_dic["groups"]=dic_a["groups"] 1050 new_dic["users"]={} 1051 for user in dic_a["users"]: 1052 1053 try: 1054 uidn=int(dic_a["users"][user]["uidNumber"]) 1055 dic_a["users"][user]["uid"]=user 1056 new_dic["users"][uidn]=dic_a["users"][user] 1057 1058 except Exception as e: 1059 continue 1060 1061 return new_dic 1062 1063 #def sort_users_by_uidNumber 1064 1065 exported_info=sort_users_by_uidNumber(exported_info) 1066 1067 skipped=[] 1032 1068 1033 1069 try: … … 1039 1075 self.add_group(properties) 1040 1076 1041 for user in sorted(exported_info["users"]): 1042 1077 for uidn in sorted(exported_info["users"]): 1078 1079 user=exported_info["users"][uidn]["uid"] 1080 1043 1081 uids={} 1044 1082 for key in self.ldap.xid_counters: 1045 1083 uids[key]=int(self.ldap.xid_counters[key]) 1046 1084 1047 1048 1085 properties={} 1049 1086 properties["uid"]=user 1050 properties["cn"]=exported_info["users"][u ser]["cn"]1051 properties["sn"]=exported_info["users"][u ser]["sn"]1052 properties["userPassword"]=exported_info["users"][u ser]["userPassword"]1053 properties["sambaLMPassword"]=exported_info["users"][u ser]["sambaLMPassword"]1054 properties["sambaNTPassword"]=exported_info["users"][u ser]["sambaNTPassword"]1055 1056 if "uidNumber" in exported_info["users"][u ser]:1057 properties["uidNumber"]=exported_info["users"][u ser]["uidNumber"]1058 1059 if "x-lliurex-usertype" in exported_info["users"][u ser]:1060 properties["x-lliurex-usertype"]=exported_info["users"][u ser]["x-lliurex-usertype"]1087 properties["cn"]=exported_info["users"][uidn]["cn"] 1088 properties["sn"]=exported_info["users"][uidn]["sn"] 1089 properties["userPassword"]=exported_info["users"][uidn]["userPassword"] 1090 properties["sambaLMPassword"]=exported_info["users"][uidn]["sambaLMPassword"] 1091 properties["sambaNTPassword"]=exported_info["users"][uidn]["sambaNTPassword"] 1092 1093 if "uidNumber" in exported_info["users"][uidn]: 1094 properties["uidNumber"]=exported_info["users"][uidn]["uidNumber"] 1095 1096 if "x-lliurex-usertype" in exported_info["users"][uidn]: 1097 properties["x-lliurex-usertype"]=exported_info["users"][uidn]["x-lliurex-usertype"] 1061 1098 else: 1062 1099 properties["x-lliurex-usertype"]="generic" 1063 1100 1064 profile=exported_info["users"][user]["profile"] 1065 1101 profile=exported_info["users"][uidn]["profile"] 1102 1103 if int(uids[profile]) > properties["uidNumber"] : 1104 print("Skipping %s ..."%user) 1105 skipped.append(user) 1106 continue 1107 1108 self.ldap.set_xid(profile,properties["uidNumber"]) 1109 uids[profile]=properties["uidNumber"] 1110 self.ldap.xid_counters[profile]=str(uids[profile]) 1066 1111 1067 1112 ret=self.add_user(profile,properties) … … 1073 1118 1074 1119 if profile=="Teachers": 1075 1076 password=properties["userPassword"] 1077 if "{SSHA}" in properties["userPassword"]: 1078 password="#! CHANGED MANUALLY !#" 1120 if "known_password" in exported_info["users"][uidn]: 1121 password=exported_info["users"][uidn]["known_password"] 1122 else: 1123 password=properties["userPassword"] 1124 1125 if "{SSHA}" in password: 1126 password="#! UNKNOWN PASSWORD !#" 1079 1127 1080 1128 self.pw.add_password(properties["uid"],properties["cn"],properties["sn"],password) … … 1082 1130 for group in exported_info["groups"]: 1083 1131 1084 for user in exported_info["groups"][group]["members"]: 1085 self.add_to_group(user,group) 1132 for i in exported_info["groups"][group]["members"]: 1133 try: 1134 if i not in skipped: 1135 self.add_to_group(i,group) 1136 except Exception as e: 1137 pass 1086 1138 1087 1139 for user in exported_info["users"]: 1088 1140 1089 if exported_info["users"][u ser]["is_admin"]:1141 if exported_info["users"][uidn]["is_admin"]: 1090 1142 self.add_teacher_to_admins(user) 1091 1143 1092 1093 for profile in uids:1094 if uids[profile] != int(self.ldap.xid_counters[profile]):1095 self.ldap.set_xid(profile,uids[profile])1096 self.ldap.xid_counters[profile]=str(uids[profile])1097 1098 1099 1144 return[True,] 1145 1100 1146 except Exception as e: 1101 1147 print e 1102 1148 return [False,str(e)] 1103 1149
Note: See TracChangeset
for help on using the changeset viewer.