Beispiel #1
0
def getFastDialDigits(_index,retry=0):
    for f in [lambda:ibs_agi.getSelectedLanguage().sayPrompt("pre_get_fast_dial_destination"),
              lambda:ibs_agi.getSelectedLanguage().sayDigit(_index),
              lambda:ibs_agi.getSelectedLanguage().sayPrompt("post_get_fast_dial_destination")]:
        digit=f()
        if digit:
            break
    
    end_of_collect="#"
    request_recollect="*"
    max_digits=ibs_agi.getConfig().getValue("max_destination_digits")
    timeout=4000
    
    digits=""
    
    while len(digits)<max_digits:
        digits+=digit
        digit=ibs_agi.getAGI().wait_for_digit(timeout)
        if not digit: #timeout
            if digits:
                break
            else:
                retry+=1
                if retry<ibs_agi.getConfig().getValue("retry"):
                    return getFastDialDigits(_index,retry)
                else:
                    return ""
        elif digits=="" and digit=="*":
            return "*"
        elif digit==request_recollect:
            return getFastDialDigits(_index)
        elif digit==end_of_collect:
            break
                
    return digits
Beispiel #2
0
def sayRemainingCredit(credit):
    for f in [lambda:ibs_agi.getSelectedLanguage().sayPrompt("pre_say_remaining_credit"),
              lambda:ibs_agi.getSelectedLanguage().sayCredit(credit),
              lambda:ibs_agi.getSelectedLanguage().sayPrompt("post_say_remaining_credit")]:
              
              ret = f()
              if ret:
                return ret
Beispiel #3
0
def changeGreeting():
    """
        record a greeting and put it in users greetings directory
    """
    ibs_agi.getSelectedLanguage().sayPrompt("pre_change_greeting")
    filename = "%s%s" % (ibs_agi.getConfig().getValue("user_greetings_root"),
                         ibs_agi.getConfig().getValue("username"))
    ibs_agi.getAGI().appexec("Record", "%s.gsm|7|60" % filename)
    ibs_agi.getSelectedLanguage().sayPrompt("change_greeting_success")
Beispiel #4
0
def getOldPassword():
    """
    """
    old_password = ibs_agi.getSelectedLanguage().sayPromptAndCollect(
        "get_old_password",
        ibs_agi.getConfig().getValue("max_password_length"))
    if not old_password:
        ibs_agi.getSelectedLanguage().sayPrompt("no_digit_entered")

    return old_password
Beispiel #5
0
def changeToNewPassword(new_password):
    """
    """
    req = request.Request()
    try:
        req.send("changePassword", True, password=new_password)
    except xmlrpclib.Fault, e:
        ibs_agi.getSelectedLanguage().sayPrompt("change_password_failure")
        logException()
        return
Beispiel #6
0
def sayRemainingTime(seconds):
    for f in [
            lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                "pre_say_remaining_time"),
            lambda: ibs_agi.getSelectedLanguage().sayTime(seconds), lambda:
            ibs_agi.getSelectedLanguage().sayPrompt("post_say_remaining_time")
    ]:

        ret = f()
        if ret:
            return ret
Beispiel #7
0
def redialLastNumber():
    """
        get last number dialed by user and dial it
    """
    req = request.Request()
    try:
        last_number = req.send("getLastDestination", True)
    except xmlrpclib.Fault, e:
        logException()
        ibs_agi.getSelectedLanguage().sayPrompt("unknown_problem")
        return
Beispiel #8
0
def getCurrentCredit():
    """
        get current credit of user
        raise an IBSException if error happens
    """
    req = request.Request()
    try:
        credit = req.send("getUserCredit", True)
    except xmlrpclib.Fault, e:
        logException()
        ibs_agi.getSelectedLanguage().sayPrompt("unknown_problem")
        raise IBSException(e.faultString)
Beispiel #9
0
def getFastDialIndexFromIBS(_index):
    """
        get fast dial index destination from ibs
        may raise an IBSException
    """
    _index = int(_index)
    req = request.Request()
    try:
        destination = req.send("getFastDialDestination", True, index=_index)
    except xmlrpclib.Fault, e:
        logException()
        ibs_agi.getSelectedLanguage().sayPrompt("unknown_problem")
        raise IBSException(e.faultString)
Beispiel #10
0
def confirmFastDial(_index, destination):
    for f in [
            lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                "pre_confirm_fast_dial"),
            lambda: ibs_agi.getSelectedLanguage().sayDigit(_index),
            lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                "mid_confirm_fast_dial"),
            lambda: ibs_agi.getSelectedLanguage().sayDigits(destination),
            lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                "post_confirm_fast_dial"),
    ]:
        digit = f()
        if digit:
            return digit

    return ibs_agi.getAGI().wait_for_digit(3000)
