Пример #1
0
def preflight_v2(request):
    """Find plugins that have embedded preflight scripts."""
    # Load in the default plugins if needed
    utils.load_default_plugins()
    manager = PluginManager()
    output = []
    # Old Sal scripts just do a GET; just send everything in that case.
    os_family = None if request.method != 'POST' else request.POST.get(
        'os_family')

    enabled_reports = Report.objects.all()
    enabled_plugins = Plugin.objects.all()
    enabled_detail_plugins = MachineDetailPlugin.objects.all()
    for enabled_plugin in itertools.chain(enabled_reports, enabled_plugins,
                                          enabled_detail_plugins):
        plugin = manager.get_plugin_by_name(enabled_plugin.name)
        if not plugin:
            continue
        if os_family is None or os_family in plugin.get_supported_os_families(
        ):
            scripts = utils.get_plugin_scripts(plugin, hash_only=True)
            if scripts:
                output += scripts

    return HttpResponse(json.dumps(output))
Пример #2
0
def index(request):
    # Get the current user's Business Units
    user = request.user
    # Count the number of users. If there is only one, they need to be made a GA
    if User.objects.count() == 1:
        # The first user created by syncdb won't have a profile. If there isn't
        # one, make sure they get one.
        try:
            profile = UserProfile.objects.get(user=user)
        except UserProfile.DoesNotExist:
            profile = UserProfile(user=user)

        profile.level = ProfileLevel.global_admin
        profile.save()

    user_is_ga = is_global_admin(user)

    if not user_is_ga:
        # user has many BU's display them all in a friendly manner
        if user.businessunit_set.count() == 0:
            c = {
                'user': request.user,
            }
            return render(request, 'server/no_access.html', c)
        if user.businessunit_set.count() == 1:
            # user only has one BU, redirect to it
            return redirect('bu_dashboard',
                            bu_id=user.businessunit_set.all()[0].id)

    # Load in the default plugins if needed
    utils.load_default_plugins()
    plugins = sal.plugin.PluginManager().get_all_plugins()

    reports = utils.get_report_names(plugins)
    output = utils.get_plugin_placeholder_markup(plugins)

    # If the user is GA level, and hasn't decided on a data sending
    # choice, template will reflect this.
    data_choice = False if (
        user_is_ga and utils.get_setting('send_data') is None) else True

    # get the user level - if they're a global admin, show all of the
    # machines. If not, show only the machines they have access to
    if user_is_ga:
        business_units = BusinessUnit.objects.all()
    else:
        business_units = user.businessunit_set.all()

    context = {
        'user': request.user,
        'business_units': business_units,
        'output': output,
        'data_setting_decided': data_choice,
        'reports': reports
    }

    context.update(utils.check_version())

    return render(request, 'server/index.html', context)
Пример #3
0
def index(request):
    # Get the current user's Business Units
    user = request.user
    # Count the number of users. If there is only one, they need to be made a GA
    if User.objects.count() == 1:
        # The first user created by syncdb won't have a profile. If there isn't
        # one, make sure they get one.
        try:
            profile = UserProfile.objects.get(user=user)
        except UserProfile.DoesNotExist:
            profile = UserProfile(user=user)

        profile.level = ProfileLevel.global_admin
        profile.save()

    user_is_ga = is_global_admin(user)

    if not user_is_ga:
        # user has many BU's display them all in a friendly manner
        if user.businessunit_set.count() == 0:
            c = {'user': request.user, }
            return render(request, 'server/no_access.html', c)
        if user.businessunit_set.count() == 1:
            # user only has one BU, redirect to it
            return redirect('bu_dashboard', bu_id=user.businessunit_set.all()[0].id)

    # Load in the default plugins if needed
    utils.load_default_plugins()
    plugins = sal.plugin.PluginManager().get_all_plugins()

    reports = utils.get_report_names(plugins)
    output = utils.get_plugin_placeholder_markup(plugins)

    # If the user is GA level, and hasn't decided on a data sending
    # choice, template will reflect this.
    data_choice = False if (user_is_ga and utils.get_setting('send_data') is None) else True

    # get the user level - if they're a global admin, show all of the
    # machines. If not, show only the machines they have access to
    if user_is_ga:
        business_units = BusinessUnit.objects.all()
    else:
        business_units = user.businessunit_set.all()

    context = {
        'user': request.user,
        'business_units': business_units,
        'output': output,
        'data_setting_decided': data_choice,
        'reports': reports}

    context.update(utils.check_version())

    return render(request, 'server/index.html', context)
Пример #4
0
def bu_dashboard(request, **kwargs):
    business_unit = kwargs['business_unit']
    machine_groups = business_unit.machinegroup_set.all()

    # Load in the default plugins if needed
    utils.load_default_plugins()
    reports = utils.get_report_names()
    output = utils.get_plugin_placeholder_markup(group_type='business_unit',
                                                 group_id=business_unit.id)

    context = {
        'user': request.user,
        'machine_groups': machine_groups,
        'business_unit': business_unit,
        'output': output,
        'reports': reports
    }
    return render(request, 'server/bu_dashboard.html', context)
Пример #5
0
def bu_dashboard(request, **kwargs):
    business_unit = kwargs['business_unit']
    machine_groups = business_unit.machinegroup_set.all()

    # Load in the default plugins if needed
    utils.load_default_plugins()
    plugins = sal.plugin.PluginManager().get_all_plugins()

    reports = utils.get_report_names(plugins)
    output = utils.get_plugin_placeholder_markup(
        plugins, group_type='business_unit', group_id=business_unit.id)

    context = {
        'user': request.user,
        'machine_groups': machine_groups,
        'business_unit': business_unit,
        'output': output,
        'reports': reports}
    return render(request, 'server/bu_dashboard.html', context)
Пример #6
0
def preflight_v2(request):
    """Find plugins that have embedded preflight scripts."""
    # Load in the default plugins if needed
    utils.load_default_plugins()
    manager = PluginManager()
    output = []
    # Old Sal scripts just do a GET; just send everything in that case.
    os_family = None if request.method != 'POST' else request.POST.get('os_family')

    enabled_reports = Report.objects.all()
    enabled_plugins = Plugin.objects.all()
    enabled_detail_plugins = MachineDetailPlugin.objects.all()
    for enabled_plugin in itertools.chain(enabled_reports, enabled_plugins, enabled_detail_plugins):
        plugin = manager.get_plugin_by_name(enabled_plugin.name)
        if not plugin:
            continue
        if os_family is None or os_family in plugin.get_supported_os_families():
            scripts = utils.get_plugin_scripts(plugin, hash_only=True)
            if scripts:
                output += scripts

    return HttpResponse(json.dumps(output))
Пример #7
0
 def test_default_plugin_load(self):
     """Ensure that no plugins result in a default loadout."""
     self.assertEqual(Plugin.objects.count(), 0)
     utils.load_default_plugins()
     self.assertNotEqual(Plugin.objects.count(), 0)
Пример #8
0
 def test_default_plugin_load(self):
     """Ensure that no plugins result in a default loadout."""
     self.assertEqual(Plugin.objects.count(), 0)
     utils.load_default_plugins()
     self.assertNotEqual(Plugin.objects.count(), 0)