Пример #1
0
 def getIp(self):
     ip = getRequest().ip_proxy if self.acceptProxy.isTrue() else getRequest().ip  # pylint: disable=maybe-no-member
     if self.reverseDns.isTrue():
         try:
             return str(dns.resolver.query(dns.reversename.from_address(ip), 'PTR')[0])
         except:
             pass
     return ip
Пример #2
0
 def getIp(self):
     ip = getRequest().ip_proxy if self.acceptProxy.isTrue() else getRequest().ip  # pylint: disable=maybe-no-member
     if self.reverseDns.isTrue():
         try:
             return str(dns.resolver.query(dns.reversename.from_address(ip), 'PTR')[0])
         except Exception:
             pass
     return ip
Пример #3
0
def __registerUser(authenticator, authInstance, username):
    """
    Check if this user already exists on database with this authenticator, if don't, create it with defaults
    This will work correctly with both internal or externals cause we first authenticate the user, if internal and user do not exists in database
    authenticate will return false, if external and return true, will create a reference in database
    """
    from uds.core.util.request import getRequest

    username = authInstance.transformUsername(username)
    logger.debug('Transformed username: {0}'.format(username))

    request = getRequest()

    usr = authenticator.getOrCreateUser(username, username)
    usr.real_name = authInstance.getRealName(username)
    usr.save()
    if usr is not None and State.isActive(usr.state):
        # Now we update database groups for this user
        usr.getManager().recreateGroups(usr)
        # And add an login event
        events.addEvent(authenticator, events.ET_LOGIN, username=username, srcip=request.ip)  # pylint: disable=maybe-no-member
        events.addEvent(authenticator, events.ET_PLATFORM, platform=request.os.OS, browser=request.os.Browser, version=request.os.Version)  # pylint: disable=maybe-no-member
        return usr

    return None
Пример #4
0
def __registerUser(authenticator: Authenticator,
                   authInstance: AuthenticatorInstance,
                   username: str) -> typing.Optional[User]:
    """
    Check if this user already exists on database with this authenticator, if don't, create it with defaults
    This will work correctly with both internal or externals cause we first authenticate the user, if internal and user do not exists in database
    authenticate will return false, if external and return true, will create a reference in database
    """
    from uds.core.util.request import getRequest

    username = authInstance.transformUsername(username)
    logger.debug('Transformed username: %s', username)

    request = getRequest()

    usr = authenticator.getOrCreateUser(username, username)
    usr.real_name = authInstance.getRealName(username)
    usr.save()
    if usr is not None and State.isActive(usr.state):
        # Now we update database groups for this user
        usr.getManager().recreateGroups(usr)
        # And add an login event
        events.addEvent(authenticator,
                        events.ET_LOGIN,
                        username=username,
                        srcip=request.ip)  # pylint: disable=maybe-no-member
        events.addEvent(authenticator,
                        events.ET_PLATFORM,
                        platform=request.os.OS,
                        browser=request.os.Browser,
                        version=request.os.Version)  # pylint: disable=maybe-no-member
        return usr

    return None
Пример #5
0
def __registerUser(authenticator, authInstance, username):
    '''
    Check if this user already exists on database with this authenticator, if don't, create it with defaults
    This will work correctly with both internal or externals cause we first authenticate the user, if internal and user do not exists in database
    authenticate will return false, if external and return true, will create a reference in database
    '''
    from uds.core.util.request import getRequest

    username = authInstance.transformUsername(username)
    logger.debug('Transformed username: {0}'.format(username))

    usr = authenticator.getOrCreateUser(username, authInstance.getRealName(username))
    if usr is not None and State.isActive(usr.state):
        # Now we update database groups for this user
        usr.getManager().recreateGroups(usr)
        # And add an login event
        events.addEvent(authenticator, events.ET_LOGIN, username=username, srcip=getRequest().ip)  # pylint: disable=maybe-no-member
        return usr

    return None
Пример #6
0
    def transformUsername(self, username):
        from uds.core.util.request import getRequest
        if self.differentForEachHost.isTrue():
            newUsername = self.getIp(getRequest().ip) + '-' + username  # pylint: disable=maybe-no-member
            # Duplicate basic user into username.
            auth = self.dbAuthenticator()
            # "Derived" users will belong to no group at all, because we will extract groups from "base" user
            # This way also, we protect from using forged "ip" + "username", because those will belong in fact to no group
            # and access will be denied
            try:
                usr = auth.users.get(name=username, state=State.ACTIVE)
                parent = usr.uuid
                usr.id = usr.uuid = None  # Empty "key" fields for replication
                if usr.real_name.strip() == '':
                    usr.real_name = usr.name
                usr.name = newUsername
                usr.parent = parent
                usr.save()
            except Exception:
                pass  # User already exists
            username = newUsername

        return username
Пример #7
0
    def transformUsername(self, username):
        from uds.core.util.request import getRequest
        if self.differentForEachHost.isTrue():
            newUsername = self.getIp(getRequest().ip) + '-' + username  # pylint: disable=maybe-no-member
            # Duplicate basic user into username.
            auth = self.dbAuthenticator()
            # "Derived" users will belong to no group at all, because we will extract groups from "base" user
            # This way also, we protect from using forged "ip" + "username", because those will belong in fact to no group
            # and access will be denied
            try:
                usr = auth.users.get(name=username, state=State.ACTIVE)
                parent = usr.uuid
                usr.id = usr.uuid = None  # Empty "key" fields for replication
                if usr.real_name.strip() == '':
                    usr.real_name = usr.name
                usr.name = newUsername
                usr.parent = parent
                usr.save()
            except Exception:
                pass  # User already exists
            username = newUsername

        return username
Пример #8
0
 def getIp(self):
     ip = getRequest().ip_proxy if self.acceptProxy.isTrue(
     ) else getRequest().ip  # pylint: disable=maybe-no-member
     logger.debug('Client IP: %s', ip)
     return ip
Пример #9
0
 def getIp(self):
     return getRequest().ip_proxy if self.acceptProxy.isTrue() else getRequest().ip  # pylint: disable=maybe-no-member
Пример #10
0
 def getIp(self):
     ip = getRequest().ip_proxy if self.acceptProxy.isTrue() else getRequest().ip  # pylint: disable=maybe-no-member
     logger.debug('Client IP: {}'.format(ip))
     return ip