def addCallerIDAuthentication():
    """
        Add Caller ID Authentication to current user caller ids
    """
    caller_id=ibs_agi.getConfig().getValue("caller_id")
    if not caller_id or caller_id=="unknown":
        ibs_agi.getSelectedLanguage().sayPrompt("invalid_callerid")
        return
    
    req=request.Request()
    try:
        last_number=req.send("addCallerIDAuthentication",True)
    except xmlrpclib.Fault,e:
        logException()
        ibs_agi.getSelectedLanguage().sayPrompt("add_callerid_authentication_failure")
        return 
def deleteCallerIDAuthentication():
    """
        delete Caller ID Authentication from current user caller ids
    """
    req = request.Request()
    try:
        last_number = req.send("deleteCallerIDAuthentication", True)
    except xmlrpclib.Fault, e:
        if e.faultString == "CALLER_ID_NOT_EXISTS":
            ibs_agi.getSelectedLanguage().sayPrompt(
                "delete_callerid_authentication_not_exists")
        else:
            logException()
            ibs_agi.getSelectedLanguage().sayPrompt(
                "delete_callerid_authentication_failure")

        return
Beispiel #13
0
def authenticate(username, password):
    req = request.Request()
    try:
        if ibs_agi.getConfig().getValue("debug"):
            toLog("Authenticate: Username %s Password %s" %
                  (username, password))

        credit = req.send("authenticate",
                          True,
                          username=username,
                          password=password)
    except xmlrpclib.Fault, e:
        ibs_agi.getSelectedLanguage().sayError(e.faultString)
        credit = 0

        if ibs_agi.getConfig().getValue("debug"):
            toLog("Authenticate: Error: %s" % e.faultString)
Beispiel #14
0
def authorize(destination):
    """
        check authorization of user for calling destination
        return number of seconds remaining or -1 for unlimited
        set config authorized variable if successfully authorized
    """
    req = request.Request()
    try:
        if ibs_agi.getConfig().getValue("debug"):
            toLog("Authorize: Destination %s" % destination)

        remaining_time = req.send("authorize", True, destination=destination)

    except xmlrpclib.Fault, e:
        ibs_agi.getSelectedLanguage().sayError(e.faultString)
        remaining_time = -1

        if ibs_agi.getConfig().getValue("debug"):
            toLog("Aurhorize: Error: %s" % e.faultString)
Beispiel #15
0
def getFastDialIndex():
    _index = ""
    counter = 0
    while _index == "" and counter < ibs_agi.getConfig().getValue("retry"):
        counter += 1
        _index = ibs_agi.getSelectedLanguage().sayPrompt(
            "enter_fast_dial_index")
        if not _index:
            _index = ibs_agi.getAGI().wait_for_digit(3000)

    return _index
Beispiel #16
0
def addDestinationToFastDial(_index, destination):
    """
        add "destination" to "_index" of fast dials of current user
    """
    _index = int(_index)

    if ibs_agi.getConfig().getValue("debug"):
        toLog("addDestinationToFastDial: Index: %s Destination: %s" %
              (_index, destination))

    req = request.Request()
    try:
        last_number = req.send("addDestinationToFastDial",
                               True,
                               index=_index,
                               destination=destination)
    except xmlrpclib.Fault, e:
        logException()
        ibs_agi.getSelectedLanguage().sayPrompt(
            "add_destination_to_fast_dial_failure")
        return
Beispiel #17
0
def sayUsedCredit(duration, used_credit):

    if duration:
        for f in [
                lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                    "pre_say_talked_duration"),
                lambda: ibs_agi.getSelectedLanguage().sayTime(duration),
                lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                    "post_say_talked_duration")
        ]:

            ret = f()
            if ret:
                return ret

    for f in [
            lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                "pre_say_used_credit"),
            lambda: ibs_agi.getSelectedLanguage().sayCredit(int(used_credit)),
            lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                "post_say_used_credit")
    ]:

        ret = f()
        if ret:
            return ret
