示例#1
0
    def __init__(self, user_search_string, search_by):
        super().__init__(user_search_string, search_by)
        self.FREEIPA_SERVER = import_from_settings('FREEIPA_SERVER')
        self.FREEIPA_USER_SEARCH_BASE = import_from_settings(
            'FREEIPA_USER_SEARCH_BASE', 'cn=users,cn=accounts')
        self.FREEIPA_KTNAME = import_from_settings('FREEIPA_KTNAME', '')

        self.server = Server('ldap://{}'.format(self.FREEIPA_SERVER),
                             use_ssl=True,
                             connect_timeout=1)
        if len(self.FREEIPA_KTNAME) > 0:
            logger.info('Kerberos bind enabled: %s', self.FREEIPA_KTNAME)
            # kerberos SASL/GSSAPI bind
            os.environ["KRB5_CLIENT_KTNAME"] = self.FREEIPA_KTNAME
            self.conn = Connection(self.server,
                                   authentication=SASL,
                                   sasl_mechanism=KERBEROS,
                                   auto_bind=True)
        else:
            # anonomous bind
            self.conn = Connection(self.server, auto_bind=True)

        if not self.conn.bind():
            raise ImproperlyConfigured(
                'Failed to bind to LDAP server: {}'.format(self.conn.result))
        else:
            logger.info('LDAP bind successful: %s',
                        self.conn.extend.standard.who_am_i())
示例#2
0
 def __init__(self):
     self.SYSTEM_MONITOR_ENDPOINT = import_from_settings('SYSTEM_MONITOR_ENDPOINT')
     self.SYSTEM_MONITOR_PANEL_TITLE = import_from_settings('SYSTEM_MONITOR_PANEL_TITLE')
     self.response = None
     self.data = {}
     self.parse_function = getattr(self, self.RESPONSE_PARSER_FUNCTION)
     self.fetch_data()
示例#3
0
def get_system_monitor_context():
    context = {}
    system_monitor = SystemMonitor()
    system_monitor_data = system_monitor.get_data()
    system_monitor_panel_title = system_monitor.get_panel_title()

    context['last_updated'] = system_monitor_data.get('last_updated')
    context['utilization_data'] = system_monitor_data.get('utilization_data')
    context['jobs_data'] = system_monitor_data.get('jobs_data')
    context['system_monitor_panel_title'] = system_monitor_panel_title
    context['SYSTEM_MONITOR_DISPLAY_XDMOD_LINK'] = import_from_settings('SYSTEM_MONITOR_DISPLAY_XDMOD_LINK', None)
    context['SYSTEM_MONITOR_DISPLAY_MORE_STATUS_INFO_LINK'] = import_from_settings('SYSTEM_MONITOR_DISPLAY_MORE_STATUS_INFO_LINK', None)

    return context
示例#4
0
    def __init__(self, user_search_string, search_by):
        super().__init__(user_search_string, search_by)
        self.LDAP_SERVER_URI = import_from_settings('LDAP_SERVER_URI')
        self.LDAP_USER_SEARCH_BASE = import_from_settings(
            'LDAP_USER_SEARCH_BASE')
        self.LDAP_BIND_DN = import_from_settings('LDAP_BIND_DN', None)
        self.LDAP_BIND_PASSWORD = import_from_settings('LDAP_BIND_PASSWORD',
                                                       None)

        self.server = Server(self.LDAP_SERVER_URI,
                             use_ssl=True,
                             connect_timeout=1)
        self.conn = Connection(self.server,
                               self.LDAP_BIND_DN,
                               self.LDAP_BIND_PASSWORD,
                               auto_bind=True)
示例#5
0
 def __init__(self, username, groups):
     """Initialize settings."""
     self.IQUOTA_API_HOST = import_from_settings('IQUOTA_API_HOST')
     self.IQUOTA_API_PORT = import_from_settings('IQUOTA_API_PORT')
     self.IQUOTA_CA_CERT = import_from_settings('IQUOTA_CA_CERT')
     self.IQUOTA_USER_PATH = import_from_settings('IQUOTA_USER_PATH')
     self.IQUOTA_GROUP_PATH = import_from_settings('IQUOTA_GROUP_PATH')
     self.IQUOTA_KEYTAB = import_from_settings('IQUOTA_KEYTAB')
     self.username = username
     self.groups = groups
