|
|
|
@ -1,5 +1,3 @@
|
|
|
|
|
#-*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
# Copyright 2008-2010 Mir Calculate. http://www.calculate-linux.org
|
|
|
|
|
#
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
@ -18,7 +16,8 @@ import os
|
|
|
|
|
import sys
|
|
|
|
|
import re
|
|
|
|
|
import ldap
|
|
|
|
|
import cStringIO, StringIO
|
|
|
|
|
# import cStringIO, StringIO
|
|
|
|
|
from io import StringIO, BytesIO
|
|
|
|
|
from ldif import LDIFParser, LDIFWriter
|
|
|
|
|
from . import cl_base
|
|
|
|
|
from . import cl_profile
|
|
|
|
@ -41,14 +40,12 @@ import tempfile
|
|
|
|
|
# Вывод в строку ввода
|
|
|
|
|
import readline
|
|
|
|
|
# Пути в XML документе
|
|
|
|
|
from xml import xpath
|
|
|
|
|
# from xml import xpath
|
|
|
|
|
from .cl_xml import xpath, firstChild
|
|
|
|
|
# Для 32 битного целого (генерация серийного номера DNS зоны)
|
|
|
|
|
import ctypes
|
|
|
|
|
from functools import reduce
|
|
|
|
|
|
|
|
|
|
#TODO delete this
|
|
|
|
|
_ = lambda x: x
|
|
|
|
|
|
|
|
|
|
Version = "calculate-server 2.1.20"
|
|
|
|
|
|
|
|
|
|
tr = cl_base.lang()
|
|
|
|
@ -136,7 +133,7 @@ class report:
|
|
|
|
|
for i in range(lenLines):
|
|
|
|
|
char = " | "
|
|
|
|
|
if i == 0 or i == 2 or i == lenLines-1:
|
|
|
|
|
char ="-+-"
|
|
|
|
|
char = "-+-"
|
|
|
|
|
convLines.append(self._insertStrChar(lines[i], lenCols, char))
|
|
|
|
|
print("\n".join(convLines))
|
|
|
|
|
print("(%s %s)"%(len(self.dataList), _("rows")))
|
|
|
|
@ -200,7 +197,7 @@ class iniLdapParser(cl_base.iniParser):
|
|
|
|
|
class addLdif(LDIFParser):
|
|
|
|
|
"""Класс необходимый для добавления записей в LDAP"""
|
|
|
|
|
def __init__(self, strInput,ldapCon):
|
|
|
|
|
FD = cStringIO.StringIO(strInput)
|
|
|
|
|
FD = StringIO(strInput)
|
|
|
|
|
LDIFParser.__init__(self, FD)
|
|
|
|
|
self.ldapCon = ldapCon
|
|
|
|
|
|
|
|
|
@ -677,17 +674,17 @@ in a sambaDomainName',
|
|
|
|
|
%delBackDir)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def stringIsJpeg(self, string):
|
|
|
|
|
"""Определяет является ли строка jpeg изображением"""
|
|
|
|
|
if len(string)<8:
|
|
|
|
|
def dataIsJpeg(self, bytes):
|
|
|
|
|
"""Определяет является ли набор байтов jpeg изображением"""
|
|
|
|
|
if len(bytes)<8:
|
|
|
|
|
return False
|
|
|
|
|
FD = cStringIO.StringIO(string)
|
|
|
|
|
FD = BytesIO(bytes)
|
|
|
|
|
isJpeg = False
|
|
|
|
|
FD.seek(0, 0)
|
|
|
|
|
(firstByte, secondByte) = FD.read(2)
|
|
|
|
|
if (ord(firstByte) == 0xff and ord(secondByte) == 0xd8):
|
|
|
|
|
if (firstByte == 0xff and secondByte == 0xd8):
|
|
|
|
|
(firstByte, secondByte) = FD.read(2)
|
|
|
|
|
if (ord(firstByte) == 0xff and ord(secondByte) == 0xe0):
|
|
|
|
|
if (firstByte == 0xff and secondByte == 0xe0):
|
|
|
|
|
isJpeg = True
|
|
|
|
|
return isJpeg
|
|
|
|
|
|
|
|
|
@ -1122,7 +1119,7 @@ in a sambaDomainName',
|
|
|
|
|
"""Добавляем jpeg фотографию пользователя в LDAP"""
|
|
|
|
|
import subprocess
|
|
|
|
|
try:
|
|
|
|
|
FD = open(photoPath)
|
|
|
|
|
FD = open(photoPath, "rb")
|
|
|
|
|
photoData = FD.read()
|
|
|
|
|
FD.close()
|
|
|
|
|
except:
|
|
|
|
@ -1134,7 +1131,7 @@ in a sambaDomainName',
|
|
|
|
|
_("not found"))
|
|
|
|
|
return False
|
|
|
|
|
modAttrs = []
|
|
|
|
|
if not self.stringIsJpeg(photoData):
|
|
|
|
|
if not self.dataIsJpeg(photoData):
|
|
|
|
|
if self.execProg("which convert") is False:
|
|
|
|
|
self.printERROR(_("Can not found package imagemagick"))
|
|
|
|
|
return False
|
|
|
|
@ -1155,7 +1152,7 @@ in a sambaDomainName',
|
|
|
|
|
fErr.close()
|
|
|
|
|
if not flagError:
|
|
|
|
|
photoData = fOut.read()
|
|
|
|
|
if not self.stringIsJpeg(photoData):
|
|
|
|
|
if not self.dataIsJpeg(photoData):
|
|
|
|
|
self.printERROR(\
|
|
|
|
|
_("Can not convert file '%s' in jpeg format") %photoPath)
|
|
|
|
|
flagError = True
|
|
|
|
@ -14445,7 +14442,7 @@ class cl_info(cl_utils2.cl_smartcon, prnServ):
|
|
|
|
|
if xmlNodes:
|
|
|
|
|
masterIPNode = xmlNodes[0]
|
|
|
|
|
xmlNodes = xpath.Evaluate( "child::value", masterIPNode)
|
|
|
|
|
ips = (x.firstChild.nodeValue.strip() for x in xmlNodes)
|
|
|
|
|
ips = (firstChild(x).nodeValue.strip() for x in xmlNodes)
|
|
|
|
|
flagAddIPs = True
|
|
|
|
|
slaveIPs.append(",".join(ips))
|
|
|
|
|
if not flagAddIPs:
|
|
|
|
@ -14510,7 +14507,7 @@ class cl_info(cl_utils2.cl_smartcon, prnServ):
|
|
|
|
|
if xmlNodes:
|
|
|
|
|
masterIPNode = xmlNodes[0]
|
|
|
|
|
xmlNodes = xpath.Evaluate( "child::value", masterIPNode)
|
|
|
|
|
ipMasterServers = [x.firstChild.nodeValue.strip() for x in xmlNodes]
|
|
|
|
|
ipMasterServers = [firstChild(x).nodeValue.strip() for x in xmlNodes]
|
|
|
|
|
if not ipMasterServers:
|
|
|
|
|
self.printERROR(_("The program does not support information \
|
|
|
|
|
for %s DNS zone")%zoneName)
|
|
|
|
@ -16460,9 +16457,9 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
if not namesArea:
|
|
|
|
|
return []
|
|
|
|
|
return [x for x in namesArea
|
|
|
|
|
if x.firstChild and x.firstChild.nodeValue and\
|
|
|
|
|
len(x.firstChild.nodeValue) > 4 and\
|
|
|
|
|
'host' in x.firstChild.nodeValue[:4]]
|
|
|
|
|
if firstChild(x) is not None and firstChild(x).nodeValue and\
|
|
|
|
|
len(firstChild(x).nodeValue) > 4 and\
|
|
|
|
|
'host' in firstChild(x).nodeValue[:4]]
|
|
|
|
|
|
|
|
|
|
def getAllXMLSubnet(self):
|
|
|
|
|
"""Получаем все XML ноды подсетей"""
|
|
|
|
@ -16474,16 +16471,16 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
if not namesArea:
|
|
|
|
|
return []
|
|
|
|
|
return [x for x in namesArea
|
|
|
|
|
if x.firstChild and x.firstChild.nodeValue and\
|
|
|
|
|
len(x.firstChild.nodeValue) > 6 and\
|
|
|
|
|
'subnet' in x.firstChild.nodeValue[:6]]
|
|
|
|
|
if firstChild(x) is not None and firstChild(x).nodeValue and\
|
|
|
|
|
len(firstChild(x).nodeValue) > 6 and\
|
|
|
|
|
'subnet' in firstChild(x).nodeValue[:6]]
|
|
|
|
|
|
|
|
|
|
def getDataInAllHost(self):
|
|
|
|
|
"""Получить информацию о статических хостах"""
|
|
|
|
|
if self.getError():
|
|
|
|
|
return False
|
|
|
|
|
allXmlNames = self._getAllXMLStaticHosts()
|
|
|
|
|
allXmlAreas = [x.parentNode.parentNode for x in allXmlNames]
|
|
|
|
|
allXmlAreas = [x.getparent().getparent() for x in allXmlNames]
|
|
|
|
|
# Информация
|
|
|
|
|
dataHost = []
|
|
|
|
|
iterXmlNames = iter(allXmlNames)
|
|
|
|
@ -16491,9 +16488,9 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
#print xmlArea.toprettyxml()
|
|
|
|
|
# Ност
|
|
|
|
|
xmlNodeName = next(iterXmlNames)
|
|
|
|
|
strNameNode = xmlNodeName.firstChild.nodeValue
|
|
|
|
|
strNameNode = firstChild(xmlNodeName).nodeValue
|
|
|
|
|
# название хоста
|
|
|
|
|
hostname = strNameNode.partition("host")[2].strip().encode("UTF-8")
|
|
|
|
|
hostname = strNameNode.partition("host")[2].strip()
|
|
|
|
|
# Параметры статического хоста
|
|
|
|
|
dataPars = self.dataParsHost.copy()
|
|
|
|
|
# Заполняем словарь dataPars реальными параметрами
|
|
|
|
@ -16507,7 +16504,7 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
if self.getError():
|
|
|
|
|
return False
|
|
|
|
|
allXmlNames = self.getAllXMLSubnet()
|
|
|
|
|
allXmlAreas = [x.parentNode.parentNode for x in allXmlNames]
|
|
|
|
|
allXmlAreas = [x.getparent().getparent() for x in allXmlNames]
|
|
|
|
|
# Информация
|
|
|
|
|
dataNet = []
|
|
|
|
|
iterXmlNames = iter(allXmlNames)
|
|
|
|
@ -16515,13 +16512,13 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
# Сеть
|
|
|
|
|
xmlNodeName = next(iterXmlNames)
|
|
|
|
|
# Название области
|
|
|
|
|
strNameNode = xmlNodeName.firstChild.nodeValue
|
|
|
|
|
strNameNode = firstChild(xmlNodeName).nodeValue
|
|
|
|
|
# ip сети
|
|
|
|
|
netIP = strNameNode.partition("subnet")[2].partition("netmask")[0]
|
|
|
|
|
netIP = netIP.encode("UTF-8")
|
|
|
|
|
# netIP = netIP.encode("UTF-8")
|
|
|
|
|
# Маска сети
|
|
|
|
|
netMask = strNameNode.partition("subnet")[2].partition("netmask")[2]
|
|
|
|
|
netMask = netMask.encode("UTF-8")
|
|
|
|
|
# netMask = netMask.encode("UTF-8")
|
|
|
|
|
# Параметры сети
|
|
|
|
|
dataPars = self.dataParsNet.copy()
|
|
|
|
|
# Заполняем словарь dataPars реальными параметрами
|
|
|
|
@ -16569,9 +16566,9 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
for node in nodesFind:
|
|
|
|
|
nodesXml = xpath.Evaluate("child::value", node)
|
|
|
|
|
for nodeFind in nodesXml:
|
|
|
|
|
if nodeFind.firstChild:
|
|
|
|
|
listOpt = [x.encode("UTF-8") for x
|
|
|
|
|
in nodeFind.firstChild.nodeValue.replace("\t"," ").split(" ") if x]
|
|
|
|
|
if firstChild(nodeFind) is not None:
|
|
|
|
|
listOpt = [x for x
|
|
|
|
|
in firstChild(nodeFind).nodeValue.replace("\t"," ").split(" ") if x]
|
|
|
|
|
dataPars[opt] = listOpt
|
|
|
|
|
return dataPars
|
|
|
|
|
|
|
|
|
@ -16585,8 +16582,8 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
if not xmlStaticHosts:
|
|
|
|
|
return []
|
|
|
|
|
slpHostName = 'host%s' %hostName.lower()
|
|
|
|
|
return [x.parentNode.parentNode for x in xmlStaticHosts
|
|
|
|
|
if slpHostName == x.firstChild.nodeValue.lower()]
|
|
|
|
|
return [x.getparent().getparent() for x in xmlStaticHosts
|
|
|
|
|
if slpHostName == firstChild(x).nodeValue.lower()]
|
|
|
|
|
|
|
|
|
|
def getXMLNet(self, net):
|
|
|
|
|
"""Получить XML ноду подсети по ip"""
|
|
|
|
@ -16598,9 +16595,9 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
return []
|
|
|
|
|
slpNetName = 'subnet%s' %net.lower()
|
|
|
|
|
lenSlpNetName = len(slpNetName)
|
|
|
|
|
return [x.parentNode.parentNode for x in xmlSubnets
|
|
|
|
|
if len(x.firstChild.nodeValue) > lenSlpNetName and
|
|
|
|
|
slpNetName == x.firstChild.nodeValue[:lenSlpNetName].lower()]
|
|
|
|
|
return [x.getparent().getparent() for x in xmlSubnets
|
|
|
|
|
if len(firstChild(x).nodeValue) > lenSlpNetName and
|
|
|
|
|
slpNetName == firstChild(x).nodeValue[:lenSlpNetName].lower()]
|
|
|
|
|
|
|
|
|
|
def createStaticHost(self, hostname, ip, mac):
|
|
|
|
|
"""Создает статический хост в файле конфигурации dhcp"""
|
|
|
|
@ -16611,7 +16608,7 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
xmlNodeBodyNewNet = dhcpObj.docObj.getNodeBody()
|
|
|
|
|
namesAreaNew = xpath.Evaluate("child::area/child::caption/child::name",
|
|
|
|
|
xmlNodeBodyNewNet)
|
|
|
|
|
splNameNewNode = namesAreaNew[0].firstChild.nodeValue
|
|
|
|
|
splNameNewNode = firstChild(namesAreaNew[0]).nodeValue
|
|
|
|
|
hostnameNode = splNameNewNode.partition("host")[2].strip()
|
|
|
|
|
if self.getXMLStaticHost(hostnameNode):
|
|
|
|
|
self.setError(_('DHCP static host "%s" exists')%hostnameNode)
|
|
|
|
@ -16627,10 +16624,10 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
if self.getError():
|
|
|
|
|
return False
|
|
|
|
|
namesArea = xpath.Evaluate("child::caption/child::name", xmlNode)
|
|
|
|
|
splNameNewNode = namesArea[0].firstChild.nodeValue
|
|
|
|
|
splNameNewNode = firstChild(namesArea[0]).nodeValue
|
|
|
|
|
netIPList = splNameNewNode.partition("subnet")[2].partition("netmask")
|
|
|
|
|
netIP = netIPList[0].strip().encode("UTF-8")
|
|
|
|
|
netMask = netIPList[2].partition("{")[0].strip().encode("UTF-8")
|
|
|
|
|
netIP = netIPList[0].strip()
|
|
|
|
|
netMask = netIPList[2].partition("{")[0].strip()
|
|
|
|
|
if not any((routers, domainName, dnsIPs, iprange)):
|
|
|
|
|
self.setError(_("empty modify options"))
|
|
|
|
|
return False
|
|
|
|
@ -16641,7 +16638,7 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
# Объединение конфигураций
|
|
|
|
|
self.join(dhcpObj)
|
|
|
|
|
# Запись файла
|
|
|
|
|
text = self.getConfig().encode("UTF-8")
|
|
|
|
|
text = self.getConfig()
|
|
|
|
|
return self.writeInConfig(text)
|
|
|
|
|
|
|
|
|
|
def modHostOpts(self, xmlNode, ip, mac):
|
|
|
|
@ -16649,8 +16646,8 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
if self.getError():
|
|
|
|
|
return False
|
|
|
|
|
namesArea = xpath.Evaluate("child::caption/child::name", xmlNode)
|
|
|
|
|
splNameNewNode = namesArea[0].firstChild.nodeValue
|
|
|
|
|
hostname = splNameNewNode.partition("host")[2].strip().encode("UTF-8")
|
|
|
|
|
splNameNewNode = firstChild(namesArea[0]).nodeValue
|
|
|
|
|
hostname = splNameNewNode.partition("host")[2].strip()
|
|
|
|
|
if not any((ip, mac)):
|
|
|
|
|
self.setError(_("empty modify options"))
|
|
|
|
|
return False
|
|
|
|
@ -16659,7 +16656,7 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
# Объединение конфигураций
|
|
|
|
|
self.join(dhcpObj)
|
|
|
|
|
# Запись файла
|
|
|
|
|
text = self.getConfig().encode("UTF-8")
|
|
|
|
|
text = self.getConfig()
|
|
|
|
|
return self.writeInConfig(text)
|
|
|
|
|
|
|
|
|
|
def createNet(self, net, routers, domainNames, dnsIPs, ipranges):
|
|
|
|
@ -16681,30 +16678,30 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
xmlNodeBodyNewNet = dhcpObj.docObj.getNodeBody()
|
|
|
|
|
namesAreaNew = xpath.Evaluate("child::area/child::caption/child::name",
|
|
|
|
|
xmlNodeBodyNewNet)
|
|
|
|
|
splNameNewNode = namesAreaNew[0].firstChild.nodeValue
|
|
|
|
|
splNameNewNode = firstChild(namesAreaNew[0]).nodeValue
|
|
|
|
|
netIP = splNameNewNode.partition("subnet")[2].partition("netmask")[0]
|
|
|
|
|
netIP = netIP.encode("UTF-8")
|
|
|
|
|
# netIP = netIP.encode("UTF-8")
|
|
|
|
|
if self.getXMLNet(netIP):
|
|
|
|
|
self.setError(_('DHCP subnet "%s" exists')%netIP)
|
|
|
|
|
return False
|
|
|
|
|
# Объединение конфигураций
|
|
|
|
|
self.join(dhcpObj)
|
|
|
|
|
# Запись файла
|
|
|
|
|
text = self.getConfig().encode("UTF-8")
|
|
|
|
|
text = self.getConfig()
|
|
|
|
|
return self.writeInConfig(text)
|
|
|
|
|
|
|
|
|
|
def deleteAllNetAndHosts(self):
|
|
|
|
|
"""Удаляет все сети и статические хосты из конфигурационного файла"""
|
|
|
|
|
# IP всех сетей
|
|
|
|
|
delNamesNets = [x.firstChild.nodeValue.partition("subnet")[2].\
|
|
|
|
|
partition("netmask")[0].encode("UTF-8")
|
|
|
|
|
delNamesNets = [firstChild(x).nodeValue.partition("subnet")[2].\
|
|
|
|
|
partition("netmask")[0]
|
|
|
|
|
for x in self.getAllXMLSubnet()
|
|
|
|
|
if x.firstChild]
|
|
|
|
|
if firstChild(x) is not None]
|
|
|
|
|
# Имена всех статических хостов
|
|
|
|
|
delNamesHosts = [x.firstChild.nodeValue.partition("host")[2].\
|
|
|
|
|
strip().encode("UTF-8")
|
|
|
|
|
delNamesHosts = [firstChild(x).nodeValue.partition("host")[2].\
|
|
|
|
|
strip()
|
|
|
|
|
for x in self._getAllXMLStaticHosts()
|
|
|
|
|
if x.firstChild]
|
|
|
|
|
if firstChild(x) is not None]
|
|
|
|
|
# Удаление
|
|
|
|
|
for term in (self.deleteNet(x) for x in delNamesNets):
|
|
|
|
|
if not term:
|
|
|
|
@ -16726,8 +16723,8 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
return False
|
|
|
|
|
# Удаление областей
|
|
|
|
|
xmlNodeBody = self.docObj.getNodeBody()
|
|
|
|
|
nextNode = lambda x: x.nextSibling
|
|
|
|
|
prevNode = lambda x: x.previousSibling
|
|
|
|
|
nextNode = lambda x: x.getnext()
|
|
|
|
|
prevNode = lambda x: x.getprevious()
|
|
|
|
|
delNodesNext = []
|
|
|
|
|
delNodesPrev = []
|
|
|
|
|
for node in deletesNodes:
|
|
|
|
@ -16757,10 +16754,10 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
delNodesNext.pop()
|
|
|
|
|
delNodes = delNodesPrev + delNodesNext
|
|
|
|
|
# Удаляем переводы строк
|
|
|
|
|
[xmlNodeBody.removeChild(x) for x in delNodes]
|
|
|
|
|
[xmlNodeBody.remove(x) for x in delNodes]
|
|
|
|
|
#print xmlNodeBody.toprettyxml().encode("UTF-8")
|
|
|
|
|
# Удаляем области
|
|
|
|
|
for term in (xmlNodeBody.removeChild(x) for x in deletesNodes):
|
|
|
|
|
for term in (xmlNodeBody.remove(x) for x in deletesNodes):
|
|
|
|
|
if not term:
|
|
|
|
|
self.setError(_('Can not remove static host "%s"')%hostname+\
|
|
|
|
|
" " + _("in config file %s")%self.nameConfigFile)
|
|
|
|
@ -16781,8 +16778,8 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
return False
|
|
|
|
|
# Удаление областей
|
|
|
|
|
xmlNodeBody = self.docObj.getNodeBody()
|
|
|
|
|
nextNode = lambda x: x.nextSibling
|
|
|
|
|
prevNode = lambda x: x.previousSibling
|
|
|
|
|
nextNode = lambda x: x.getnext()
|
|
|
|
|
prevNode = lambda x: x.getprevious()
|
|
|
|
|
delNodesNext = []
|
|
|
|
|
delNodesPrev = []
|
|
|
|
|
for node in deletesNodes:
|
|
|
|
@ -16812,16 +16809,16 @@ class dncpTxt(cl_profile.dhcp, shareTxt, shareIP):
|
|
|
|
|
delNodesNext.pop()
|
|
|
|
|
delNodes = delNodesPrev + delNodesNext
|
|
|
|
|
# Удаляем переводы строк
|
|
|
|
|
[xmlNodeBody.removeChild(x) for x in delNodes]
|
|
|
|
|
[xmlNodeBody.remove(x) for x in delNodes]
|
|
|
|
|
#print xmlNodeBody.toprettyxml().encode("UTF-8")
|
|
|
|
|
# Удаляем области
|
|
|
|
|
for term in (xmlNodeBody.removeChild(x) for x in deletesNodes):
|
|
|
|
|
for term in (xmlNodeBody.remove(x) for x in deletesNodes):
|
|
|
|
|
if not term:
|
|
|
|
|
self.setError(_('Can not remove subnet "%s"')%net+\
|
|
|
|
|
" " + _("in config file %s")%self.nameConfigFile)
|
|
|
|
|
return False
|
|
|
|
|
# Запись файла
|
|
|
|
|
text = self.getConfig().encode("UTF-8")
|
|
|
|
|
text = self.getConfig()
|
|
|
|
|
return self.writeInConfig(text)
|
|
|
|
|
|
|
|
|
|
class dnsTxt(cl_profile.bind,shareTxt):
|
|
|
|
@ -16883,8 +16880,8 @@ class dnsTxt(cl_profile.bind,shareTxt):
|
|
|
|
|
if not namesArea:
|
|
|
|
|
return []
|
|
|
|
|
return [x for x in namesArea
|
|
|
|
|
if x.firstChild and x.firstChild.nodeValue and\
|
|
|
|
|
'zone"' in x.firstChild.nodeValue]
|
|
|
|
|
if firstChild(x) is not None and firstChild(x).nodeValue and\
|
|
|
|
|
'zone"' in firstChild(x).nodeValue]
|
|
|
|
|
|
|
|
|
|
def getXMLZoneToName(self, nameZone):
|
|
|
|
|
"""Получить XML ноду DNS зоны по ее имени"""
|
|
|
|
@ -16897,10 +16894,10 @@ class dnsTxt(cl_profile.bind,shareTxt):
|
|
|
|
|
if not xmlZonesNames:
|
|
|
|
|
return []
|
|
|
|
|
nameZoneL = nameZone.lower()
|
|
|
|
|
return [x.parentNode.parentNode
|
|
|
|
|
return [x.getparent().getparent()
|
|
|
|
|
for x in xmlZonesNames
|
|
|
|
|
if nameZoneL == \
|
|
|
|
|
x.firstChild.nodeValue.lower().partition('"')[2].partition('"')[0]]
|
|
|
|
|
firstChild(x).nodeValue.lower().partition('"')[2].partition('"')[0]]
|
|
|
|
|
|
|
|
|
|
def getAllNamesZones(self):
|
|
|
|
|
"""Получить все имена нод областей (кроме служебных)"""
|
|
|
|
@ -16912,16 +16909,16 @@ class dnsTxt(cl_profile.bind,shareTxt):
|
|
|
|
|
if not xmlZonesNames:
|
|
|
|
|
return retNodesNames
|
|
|
|
|
for nodeZone in xmlZonesNames:
|
|
|
|
|
if '"."' in nodeZone.firstChild.nodeValue.lower():
|
|
|
|
|
if '"."' in firstChild(nodeZone).nodeValue.lower():
|
|
|
|
|
continue
|
|
|
|
|
elif '"localhost"' in nodeZone.firstChild.nodeValue.lower():
|
|
|
|
|
elif '"localhost"' in firstChild(nodeZone).nodeValue.lower():
|
|
|
|
|
continue
|
|
|
|
|
elif '"127.in-addr.arpa"' in nodeZone.firstChild.nodeValue.lower():
|
|
|
|
|
elif '"127.in-addr.arpa"' in firstChild(nodeZone).nodeValue.lower():
|
|
|
|
|
continue
|
|
|
|
|
retNodesNames.append(\
|
|
|
|
|
nodeZone.firstChild.nodeValue.rpartition('"')[0].partition('"')[2])
|
|
|
|
|
firstChild(nodeZone).nodeValue.rpartition('"')[0].partition('"')[2])
|
|
|
|
|
retNodesNames = [x for x in retNodesNames if x]
|
|
|
|
|
return [x.encode("UTF-8") for x in retNodesNames]
|
|
|
|
|
return retNodesNames
|
|
|
|
|
|
|
|
|
|
def deleteZone(self, zoneName):
|
|
|
|
|
"""Удаляет зону из конфигурационного файла bind"""
|
|
|
|
@ -16935,8 +16932,8 @@ class dnsTxt(cl_profile.bind,shareTxt):
|
|
|
|
|
return False
|
|
|
|
|
# Удаление областей
|
|
|
|
|
xmlNodeBody = self.docObj.getNodeBody()
|
|
|
|
|
nextNode = lambda x: x.nextSibling
|
|
|
|
|
prevNode = lambda x: x.previousSibling
|
|
|
|
|
nextNode = lambda x: x.getnext()
|
|
|
|
|
prevNode = lambda x: x.getprevious()
|
|
|
|
|
delNodesNext = []
|
|
|
|
|
delNodesPrev = []
|
|
|
|
|
for node in deletesNodes:
|
|
|
|
@ -16966,16 +16963,16 @@ class dnsTxt(cl_profile.bind,shareTxt):
|
|
|
|
|
delNodesNext.pop()
|
|
|
|
|
delNodes = delNodesPrev + delNodesNext
|
|
|
|
|
# Удаляем переводы строк
|
|
|
|
|
[xmlNodeBody.removeChild(x) for x in delNodes]
|
|
|
|
|
[xmlNodeBody.remove(x) for x in delNodes]
|
|
|
|
|
#print xmlNodeBody.toprettyxml().encode("UTF-8")
|
|
|
|
|
# Удаляем области
|
|
|
|
|
for term in [xmlNodeBody.removeChild(x) for x in deletesNodes]:
|
|
|
|
|
for term in [xmlNodeBody.remove(x) for x in deletesNodes]:
|
|
|
|
|
if not term:
|
|
|
|
|
self.setError(_('Can not remove DNS zone "%s"')%zoneName+\
|
|
|
|
|
" " + _("in config file %s")%self.nameConfigFile)
|
|
|
|
|
return False
|
|
|
|
|
# Запись файла
|
|
|
|
|
text = self.getConfig().encode("UTF-8")
|
|
|
|
|
text = self.getConfig()
|
|
|
|
|
return self.writeInConfig(text)
|
|
|
|
|
|
|
|
|
|
def deleteAllZones(self, functPrintSuccess=False):
|
|
|
|
@ -16995,7 +16992,7 @@ class dnsTxt(cl_profile.bind,shareTxt):
|
|
|
|
|
if not xmlZonesNames:
|
|
|
|
|
return True
|
|
|
|
|
for nodeZone in xmlZonesNames:
|
|
|
|
|
nodeValue = nodeZone.firstChild.nodeValue.lower()
|
|
|
|
|
nodeValue = firstChild(nodeZone).nodeValue.lower()
|
|
|
|
|
if '"."' in nodeValue:
|
|
|
|
|
continue
|
|
|
|
|
elif '"localhost"' in nodeValue:
|
|
|
|
@ -17003,14 +17000,14 @@ class dnsTxt(cl_profile.bind,shareTxt):
|
|
|
|
|
elif '"127.in-addr.arpa"' in nodeValue:
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
nodeValue = nodeValue.encode("UTF-8")
|
|
|
|
|
# nodeValue = nodeValue.encode("UTF-8")
|
|
|
|
|
# Название зоны
|
|
|
|
|
nameZ = nodeValue.rpartition('"')[0].partition('"')[2]
|
|
|
|
|
deletesNodes.append((nodeZone.parentNode.parentNode,nameZ))
|
|
|
|
|
deletesNodes.append((nodeZone.getparent().getparent(), nameZ))
|
|
|
|
|
# Удаление областей
|
|
|
|
|
xmlNodeBody = self.docObj.getNodeBody()
|
|
|
|
|
nextNode = lambda x: x.nextSibling
|
|
|
|
|
prevNode = lambda x: x.previousSibling
|
|
|
|
|
nextNode = lambda x: x.getnext()
|
|
|
|
|
prevNode = lambda x: x.getprevious()
|
|
|
|
|
delNodesNext = []
|
|
|
|
|
delNodesPrev = []
|
|
|
|
|
for node, zoneNameTmp in deletesNodes:
|
|
|
|
@ -17043,11 +17040,11 @@ class dnsTxt(cl_profile.bind,shareTxt):
|
|
|
|
|
if not delNode in delNodes:
|
|
|
|
|
delNodes.append(delNode)
|
|
|
|
|
# Удаляем переводы строк
|
|
|
|
|
[xmlNodeBody.removeChild(x) for x in delNodes]
|
|
|
|
|
[xmlNodeBody.remove(x) for x in delNodes]
|
|
|
|
|
#print xmlNodeBody.toprettyxml().encode("UTF-8")
|
|
|
|
|
# Удаляем области
|
|
|
|
|
for delNode, zoneName in deletesNodes:
|
|
|
|
|
if xmlNodeBody.removeChild(delNode):
|
|
|
|
|
if xmlNodeBody.remove(delNode):
|
|
|
|
|
# Печатаем сообщение о успешном удалении зоны
|
|
|
|
|
if flagPrintSuccess:
|
|
|
|
|
functPrintSuccess(zoneName)
|
|
|
|
@ -17056,7 +17053,7 @@ class dnsTxt(cl_profile.bind,shareTxt):
|
|
|
|
|
" " + _("in config file %s")%self.nameConfigFile)
|
|
|
|
|
return False
|
|
|
|
|
# Запись файла
|
|
|
|
|
text = self.getConfig().encode("UTF-8")
|
|
|
|
|
text = self.getConfig()
|
|
|
|
|
return self.writeInConfig(text)
|
|
|
|
|
|
|
|
|
|
def createZone(self, clVars, zoneName, zoneType, zoneMasters=[]):
|
|
|
|
@ -17072,7 +17069,7 @@ class dnsTxt(cl_profile.bind,shareTxt):
|
|
|
|
|
namesAreaNew = xpath.Evaluate(\
|
|
|
|
|
"child::area/child::caption/child::name", xmlNodeBodyNewZone)
|
|
|
|
|
splNameNewNode =\
|
|
|
|
|
namesAreaNew[0].firstChild.nodeValue.replace("{","").split('"')
|
|
|
|
|
firstChild(namesAreaNew[0]).nodeValue.replace("{","").split('"')
|
|
|
|
|
splNameNewNode = splNameNewNode[1]
|
|
|
|
|
if self.getXMLZoneToName(splNameNewNode):
|
|
|
|
|
self.setError(_('DNS zone "%s" exists')%splNameNewNode)
|
|
|
|
@ -17080,7 +17077,7 @@ class dnsTxt(cl_profile.bind,shareTxt):
|
|
|
|
|
# Объединение конфигураций
|
|
|
|
|
self.join(bindObj)
|
|
|
|
|
# Запись файла
|
|
|
|
|
text = self.getConfig().encode("UTF-8")
|
|
|
|
|
text = self.getConfig()
|
|
|
|
|
return self.writeInConfig(text)
|
|
|
|
|
|
|
|
|
|
def notFoundZones(self, zoneNames):
|
|
|
|
@ -20211,7 +20208,7 @@ class servDhcp(shareLdap, shareIP):
|
|
|
|
|
self.printERROR("Can not found network %s in network interfaces: \
|
|
|
|
|
eth0, eth1, ... etc."%net)
|
|
|
|
|
if osNets:
|
|
|
|
|
self.printWARNING(_("Existing nets: %s")%osNets)
|
|
|
|
|
self.printWARNING(_("Existing nets: %s") % osNets)
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def isCorrectMacAddress(self, mac):
|
|
|
|
|