def create(request, format=None): print(request.data) ou = OrgUnit() if request.data != {}: if request.data['name'] != '': if request.data['domain_name'] != '': ou.name = request.data['name'] + ',' + request.data[ 'domain_name'] else: return Response( "domain_name filed should not be empty {0}".format( request.data), status=status.HTTP_400_BAD_REQUEST) else: return Response("name field should not be empty {0}".format( request.data), status=status.HTTP_400_BAD_REQUEST) else: return Response("Invalid ou {0}".format(request.data), status=status.HTTP_400_BAD_REQUEST) ou.description = request.data['description'] response = OUService(ConnectionService('exza')).create( ou=ou, request=request.data) return Response(response.description, response.status)
def create(request, format=None): print(request.data) cm = ComputerMgmt() if request.data != {}: cm.computer_name = request.data['computer_name'] cm.domain_container = request.data['domain_container'] cm.description = request.data['description'] response = CMServices(ConnectionService('exza')).create( cm=cm, request=request.data) return Response(response.status) return Response("Invalid Computer data")
def remove_members(request, format=None): if request.data != {}: if request.data['groupname'] != '': if request.data['listofnames'] != '': response = GrpService(ConnectionService('exza')).remove_members(request=request.data) else: return Response(response.description, response.status) else: return Response(response.description, response.status) else: return Response(response.description, response.status) return Response(response.description, response.status)
def move(request, format=None): if request.data != {}: if request.data['username'] != '': if request.data['new_container'] != '': response = UserServices( ConnectionService('exza')).move(request=request.data) else: return Response(response.description, response.status) else: return Response(response.description, response.status) else: return Response(response.description, response.status) return Response(response.description, response.status)
def edit(request, name, format=None): response = OUService(ConnectionService('exza')).edit(name=name) if response.data is None: return Response(response.description, response.status) ous = [] for msg in response.data: ou = OrgUnit() ou.name = msg.get('name') ou.description = msg.get('description') ous.append(ou) serializer = OrgUnitSerializer(ous, many=True) return Response(serializer.data)
def create(request, format=None): if request.data != {}: print(str(request.data)) if ((request.data['password'] != '' and request.data['random_password'] == True) or (request.data['password'] == '' and request.data['random_password'] == False)): return Response("Invalid password options") else: response = UserServices( ConnectionService('exza')).create(request=request.data) return Response(response.status) return Response("Bad request")
def list_members(request, name, format=None): response = GrpService(ConnectionService('exza')).list_members(name=name) if response.data is None: print(response.description) return Response(response.description, status=response.status) mems = [] for msg in response.data: gm = grpmembers() gm.name = msg.get('name') mems.append(gm) print(response.description, response.status) serializer = grpmembersserializer(mems, many=True) return Response(serializer.data, status=status.HTTP_200_OK)
def list(request, format=None): response = UserServices(ConnectionService('exza')).list() user_services = [] if response.data is None: print(response.description) return Response(response.description, status=response.status) for msg in response.data: user_report = UserReport() user_report.name = msg.get('name') # user_report.objectClass = msg.get('objectClass') user_report.givenName = msg.get('givenName') user_report.instanceType = msg.get('instanceType') user_report.whenCreated = str(msg.get('whenCreated')) user_report.whenChanged = str(msg.get('whenChanged')) user_report.displayName = msg.get('displayName') user_report.uSNCreated = msg.get('uSNCreated') user_report.company = msg.get('company') user_report.badPwdCount = msg.get('badPwdCount') user_report.dn = msg.get('dn') user_report.description = msg.get('description') user_report.cn = msg.get('cn') user_report.sn = msg.get('sn') user_report.codePage = msg.get('codePage') user_report.countryCode = msg.get('countryCode') user_report.badPasswordTime = msg.get('badPasswordTime') user_report.lastLogoff = msg.get('lastLogoff') user_report.lastLogon = msg.get('lastLogon') user_report.primaryGroupID = msg.get('primaryGroupID') user_report.accountExpires = msg.get('accountExpires') user_report.logonCount = msg.get('logonCount') user_report.sAMAccountName = msg.get('sAMAccountName') user_report.sAMAccountType = msg.get('sAMAccountType') user_report.userPrincipalName = msg.get('userPrincipalName') user_report.objectCategory = msg.get('objectCategory') user_report.pwdLastSet = msg.get('pwdLastSet') user_report.userAccountControl = msg.get('userAccountControl') user_report.uSNChanged = msg.get('uSNChanged') user_report.mail = msg.get('mail') user_report.telephoneNumber = msg.get('telephoneNumber') # user_report.memberOf = str(msg.get('memberOf')) # memberOf = msg.get('memberOf') # print(type(memberOf)) user_report.distinguishedName = msg.get('distinguishedName') user_services.append(user_report) serializer = UserReportSerializer(user_services, many=True) return Response(serializer.data, status=status.HTTP_200_OK)
def show(request, name, format=None): response = GrpService(ConnectionService('exza')).show(name=name) grps = [] for msg in response.data: print(msg) grp = grpmgmt() grp.name = msg.get('name') grp.description = msg.get('description') grp.container = msg.get('dn') grp.group_type = msg.get('group_type') grp.group_scope = msg.get('group_scope') grp.mail_id = msg.get('mail') grp.notes = msg.get('info') grps.append(grp) serializer = grpmgmtserializer(grps, many=True) return Response(serializer.data, response.status)
def set_expiry(request, format=None): if request.data != {}: if (request.data['username'] != ''): if ((request.data['expiry_days'] > 0 and request.data['no_expiry'] == True) or (request.data['expiry_days'] == 0 and request.data['no_expiry'] == False)): return Response("Invalid password options") else: response = UserServices( ConnectionService('exza')).set_expiry(request=request.data) else: return Response("Invalid username") else: return Response("Invalid data") return Response(response.status)
def list(request, format=None): response = GrpService(ConnectionService('exza')).list() grps = [] if response.data is None: print(response.description) return Response(response.description, status=response.status) for msg in response.data: print(msg) grp = grpmgmt() grp.name = msg.get('name') grp.description = msg.get('description') grp.container = msg.get('dn') grp.group_type = msg.get('group_type') grp.group_scope = msg.get('group_scope') grp.mail_id = msg.get('mail') grp.notes = msg.get('info') grps.append(grp) serializer = grpmgmtserializer(grps, many=True) return Response(serializer.data,status=status.HTTP_200_OK)
def show(request, computer_name, format=None): print(computer_name) response = CMServices( ConnectionService('exza')).show(computer_name=computer_name) if response.data is None: return Response("No records") comp_list = [] for msg in response.data: print(msg) comp_report = ComputerReport() comp_report.name = msg.get('name') comp_report.dn = msg.get('dn') # compreport.objectClass = msg.get('objectClass') comp_report.cn = msg.get('cn') comp_report.sn = msg.get('sn') comp_report.description = msg.get('description') comp_report.instanceType = msg.get('instanceType') comp_report.whenCreated = msg.get('whenCreated') comp_report.whenChanged = msg.get('whenChanged') comp_report.uSNCreated = msg.get('uSNCreated') comp_report.badPwdCount = msg.get('badPwdCount') comp_report.codePage = msg.get('codePage') comp_report.countryCode = msg.get('countryCode') comp_report.badPasswordTime = msg.get('badPasswordTime') comp_report.lastLogoff = msg.get('lastLogoff') comp_report.lastLogon = msg.get('lastLogon') comp_report.primaryGroupID = msg.get('primaryGroupID') comp_report.accountExpires = msg.get('accountExpires') comp_report.logonCount = msg.get('logonCount') comp_report.sAMAccountName = msg.get('sAMAccountName') comp_report.sAMAccountType = msg.get('sAMAccountType') comp_report.objectCategory = msg.get('objectCategory') comp_report.pwdLastSet = msg.get('pwdLastSet') comp_report.userAccountControl = msg.get('userAccountControl') comp_report.isCriticalSystemObject = msg.get('isCriticalSystemObject') comp_report.uSNChanged = msg.get('uSNChanged') comp_report.distinguishedName = msg.get('distinguishedName') comp_list.append(comp_report) print(response.data) serializer = ComputerReportSerializer(comp_list, many=True) return Response(serializer.data, response.status)
def move(request, format=None): computer_name = request.data['computer_name'] domain_container = request.data['domain_container'] if request.data != {}: if (computer_name == '' or domain_container == ''): return Response("Fields cannot be empty!!") else: computer_list = computer_name.split(',') print(len(computer_list)) count = 0 for i in range(0, len(computer_list)): print(computer_list[i]) response = CMServices(ConnectionService('exza')).rename( computer_name=computer_list[i], domain_container=domain_container) if (response.status == 200): count = count + 1 return Response("In testing") else: return Response("Invalid data")
def list(request, format=None): response = OUService(ConnectionService('exza')).list() ous = [] if response.data is None: print(response.description) return Response(response.description, status=response.status) for msg in response.data: print(msg) ou = OrgUnitReport() ou.ou_name = msg.get('name') ou.description = msg.get('description') ou.domain_name = msg.get('dn') ou.distinguished_name = msg.get('distinguishedName') ou.when_changed = msg.get('whenChanged') ou.when_Created = msg.get('whenCreated') # ou.object_guid = msg.get('objectGUID') ou.managed_by = msg.get('managedBy') ous.append(ou) serializer = OrgUnitReportSerializer(ous, many=True) return Response(serializer.data, status=status.HTTP_200_OK)
def set_password(request, format=None): print(str(request.data)) if request.data != {}: if request.data['username'] != '': if (request.data['password'] != '' and request.data['random_password'] == True) or (request.data['password'] == '' and request.data['random_password'] == False): return Response("Invalid password options!!") else: if (request.data['random_password'] == False): if (request.data['password'] != request.data['retype_password']): return Response("password mismatch") else: return Response("username can not be empty!!") else: return Response("Invalid data") response = UserServices( ConnectionService('exza')).set_password(request=request.data) return Response(response.status)
def create(request, format=None): print(request.data) gp = grpmgmt() if request.data != {}: if request.data['name'] != '': gp.name = request.data['name'] else: return Response("group_name should not be empty",status=status.HTTP_400_BAD_REQUEST) # if request.data['description'] != '': gp.description = request.data['description'] # else: # return Response("description should not be empty", status=status.HTTP_400_BAD_REQUEST) if request.data['container'] != '': gp.container = request.data['container'] else: return Response("container should not be empty", status=status.HTTP_400_BAD_REQUEST) # gp.group_type = request.data['group_type'] gp.mail_id = request.data['mail_id'] gp.notes = request.data['notes'] else: return Response("Invalid request", status=status.HTTP_400_BAD_REQUEST) response = GrpService(ConnectionService('exza')).create(grp=gp,request=request.data) return Response(response.description,response.status)
def delete(request, name, format=None): print("In delete: " + name) response = GrpService(ConnectionService('exza')).delete(name=name) return Response(response.description, response.status)
def rename(request, old_name, format=None): response = OUService(ConnectionService('exza')).rename( old_name=old_name, request=request.data) return Response(response.description, response.status)
def delete(request, name, format=None): ou = OrgUnit() ou.name = name response = OUService(ConnectionService('exza')).delete( ou=ou, force_subtree_delete=False) return Response(response.description, response.status)
def disable(request, username, format=None): print("In views: " + username) response = UserServices( ConnectionService('exza')).user_disable(username=username) return Response(response.status)
def delete(request, computer_name, format=None): response = CMServices(ConnectionService('exza')).delete( computer_name=computer_name, force_subtree_delete=False) return Response(response.status)
def edit(request, username, format=None): if username != '': response = UserServices(ConnectionService('exza')).show(name=username) else: return Response("username field cannot be empty!!") if response.data is None: print(response.description) return Response(status=response.status) for msg in response.data: user_report = UserReport() user_report.dn = msg.get('dn') user_report.sn = msg.get('sn') user_report.givenName = msg.get('givenName') user_report.displayName = msg.get('displayName') user_report.description = msg.get('description') user_report.company = msg.get('company') user_report.mail = msg.get('mail') user_report.telephoneNumber = msg.get('telephoneNumber') # res_string = "dn: " + dn + "\nchangetype: modify\ndelete: sn\n" + "sn: " + sn + "\ndelete: description\n" + "description: " + description + "\ndelete: telephoneNumber\n" + "telephoneNumber: " + telephoneNumber + "\ndelete: givenName\n" + "givenName: " + givenName + "\ndelete: displayName\n" + "displayName: " + displayName + "\ndelete: company\n" + "company: " + company + "\ndelete: mail\n" + "mail: " + mail # res_string += "\nadd: sn\n" + "sn: " + new_sn + "\nadd: description\n" + "description: " + new_description + "\nadd: telephoneNumber\n" + "telephoneNumber: " + new_telephoneNumber + "\nadd: givenName\n" + "givenName: " + new_givenName + "\nadd: displayName\n" + "displayName: " + new_displayName + "\nadd: company\n" + "company: " + new_company + "\nadd: mail\n" + "mail: " + new_mail delete_string = "dn: " + str(user_report.dn) + "\nchangetype: modify\n" add_string = "" if request.data['surname'] != '': if user_report.sn != None: delete_string += "delete: sn\n" + "sn: " + str( user_report.sn) + "\n" add_string += "add: sn\n" + "sn: " + request.data['surname'] + "\n" else: add_string += "add: sn\n" + "sn: " + request.data['surname'] + "\n" if request.data['name'] != '': if user_report.givenName != None: delete_string += "delete: givenName\n" + "givenName: " + str( user_report.givenName) + "\n" add_string += "add: givenName\n" + "givenName: " + request.data[ 'name'] + "\n" else: add_string += "add: givenName\n" + "givenName: " + request.data[ 'name'] + "\n" if request.data['description'] != '': if user_report.description != None: delete_string += "delete: description\n" + "description: " + str( user_report.description) + "\n" add_string += "add: description\n" + "description: " + request.data[ 'description'] + "\n" else: add_string += "add: description\n" + "description: " + request.data[ 'description'] + "\n" if request.data['displayName'] != '': if user_report.displayName != None: delete_string += "delete: displayName\n" + "displayName: " + str( user_report.displayName) + "\n" add_string += "add: displayName\n" + "displayName: " + request.data[ 'displayName'] + "\n" else: add_string += "add: displayName\n" + "displayName: " + request.data[ 'displayName'] + "\n" if request.data['company'] != '': if user_report.company != None: delete_string += "delete: company\n" + "company: " + str( user_report.company) + "\n" add_string += "add: company\n" + "company: " + request.data[ 'company'] + "\n" else: add_string += "add: company\n" + "company: " + request.data[ 'company'] + "\n" if request.data['telephoneNumber'] != '': if user_report.telephoneNumber != None: delete_string += "delete: telephoneNumber\n" + "telephoneNumber: " + str( user_report.telephoneNumber) + "\n" add_string += "add: telephoneNumber\n" + "telephoneNumber: " + request.data[ 'telephoneNumber'] + "\n" else: add_string += "add: telephoneNumber\n" + "telephoneNumber: " + request.data[ 'telephoneNumber'] + "\n" if request.data['mail'] != '': if user_report.mail != None: delete_string += "delete: mail\n" + "mail: " + str( user_report.mail) + "\n" add_string += "add: mail\n" + "mail: " + request.data[ 'mail'] + "\n" else: add_string += "add: mail\n" + "mail: " + request.data[ 'mail'] + "\n" input_string = delete_string + add_string response = UserServices(ConnectionService('exza')).edit_user( username=username, input_string=input_string) return Response(response.status)