def ensure_settings(): # Check the settings table, there should be one row if db(db.my_app_settings).count() < 1: # Add a row db.my_app_settings.insert() # Make sure LDAP is reset after reloading settings AD.Close() return True
def config_ad_settings(): ensure_settings() rows = db().select(db.my_app_settings.ALL) form = SQLFORM(db.my_app_settings, rows[0], showid=False, fields=[ "ad_import_enabled", "ad_service_user", "ad_service_password", "ad_server_protocol", "ad_server_address" ]).process() if form.accepted: # Saved response.flash = "Settings Saved!" AD.Close() pass elif form.errors: response.flash = "Error! " + str(form.errors) return dict(form=form)
def faculty_do_import(): AD.Close() sheet_name = request.vars.sheet_name erase_current_password = False if request.vars.erase_current_password == "True": erase_current_password = True erase_current_quota = False if request.vars.erase_current_quota == "True": erase_current_quota = True # Add faculty account to faculty_info table count = Faculty.CreateW2PyAccounts(sheet_name, erase_current_password, erase_current_quota) # Setup queue for canvas and for ad imports count2 = Faculty.QueueActiveDirectoryImports(sheet_name) count3 = Faculty.QueueCanvasImports(sheet_name) if count2 > count: count = count2 if count3 > count: count = count3 return dict(sheet_name=sheet_name, count=count)
def config_zfs_settings(): ensure_settings() msg = "" rows = db().select(db.my_app_settings.ALL) form = SQLFORM(db.my_app_settings, rows[0], showid=False, fields=[ "zpool_enabled", "zpool_server_address", "zpool_login_user", "zpool_login_password", "zpool_source_dataset", "zpool_dest_dataset", "zpool_sync_setting" ]).process() if form.accepted: # Saved response.flash = "Settings Saved!" AD.Close() pass elif form.errors: response.flash = "Error! " + str(form.errors) return dict(form=form, message=msg)
def config_student_settings(): ensure_settings() rows = db().select(db.my_app_settings.ALL) form = SQLFORM(db.my_app_settings, rows[0], showid=False, fields=[ "student_id_pattern", "student_password_pattern", "student_email_pattern", "ad_student_cn", "ad_student_group_cn", "ad_student_home_directory", "ad_student_home_drive", "ad_student_profile_directory", "ad_student_login_script_path", "ad_student_home_directory_quota" ]).process() if form.accepted: # Saved response.flash = "Settings Saved!" AD.Close() pass elif form.errors: response.flash = "Error! " + str(form.errors) return dict(form=form)
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