Exemplo n.º 1
0
def site_drop(site_id):
    """ Drop a given site.
    """
    topic = 'site.deleted'
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    if not (is_site_admin(flask.g.fas_user, siteobj)
            or is_mirrormanager_admin(flask.g.fas_user)):
        flask.abort(403, 'Access denied')

    form = forms.ConfirmationForm()
    site_name = siteobj.name
    if form.validate_on_submit():
        message = dict(
            site_id=siteobj.id,
            site_name=siteobj.name,
            org_url=siteobj.org_url)

        SESSION.delete(siteobj)
        try:
            SESSION.commit()
            flask.flash('Site "%s" dropped' % site_name)
            fedmsg_publish(topic, message)
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not delete this site')
            APP.logger.debug('Could not delete this site')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('index'))
Exemplo n.º 2
0
def siteadmin_new(site_id):
    """ Create a new site_admin.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = forms.LostPasswordForm()
    if form.validate_on_submit():
        site_admin = model.SiteAdmin()
        SESSION.add(site_admin)
        site_admin.site_id = siteobj.id
        form.populate_obj(obj=site_admin)

        try:
            SESSION.flush()
            flask.flash('Site Admin added')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not add Site Admin')
            APP.logger.debug('Could not add Site Admin')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('site_view', site_id=site_id))

    return flask.render_template(
        'site_admin_new.html',
        form=form,
        site=siteobj,
    )
Exemplo n.º 3
0
def siteadmin_delete(site_id, admin_id):
    """ Delete a site_admin.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    siteadminobj = mmlib.get_siteadmin(SESSION, admin_id)

    if siteadminobj is None:
        flask.abort(404, 'Site Admin not found')

    if siteadminobj not in siteobj.admins:
        flask.abort(404, 'Site Admin not related to this Site')

    if len(siteobj.admins) <= 1:
        flask.flash('There is only one admin set, you cannot delete it.',
                    'error')
        return flask.redirect(flask.url_for('site_view', site_id=site_id))

    SESSION.delete(siteadminobj)

    try:
        SESSION.commit()
        flask.flash('Site Admin deleted')
    except SQLAlchemyError as err:
        SESSION.rollback()
        flask.flash('Could not delete Site Admin', 'error')
        APP.logger.debug('Could not delete Site Admin')
        APP.logger.exception(err)

    return flask.redirect(flask.url_for('site_view', site_id=site_id))
Exemplo n.º 4
0
def siteadmin_new(site_id):
    """ Create a new site_admin.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = forms.LostPasswordForm()
    if form.validate_on_submit():
        site_admin = model.SiteAdmin()
        SESSION.add(site_admin)
        site_admin.site_id = siteobj.id
        form.populate_obj(obj=site_admin)

        try:
            SESSION.flush()
            flask.flash('Site Admin added')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not add Site Admin')
            APP.logger.debug('Could not add Site Admin')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('site_view', site_id=site_id))

    return flask.render_template(
        'site_admin_new.html',
        form=form,
        site=siteobj,
    )
Exemplo n.º 5
0
def site_view(site_id):
    """ View information about a given site.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = forms.AddSiteForm(obj=siteobj)
    if form.validate_on_submit():
        obj = form.populate_obj(obj=siteobj)

        try:
            SESSION.flush()
            flask.flash('Site Updated')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code check before adding the
            # new SiteAdmin and therefore the only situation where it could
            # fail is a failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not update the Site')
            APP.logger.debug('Could not update the Site')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site.html',
        site=siteobj,
        form=form,
    )
