|
|
|
@ -25,7 +25,7 @@ from base64 import encodestring as b64encode
|
|
|
|
|
import smbpasswd
|
|
|
|
|
from cl_print import color_print
|
|
|
|
|
# для создания сертификата
|
|
|
|
|
from server.users import users
|
|
|
|
|
import pwd
|
|
|
|
|
from server.utils import execProg
|
|
|
|
|
import cl_lang
|
|
|
|
|
# Перевод модуля
|
|
|
|
@ -109,7 +109,7 @@ class encrypt(color_print):
|
|
|
|
|
nsCertType="server",
|
|
|
|
|
sslDays=730,
|
|
|
|
|
sslBits=1024,
|
|
|
|
|
userName="root",groupName="root",
|
|
|
|
|
userName="root",
|
|
|
|
|
certFile="/tmp/server.pem",
|
|
|
|
|
certFileMode=0400,
|
|
|
|
|
keyFile="/tmp/server.key",
|
|
|
|
@ -121,13 +121,14 @@ class encrypt(color_print):
|
|
|
|
|
return True
|
|
|
|
|
# Удаляем файл сертификата
|
|
|
|
|
map(lambda x: os.remove(x), foundCertFiles)
|
|
|
|
|
# Объект для работы с пользователями
|
|
|
|
|
usersObj = users()
|
|
|
|
|
# получаем id и gid пользователя
|
|
|
|
|
uidAndGid = usersObj.getUserUidAndGid(userName, groupName)
|
|
|
|
|
if not uidAndGid:
|
|
|
|
|
try:
|
|
|
|
|
pwdObj = pwd.getpwnam(userName)
|
|
|
|
|
except:
|
|
|
|
|
self.printERROR(_("Not found user %s")%userName)
|
|
|
|
|
return False
|
|
|
|
|
uid, gid = uidAndGid
|
|
|
|
|
uid = pwdObj.pw_uid
|
|
|
|
|
gid = pwdObj.pw_gid
|
|
|
|
|
textCnf="""[ req ]
|
|
|
|
|
prompt = no
|
|
|
|
|
default_bits = %s
|
|
|
|
@ -157,9 +158,9 @@ nsCertType = %s
|
|
|
|
|
for fileName in certAndKeyFiles:
|
|
|
|
|
dirName = os.path.split(fileName)[0]
|
|
|
|
|
if not os.path.exists(dirName):
|
|
|
|
|
self.createUserDir(0, 0, dirName, 0755)
|
|
|
|
|
self._createDir(0, 0, dirName, 0755)
|
|
|
|
|
# Создание конфигурационного файла
|
|
|
|
|
usersObj.createUserFile(cnfFile, textCnf, 0, 0, 0600)
|
|
|
|
|
self._createFile(cnfFile, textCnf, 0, 0, 0600)
|
|
|
|
|
# Создание сертификата
|
|
|
|
|
textLine = execProg(\
|
|
|
|
|
"%s req -new -x509 -nodes -config %s -days %s -out %s -keyout %s"\
|
|
|
|
@ -184,3 +185,34 @@ nsCertType = %s
|
|
|
|
|
self.printERROR(_("Can not create certificate %s")%certFile)
|
|
|
|
|
return False
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def _createDir(self, uid, gid, dirName, mode=0700):
|
|
|
|
|
"""Создание пользовательской директории"""
|
|
|
|
|
if not os.path.exists(dirName):
|
|
|
|
|
os.makedirs(dirName)
|
|
|
|
|
if mode:
|
|
|
|
|
os.chmod(dirName,mode)
|
|
|
|
|
os.chown(dirName,uid,gid)
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
self.printERROR(_("Path %s exists") %dirName)
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def _createFile(self, fileName, fileTxt, uid, gid, mode=0644):
|
|
|
|
|
"""Создает пользовательский файл с содержимым
|
|
|
|
|
|
|
|
|
|
Если директория файла не существует то ошибка
|
|
|
|
|
"""
|
|
|
|
|
dirName = os.path.split(fileName)[0]
|
|
|
|
|
if not os.path.exists(dirName):
|
|
|
|
|
self.printERROR(_("Path %s not exists") %dirName)
|
|
|
|
|
return False
|
|
|
|
|
fd = os.open(fileName, os.O_CREAT)
|
|
|
|
|
os.close(fd)
|
|
|
|
|
os.chmod(fileName, mode)
|
|
|
|
|
os.chown(fileName,uid,gid)
|
|
|
|
|
if fileTxt:
|
|
|
|
|
FD = open(fileName, "r+")
|
|
|
|
|
FD.write(fileTxt)
|
|
|
|
|
FD.close()
|
|
|
|
|
return True
|
|
|
|
|