Beispiel #18
0
def getDestination(repeat=False, retry=0):
    """
        get destination and return it. return '*' if user requested to goto the menu
    """
    end_of_collect = "#"
    request_redial = "*"
    max_digits = ibs_agi.getConfig().getValue("max_destination_digits")
    timeout = 4000

    destination = ""
    if repeat:  #are we trying to redial?
        digit = ibs_agi.getSelectedLanguage().sayPrompt(
            "get_destination_again")
    else:
        digit = ibs_agi.getSelectedLanguage().sayPrompt("get_destination")
    if digit == "*":
        return digit
    else:
        while len(destination) < max_digits:
            destination += digit
            digit = ibs_agi.getAGI().wait_for_digit(timeout)
            if not digit:  #timeout
                if destination:
                    break
                else:
                    retry += 1
                    if retry < ibs_agi.getConfig().getValue("retry"):
                        return getDestination(repeat, retry)
                    else:
                        return ""
            elif destination == "" and digit == "*":
                return "*"
            elif digit == request_redial:
                return getDestination(True)
            elif digit == end_of_collect:
                break

        return destination
Beispiel #19
0
def menu():
    while True:
        selection = ibs_agi.getStateMachine().gotoState("SAY_MENU")

        if selection == "":  #timeout
            selection = ibs_agi.getAGI().wait_for_digit(5000)
            if selection == "":
                ibs_agi.getSelectedLanguage().sayPrompt("no_digit_entered")
                continue

        if ibs_agi.getConfig().getValue("debug"):
            toLog("Menu: Selected %s" % selection)

        if selection in "*#":  #go and ask for destination again
            return

        try:
            new_state = ibs_agi.getSelectedLanguage().getMenuIndexState(
                int(selection))
        except (KeyError, ValueError):
            ibs_agi.getStateMachine().gotoState("BAD_MENU_SELECTION")
            continue

        ibs_agi.getStateMachine().gotoState(new_state)
Beispiel #20
0
def dialDestination(destination, remaining_time):
    """
        dial destination and return duration of call
        if call was unsuccessful say the error
    """
    dial_str = ibs_agi.getConfig().getDialString(destination)
    if remaining_time > 0:
        dial_str += "L(%s:30000)" % (int(remaining_time) * 1000)
        ibs_agi.getAGI().set_variable(
            "LIMIT_WARNING_FILE",
            ibs_agi.getSelectedLanguage()._getFilePath("disconnect_30"))
        ibs_agi.getAGI().set_variable(
            "LIMIT_TIMEOUT_FILE",
            ibs_agi.getSelectedLanguage()._getFilePath(
                "you_have_been_disconnected"))

    if ibs_agi.getConfig().getValue("debug"):
        toLog("Dial: Destination %s DialString %s" % (destination, dial_str))

    ibs_agi.getAGI().appexec("Dial", dial_str)

    duration = 0
    status = ibs_agi.getAGI().get_variable("DIALSTATUS")

    if status in ["CHANUNAVAIL", "CONGESTION"]:
        ibs_agi.getSelectedLanguage().sayPrompt("destination_out_of_service")
    elif status in ["BUSY"]:
        ibs_agi.getSelectedLanguage().sayPrompt("destination_busy")
    elif status in ["NOANSWER"]:
        ibs_agi.getSelectedLanguage().sayPrompt("destination_noanswer")
    elif status in ["ANSWER"]:
        duration = ibs_agi.getAGI().get_variable("ANSWEREDTIME")
    elif status in ["CANCEL"]:
        pass

    if ibs_agi.getConfig().getValue("debug"):
        toLog("Dial: Status %s AnsweredTime %s" % (status, duration))

    ibs_agi.getConfig().setValue("authorized", False)

    return duration, status
Beispiel #21
0
def getUsername(authentication_counter):
    """
        ask for username, retry if no username entered. return username or empty string
    """
    counter = 0
    username = ""
    while username == "" and counter < ibs_agi.getConfig().getValue("retry"):
        counter += 1
        max_len = ibs_agi.getConfig().getValue("username_length")
        if authentication_counter:
            prompt = "get_username_again"
        else:
            prompt = "get_username"

        username = ibs_agi.getSelectedLanguage().sayPromptAndCollect(
            prompt, max_len)

    ibs_agi.getConfig().setValue("username", username)
    return username
Beispiel #22
0
def fastDial():
    """
    """
    while True:
        _index = ibs_agi.getStateMachine().gotoState("GET_FAST_DIAL_INDEX")
        if not _index or not _index.isdigit():  #timeout or #*
            return

        try:
            destination = ibs_agi.getStateMachine().gotoState(
                "GET_FAST_DIAL_DESTINATION_FROM_IBS", _index)
        except IBSException:
            return

        if destination == "":
            return ibs_agi.getSelectedLanguage().sayPrompt(
                "destination_incorrect")

        confirm = ibs_agi.getStateMachine().gotoState("CONFIRM_FAST_DIAL",
                                                      _index, destination)
        if confirm == _index:
            return ibs_agi.getStateMachine().gotoState("DIAL", destination)
