def get_context(self, saas):
     context = super(DokuWikiMuController, self).get_context(saas)
     domain = saas.get_site_domain()
     context.update({
         'template':
         settings.SAAS_DOKUWIKI_TEMPLATE_PATH,
         'farm_path':
         os.path.normpath(settings.SAAS_DOKUWIKI_FARM_PATH),
         'app_path':
         os.path.join(settings.SAAS_DOKUWIKI_FARM_PATH, domain),
         'user':
         settings.SAAS_DOKUWIKI_USER,
         'group':
         settings.SAAS_DOKUWIKI_GROUP,
         'email':
         saas.account.email,
         'custom_url':
         saas.custom_url,
         'domain':
         domain,
     })
     if saas.custom_url:
         custom_url = urlparse(saas.custom_url)
         context.update({
             'custom_domain': custom_url.netloc,
         })
     password = getattr(saas, 'password', None)
     salt = random_ascii(8)
     context.update({
         'password':
         crypt.crypt(password, '$1$' + salt) if password else None,
         'users_path':
         os.path.join(context['app_path'], 'conf/users.auth.php'),
     })
     return context
Beispiel #2
0
 def get_context(self, saas):
     context = super(DokuWikiMuBackend, self).get_context(saas)
     domain = saas.get_site_domain()
     context.update({
         'template': settings.SAAS_DOKUWIKI_TEMPLATE_PATH,
         'farm_path': os.path.normpath(settings.SAAS_DOKUWIKI_FARM_PATH),
         'app_path': os.path.join(settings.SAAS_DOKUWIKI_FARM_PATH, domain),
         'user': settings.SAAS_DOKUWIKI_USER,
         'group': settings.SAAS_DOKUWIKI_GROUP,
         'email': saas.account.email,
         'custom_url': saas.custom_url,
         'domain': domain,
     })
     if saas.custom_url:
         custom_url = urlparse(saas.custom_url)
         context.update({
             'custom_domain': custom_url.netloc,
         })
     password = getattr(saas, 'password', None)
     salt = random_ascii(8)
     context.update({
         'password': crypt.crypt(password, '$1$'+salt) if password else None,
         'users_path': os.path.join(context['app_path'], 'conf/users.auth.php'),
     })
     return context
Beispiel #3
0
 def __init__(self, *args, **kwargs):
     super(SaaSPasswordForm, self).__init__(*args, **kwargs)
     if self.is_change:
         self.fields['password1'].required = False
         self.fields['password1'].widget = forms.HiddenInput()
         self.fields['password2'].required = False
         self.fields['password2'].widget = forms.HiddenInput()
     else:
         self.fields['password'].widget = forms.HiddenInput()
         self.fields['password1'].help_text = _("Suggestion: %s") % random_ascii(10)
Beispiel #4
0
 def __init__(self, *args, **kwargs):
     super(SaaSPasswordForm, self).__init__(*args, **kwargs)
     if self.is_change:
         self.fields['password1'].required = False
         self.fields['password1'].widget = forms.HiddenInput()
         self.fields['password2'].required = False
         self.fields['password2'].widget = forms.HiddenInput()
     else:
         self.fields['password'].widget = forms.HiddenInput()
         self.fields['password1'].help_text = _(
             "Suggestion: %s") % random_ascii(10)
Beispiel #5
0
 def __init__(self, *args, **kwargs):
     super(SoftwareServiceForm, self).__init__(*args, **kwargs)
     self.is_change = bool(self.instance and self.instance.pk)
     if self.is_change:
         site_domain = self.instance.get_site_domain()
         self.fields['password1'].required = False
         self.fields['password1'].widget = forms.HiddenInput()
         self.fields['password2'].required = False
         self.fields['password2'].widget = forms.HiddenInput()
     else:
         self.fields['password'].widget = forms.HiddenInput()
         self.fields['password1'].help_text = _("Suggestion: %s") % random_ascii(10)
         site_domain = self.plugin.site_domain
     if site_domain:
         site_link = '<a href="http://%s">%s</a>' % (site_domain, site_domain)
     else:
         site_link = '&lt;site_name&gt;.%s' % self.plugin.site_base_domain
     self.fields['site_url'].widget.display = site_link
     self.fields['name'].label = _("Username")
Beispiel #6
0
 def __init__(self, *args, **kwargs):
     super(UserCreationForm, self).__init__(*args, **kwargs)
     self.fields['password1'].help_text = _("Suggestion: %s") % random_ascii(10)
Beispiel #7
0
 def get_password(self):
     return random_ascii(10)
