示例#1
0
def faxIncoming(config, user, call, already_connected):
    """
    Called by callIncoming when an incoming fax call is received

    'call' a python Call handle referencing to the call
    'user' name of the user who is responsible for this
    'config' ConfigParser instance holding the config data
    'already_connected' ture if we're already connected (that means we must
    switch to fax mode)
    """
    # todo: use config.getQueueFiles + _mkdir here
    receivedQ = fileutils._mkuserdir(user,
                                     config.get('GLOBAL', "fax_user_dir"),
                                     user, "received")

    # assure these variables are defined
    filename = faxInfo = None

    stationID = config.getUser(user, "fax_stationID", default="")
    if not stationID:
        core.error("Warning: fax_stationID not found for user %s "
                   "-> using empty string" % user)
    # empty string is no problem for headline
    headline = config.getUser(user, "fax_headline", default="")

    call.log("call from %s to %s for %s connecting with fax" % \
             (call.from_nr, call.to_nr, user), 1)
    try:
        if already_connected:
            faxInfo = call.switch_to_faxG3(stationID, headline)
        else:
            faxInfo = call.connect_faxG3(stationID, headline)
        filename = fileutils.uniqueName(receivedQ, "fax", faxInfo.format)[1]
        call.fax_receive(filename)
        causes = call.disconnect()
        call.log("connection finished with cause 0x%x, 0x%x" % causes, 1)
    except core.CallGoneError:
        # catch this here to get the cause info into the mail
        causes = call.disconnect()
        call.log("connection lost with cause 0x%x, 0x%x" % causes, 1)
        # todo: send error mail here? Don't think it makes sense to send
        # a mail on each try, which would mean sending 10 mails for one fax...
        # If the user wants to know the current status he should use "capisuitefax -l"
    else:
        assert filename
        if os.access(filename, os.R_OK):
            faxInfo = faxInfo.as_dict()
            faxInfo.update({
                'filename' : filename,
                'call_from': call.from_nr,
                'call_to'  : call.to_nr,
                'causes'   : causes,
                'hostname' : os.uname()[1]
                })
            capisuite.fax.createReceivedJob(user, **faxInfo)
            action = _getAction(config, user, "fax_action",
                                ("saveonly", "mailandsave"))
            if action == "mailandsave":
                fromaddress = config.getUser(user, "fax_email_from", user)
                mailaddress = config.getUser(user, "fax_email", user)

                helpers.sendMIMEMail(
                    fromaddress, mailaddress,
                    config.get('MailFaxReceived', 'subject') % faxInfo,
                    faxInfo['format'],
                    config.get('MailFaxReceived', 'text') % faxInfo,
                    filename)
示例#2
0
def faxIncoming(config, user, call, already_connected):
    """
    Called by callIncoming when an incoming fax call is received

    'call' a python Call handle referencing to the call
    'user' name of the user who is responsible for this
    'config' ConfigParser instance holding the config data
    'already_connected' ture if we're already connected (that means we must
    switch to fax mode)
    """
    # todo: use config.getQueueFiles + _mkdir here
    receivedQ = fileutils._mkuserdir(user, config.get('GLOBAL',
                                                      "fax_user_dir"), user,
                                     "received")

    # assure these variables are defined
    filename = faxInfo = None

    stationID = config.getUser(user, "fax_stationID", default="")
    if not stationID:
        core.error("Warning: fax_stationID not found for user %s "
                   "-> using empty string" % user)
    # empty string is no problem for headline
    headline = config.getUser(user, "fax_headline", default="")

    call.log("call from %s to %s for %s connecting with fax" % \
             (call.from_nr, call.to_nr, user), 1)
    try:
        if already_connected:
            faxInfo = call.switch_to_faxG3(stationID, headline)
        else:
            faxInfo = call.connect_faxG3(stationID, headline)
        filename = fileutils.uniqueName(receivedQ, "fax", faxInfo.format)[1]
        call.fax_receive(filename)
        causes = call.disconnect()
        call.log("connection finished with cause 0x%x, 0x%x" % causes, 1)
    except core.CallGoneError:
        # catch this here to get the cause info into the mail
        causes = call.disconnect()
        call.log("connection lost with cause 0x%x, 0x%x" % causes, 1)
        # todo: send error mail here? Don't think it makes sense to send
        # a mail on each try, which would mean sending 10 mails for one fax...
        # If the user wants to know the current status he should use "capisuitefax -l"
    else:
        assert filename
        if os.access(filename, os.R_OK):
            faxInfo = faxInfo.as_dict()
            faxInfo.update({
                'filename': filename,
                'call_from': call.from_nr,
                'call_to': call.to_nr,
                'causes': causes,
                'hostname': os.uname()[1]
            })
            capisuite.fax.createReceivedJob(user, **faxInfo)
            action = _getAction(config, user, "fax_action",
                                ("saveonly", "mailandsave"))
            if action == "mailandsave":
                fromaddress = config.getUser(user, "fax_email_from", user)
                mailaddress = config.getUser(user, "fax_email", user)

                helpers.sendMIMEMail(
                    fromaddress, mailaddress,
                    config.get('MailFaxReceived', 'subject') % faxInfo,
                    faxInfo['format'],
                    config.get('MailFaxReceived', 'text') % faxInfo, filename)
