68 lines
2.5 KiB
Python
68 lines
2.5 KiB
Python
|
"""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()
|
||
|
|