示例#6
0
                                            ProjectUserStatusChoice)
from core.djangoapps.subscription.forms import (SubscriptionAddUserForm,
                                                SubscriptionDeleteUserForm,
                                                SubscriptionForm,
                                                SubscriptionReviewUserForm,
                                                SubscriptionSearchForm)
from core.djangoapps.subscription.models import (Subscription,
                                                 SubscriptionStatusChoice,
                                                 SubscriptionUser,
                                                 SubscriptionUserStatusChoice)
from core.djangoapps.subscription.signals import (subscription_activate_user,
                                                  subscription_remove_user)
from core.djangoapps.subscription.utils import (
    generate_guauge_data_from_usage, get_user_resources)

EMAIL_ENABLED = import_from_settings('EMAIL_ENABLED', False)
if EMAIL_ENABLED:
    EMAIL_DEVELOPMENT_EMAIL_LIST = import_from_settings(
        'EMAIL_DEVELOPMENT_EMAIL_LIST')
    EMAIL_SUBJECT_PREFIX = import_from_settings('EMAIL_SUBJECT_PREFIX')
    EMAIL_SENDER = import_from_settings('EMAIL_SENDER')
    EMAIL_TICKET_SYSTEM_ADDRESS = import_from_settings(
        'EMAIL_TICKET_SYSTEM_ADDRESS')
    EMAIL_OPT_OUT_INSTRUCTION_URL = import_from_settings(
        'EMAIL_OPT_OUT_INSTRUCTION_URL')
    EMAIL_SIGNATURE = import_from_settings('EMAIL_SIGNATURE')
    EMAIL_CENTER_NAME = import_from_settings('CENTER_NAME')

logger = logging.getLogger(__name__)

示例#7
0
    ProjectAddUserForm, ProjectAddUsersToSubscriptionForm,
    ProjectRemoveUserForm, ProjectReviewEmailForm, ProjectReviewForm,
    ProjectSearchForm, ProjectUserUpdateForm)
from core.djangoapps.project.models import (Project, ProjectReview,
                                            ProjectReviewStatusChoice,
                                            ProjectStatusChoice, ProjectUser,
                                            ProjectUserRoleChoice,
                                            ProjectUserStatusChoice)
from core.djangoapps.publication.models import Publication
from core.djangoapps.subscription.models import (Subscription,
                                                 SubscriptionUser,
                                                 SubscriptionUserStatusChoice)
from core.djangoapps.subscription.signals import (subscription_activate_user,
                                                  subscription_remove_user)

EMAIL_ENABLED = import_from_settings('EMAIL_ENABLED', False)
if EMAIL_ENABLED:
    EMAIL_DIRECTOR_EMAIL_ADDRESS = import_from_settings(
        'EMAIL_DIRECTOR_EMAIL_ADDRESS')
    EMAIL_DEVELOPMENT_EMAIL_LIST = import_from_settings(
        'EMAIL_DEVELOPMENT_EMAIL_LIST')
    EMAIL_SUBJECT_PREFIX = import_from_settings('EMAIL_SUBJECT_PREFIX')
    EMAIL_SENDER = import_from_settings('EMAIL_SENDER')


class ProjectDetailView(LoginRequiredMixin, UserPassesTestMixin, DetailView):
    model = Project
    template_name = 'project/project_detail.html'
    context_object_name = 'project'
    login_url = "/"  # redirect URL if fail test_func
示例#8
0
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.views import View
from django.views.generic import TemplateView

from common.djangoapps.user.forms import UserSearchForm
from common.djangoapps.user.utils import CombinedUserSearch
from common.djangolibs.mail import send_email_template
from common.djangolibs.utils import import_from_settings

logger = logging.getLogger(__name__)
EMAIL_ENABLED = import_from_settings('EMAIL_ENABLED', False)
if EMAIL_ENABLED:
    EMAIL_TICKET_SYSTEM_ADDRESS = import_from_settings(
        'EMAIL_TICKET_SYSTEM_ADDRESS')


