Ejemplo n.º 1
0
def showApplGroupMembers(name, url_back):
    """
    show application-site group content

    shows application group content when selecting a source in the dropdown
    menu while adding a new rule

    argument:
        group_id: the group that's been selected

    return: renders the show application group content page just below the
        select
    """
    form_select_app = ApplicationSelectForm(request.form)

    members = APIObject(name, 'application-site-group').show_members()
    choices = APIObject('APGR_APLICACIONS',
                        'application-site-group').show_members()

    options = [('', 'seleccionar')]
    for element in choices:
        already_in_group = False
        for appl in members:
            if element['name'] == appl['name']:
                already_in_group = True
        if not already_in_group:
            options.append((element['name'], element['name']))
    form_select_app.name.choices = options

    return render_template('show-appl-group-members.html',
                           form_select_app=form_select_app,
                           members=members,
                           name=name,
                           url_back=url_back)
Ejemplo n.º 2
0
def setApplicationSite(name, url_back):
    """
    edit host

    edits an existing host

    arguments:
        object_uid:

    return: renders the show group members page
    """
    form = ApplicationSiteForm(request.form)

    appl = APIObject(name, 'application-site')
    appl_to_edit = appl.show()

    if request.method == 'POST' and form.validate():
        appl.edit(new_name=app.config['ID_COLE'] + 'APPL_' + form.name.data,
                  url_list=form.url_list.data)
        api.api_call('publish')
        flash('URL edited')
        return redirect(url_for(url_back))

    return render_template('edit-application-site.html',
                           form=form,
                           appl_to_edit=appl_to_edit,
                           url_back=url_back)
Ejemplo n.º 3
0
def addHost(group_name, url_back):
    """add host
    Add a new host inside a group

    Arguments:
        group_nam - the name of the group where the host has to be added
        url_back - url for redirecting when finished

    Return: if form validates, create the host and add it to the group, if
        doesn't render a page with the errors
    """
    form = HostForm(request.form)
    if request.method == 'POST' and form.validate():
        host = APIObject('HOST_' + form.name.data, 'host')
        add = host.add(ipv4_address=form.ipv4_address.data)
        if not add.success:
            if 'errors' in add.res_obj['data']:
                message = add.res_obj['data']['errors'][0]['message']
                if message[:26] == 'More than one object named':
                    flash('A computer with that name already exists')
            if 'warnings' in add.res_obj['data']:
                message = add.res_obj['data']['warnings'][0]['message']
                if message[:37] == 'More than one object have the same IP':
                    flash('A computer with this IP already exists')
        else:
            host.add_to_group('set-group', group_name)
            api.api_call('publish')
            flash('Equipment added')
        return redirect(url_for(url_back))
    else:
        return render_template('form-errors.html',
                               form=form,
                               url_back=url_back)
Ejemplo n.º 4
0
def setHost(name, url_back):
    """edit host

    Edit an existing host

    Arguments:
        name - name of the host to be edited
        url_back - url for redirecting when finished

    Return: if form validates edit the host, if doesn't show a page with the
        errors
    """
    form = HostForm(request.form)

    host = APIObject(name, 'host')
    host_to_edit = host.show()

    if request.method == 'POST' and form.validate():
        host.edit(new_name=app.config['ID_COLE'] + 'HOST_' + form.name.data,
                  ipv4_address=form.ipv4_address.data)
        api.api_call('publish')
        flash('Edited team')
        return redirect(url_for(url_back))

    return render_template('edit-host.html',
                           form=form,
                           host_to_edit=host_to_edit,
                           url_back=url_back)
Ejemplo n.º 5
0
def manageGroups():
    """manage groups

    Show the hosts groups detail and allow create, edit and delete them

    Return: render the manage groups page
    """
    professors = APIObject('GRUP_LlistaEquipsProfessors', 'group').show()
    alumnes = APIObject('GRUP_LlistaEquipsAlumnes', 'group').show()
    return render_template('manage-groups.html',
                           professors=professors,
                           alumnes=alumnes,
                           url_back='manageGroups')
Ejemplo n.º 6
0
def addApplicationSite(group_name, url_back):
    """
    add application-site

    add a new application-site inside a group

    arguments:
        group_id: the id number of the application-site groups

    return: renders the show application-sites page
    """
    form = ApplicationSiteForm(request.form)

    if form.validate():

        appl = APIObject('APPL_' + form.name.data, 'application-site')
        appl.add(url_list=form.url_list.data,
                 primary_category='Custom_Application_Site')  # required
        appl.add_to_group('set-application-site-group', group_name)
        appl.add_to_group('set-application-site-group', 'APGR_GENERAL')
        api.api_call('publish')
        flash('URL added')
        return redirect(url_for(url_back))

    # I have to check what to do here
    return redirect(url_for('blockURL'))
Ejemplo n.º 7
0
def deleteHost(name, group_name, url_back):
    """delete host

    Delete an existing host

    Arguments:
        name - the name of the host to be deleted
        group_name - the name of the group where the host belongs
        url_back - url for redirecting when finished

    Return: if POST delete the host, if GET render the delete host page
    """
    host = APIObject(name, 'host')
    host_to_delete = host.show()

    if request.method == 'POST':
        host.delete_from_group('set-group', group_name)
        host.delete()

        api.api_call('publish')
        flash('Equipment removed')
        return redirect(url_for(url_back))

    return render_template('delete-host.html',
                           group_name=group_name,
                           host_to_delete=host_to_delete,
                           url_back=url_back)
