예제 #1
0
def dial(destination):
    duration = 0
    status = "HANGUP"
    do_call_end = True
    authorized = False
    try:
        remaining_time = ibs_agi.getStateMachine().gotoState(
            "AUTHORIZE", destination)

        if ibs_agi.getConfig().getValue("authorized"):
            ibs_agi.getStateMachine().gotoState("SAY_REMAINING_TIME",
                                                remaining_time)
            (duration, status) = ibs_agi.getStateMachine().gotoState(
                "DIAL_DESTINATION", destination, remaining_time)
        else:
            do_call_end = False
            return
    finally:
        if do_call_end:
            (duration, used_credit) = ibs_agi.getStateMachine().gotoState(
                "CALL_END", duration, status)

            ch_status = ibs_agi.getAGI().channel_status()
            if ibs_agi.getConfig().getValue("debug"):
                toLog("AferDial ChannelStatus: " + str(ch_status))

            ibs_agi.getStateMachine().gotoState("SAY_USED_CREDIT", duration,
                                                used_credit)
예제 #2
0
def chooseLanguage():
    if ibs_agi.getConfig().getValue(
            "language") != "":  #language already selected
        return
    elif len(ibs_agi.getLangManager().getAllLanguages()) == 1:
        lang_obj = ibs_agi.getLangManager().getLanguageByIndex(0)
    else:
        digit = ''
        while not digit:
            i = 0
            for lang_code, lang_obj in ibs_agi.getLangManager(
            ).getAllLanguages():
                digit = lang_obj.sayLanguageOption(i + 1)
                if digit:
                    break
                i += 1

            if not digit:
                digit = ibs_agi.getAGI().wait_for_digit(5000)

            if not digit:
                ibs_agi.getLangManager().getLanguageByIndex(0).sayPrompt(
                    "no_digit_entered")
                continue
            else:
                try:
                    lang_obj = ibs_agi.getLangManager().getLanguageByIndex(
                        int(digit) - 1)
                except IndexError:
                    continue

                break

    ibs_agi.getConfig().setValue("language", lang_obj.getLanguageCode())
예제 #3
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
예제 #4
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")
예제 #5
0
파일: request.py 프로젝트: sankopay/IBSng
    def send(self, method_name, add_session_variables=False, **kargs):
        """
            call method name with dictionary arguments and return the results
        """
        kargs["asterisk_password"] = ibs_agi.getConfig().getValue(
            "asterisk_password")

        if add_session_variables:
            kargs["username"] = ibs_agi.getConfig().getValue("username")
            kargs["caller_id"] = ibs_agi.getConfig().getValue("caller_id")
            kargs["channel"] = ibs_agi.getConfig().getValue("channel")
            kargs["unique_id"] = ibs_agi.getConfig().getValue("unique_id")

        return apply(IBSRequest.send, [self, "asterisk.%s" % method_name],
                     kargs)
예제 #6
0
def userPassAuthenticate():
    counter=0
    while counter<ibs_agi.getConfig().getValue("retry") and not ibs_agi.getConfig().getValue("authenticated"):
        username=ibs_agi.getStateMachine().gotoState("GET_USERNAME",counter)
        if username == "":
            ibs_agi.getStateMachine().gotoState("AUTHENTICATION_FAILED")
            
        password=ibs_agi.getStateMachine().gotoState("GET_PASSWORD")
        credit=ibs_agi.getStateMachine().gotoState("AUTHENTICATE",username,password)
        counter+=1

    if not ibs_agi.getConfig().getValue("authenticated"):
        ibs_agi.getStateMachine().gotoState("AUTHENTICATION_FAILED")

    return credit
예제 #7
0
def callEnd(duration, status):
    """
    """
    req=request.Request()
    try:
        if ibs_agi.getConfig().getValue("debug"):
            toLog("CallEnd: duration %s status %s"%(duration,status))

        (duration,used_credit)=req.send("callEnd",True,duration=duration,dc_cause=status)

        if ibs_agi.getConfig().getValue("debug"):
            toLog("CallEnd: duration %s used_credit %s"%(duration,used_credit))

    except xmlrpclib.Fault,e:
        logException()
        duration=used_credit=0
예제 #8
0
파일: request.py 프로젝트: sankopay/IBSng
    def __init__(self, asterisk_password=None):
        IBSRequest.__init__(self, "ANONYMOUS", "ANONYMOUS", "ANONYMOUS")
        if asterisk_password == None:
            asterisk_password = ibs_agi.getConfig().getValue(
                "asterisk_password")

        self.asterisk_password = asterisk_password
        self.add_session_variables = False
