Example #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))
Example #2
0
def create():
    if request.method == 'GET':
        return render_template('admin_record_create.html')
    name = request.form.get('name', default='').strip()
    host_or_ip = request.form.get('host', default='').strip()

    if len(name) < 3:
        flash(u'域名长度必须大于3', 'error')
        return redirect(url_for('admin_record.create'))
    if '.' in name:
        flash(u'域名不能包含"."', 'error')
        return redirect(url_for('admin_record.create'))

    domain = '{0}.hunantv.com'.format(name)

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

    r = Record.create(g.user, name, domain, host_or_ip)
    if not r:
        flash(u'创建失败', 'error')
        return redirect(url_for('admin_record.create'))
    return redirect(url_for('record.get_record', record_id=r.id))
Example #3
0
def create_record():
    name = request.form.get('name', default='').strip()
    host_or_ip = request.form.get('host', 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 subname not in sub_domains:
            abort(400, u'不正确的子域名')
        domain = name + '.' + subname + '.hunantv.com'
    # 是admin就很暴力了...
    else:
        if name.startswith('.') or name.endswith('.'):
            abort(400, u'域名不能以"."开始或者结束, 并不是dnspod啊  ( ̄▽ ̄")')
        domain = name + '.hunantv.com'

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

    r = Record.create(g.user, name, domain, host_or_ip)
    if not r:
        abort(400, u'创建失败, 别问我为什么是400... o( ̄ヘ ̄*o)')
    return {'r': 0, 'message': 'ok', 'data': r}
Example #4
0
def create_record():
    if request.method == 'GET':
        return render_template('admin_record.html')

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

    if domain.startswith('.') or domain.endswith('.'):
        flash(u'域名不能以"."开始或者结束, 并不是dnspod啊 ( ̄▽ ̄")', 'error')
        return redirect(url_for('admin.create_record'))

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

    r = Record.create(g.user, domain, domain, host_or_ip, comment)
    if not r:
        flash(u'创建失败', 'error')
        return redirect(url_for('admin.create_record'))

    return redirect(url_for('record.get_record', record_id=r.id))