def build(self): """ Returns a complete tree of sidebar items. :returns: dict """ sidebar = { 'id': None, 'children': [], } def find_id(_id, e=sidebar): if 'id' in e and e['id'] == _id: return e for c in e['children']: f = find_id(_id, e=c) if f: return f for provider in SidebarItemProvider.all(self.context): for item in provider.provide(): if 'url' in item: try: authorize('sidebar:view:%s' % item['url']).check() except SecurityError: continue attach_to = find_id(item['attach']) if not attach_to: raise Exception('Attachment point not found: %s' % item['attach']) attach_to['children'].append(item) return sidebar
def handle_api_extra_students(self, http_context): path = '/etc/sophomorix/user/extraschueler.txt' fieldnames = [ 'class', 'last_name', 'first_name', 'birthday', 'login', 'reserved', ] if http_context.method == 'GET': with authorize('lm:users:extra-students:read'): return list( csv.DictReader( CSVSpaceStripper( open(path), encoding=http_context.query.get('encoding', 'utf-8') ), delimiter=';', fieldnames=fieldnames ) ) if http_context.method == 'POST': with authorize('lm:users:extra-students:write'): data = http_context.json_body() for item in data: item.pop('_isNew', None) lm_backup_file(path) with open(path, 'w') as f: csv.DictWriter( f, delimiter=';', fieldnames=fieldnames, encoding=http_context.query.get('encoding', 'utf-8') ).writerows(data)
def handle_api_users_schooladmins_create(self, http_context): school = 'default-school' action = http_context.json_body()['action'] users = http_context.json_body()['users'] user = '******'.join([x.strip() for x in users]) if action == 'create': with authorize('lm:users:schooladmins:create'): sophomorixCommand = [ 'sophomorix-admin', '--create-school-admin', user, '--school', school, '--random-passwd-save', '-jj' ] result = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0') if result['TYPE'] == "ERROR": return ["ERROR", result['MESSAGE_EN']] if result['TYPE'] == "LOG": return ["LOG", result['LOG']] # return lmn_getSophomorixValue(sophomorixCommand, 'COMMENT_EN') if action == 'delete': with authorize('lm:users:schooladmins:delete'): sophomorixCommand = ['sophomorix-admin', '--kill', user, '-jj'] result = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0') if result['TYPE'] == "ERROR": return ["ERROR", result['MESSAGE_EN']] if result['TYPE'] == "LOG": return ["LOG", result['LOG']]
def handle_api_sophomorix_newfile(self, http_context): # TODO needs update for multischool path = http_context.json_body()['path'] userlist = http_context.json_body()['userlist'] if http_context.method == 'POST': if userlist == 'teachers.csv': with authorize('lm:users:teachers:write'): sophomorixCommand = [ 'sophomorix-newfile', path, '--name', userlist, '-jj' ] result = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0') if result['TYPE'] == "ERROR": return ["ERROR", result['MESSAGE_EN']] if result['TYPE'] == "LOG": return ["LOG", result['LOG']] if userlist == 'students.csv': with authorize('lm:users:students:write'): sophomorixCommand = [ 'sophomorix-newfile', path, '--name', userlist, '-jj' ] result = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0') if result['TYPE'] == "ERROR": return ["ERROR", result['MESSAGE_EN']] if result['TYPE'] == "LOG": return ["LOG", result['LOG']]
def handle_api_extra_courses(self, http_context): school = 'default-school' path = '/etc/linuxmuster/sophomorix/' + school + '/extraclasses.csv' if os.path.isfile(path) is False: os.mknod(path) fieldnames = [ 'course', 'base_name', 'count', 'birthday', 'gecos', 'password', 'removal_date', ] if http_context.method == 'GET': with authorize('lm:users:extra-courses:read'): return list( csv.DictReader(CSVSpaceStripper( open(path), encoding=http_context.query.get('encoding', 'utf-8')), delimiter=';', fieldnames=fieldnames)) if http_context.method == 'POST': with authorize('lm:users:extra-courses:write'): data = http_context.json_body() for item in data: item.pop('_isNew', None) lmn_backup_file(path) with open(path, 'w') as f: csv.DictWriter(f, delimiter=';', fieldnames=fieldnames, encoding=http_context.query.get( 'encoding', 'utf-8')).writerows(data)
def handle_api_sophomorix_globaladmins(self, http_context): action = http_context.json_body()['action'] if http_context.method == 'POST': globaladminsList = [] with authorize('lm:users:globaladmins:read'): if action == 'get-all': sophomorixCommand = [ 'sophomorix-query', '--globaladministrator', '--user-full', '-jj' ] else: user = http_context.json_body()['user'] sophomorixCommand = [ 'sophomorix-query', '--globaladministrator', '--user-full', '-jj', '--sam', user ] globaladminsCheck = lmn_getSophomorixValue( sophomorixCommand, 'LISTS/USER') if len(globaladminsCheck) != 0: globaladmins = lmn_getSophomorixValue( sophomorixCommand, 'USER') for globaladmin in globaladmins: globaladminsList.append(globaladmins[globaladmin]) return globaladminsList else: return ["none"] if http_context.method == 'POST': with authorize('lm:users:globaladmins:write'): return 0
def handle_api_users(self, http_context): """ Load (method get) and save (method post) the ajenti users config file. Method GET. Method POST. :param http_context: HttpContext :type http_context: HttpContext :return: Content of the ajenti users config file :rtype: dict """ if os.getuid() != 0: raise EndpointReturn(403) if http_context.method == 'GET': with authorize('core:config:read'): self.context.worker.reload_master_config() return aj.users.data if http_context.method == 'POST': with authorize('core:config:write'): data = json.loads(http_context.body.decode()) aj.users.data.update(data) aj.users.save() self.context.worker.reload_master_config() return aj.users.data
def handle_api_sophomorix_teachers(self, http_context): action = http_context.json_body()['action'] if http_context.method == 'POST': schoolname = 'default-school' teachersList = [] with authorize('lm:users:teachers:read'): if action == 'get-all': # TODO: This could run with --user-basic but not all memberOf are filled. Needs verification sophomorixCommand = [ 'sophomorix-query', '--teacher', '--schoolbase', schoolname, '--user-basic', '-jj' ] else: user = http_context.json_body()['user'] sophomorixCommand = [ 'sophomorix-query', '--teacher', '--schoolbase', schoolname, '--user-basic', '-jj', '--sam', user ] teachersCheck = lmn_getSophomorixValue(sophomorixCommand, 'LISTS/USER') if len(teachersCheck) != 0: teachers = lmn_getSophomorixValue(sophomorixCommand, 'USER') for teacher in teachers: teachersList.append(teachers[teacher]) return teachersList else: return ["none"] if http_context.method == 'POST': with authorize('lm:users:teachers:write'): return 0
def handle_api_config(self, http_context): if os.getuid() != 0: raise EndpointReturn(403) if http_context.method == "GET": with authorize("core:config:read"): self.context.worker.reload_master_config() return aj.config.data if http_context.method == "POST": with authorize("core:config:write"): data = json.loads(http_context.body) aj.config.data.update(data) aj.config.save() self.context.worker.reload_master_config() return aj.config.data
def handle_api_config(self, http_context): if os.getuid() != 0: raise EndpointReturn(403) if http_context.method == 'GET': with authorize('core:config:read'): self.context.worker.reload_master_config() return aj.config.data if http_context.method == 'POST': with authorize('core:config:write'): data = json.loads(http_context.body.decode()) aj.config.data.update(data) aj.config.save() self.context.worker.reload_master_config() return aj.config.data
def handle_api_sophomorix_students(self, http_context): action = http_context.json_body()['action'] if http_context.method == 'POST': schoolname = 'default-school' studentsList = [] with authorize('lm:users:students:read'): if action == 'get-all': sophomorixCommand = [ 'sophomorix-query', '--student', '--schoolbase', schoolname, '--user-basic', '-jj' ] else: user = http_context.json_body()['user'] # sophomorixCommand = ['sophomorix-query', '--student', '--schoolbase', schoolname, '--user-full', '-jj', '--sam', user] sophomorixCommand = [ 'sophomorix-query', '--user-full', '-jj', '--sam', user ] studentsCheck = lmn_getSophomorixValue(sophomorixCommand, 'LISTS/USER') if len(studentsCheck) != 0: students = lmn_getSophomorixValue(sophomorixCommand, 'USER') for student in students: # TODO: get a better way to remove Birthay from user detail page students[student]['sophomorixBirthdate'] = 'hidden' studentsList.append(students[student]) return studentsList else: return ["none"]
def handle_api_get_user_in_room(self, http_context): if http_context.method == 'POST': school = 'default-school' action = http_context.json_body()['action'] username = http_context.json_body()['username'] with authorize('lm:users:students:read'): if action == 'get-my-room': try: sophomorixCommand = [ 'sophomorix-query', '-jj', '--smbstatus', '--schoolbase', school, '--query-user', username ] response = lmn_getSophomorixValue( sophomorixCommand, '') # remove our own room = response[username]['ROOM'] response.pop(username, None) usersList = [] usersInRoom = {} for user in response: usersList.append(user) usersInRoom = { "usersList": usersList, "room": room, "objects": response } return usersInRoom except Exception: return 0
def handle_api_session_file_trans(self, http_context): senders = http_context.json_body()['senders'] command = http_context.json_body()['command'] receivers = http_context.json_body()['receivers'] files = http_context.json_body()['files'] session = http_context.json_body()['session'] now = strftime("%Y%m%d_%H-%M-%S", gmtime()) with authorize('lmn:session:trans'): if command == 'share': try: for sender in senders: # check if bulkmode (array of usernames) or single user (object containing username) # if first element is not a string if not isinstance(receivers[0], six.string_types): receivers[0]= receivers[0]['sAMAccountName'] receiversCSV = ",".join(receivers) for File in files: sophomorixCommand = ['sophomorix-transfer', '-jj', '--scopy', '--from-user', sender, '--to-user', receiversCSV, '--from-path', 'transfer/'+File, '--to-path', 'transfer/'] returnMessage = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0') except Exception as e: raise Exception('Something went wrong. Error:\n' + str(e)) if command == 'copy': try: for receiver in receivers: #raise Exception('Bad value in LDAP field SophomorixUserPermissions! Python error:\n' + str(senders)) sendersCSV = '' for sender in senders: sendersCSV += sender['sAMAccountName']+',' # if files is All we're automatically in bulk mode if files == "All": sophomorixCommand = ['sophomorix-transfer', '-jj', '--scopy', '--from-user', sendersCSV, '--to-user', receiver, '--from-path', 'transfer', '--to-path', 'transfer/collected/'+now+'-'+session+'/', '--to-path-addon', 'fullinfo', '--no-target-directory'] returnMessage = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0') else: for File in files: sophomorixCommand = ['sophomorix-transfer', '-jj', '--scopy', '--from-user', sendersCSV, '--to-user', receiver, '--from-path', 'transfer/'+File, '--to-path', 'transfer/collected/'+now+'-'+session+'/', '--to-path-addon', 'fullinfo' ] returnMessage = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0') except Exception as e: raise Exception('Something went wrong. Error:\n' + str(e)) if command == 'move': try: for receiver in receivers: sendersCSV = '' for sender in senders: sendersCSV += sender['sAMAccountName']+',' # if files is All we're automatically in bulk mode if files == "All": sophomorixCommand = ['sophomorix-transfer', '-jj', '--move', '--keep-source-directory', '--from-user', sendersCSV, '--to-user', receiver, '--from-path', 'transfer', '--to-path', 'transfer/collected/'+now+'-'+session+'/', '--to-path-addon', 'fullinfo', '--no-target-directory'] returnMessage = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0') else: for File in files: sophomorixCommand = ['sophomorix-transfer', '-jj', '--move', '--from-user', sendersCSV, '--to-user', receiver, '--from-path', 'transfer/'+File, '--to-path', 'transfer/collected/'+now+'-'+session+'/', '--to-path-addon', 'fullinfo' ] returnMessage = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0') except Exception as e: raise Exception('Something went wrong. Error:\n' + str(e)) if returnMessage['TYPE'] == "ERROR": return returnMessage['TYPE']['LOG'] return returnMessage['TYPE'], returnMessage['LOG'] return returnMessage['TYPE']['LOG']
def handle_api_ldap_user_search(self, http_context): school = 'default-school' with authorize('lm:users:students:read'): try: sophomorixCommand = ['sophomorix-query', '-jj', '--schoolbase', school, '--student', '--user-basic', '--anyname', '*'+http_context.query['q']+'*'] users = lmn_getSophomorixValue(sophomorixCommand, 'USER', True) except Exception: return 0 userList = [] for user in users: userList.append(users[user]) return userList
def handle_api_teachers(self, http_context): school = 'default-school' path = '/etc/linuxmuster/sophomorix/' + school + '/teachers.csv' if os.path.isfile(path) is False: os.mknod(path) fieldnames = [ 'class', 'last_name', 'first_name', 'birthday', 'login', 'password', 'usertoken', 'quota', 'mailquota', 'reserved', ] if http_context.method == 'GET': with authorize('lm:users:teachers:read'): return list( csv.DictReader(CSVSpaceStripper( open(path), encoding=http_context.query.get('encoding', 'utf-8')), delimiter=';', fieldnames=fieldnames)) if http_context.method == 'POST': with authorize('lm:users:teachers:write'): data = http_context.json_body() for item in data: item.pop('_isNew', None) lmn_backup_file(path) with open(path, 'w') as f: csv.DictWriter(f, delimiter=';', fieldnames=fieldnames, encoding=http_context.query.get( 'encoding', 'utf-8')).writerows(data)
def handle_api_ldap_group_search(self, http_context): school = 'default-school' with authorize('lm:users:students:read'): try: sophomorixCommand = ['sophomorix-query', '-jj', '--schoolbase', school, '--class', '--group-members', '--user-full', '--sam', '*'+http_context.query['q']+'*'] schoolClasses = lmn_getSophomorixValue(sophomorixCommand, 'MEMBERS', True) except Exception: return 0 schoolClassList = [] for schoolClass in schoolClasses: schoolClassJson = {} schoolClassJson['sophomorixAdminClass'] = schoolClass schoolClassJson['members'] = schoolClasses[schoolClass] schoolClassList.append(schoolClassJson) return schoolClassList
def handle_api_get_smtp_config(self, http_context): """ Load the smtp config file without password. :param http_context: HttpContext :type http_context: HttpContext :return: Content of the ajenti config file without password :rtype: dict """ if os.getuid() != 0: raise EndpointReturn(403) with authorize('core:config:read'): return aj.smtp_config.data
def handle_api_post_smtp_config(self, http_context): """ Save the smtp config file without password. :param http_context: HttpContext :type http_context: HttpContext :return: Content of the ajenti config file without password :rtype: dict """ if os.getuid() != 0: raise EndpointReturn(403) with authorize('core:config:write'): data = json.loads(http_context.body.decode()) aj.smtp_config.save(data)
def handle_api_get_config(self, http_context): """ Load the ajenti config file. :param http_context: HttpContext :type http_context: HttpContext :return: Content of the ajenti config file :rtype: dict """ if os.getuid() != 0: raise EndpointReturn(403) with authorize('core:config:read'): self.context.worker.reload_master_config() return aj.config.data
def handle_api_groupmembership_details(self, http_context): action = http_context.json_body()['action'] if http_context.method == 'POST': # schoolname = 'default-school' with authorize('lmn:groupmemberships:write'): if action == 'get-specified': groupName = http_context.json_body()['groupName'] sophomorixCommand = [ 'sophomorix-query', '--group-members', '--group-full', '--sam', groupName, '-jj' ] groupDetails = lmn_getSophomorixValue( sophomorixCommand, '') if not 'MEMBERS' in groupDetails.keys(): groupDetails['MEMBERS'] = {} return groupDetails
def handle_api_post_config(self, http_context): """ Save the ajenti config file. :param http_context: HttpContext :type http_context: HttpContext :return: Content of the ajenti config file :rtype: dict """ if os.getuid() != 0: raise EndpointReturn(403) with authorize('core:config:write'): data = json.loads(http_context.body.decode()) aj.config.data.update(data) aj.config.save() self.context.worker.reload_master_config() return aj.config.data
def handle_api_users_print(self, http_context): school = 'default-school' if http_context.method == 'GET': sophomorixCommand = [ 'sophomorix-print', '--school', school, '--info', '-jj' ] with authorize('lm:users:students:read'): # classes = lmn_getSophomorixValue(sophomorixCommand, 'LIST_BY_sophomorixSchoolname_sophomorixAdminClass/'+school) # Check if there are any classes if not return empty list classes_raw = lmn_getSophomorixValue(sophomorixCommand, '') if 'LIST_BY_sophomorixSchoolname_sophomorixAdminClass' not in classes_raw: classes = [] else: classes = classes_raw[ 'LIST_BY_sophomorixSchoolname_sophomorixAdminClass'][ school] if lmn_checkPermission('lm:users:teachers:read'): # append empty element. This references to all users classes.append('') else: classes.remove('teachers') return classes if http_context.method == 'POST': user = http_context.json_body()['user'] one_per_page = http_context.json_body()['one_per_page'] pdflatex = http_context.json_body()['pdflatex'] schoolclass = http_context.json_body()['schoolclass'] sophomorixCommand = [ 'sophomorix-print', '--school', school, '--caller', str(user) ] if one_per_page: sophomorixCommand.extend(['--one-per-page']) if pdflatex: sophomorixCommand.extend(['--command']) sophomorixCommand.extend(['pdflatex']) if schoolclass: sophomorixCommand.extend(['--class', schoolclass]) # sophomorix-print needs the json parameter at the very end sophomorixCommand.extend(['-jj']) # check permissions if not schoolclass: # double check if user is allowed to print all passwords with authorize('lm:users:teachers:read'): pass # double check if user is allowed to print teacher passwords if schoolclass == 'teachers': with authorize('lm:users:teachers:read'): pass # generate real shell environment for sophomorix print shell_env = { 'TERM': 'xterm', 'SHELL': '/bin/bash', 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOME': '/root', '_': '/usr/bin/python2' } subprocess.check_call(sophomorixCommand, shell=False, env=shell_env) return
def handle_api_session_sessions(self, http_context): action = http_context.json_body()['action'] if action == 'get-sessions': supervisor = http_context.json_body()['username'] with authorize('lm:users:students:read'): try: sophomorixCommand = ['sophomorix-session', '-i', '-jj', '--supervisor', supervisor] sessions = lmn_getSophomorixValue(sophomorixCommand, '') # Most likeley key error 'cause no sessions for this user exist except Exception as e: raise Exception('Bad value in LDAP field SophomorixUserPermissions! Python error:\n' + str(e)) return 0 sessionsList = [] if supervisor not in sessions['SUPERVISOR_LIST']: sessionJson = {} sessionJson['SESSIONCOUNT'] = 0 sessionsList.append(sessionJson) return sessionsList for session in sessions['SUPERVISOR'][supervisor]['sophomorixSessions']: sessionJson = {} sessionJson['ID'] = session sessionJson['COMMENT'] = sessions['SUPERVISOR'][supervisor]['sophomorixSessions'][session]['COMMENT'] if 'PARTICIPANT_COUNT' not in sessions['SUPERVISOR'][supervisor]['sophomorixSessions'][session]: sessionJson['PARTICIPANT_COUNT'] = 0 else: sessionJson['PARTICIPANT_COUNT'] = sessions['SUPERVISOR'][supervisor]['sophomorixSessions'][session]['PARTICIPANT_COUNT'] sessionsList.append(sessionJson) return sessionsList if action == 'get-participants': participantList = [] supervisor = http_context.json_body()['username'] session = http_context.json_body()['session'] with authorize('lm:users:students:read'): try: sophomorixCommand = ['sophomorix-session', '-i', '-jj'] participants = lmn_getSophomorixValue(sophomorixCommand, 'ID/'+session+'/PARTICIPANTS', True) i = 0 for participant in participants: participantList.append(participants[participant]) participantList[i]['sAMAccountName'] = participant #if participant.endswith('-exam'): # participantList[i]['sAMAccountname-basename'] = participant.replace('-exam', '') #else: # participantList[i]['sAMAccountname-basename'] = participant participantList[i]['changed'] = 'FALSE' participantList[i]['exammode-changed'] = 'FALSE' for key in participantList[i]: if participantList[i][key] == 'TRUE': participantList[i][key] = True if participantList[i][key] == 'FALSE': participantList[i][key] = False i = i + 1 except Exception: participantList = 'empty' return participantList if action == 'kill-sessions': session = http_context.json_body()['session'] with authorize('lm:users:students:read'): sophomorixCommand = ['sophomorix-session', '-j', '--session', session, '--kill'] result = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0/LOG') return result if action == 'rename-session': session = http_context.json_body()['session'] comment = http_context.json_body()['comment'] with authorize('lm:users:students:read'): sophomorixCommand = ['sophomorix-session', '-j', '--session', session, '--comment', comment] result = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0/LOG') return result if action == 'new-session': supervisor = http_context.json_body()['username'] comment = http_context.json_body()['comment'] with authorize('lm:users:students:read'): sophomorixCommand = ['sophomorix-session', '--create', '--supervisor', supervisor, '-j', '--comment', comment] result = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0/LOG') return result # TODO: Removed remove block in future release #if action == 'change-exam-supervisor': # supervisor = http_context.json_body()['supervisor'] # participant = http_context.json_body()['participant'] # comment = http_context.json_body()['comment'] # with authorize('lm:users:students:read'): # try: # sophomorixCommand = ['sophomorix-exam-mode', '--unset', '--subdir', session, '-j', '--participants', participant] # result = lmn_getSophomorixValue(sophomorixCommand, 'COMMENT_EN') # except Exception as e: # raise Exception('Error:\n' + str(e)) # try: # sophomorixCommand = ['sophomorix-exam-mode', '--set', '--supervisor', supervisor, '-j', '--participants', participant] # result = lmn_getSophomorixValue(sophomorixCommand, 'COMMENT_EN') # except Exception as e: # raise Exception('Error:\n' + str(e)) if action == 'end-exam': supervisor = http_context.json_body()['supervisor'] participant = http_context.json_body()['participant'] sessionName = http_context.json_body()['sessionName'] now = strftime("%Y%m%d_%H-%M-%S", gmtime()) #raise Exception('Bad value in LDAP field SophomorixUserPermissions! Python error:\n' + str(http_context.json_body())) with authorize('lm:users:students:read'): try: sophomorixCommand = ['sophomorix-exam-mode', '--unset', '--subdir', 'transfer/collected/'+now+'-'+sessionName+'-ended-by-'+supervisor+'/exam', '-j', '--participants', participant] result = lmn_getSophomorixValue(sophomorixCommand, 'COMMENT_EN') except Exception as e: raise Exception('Error:\n' + str(e)) if action == 'save-session': def checkIfUserInManagementGroup(participant, participantBasename, managementgroup, managementList, noManagementList): try: boolean = participant[managementgroup] if (boolean is True) or (boolean == 'TRUE'): managementList.append(participantBasename) else: noManagementList.append(participantBasename) except KeyError: noManagementList.append(participantBasename) pass return 0 session = http_context.json_body()['session'] sessionName = http_context.json_body()['sessionName'] supervisor = http_context.json_body()['username'] participants = http_context.json_body()['participants'] participantsList = [] now = strftime("%Y%m%d_%H-%M-%S", gmtime()) examModeList, noExamModeList, wifiList, noWifiList, internetList, noInternetList, intranetList, noIntranetList, webfilterList, noWebfilterList, printingList, noPrintingList = [], [], [], [], [], [], [], [], [], [], [], [] # Remove -exam in username to keep username as it is insead of saving -exam usernames in session for participant in participants: if participant['sAMAccountName'].endswith('-exam'): participantBasename = participant['sAMAccountName'].replace('-exam', '') else: participantBasename = str(participant['sAMAccountName']) #participant['sAMAccountName'] # Fill lists from WebUI Output -> Create csv of session members # This will executed on every save participantsList.append(participantBasename) # Only check for exammode if this value was changed in WEBUI if participant['exammode-changed'] is True: checkIfUserInManagementGroup(participant, participantBasename, 'exammode_boolean', examModeList, noExamModeList) # Only check for managementgroups if this value was changed in WEBUI if participant['changed'] is True: checkIfUserInManagementGroup(participant, participant['sAMAccountName'], 'group_wifiaccess', wifiList, noWifiList) checkIfUserInManagementGroup(participant, participant['sAMAccountName'], 'group_internetaccess', internetList, noInternetList) checkIfUserInManagementGroup(participant, participant['sAMAccountName'], 'group_intranetaccess', intranetList, noIntranetList) checkIfUserInManagementGroup(participant, participant['sAMAccountName'], 'group_webfilter', webfilterList, noWebfilterList) checkIfUserInManagementGroup(participant, participant['sAMAccountName'], 'group_printing', printingList, noPrintingList) #i = i + 1 # Create CSV lists we need for sophomorix participantsCSV = ",".join(participantsList) examModeListCSV = ",".join(examModeList) noExamModeListCSV = ",".join(noExamModeList) wifiListCSV = ",".join(wifiList) noWifiListCSV = ",".join(noWifiList) internetListCSV = ",".join(internetList) noInternetListCSV = ",".join(noInternetList) intranetListCSV = ",".join(intranetList) noIntranetListCSV = ",".join(noIntranetList) webfilterListCSV = ",".join(webfilterList) noWebfilterListCSV = ",".join(noWebfilterList) printingListCSV = ",".join(printingList) noPrintingListCSV = ",".join(noPrintingList) # Set managementgroups try: sophomorixCommand = ['sophomorix-managementgroup', '--wifi', wifiListCSV, '--nowifi', noWifiListCSV, '--internet', internetListCSV, '--nointernet', noInternetListCSV, '--intranet', intranetListCSV, '--nointranet', noIntranetListCSV, '--webfilter', webfilterListCSV, '--nowebfilter', noWebfilterListCSV, '--printing', printingListCSV, '--noprinting', noPrintingListCSV, '-jj'] result = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0/LOG') except Exception as e: raise Exception('Error:\n' + str('sophomorix-managementgroup \ --wifi "' + wifiListCSV + '" --nowifi "' + noWifiListCSV + '" --internet "' + internetListCSV + '" --nointernet "' + noInternetListCSV + '" --intranet "' + intranetListCSV + '" --nointranet "' + noIntranetListCSV + '" --webfilter "' + webfilterListCSV + '" --nowebfilter "' + noWebfilterListCSV + '" --printing "' + printingListCSV + '" --noprinting "' + noPrintingListCSV + '" -jj ') + "\n Error was: " + str(e)) # Save session members try: sophomorixCommand = ['sophomorix-session', '--session', session, '-j', '--participants', participantsCSV] result = lmn_getSophomorixValue(sophomorixCommand, 'OUTPUT/0/LOG') except Exception: raise Exception('Error:\n' + str('sophomorix-session --session ' + session + ' -j --participants ' + participantsCSV)) # Put chosen members in exam mode try: if examModeListCSV != "": sophomorixCommand = ['sophomorix-exam-mode', '--set', '--supervisor', supervisor, '-j', '--participants', examModeListCSV] result = lmn_getSophomorixValue(sophomorixCommand, 'COMMENT_EN') except Exception: raise Exception('Error:\n' + str('sophomorix-exam-mode --set --supervisor ' + supervisor + ' -j --participants ' + examModeListCSV)) # Remove chosen members from exam mode try: if noExamModeListCSV != "": sophomorixCommand = ['sophomorix-exam-mode', '--unset', '--subdir', 'transfer/collected/'+now+'-'+sessionName+'/exam', '-j', '--participants', noExamModeListCSV] result = lmn_getSophomorixValue(sophomorixCommand, 'COMMENT_EN') except Exception: raise Exception('Error:\n' + str('sophomorix-exam-mode --unset --subdir ' + session + ' -j --participants ' + noExamModeListCSV)) return result if http_context.method == 'POST': with authorize('lm:users:students:write'): return 0