develop
asamoukin 16 years ago
parent 9d68bc303d
commit 92b3584340

@ -223,13 +223,18 @@ class shareLdap(imp_cl_err, imp_cl_xml, imp_cl_help, imp_cl_smcon):
def addDN(self, *arg):
"""Складывает текстовые элементы DN"""
return ','.join(arg)
DNs = []
for dn in arg:
if dn:
DNs.append(dn)
return ','.join(DNs)
def chownR(self, directory, uid, gid):
"""изменяет владельца и группу
для всех файлов и директорий внутри directory
"""
fileObj = cl_profile._file()
scanObjs = fileObj.scanDirs([directory])
# меняем владельца домашней директории
os.chown(directory, uid,gid)
@ -292,6 +297,41 @@ class shareLdap(imp_cl_err, imp_cl_xml, imp_cl_help, imp_cl_smcon):
return max(lst)
return False
@foundConnect
def fullElementDNtoText(self, relDN):
"""Выводит все внутренние элементы DN виде текста"""
DN = self.addDN(relDN, self.baseDN)
listDN=[]
try:
dnList = self.conLdap.search_s(DN,
ldap.SCOPE_SUBTREE,
'(objectclass=*)',None)
except ldap.LDAPError, e:
self.printERROR(_("fullElementDN") +": "+e[0]['desc'])
return False
outText = ""
lenDNlist = len(dnList)
dnIter = 0
for dn, f in dnList:
dnIter += 1
outText += "dn: " + dn + "\n"
listObjectClass = []
listOtherAttr = []
attrs = f.keys()
attrs.sort()
for attr in attrs:
for val in f[attr]:
attrText = attr + ": " + val
if attr == "objectClass":
listObjectClass.append(attrText)
else:
listOtherAttr.append(attrText)
listAttr = listObjectClass + listOtherAttr
for i in listAttr:
outText += i + "\n"
if dnIter < lenDNlist:
outText += "\n"
return outText
@foundConnect
def deleteDN(self, relDelDN):
@ -1304,6 +1344,19 @@ class servUnix(shareLdap):
DN = self.addDN("uid="+userName, self.relUsersDN)
if not self.modAttrsDN(DN, modAttrs):
return False
# Переносим домашнюю директорию пользователя
if options.has_key('d') and options.has_key('m'):
homeDirOld = res[0][0][1]['homeDirectory'][0]
homeDirNew = homeDir
textLine = self.execProg("mv %s %s" %(homeDirOld, homeDirNew))
if not (textLine == None):
self.printERROR(_("Not move home directory") + " ...")
modAttrs = ((ldap.MOD_REPLACE, 'homeDirectory',
homeDirOld),)
self.modAttrsDN(DN, modAttrs)
return False
else:
self.printSUCCESS(_("Move home directory") + " ...")
if options.has_key('c'):
self.printSUCCESS(_("Modify comment") + " ...")
if options.has_key('s'):
@ -1486,6 +1539,68 @@ class servUnix(shareLdap):
groupDN = self.addDN("cn="+groupName, self.relGroupsDN)
return self.modAttrsDN(groupDN, modAttrs)
@foundConnect
def backupUnixServer(self, options):
ldifText = self.fullElementDNtoText(self.relDN)
if not ldifText:
self.printError("Not found or empty service Unix DN")
return False
tmpListFile = "/tmp/listUnixFiles.txt"
archLdifFile = "/tmp/unix.ldif"
tmpArchFile = "/tmp/archiv.tar.bz2"
backupDirectory = "/var/calculate/backup/CDS/unix"
backupFile = "archiv.tar.bz2"
if os.path.exists(tmpArchFile):
os.remove(tmpArchFile)
if os.path.exists(archLdifFile):
os.remove(archLdifFile)
if os.path.exists(tmpListFile):
os.remove(tmpListFile)
FD = open (archLdifFile, "w+")
FD.write(ldifText)
FD.close()
profilePath = self.clVars.Get("setup_path_profinstall")
servicePath = os.path.join(profilePath[0],'unix')
fileObj = cl_profile._file()
dirObjs = fileObj.scanDirs([servicePath])
dirObj = dirObjs[0]
tmpArchFiles = ""
for fileProfile in dirObj.files:
path = fileProfile.split(servicePath)[1]
tmpArchFiles += path + "\n"
tmpArchFiles += archLdifFile + "\n"
FDtmp = open (tmpListFile, "w+")
FDtmp.write(tmpArchFiles)
FDtmp.close()
self.execProg("tar --files-from=%s -cjf %s"\
%(tmpListFile,tmpArchFile))
if os.path.exists(tmpArchFile):
if not os.path.exists(backupDirectory):
try:
os.makedirs(backupDirectory)
except os.IOError:
self.printERROR(_("Not create directory:") + " " +\
str(backupDirectory))
return False
FDO = open (tmpArchFile, "r")
archData = FDO.read()
FDO.close()
bFile = os.path.join(backupDirectory, backupFile)
FDtmp = open (bFile, "w+")
FDtmp.write(archData)
FDtmp.close()
if os.path.exists(bFile):
return True
else:
self.printERROR(_("Not move archive file:") + " " +\
str(tmpArchFile) + " " + str(bFile))
return False
else:
self.printERROR(_("Not create archive file:") + " " +\
str(tmpArchFile))
return False
@foundConnect
def setupUnixServer(self, options):
"""Начальная настройка LDAP сервиса"""
@ -1904,6 +2019,11 @@ class servLdap(shareLdap):
self.ldifFileBase =\
"/usr/lib/calculate/calculate-server/ldif/ldap_base.ldif"
@foundConnect
def backupLdapServer(self, options):
print self.fullElementDNtoText('')
# надо доделать
def setupLdapServer(self, options):
"""Начальная настройка LDAP сервиса"""
# Принудительная установка
@ -2040,6 +2160,7 @@ class cl_ldap(shareLdap):
'cl-usermod':5,
'cl-setup':6,
'cl-passwd':7,
'cl-backup':8,
}
# Cвязь сервисов и действующих опций
self.relServices = {"samba":[_("Common options"),
@ -2290,20 +2411,13 @@ group already exists")
'helpChapter':_("Service Unix options"),
'help':_("append the user to the supplemental GROUPS")
},
#{'progAccess':(5,),
#'shortOption':"l",
#'longOption':"login",
#'optVal':"NEW_LOGIN",
#'helpChapter':_("Common options"),
#'help':_("new value of the login name")
#},
#{'progAccess':(5,),
#'shortOption':"m",
#'longOption':"move-home",
#'helpChapter':_("Common options"),
#'help':_("move contents of the home directory to the new location\
#(use only with -d)")
#},
{'progAccess':(5,),
'shortOption':"m",
'longOption':"move-home",
'helpChapter':_("Service Unix options"),
'help':_("move contents of the home directory to the new location\
(use only with -d)")
},
{'progAccess':(5,),
'shortOption':"p",
'longOption':"password",
@ -2382,7 +2496,7 @@ group already exists")
#'help':_("show enviroment values (filter for type, all - no filter)")
#},
# Services
{'progAccess':(6,),
{'progAccess':(6,8),
'helpChapter':_("Services"),
'help':pcs(" ldap", self.column_width,
"ldap " + servName, self.consolewidth-self.column_width)
@ -2391,7 +2505,7 @@ group already exists")
'help':pcs(" unix", self.column_width,
"unix " + servName, self.consolewidth-self.column_width)
},
{'progAccess':(3,4,5,6,7),
{'progAccess':(3,4,5,6,7,8),
'helpChapter':_("Services"),
'help':pcs(" samba", self.column_width,
"samba " + servName, self.consolewidth-self.column_width)
@ -2436,6 +2550,11 @@ group already exists")
'help': cmdName + " " + " [" + _("options") + "] " +\
_("group") + " " + _("service")
},
{
'progAccess':(1,),
'helpChapter':_("Usage"),
'help': cmdName + " " +_("group") + " " + _("service")
},
{
'progAccess':(2,),
'helpChapter':_("Usage"),
@ -2472,6 +2591,11 @@ group already exists")
'help': cmdName + " " + " [" + _("options") + "] " + _("user") +\
" " + _("service")
},
{
'progAccess':(8,),
'helpChapter':_("Usage"),
'help': cmdName + " " + _("service")
},
{
'progAccess':(0,),
'helpChapter':"Function",
@ -2512,6 +2636,11 @@ group already exists")
'helpChapter':"Function",
'help':_("Change user password")
},
{
'progAccess':(8,),
'helpChapter':"Function",
'help':_("Backup service")
},
# Примеры
{
'progAccess':(0,),
@ -2571,6 +2700,13 @@ group already exists")
"# "+_("change password for Samba service user test") + ".",
self.consolewidth-self.column_width)
},
{
'progAccess':(8,),
'helpChapter':_("Examples"),
'help':pcs(" cl-backup samba", self.column_width,
"# "+_("backup Samba service") + ".",
self.consolewidth-self.column_width)
},
#{
#'helpChapter':_("Examples"),
#'help':pcs(" " + cmdName + " --env boot", self.column_width,

@ -0,0 +1,51 @@
#!/usr/bin/python
#-*- coding: utf-8 -*-
#Copyright 2008 Calculate Pack, http://www.calculate-linux.ru
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import os
sys.path.insert(0,os.path.abspath('/usr/lib/calculate/calculate-lib/pym'))
sys.path.insert(0,os.path.abspath('/usr/lib/calculate/calculate-server/pym'))
import cl_base
tr = cl_base.lang()
tr.setGlobalDomain('cl_server')
tr.setLanguage(sys.modules[__name__])
import cl_ldap
if __name__ == "__main__":
ldapObj = cl_ldap.cl_ldap("cl-backup")
optObj = cl_ldap.tsOpt(ldapObj,[])
flagError = False
if not optObj.flagHelp and optObj.params.has_key('service'):
# Настройка сервера LDAP
flagError = True
if optObj.params['service'] == "ldap":
obj = cl_ldap.servLdap()
if obj.backupLdapServer(optObj.opt):
flagError = False
elif optObj.params['service'] == "unix":
obj = cl_ldap.servUnix()
if obj.backupUnixServer(optObj.opt):
flagError = False
# Настройка сервера Samba
elif optObj.params['service'] == "samba":
obj = cl_ldap.servSamba()
if obj.backupSambaServer(optObj.opt):
flagError = False
if flagError:
sys.exit(1)
else:
sys.exit(0)

@ -21,7 +21,7 @@ sys.path.insert(0,os.path.abspath('/usr/lib/calculate/calculate-lib/pym'))
sys.path.insert(0,os.path.abspath('/usr/lib/calculate/calculate-server/pym'))
import cl_base
tr = cl_base.lang()
tr.setGlobalDomain('cl_passwd')
tr.setGlobalDomain('cl_server')
tr.setLanguage(sys.modules[__name__])
import cl_ldap

@ -128,5 +128,6 @@ setup(
"./scripts/cl-groupdel",
"./scripts/cl-passwd",
"./scripts/cl-setup",
"./scripts/cl-backup",
],
)

Loading…
Cancel
Save