Exemplo n.º 6
0
def siteadmin_delete(site_id, admin_id):
    """ Delete a site_admin.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    siteadminobj = mmlib.get_siteadmin(SESSION, admin_id)

    if siteadminobj is None:
        flask.abort(404, 'Site Admin not found')

    if siteadminobj not in siteobj.admins:
        flask.abort(404, 'Site Admin not related to this Site')

    if len(siteobj.admins) <= 1:
        flask.flash(
            'There is only one admin set, you cannot delete it.', 'error')
        return flask.redirect(flask.url_for('site_view', site_id=site_id))

    SESSION.delete(siteadminobj)

    try:
        SESSION.commit()
        flask.flash('Site Admin deleted')
    except SQLAlchemyError as err:
        SESSION.rollback()
        flask.flash('Could not delete Site Admin', 'error')
        APP.logger.debug('Could not delete Site Admin')
        APP.logger.exception(err)

    return flask.redirect(flask.url_for('site_view', site_id=site_id))
Exemplo n.º 7
0
def site_drop(site_id):
    """ Drop a given site.
    """
    topic = 'site.deleted'
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    if not (is_site_admin(flask.g.fas_user, siteobj)
            or is_mirrormanager_admin(flask.g.fas_user)):
        flask.abort(403, 'Access denied')

    form = forms.ConfirmationForm()
    site_name = siteobj.name
    if form.validate_on_submit():
        message = dict(site_id=siteobj.id,
                       site_name=siteobj.name,
                       org_url=siteobj.org_url)

        SESSION.delete(siteobj)
        try:
            SESSION.commit()
            flask.flash('Site "%s" dropped' % site_name)
            fedmsg_publish(topic, message)
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not delete this site')
            APP.logger.debug('Could not delete this site')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('index'))
Exemplo n.º 8
0
def host_new(site_id):
    """ Create a new host.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = forms.AddHostForm()
    if form.validate_on_submit():
        host = model.Host()
        SESSION.add(host)
        host.site_id = siteobj.id
        form.populate_obj(obj=host)
        host.bandwidth_int = int(host.bandwidth_int)
        host.asn = None if not host.asn else int(host.asn)

        try:
            SESSION.flush()
            flask.flash('Host added')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not create the new host')
            APP.logger.debug('Could not create the new host')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('site_view', site_id=site_id))

    return flask.render_template(
        'host_new.html',
        form=form,
        site=siteobj,
    )
Exemplo n.º 9
0
def siteadmin_new(site_id):
    """ Create a new site_admin.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = login_forms.LostPasswordForm()
    if form.validate_on_submit():
        site_admin = model.SiteAdmin()
        SESSION.add(site_admin)
        site_admin.site_id = siteobj.id
        form.populate_obj(obj=site_admin)

        try:
            SESSION.flush()
            flask.flash('Site Admin added')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this as there is no unique constraint in the
            # Site table. So the only situation where it could fail is a
            # failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not add Site Admin')
            APP.logger.debug('Could not add Site Admin')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('site_view', site_id=site_id))

    return flask.render_template(
        'site_admin_new.html',
        form=form,
        site=siteobj,
    )
Exemplo n.º 10
0
def site_view(site_id):
    """ View information about a given site.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = forms.AddSiteForm(obj=siteobj)
    if form.validate_on_submit():
        obj = form.populate_obj(obj=siteobj)

        try:
            SESSION.flush()
            flask.flash('Site Updated')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code check before adding the
            # new SiteAdmin and therefore the only situation where it could
            # fail is a failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not update the Site')
            APP.logger.debug('Could not update the Site')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site.html',
        site=siteobj,
        form=form,
    )
Exemplo n.º 11
0
def siteadmin_new(site_id):
    """ Create a new site_admin.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = login_forms.LostPasswordForm()
    if form.validate_on_submit():
        site_admin = model.SiteAdmin()
        SESSION.add(site_admin)
        site_admin.site_id = siteobj.id
        form.populate_obj(obj=site_admin)

        try:
            SESSION.flush()
            flask.flash('Site Admin added')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this as there is no unique constraint in the
            # Site table. So the only situation where it could fail is a
            # failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not add Site Admin')
            APP.logger.debug('Could not add Site Admin')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('site_view', site_id=site_id))

    return flask.render_template(
        'site_admin_new.html',
        form=form,
        site=siteobj,
    )
Exemplo n.º 12
0
def host_new(site_id):
    """ Create a new host.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = forms.AddHostForm()
    if form.validate_on_submit():
        host = model.Host()
        SESSION.add(host)
        host.site_id = siteobj.id
        form.populate_obj(obj=host)
        host.bandwidth_int = int(host.bandwidth_int)
        host.asn = None if not host.asn else int(host.asn)

        try:
            SESSION.flush()
            flask.flash('Host added')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not create the new host')
            APP.logger.debug('Could not create the new host')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('site_view', site_id=site_id))

    return flask.render_template(
        'host_new.html',
        form=form,
        site=siteobj,
    )
