Exemplo n.º 1
0
def user_get_vmbox(agi, cursor, args):
    userid = agi.get_variable('XIVO_USERID')

    xlen = len(args)

    if xlen > 0 and args[0] != '':
        try:
            context = agi.get_variable('XIVO_BASE_CONTEXT')
            if not context:
                agi.dp_break('Could not get the context of the caller')

            user = objects.User(agi, cursor, exten=args[0], context=context)
        except (ValueError, LookupError) as e:
            agi.dp_break(str(e))
    else:
        try:
            user = objects.User(agi, cursor, int(userid))
        except (ValueError, LookupError) as e:
            agi.dp_break(str(e))

    if not user.vmbox:
        agi.dp_break("User has no voicemail box (id: %d)" % user.id)

    if user.vmbox.skipcheckpass:
        vmmain_options = "s"
    else:
        vmmain_options = ""

    agi.set_variable('XIVO_VMMAIN_OPTIONS', vmmain_options)
    agi.set_variable('XIVO_MAILBOX', user.vmbox.mailbox)
    agi.set_variable('XIVO_MAILBOX_CONTEXT', user.vmbox.context)
Exemplo n.º 2
0
    def get_user(self):
        channel_name = self._agi.env['agi_channel']

        result = EXTEN_CONTEXT_RE.match(channel_name)
        if result:
            exten = result.group(1)
            context = result.group(2)
            if context == 'usersharedlines':
                search_params = {'xid': exten}
            else:
                search_params = {'exten': exten, 'context': context}

            return objects.User(self._agi, self._cursor, **search_params)

        raise LookupError(
            'Failed to find a matching user from {}'.format(channel_name))
Exemplo n.º 3
0
    def _retrieve_user(self):
        try:
            if not self.userid:
                userid = self.useruuid
            else:
                userid = int(self.userid)
            self.user = objects.User(self._agi, self._cursor, userid)
            if self.user.enablexfer:
                self.options += 'T'

            if not self.outcall.internal:
                if self.user.enableonlinerec:
                    self.options += "X"
                self.callrecord = self.user.call_record_outgoing_external_enabled
        except (ValueError, LookupError):
            logger.debug('Could not retrieve user %s', self.userid)
        self._agi.set_variable(dialplan_variables.CALL_OPTIONS, self.options)
Exemplo n.º 4
0
def vmbox_get_info(agi, cursor, args):
    caller = None
    vmbox = None
    xlen = len(args)
    if xlen > 0 and args[0] != '':
        try:
            xivo_userid = agi.get_variable('XIVO_USERID')
            if xivo_userid:
                caller = objects.User(agi, cursor, xid=int(xivo_userid))
            context = agi.get_variable('XIVO_BASE_CONTEXT')
            if not context:
                agi.dp_break('Could not get the context of the caller')

            vmbox = objects.VMBox(agi,
                                  cursor,
                                  mailbox=args[0],
                                  context=context)
        except (ValueError, LookupError) as e:
            logger.error(
                'Error while retrieving vmbox from number and context',
                exc_info=True)
            agi.dp_break(str(e))
    else:
        try:
            vmboxid = int(agi.get_variable('XIVO_VMBOXID'))
            vmbox = objects.VMBox(agi, cursor, vmboxid)
        except (ValueError, LookupError) as e:
            logger.error('Error while retrieving vmbox from id', exc_info=True)
            agi.dp_break(str(e))

    if vmbox.skipcheckpass:
        vmmain_options = "s"
    else:
        vmmain_options = ""

    if caller and caller.language:
        mbox_lang = caller.language
    elif vmbox.language:
        mbox_lang = vmbox.language
    else:
        mbox_lang = ''

    agi.set_variable('XIVO_VMMAIN_OPTIONS', vmmain_options)
    agi.set_variable('XIVO_MAILBOX', vmbox.mailbox)
    agi.set_variable('XIVO_MAILBOX_CONTEXT', vmbox.context)
    agi.set_variable('XIVO_MAILBOX_LANGUAGE', mbox_lang)
Exemplo n.º 5
0
    def get_user(self):
        channel_name = self._agi.env['agi_channel']
        search_params = {}

        result = AGENT_CHANNEL_RE.match(channel_name)
        if result:
            agent_id = result.group(1)
            search_params = {'agent_id': int(agent_id)}
        else:
            user_uuid = self._agi.get_variable('XIVO_USERUUID')
            if user_uuid:
                search_params = {'xid': user_uuid}

        if search_params:
            return objects.User(self._agi, self._cursor, **search_params)

        raise LookupError(
            'Failed to find a matching user from {}'.format(channel_name))
Exemplo n.º 6
0
def record_caller(agi, cursor, args):
    is_being_recorded = agi.get_variable('WAZO_CALL_RECORD_ACTIVE') == '1'
    if is_being_recorded:
        return

    user_id = agi.get_variable(dialplan_variables.USERID)
    if not user_id:
        return

    caller = objects.User(agi, cursor, int(user_id))
    if not caller:
        return

    is_external = agi.get_variable(dialplan_variables.OUTCALL_ID) != ''
    should_record = (
        (not is_external and caller.call_record_outgoing_internal_enabled)
        or (is_external and caller.call_record_outgoing_external_enabled))
    if not should_record:
        return

    _start_mix_monitor(agi)
