示例#1
0
def fssocket(reqdata):
    result = True
    try:
        commands = reqdata.get('commands')
        requestid = reqdata.get('requestid')
        fs = greenswitch.InboundESL(host=ESL_HOST,
                                    port=ESL_PORT,
                                    password=ESL_SECRET)
        fs.connect()
        for command in commands:
            response = fs.send(f'api {command}')
            if response:
                resultstr = response.data
                if '+OK' in resultstr[:3].upper():
                    _result = True
                else:
                    _result = False
                    logify(
                        f"module=liberator, space=bases, action=fssocket, requestid={requestid}, command={command}, result={resultstr}"
                    )
                result = bool(result and _result)
        logify(
            f"module=liberator, space=bases, action=fssocket, requestid={requestid}, commands={commands}, result={result}"
        )
    except Exception as e:
        logify(
            f"module=liberator, space=bases, action=fssocket, reqdata={reqdata}, exception={e}, tracings={traceback.format_exc()}"
        )
    finally:
        return result
示例#2
0
    def dial(self):
        dsb = 'sofia/internal/9'
        termination_gw = 'vgw.xoip.biz'
        intouch_fs_gw = '85.90.246.57'
        intouch_fs_gw_pwd = 'xHD192ESp'

        self.uuid = str(uuid4())

        calltout = self._get_call_duration()

        data = {
            'uuid': self.uuid,
            'caller': self.caller[1:],
            'callee': self.callee[1:],
            'voipgw': termination_gw,
            'dialstringbase': dsb,
            'origcrcid': self.orig_caller_cid,
            'origcecid': self.orig_callee_cid,
            'calltimeout': calltout
        }

        #af = '+OK Job-UUID: 8e44c73c-3c52-4573-b2a0-cc938678ee3d'

        try:
            fs = greenswitch.InboundESL(host=intouch_fs_gw,
                                        port=8021,
                                        password=intouch_fs_gw_pwd)
            fs.connect()
            command = 'bgapi luarun callup.lua {uuid} {dialstringbase}{caller}@{voipgw} {dialstringbase}{callee}@{voipgw} {origcrcid} {origcecid} {calltimeout}'.format(
                **data)

            print(command)

            r = fs.send(command)

            if r.data[0:3] == '+OK':
                jobuuid = r.data.split(':')[1].strip()
                return jobuuid
            else:
                raise FailedDialOutError()
        except AttributeError:
            print("Something happened")
示例#3
0
def fssocket(reqdata):
    result, fs = True, None
    try:
        commands = reqdata.get('commands')
        requestid = reqdata.get('requestid')
        defer = reqdata.get('defer')
        if defer: time.sleep(defer)
        # connecting
        fs = greenswitch.InboundESL(host=ESL_HOST,
                                    port=ESL_PORT,
                                    password=ESL_SECRET)
        for _ in range(0, 9):
            try:
                fs.connect()
                if fs.connected: break
            except:
                time.sleep(5)
        # send api commands
        if commands and fs.connected:
            for command in commands:
                response = fs.send(f'api {command}')
                if response:
                    resultstr = response.data
                    if '+OK' in resultstr or 'Success' in resultstr or '+ok' in resultstr:
                        _result = True
                    else:
                        _result = False
                        logify(
                            f"module=liberator, space=basemgr, action=fssocket, requestid={requestid}, command={command}, result={resultstr}"
                        )
                    result = bool(result and _result)
        logify(
            f"module=liberator, space=basemgr, action=fssocket, connected={fs.connected}, requestid={requestid}, commands={commands}, result={result}"
        )
    except Exception as e:
        logify(
            f"module=liberator, space=basemgr, action=fssocket, reqdata={reqdata}, exception={e}, tracings={traceback.format_exc()}"
        )
    finally:
        if fs and fs.connected: fs.stop()
        return result
示例#4
0
 def __init__(self):
     self.metrics = []
     parser = argparse.ArgumentParser(
         description='Collect FreeSWITCH Metrics')
     parser.add_argument('--host',
                         metavar='HOST',
                         default='127.0.0.1',
                         help='FreeSWITCH ESL Host')
     parser.add_argument('-p',
                         '--port',
                         metavar='PORT',
                         default=8021,
                         help='FreeSWITCH ESL Port')
     parser.add_argument('-s',
                         '--secret',
                         metavar='PASSWORD',
                         default='ClueCon',
                         help='FreeSWITCH ESL Password')
     args = parser.parse_args()
     self.fs = greenswitch.InboundESL(host=args.host,
                                      port=args.port,
                                      password=args.secret)
     self.fs.connect()
示例#5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function

import logging
import gevent
import greenswitch


def on_sofia_register_failure(event):
    message = 'Failed register attempt from {network-ip} to user {to-user} profile {profile-name}'
    print(message.format(**event.headers))


fs = greenswitch.InboundESL(host='192.168.50.4', port=8021, password='******')
fs.connect()
fs.register_handle('sofia::register_failure', on_sofia_register_failure)
fs.send('EVENTS PLAIN ALL')

print('Connected to FreeSWITCH!')
while True:
    try:
        gevent.sleep(1)
    except KeyboardInterrupt:
        fs.stop()
        break
print('ESL Disconnected.')