Exemplo n.º 1
0
def create_user_object(jabber_id, name, vcard):
    if isinstance(jabber_id, sleekxmpp.jid.JID
                  ) and jabber_id.bare is not None and jabber_id.bare:
        jabber_id_bare = jabber_id.bare
    else:
        jabber_id_bare = jabber_id

    vcard_nickname = None
    vcard_email = None

    if vcard is not None:
        # get_payload() returns the xml for the Iq() as a Element object
        payload = vcard.get_payload()
        vcard_xml = payload[0]
        # vcard_full_name = vcard_xml.findtext('.//{vcard-temp}FN')
        vcard_nickname = vcard_xml.findtext('.//{vcard-temp}NICKNAME')
        vcard_email = vcard_xml.findtext('.//{vcard-temp}USERID')

    client_user = XMPPUser(
        jabber_id_bare, vcard_nickname
        if vcard_nickname is not None and vcard_nickname else name,
        vcard_email if vcard_email is not None and vcard_email else None)

    # Create a User object
    user_object = User(0)
    user_object.name = name
    user_object.points = 0
    json_data = client_user.to_json()
    user_object.usernames = {json_data['client']: [json_data['username']]}
    user_object.current_username = json_data['username']

    logger.debug("client_user is '%s'" % client_user)
    return client_user
Exemplo n.º 2
0
    def build_user(self, result_data):
        user = User(result_data['user_id'])

        user.aliases = result_data['aliases'] if 'aliases' in result_data else None
        user.is_stashed = True
        user.last_modified = (
            result_data['last_modified']
            if 'last_modified' in result_data
            else None
        )
        user.name = result_data['name'] if 'name' in result_data else None
        user.plugin_data = (
            result_data['plugin_data']
            if 'plugin_data' in result_data and isinstance(result_data['plugin_data'], dict)
            else None
        )
        user.points = (
            result_data['points']
            if 'points' in result_data and isinstance(result_data['points'], (int, long))
            else 0
        )
        user.timestamp = result_data['timestamp'] if 'timestamp' in result_data else None
        user.usernames = (
            result_data['usernames']
            if 'usernames' in result_data and isinstance(result_data['usernames'], dict)
            else None
        )
        user.permissions = result_data['permissions'] if 'permissions' in result_data else None

        return user
Exemplo n.º 3
0
def create_user_object(handle, name, aliases):
    client = 'skype'

    user = User(handle)
    user.aliases = aliases
    user.client = client
    user.name = name

    logger.debug("create_user_object - user is '%s'" % user)
    return user
Exemplo n.º 4
0
    def build_user(self, result_data):
        user = User(result_data.eid)

        user.name = result_data['name'] if 'name' in result_data else None
        user.usernames = result_data['usernames'] if 'usernames' in result_data else {}
        user.points = result_data['points'] if 'points' in result_data else None
        user.permissions = result_data['permissions'] if 'permissions' in result_data else []
        user.aliases = result_data['aliases'] if 'aliases' in result_data else []
        user.image = result_data['image'] if 'image' in result_data else None
        user.is_stashed = True

        return user
Exemplo n.º 5
0
    def get_user_from_message(self, message_sender, channel=None, event=None, **kwargs):
        user = User(0)

        logger.debug("Channel is '%s', message_sender is '%s', event is '%s'" % (channel, message_sender, event))

        # Get client object information
        client_user = self._get_client_object_from_message_object(message_sender, channel=channel, event=event)
        user.client_user = client_user

        user.name = client_user.name
        user.current_username = client_user.username

        return user
Exemplo n.º 6
0
    def get_user_from_message(self, message_sender, channel=None, event=None, **kwargs):
        user = User(0)

        logger.debug("Channel is '%s', message_sender is '%s', event is '%s'" % (channel, message_sender, event))

        api_json = self.client.api_call('users.info', user=message_sender)
        if 'user' in api_json and api_json['user'] is not None:
            client_user = create_user_object_from_json(api_json['user'])
            user.client_user = client_user

            user.name = client_user.name
            user.current_username = client_user.username

        return user
Exemplo n.º 7
0
    def trigger_add_user(self, client, message, **kwargs):
        capture = kwargs.get('capture_groups', None)
        captured_name = capture[0]
        captured_username = capture[1]
        text = None

        if captured_name and captured_username:
            a_user = User(0)
            a_user.name = captured_name
            a_user.usernames = {client.integration_name: [captured_username]}

            try:
                self.havocbot.db.add_user(a_user)
            except UserDataAlreadyExistsException:
                text = 'That user already exists'
            else:
                text = 'User added'
            finally:
                client.send_message(text, message.reply(), event=message.event)
        else:
            text = 'Invalid parameters. Check the help option for usage'
            client.send_message(text, message.reply(), event=message.event)