Example #1
0
 def send_direct(self, to, fromm, body, empty=False):
     """Send a message directly via the BTS addressed using IMSIs"""
     for chunk in chunk_sms(body):
         imsi = to[0]
         ipaddr = to[1]
         port = to[2]
         body = (sms_utilities.SMS_Deliver.gen_msg(
             to, fromm, chunk, empty).upper())
         freeswitch.consoleLog(
             'info', 'Message body is: \'' + str(chunk) + '\'\n')
         event = freeswitch.Event("CUSTOM", "SMS::SEND_MESSAGE")
         event.addHeader("proto", "sip")
         event.addHeader("dest_proto", "sip")
         event.addHeader("from", fromm)
         from_full = ("sip:" + fromm + "@" +
                      freeswitch.getGlobalVariable("domain"))
         event.addHeader("from_full", from_full)
         to_full = str(freeswitch.getGlobalVariable("smqueue_profile") +
                       "/sip:"+ str(imsi) + "@" + ipaddr + ":" + str(port))
         event.addHeader("to", to_full)
         event.addHeader("subject", "SIMPLE_MESSAGE")
         event.addHeader("type", "application/vnd.3gpp.sms")
         event.addHeader("hint", "the hint")
         event.addHeader("replying", "false")
         event.addBody(body)
         event.fire()
Example #2
0
def fsapi(session, stream, env, args):
    res = localize(args)
    if isinstance(session, str):
        # we're in the FS CLI, so no session object
        consoleLog('info', "No session; otherwise would set _localstr=%s" % res)
    else:
        session.execute("set", "_localstr=%s" % res)
def localize(args):
    strkey, params = parse(args)

    # do the localization lookup
    res = freeswitch_strings.localize(strkey, params)
    consoleLog('info', "Localizing %s: %s" % (args, res))
    return res
Example #4
0
def fsapi(session, stream, env, args):
    count, fullgw, current_pos, new_pos, idx = 0, 0, 0, 0, 0
    upgw = []
    upgw_list = file_list(file_path)
    for gw in range(len(upgw_list)):
        if re.search(
                r"State\s+REGED\s+",
                api.executeString("sofia status gateway " + upgw_list[gw])):
            upgw.append(upgw_list[gw])
            count = count + 1
    db_exists()
    current_pos = db_select()
    if int(current_pos) >= count:
        current_pos = 0
    new_pos = int(current_pos) + 1
    idx = int(current_pos)
    db_insert(new_pos)
    info = api.executeString("show channels")
    while 0 < 1:
        if re.search("sofia/gateway/" + upgw[idx], info):
            idx = idx + 1
            if int(current_pos) >= count:
                idx = 0
            if idx >= count:
                break
        else:
            stream.write(str(upgw[idx]))
            freeswitch.consoleLog(
                "info", "Discovery of available gateway: %s\n" % upgw[idx])
            break
Example #5
0
def chat(message, imsi):
    """Handle chat requests.

    Args:
      imsi: a subscriber's IMSI
    """
    port = str(subscriber.get_port(imsi))
    consoleLog('info', "Returned Chat: " + port + "\n")
    message.chat_execute('set', '_openbts_ret=%s' % port)
def fsapi(session, stream, env, arg):
    """
    Args: string of amount

    Does not return anything, but writes to output the value of the formatted
    currency amount"""
    resp = humanize_credits(int(arg))
    consoleLog('info', "endaga_currency FSAPI %s -> %s" % (arg, resp))
    stream.write(str(resp))
def fsapi(session, stream, env, imsi):
    """Handle FS API requests.

    Args:
      imsi: a subscriber's IMSI
    """
    ip_address = str(subscriber.get_ip(imsi))
    consoleLog('info', "Returned FSAPI: " + ip_address + "\n")
    stream.write(ip_address)
def chat(message, imsi):
    """Handle chat requests.

    Args:
      imsi: a subscriber's IMSI
    """
    ip_address = str(subscriber.get_ip(imsi))
    consoleLog('info', "Returned Chat: " + ip_address + "\n")
    message.chat_execute('set', '_openbts_ret=%s' % ip_address)
Example #9
0
def chat(message, number):
    """Handle chat requests.

    Args:
      number: the number you want canonicalized
    """
    canon = nu.canonicalize(number)
    consoleLog('info', "Returned Chat: " + canon + "\n")
    message.chat_execute('set', '_openbts_ret=%s' % canon)
Example #10
0
def fsapi(session, stream, env, number):
    """Handle FS API requests.

    Args:
      number: the number you want canonicalized
    """
    canon = nu.canonicalize(number)
    consoleLog('info', "Returned FSAPI: " + canon + "\n")
    stream.write(canon)
Example #11
0
def fsapi(session, stream, env, imsi):
    """Handle FS API requests.

    Args:
      imsi: a subscriber's IMSI
    """
    port = str(subscriber.get_port(imsi))
    consoleLog('info', "Returned FSAPI: " + port + "\n")
    stream.write(port)
