示例#1
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)
示例#2
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)
示例#3
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)
示例#4
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'))
示例#5
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)
示例#6
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)
示例#7
0
def logout():
    """logout

    Perform a logout call to the server and clear the session

    Return: redirect to home
    """
    api.api_call('logout')
    session.clear()
    return redirect(url_for('login'))
示例#8
0
def installPolicy():
    """
    edit application-site

    edit an existing application-site

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

    return: renders the show application-sites page
    """
    payload = {
        'access': True,
        'policy-package': 'standard',
        'targets': app.config['TARGETS'],
        'threat-prevention': False}
    api.api_call('install-policy', payload)
    flash(u'Política instal·lada')
    return redirect(url_for('home'))
示例#9
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))
示例#10
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)
示例#11
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)
示例#12
0
 def wrap(*args, **kwargs):
     # if we have a session username
     if 'username' in session:
         # and there is an status-code when we ask to the server
         call = api.api_call('show-login-message')
         if hasattr(call, 'status_code'):
             # and this status_code is 200
             if call.status_code == 200:
                 # then go on
                 return f(*args, **kwargs)
         # either there isn't an status_code but is not 200 or there is not
         # any status_code at all, probably expired, let's clear the session
         session.clear()
         return render_template('session-expired.html')
     # we don't have a session username, so let's get one
     return redirect(url_for('login'))
示例#13
0
def createEntity():
    """
    create entity

    creates all needed groups and application groups for a new entity

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

    if request.method == 'POST' and form.validate():

        id_entity = form.entity_code.data

        app_groups = [
            'APLICACIONS', 'GENERAL', 'LlistaNegraAplicacionsAlumnes',
            'LlistaNegraAplicacionsProfessors', 'LlistaNegraAplicacionsTots',
            'LlistaNegraURLsAlumnes', 'LlistaNegraURLsProfessors',
            'LlistaNegraURLsTots'
        ]
        groups = [
            'LlistaEquipsAlumnes', 'LlistaEquipsProfessors',
            'LlistaNegraEquips'
        ]

        # create application site groups
        for app_group in app_groups:
            app_group_to_add = EntityObject(id_entity + '_APGR_' + app_group,
                                            'application-site-group')
            app_group_to_add.add()
        # create groups
        for group in groups:
            group_to_add = EntityObject(id_entity + '_GRUP_' + group, 'group')
            group_to_add.add()
        # add-package
        payload = {
            'name': 'Escola_' + id_entity,
            'comments': 'Escola ' + id_entity,
            'color': 'green',
            'threat-prevention': False,
            'access': True
        }
        api.api_call('add-package', payload)

        # set-access-layer
        payload = {
            'name': 'Escola_' + id_entity + ' Network',
            'applications-and-url-filtering': True,
            'show-parent-rule': False
        }
        api.api_call('set-access-layer', payload)

        # set-access-rule
        payload = {
            'name': 'Cleanup rule',
            'layer': 'Escola_' + id_entity + ' Network',
            'action': 'Accept',
            'track': 'Log'
        }
        api.api_call('set-access-rule', payload)

        # add-access-section
        payload = {
            'layer': 'Escola_' + id_entity + ' Network',
            'position': 'top',
            'name': 'Regles definides per escola'
        }
        api.api_call('add-access-section', payload)

        # add-access-rule
        payload = {
            'layer': 'Escola_' + id_entity + ' Network',
            'position': 1,
            'source': id_entity + '_GRUP_LlistaEquipsProfessors',
            'service': id_entity + '_APGR_LlistaNegraAplicacionsProfessors',
            'destination': 'Any',
            'action': 'Drop',
            'track': 'Log'
        }
        api.api_call('add-access-rule', payload)

        # add-access-rule
        payload = {
            'layer': 'Escola_' + id_entity + ' Network',
            'position': 1,
            'source': id_entity + '_GRUP_LlistaEquipsAlumnes',
            'service': id_entity + '_APGR_LlistaNegraAplicacionsAlumnes',
            'destination': 'Any',
            'action': 'Drop',
            'track': 'Log'
        }
        api.api_call('add-access-rule', payload)

        # add-access-rule
        payload = {
            'layer': 'Escola_' + id_entity + ' Network',
            'position': 1,
            'source': id_entity + '_GRUP_LlistaNegraEquips',
            'service': 'Any',
            'destination': 'Any',
            'action': 'Drop',
            'track': 'Log'
        }
        api.api_call('add-access-rule', payload)

        # add-access-section
        payload = {
            'layer': 'Escola_' + id_entity + ' Network',
            'position': 'bottom',
            'name': 'Regles definides per administradors'
        }
        api.api_call('add-access-section', payload)

        api.api_call('publish')
        flash(u"School is set up")

        return redirect(url_for('home', url_back='createEntity'))

    return render_template('create-entity.html',
                           form=form,
                           url_back='manageGroups')