Ejemplo n.º 8
0
def blockIP():
    """block access

    Shows the group and the application-site-group for blocking hosts and URLs

    Return: render the block access page
    """
    group = APIObject('GRUP_LlistaNegraEquips', 'group').show()
    return render_template('block-ip.html', group=group, url_back='blockIP')
Ejemplo n.º 9
0
def blockAppl():
    """
    block access

    shows the group and the application-site-group for blocking hosts and URLs

    return: renders the block access page
    """
    tots = APIObject('APGR_LlistaNegraAplicacionsTots',
                     'application-site-group').show()
    professors = APIObject('APGR_LlistaNegraAplicacionsProfessors',
                           'application-site-group').show()
    alumnes = APIObject('APGR_LlistaNegraAplicacionsAlumnes',
                        'application-site-group').show()

    return render_template('block-appl.html',
                           tots=tots,
                           professors=professors,
                           alumnes=alumnes,
                           url_back='blockAppl')
Ejemplo n.º 10
0
def blockURL():
    """
    show application-site groups

    show the application-site groups

    return: renders the show application-site groups page
    """
    tots = APIObject('APGR_LlistaNegraURLsTots',
                     'application-site-group').show()
    professors = APIObject('APGR_LlistaNegraURLsProfessors',
                           'application-site-group').show()
    alumnes = APIObject('APGR_LlistaNegraURLsAlumnes',
                        'application-site-group').show()

    return render_template('block-url.html',
                           tots=tots,
                           professors=professors,
                           alumnes=alumnes,
                           url_back='blockURL')
Ejemplo n.º 11
0
def addExistingApplication(group_name, url_back):
    """
    add existing application

    adds an existing host to a group

    arguments:
        host_id: the id of the host to be added to the group
        group_id: the id of the group where the host has to be added

    return: when POST adds the host to the group, if NO renders the
        show groups page
    """
    form = ApplicationSelectForm(request.form)

    appl = APIObject(form.name.data, 'application-site')
    appl.add_to_group('set-application-site-group', group_name)

    api.api_call('publish')
    flash('URL added')
    return redirect(url_for(url_back))
Ejemplo n.º 12
0
def deleteAppl(name, group_name, url_back):
    """
    delete application-site

    delete an existing application-site

    arguments:
        app_list: the id number of the application-site groups

    return: renders the show application-sites page
    """
    appl = APIObject(name, 'application-site')
    appl.name = appl.name[5:]
    appl_to_delete = appl.show()

    if request.method == 'POST':

        appl.delete_from_group('set-application-site-group', group_name)

        api.api_call('publish')
        flash(u'Application Removed')
        return redirect(url_for(url_back))

    return render_template('delete-appl.html',
                           group_name=group_name,
                           appl_to_delete=appl_to_delete,
                           url_back=url_back)
Ejemplo n.º 13
0
def deleteApplicationSite(name, group_name, url_back):
    """
    delete application-site

    delete an existing application-site

    arguments:
        app_list: the id number of the application-site groups

    return: renders the show application-sites page
    """
    appl = APIObject(name, 'application-site')
    appl_to_delete = appl.show()

    if request.method == 'POST':

        appl.delete_from_group('set-application-site-group', group_name)

        if appl.where_used() >= 2:
            api.api_call('publish')
            flash(
                u"The URL belongs to more lists, it is not completely deleted")
            return redirect(url_for(url_back))

        appl.delete_from_group('set-application-site-group', 'APGR_GENERAL')

        appl.delete()

        api.api_call('publish')
        flash(u'URL removed')
        return redirect(url_for(url_back))

    return render_template('delete-application-site.html',
                           group_name=group_name,
                           appl_to_delete=appl_to_delete,
                           url_back=url_back)
Ejemplo n.º 14
0
def deleteApplicationSite(name, group_name, url_back):
    """
    delete application-site

    delete an existing application-site

    arguments:
        app_list: the id number of the application-site groups

    return: renders the show application-sites page
    """
    appl = APIObject(name, 'application-site')
    appl_to_delete = appl.show()

    if request.method == 'POST':

        appl.delete_from_group('set-application-site-group', group_name)

        if appl.where_used() >= 2:
            api.api_call('publish')
            flash(u"La URL pertany a més llistes, no s'elimina totalment")
            return redirect(url_for(url_back))

        appl.delete_from_group('set-application-site-group', 'APGR_GENERAL')

        appl.delete()

        api.api_call('publish')
        flash(u'URL eliminada')
        return redirect(url_for(url_back))

    return render_template(
        'delete-application-site.html',
        group_name=group_name,
        appl_to_delete=appl_to_delete,
        url_back=url_back)
Ejemplo n.º 15
0
def showGroupMembers(group_name, url_back):
    """show group members

    Show the hosts of each group, allow the user to add a new host to the group

    Arguments:
        group_name - the group's name
        url_back - url for redirecting when finished

    Return: render the show group members page
    """
    form = HostForm(request.form)
    members = APIObject(group_name, 'group').show_members()
    return render_template('show-group-members.html',
                           members=members,
                           form=form,
                           group_name=group_name,
                           url_back=url_back)