示例#3
0
def voiceIncoming(config, user, call):
    """
    Called by callIncoming when an incoming voice call is received

    'call' a python Call handle referencing to the call
    'user' name of the user who is responsible for this
    'config' ConfigParser instance holding the config data
    """
    try:
        if not config.has_option(user, 'voice_delay'):
            core.error("voice_delay not found for user %s! -> "
                    "rejecting call" % user)
            call.reject(0x34A9)
            return
        delay = config.getint(user, "voice_delay")
        call.log("call from %s to %s for %s connecting with voice" % \
            (call.from_nr, call.to_nr, user), 1)
        call.connect_voice(delay)

        userdir = config.get('GLOBAL', "voice_user_dir")
        action = _getAction(config, user, "voice_action",
                            ("saveonly", "mailandsave", "none"))
        receivedQ = fileutils._mkuserdir(user, userdir, user, "received")
        userannouncement = os.path.join(
            userdir, user,
            config.getUser(user, "announcement", "announcement.la"))
        pin = config.getUser(user, "pin", "")
        filename = None # assure it's defined

        call.enable_DTMF()
        if os.access(userannouncement, os.R_OK):
            call.audio_send(userannouncement, 1)
        else:
            if call.to_nr != "-":
                say(config, user, call, "anrufbeantworter-von.la")
                capisuite.voice.sayNumber(config, user, call, call.to_nr)
            say(config, user, call, "bitte-nachricht.la")

        if action != "none":
            say(config, user, call, "beep.la")
            length = config.getUser(user, "record_length", 60)
            # todo: put this into voice.getNameForRecord
            filename = fileutils.uniqueName(receivedQ, "voice", 'la')[1]
            silence_timeout = config.getUser(user, "record_silence_timeout", 5)
            msg_length = call.audio_receive(filename, int(length),
                                                 int(silence_timeout), 1)
        dtmf_list = call.read_DTMF(0)
        if dtmf_list == "X":
            if os.access(filename, os.R_OK):
                os.unlink(filename)
            faxIncoming(config, user, call, 1)
        elif dtmf_list and pin:
            # wait 5 seconds for input
            dtmf_list += call.read_DTMF(3)
            count = 1
            # allow three tries
            while count < 3 and pin != dtmf_list:
                call.log("wrong PIN entered...", 1)
                say(config, user, call, "beep.la")
                dtmf_list = call.read_DTMF(3)
                count += 1
            else:
                # failed three time
                # todo: hang up?
                # gh: Yes.
                pass
            if pin == dtmf_list:
                if os.access(filename, os.R_OK):
                    os.unlink(filename)
                call.log("Starting remote inquiry...", 1)
                remoteInquiry(config, user, call, receivedQ)

    except core.CallGoneError:
        # catch this here to get the cause info in the mail
        causes = call.disconnect()
        call.log("connection lost with cause 0x%x, 0x%x" % causes, 1)
    else:
        causes = call.disconnect()
        call.log("connection finished with cause 0x%x, 0x%x" % causes, 1)

    if (filename and os.access(filename, os.R_OK)):    
        info = capisuite.voice.createReceivedJob(user, filename, call.from_nr,
                                                 call.to_nr, causes)
        fromaddress = config.getUser(user, "voice_email_from", user)
        mailaddress = config.getUser(user, "voice_email", user)
        if action == "mailandsave":
            info['hostname'] = os.uname()[1]
            info['msg_length'] = msg_length
            helpers.sendMIMEMail(
                fromaddress, mailaddress,
                config.get('MailVoiceReceived', 'subject') % info,
                "la",
                config.get('MailVoiceReceived', 'text') % info,
                filename)
