示例#1
0
def userprefsview(request):
    have_external_auth = bool(request.external_auth_info)
    if have_external_auth and request.method == 'POST':
        return HttpResponseNotAllowed(['GET'])

    user = request.user
    # Process the profile update form.
    profile_form, response = process_form(request, ProfileForm,
                                          reverse('prefs'), 'profile',
                                          "Profile updated.",
                                          {'instance': user})
    if response is not None:
        return response
    if have_external_auth:
        for field in profile_form:
            field.field.disabled = True

    # Process the password change form.
    password_form, response = process_form(request, PasswordChangeForm,
                                           reverse('prefs'), 'password',
                                           "Password updated.", {'user': user})
    password_form.fields['old_password'].widget.attrs.pop('autofocus', None)
    if response is not None:
        create_audit_event(EVENT_TYPES.AUTHORISATION,
                           ENDPOINT.UI,
                           request,
                           None,
                           description="Updated password.")
        return response

    return render(request, 'maasserver/prefs.html', {
        'profile_form': profile_form,
        'password_form': password_form
    })
示例#2
0
def userprefsview(request):
    user = request.user
    # Process the profile update form.
    profile_form, response = process_form(request, ProfileForm,
                                          reverse('prefs'), 'profile',
                                          "Profile updated.",
                                          {'instance': user})
    if response is not None:
        return response

    # Process the password change form.
    password_form, response = process_form(request, PasswordChangeForm,
                                           reverse('prefs'), 'password',
                                           "Password updated.", {'user': user})
    password_form.fields['old_password'].widget.attrs.pop('autofocus', None)
    if response is not None:
        create_audit_event(EVENT_TYPES.AUTHORISATION,
                           ENDPOINT.UI,
                           request,
                           None,
                           description="Password changed for '%(username)s'.")
        return response

    return render(request, 'maasserver/prefs.html', {
        'profile_form': profile_form,
        'password_form': password_form
    })
示例#3
0
    def post(self, request, *args, **kwargs):
        """Called by `TemplateView`: handle a POST request."""
        self.object = user = self.get_object()
        next_page = reverse("settings_users")

        # Process the profile-editing form, if that's what was submitted.
        profile_form, response = process_form(
            request,
            EditUserForm,
            next_page,
            "profile",
            "Profile updated.",
            {"instance": user},
        )
        if response is not None:
            create_audit_event(
                EVENT_TYPES.AUTHORISATION,
                ENDPOINT.UI,
                request,
                None,
                description=(
                    ("Updated user profile (username: %s, full name: %s, " +
                     "email: %s, administrator: %s)") % (
                         profile_form.cleaned_data["username"],
                         profile_form.cleaned_data["last_name"],
                         profile_form.cleaned_data["email"],
                         profile_form.cleaned_data["is_superuser"],
                     )),
            )
            return response

        # Process the password change form, if that's what was submitted.
        password_form, response = process_form(
            request,
            AdminPasswordChangeForm,
            next_page,
            "password",
            "Password updated.",
            {"user": user},
        )
        if response is not None:
            create_audit_event(
                EVENT_TYPES.AUTHORISATION,
                ENDPOINT.UI,
                request,
                None,
                description="Updated password.",
            )
            return response

        return self.respond(request, profile_form, password_form)
示例#4
0
文件: prefs.py 项目: ocni-dtu/maas
def userprefsview(request):
    have_external_auth = bool(request.external_auth_info)
    if have_external_auth and request.method == "POST":
        return HttpResponseNotAllowed(["GET"])

    user = request.user
    # Process the profile update form.
    profile_form, response = process_form(
        request,
        ProfileForm,
        reverse("prefs"),
        "profile",
        "Profile updated.",
        {"instance": user},
    )
    if response is not None:
        return response
    if have_external_auth:
        for field in profile_form:
            field.field.disabled = True

    # Process the password change form.
    password_form, response = process_form(
        request,
        PasswordChangeForm,
        reverse("prefs"),
        "password",
        "Password updated.",
        {"user": user},
    )
    password_form.fields["old_password"].widget.attrs.pop("autofocus", None)
    if response is not None:
        create_audit_event(
            EVENT_TYPES.AUTHORISATION,
            ENDPOINT.UI,
            request,
            None,
            description="Updated password.",
        )
        return response

    return render(
        request,
        "maasserver/prefs.html",
        {
            "profile_form": profile_form,
            "password_form": password_form
        },
    )