Exemplo n.º 13
0
def host_new(site_id):
    """ Create a new host.
    """

    topic = 'host.added'
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    if not (is_site_admin(flask.g.fas_user, siteobj)
            or is_mirrormanager_admin(flask.g.fas_user)):
        flask.abort(403, 'Access denied')

    form = forms.AddHostForm()
    if form.validate_on_submit():
        host = model.Host()
        SESSION.add(host)
        host.site_id = siteobj.id
        form.populate_obj(obj=host)
        host.admin_active = True

        host.bandwidth_int = int(host.bandwidth_int)
        host.asn = None if not host.asn else int(host.asn)
        message = dict(
            site_id=host.site_id,
            bandwidth=host.bandwidth_int,
            asn=host.asn)

        try:
            SESSION.flush()
            flask.flash('Host added')
            fedmsg_publish(topic, message)
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not create the new host')
            APP.logger.debug('Could not create the new host')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('site_view', site_id=site_id))

    return flask.render_template(
        'host_new.html',
        form=form,
        site=siteobj,
    )
Exemplo n.º 14
0
def host_new(site_id):
    """ Create a new host.
    """

    topic = 'host.added'
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    if not (is_site_admin(flask.g.fas_user, siteobj)
            or is_mirrormanager_admin(flask.g.fas_user)):
        flask.abort(403, 'Access denied')

    form = forms.AddHostForm()
    if form.validate_on_submit():
        host = model.Host()
        SESSION.add(host)
        host.site_id = siteobj.id
        form.populate_obj(obj=host)
        host.admin_active = True

        host.bandwidth_int = int(host.bandwidth_int)
        host.asn = None if not host.asn else int(host.asn)
        message = dict(
            site_id=host.site_id,
            bandwidth=host.bandwidth_int,
            asn=host.asn)

        try:
            SESSION.flush()
            flask.flash('Host added')
            fedmsg_publish(topic, message)
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not create the new host')
            APP.logger.debug('Could not create the new host')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('site_view', site_id=site_id))

    return flask.render_template(
        'host_new.html',
        form=form,
        site=siteobj,
    )
