mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
+13
-9
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from django.shortcuts import get_object_or_404, render_to_response
|
||||
from django.template.loader import render_to_string
|
||||
from django.template import RequestContext
|
||||
@@ -18,6 +19,7 @@ from mailng.lib import _render, _ctx_ok, _ctx_ko
|
||||
from mailng.lib import events
|
||||
import string
|
||||
import copy
|
||||
import pwd
|
||||
|
||||
def is_superuser(user):
|
||||
if not user.is_superuser:
|
||||
@@ -157,6 +159,8 @@ def newmailbox(request, dom_id=None):
|
||||
else:
|
||||
mb = form.save(commit=False)
|
||||
if mb.create_dir(domain):
|
||||
from django.conf import settings
|
||||
|
||||
user = User()
|
||||
user.username = user.email = "%s@%s" % (mb.address, domain.name)
|
||||
user.set_unusable_password()
|
||||
@@ -174,7 +178,8 @@ def newmailbox(request, dom_id=None):
|
||||
|
||||
mb.password = crypt_password(request.POST["password1"])
|
||||
|
||||
mb.uid = mb.gid = 500
|
||||
mb.uid = pwd.getpwnam(settings.VIRTUAL_UID).pw_uid
|
||||
mb.gid = pwd.getpwnam(settings.VIRTUAL_GID).pw_gid
|
||||
mb.domain = domain
|
||||
mb.quota = request.POST["quota"]
|
||||
if not mb.quota:
|
||||
@@ -218,13 +223,12 @@ def editmailbox(request, dom_id, mbox_id=None):
|
||||
error = _("Failed to rename mailbox, check permissions")
|
||||
if not error:
|
||||
mb = form.save(commit=False)
|
||||
enabled = request.POST.has_key("enabled") \
|
||||
mb.user.is_active = request.POST.has_key("enabled") \
|
||||
and request.POST["enabled"] or False
|
||||
if enabled != mb.user.is_active \
|
||||
or request.POST["password1"] != mb.user.password:
|
||||
mb.user.is_active = enabled
|
||||
mb.user.password = request.POST["password1"]
|
||||
mb.user.save()
|
||||
mb.user.save()
|
||||
|
||||
if request.POST["password1"] != u"é":
|
||||
mb.password = crypt_password(request.POST["password1"])
|
||||
mb.quota = request.POST["quota"]
|
||||
if not mb.quota:
|
||||
mb.quota = mb.domain.quota
|
||||
@@ -242,8 +246,8 @@ def editmailbox(request, dom_id, mbox_id=None):
|
||||
form = MailboxForm(instance=mb)
|
||||
form.fields['quota'].initial = mb.quota
|
||||
form.fields['enabled'].initial = mb.user.is_active
|
||||
form.fields['password1'].initial = mb.user.password
|
||||
form.fields['password2'].initial = mb.user.password
|
||||
form.fields['password1'].initial = "é"
|
||||
form.fields['password2'].initial = "é"
|
||||
return _render(request, 'admin/editmailbox.html', {
|
||||
"form" : form, "mbox" : mb
|
||||
})
|
||||
|
||||
@@ -37,15 +37,6 @@ def exec_pipe(cmd):
|
||||
code = -1
|
||||
return code, output
|
||||
|
||||
def crypt_password(raw_password):
|
||||
import md5
|
||||
import random
|
||||
|
||||
salt = md5.new(str(random.random) + str(random.random)).hexdigest()
|
||||
salt = salt[:5]
|
||||
hash = md5.new(salt + raw_password).hexdigest()
|
||||
return "%s$%s$%s" % ("md5", salt, hash)
|
||||
|
||||
def _render(request, tpl, user_context):
|
||||
return render_to_response(tpl, user_context,
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
+16
-4
@@ -1,5 +1,6 @@
|
||||
from django.contrib.auth.models import User
|
||||
from mailng.admin.models import Mailbox
|
||||
from django.conf import settings
|
||||
import hashlib
|
||||
import crypt
|
||||
import string
|
||||
@@ -25,15 +26,26 @@ class SimpleBackend:
|
||||
except User.DoesNotExist:
|
||||
return None
|
||||
|
||||
def __get_password_scheme():
|
||||
try:
|
||||
scheme = getattr(settings, "PASSWORD_SCHEME")
|
||||
except AttributeError:
|
||||
scheme = "crypt"
|
||||
return scheme
|
||||
|
||||
def check_password(password, crypted):
|
||||
if True:
|
||||
scheme = __get_password_scheme()
|
||||
if scheme == "crypt":
|
||||
return crypt.crypt(password, crypted) == crypted
|
||||
else:
|
||||
if scheme == "md5":
|
||||
return hashlib.md5(password).hexdigest() == crypted
|
||||
return password
|
||||
|
||||
def crypt_password(password):
|
||||
if True:
|
||||
scheme = __get_password_scheme()
|
||||
if scheme == "crypt":
|
||||
salt = ''.join(Random().sample(string.letters + string.digits, 2))
|
||||
return crypt.crypt(password, salt)
|
||||
else:
|
||||
if scheme == "md5":
|
||||
return hashlib.md5(password).hexdigest()
|
||||
return password
|
||||
|
||||
@@ -96,6 +96,7 @@ AUTHENTICATION_BACKENDS = (
|
||||
STORAGE_PATH = "/var/vmail"
|
||||
VIRTUAL_UID = "vmail"
|
||||
VIRTUAL_GID = "vmail"
|
||||
PASSWORD_SCHEME = "crypt" # Possible values : crypt, md5 or "" for clear passwords
|
||||
|
||||
# Mailboxes format: maildir (default) or mbox
|
||||
# MAILBOX_TYPE = ""
|
||||
|
||||
Reference in New Issue
Block a user