- working with sqlalchemy 0.3.10
- remove duplicate foreign key definitions from tables.py - use _saltchars in passwordutils.py git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@240 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
parent
aaa23c9c5f
commit
f24de13a6f
8 changed files with 63 additions and 47 deletions
0
data/templates/home/README
Normal file
0
data/templates/home/README
Normal file
|
@ -1,4 +1,4 @@
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 by Jan Dittberner.
|
# Copyright (C) 2007 by Jan Dittberner.
|
||||||
#
|
#
|
||||||
|
@ -64,6 +64,23 @@ class BackendEntity(object):
|
||||||
self.logger.info("%s: %s", toexec, sts[1])
|
self.logger.info("%s: %s", toexec, sts[1])
|
||||||
return sts[1]
|
return sts[1]
|
||||||
|
|
||||||
|
def supipe(self, cmdlines):
|
||||||
|
"""Executes multiple commands as root and pipes the output of
|
||||||
|
the commands to the input of the next commands."""
|
||||||
|
self.logger.debug("supipe called: %s", " | ".join(cmdlines))
|
||||||
|
suwrapper = config.get('common', 'suwrapper')
|
||||||
|
predecessor = None
|
||||||
|
for cmdline in cmdlines:
|
||||||
|
toexec = "%s %s" % (suwrapper, cmdline)
|
||||||
|
if predecessor is None:
|
||||||
|
p = Popen(toexec, shell = True, stdout = PIPE)
|
||||||
|
else:
|
||||||
|
p = Popen(toexec, shell = True, stdin = predecessor.stdout,
|
||||||
|
stdout = PIPE)
|
||||||
|
predecessor = p
|
||||||
|
output = predecessor.communicate()[0]
|
||||||
|
return predecessor.wait()
|
||||||
|
|
||||||
def send_mail(self, subject, text):
|
def send_mail(self, subject, text):
|
||||||
"""This method sends a mail with the given text and subject
|
"""This method sends a mail with the given text and subject
|
||||||
and signs it usign GnuPG. If a public key of the recipient is
|
and signs it usign GnuPG. If a public key of the recipient is
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 by Jan Dittberner.
|
# Copyright (C) 2007, 2008 by Jan Dittberner.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 by Jan Dittberner.
|
# Copyright (C) 2007, 2008 by Jan Dittberner.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 by Jan Dittberner.
|
# Copyright (C) 2007, 2008 by Jan Dittberner.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -25,6 +25,7 @@ from settings import config
|
||||||
from BackendTo import *
|
from BackendTo import *
|
||||||
from BackendEntity import *
|
from BackendEntity import *
|
||||||
from BackendEntityHandler import *
|
from BackendEntityHandler import *
|
||||||
|
import os
|
||||||
|
|
||||||
class SysuserEntity(BackendEntity):
|
class SysuserEntity(BackendEntity):
|
||||||
"""Entity class for system users."""
|
"""Entity class for system users."""
|
||||||
|
@ -52,8 +53,9 @@ class SysuserEntity(BackendEntity):
|
||||||
usernames = [user.username for user in \
|
usernames = [user.username for user in \
|
||||||
getenttools.find_user_by_prefix(prefix)]
|
getenttools.find_user_by_prefix(prefix)]
|
||||||
maxid = max([int(username[len(prefix):]) for username in usernames])
|
maxid = max([int(username[len(prefix):]) for username in usernames])
|
||||||
for num in range(1, maxid + 1):
|
maxid += 2
|
||||||
username = "%s%02d" % (prefix, num)
|
for number in range(1, maxid):
|
||||||
|
username = "%s%02d" % (prefix, number)
|
||||||
if not username in usernames:
|
if not username in usernames:
|
||||||
return username
|
return username
|
||||||
|
|
||||||
|
@ -79,15 +81,15 @@ class SysuserEntity(BackendEntity):
|
||||||
|
|
||||||
def _populate_home(self):
|
def _populate_home(self):
|
||||||
templatedir = get_template_dir(config.get('sysuser', 'hometemplate'))
|
templatedir = get_template_dir(config.get('sysuser', 'hometemplate'))
|
||||||
cmdline = 'cp -R "%(template)s" "%(home)s"' % {
|
olddir = os.getcwd()
|
||||||
'template' : templatedir,
|
os.chdir(templatedir)
|
||||||
'home' : self.delegateto.home }
|
cmd1 = 'find . -depth \! -regex ".*\.svn.*" \! -name "*~" -print0'
|
||||||
self.sucommand(cmdline)
|
cmd2 = 'cpio --pass-through --owner=%(username)s.%(group)s --null --make-directories %(home)s' % {
|
||||||
cmdline = 'chown -R "%(username)s":"%(group)s" %(home)s' % {
|
|
||||||
'username' : self.delegateto.username,
|
'username' : self.delegateto.username,
|
||||||
'group' : config.get('sysuser', 'defaultgroup'),
|
'group' : config.get('sysuser', 'defaultgroup'),
|
||||||
'home' : self.delegateto.home }
|
'home' : self.delegateto.home}
|
||||||
self.sucommand(cmdline)
|
self.supipe((cmd1, cmd2))
|
||||||
|
os.chdir(olddir)
|
||||||
|
|
||||||
def _mail_sysuser(self):
|
def _mail_sysuser(self):
|
||||||
template = get_template(config.get('common', 'mailtemplates'),
|
template = get_template(config.get('common', 'mailtemplates'),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 by Jan Dittberner.
|
# Copyright (C) 2007, 2008 by Jan Dittberner.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -43,30 +43,15 @@ except exceptions.NoSuchTableError, nste:
|
||||||
|
|
||||||
meta = BoundMetaData(config.get('database', 'uri'))
|
meta = BoundMetaData(config.get('database', 'uri'))
|
||||||
#meta.engine.echo = True
|
#meta.engine.echo = True
|
||||||
client_table = Table(
|
client_table = Table('client', meta, schema = dbschema, autoload = True)
|
||||||
'client', meta, schema = dbschema, autoload = True)
|
sysuser_table = Table('sysuser', meta, schema = dbschema, autoload = True)
|
||||||
sysuser_table = Table(
|
domain_table = Table('domain', meta, schema = dbschema, autoload = True)
|
||||||
'sysuser', meta, ForeignKeyConstraint(['clientid'], ['client.clientid']),
|
record_table = Table('record', meta, schema = dbschema, autoload = True)
|
||||||
schema = dbschema, autoload = True)
|
supermaster_table = Table('supermaster', meta, schema = dbschema,
|
||||||
domain_table = Table(
|
autoload = True)
|
||||||
'domain', meta, ForeignKeyConstraint(['sysuserid'], ['sysuser.sysuserid']),
|
mailaccount_table = Table('mailaccount', meta, schema = dbschema,
|
||||||
schema = dbschema, autoload = True)
|
autoload = True)
|
||||||
record_table = Table(
|
mailaddress_table = Table('mailaddress', meta, schema = dbschema,
|
||||||
'record', meta, ForeignKeyConstraint(['domainid'], ['domain.domainid']),
|
autoload = True)
|
||||||
schema = dbschema, autoload = True)
|
mailtarget_table = Table('mailtarget', meta, schema = dbschema,
|
||||||
supermaster_table = Table(
|
autoload = True)
|
||||||
'supermaster', meta,
|
|
||||||
ForeignKeyConstraint(['account'], ['sysuser.sysuserid']),
|
|
||||||
schema = dbschema, autoload = True)
|
|
||||||
mailaccount_table = Table(
|
|
||||||
'mailaccount', meta,
|
|
||||||
ForeignKeyConstraint(['domainid'], ['domain.domainid']),
|
|
||||||
schema = dbschema, autoload = True)
|
|
||||||
mailaddress_table = Table(
|
|
||||||
'mailaddress', meta,
|
|
||||||
ForeignKeyConstraint(['domainid'], ['domain.domainid']),
|
|
||||||
schema = dbschema, autoload = True)
|
|
||||||
mailtarget_table = Table(
|
|
||||||
'mailtarget', meta,
|
|
||||||
ForeignKeyConstraint(['mailaddressid'], ['mailaddress.mailaddressid']),
|
|
||||||
schema = dbschema, autoload = True)
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 by Jan Dittberner.
|
# Copyright (C) 2007 by Jan Dittberner.
|
||||||
#
|
#
|
||||||
|
@ -24,6 +24,7 @@ import crypt, crack, random
|
||||||
_pwchars = []
|
_pwchars = []
|
||||||
for pair in (('0', '9'), ('A', 'Z'), ('a', 'z')):
|
for pair in (('0', '9'), ('A', 'Z'), ('a', 'z')):
|
||||||
_pwchars.extend(range(ord(pair[0]), ord(pair[1])))
|
_pwchars.extend(range(ord(pair[0]), ord(pair[1])))
|
||||||
|
_saltchars = [char for char in _pwchars]
|
||||||
for char in "-+/*_@":
|
for char in "-+/*_@":
|
||||||
_pwchars.append(ord(char))
|
_pwchars.append(ord(char))
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ def checkpassword(password):
|
||||||
def md5_crypt_password(password):
|
def md5_crypt_password(password):
|
||||||
"""Hashes the given password with MD5 and a random salt value."""
|
"""Hashes the given password with MD5 and a random salt value."""
|
||||||
salt = "".join([chr(letter) for letter in \
|
salt = "".join([chr(letter) for letter in \
|
||||||
random.sample(_pwchars, 8)])
|
random.sample(_saltchars, 8)])
|
||||||
return crypt.crypt(password, '$1$' + salt)
|
return crypt.crypt(password, '$1$' + salt)
|
||||||
|
|
||||||
def get_pw_tuple(password = None):
|
def get_pw_tuple(password = None):
|
||||||
|
|
11
gnuviechadmin/util/stmtcreator.py
Normal file
11
gnuviechadmin/util/stmtcreator.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
from passwordutils import *
|
||||||
|
import sys
|
||||||
|
|
||||||
|
for line in sys.stdin.read().splitlines():
|
||||||
|
parts = line.split()
|
||||||
|
(email, domain) = parts[0].split("@")
|
||||||
|
username = parts[1][0:5]
|
||||||
|
pwtuple = get_pw_tuple()
|
||||||
|
print "INSERT INTO mailpassword (id, clearpass, cryptpass, uid, gid, home, spamcheck) VALUES ('%s', '%s', '%s', %d, %d, '/home/mail/%s/%s', 'false');" % (parts[1], pwtuple[0], pwtuple[1], int(parts[2]), 119, username, parts[1])
|
||||||
|
print "INSERT INTO mailaddress (domainid, email, target) VALUES (%d, '%s', '%s');" % (int(parts[3]), email, parts[1])
|
||||||
|
|
Loading…
Reference in a new issue