@method_decorator(login_required, name='dispatch')
class UserProfile(TemplateView):
    template_name = 'user/user_profile.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        group_list = ', '.join(
            [group.name for group in self.request.user.groups.all()])
        context['group_list'] = group_list
        return context
示例#9
0
import logging
import shlex
import subprocess
import csv
from io import StringIO

from common.djangolibs.utils import import_from_settings

SLURM_CLUSTER_ATTRIBUTE_NAME = import_from_settings(
    'SLURM_CLUSTER_ATTRIBUTE_NAME', 'slurm_cluster')
SLURM_ACCOUNT_ATTRIBUTE_NAME = import_from_settings(
    'SLURM_ACCOUNT_ATTRIBUTE_NAME', 'slurm_account_name')
SLURM_SPECS_ATTRIBUTE_NAME = import_from_settings('SLURM_SPECS_ATTRIBUTE_NAME',
                                                  'slurm_specs')
SLURM_USER_SPECS_ATTRIBUTE_NAME = import_from_settings(
    'SLURM_USER_SPECS_ATTRIBUTE_NAME', 'slurm_user_specs')
SLURM_NOOP = import_from_settings('SLURM_NOOP', False)
SLURM_SACCTMGR_PATH = import_from_settings('SLURM_SACCTMGR_PATH',
                                           '/usr/bin/sacctmgr')
SLURM_CMD_REMOVE_USER = SLURM_SACCTMGR_PATH + ' -Q -i delete user where name={} cluster={} account={}'
SLURM_CMD_ADD_USER = SLURM_SACCTMGR_PATH + ' -Q -i create user name={} cluster={} account={}'
SLURM_CMD_CHECK_ASSOCIATION = SLURM_SACCTMGR_PATH + ' list associations User={} Cluster={} Account={} Format=Cluster,Account,User,QOS -P'
SLURM_CMD_BLOCK_ACCOUNT = SLURM_SACCTMGR_PATH + ' -Q -i modify account {} where Cluster={} set GrpSubmitJobs=0'

logger = logging.getLogger(__name__)


def _run_slurm_cmd(cmd, noop=True):
    if noop:
        logger.warn('NOOP - Slurm cmd: %s', cmd)
        return
示例#10
0
文件: mail.py 项目: aculich/coldfront
import logging
from smtplib import SMTPException

from django.conf import settings
from django.core.mail import send_mail
from django.template.loader import render_to_string

from common.djangolibs.utils import import_from_settings

logger = logging.getLogger(__name__)
EMAIL_ENABLED = import_from_settings('EMAIL_ENABLED', False)
if EMAIL_ENABLED:
    EMAIL_SUBJECT_PREFIX = import_from_settings('EMAIL_SUBJECT_PREFIX')
    EMAIL_DEVELOPMENT_EMAIL_LIST = import_from_settings('EMAIL_DEVELOPMENT_EMAIL_LIST')


def send_email(subject, body, sender, receiver_list):
    """Helper function for sending emails
    """

    if not EMAIL_ENABLED:
        return

    if len(receiver_list) == 0:
        logger.error('Failed to send email missing receiver_list')
        return

    if len(sender) == 0:
        logger.error('Failed to send email missing sender address')
        return
示例#11
0
import datetime

from django import forms
from django.shortcuts import get_object_or_404

from common.djangolibs.utils import import_from_settings
from core.djangoapps.project.models import (Project, ProjectReview,
                                            ProjectUserRoleChoice)

EMAIL_DIRECTOR_PENDING_PROJECT_REVIEW_EMAIL = import_from_settings(
    'EMAIL_DIRECTOR_PENDING_PROJECT_REVIEW_EMAIL')


class ProjectSearchForm(forms.Form):
    """ Search form for the Project list page.
    """
    LAST_NAME = 'Last Name'
    USERNAME = '******'
    FIELD_OF_SCIENCE = 'Field of Science'

    last_name = forms.CharField(label=LAST_NAME,
                                max_length=100,
                                required=False)
    username = forms.CharField(label=USERNAME, max_length=100, required=False)
    field_of_science = forms.CharField(label=FIELD_OF_SCIENCE,
                                       max_length=100,
                                       required=False)
    show_all_projects = forms.BooleanField(initial=False, required=False)