Example #12
0
def handler(session, args):
    freeswitch.consoleLog("crit", "Handling IVR")
    session.setHangupHook(hangup_hook)

    record_message(session)

    session.hangup()
    freeswitch.consoleLog("crit", "Hung up")

    return "true"
def chat(message, arg):
    """
    Arg: string amount

    Does not return anything, but sets the variable "_endaga_ret" to the value
    of the formatted currency string.
    """
    resp = humanize_credits(int(arg))
    consoleLog('info', "endaga_currency Chat %s -> %s" % (arg, resp))
    message.chat_execute('set', '_endaga_ret=%s' % resp)
Example #14
0
def hangup_hook(session, what, args=''):
    """
    Must be explicitly set up with session.setHangupHook(hangup_hook).

    `session` is a session object.
    `what` is "hangup" or "transfer".
    `args` is populated if you pass extra args to session.setInputCallback().

    """
    freeswitch.consoleLog("info", "hangup hook for '%s'\n" % what)
Example #15
0
def chat(message, imsi):
    """Handle chat requests.

    Args:
      imsi: a subscriber's IMSI
    """
    try:
        callerid = str(subscriber.get_caller_id(imsi))
    except SubscriberNotFound:
        callerid = ''
    consoleLog('info', "Returned Chat: " + callerid + "\n")
    message.chat_execute('set', '_openbts_ret=%s' % callerid)
def handler(session, args):
    """Do the CID lookup (against our php service...)."""
    response = urllib2.urlopen("%s?call=%s&format=json" % (CNAM_PHP, session.getVariable("uuid")))
    data = json.load(response)
    if "error" in data:
        freeswitch.consoleLog("error", str(data['error']))
    else:
        for key, value in data.iteritems():
            freeswitch.consoleLog("info", str("%s=%s" % (key, value)))
            session.execute("set", str("%s=%s" % (key, value)))
        if "effective_caller_id_name" in data:
            session.execute("set_profile_var", str("caller_id_name=%s" % data['effective_caller_id_name']))
Example #17
0
def fsapi(session, stream, env, imsi):
    """Handle FS API requests.

    Args:
      imsi: a subscriber's IMSI
    """
    try:
        callerid = str(subscriber.get_caller_id(imsi))
    except SubscriberNotFound:
        callerid = ''
    consoleLog('info', "Returned FSAPI: " + callerid + "\n")
    stream.write(callerid)
def fsapi(session, stream, env, imsi):
    """Handle FS API requests.

    Args:
      imsi: a subscriber's IMSI
    """
    try:
        account_balance = str(subscriber.get_account_balance(imsi))
    except SubscriberNotFound:
        account_balance = ''
    consoleLog('info', "Returned FSAPI: " + account_balance + "\n")
    stream.write(account_balance)
def fsapi(session, stream, env, msisdn):
    """Handle FS API requests.

    Args:
      msisdn: a subscriber's number
    """
    try:
        imsi = str(subscriber.get_imsi_from_number(msisdn, False))
    except SubscriberNotFound:
        imsi = ''
    consoleLog('info', "Returned FSAPI: " + imsi + "\n")
    stream.write(imsi)
def chat(message, imsi):
    """Handle chat requests.

    Args:
      imsi: a subscriber's IMSI
    """
    try:
        account_balance = str(subscriber.get_account_balance(imsi))
    except SubscriberNotFound:
        account_balance = ''
    consoleLog('info', "Returned Chat: " + account_balance + "\n")
    message.chat_execute('set', '_openbts_ret=%s' % account_balance)
def chat(message, msisdn):
    """Handle chat requests.

    Args:
      msisdn: a subscriber's number
    """
    try:
        imsi = str(subscriber.get_imsi_from_number(msisdn, False))
    except SubscriberNotFound:
        imsi = ''
    consoleLog('info', "Returned Chat: " + imsi + "\n")
    message.chat_execute('set', '_openbts_ret=%s' % imsi)
Example #22
0
def fsapi(session, stream, env, username):
    """Handle FS API requests.

    Args:
      username: a sip username in the hlr
    """
    try:
        imsi = str(subscriber.get_imsi_from_username(username))
    except SubscriberNotFound:
        imsi = ''
    consoleLog('info', "Returned FSAPI: " + imsi + "\n")
    stream.write(imsi)
Example #23
0
def chat(message, username):
    """Handle chat requests.

    Args:
      username: a sip username in the HLR
    """
    try:
        imsi = str(subscriber.get_imsi_from_username(username))
    except SubscriberNotFound:
        imsi = ''
    consoleLog('info', "Returned Chat: " + imsi + "\n")
    message.chat_execute('set', '_openbts_ret=%s' % imsi)
