Esempio n. 1
0
def deleteDomains():

    # use a whitelist to avoid possible buffer overflow vulns or crashes
    VALID_REQUEST_DATA_ARGS = {"domain_id": str, "config_id": int}

    # ensure requred args are provided
    REQUIRED_ARGS = {'domain_id', 'config_id'}

    # defaults.. keep data returned separate from returned metadata
    response_payload = {
        'error': '',
        'msg': '',
        'kamreload': globals.reload_required,
        'data': []
    }

    try:
        if (settings.DEBUG):
            debugEndpoint()

        # get request data
        data = getRequestData()

        # sanity checks
        for k, v in data.items():
            if k not in VALID_REQUEST_DATA_ARGS.keys():
                raise http_exceptions.BadRequest(
                    "Request data argument '{}' not recognized".format(k))
            if not type(v) == VALID_REQUEST_DATA_ARGS[k]:
                raise http_exceptions.BadRequest(
                    "Request data argument '{}' not valid".format(k))

        for k in REQUIRED_ARGS:
            if k not in VALID_REQUEST_DATA_ARGS.keys():
                raise http_exceptions.BadRequest(
                    "Request argument '{}' is required".format(k))

        config_id = data['config_id']
        domain_id = data['domain_id']

        # Create instance of Media Server Class
        if config_id != None:
            config_info = config(config_id)
            plugin = config_info.getPlugin()
            # Create instance of Media Server Class
            if plugin:
                mediaserver = plugin.mediaserver(config_info)
                if mediaserver:
                    domains = plugin.domains(mediaserver)
                    # Delete the domain
                    if domains.delete(domain_id):
                        response_payload['msg'] = "Success"

        return jsonify(response_payload), StatusCodes.HTTP_OK

    except Exception as ex:
        return showApiError(ex)
Esempio n. 2
0
def getExtensions(config_id=None, domain_id=None, extension_id=None):
    """
    List all of the domains on a PBX\n
    If the PBX only contains a single domain then it will return the hostname or ip address of the system.
    If the PBX is multi-tenant then a list of all domains will be returned

    ===============
    Request Payload
    ===============

    .. code-block:: json


    {}

    ================
    Response Payload
    ================

    .. code-block:: json
    {
         "data": [
        [
            {
                "call_timeout": null,
                "domain_uuid": "51f66016-c2d5-4bd8-8117-29c8fc8ffa17",
                "enabled": "true",
                "extensions_id": "ae3cb4b8-f467-4a13-9bb8-9296226c1887",
                "number": "504",
                "user_context": "restaurant.detroitpbx.com"
            }
        ]
    }
    """

    # Determine which plug-in to use
    # Currently we only support FusionPBX
    # Check if Configuration ID exists

    response_payload = {
        'error': '',
        'msg': '',
        'kamreload': globals.reload_required,
        'data': []
    }

    try:
        if settings.DEBUG:
            debugEndpoint()

        if config_id != None and domain_id != None:
            config_info = config(config_id)
            plugin = config_info.getPlugin()
            # Create instance of Media Server Class
            if plugin:
                mediaserver = plugin.mediaserver(config_info)
                if mediaserver:
                    domains = plugin.domains(mediaserver)
                    domain = domains.read(domain_id)
                    extensions = plugin.extensions(mediaserver, domain[0])
                    extension_list = extensions.read(extension_id)
                    response_payload[
                        'msg'] = '{} extensions were found'.format(
                            len(extension_list))
                    response_payload['data'].append(extension_list)
        else:
            raise Exception(
                "The configuration id and the domain_id must be provided")

        return jsonify(response_payload), StatusCodes.HTTP_OK

    except Exception as ex:
        return showApiError(ex)
Esempio n. 3
0
def putExtensions():

    # use a whitelist to avoid possible buffer overflow vulns or crashes
    VALID_REQUEST_DATA_ARGS = {"domain_id": str, "account_code": str, "extension": str, "password": str, \
                              "outbound_caller_number": str, "outbound_caller_name": str, "vm_enabled": bool, \
                              "vm_password": int, "vm_notify_email": str, "enabled": bool, "call_timeout": int, \
                              "config_id": int}

    # ensure requred args are provided
    REQUIRED_ARGS = {
        'domain_id', 'extension', 'password', 'enabled', 'config_id'
    }

    # defaults.. keep data returned separate from returned metadata
    response_payload = {
        'error': '',
        'msg': '',
        'kamreload': globals.reload_required,
        'data': []
    }

    try:
        if (settings.DEBUG):
            debugEndpoint()

        # get request data
        data = getRequestData()
        print(data)

        # sanity checks
        for k, v in data.items():
            if k not in VALID_REQUEST_DATA_ARGS.keys():
                raise http_exceptions.BadRequest(
                    "Request data argument '{}' not recognized".format(k))
            if not type(v) == VALID_REQUEST_DATA_ARGS[k]:
                raise http_exceptions.BadRequest(
                    "Request data argument '{}' not valid".format(k))

        for k in REQUIRED_ARGS:
            if k not in VALID_REQUEST_DATA_ARGS.keys():
                raise http_exceptions.BadRequest(
                    "Request argument '{}' is required".format(k))

        # Create instance of Media Server Class
        config_id = data['config_id']
        domain_id = data['domain_id']

        if config_id != None and domain_id != None:
            config_info = config(config_id)
            plugin = config_info.getPlugin()
            # Create instance of Media Server Class
            if plugin:
                mediaserver = plugin.mediaserver(config_info)
                if mediaserver:
                    domains = plugin.domains(mediaserver)
                    domain = domains.read(domain_id)
                    print(domain_id)
                    print(domain[0]['domain_id'])
                    extensions = plugin.extensions(mediaserver, domain[0])
                    extensions.update(data)

        return jsonify(response_payload), StatusCodes.HTTP_OK

    except Exception as ex:
        return showApiError(ex)