Beispiel #23
0
import xmlrpclib
import ibs_agi
from lib import request
from lib.error import *


def init():
    ibs_agi.getStateMachine().registerState("CHANGE_TO_NEW_PASSWORD",
                                            changeToNewPassword)


def changeToNewPassword(new_password):
    """
    """
    req = request.Request()
    try:
        req.send("changePassword", True, password=new_password)
    except xmlrpclib.Fault, e:
        ibs_agi.getSelectedLanguage().sayPrompt("change_password_failure")
        logException()
        return
    else:
        ibs_agi.getSelectedLanguage().sayPrompt("change_password_success")
Beispiel #24
0
import xmlrpclib
import ibs_agi
from lib import request
from lib.error import *


def init():
    ibs_agi.getStateMachine().registerState("CHECK_OLD_PASSWORD",
                                            checkOldPassword)


def checkOldPassword(old_password):
    """
        check old password, return True if password was correct
        otherwise return False
    """
    req = request.Request()
    try:
        pass_correct = req.send("checkPassword", True, password=old_password)
    except xmlrpclib.Fault, e:
        logException()
        return
    else:
        if not pass_correct:
            ibs_agi.getSelectedLanguage().sayPrompt("old_password_incorrect")

        return pass_correct
Beispiel #25
0
def getPassword():
    password = ibs_agi.getSelectedLanguage().sayPromptAndCollect(
        "get_password",
        ibs_agi.getConfig().getValue("max_password_length"))
    ibs_agi.getConfig().setValue("password", password)
    return password
import ibs_agi
from lib import request
from lib.error import *


def init():
    ibs_agi.getStateMachine().registerState("DELETE_CALLERID_AUTHENTICATION",
                                            deleteCallerIDAuthentication)


def deleteCallerIDAuthentication():
    """
        delete Caller ID Authentication from current user caller ids
    """
    req = request.Request()
    try:
        last_number = req.send("deleteCallerIDAuthentication", True)
    except xmlrpclib.Fault, e:
        if e.faultString == "CALLER_ID_NOT_EXISTS":
            ibs_agi.getSelectedLanguage().sayPrompt(
                "delete_callerid_authentication_not_exists")
        else:
            logException()
            ibs_agi.getSelectedLanguage().sayPrompt(
                "delete_callerid_authentication_failure")

        return
    else:
        ibs_agi.getSelectedLanguage().sayPrompt(
            "delete_callerid_authentication_success")
Beispiel #27
0
    if ibs_agi.getConfig().getValue("debug"):
        toLog("addDestinationToFastDial: Index: %s Destination: %s" %
              (_index, destination))

    req = request.Request()
    try:
        last_number = req.send("addDestinationToFastDial",
                               True,
                               index=_index,
                               destination=destination)
    except xmlrpclib.Fault, e:
        logException()
        ibs_agi.getSelectedLanguage().sayPrompt(
            "add_destination_to_fast_dial_failure")
        return
    else:
        for f in [
                lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                    "pre_add_destination_to_fast_dial_success"),
                lambda: ibs_agi.getSelectedLanguage().sayDigits(destination),
                lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                    "mid_add_destination_to_dast_dial_success"),
                lambda: ibs_agi.getSelectedLanguage().sayDigit(_index),
                lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                    "post_add_destination_to_dast_dial_success")
        ]:
            digit = f()
            if digit:
                break
Beispiel #28
0
import ibs_agi
from lib import request
from lib.error import *


def init():
    ibs_agi.getStateMachine().registerState("REDIAL_LAST_NUMBER",
                                            redialLastNumber)


def redialLastNumber():
    """
        get last number dialed by user and dial it
    """
    req = request.Request()
    try:
        last_number = req.send("getLastDestination", True)
    except xmlrpclib.Fault, e:
        logException()
        ibs_agi.getSelectedLanguage().sayPrompt("unknown_problem")
        return
    else:
        if ibs_agi.getConfig().getValue("debug"):
            toLog("getLastDestination: %s" % last_number)

        if not last_number:
            ibs_agi.getSelectedLanguage().sayPrompt("destination_incorrect")
            return

        return ibs_agi.getStateMachine().gotoState("DIAL", last_number)
Beispiel #29
0
def authenticationFailed():
    ibs_agi.getSelectedLanguage().sayPrompt("authentication_failed")
    ibs_agi.getStateMachine().gotoState("GOODBYE_HANGUP")
    raise IBSException("Authentication Failed")
Beispiel #30
0
def goodbyeHangup():
    ibs_agi.getSelectedLanguage().sayFile("goodbye")
    return ibs_agi.getStateMachine().gotoState("HANGUP")