Ejemplo n.º 1
0
def edit(contact_id):
    contact = Contact.query.filter_by(id=contact_id).first_or_404()
    communities_self = Community.query.join(
        Contact,
        Community.contacts
    ).filter_by(id=current_user.id)
    communities_edit = Community.query.join(
        Contact,
        Community.contacts
    ).filter_by(id=contact_id)
    same = False
    for community_self in communities_self:
        for community_edit in communities_edit:
            if community_edit.id == community_self.id:
                community_self.selected = True
                same = True
    if (current_user.admin is False and int(contact_id) != current_user.id) or (
                    current_user.admin is True and same is False):  # noqa
        flash('You don''t have permissions to edit selected contact information')  # noqa
        return redirect(url_for('index'))
    form = FormContact(obj=contact, edit=True)
    form.communities.query = current_user.get_communities()
    if form.validate_on_submit():
        form.populate_obj(contact)
        if form.newpassword is not None:
            contact.set_password(form.newpassword.data)
        db.session.add(contact)
        db.session.commit()
        return redirect(url_for('contacts.list'))
    return render_template('contact/detail.html',
                           contact=contact,
                           communities=communities_self,
                           form=form)
Ejemplo n.º 2
0
def create():
    form = FormNameserver()
    form.community.query = current_user.get_communities()
    form.submit.label.text='Create Nameserver'
    if form.validate_on_submit():
        nameserver = NameServer()
        form.populate_obj(nameserver)
        db.session.add(nameserver)
        db.session.commit()
        flash('Nameserver has been created')
        return redirect(url_for('nameservers.list'))
    return render_template("nameserver/detail.html", form=form, edit=False)
Ejemplo n.º 3
0
def create():
    form = FormContact()
    form.communities.query = current_user.get_communities()
    if form.validate_on_submit():
        contact = Contact()
        form.populate_obj(contact)
        contact.set_password(form.newpassword.data)
        db.session.add(contact)
        db.session.commit()
        flash('Contact has been created')
        return redirect(url_for('contacts.list'))
    return render_template("contact/detail.html", form=form)
Ejemplo n.º 4
0
def create():
    form = CustomerEdgeForm()
    form.community.query = current_user.get_communities()
    form.asn.query = current_user.get_asns()
    form.submit.label.text='Create CustomerEdge'
    if form.validate_on_submit():
        ce = CustomerEdge()
        form.populate_obj(ce)
        db.session.add(ce)
        db.session.commit()
        flash('Customer Edge has been created')
        return redirect(url_for('customeredges.list'))
    return render_template("customeredge/new.html", form=form)
Ejemplo n.º 5
0
def create():
    form = CustomerEdgeForm()
    form.community.query = current_user.get_communities()
    form.asn.query = current_user.get_asns()
    form.submit.label.text = 'Create CustomerEdge'
    if form.validate_on_submit():
        ce = CustomerEdge()
        form.populate_obj(ce)
        db.session.add(ce)
        db.session.commit()
        flash('Customer Edge has been created')
        return redirect(url_for('customeredges.list'))
    return render_template("customeredge/new.html", form=form)
Ejemplo n.º 6
0
def create():
    form = FormAS()
    form.communities.query = current_user.get_communities()
    form.contacts.query = current_user.get_contacts()
    form.submit.label.text='Create ASN'
    if form.validate_on_submit():
        asn = AS()
        form.populate_obj(asn)
        asn.created = datetime.now()
        asn.changed = datetime.now()
        db.session.add(asn)
        db.session.commit()
        flash('Customer Edge has been created')
        return redirect(url_for('asns.list'))
    return render_template("as/detail.html", form=form, edit=False)
Ejemplo n.º 7
0
def create():
    form = FormAS()
    form.communities.query = current_user.get_communities()
    form.contacts.query = current_user.get_contacts()
    form.submit.label.text = 'Create ASN'
    if form.validate_on_submit():
        asn = AS()
        form.populate_obj(asn)
        asn.created = datetime.now()
        asn.changed = datetime.now()
        db.session.add(asn)
        db.session.commit()
        flash('Customer Edge has been created')
        return redirect(url_for('asns.list'))
    return render_template("as/detail.html", form=form, edit=False)
Ejemplo n.º 8
0
def edit(nameserver_id):
    comm_subq = Community.query.filter(
        Community.contacts.contains(current_user)).subquery()
    this_nameserver = NameServer.query.filter_by(id=nameserver_id).join(comm_subq, AS.Community).first()
    if this_nameserver is None:
        flash('Access denied!')
        return redirect(url_for('index'))
    form = FormNameserver(obj=this_nameserver, edit=True)
    form.community.query = current_user.get_communities()
    form.submit.label.text='Update Nameserver'
    if form.validate_on_submit():
        form.populate_obj(this_nameserver)
        this_nameserver.changed = datetime.now()
        db.session.add(this_nameserver)
        db.session.commit()
        flash('Nameserver edited successfully!')
        return redirect(url_for('nameservers.list'))
    return render_template("nameserver/detail.html", form=form, edit=True)
