develop
asamoukin 16 years ago
parent 0783ba9a2a
commit 7f29e306d9

@ -26,6 +26,19 @@ import cl_profile
# Для подсчета символов
import termios, fcntl, struct
class iniLdapParser(cl_base.iniParser):
"""Класс для работы c ini-файлом ldap"""
def __init__(self):
# название ini файла
nameIniFile = "/etc/calculate2/calculate.ldap"
cl_base.iniParser.__init__(self,nameIniFile)
# права создаваемого ini-файла
self.setMode(0600)
pathIniFile = os.path.split(nameIniFile)[0]
if not os.path.exists(pathIniFile):
os.makedirs(pathIniFile)
class addLdif(LDIFParser):
"""Класс необходимый для добавления записей в LDAP"""
def __init__(self, strInput,ldapCon):
@ -427,92 +440,6 @@ _("in the system") + ".\n"
else:
return False
def getParamIniFile(self, name):
"""Получаем значение параметра по его имени из ini файла"""
if os.access(self.iniFile, os.F_OK):
FD = open (self.iniFile)
lines = FD.read().splitlines()
FD.close()
dictParam = {}
for par in lines:
n ,v = par.split("=")
if not dictParam.has_key(n.strip()):
dictParam[n.strip()] = v.strip()
if dictParam.has_key(name):
return dictParam[name]
else:
return ""
else:
self.setError(_("Not found ini file:")) + "\n " + self.iniFile
return False
def createIniFile(self):
pass
def setParamIniFile(self, name, value):
"""Записываем новый параметр в ini файл"""
# Если ini файл не существует создаем его
if not os.access(self.iniFile, os.F_OK):
self.createIniFile()
FD = open (self.iniFile)
lines = FD.read().splitlines()
FD.close()
dictParam = {}
newLines = []
for par in lines:
n ,v = par.split("=")
if not dictParam.has_key(n.strip()):
dictParam[n.strip()] = v.strip()
newLines.append((n.strip(),v.strip(),par))
if dictParam.has_key(name):
i = 0
for n,v,l in newLines:
if n == name:
newLines[i] = (name, value, name + "=" + value)
break
i += 1
else:
newLines.append((name, value, name + "=" + value))
if newLines:
FD = open (self.iniFile, "w")
FD.truncate(0)
FD.seek(0)
for n,v,l in newLines[:-1]:
FD.write(l+"\n")
FD.write(newLines[-1][2])
FD.close()
return True
def delParamIniFile(self, name):
"""Удаляет параметр из ini файла"""
if os.access(self.iniFile, os.F_OK):
FD = open (self.iniFile)
lines = FD.read().splitlines()
FD.close()
dictParam = {}
newLines = []
for par in lines:
n ,v = par.split("=")
if not dictParam.has_key(n.strip()):
dictParam[n.strip()] = v.strip()
if n.strip() != name:
newLines.append((n.strip(),v.strip(),par))
FD = open (self.iniFile, "w")
FD.truncate(0)
FD.seek(0)
if newLines:
for n,v,l in newLines[:-1]:
FD.write(l+"\n")
FD.write(newLines[-1][2])
else:
FD.write("")
FD.close()
return True
else:
self.setError(_("Not found ini file:")) + "\n " + self.iniFile
return False
def createLdif(self, ldifFile, objVars):
"""Cоздает ldif из ldif - профиля"""
if not os.access(ldifFile, os.F_OK):
@ -601,20 +528,22 @@ _("in the system") + ".\n"
lst.append(bg)
sys.stdout.write("\033[%sm%s\033[0m" %(";".join(lst),string))
def redBrightPrint(self, string):
"""Печатает яркое красное сообщение"""
self.colorPrint("1","31","",string)
def greenBrightPrint(self, string):
"""Печатает яркое зеленое сообщение"""
self.colorPrint("1","32","",string)
def yellowBrightPrint(self, string):
"""Печатает яркое желтое сообщение"""
self.colorPrint("1","33","",string)
def blueBrightPrint(self, string):
"""Печатает яркое cинее сообщение"""
self.colorPrint("1","34","",string)
def redBrightPrint(self, string):
"""Печатает яркое красное сообщение"""
self.colorPrint("1","31","",string)
def brPrint(self):
sys.stdout.write("\n")
def lenString(self, string):
"""Получаем длинну строки"""
@ -625,6 +554,7 @@ _("in the system") + ".\n"
def defaultPrint(self, string):
sys.stdout.write(string)
sys.stdout.flush()
def printLine(self, argL, argR):
"""Печатает справа и слева консоли цветные сообщения"""
@ -638,6 +568,8 @@ _("in the system") + ".\n"
'blueBr':self.blueBrightPrint,
# ярко красный
'redBr':self.redBrightPrint,
# ярко желтый
'yellowBr':self.yellowBrightPrint,
}
# cмещение от левого края консоли
offsetL = 0
@ -660,6 +592,7 @@ _("in the system") + ".\n"
colorDict[color](rightString)
else:
colorDict[''](rightString)
print ""
def printNotOK(self, string):
"""Вывод на печать в случае сбоя"""
@ -682,7 +615,14 @@ _("in the system") + ".\n"
('blueBr',']'),
)
)
def printWARNING(self, string):
"""Вывод на печать предупреждения"""
self.printLine((('yellowBr',' * '),
('',string),
),
(('',''),
)
)
def setupLdapServer(self, options):
"""Начальная настройка LDAP сервиса"""
@ -690,25 +630,30 @@ _("in the system") + ".\n"
forceOptions = False
if "f" in options:
forceOptions = True
clVars = cl_base.DataVars()
clVars.flServer()
clVars.flIniFile()
# В случае если сервер установлен
if self.getParamIniFile("setup_LDAP") == "yes" and\
if clVars.Get("soft_ldap_setup") == "yes" and\
not forceOptions:
print _("LDAP server is configured")
self.printWARNING (_("WARNING") + ": " +\
_("LDAP server is configured")+ ".")
return True
# Проверим запущен ли ldap
if self.getRunService("ldap"):
print _("The LDAP service is running")
self.printWARNING (_("WARNING") + ": " +\
_("The LDAP service is running") + ".")
print "1. " +_("Stop the LDAP service")
print " /etc/init.d/slapd stop"
print "2. " + _("You can save configuration files and a database \
LDAP in backup directory")
print "3. " + _("Restart the program")
return True
self.setParamIniFile("setup_LDAP","no")
clVars = cl_base.DataVars()
clVars.flServer()
#self.setParamIniFile("setup_LDAP","no")
clVars.Write("soft_ldap_setup","no")
# Для тестовых целей устанавливаем директорию инсталяции
clVars.Set("setup_path_install","/tmp/test1/")
#clVars.Set("setup_path_install","/tmp/test1/")
# Устанавливаем переменную (говорит о том что первый проход)
clVars.Set("setup_pass_parser","1",True)
# Cоздаем объект профиль устанавливая директорию ldap для
@ -749,15 +694,8 @@ LDAP in backup directory")
else:
self.printNotOK(_("LDAP restart ..."))
return False
self.setParamIniFile("setup_LDAP","yes")
#print clVars.Get("soft_ldap_admin")
#print clVars.Get("soft_ldap_adminpw")
#
#self.setParamIniFile("test1","param1")
#self.delParamIniFile("test1")
#self.delParamIniFile("test")
#print self.getParamIniFile("test")
ldapParser = iniLdapParser()
ldapParser.setVar("admin",
{"DN":clVars.Get("soft_ldap_admin"),
"PASS":clVars.Get("soft_ldap_adminpw")})
clVars.Write("soft_ldap_setup","yes")

@ -1,13 +1,13 @@
#-*- 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.
@ -91,6 +91,10 @@ class Data:
soft_samba_netbios= {'mode':"r",
'type':('param','soft'),
}
#Настроен или нет сервис LDAP
soft_ldap_setup= {'mode':"w",
'type':('param','soft'),
}
#-----------------------------------------------------
#Служебные переменные
#-----------------------------------------------------

Loading…
Cancel
Save