Beispiel #8
0
    def handle(self, *args, **options):
        interactive = options.get('interactive')
        db_password = options.get('db_password')
        context = {
            'db_name': options.get('db_name'),
            'db_user': options.get('db_user'),
            'db_password': db_password,
            'db_host': options.get('db_host'),
            'db_port': options.get('db_port'),
            'default_db_password': db_password or random_ascii(10),
        }

        create_user = "******"
        alter_user = "******"
        create_database = "CREATE DATABASE %(db_name)s OWNER %(db_user)s;"

        # Create or update user
        if self.run_postgres(create_user % context,
                             valid_codes=(0, 1)).exit_code == 1:
            if interactive and not db_password:
                msg = (
                    "Postgres user '%(db_user)s' already exists, "
                    "please provide a password [%(default_db_password)s]: " %
                    context)
                context['db_password'] = input(
                    msg) or context['default_db_password']
                self.run_postgres(alter_user % context)
                msg = "Updated Postgres user '%(db_user)s' password: '******'"
                self.stdout.write(msg % context)
            elif db_password:
                self.run_postgres(alter_user % context)
                msg = "Updated Postgres user '%(db_user)s' password: '******'"
                self.stdout.write(msg % context)
            else:
                raise CommandError(
                    "Postgres user '%(db_user)s' already exists and "
                    "--db_password has not been provided." % context)
        else:
            context['db_password'] = context['default_db_password']
            msg = "Created new Postgres user '%(db_user)s' with password '%(db_password)s'"
            self.stdout.write(msg % context)
        self.run_postgres(create_database % context, valid_codes=(0, 1))

        context.update(
            {'settings': os.path.join(get_project_dir(), 'settings.py')})

        if run("grep '^DATABASES\s*=\s*{' %(settings)s" % context,
               valid_codes=(0, 1)).exit_code == 0:
            # Update existing settings_file
            run(
                textwrap.dedent("""sed -i \\
                -e "s/'ENGINE':[^#]*/'ENGINE': 'django.db.backends.postgresql_psycopg2',  /" \\
                -e "s/'NAME':[^#]*/'NAME': '%(db_name)s',  /" \\
                -e "s/'USER':[^#]*/'USER': '******',  /" \\
                -e "s/'PASSWORD':[^#]*/'PASSWORD': '******',  /" \\
                -e "s/'HOST':[^#]*/'HOST': '%(db_host)s',  /" \\
                -e "s/'PORT':[^#]*/'PORT': '%(db_port)s',  /" %(settings)s\
                """) % context)
        else:
            db_config = textwrap.dedent("""\
                DATABASES = {
                    'default': {
                        'ENGINE': 'django.db.backends.postgresql_psycopg2',
                        'NAME': '%(db_name)s',
                        'USER': '******',
                        'PASSWORD': '******',
                        'HOST': '%(db_host)s',
                        'PORT': '%(db_port)s',
                        'ATOMIC_REQUESTS': True,
                    }
                }""") % context
            context.update({'db_config': db_config})
            run('echo "%(db_config)s" >> %(settings)s' % context)
 def handle(self, *args, **options):
     interactive = options.get('interactive')
     db_password = options.get('db_password')
     context = {
         'db_name': options.get('db_name'),
         'db_user': options.get('db_user'),
         'db_password': db_password,
         'db_host': options.get('db_host'),
         'db_port': options.get('db_port'),
         'default_db_password': db_password or random_ascii(10),
     }
     
     create_user = "******"
     alter_user = "******"
     create_database = "CREATE DATABASE %(db_name)s OWNER %(db_user)s;"
     
     # Create or update user
     if self.run_postgres(create_user % context, valid_codes=(0,1)).exit_code == 1:
         if interactive and not db_password:
             msg = ("Postgres user '%(db_user)s' already exists, "
                    "please provide a password [%(default_db_password)s]: " % context)
             context['db_password'] = input(msg) or context['default_db_password']
             self.run_postgres(alter_user % context)
             msg = "Updated Postgres user '%(db_user)s' password: '******'"
             self.stdout.write(msg % context)
         elif db_password:
             self.run_postgres(alter_user % context)
             msg = "Updated Postgres user '%(db_user)s' password: '******'"
             self.stdout.write(msg % context)
         else:
             raise CommandError("Postgres user '%(db_user)s' already exists and "
                                "--db_pass has not been provided." % context)
     else:
         context['db_password'] = context['default_db_password']
         msg = "Created new Postgres user '%(db_user)s' with password '%(db_password)s'"
         self.stdout.write(msg % context)
     self.run_postgres(create_database % context, valid_codes=(0,1))
     
     context.update({
         'settings': os.path.join(get_project_dir(), 'settings.py')
     })
     
     if run("grep '^DATABASES\s*=\s*{' %(settings)s" % context, valid_codes=(0,1)).exit_code == 0:
         # Update existing settings_file
         run(textwrap.dedent("""sed -i \\
             -e "s/'ENGINE':[^#]*/'ENGINE': 'django.db.backends.postgresql_psycopg2',  /" \\
             -e "s/'NAME':[^#]*/'NAME': '%(db_name)s',  /" \\
             -e "s/'USER':[^#]*/'USER': '******',  /" \\
             -e "s/'PASSWORD':[^#]*/'PASSWORD': '******',  /" \\
             -e "s/'HOST':[^#]*/'HOST': '%(db_host)s',  /" \\
             -e "s/'PORT':[^#]*/'PORT': '%(db_port)s',  /" %(settings)s\
             """) % context
         )
     else:
         db_config = textwrap.dedent("""\
             DATABASES = {
                 'default': {
                     'ENGINE': 'django.db.backends.postgresql_psycopg2',
                     'NAME': '%(db_name)s',
                     'USER': '******',
                     'PASSWORD': '******',
                     'HOST': '%(db_host)s',
                     'PORT': '%(db_port)s',
                     'ATOMIC_REQUESTS': True,
                 }
             }""") % context
         context.update({
             'db_config': db_config
         })
         run('echo "%(db_config)s" >> %(settings)s' % context)
Beispiel #10
0
 def __init__(self, *args, **kwargs):
     super(UserCreationForm, self).__init__(*args, **kwargs)
     self.fields['password1'].help_text = _(
         "Suggestion: %s") % random_ascii(10)
Beispiel #11
0
 def get_password(self):
     return random_ascii(10)