示例#5
0
def network(request):
    # Process the network form.
    proxy_form, response = process_form(request, ProxyForm,
                                        reverse('settings_network'), 'proxy',
                                        "Configuration updated.")
    if response is not None:
        return response

    # Process the DNS form.
    dns_form, response = process_form(request, DNSForm,
                                      reverse('settings_network'), 'dns',
                                      "Configuration updated.")
    if response is not None:
        return response

    # Process the NTP form.
    ntp_form, response = process_form(request, NTPForm,
                                      reverse('settings_network'), 'ntp',
                                      "Configuration updated.")
    if response is not None:
        return response

    # Process the Syslog form.
    syslog_form, response = process_form(request, SyslogForm,
                                         reverse('settings_network'), 'syslog',
                                         "Configuration updated.")
    if response is not None:
        return response

    # Process the network discovery form.
    network_discovery_form, response = process_form(
        request, NetworkDiscoveryForm, reverse('settings_network'),
        'network_discovery', "Configuration updated.")
    if response is not None:
        return response

    return render(
        request, 'maasserver/settings_network.html', {
            'proxy_form': proxy_form,
            'dns_form': dns_form,
            'ntp_form': ntp_form,
            'syslog_form': syslog_form,
            'network_discovery_form': network_discovery_form,
            'show_license_keys': show_license_keys(),
            'page_name': 'settings',
        })
示例#6
0
    def post(self, request, *args, **kwargs):
        """Called by `TemplateView`: handle a POST request."""
        self.object = user = self.get_object()
        next_page = reverse('settings')

        # Process the profile-editing form, if that's what was submitted.
        profile_form, response = process_form(
            request, EditUserForm, next_page, 'profile', "Profile updated.",
            {'instance': user})
        if response is not None:
            return response

        # Process the password change form, if that's what was submitted.
        password_form, response = process_form(
            request, AdminPasswordChangeForm, next_page, 'password',
            "Password updated.", {'user': user})
        if response is not None:
            return response

        return self.respond(request, profile_form, password_form)
示例#7
0
    def post(self, request, *args, **kwargs):
        """Called by `TemplateView`: handle a POST request."""
        self.object = user = self.get_object()
        next_page = reverse('settings')

        # Process the profile-editing form, if that's what was submitted.
        profile_form, response = process_form(request, EditUserForm, next_page,
                                              'profile', "Profile updated.",
                                              {'instance': user})
        if response is not None:
            create_audit_event(
                EVENT_TYPES.AUTHORISATION,
                ENDPOINT.UI,
                request,
                None,
                description=(
                    "User profile (username: %s, full name: %s, email: %s, "
                    "administrator: %s)" %
                    (profile_form.cleaned_data['username'],
                     profile_form.cleaned_data['last_name'],
                     profile_form.cleaned_data['email'],
                     profile_form.cleaned_data['is_superuser']) +
                    " updated by '%(username)s'."))
            return response

        # Process the password change form, if that's what was submitted.
        password_form, response = process_form(request,
                                               AdminPasswordChangeForm,
                                               next_page, 'password',
                                               "Password updated.",
                                               {'user': user})
        if response is not None:
            create_audit_event(
                EVENT_TYPES.AUTHORISATION,
                ENDPOINT.UI,
                request,
                None,
                description="Password changed for '%(username)s'.")
            return response

        return self.respond(request, profile_form, password_form)
示例#8
0
def userprefsview(request):
    user = request.user
    # Process the profile update form.
    profile_form, response = process_form(request, ProfileForm,
                                          reverse('prefs'), 'profile',
                                          "Profile updated.",
                                          {'instance': user})
    if response is not None:
        return response

    # Process the password change form.
    password_form, response = process_form(request, PasswordChangeForm,
                                           reverse('prefs'), 'password',
                                           "Password updated.", {'user': user})
    if response is not None:
        return response

    return render(request, 'maasserver/prefs.html', {
        'profile_form': profile_form,
        'password_form': password_form
    })
示例#9
0
def userprefsview(request):
    user = request.user
    # Process the profile update form.
    profile_form, response = process_form(
        request, ProfileForm, reverse('prefs'), 'profile', "Profile updated.",
        {'instance': user})
    if response is not None:
        return response

    # Process the password change form.
    password_form, response = process_form(
        request, PasswordChangeForm, reverse('prefs'), 'password',
        "Password updated.", {'user': user})
    if response is not None:
        return response

    return render_to_response(
        'maasserver/prefs.html',
        {
            'profile_form': profile_form,
            'password_form': password_form,
        },
        context_instance=RequestContext(request))