示例#4
0
def voiceIncoming(config, user, call):
    """
    Called by callIncoming when an incoming voice call is received

    'call' a python Call handle referencing to the call
    'user' name of the user who is responsible for this
    'config' ConfigParser instance holding the config data
    """
    try:
        if not config.has_option(user, 'voice_delay'):
            core.error("voice_delay not found for user %s! -> "
                       "rejecting call" % user)
            call.reject(0x34A9)
            return
        delay = config.getint(user, "voice_delay")
        call.log("call from %s to %s for %s connecting with voice" % \
            (call.from_nr, call.to_nr, user), 1)
        call.connect_voice(delay)

        userdir = config.get('GLOBAL', "voice_user_dir")
        action = _getAction(config, user, "voice_action",
                            ("saveonly", "mailandsave", "none"))
        receivedQ = fileutils._mkuserdir(user, userdir, user, "received")
        userannouncement = os.path.join(
            userdir, user,
            config.getUser(user, "announcement", "announcement.la"))
        pin = config.getUser(user, "pin", "")
        filename = None  # assure it's defined

        call.enable_DTMF()
        if os.access(userannouncement, os.R_OK):
            call.audio_send(userannouncement, 1)
        else:
            if call.to_nr != "-":
                say(config, user, call, "anrufbeantworter-von.la")
                capisuite.voice.sayNumber(config, user, call, call.to_nr)
            say(config, user, call, "bitte-nachricht.la")

        if action != "none":
            say(config, user, call, "beep.la")
            length = config.getUser(user, "record_length", 60)
            # todo: put this into voice.getNameForRecord
            filename = fileutils.uniqueName(receivedQ, "voice", 'la')[1]
            silence_timeout = config.getUser(user, "record_silence_timeout", 5)
            msg_length = call.audio_receive(filename, int(length),
                                            int(silence_timeout), 1)
        dtmf_list = call.read_DTMF(0)
        if dtmf_list == "X":
            if os.access(filename, os.R_OK):
                os.unlink(filename)
            faxIncoming(config, user, call, 1)
        elif dtmf_list and pin:
            # wait 5 seconds for input
            dtmf_list += call.read_DTMF(3)
            count = 1
            # allow three tries
            while count < 3 and pin != dtmf_list:
                call.log("wrong PIN entered...", 1)
                say(config, user, call, "beep.la")
                dtmf_list = call.read_DTMF(3)
                count += 1
            else:
                # failed three time
                # todo: hang up?
                # gh: Yes.
                pass
            if pin == dtmf_list:
                if os.access(filename, os.R_OK):
                    os.unlink(filename)
                call.log("Starting remote inquiry...", 1)
                remoteInquiry(config, user, call, receivedQ)

    except core.CallGoneError:
        # catch this here to get the cause info in the mail
        causes = call.disconnect()
        call.log("connection lost with cause 0x%x, 0x%x" % causes, 1)
    else:
        causes = call.disconnect()
        call.log("connection finished with cause 0x%x, 0x%x" % causes, 1)

    if (filename and os.access(filename, os.R_OK)):
        info = capisuite.voice.createReceivedJob(user, filename, call.from_nr,
                                                 call.to_nr, causes)
        fromaddress = config.getUser(user, "voice_email_from", user)
        mailaddress = config.getUser(user, "voice_email", user)
        if action == "mailandsave":
            info['hostname'] = os.uname()[1]
            info['msg_length'] = msg_length
            helpers.sendMIMEMail(
                fromaddress, mailaddress,
                config.get('MailVoiceReceived', 'subject') % info, "la",
                config.get('MailVoiceReceived', 'text') % info, filename)