Exemplo n.º 15
0
def site_view(site_id):
    """ View information about a given site.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    if not (is_site_admin(flask.g.fas_user, siteobj)
            or is_mirrormanager_admin(flask.g.fas_user)):
        flask.abort(403, 'Access denied')

    form = forms.AddSiteForm(obj=siteobj)
    if form.validate_on_submit():
        admin_active = siteobj.admin_active
        private = siteobj.private
        obj = form.populate_obj(obj=siteobj)

        # If the user is *not* an admin, keep the current admin_active flag
        if not is_mirrormanager_admin(flask.g.fas_user):
            siteobj.admin_active = admin_active

        # If the private flag has been changed, invalidate mirrors
        if siteobj.private != private:
            for host in siteobj.hosts:
                host.set_not_up2date(SESSION)

        try:
            SESSION.flush()
            flask.flash('Site Updated')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code check before adding the
            # new SiteAdmin and therefore the only situation where it could
            # fail is a failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not update the Site')
            APP.logger.debug('Could not update the Site')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site.html',
        site=siteobj,
        form=form,
    )
Exemplo n.º 16
0
def siteadmin_delete(site_id, admin_id):
    """ Delete a site_admin.
    """
    form = forms.ConfirmationForm()
    if form.validate_on_submit():

        siteobj = mmlib.get_site(SESSION, site_id)

        if siteobj is None:
            flask.abort(404, 'Site not found')

        if not (is_site_admin(flask.g.fas_user, siteobj)
                or is_mirrormanager_admin(flask.g.fas_user)):
            flask.abort(403, 'Access denied')

        siteadminobj = mmlib.get_siteadmin(SESSION, admin_id)

        if siteadminobj is None:
            flask.abort(404, 'Site Admin not found')

        if siteadminobj not in siteobj.admins:
            flask.abort(404, 'Site Admin not related to this Site')

        if len(siteobj.admins) <= 1:
            flask.flash(
                'There is only one admin set, you cannot delete it.', 'error')
            return flask.redirect(flask.url_for('site_view', site_id=site_id))

        SESSION.delete(siteadminobj)

        try:
            SESSION.commit()
            flask.flash('Site Admin deleted')
        except SQLAlchemyError as err:  # pragma: no cover
            # We check everything before deleting so the only error we could
            # run in is DB server related, and that we can't fake in our
            # tests
            SESSION.rollback()
            flask.flash('Could not delete Site Admin', 'error')
            APP.logger.debug('Could not delete Site Admin')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('site_view', site_id=site_id))
Exemplo n.º 17
0
def siteadmin_delete(site_id, admin_id):
    """ Delete a site_admin.
    """
    form = forms.ConfirmationForm()
    if form.validate_on_submit():

        siteobj = mmlib.get_site(SESSION, site_id)

        if siteobj is None:
            flask.abort(404, 'Site not found')

        if not (is_site_admin(flask.g.fas_user, siteobj)
                or is_mirrormanager_admin(flask.g.fas_user)):
            flask.abort(403, 'Access denied')

        siteadminobj = mmlib.get_siteadmin(SESSION, admin_id)

        if siteadminobj is None:
            flask.abort(404, 'Site Admin not found')

        if siteadminobj not in siteobj.admins:
            flask.abort(404, 'Site Admin not related to this Site')

        if len(siteobj.admins) <= 1:
            flask.flash('There is only one admin set, you cannot delete it.',
                        'error')
            return flask.redirect(flask.url_for('site_view', site_id=site_id))

        SESSION.delete(siteadminobj)

        try:
            SESSION.commit()
            flask.flash('Site Admin deleted')
        except SQLAlchemyError as err:  # pragma: no cover
            # We check everything before deleting so the only error we could
            # run in is DB server related, and that we can't fake in our
            # tests
            SESSION.rollback()
            flask.flash('Could not delete Site Admin', 'error')
            APP.logger.debug('Could not delete Site Admin')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('site_view', site_id=site_id))
Exemplo n.º 18
0
def site_view(site_id):
    """ View information about a given site.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = forms.AddSiteForm(obj=siteobj)
    if form.validate_on_submit():
        admin_active = siteobj.admin_active
        private = siteobj.private
        obj = form.populate_obj(obj=siteobj)

        # If the user is *not* an admin, keep the current admin_active flag
        if not is_mirrormanager_admin(flask.g.fas_user):
            siteobj.admin_active = admin_active

        # If the private flag has been changed, invalidate mirrors
        if siteobj.private != private:
            for host in siteobj.hosts:
                host.set_not_up2date(SESSION)

        try:
            SESSION.flush()
            flask.flash('Site Updated')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code check before adding the
            # new SiteAdmin and therefore the only situation where it could
            # fail is a failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not update the Site')
            APP.logger.debug('Could not update the Site')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site.html',
        site=siteobj,
        form=form,
    )
Exemplo n.º 19
0
def site_view(site_id):
    """ View information about a given site.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = forms.AddSiteForm(obj=siteobj)
    if form.validate_on_submit():
        obj = form.populate_obj(obj=siteobj)
        SESSION.commit()
        flask.flash('Site Updated')
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site.html',
        site=siteobj,
        form=form,
    )
Exemplo n.º 20
0
def site_view(site_id):
    """ View information about a given site.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = forms.AddSiteForm(obj=siteobj)
    if form.validate_on_submit():
        obj = form.populate_obj(obj=siteobj)
        SESSION.commit()
        flask.flash('Site Updated')
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site.html',
        site=siteobj,
        form=form,
    )