Exemplo n.º 7
0
def phone_get_features(agi, cursor, args):
    userid = agi.get_variable('XIVO_USERID')

    try:
        user = objects.User(agi, cursor, int(userid))
    except (ValueError, LookupError) as e:
        agi.dp_break(str(e))

    _set_current_forwards(agi, user.id)

    for service in objects.ExtenFeatures.FEATURES['services']:
        if service == 'callrecord':
            enabled = user.call_record_enabled
            agi.set_variable("XIVO_CALLRECORD", int(enabled))
        elif service == 'enablevm':
            enabled = user.enablevoicemail
            agi.set_variable("XIVO_ENABLEVOICEMAIL", int(enabled))
        elif service == 'incallfilter':
            enabled = user.incallfilter
            agi.set_variable("XIVO_INCALLFILTER", int(enabled))
        elif service == 'enablednd':
            enabled = user.enablednd
            agi.set_variable("XIVO_ENABLEDND", int(enabled))
Exemplo n.º 8
0
def _get_user_from_exten(agi, cursor, exten):
    context = _get_context_of_calling_user(agi)

    return objects.User(agi, cursor, exten=exten, context=context)
Exemplo n.º 9
0
def _get_calling_user(agi, cursor):
    return objects.User(agi, cursor, _get_id_of_calling_user(agi))
Exemplo n.º 10
0
def _user_set_call_rights(agi, cursor, args):
    userid = agi.get_variable('XIVO_USERID')
    dstnum = agi.get_variable('XIVO_DSTNUM')
    outcallid = agi.get_variable('XIVO_OUTCALLID')

    cursor.query("SELECT ${columns} FROM rightcallexten",
                 ('rightcallid', 'exten'))
    res = cursor.fetchall()

    if not res:
        call_rights.allow(agi)

    rightcallidset = set(
        (row['rightcallid'] for row in res
         if call_rights.extension_matches(dstnum, row['exten'])))

    if not rightcallidset:
        call_rights.allow(agi)

    rightcallids = '(' + ','.join((str(el) for el in rightcallidset)) + ')'

    try:
        user = objects.User(agi, cursor, int(userid))
    except (ValueError, LookupError):
        if not outcallid:
            call_rights.allow(agi)
    else:
        cursor.query(
            "SELECT ${columns} FROM rightcall "
            "INNER JOIN rightcallmember "
            "ON rightcall.id = rightcallmember.rightcallid "
            "WHERE rightcall.id IN " + rightcallids + " "
            "AND rightcallmember.type = 'user' "
            "AND rightcallmember.typeval = '%s' "
            "AND rightcall.commented = 0",
            (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME,
             call_rights.RIGHTCALL_PASSWD_COLNAME), (user.id, ))
        res = cursor.fetchall()

        if user.rightcallcode:
            for i, value in enumerate(res):
                if value[1]:
                    res[i][1] = user.rightcallcode

        call_rights.apply_rules(agi, res)

        cursor.query(
            "SELECT ${columns} FROM groupfeatures "
            "INNER JOIN queuemember "
            "ON groupfeatures.name = queuemember.queue_name "
            "INNER JOIN queue "
            "ON queue.name = queuemember.queue_name "
            "WHERE queuemember.userid = %s "
            "AND queuemember.usertype = 'user' "
            "AND queuemember.category = 'group' "
            "AND queuemember.commented = 0 "
            "AND queue.category = 'group' "
            "AND queue.commented = 0", ('groupfeatures.id', ), (user.id, ))
        res = cursor.fetchall()

        if res:
            groupids = [row['groupfeatures.id'] for row in res]
            cursor.query(
                "SELECT ${columns} FROM rightcall "
                "INNER JOIN rightcallmember "
                "ON rightcall.id = rightcallmember.rightcallid "
                "WHERE rightcall.id IN " + rightcallids + " "
                "AND rightcallmember.type = 'group' "
                "AND rightcallmember.typeval IN (" +
                ", ".join(["'%s'"] * len(res)) + ") "
                "AND rightcall.commented = 0",
                (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME,
                 call_rights.RIGHTCALL_PASSWD_COLNAME), groupids)
            res = cursor.fetchall()
            call_rights.apply_rules(agi, res)

    if outcallid:
        cursor.query(
            "SELECT ${columns} FROM rightcall "
            "INNER JOIN rightcallmember "
            "ON rightcall.id = rightcallmember.rightcallid "
            "INNER JOIN outcall "
            "ON CAST(rightcallmember.typeval AS integer) = outcall.id "
            "WHERE rightcall.id IN " + rightcallids + " "
            "AND rightcallmember.type = 'outcall' "
            "AND outcall.id = %s "
            "AND rightcall.commented = 0",
            (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME,
             call_rights.RIGHTCALL_PASSWD_COLNAME), (outcallid, ))
        res = cursor.fetchall()
        call_rights.apply_rules(agi, res)

    call_rights.allow(agi)