Ejemplo n.º 1
0
def create_record():
    if request.method == 'GET':
        sub_domains = Domain.get_all()
        return render_template('create_record.html', sub_domains=sub_domains)

    name = request.form.get('name', default='').strip()
    subname = request.form.get('subname', default='').strip()
    host_or_ip = request.form.get('host', default='').strip()
    comment = request.form.get('comment', default='').strip()

    if len(name) < 5 and not g.user.is_admin():
        flash(u'域名长度必须大于5', 'error')
        return redirect(url_for('record.create_record'))
    if '.' in name:
        flash(u'域名不能包含"."', 'error')
        return redirect(url_for('record.create_record'))
    if not Domain.get_by_name(subname):
        flash(u'不正确的子域名', 'error')
        return redirect(url_for('record.create_record'))
    domain = '%s.%s' % (name, subname)

    r = Record.get_by_domain(domain)
    if r:
        if r.can_do(g.user):
            flash(u'域名已经存在, 可以编辑', 'info')
            return redirect(url_for('record.edit_record', record_id=r.id))
        abort(403)

    r = Record.create(g.user, name, domain, host_or_ip, comment)
    if not r:
        flash(u'创建失败', 'error')
        return redirect(url_for('record.create_record'))
    return redirect(url_for('record.get_record', record_id=r.id))
Ejemplo n.º 2
0
def create_domain():
    if request.method == 'GET':
        return render_template('create_domain.html')

    domain = request.form.get('domain').strip()
    d = Domain.get_by_name(domain)
    if d:
        flash(u'Domain already exist.', 'info')
        return redirect(url_for('admin.create_domain'))

    d = Domain.create(domain)
    if not d:
        flash(u'创建失败', 'error')
        return redirect(url_for('admin.create_domain'))
    return redirect(url_for('admin.domain_show'))
Ejemplo n.º 3
0
Archivo: api.py Proyecto: CMGS/argonath
def create_record():
    name = request.form.get('name', default='').strip()
    host_or_ip = request.form.get('host', default='').strip()
    comment = request.form.get('comment', default='').strip()

    # 给跪了, 不是admin就判断subname什么的
    if not g.user.is_admin():
        subname = request.form.get('subname', default='').strip()
        if len(name) < 5 and not g.user.is_admin():
            abort(400, u'域名长度必须大于5')
        if '.' in name:
            abort(400, u'域名不能包含"."')
        if not Domain.get_by_name(subname):
            abort(400, u'不正确的子域名')
        domain = '%s.%s' % (name, subname)
    # 是admin就很暴力了...
    # 可以随便传域名的哦...
    else:
        if name.startswith('.') or name.endswith('.'):
            abort(400, u'域名不能以"."开始或者结束, 并不是dnspod啊  ( ̄▽ ̄")')
        domain = name

    r = Record.get_by_domain(domain)
    if r:
        abort(400, u'记录已经存在, 你可以尝试编辑')

    r = Record.create(g.user, name, domain, host_or_ip, comment)
    if not r:
        abort(400, u'创建失败, 别问我为什么是400... o( ̄ヘ ̄*o)')
    return {'r': 0, 'message': 'ok', 'data': r}
Ejemplo n.º 4
0
def delete_domain(id):
    d = Domain.get(id)
    if not d:
        abort(404)
    d.delete()
    return redirect(url_for('admin.domain_show'))
Ejemplo n.º 5
0
def domain_show():
    domains, total = Domain.list_domains()
    return render_template('list_domains.html', domains=domains, total=total, endpoint='admin.domain_show')