def chat(message, args):
    """Handles data from the chatplan.

    Args:
      string of the form <service_type>|<call_or_sms>|<destination_number>
    """
    service_type, call_or_sms, destination_number = args.split('|')
    # Sanitize the destination number.
    destination_number = number_utilities.strip_number(destination_number)
    res = str(billing.get_service_tariff(
        service_type, call_or_sms, destination_number=destination_number))
    consoleLog('info', "Returned Chat: " + res + "\n")
    message.chat_execute('set', 'service_type=%s' % res)
def fsapi(session, stream, env, args):
    """Handles data from the FS API.

    Args:
      string of the form <service_type>|<call_or_sms>|<destination_number>
    """
    service_type, call_or_sms, destination_number = args.split('|')
    # Sanitize the destination number.
    destination_number = number_utilities.strip_number(destination_number)
    res = str(billing.get_service_tariff(
        service_type, call_or_sms, destination_number=destination_number))
    consoleLog('info', "Returned FSAPI: " + res + "\n")
    stream.write(res)
def chat(message, args):
    """Handles data from the chatplan.

    Args:
      string of the form <account_balance>|<service_type>|<destination_number>
    """
    balance, service_type, destination_number = args.split('|')
    # Sanitize the destination number.
    destination_number = number_utilities.strip_number(destination_number)
    res = str(
        billing.get_seconds_available(int(balance), service_type,
                                      destination_number))
    consoleLog('info', "Returned Chat: " + res + "\n")
    message.chat_execute('set', 'service_type=%s' % res)
def fsapi(session, stream, env, args):
    """Handles data from the FS API.

    Args:
      string of the form <account_balance>|<service_type>|<destination_number>
    """
    balance, service_type, destination_number = args.split('|')
    # Sanitize the destination number.
    destination_number = number_utilities.strip_number(destination_number)
    res = str(
        billing.get_seconds_available(int(balance), service_type,
                                      destination_number))
    consoleLog('info', "Returned FSAPI: " + res + "\n")
    stream.write(res)
def fsapi(session, stream, env, imsi):
    """Handle FS API requests.

    Args:
      imsi: a subscriber's number
    """
    try:
        auth = subscriber.is_authed(imsi)
    except Exception:  # handle all failures as no auth
        exc_type, exc_value, _ = sys.exc_info()
        consoleLog('error', "%s: %s\n" % (exc_type, exc_value))
        auth = False
    consoleLog('info', "Returned FSAPI: " + str(auth) + "\n")
    stream.write(str(auth))
def chat(message, imsi):
    """Handle chat requests.

    Args:
      imsi: a subscriber's authorization
    """
    try:
        auth = subscriber.is_authed(imsi)
    except Exception:  # handle all failurs as no auth
        exc_type, exc_value, _ = sys.exc_info()
        consoleLog('error', "%s: %s\n" % (exc_type, exc_value))
        auth = False
    consoleLog('info', "Returned Chat: " + str(auth) + "\n")
    message.chat_execute('set', '_openbts_ret=%s' % auth)
def handler(session, args):
    """Do the CID lookup (against our php service...)."""
    response = urllib2.urlopen("%s?call=%s&format=json" %
                               (CNAM_PHP, session.getVariable("uuid")))
    data = json.load(response)
    if "error" in data:
        freeswitch.consoleLog("error", str(data['error']))
    else:
        for key, value in data.iteritems():
            freeswitch.consoleLog("info", str("%s=%s" % (key, value)))
            session.execute("set", str("%s=%s" % (key, value)))
        if "effective_caller_id_name" in data:
            session.execute(
                "set_profile_var",
                str("caller_id_name=%s" % data['effective_caller_id_name']))
def fsapi(session, stream, env, args):
    """
    Args: string config key

    Does not return anything, but writes to output the value of the config key
    in the ConfigDB if it exists, or to the empty string otherwise.
    """
    cdb = config_database.ConfigDB()
    key = args.strip()
    try:
        res = cdb[key].strip()
    except KeyError:
        res = ""
    consoleLog('info', "ConfigDB FSAPI %s -> %s" % (key, res))
    stream.write(res)
Example #32
0
def chat(message, args):
    freeswitch.consoleLog("info", "SMS in ------------------------------------------>\n")
    freeswitch.consoleLog("info", message.getBody())  
    EDT =  message.getHeader("Event-Date-Timestamp")
    fr = message.getHeader("from")
    to = message.getHeader("to")
    body = message.getBody()
    from_number = body.split('\n')[0]
    body = body.split('\n')[1]             #this may not be necessary, and may break if there is no associated number
    payload={
                'Event-Date-Timestamp'  :EDT,
                'from'                  :fr,
                'to'                    :to,
                'from_number'           :from_number,
                'body'                  :body,
            }            
    data = json.dumps(payload)         
    r = requests.get(TELEPHONY_SERVER_IP, params = payload)
    if not r.status_code==200:
        freeswitch.consoleLog("info","Problem sending....")  
        freeswitch.consoleLog("info", str(r.status_code)+'\n')
        freeswitch.consoleLog("info", str(r.text)+'\n')
        freeswitch.consoleLog("info", str(r.url)+'\n')