Ejemplo n.º 9
0
def edit(asn_id):
    comm_subq = Community.query.filter(
        Community.contacts.contains(current_user)).subquery()
    this_asn = AS.query.filter_by(id=asn_id).join(comm_subq, AS.Community).first()
    if this_asn is None:
        flash('Access denied!')
        return redirect(url_for('index'))
    form = FormAS(obj=this_asn, edit=True)
    form.communities.query = current_user.get_communities()
    form.contacts.query = current_user.get_contacts()
    form.submit.label.text='Update ASN'
    if form.validate_on_submit():
        form.populate_obj(this_asn)
        this_asn.changed = datetime.now()
        db.session.add(this_asn)
        db.session.commit()
        return redirect(url_for('asns.list'))
    return render_template("as/detail.html", form=form, edit=True)
Ejemplo n.º 10
0
def edit(asn_id):
    comm_subq = Community.query.filter(
        Community.contacts.contains(current_user)).subquery()
    this_asn = AS.query.filter_by(id=asn_id).join(comm_subq,
                                                  AS.Community).first()
    if this_asn is None:
        flash('Access denied!')
        return redirect(url_for('index'))
    form = FormAS(obj=this_asn, edit=True)
    form.communities.query = current_user.get_communities()
    form.contacts.query = current_user.get_contacts()
    form.submit.label.text = 'Update ASN'
    if form.validate_on_submit():
        form.populate_obj(this_asn)
        this_asn.changed = datetime.now()
        db.session.add(this_asn)
        db.session.commit()
        return redirect(url_for('asns.list'))
    return render_template("as/detail.html", form=form, edit=True)
Ejemplo n.º 11
0
def edit(ce_id):
    if current_user.is_ce_permitted(ce_id) is False:
        flash('You don' 't belong to the CustomerEdge' 's Community')  # noqa
        return redirect(url_for('customeredges.list'))
    ce = CustomerEdge.query.filter_by(id=ce_id).options(
        db.joinedload('asn')).options(db.lazyload('community')).first()
    sessions = PeeringSession.query.filter_by(ce_id=ce.id).options(
        db.joinedload('TunnelType')).options(db.joinedload('ProviderEdge'))
    form = CustomerEdgeForm(obj=ce, edit=True)
    form.asn.query = current_user.get_asns()
    form.community.query = current_user.get_communities()
    form.submit.label.text = 'Update Customer Edge'
    sessionform = SessionForm()
    sessionform.type.query = TunnelType.query
    if form.validate_on_submit():
        flash('CustomerEdge edited successfully!')
        return redirect(url_for('customeredges.list'))
    if sessionform.validate_on_submit():
        print('gen sessions')
        #Generate GRE tunnels, ips and sessions
        pes = ProviderEdge.query.all()
        for pe in pes:
            transfer = Prefix.get_availprefix(1, 4, 31)
            session = PeeringSession()
            session.pe_id = pe.id
            session.ce_id = ce_id
            session.pe_v4 = str(transfer[0])
            session.ce_v4 = str(transfer[1])
            session.tunneltype_id = 1
            session.enabled = 1
            db.session.add(session)
            db.session.commit()
        return redirect(url_for('customeredges.edit', ce_id=ce_id))
    return render_template('customeredge/detail.html',
                           ce=ce,
                           sessions=sessions,
                           form=form,
                           sessionform=sessionform)
Ejemplo n.º 12
0
def edit(ce_id):
    if current_user.is_ce_permitted(ce_id) is False:
        flash('You don''t belong to the CustomerEdge''s Community')  # noqa
        return redirect(url_for('customeredges.list'))
    ce = CustomerEdge.query.filter_by(id=ce_id).options(
        db.joinedload('asn')).options(db.lazyload('community')).first()
    sessions = PeeringSession.query.filter_by(ce_id=ce.id).options(
        db.joinedload('TunnelType')).options(db.joinedload('ProviderEdge'))
    form = CustomerEdgeForm(obj=ce, edit=True)
    form.asn.query = current_user.get_asns()
    form.community.query = current_user.get_communities()
    form.submit.label.text = 'Update Customer Edge'
    sessionform = SessionForm()
    sessionform.type.query = TunnelType.query
    if form.validate_on_submit():
        flash('CustomerEdge edited successfully!')
        return redirect(url_for('customeredges.list'))
    if sessionform.validate_on_submit():
        print('gen sessions')
        #Generate GRE tunnels, ips and sessions
        pes = ProviderEdge.query.all()
        for pe in pes:
            transfer = Prefix.get_availprefix(1,4,31)
            session = PeeringSession()
            session.pe_id = pe.id
            session.ce_id = ce_id
            session.pe_v4 = str(transfer[0])
            session.ce_v4 = str(transfer[1])
            session.tunneltype_id = 1
            session.enabled = 1
            db.session.add(session)
            db.session.commit()
        return redirect(url_for('customeredges.edit',ce_id=ce_id))
    return render_template(
        'customeredge/detail.html',
        ce=ce,
        sessions=sessions, form=form, sessionform=sessionform)