def EnableAccount(faculty_id): ret = "" db = current.db # Grab the current db object auth = current.auth # Grab the current auth object user_name = Faculty.GetUsername(faculty_id) pw = Faculty.GetPassword(faculty_id) Faculty.SetPassword(faculty_id, pw) # AD - Disable user_dn = Faculty.GetAD_DN(user_name, Faculty.GetProgram(faculty_id)) AD.EnableUser(user_dn) # Update the database to reflect the change db(db.faculty_info.user_id == faculty_id).update(account_enabled=True) return ret
def EnableAccount(student_id): ret = "" db = current.db # Grab the current db object auth = current.auth # Grab the current auth object user_name = Student.GetUsername(student_id) pw = Student.GetPassword(student_id) Student.SetPassword(student_id, pw) # AD - Disable user_dn = Student.GetAD_DN(user_name, Student.GetProgram(student_id)) r = AD.EnableUser(user_dn) # Update the database to reflect the change db(db.student_info.user_id == student_id).update(account_enabled=True) if r is False: ret = "ERROR disabling account - " + AD.GetErrorString() return ret
def ProcessADStudent(): db = current.db # Grab the current db object scheduler = current.scheduler ret = "" # AD.Close() ldap_enabled = AppSettings.GetValue('ad_import_enabled', False) if ldap_enabled is not True: return "Done! - LDAP Import Disabled" if AD.Connect() is not True: ret += "<b>Error connecting to Active Directory server</b><br/><font size=-4>" ret += AD.GetErrorString() ret += "</font><br/>Done!" return ret if AD.VerifyADSettings() is not True: ret += "<b>Error verifying AD settings</b><br/><font size=-4>" ret += AD.GetErrorString() ret += "</font><br/>Done!" return ret else: # If everything is good clear errors AD._errors = [] # ad_student_cn = AppSettings.GetValue('ad_student_cn', 'OU=Students,DC=ad,DC=correctionsed,DC=com') ad_student_group_cn = AppSettings.GetValue( 'ad_student_group_cn', 'OU=StudentGroups,DC=ad,DC=correctionsed,DC=com') ad_student_group_dn = 'CN=Students,' + ad_student_group_cn # Ensure the student group exists if AD.CreateGroup(ad_student_group_dn) is not True: ret += "<b>Error creating students group:</b> " + str( ad_student_group_dn) + "<br />" ret += str(AD._errors) # Grab the first student off the queue rows = db(db.student_import_queue.id == db.student_ad_import_queue.student_import_queue)\ .select(orderby=db.student_import_queue.account_enabled|db.student_import_queue.student_name, limitby=(0, 1)) for row in rows: # Pop the student off the queue db(db.student_ad_import_queue.id == row.student_ad_import_queue.id).delete() db.commit() # Get the student info # Get info for current student student_user_name = Student.GetUsername( row.student_import_queue.user_id) student_password = Student.GetPassword( row.student_import_queue.user_id, row.student_import_queue.student_password) (student_first_name, student_last_name) = Util.ParseName( row.student_import_queue.student_name) student_email = Student.GetEmail(row.student_import_queue.user_id) student_display_name = row.student_import_queue.student_name + " (" + student_user_name + ")" student_user_id = row.student_import_queue.user_id student_home_directory = Student.GetHomeDirectory( row.student_import_queue.user_id) student_home_drive = Student.GetHomeDrive( row.student_import_queue.user_id) student_login_script_path = Student.GetLoginScriptPath( row.student_import_queue.user_id) student_profile_path = Student.GetProfilePath( row.student_import_queue.user_id) student_enabled = row.student_import_queue.account_enabled student_quota = Student.GetADQuota( row.student_import_queue.user_id) student_dn = Student.GetAD_DN(student_user_name, row.student_import_queue.program) student_cn = Student.GetAD_CN(row.student_import_queue.program) first_run = False fr = db(db.student_ad_import_status.user_id == row.student_import_queue.user_id).select().first() if fr is None: first_run = True db.student_ad_import_status.insert( user_id=row.student_import_queue.user_id) db.commit() # print("Student Info: ") # print(" -> User Name: " + str(student_user_name)) # print(" -> Password: "******" -> First Name: " + str(student_first_name)) # print(" -> Last Name: " + str(student_last_name)) # print(" -> Email: " + str(student_email)) # print(" -> Display Name: " + str(student_display_name)) # print(" -> ID: " + str(student_user_id)) # print(" -> Home Dir: " + str(student_home_directory)) # print(" -> Home Drive: " + str(student_home_drive)) # print(" -> Login Script: " + str(student_login_script_path)) # print(" -> Profile Path: " + str(student_profile_path)) # print(" -> Enabled: " + str(student_enabled)) # print(" -> Quota: " + str(student_quota)) # print(" -> AD DN: " + str(student_dn)) # print(" -> AD CN: " + str(student_cn)) # Create the student if AD.CreateUser(student_user_name, student_cn) is not True: ret += "<b>Error creating students account:</b> " + str(student_user_name) +\ " - " + str(student_cn) + "<br />Done!" return ret db.commit() # Update user with current info if AD.UpdateUserInfo(student_dn, email_address=student_email, first_name=student_first_name, last_name=student_last_name, display_name=student_display_name, description="Student Account", id_number=student_user_name, home_drive_letter=student_home_drive, home_directory=student_home_directory, login_script=student_login_script_path, profile_path=student_profile_path, ts_allow_login='******') is not True: ret += "<b>Error creating setting student information:</b> " + str( student_user_name) + "<br />" db.commit() # Set password if AD.SetPassword(student_dn, student_password) is not True: ret += "<b>Error setting password for user:</b> " + str( student_user_name) + "<br />" db.commit() # Add to the students group if AD.AddUserToGroup(student_dn, ad_student_group_dn) is not True: ret += "<b>Error adding user to students group:</b> " + str( student_user_name) + "<br />" db.commit() if student_enabled is True: AD.EnableUser(student_dn) else: AD.DisableUser(student_dn) db.commit() # Get the list of classes for this student if student_enabled is True: enroll_classes = row.student_import_queue.import_classes.split( ',') for enroll_class in enroll_classes: # Trim spaces enroll_class = enroll_class.strip() if enroll_class == '': continue # Skip empty class names Student.AddClass(row.student_import_queue.user_id, enroll_class) class_dn = AD.GetDN(enroll_class, ad_student_group_cn) if AD.GetLDAPObject(class_dn) is None: # Class group doesn't exist, add it if AD.CreateGroup(class_dn) is not True: ret += "<b>Error creating class group:</b> " + str( enroll_class) + "<br />" # Add student to the class group if AD.AddUserToGroup(student_dn, class_dn) is not True: ret += "<b>Error adding student to group:</b> " + str(student_user_name) + "/" +\ str(enroll_class) + "<br />" db.commit() # Setup physical home directory if student_enabled is True: # if (AD.CreateHomeDirectory(student_user_name, student_home_directory) != True): # ret += "<b>Error creating home folder:</b> " + str(student_user_name) + "<br />" if first_run: result = scheduler.queue_task( 'create_home_directory', pvars=dict(user_name=student_user_name, home_directory=student_home_directory), timeout=1200, immediate=True, sync_output=5, group_name="create_home_directory") if AD.SetDriveQuota(student_user_name, student_quota) is not True: ret += "<b>Error setting quota for student:</b> " + str( student_user_name) + "<br />" db.commit() # Show errors if len(AD._errors) > 0: ret += AD.GetErrorString() ret += student_display_name # + " (" + student_user_name + ")" if row.student_import_queue.account_enabled is True: ret += " - <span style='color: green; font-weight: bolder;'>Imported</span>" else: ret += " - <span style='color: red; font-weight: bolder;'>Disabled</span>" if ret == "": ret = "Done!" return ret
def ProcessADFaculty(): db = current.db # Grab the current db object scheduler = current.scheduler ret = "" ldap_enabled = AppSettings.GetValue('ad_import_enabled', False) if ldap_enabled is not True: return "Done! - LDAP Import Disabled" if AD.Connect() is not True: ret += "<b>Error connecting to Active Directory server</b><br/><font size=-4>" ret += AD.GetErrorString() ret += "</font><br/>Done!" return ret if AD.VerifyADSettings() is not True: ret += "<b>Error verifying AD settings</b><br/><font size=-4>" ret += AD.GetErrorString() ret += "</font><br/>Done!" return ret else: # If everything is good clear errors AD._errors = [] ad_faculty_group_cn = AppSettings.GetValue('ad_faculty_group_cn', 'OU=FacultyGroups,DC=ad,DC=correctionsed,DC=com') ad_faculty_group_dn = 'CN=Faculty,' + ad_faculty_group_cn # Ensure the faculty group exists if AD.CreateGroup(ad_faculty_group_dn) is not True: ret += "<b>Error creating faculty group:</b> " + str(ad_faculty_group_dn) + "<br />" ret += str(AD._errors) # Grab the first faculty off the queue rows = db(db.faculty_import_queue.id == db.faculty_ad_import_queue.faculty_import_queue)\ .select(orderby=db.faculty_import_queue.account_enabled|db.faculty_import_queue.faculty_name, limitby=(0, 1)) for row in rows: # Pop the faculty off the queue db(db.faculty_ad_import_queue.id == row.faculty_ad_import_queue.id).delete() db.commit() # Get the faculty info faculty_user_name = Faculty.GetUsername(row.faculty_import_queue.user_id) faculty_password = Faculty.GetPassword(row.faculty_import_queue.user_id, row.faculty_import_queue.faculty_password) (faculty_first_name, faculty_last_name) = Util.ParseName(row.faculty_import_queue.faculty_name) faculty_email = Faculty.GetEmail(row.faculty_import_queue.user_id) faculty_display_name = row.faculty_import_queue.faculty_name + " (" + faculty_user_name + ")" faculty_user_id = row.faculty_import_queue.user_id faculty_home_directory = Faculty.GetHomeDirectory(row.faculty_import_queue.user_id) faculty_home_drive = Faculty.GetHomeDrive(row.faculty_import_queue.user_id) faculty_login_script_path = Faculty.GetLoginScriptPath(row.faculty_import_queue.user_id) faculty_profile_path = Faculty.GetProfilePath(row.faculty_import_queue.user_id) faculty_enabled = row.faculty_import_queue.account_enabled faculty_quota = Faculty.GetADQuota(row.faculty_import_queue.user_id) faculty_dn = Faculty.GetAD_DN(faculty_user_name, row.faculty_import_queue.program) faculty_cn = Faculty.GetAD_CN(row.faculty_import_queue.program) first_run = False fr = db(db.faculty_ad_import_status.user_id==row.faculty_import_queue.user_id).select().first() if fr is None: first_run = True db.faculty_ad_import_status.insert(user_id=row.faculty_import_queue.user_id) db.commit() # Create the faculty if AD.CreateUser(faculty_user_name, faculty_cn) is not True: ret += "<b>Error creating faculty account:</b> " + str(faculty_user_name) + " - " + str(faculty_cn) +\ "<br />Done!" # + AD.GetErrorString() return ret db.commit() # Update user with current info if AD.UpdateUserInfo(faculty_dn, email_address=faculty_email, first_name=faculty_first_name, last_name=faculty_last_name, display_name=faculty_display_name, description="Faculty Account", id_number=faculty_user_name, home_drive_letter=faculty_home_drive, home_directory=faculty_home_directory, login_script=faculty_login_script_path, profile_path=faculty_profile_path, ts_allow_login='******') is not True: ret += "<b>Error creating setting faculty information:</b> " + str(faculty_user_name) + "<br />" db.commit() # Set password if AD.SetPassword(faculty_dn, faculty_password) is not True: ret += "<b>Error setting password for user:</b> " + str(faculty_user_name) + "<br />" db.commit() # Add to the faculty group if AD.AddUserToGroup(faculty_dn, ad_faculty_group_dn) is not True: ret += "<b>Error adding user to faculty group:</b> " + str(faculty_user_name) + "<br />" db.commit() if faculty_enabled is True: AD.EnableUser(faculty_dn) else: AD.DisableUser(faculty_dn) db.commit() # NOTE - We do NOT want to remove faculty from anything automatically # Get the list of classes for this faculty if faculty_enabled is True: enroll_classes = row.faculty_import_queue.import_classes.split(',') for enroll_class in enroll_classes: # Trim spaces enroll_class = enroll_class.strip() if enroll_class == '': continue # Skip empty class names # ret += "Enrolling into: " + enroll_class Faculty.AddClass(row.faculty_import_queue.user_id, enroll_class) class_dn = AD.GetDN(enroll_class + "-F", ad_faculty_group_cn) if AD.GetLDAPObject(class_dn) is None: # Class group doesn't exist, add it if AD.CreateGroup(class_dn) is not True: ret += "<b>Error creating class group:</b> " + str(enroll_class) + "<br />" # Add faculty to the class group if AD.AddUserToGroup(faculty_dn, class_dn) is not True: ret += "<b>Error adding faculty to group:</b> " + str(faculty_user_name) +\ "/" + str(enroll_class) + "<br />" db.commit() # Setup physical home directory if faculty_enabled is True: # if (AD.CreateHomeDirectory(faculty_user_name, faculty_home_directory) != True): # ret += "<b>Error creating home folder:</b> " + str(faculty_user_name) + "<br />" if first_run: result = scheduler.queue_task('create_home_directory', pvars=dict(user_name=faculty_user_name, home_directory=faculty_home_directory), timeout=1200, immediate=True, sync_output=5, group_name="create_home_directory") if AD.SetDriveQuota(faculty_user_name, faculty_quota) is not True: ret += "<b>Error setting quota for faculty:</b> " + str(faculty_user_name) + "<br />" db.commit() # Show errors if len(AD._errors) > 0: ret += AD.GetErrorString() ret += faculty_display_name # + " (" + faculty_user_name + ")" if row.faculty_import_queue.account_enabled is True: ret += " - <span style='color: green; font-weight: bolder;'>Imported</span>" else: ret += " - <span style='color: red; font-weight: bolder;'>Disabled</span>" # Finished importing, clean up after AD AD.Close() if ret == "": ret = "Done!" return ret