- added gnuviech package
- better code structure - class for domain - class for preferences - password generation function git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@82 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
parent
e18a12269f
commit
a7edeca826
8 changed files with 235 additions and 74 deletions
67
backend/gnuviech/__init__.py
Normal file
67
backend/gnuviech/__init__.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
"""GNUViech administration tool helper classes.
|
||||
|
||||
(c) 2004 Jan Dittberner <jan@gnuviech.info>
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
class GNVPrefs:
|
||||
"""This class has static variables for the settings of the GNUViech
|
||||
administration tool. These settings can be customized in the file
|
||||
gvadm.preferences."""
|
||||
# define standard values
|
||||
PWDMINLENGTH = 6
|
||||
PWDMAXLENGTH = 12
|
||||
PWDCHARS = range(ord('a'), ord('z'))
|
||||
PWDCHARS.extend(range(ord('A'), ord('Z')))
|
||||
PWDCHARS.extend(range(ord('0'), ord('9')))
|
||||
PWDCHARS.extend((ord('@'), ord('#'), ord(','), ord('.'), ord('*'),
|
||||
ord('+'), ord('-'), ord('='), ord('!'), ord('$'),
|
||||
ord('"')))
|
||||
USERPREFIX = "usr"
|
||||
BASEPREFIX = ""
|
||||
GVADMDIR = BASEPREFIX+"/etc/gvadm/"
|
||||
EXIMCONFDIR = BASEPREFIX+"/etc/exim/"
|
||||
VIRTUALDOMDIR = EXIMCONFDIR+"virtual/"
|
||||
HOMEDIR = BASEPREFIX+"/home"
|
||||
POPHOMEDIR = HOMEDIR+"/mail/"
|
||||
WEBHOMEDIR = HOMEDIR+"/www/"
|
||||
WEBLOGDIR = WEBHOMEDIR+"logs/"
|
||||
WEBSTATSDIR = WEBHOMEDIR+"stats/"
|
||||
# load custom settings
|
||||
execfile("gvadm.preferences")
|
||||
|
||||
def __repr__(self):
|
||||
items = dir(self)
|
||||
items.sort()
|
||||
return "gnuviech.GNVPrefs\n\t" + "\n\t".join(["%s = %s" %
|
||||
(item, getattr(self, item)) for item in items if getattr(self, item).__class__ in (str, int, list, dict)]) + "\n"
|
||||
|
||||
class NoAdmDirError(Exception):
|
||||
"""This exception is raised if the admin directory does'nt exist."""
|
||||
pass
|
||||
|
||||
def setupDirs():
|
||||
"""Setup the directories and files required for proper operation of the
|
||||
GNUViech administration tool."""
|
||||
for directory in (GNVPrefs.BASEPREFIX,
|
||||
GNVPrefs.BASEPREFIX+"/etc",
|
||||
GNVPrefs.GVADMDIR,
|
||||
GNVPrefs.EXIMCONFDIR,
|
||||
GNVPrefs.VIRTUALDOMDIR,
|
||||
GNVPrefs.HOMEDIR,
|
||||
GNVPrefs.POPHOMEDIR,
|
||||
GNVPrefs.WEBHOMEDIR,
|
||||
GNVPrefs.WEBLOGDIR,
|
||||
GNVPrefs.WEBSTATSDIR):
|
||||
if (not os.access(directory, os.R_OK & os.X_OK)):
|
||||
print "making %s." % directory
|
||||
os.mkdir(directory)
|
||||
for required in (GNVPrefs.BASEPREFIX+"/etc/passwd",
|
||||
GNVPrefs.BASEPREFIX+"/etc/shadow",
|
||||
GNVPrefs.EXIMCONFDIR+"eximpasswords"):
|
||||
if (not os.access(required, os.R_OK)):
|
||||
print "creating %s." % required
|
||||
file = open(required, "w")
|
||||
file.close()
|
||||
|
||||
20
backend/gnuviech/tools.py
Normal file
20
backend/gnuviech/tools.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
"""Tool functions for GNUViech administration tool
|
||||
|
||||
(c) 2004 Jan Dittberner <jan@gnuviech.info>
|
||||
"""
|
||||
|
||||
from random import Random
|
||||
from gnuviech import GNVPrefs
|
||||
|
||||
def generatePassword():
|
||||
r = Random()
|
||||
devrnd = open("/dev/random", "r")
|
||||
r.seed(ord(devrnd.read(1)))
|
||||
devrnd.close()
|
||||
return "".join([chr(char) for char in
|
||||
r.sample(GNVPrefs.PWDCHARS,
|
||||
r.randint(GNVPrefs.PWDMINLENGTH,
|
||||
GNVPrefs.PWDMAXLENGTH))])
|
||||
|
||||
# regex für email check
|
||||
# p = re.compile(u"^([a-zA-Z0-9_\-.]+)@([a-zA-Z0-9\-]+(\.|[a-zA-Z0-9\-]+)*\.[a-z]{2,5})$")
|
||||
Loading…
Add table
Add a link
Reference in a new issue