示例#10
0
文件: settings.py 项目: zhangrb/maas
def storage(request):
    storage_settings_form, response = process_form(request,
                                                   StorageSettingsForm,
                                                   reverse('settings_storage'),
                                                   'storage_settings',
                                                   "Configuration updated.")
    if response is not None:
        return response

    return render(
        request, 'maasserver/settings_storage.html', {
            'storage_settings_form': storage_settings_form,
            'show_license_keys': show_license_keys(),
        })
示例#11
0
def storage(request):
    storage_settings_form, response = process_form(
        request,
        StorageSettingsForm,
        reverse("settings_storage"),
        "storage_settings",
        "Configuration updated.",
    )
    if response is not None:
        return response

    return render(
        request,
        "maasserver/settings_storage.html",
        {
            "storage_settings_form": storage_settings_form,
            "show_license_keys": show_license_keys(),
            "page_name": "settings",
        },
    )
示例#12
0
def settings(request):
    user_list = UserProfile.objects.all_users().order_by('username')

    # Process Third Party Drivers form.
    third_party_drivers_form, response = process_form(
        request, ThirdPartyDriversForm, reverse('settings'),
        'third_party_drivers', "Configuration updated.")
    if response is not None:
        return response

    # Process disk erasing on release form.
    storage_settings_form, response = process_form(request,
                                                   StorageSettingsForm,
                                                   reverse('settings'),
                                                   'storage_settings',
                                                   "Configuration updated.")
    if response is not None:
        return response

    # Process the MAAS form.
    maas_form, response = process_form(request, MAASForm, reverse('settings'),
                                       'maas', "Configuration updated.")
    if response is not None:
        return response

    # Process the network form.
    proxy_form, response = process_form(request, ProxyForm,
                                        reverse('settings'), 'proxy',
                                        "Configuration updated.")
    if response is not None:
        return response

    # Process the DNS form.
    dns_form, response = process_form(request, DNSForm, reverse('settings'),
                                      'dns', "Configuration updated.")
    if response is not None:
        return response

    # Process the NTP form.
    ntp_form, response = process_form(request, NTPForm, reverse('settings'),
                                      'ntp', "Configuration updated.")
    if response is not None:
        return response

    # Process the network discovery form.
    network_discovery_form, response = process_form(request,
                                                    NetworkDiscoveryForm,
                                                    reverse('settings'),
                                                    'network_discovery',
                                                    "Configuration updated.")
    if response is not None:
        return response

    # Process the Commissioning form.
    commissioning_form, response = process_form(request, CommissioningForm,
                                                reverse('settings'),
                                                'commissioning',
                                                "Configuration updated.")
    if response is not None:
        return response

    # Process the Deploy form.
    deploy_form, response = process_form(request, DeployForm,
                                         reverse('settings'), 'deploy',
                                         "Configuration updated.")
    if response is not None:
        return response

    # Process the Ubuntu form.
    ubuntu_form, response = process_form(request, UbuntuForm,
                                         reverse('settings'), 'ubuntu',
                                         "Configuration updated.")
    if response is not None:
        return response

    # Process the Windows form.
    windows_form, response = process_form(request, WindowsForm,
                                          reverse('settings'), 'windows',
                                          "Configuration updated.")
    if response is not None:
        return response

    # Process the Global Kernel Opts form.
    kernelopts_form, response = process_form(request, GlobalKernelOptsForm,
                                             reverse('settings'), 'kernelopts',
                                             "Configuration updated.")
    if response is not None:
        return response

    # Commissioning scripts.
    commissioning_scripts = Script.objects.filter(
        script_type=SCRIPT_TYPE.COMMISSIONING)

    # Test scripts.
    test_scripts = Script.objects.filter(script_type=SCRIPT_TYPE.TESTING,
                                         default=False)

    # License keys w/ titles for osystem and distro_series
    osystems = list(gen_all_known_operating_systems())
    show_license_keys = has_osystems_supporting_license_keys(osystems)
    license_keys = LicenseKey.objects.all()
    for license_key in license_keys:
        set_license_key_titles(license_key, osystems)

    return render(
        request, 'maasserver/settings.html', {
            'user_list': user_list,
            'commissioning_scripts': commissioning_scripts,
            'test_scripts': test_scripts,
            'show_license_keys': show_license_keys,
            'license_keys': license_keys,
            'maas_form': maas_form,
            'proxy_form': proxy_form,
            'dns_form': dns_form,
            'ntp_form': ntp_form,
            'network_discovery_form': network_discovery_form,
            'third_party_drivers_form': third_party_drivers_form,
            'storage_settings_form': storage_settings_form,
            'commissioning_form': commissioning_form,
            'deploy_form': deploy_form,
            'ubuntu_form': ubuntu_form,
            'windows_form': windows_form,
            'kernelopts_form': kernelopts_form,
            'external_auth_enabled': bool(request.external_auth_info),
        })
