Esempio n. 1
0
def index():
    results_per_page = 20

    provider = Provider()
    zones = provider.dns_zones()
    tags = provider.tags()

    search = request.args.get('search', '').strip()
    search_tags = request.args.getlist('tags')

    page = int(request.args.get('page', 1))
    if page <= 0:
        page = 1

    user_id = None if current_user.admin else current_user.id

    page_url = 'tags=' + '&tags='.join(search_tags)
    page_url += "&search={0}&page=".format(search)

    return render_template('dns/zones/index.html',
                           zones=zones.get_user_zones_paginated(
                               user_id,
                               order_by='domain',
                               page=page,
                               per_page=results_per_page,
                               search=search,
                               tags=search_tags),
                           page=page,
                           per_page=results_per_page,
                           page_url=page_url,
                           search=search,
                           search_tags=search_tags,
                           tags=tags.all(user_id=user_id,
                                         order_by='asc',
                                         order_column='name'))
Esempio n. 2
0
def zone_edit(dns_zone_id):
    provider = Provider()
    zones = provider.dns_zones()
    tags = provider.tags()

    zone = None
    dns_zone_id = 0 if dns_zone_id < 0 else dns_zone_id
    if dns_zone_id > 0:
        if not zones.can_access(dns_zone_id, current_user.id):
            flash('Access Denied', 'error')
            return redirect(url_for('home.index'))

        zone = zones.get(dns_zone_id)
        if not zone:
            flash('Zone not found', 'error')
            return redirect(url_for('home.index'))

    username = current_user.username if zone is None else zone.username

    user_id = zone.user_id if dns_zone_id > 0 else current_user.id

    return render_template('dns/zones/edit.html',
                           dns_zone_id=dns_zone_id,
                           user_domain=zones.get_user_base_domain(username),
                           zone=zone,
                           tags=tags.all(user_id=user_id,
                                         order_column='name',
                                         order_by='asc'))
Esempio n. 3
0
def tags_index():
    provider = Provider()
    tags = provider.tags()

    user_id = None if current_user.admin else current_user.id

    return render_template('dns/tags/index.html',
                           tags=tags.all(user_id=user_id,
                                         order_column='name',
                                         order_by='asc'))
Esempio n. 4
0
def tags_edit(tag_id):
    provider = Provider()
    tags = provider.tags()

    user_id = None if current_user.admin else current_user.id
    if tag_id > 0:
        if not tags.can_access(tag_id, user_id):
            flash('You cannot access the selected tag', 'error')
            return redirect(url_for('dns.tags_index'))

        tag = tags.get(tag_id, user_id=user_id)
    else:
        tag = None

    return render_template('dns/tags/edit.html', tag_id=tag_id, tag=tag)
Esempio n. 5
0
def tags_delete(tag_id):
    provider = Provider()
    zones = provider.dns_zones()
    tags = provider.tags()

    user_id = None if current_user.admin else current_user.id
    if not tags.can_access(tag_id, user_id):
        flash('You cannot access the selected tag', 'error')
        return redirect(url_for('dns.tags_index'))

    zones.tag_delete(tag_id)

    if not tags.delete(tag_id, user_id=user_id):
        flash('Could not delete tag', 'error')
        return redirect(url_for('dns.tags_index'))

    flash('Tag deleted', 'success')
    return redirect(url_for('dns.tags_index'))
Esempio n. 6
0
def tags_edit_save(tag_id):
    provider = Provider()
    tags = provider.tags()

    name = request.form['name'].strip().lower()
    if len(name) == 0:
        flash('Please enter a tag name', 'error')
        return redirect(url_for('dns.tags_index'))

    user_id = None if current_user.admin else current_user.id
    if tag_id > 0:
        if not tags.can_access(tag_id, user_id):
            flash('You cannot access the selected tag', 'error')
            return redirect(url_for('dns.tags_index'))

        tag = tags.update(tag_id, name)
    else:
        tag = tags.save(current_user.id, name)

    flash('Tag Created' if tag_id == 0 else 'Tag Updated', 'success')
    return redirect(url_for('dns.tags_index'))