def addAWSKeys(requests): ipAddress = requests.POST.get("IP_address") course_title = requests.POST.get('course_title') class_studentObj = getStudentClassObject(requests, course_title) awsC = class_studentObj.awscredential if awsC == None: raise Exception( 'Please upload your account number first before adding a new server.' ) try: url = 'http://' + ipAddress + ":8999/account/get/?secret_key=m0nKEY" response = req.get(url, timeout=5) jsonObj = json.loads(response.content.decode()) except req.exceptions.ConnectTimeout: raise Exception( 'Cannot reach server. Please start up server before proceeding') account_number = jsonObj['User']['Account'] access_key = encode(jsonObj['User']['Results']['aws_access_key_id ']) secret_access_key = encode( jsonObj['User']['Results']['aws_secret_access_key ']) if awsC.account_number == account_number: awsC.access_key = access_key awsC.secret_access_key = secret_access_key awsC.save() else: raise Exception( 'Server is not configured properly. Please make sure valid AWS Credentials were used.' )
def configureDB_telegram(requests): response = {"configure_telegram" : "active"} utilities.populateRelevantCourses(requests,instructorEmail=requests.user.email) response['courses'] = requests.session['courseList_updated'] if requests.method == "GET": return render(requests, "Module_TeamManagement/Instructor/instructorTools.html", response) try: username = requests.user.email.split('@')[0] phone_number = requests.POST.get('phone_number') login_code = requests.POST.get('login_code') toolType = 'Telegram' if requests.POST.get('type') == None else requests.POST.get('type') facultyObj = Faculty.objects.get(username=username) registered_course = facultyObj.course_section.all() if len(phone_number) == 8: phone_number = str('+65') + phone_number client = tele_util.getClient(username) if not client.is_user_authorized(): if phone_number != None and login_code == None: client.send_code_request(phone_number) encrypt_phone_number = utilities.encode(phone_number) facultyObj.phone_number = encrypt_phone_number facultyObj.save() return HttpResponse('') elif phone_number != None and login_code != None: try: client.sign_in(phone=phone_number, code=login_code) except PhoneNumberUnoccupiedError: client.sign_up(phone=phone_number, code=login_code) print(toolType) for course_section in registered_course: bootstrap.configureCourseToolsList(course_section.course_section_id,toolType) # Add faculty telegram username into DB # myself = client.get_me() # facultyObj.telegram_username = '******' + str(myself.username) # facultyObj.save() tele_util.disconnectClient(client) except Exception as e: traceback.print_exc() response['error_message'] = e.args[0] return render(requests, "Module_TeamManagement/Instructor/instructorTools.html", response) response['message'] = 'Telegram Account Configured' # return render(requests, "Module_TeamManagement/Instructor/instructorTools.html", response) return faculty_HomePage(requests)
def parse_File_Faculty(filePath,bootstrapInfo={}): # Create a workbook object from the filePath workbook = xlrd.open_workbook(filePath) # Get first worksheet sheet = workbook.sheet_by_index(0) # Get headers headers = sheet.row_values(0) # Get header indexes of each column index_username = headers.index('Username') index_lastname = headers.index('Last Name') index_firstname = headers.index('First Name') index_email = headers.index('Email') # Start with '1' instead of '0' to clear header buffer for row in range(1,sheet.nrows): faculty = [] rowData = sheet.row_values(row) # Declare variables username = rowData[index_username].strip() if '\\' in username: username = username.split("\\")[1] email = rowData[index_email].strip() firstname = rowData[index_firstname].strip() lastname = rowData[index_lastname].strip() if 'Phone Number' in headers: phoneNumber = str(int(rowData[headers.index('Phone Number')])).strip() if len(phoneNumber) == 8: phoneNumber = str('+65') + phoneNumber encrypt_phoneNumber = utilities.encode(phoneNumber) faculty.append(encrypt_phoneNumber) # Create faculty : list faculty = [email,username,firstname,lastname] + faculty # Store in dict with faculty as key and faculty : list as value try: bootstrapInfo['faculty'].append(faculty) except: bootstrapInfo['faculty'] = [faculty] return bootstrapInfo
def faculty_Setup_GetAWSKeys(requests): response = {"faculty_Setup_GetAWSKeys": "active"} # Redirect user to login page if not authorized and student try: processLogin.InstructorVerification(requests) except: logout(requests) return render(requests, 'Module_Account/login.html', response) account_number = requests.POST.get('account_number') access_key = requests.POST.get('access_key') secret_access_key = requests.POST.get('secret_access_key') try: if account_number == None or access_key == None or secret_access_key == None: raise Exception( 'Please input an account_number, access_key and secret_access_key' ) faculty_email = requests.user.email facultyObj = Faculty.objects.get(email=faculty_email) # Validate if account_number is a valid account_number valid = aws_util.validateAccountNumber(account_number, access_key, secret_access_key) if not valid: raise Exception( "Invalid parameters. Please specify a valid account number.") # try:UPDATE, except:SAVE Account_Number, Access_Key and Secret_Access_Key to AWS_Credentials try: credentialsObj = facultyObj.awscredential old_account_number = credentialsObj.account_number # Create NEW AWS_Credentials credentialsObj.account_number = account_number credentialsObj.access_key = encode(access_key) credentialsObj.secret_access_key = encode(secret_access_key) credentialsObj.save() facultyObj.awscredential = credentialsObj facultyObj.save() # Delete OLD AWS_Credentials and Images tied to it old_credentialsObj = AWS_Credentials.objects.get( account_number=old_account_number) imageObjs = old_credentialsObj.imageDetails.all() for imageObj in imageObjs: imageObj.delete() old_credentialsObj.delete() except: access_key = encode(access_key) secret_access_key = encode(secret_access_key) credentialsObj = AWS_Credentials.objects.create( account_number=account_number, access_key=access_key, secret_access_key=secret_access_key, ) credentialsObj.save() facultyObj.awscredential = credentialsObj facultyObj.save() response['message'] = 'Successfully updated AWS Credentials' except Exception as e: traceback.print_exc() response['error_message'] = 'Error in AWS Information form: ' + str( e.args[0]) return faculty_Setup_Base(requests, response) return faculty_Setup_Base(requests, response)