Beispiel #1
0
def domain_delete_process(domain):
    domain = get_domain(domain)

    if not domain:
        return redirect(url_for('domain.index'))

    ownership = g.session.query(DomainOwnership)\
                         .filter(DomainOwnership.user == get_user())\
                         .filter(DomainOwnership.domain == domain).first()

    errors = []
    if domain.records:
        errors.append('records')

    if ownership.master:
        subdomain_num = g.session.query(Domain)\
                                 .filter(Domain.parent.contains(domain)).count()
        subdomain_sharing = g.session.query(SubdomainSharing)\
                                     .filter(SubdomainSharing.domain == domain)\
                                     .count()
        if subdomain_num != 0 or subdomain_sharing != 0:
            errors.append('subdomains')

    if errors:
        return render_template('domain_del.html', domain=domain, errors=errors)

    with g.session.begin():
        g.session.delete(ownership)
        g.session.delete(domain)

    return redirect(url_for('domain.index'))
Beispiel #2
0
def subdomain_add(token):
    ticket = g.session.query(SubdomainSharing)\
                      .filter(SubdomainSharing.token.like(token)).first()
    if not ticket:
        return redirect(url_for('domain.index'))

    if ticket.email and ticket.email != get_user().email:
        return redirect(url_for('domain.index'))

    subdomain_name = '%s.%s' % (ticket.name, ticket.domain.name)
    domain = Domain(name=subdomain_name, parent_id=ticket.domain.id)
    ownership = DomainOwnership(master=False, user=get_user(), domain=domain)

    with g.session.begin():
        g.session.add(domain)
        g.session.add(ownership)
        g.session.delete(ticket)
    return redirect(url_for('domain.index'))
Beispiel #3
0
def index():
    tickets = g.session.query(SubdomainSharing)\
                       .filter(SubdomainSharing.email.like(get_user().email))\
                       .all()
    ns_list = g.session.query(NameServer).all()
    return render_template('dashboard.html',
                           ns_list=ns_list,
                           ownership_list=g.user.ownership,
                           subdomain_tickets=tickets)
def ticket_new_process(domain):
    form = SubdomainForm(request.form)
    domain = get_domain(domain, True)

    if not domain:
        return redirect(url_for('domain.index'))

    if not form.validate():
        return render_template('domain_subdomain/new.html',
                               domain=domain,
                               form=form)

    if form.email.data == get_user().email:
        form.email.errors.append('Email error')
        return render_template('domain_subdomain/new.html',
                               domain=domain,
                               form=form)

    ticket_num = g.session.query(SubdomainSharing)\
                          .filter(SubdomainSharing.domain == domain)\
                          .filter(SubdomainSharing.name == form.name.data)\
                          .count()

    if ticket_num:
        form.name.errors.append('Duplicate subdomain.')
        return render_template('domain_subdomain/new.html',
                               domain=domain,
                               form=form)

    domain_num = g.session.query(Domain)\
                  .filter(Domain.name == form.name.data + '.' + domain.name)\
                  .count()

    if domain_num:
        form.name.errors.append('Duplicate subdomain.')
        return render_template('domain_subdomain/new.html',
                               domain=domain,
                               form=form)

    try:
        ticket = SubdomainSharing(domain=domain,
                                  name=form.name.data,
                                  email=form.email.data)

        with g.session.begin():
            g.session.add(ticket)
    except ValueError as e:
        form.name.errors.append(e)
        return render_template('domain_subdomain/new.html',
                               domain=domain,
                               form=form)

    return redirect(
        url_for('domain_subdomain.subdomain_info', domain=domain.name))
Beispiel #5
0
    def define_session():
        g.service_name = 'DNS Forever beta'
        g.session = Session()

        g.user = get_user()
        if g.user:
            g.domain_list = [ownership.domain.name
                             for ownership in g.user.ownership]
        else:
            g.domain_list = []

        g.debug = app.debug
Beispiel #6
0
def subdomain_delete(token):
    ticket = g.session.query(SubdomainSharing)\
                      .filter(SubdomainSharing.token.like(token)).first()
    if not ticket:
        return redirect(url_for('domain.index'))

    if ticket.email and ticket.email != get_user().email:
        return redirect(url_for('domain.index'))

    with g.session.begin():
        g.session.delete(ticket)

    return redirect(url_for('domain.index'))
Beispiel #7
0
    def define_session():
        g.service_name = 'DNS Forever beta'
        g.session = Session()

        g.user = get_user()
        if g.user:
            g.domain_list = [
                ownership.domain.name for ownership in g.user.ownership
            ]
        else:
            g.domain_list = []

        g.debug = app.debug
Beispiel #8
0
def resetpasswd():
    if request.method == 'GET':
        return render_template('resetpasswd.html', form=ResetPasswordForm())

    form = ResetPasswordForm(request.form)

    if not form.validate():
        return render_template('resetpasswd.html', form=form)

    user = get_user()

    if password_hash(form.old_password.data) != user.password:
        form.old_password.errors.append('Please enter the correct password.')
        return render_template('resetpasswd.html', form=form)

    user.password = password_hash(form.new_password.data)

    with g.session.begin():
        g.session.add(user)

    return redirect(url_for('index.index'))
Beispiel #9
0
def resetpasswd():
    if request.method == 'GET':
        return render_template('resetpasswd.html', form=ResetPasswordForm())

    form = ResetPasswordForm(request.form)

    if not form.validate():
        return render_template('resetpasswd.html', form=form)

    user = get_user()

    if password_hash(form.old_password.data) != user.password:
        form.old_password.errors.append('Please enter the correct password.')
        return render_template('resetpasswd.html', form=form)

    user.password = password_hash(form.new_password.data)

    with g.session.begin():
        g.session.add(user)

    return redirect(url_for('index.index'))
Beispiel #10
0
def new_process():
    if 'domain' in request.form:
        domains = request.form['domain'].split()
    else:
        domains = []

    error_domains = []
    for domain in domains:
        try:
            domain = str(domain)
        except:
            error_domains.append(domain)
            continue

        if not DOMAIN_PATTERN.match(domain.lower()):
            error_domains.append(domain)
            continue

        if check_domain_owner(domain) is False:
            error_domains.append(domain)
            continue

        try:
            with g.session.begin():
                domain = Domain(name=domain.lower())
                ownership = DomainOwnership(master=True,
                                            user=get_user(),
                                            domain=domain)
                g.session.add(ownership)
        except:
            error_domains.append(domain)
            continue

    if len(error_domains) > 0:
        return render_template('domain_new.html',
                               error_domains=error_domains,
                               domains=domains)

    return redirect(url_for('domain.index'))