示例#13
0
def general(request):
    # Process Third Party Drivers form.
    third_party_drivers_form, response = process_form(
        request, ThirdPartyDriversForm, reverse('settings_general'),
        'third_party_drivers', "Configuration updated.")
    if response is not None:
        return response

    # Process the MAAS form.
    maas_form, response = process_form(request, MAASForm,
                                       reverse('settings_general'), 'maas',
                                       "Configuration updated.")
    if response is not None:
        return response

    # Process the Commissioning form.
    commissioning_form, response = process_form(request, CommissioningForm,
                                                reverse('settings_general'),
                                                'commissioning',
                                                "Configuration updated.")
    if response is not None:
        return response

    # Process the Deploy form.
    deploy_form, response = process_form(request, DeployForm,
                                         reverse('settings_general'), 'deploy',
                                         "Configuration updated.")
    if response is not None:
        return response

    # Process the Ubuntu form.
    ubuntu_form, response = process_form(request, UbuntuForm,
                                         reverse('settings_general'), 'ubuntu',
                                         "Configuration updated.")
    if response is not None:
        return response

    # Process the Windows form.
    windows_form, response = process_form(request, WindowsForm,
                                          reverse('settings_general'),
                                          'windows', "Configuration updated.")
    if response is not None:
        return response

    # Process the VMware vCenter form.
    vcenter_form, response = process_form(request, VCenterForm,
                                          reverse('settings_general'),
                                          'vcenter', "Configuration updated.")
    if response is not None:
        return response

    # Process the Global Kernel Opts form.
    kernelopts_form, response = process_form(request, GlobalKernelOptsForm,
                                             reverse('settings_general'),
                                             'kernelopts',
                                             "Configuration updated.")
    if response is not None:
        return response

    return render(
        request, 'maasserver/settings_general.html', {
            'maas_form': maas_form,
            'third_party_drivers_form': third_party_drivers_form,
            'commissioning_form': commissioning_form,
            'deploy_form': deploy_form,
            'ubuntu_form': ubuntu_form,
            'windows_form': windows_form,
            'vcenter_form': vcenter_form,
            'kernelopts_form': kernelopts_form,
            'show_license_keys': show_license_keys(),
            'page_name': 'settings',
        })
示例#14
0
def network(request):
    # Process the network form.
    proxy_form, response = process_form(
        request,
        ProxyForm,
        reverse("settings_network"),
        "proxy",
        "Configuration updated.",
    )
    if response is not None:
        return response

    # Process the DNS form.
    dns_form, response = process_form(
        request,
        DNSForm,
        reverse("settings_network"),
        "dns",
        "Configuration updated.",
    )
    if response is not None:
        return response

    # Process the NTP form.
    ntp_form, response = process_form(
        request,
        NTPForm,
        reverse("settings_network"),
        "ntp",
        "Configuration updated.",
    )
    if response is not None:
        return response

    # Process the Syslog form.
    syslog_form, response = process_form(
        request,
        SyslogForm,
        reverse("settings_network"),
        "syslog",
        "Configuration updated.",
    )
    if response is not None:
        return response

    # Process the network discovery form.
    network_discovery_form, response = process_form(
        request,
        NetworkDiscoveryForm,
        reverse("settings_network"),
        "network_discovery",
        "Configuration updated.",
    )
    if response is not None:
        return response

    return render(
        request,
        "maasserver/settings_network.html",
        {
            "proxy_form": proxy_form,
            "dns_form": dns_form,
            "ntp_form": ntp_form,
            "syslog_form": syslog_form,
            "network_discovery_form": network_discovery_form,
            "show_license_keys": show_license_keys(),
            "page_name": "settings",
        },
    )
