Example #1
0
def call_server(server,
                path,
                method,
                data=None,
                params=None,
                to_manager=False):
    """
    Execute an HTTP Request to the server identified by it's name.

    :param str|unicode server: server name
    :param str|unicode path: remote path
    :param dict|None params: query string parameters
    :param bool to_manager: send request to manager instead of daemon
    :return: Returns decoded Server response data
    :rtype: (dict|list)
    """
    server = db.session.query(Server).filter_by(name=server).first()
    if server is None:
        return jsonify(errors={'name': "Not found"}), 404

    url = server.manager_url if to_manager else server.pdns_url
    headers = {}
    if server.api_key:
        headers['X-API-Key'] = server.api_key

    return fetch_json(url + path,
                      method=method,
                      data=data,
                      params=params,
                      headers=headers)
Example #2
0
 def sideload(self, what):
     remote_url = urlparse.urljoin(self.pdns_url,
                                   '/servers/localhost/' + what)
     try:
         return fetch_json(remote_url)
     except:
         return {}
Example #3
0
def call_server(server, path, method, data=None, params=None, to_manager=False):
    """
    Execute an HTTP Request to the server identified by it's name.

    :param str|unicode server: server name
    :param str|unicode path: remote path
    :param dict|None params: query string parameters
    :param bool to_manager: send request to manager instead of daemon
    :return: Returns decoded Server response data
    :rtype: (dict|list)
    """
    server = db.session.query(Server).filter_by(name=server).first()
    if server is None:
        return jsonify(errors={'name': "Not found"}), 404

    url = server.manager_url if to_manager else server.pdns_url
    headers = {}
    if server.api_key:
        headers['X-API-Key'] = server.api_key

    return fetch_json(
        url + path,
        method=method,
        data=data,
        params=params,
        headers=headers
    )
Example #4
0
def server_flushcache(server):
    server = db.session.query(Server).filter_by(name=server).first()
    if server is None:
        return jsonify(errors={'name': "Not found"}), 404

    domain = request.values.get('domain', '')

    remote_url = server.pdns_url
    remote_url += '/jsonstat?command=flush-cache&domain=' + domain

    data = fetch_json(remote_url)

    return jsonify({'domain': domain, 'content': data})
Example #5
0
def server_flushcache(server):
    server = db.session.query(Server).filter_by(name=server).first()
    if server is None:
        return jsonify(errors={'name':"Not found"}), 404

    domain = request.values.get('domain', '')

    remote_url = server.pdns_url
    remote_url += '/jsonstat?command=flush-cache&domain=' + domain

    data = fetch_json(remote_url)

    return jsonify({'domain': domain, 'content': data})
Example #6
0
def server_loggrep(server):
    server = db.session.query(Server).filter_by(name=server).first()
    if server is None:
        return jsonify(errors={'name':"Not found"}), 404

    needle = request.values.get('needle')

    remote_url = server.pdns_url
    remote_url += '/jsonstat?command=log-grep&needle=' + needle

    data = fetch_json(remote_url)

    return jsonify({'needle': needle, 'content': data})
Example #7
0
def server_action(server, action):
    server = db.session.query(Server).filter_by(name=server).first()
    if server is None:
        return jsonify(errors={'name':"Not found"}), 404

    pdns_actions = ['stats', 'config']
    manager_actions = ['start', 'stop', 'restart', 'update', 'install']
    generic_actions = pdns_actions + manager_actions
    if action not in generic_actions:
        return "invalid api action", 404

    if action in manager_actions:
        if request.method != 'POST':
            return "must call action %s using POST" % (action,), 403
        if not Auth.getCurrentUser().has_role('edit'):
            return 'Not authorized', 401

    remote_url = None
    if action in manager_actions:
        target = server.daemon_type
        remote_url = urlparse.urljoin(server.manager_url, '/do/?action='+action+'&target='+target)

    else:
        # pdns actions
        remote_action = action
        if server.daemon_type == 'Authoritative':
            if action == 'stats':
                remote_action = 'get'
            elif action == 'config':
                remote_action = 'config'
        remote_url = urlparse.urljoin(server.pdns_url, '/jsonstat?command=' + remote_action)

    data = fetch_json(remote_url)

    if isinstance(data, list):
        return jsonify({action: data})
    else:
        return jsonify(data)
Example #8
0
 def sideload(self, what):
     remote_url = urlparse.urljoin(self.pdns_url, '/servers/localhost/' + what)
     try:
         return fetch_json(remote_url)
     except:
         return {}