class ProjectAddUserForm(forms.Form):
示例#12
0
import datetime
# import the logging library
import logging

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

from core.djangoapps.subscription.models import (Subscription,
                                                 SubscriptionStatusChoice)

from common.djangolibs.utils import get_domain_url, import_from_settings
from common.djangolibs.mail import send_email_template
# Get an instance of a logger
logger = logging.getLogger(__name__)

CENTER_NAME = import_from_settings('CENTER_NAME')
CENTER_BASE_URL = import_from_settings('CENTER_BASE_URL')
CENTER_PROJECT_RENEWAL_HELP_URL = import_from_settings(
    'CENTER_PROJECT_RENEWAL_HELP_URL')
EMAIL_SENDER = import_from_settings('EMAIL_SENDER')
EMAIL_OPT_OUT_INSTRUCTION_URL = import_from_settings(
    'EMAIL_OPT_OUT_INSTRUCTION_URL')
EMAIL_SIGNATURE = import_from_settings('EMAIL_SIGNATURE')
EMAIL_SUBSCRIPTION_EXPIRING_NOTIFICATION_DAYS = import_from_settings(
    'EMAIL_SUBSCRIPTION_EXPIRING_NOTIFICATION_DAYS', [
        7,
    ])


def update_statuses():
示例#13
0
import logging
import os

from django.core.exceptions import ImproperlyConfigured
from common.djangolibs.utils import import_from_settings

from ipalib import api

CLIENT_KTNAME = import_from_settings('FREEIPA_KTNAME')
UNIX_GROUP_ATTRIBUTE_NAME = import_from_settings(
    'FREEIPA_GROUP_ATTRIBUTE_NAME', 'freeipa_group')
FREEIPA_NOOP = import_from_settings('FREEIPA_NOOP', False)

logger = logging.getLogger(__name__)

try:
    os.environ["KRB5_CLIENT_KTNAME"] = CLIENT_KTNAME
    api.bootstrap()
    api.finalize()
    api.Backend.rpcclient.connect()
except Exception as e:
    logger.error("Failed to initialze FreeIPA lib: %s", e)
    raise ImproperlyConfigured('Failed to initialze FreeIPA: {0}'.format(e))


def check_ipa_group_error(res):
    if not res:
        raise ValueError('Missing FreeIPA response')

    if res['completed'] == 1:
        return
示例#14
0
import logging

from django.contrib.auth.models import Group

from common.djangolibs.utils import import_from_settings
from mozilla_django_oidc.auth import OIDCAuthenticationBackend

logger = logging.getLogger(__name__)

PI_GROUP = import_from_settings('MOKEY_OIDC_PI_GROUP', 'pi')
ALLOWED_GROUPS = import_from_settings('MOKEY_OIDC_ALLOWED_GROUPS', [])
DENY_GROUPS = import_from_settings('MOKEY_OIDC_DENY_GROUPS', [])


class OIDCMokeyAuthenticationBackend(OIDCAuthenticationBackend):
    def _sync_groups(self, user, groups):
        is_pi = False
        user.groups.clear()
        for group_name in groups:
            group, created = Group.objects.get_or_create(name=group_name)
            user.groups.add(group)
            if group_name == PI_GROUP:
                is_pi = True

        user.userprofile.is_pi = is_pi

    def create_user(self, claims):
        email = claims.get('email')
        username = claims.get('uid')
        if not username:
            logger.error(
示例#15
0
 def __init__(self, user_search_string, search_by, usernames_names_to_exclude=[]):
     self.USER_SEARCH_CLASSES = import_from_settings('ADDITIONAL_USER_SEARCH_CLASSES', [])
     self.USER_SEARCH_CLASSES.insert(0, 'common.djangoapps.user.utils.LocalUserSearch')
     self.user_search_string = user_search_string
     self.search_by = search_by
     self.usernames_names_to_exclude = usernames_names_to_exclude