示例#15
0
def general(request):
    # Process Third Party Drivers form.
    third_party_drivers_form, response = process_form(
        request,
        ThirdPartyDriversForm,
        reverse("settings_general"),
        "third_party_drivers",
        "Configuration updated.",
    )
    if response is not None:
        return response

    # Process the MAAS form.
    maas_form, response = process_form(
        request,
        MAASForm,
        reverse("settings_general"),
        "maas",
        "Configuration updated.",
    )
    if response is not None:
        return response

    # Process the Commissioning form.
    commissioning_form, response = process_form(
        request,
        CommissioningForm,
        reverse("settings_general"),
        "commissioning",
        "Configuration updated.",
    )
    if response is not None:
        return response

    # Process the Deploy form.
    deploy_form, response = process_form(
        request,
        DeployForm,
        reverse("settings_general"),
        "deploy",
        "Configuration updated.",
    )
    if response is not None:
        return response

    # Process the Ubuntu form.
    ubuntu_form, response = process_form(
        request,
        UbuntuForm,
        reverse("settings_general"),
        "ubuntu",
        "Configuration updated.",
    )
    if response is not None:
        return response

    # Process the Windows form.
    windows_form, response = process_form(
        request,
        WindowsForm,
        reverse("settings_general"),
        "windows",
        "Configuration updated.",
    )
    if response is not None:
        return response

    # Process the VMware vCenter form.
    vcenter_form, response = process_form(
        request,
        VCenterForm,
        reverse("settings_general"),
        "vcenter",
        "Configuration updated.",
    )
    if response is not None:
        return response

    # Process the Global Kernel Opts form.
    kernelopts_form, response = process_form(
        request,
        GlobalKernelOptsForm,
        reverse("settings_general"),
        "kernelopts",
        "Configuration updated.",
    )
    if response is not None:
        return response

    return render(
        request,
        "maasserver/settings_general.html",
        {
            "maas_form": maas_form,
            "third_party_drivers_form": third_party_drivers_form,
            "commissioning_form": commissioning_form,
            "deploy_form": deploy_form,
            "ubuntu_form": ubuntu_form,
            "windows_form": windows_form,
            "vcenter_form": vcenter_form,
            "kernelopts_form": kernelopts_form,
            "show_license_keys": show_license_keys(),
            "page_name": "settings",
        },
    )
示例#16
0
def settings(request):
    user_list = UserProfile.objects.all_users().order_by('username')
    # Process the MAAS & network form.
    maas_and_network_form, response = process_form(
        request, MAASAndNetworkForm, reverse('settings'), 'maas_and_network',
        "Configuration updated.")
    if response is not None:
        return response

    # Process the Commissioning form.
    commissioning_form, response = process_form(
        request, CommissioningForm, reverse('settings'), 'commissioning',
        "Configuration updated.")
    if response is not None:
        return response

    # Process the Ubuntu form.
    ubuntu_form, response = process_form(
        request, UbuntuForm, reverse('settings'), 'ubuntu',
        "Configuration updated.")
    if response is not None:
        return response

    # Process the Global Kernel Opts form.
    kernelopts_form, response = process_form(
        request, GlobalKernelOptsForm, reverse('settings'), 'kernelopts',
        "Configuration updated.")
    if response is not None:
        return response

    # Process accept clusters en masse.
    if 'mass_accept_submit' in request.POST:
        number = NodeGroup.objects.accept_all_pending()
        messages.info(request, "Accepted %d cluster(s)." % number)
        return HttpResponseRedirect(reverse('settings'))

    # Process reject clusters en masse.
    if 'mass_reject_submit' in request.POST:
        number = NodeGroup.objects.reject_all_pending()
        messages.info(request, "Rejected %d cluster(s)." % number)
        return HttpResponseRedirect(reverse('settings'))

    # Import PXE files for all the accepted clusters.
    if 'import_all_boot_images' in request.POST:
        NodeGroup.objects.import_boot_images_accepted_clusters()
        message = (
            "Import of boot images started on all cluster controllers.  "
            "Importing the boot images can take a long time depending on "
            "the available bandwidth.")
        messages.info(request, message)
        return HttpResponseRedirect(reverse('settings'))

    # Cluster listings.
    accepted_clusters = NodeGroup.objects.filter(
        status=NODEGROUP_STATUS.ACCEPTED).order_by('cluster_name')
    pending_clusters = NodeGroup.objects.filter(
        status=NODEGROUP_STATUS.PENDING).order_by('cluster_name')
    rejected_clusters = NodeGroup.objects.filter(
        status=NODEGROUP_STATUS.REJECTED).order_by('cluster_name')

    # Commissioning scripts.
    commissioning_scripts = CommissioningScript.objects.all()

    return render_to_response(
        'maasserver/settings.html',
        {
            'user_list': user_list,
            'commissioning_scripts': commissioning_scripts,
            'accepted_clusters': accepted_clusters,
            'pending_clusters': pending_clusters,
            'rejected_clusters': rejected_clusters,
            'maas_and_network_form': maas_and_network_form,
            'commissioning_form': commissioning_form,
            'ubuntu_form': ubuntu_form,
            'kernelopts_form': kernelopts_form,
        },
        context_instance=RequestContext(request))