Beispiel #1
0
def record_apply(domain_name):
    """
    example jdata: {u'record_ttl': u'1800', u'record_type': u'CNAME', u'record_name': u'test4', u'record_status': u'Active', u'record_data': u'duykhanh.me'}
    """
    #TODO: filter removed records / name modified records.

    if not current_user.can_access_domain(domain_name):
        return make_response(
            jsonify({
                'status': 'error',
                'msg': 'You do not have access to that domain'
            }), 403)

    try:
        pdata = request.data
        jdata = json.loads(pdata)

        r = Record()
        result = r.apply(domain_name, jdata)
        if result['status'] == 'ok':
            history = History(msg='Apply record changes to domain %s' %
                              domain_name,
                              detail=str(jdata),
                              created_by=current_user.username)
            history.add()
            return make_response(jsonify(result), 200)
        else:
            return make_response(jsonify(result), 400)
    except:
        print traceback.format_exc()
        return make_response(
            jsonify({
                'status': 'error',
                'msg': 'Error when applying new changes'
            }), 500)
Beispiel #2
0
def domain(domain_name):
    r = Record()
    domain = Domain.query.filter(Domain.name == domain_name).first()
    if not domain:
        return redirect(url_for('error', code=404))

    if not current_user.can_access_domain(domain_name):
        abort(403)

    # query domain info from PowerDNS API
    zone_info = r.get_record_data(domain.name)
    if zone_info:
        jrecords = zone_info['records']
    else:
        # can not get any record, API server might be down
        return redirect(url_for('error', code=500))

    records = []
    #TODO: This should be done in the "model" instead of "view"
    if NEW_SCHEMA:
        for jr in jrecords:
            if jr['type'] in app.config['RECORDS_ALLOW_EDIT']:
                for subrecord in jr['records']:
                    record = Record(name=jr['name'], type=jr['type'], status='Disabled' if subrecord['disabled'] else 'Active', ttl=jr['ttl'], data=subrecord['content'])
                    records.append(record)
    else:
        for jr in jrecords:
            if jr['type'] in app.config['RECORDS_ALLOW_EDIT']:
                record = Record(name=jr['name'], type=jr['type'], status='Disabled' if jr['disabled'] else 'Active', ttl=jr['ttl'], data=jr['content'])
                records.append(record)
    if not re.search('ip6\.arpa|in-addr\.arpa$', domain_name):
        editable_records = app.config['RECORDS_ALLOW_EDIT']
    else:
        editable_records = ['PTR']
    return render_template('domain.html', domain=domain, records=records, editable_records=editable_records)
Beispiel #3
0
def domain_dnssec(domain_name):
    if not current_user.can_access_domain(domain_name):
        return make_response(jsonify({'status': 'error', 'msg': 'You do not have access to that domain'}), 403)

    domain = Domain()
    dnssec = domain.get_domain_dnssec(domain_name)
    return make_response(jsonify(dnssec), 200)
Beispiel #4
0
def domain_dnssec_disable(domain_name):
    if not current_user.can_access_domain(domain_name):
        return make_response(
            jsonify({
                'status': 'error',
                'msg': 'You do not have access to that domain'
            }), 403)

    domain = Domain()
    dnssec = domain.get_domain_dnssec(domain_name)

    for key in dnssec['dnssec']:
        response = domain.delete_dnssec_key(domain_name, key['id'])

    return make_response(jsonify({'status': 'ok', 'msg': 'DNSSEC removed.'}))
Beispiel #5
0
def record_update(domain_name):
    """
    This route is used for domain work as Slave Zone only
    Pulling the records update from its Master
    """

    if not current_user.can_access_domain(domain_name):
        return make_response(
            jsonify({
                'status': 'error',
                'msg': 'You do not have access to that domain'
            }), 403)

    try:
        pdata = request.data
        jdata = json.loads(pdata)

        domain_name = jdata['domain']
        d = Domain()
        result = d.update_from_master(domain_name)
        if result['status'] == 'ok':
            return make_response(
                jsonify({
                    'status': 'ok',
                    'msg': result['msg']
                }), 200)
        else:
            return make_response(
                jsonify({
                    'status': 'error',
                    'msg': result['msg']
                }), 500)
    except:
        print traceback.format_exc()
        return make_response(
            jsonify({
                'status': 'error',
                'msg': 'Error when applying new changes'
            }), 500)