Esempio n. 4
0
def postDomains():

    # use a whitelist to avoid possible buffer overflow vulns or crashes
    VALID_REQUEST_DATA_ARGS = {
        "name": str,
        "enabled": bool,
        "description": str,
        "config_id": int,
        "cos": str,
        "settings": dict
    }

    # ensure requred args are provided
    REQUIRED_ARGS = {'name', 'config_id'}

    # defaults.. keep data returned separate from returned metadata
    response_payload = {
        'error': '',
        'msg': '',
        'kamreload': globals.reload_required,
        'data': []
    }

    try:
        if (settings.DEBUG):
            debugEndpoint()

        # get request data
        data = getRequestData()

        # sanity checks
        for k, v in data.items():
            if k not in VALID_REQUEST_DATA_ARGS.keys():
                raise http_exceptions.BadRequest(
                    "Request data argument '{}' not recognized".format(k))
            if not type(v) == VALID_REQUEST_DATA_ARGS[k]:
                raise http_exceptions.BadRequest(
                    "Request data argument '{}' not valid".format(k))

        for k in REQUIRED_ARGS:
            if k not in VALID_REQUEST_DATA_ARGS.keys():
                raise http_exceptions.BadRequest(
                    "Request argument '{}' is required".format(k))

        config_id = data['config_id']
        cos = data['cos'] if 'cos' in data else None
        domain_settings = data['settings'] if 'settings' in data else None

        # Create instance of Media Server Class
        if config_id != None:
            config_info = config(config_id)
            plugin = config_info.getPlugin()
            # Create instance of Media Server Class
            if plugin:
                mediaserver = plugin.mediaserver(config_info)
                if mediaserver:
                    domains = plugin.domains(mediaserver)
                    domain = domains.create(data)
                    #Generate Close of Service
                    if cos:
                        cos_object = plugin.cos(domain, data)
                        cos_object.create(cos)
                    if domain_settings:
                        cos_object.create("domain_settings")

                    response_payload['data'] = {"domain_id": domain.domain_id}

        return jsonify(response_payload), StatusCodes.HTTP_OK

    except Exception as ex:
        return showApiError(ex)
Esempio n. 5
0
def getDomains(config_id=None, domain_id=None):
    """
    List all of the domains on a PBX\n
    If the PBX only contains a single domain then it will return the hostname or ip address of the system.
    If the PBX is multi-tenant then a list of all domains will be returned

    ===============
    Request Payload
    ===============

    .. code-block:: json


    {}

    ================
    Response Payload
    ================

    .. code-block:: json

        {
            error: <string>,
            msg: <string>,
            kamreload: <bool>,
            data: [
                domains: [
                    {
                    domain_id: <int>,
                    name: <string>,
                    enabled: <string>,
                    description: <string>
                    }
                ]
            ]
        }
    """

    # Determine which plug-in to use
    # Currently we only support FusionPBX
    # Check if Configuration ID exists

    response_payload = {
        'error': '',
        'msg': '',
        'kamreload': globals.reload_required,
        'data': []
    }

    try:
        if settings.DEBUG:
            debugEndpoint()

        if config_id != None:
            config_info = config(config_id)
            plugin = config_info.getPlugin()
            # Create instance of Media Server Class
            if plugin:
                mediaserver = plugin.mediaserver(config_info)
                if mediaserver:
                    domains = plugin.domains(mediaserver)
                    # Use plugin to get list of domains by calling plugin.<pbxtype>.getDomain()
                    domain_list = domains.read(domain_id)
                    response_payload['msg'] = '{} domains were found'.format(
                        len(domain_list))
                    response_payload['data'].append(domain_list)
        else:
            raise Exception("The configuration id must be provided")

        return jsonify(response_payload), StatusCodes.HTTP_OK

    except Exception as ex:
        return showApiError(ex)