예제 #9
0
파일: request.py 프로젝트: sankopay/IBSng
    def send(self, method_name, **kargs):
        server = xmlrpclib.ServerProxy(
            "http://%s:%s" % ibs_agi.getConfig().getValue("IBSng_server"))
        kargs["auth_type"] = self.auth_type
        kargs["auth_name"] = self.auth_name
        kargs["auth_pass"] = self.auth_pass

        return getattr(server, method_name)(kargs)
예제 #10
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)
예제 #11
0
파일: greeting.py 프로젝트: sankopay/IBSng
def sayUserGreeting():
    """
        say user greeting if available
        return True if greeting was not available for user
        return False if greeting was played
    """
    if ibs_agi.getConfig().getValue("authenticated"):
        filename = "%s%s" % (ibs_agi.getConfig().getValue(
            "user_greetings_root"), ibs_agi.getConfig().getValue("username"))
        try:
            os.stat("%s.gsm" % filename)
        except OSError:
            return True
        else:
            ibs_agi.getAGI().stream_file(filename, ibs_agi.ALL_ESCAPE)
            return False

    return True
예제 #12
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
예제 #13
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)
예제 #14
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
예제 #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
예제 #16
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
예제 #17
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
예제 #18
0
def setSessionVariables():
    caller_id = filter_caller_id_match.sub(
        "",
        ibs_agi.getAGI().env["agi_callerid"])
    ibs_agi.getConfig().setValue("caller_id", caller_id)
    ibs_agi.getConfig().setValue("unique_id",
                                 ibs_agi.getAGI().env["agi_uniqueid"])
    ibs_agi.getConfig().setValue("channel",
                                 ibs_agi.getAGI().env["agi_channel"])
예제 #19
0
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 
예제 #20
0
    def gotoState(self, state_name, *args):
        """     
            change state to state_name, passing args to new state method
            after state method returns, last state will be recovered
        """
        if ibs_agi.getConfig().getValue("debug"):
            toLog("StateMachine: Going to state %s %s" % (state_name, args))

        last_state = self.cur_state
        self.cur_state = state_name
        try:
            ret_val = apply(self.__getState(state_name), args)
        except KeyError:
            toLog("StateMachine: State %s not found" % state_name)
            ret_val == None

        self.cur_state = last_state
        return ret_val
예제 #21
0
파일: main.py 프로젝트: sankopay/IBSng
def main():
    ibs_agi.getStateMachine().gotoState("SET_SESSION_VARIABLES")
    credit=ibs_agi.getStateMachine().gotoState("CALLERID_AUTHENTICATE")
    ibs_agi.getStateMachine().gotoState("GREETING")
    ibs_agi.getStateMachine().gotoState("CHOOSE_LANGUAGE")
    if not ibs_agi.getConfig().getValue("authenticated"):
        credit=ibs_agi.getStateMachine().gotoState("USER_PASS_AUTHENTICATE")
    
    ibs_agi.getStateMachine().gotoState("SAY_REMAINING_CREDIT",credit)
    
    
    while True:
        destination=ibs_agi.getStateMachine().gotoState("GET_DESTINATION")
        if destination=="*":
            ibs_agi.getStateMachine().gotoState("MENU")
        elif destination=="":
            ibs_agi.getStateMachine().gotoState("GOODBYE_HANGUP")
        else:
            ibs_agi.getStateMachine().gotoState("DIAL",destination)     
예제 #22
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
예제 #23
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)
예제 #24
0
def toLog(_str): 
    if "logger" not in globals():
        global logger
        logger=Logger(ibs_agi.getConfig().getValue("log_file"))
    logger.write("%s:%s"%(ibs_agi.getConfig().getValue("username"),_str))
예제 #25
0
 def _getLanguageRoot(self):
     return "%s%s/" % (ibs_agi.getConfig().getValue("sounds_root"),
                       self.getLanguageCode())
예제 #26
0
 def __init__(self):
     self.languages=[]
     self.requested_languages=ibs_agi.getConfig().getValue("requested_languages")
     self.__initLanguages()
예제 #27
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)
예제 #28
0
    ibs_agi.getStateMachine().registerState("AUTHORIZE", authorize)


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)

    else:
        ibs_agi.getConfig().setValue("authorized", True)

        if ibs_agi.getConfig().getValue("debug"):
            toLog("Aurhorize: RemainingTime: %s" % remaining_time)

    return remaining_time
예제 #29
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
예제 #30
0
 def getSelectedLanguage(self):
     return self.getLanguage(ibs_agi.getConfig().getValue("language"))