Beispiel #1
0
    def __init__(self, configfile, daemon=False,
                    pidfile='/tmp/plivo_outbound.pid'):
        self._config = helpers.get_config(configfile)
        self._handler_mode = helpers.get_conf_value(self._config,
                                    'freeswitch', 'FS_OUTBOUND_HANDLER')

        if self._handler_mode == 'thread':
            self.server = PlivoThreadOutboundServer(self._config,
                                        daemon, pidfile)
        elif self._handler_mode == 'process':
            self.server = PlivoProcessOutboundServer(self._config,
                                        daemon, pidfile)
        else:
            self.server = PlivoSpawnOutboundServer(self._config,
                                        daemon, pidfile)
Beispiel #2
0
    def __init__(self, configfile, daemon=False,
                    pidfile='/tmp/plivo_outbound.pid'):
        self._request_id = 0
        self._daemon = daemon
        self._run = False
        self._pidfile = pidfile
        # load config
        self._config = helpers.get_config(configfile)
        # set trace flag
        self._trace = helpers.get_conf_value(self._config,
                            'freeswitch', 'FS_OUTBOUND_TRACE') == 'true'
        # create logger
        self.create_logger()
        # create outbound server
        self.fs_outbound_address = helpers.get_conf_value(self._config,
                                        'freeswitch', 'FS_OUTBOUND_ADDRESS')
        fs_host, fs_port = self.fs_outbound_address.split(':', 1)
        fs_port = int(fs_port)
        self.default_answer_url = helpers.get_conf_value(self._config,
                                        'freeswitch', 'DEFAULT_ANSWER_URL')
        self.auth_id = helpers.get_conf_value(self._config,
                                        'rest_server', 'AUTH_ID')
        self.auth_token = helpers.get_conf_value(self._config,
                                        'rest_server', 'AUTH_TOKEN')
        self.default_hangup_url = helpers.get_conf_value(self._config,
                                        'freeswitch', 'DEFAULT_HANGUP_URL')
        self.default_http_method = helpers.get_conf_value(self._config,
                                        'rest_server', 'DEFAULT_HTTP_METHOD')
        if not self.default_http_method in ('GET', 'POST'):
            self.default_http_method = 'POST'

        self.extra_fs_vars = helpers.get_conf_value(self._config,
                                            'freeswitch', 'EXTRA_FS_VARS')

        # This is where we define the connection with the
        # Plivo XML element Processor
        outboundsocket.OutboundServer.__init__(self, (fs_host, fs_port),
                                PlivoOutboundEventSocket, filter=None)
Beispiel #3
0
 def __init__(self, configfile, daemon=False, pidfile="/tmp/plivo_outbound.pid", filter=None):
     self._request_id = 0
     self._daemon = daemon
     self._run = False
     self._pidfile = pidfile
     # load config
     self._config = helpers.get_config(configfile)
     # create logger
     self.create_logger()
     # create outbound server
     self.fs_outbound_address = helpers.get_conf_value(self._config, "freeswitch", "FS_OUTBOUND_ADDRESS")
     fs_host, fs_port = self.fs_outbound_address.split(":", 1)
     fs_port = int(fs_port)
     self.default_answer_url = helpers.get_conf_value(self._config, "freeswitch", "DEFAULT_ANSWER_URL")
     self.auth_id = helpers.get_conf_value(self._config, "rest_server", "AUTH_ID")
     self.auth_token = helpers.get_conf_value(self._config, "rest_server", "AUTH_TOKEN")
     self.default_hangup_url = helpers.get_conf_value(self._config, "freeswitch", "DEFAULT_HANGUP_URL")
     # default hangup_url is answer_url
     if not self.default_hangup_url:
         self.default_hangup_url = self.default_answer_url
     # This is where we define the connection with the
     # Plivo XML grammar Processor
     OutboundServer.__init__(self, (fs_host, fs_port), PlivoOutboundEventSocket, filter)
Beispiel #4
0
    def __init__(self, configfile, daemon=False,
                        pidfile='/tmp/plivo_rest.pid'):
        """Constructor

        Initialize main properties such as daemon, pidfile, config, etc...

        This will init the http server that will provide the Rest interface,
        the rest server is configured on HTTP_ADDRESS

        Extra:
        * FS_INBOUND_ADDRESS : Define the event_socket interface to connect to
        in order to initialize CallSession with Freeswitch

        * FS_OUTBOUND_ADDRESS : Define where on which address listen to
        initialize event_socket session with Freeswitch in order to control
        new CallSession

        """
        self._daemon = daemon
        self._run = False
        self._pidfile = pidfile
        # load config
        self._config = helpers.get_config(configfile)
        # create flask app
        self.app = Flask(self.name)
        self.app.secret_key = helpers.get_conf_value(self._config,
                                                'rest_server', 'SECRET_KEY')
        self.app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024
        # create logger
        self.create_logger()
        # create rest server
        self.fs_inbound_address = helpers.get_conf_value(self._config,
                                        'freeswitch', 'FS_INBOUND_ADDRESS')
        fs_host, fs_port = self.fs_inbound_address.split(':', 1)
        fs_port = int(fs_port)
        fs_password = helpers.get_conf_value(self._config,
                                                'freeswitch', 'FS_PASSWORD')
        # get auth id and auth token
        self.auth_id = helpers.get_conf_value(self._config,
                                        'rest_server', 'AUTH_ID')
        self.auth_token = helpers.get_conf_value(self._config,
                                        'rest_server', 'AUTH_TOKEN')
        # get outbound socket host/port
        fs_out_address = helpers.get_conf_value(self._config,
                                        'freeswitch', 'FS_OUTBOUND_ADDRESS')
        fs_out_host, fs_out_port  = fs_out_address.split(':', 1)
        # if outbound host is 0.0.0.0, send to 127.0.0.1
        if fs_out_host == '0.0.0.0':
            fs_out_address = '127.0.0.1:%s' % fs_out_port
        # create inbound socket instance
        self._rest_inbound_socket = RESTInboundSocket(fs_host, fs_port,
                                                    fs_password, 
                                                    outbound_address=fs_out_address,
                                                    auth_id=self.auth_id,
                                                    auth_token=self.auth_token,
                                                    filter='ALL',
                                                    log=self.log)
        # expose api functions to flask app
        for path, func_desc in urls.URLS.iteritems():
            func, methods = func_desc
            fn = getattr(self, func.__name__)
            self.app.add_url_rule(path, func.__name__, fn, methods=methods)
        # create wsgi server
        self.http_address = helpers.get_conf_value(self._config,
                                            'rest_server', 'HTTP_ADDRESS')
        http_host, http_port = self.http_address.split(':', 1)
        http_port = int(http_port)
        self.http_server = WSGIServer((http_host, http_port),
                                       self.app, log=self.log)