Example #1
0
	def saveDomains(self, domains):
		from modules.domain import Domain, DomainList
		domainList = DomainList()
		for f in domains['_items']:
			domainList.add(Domain.fromDict(f))
		log.debug('Want to save %i domains' % (len(domainList),))

		for domain in domainList:
			# get the old domain
			oldDomain = None
			if domain.state != Domain.STATE_CREATE:
				oldDomain = Domain(domain.id)
				oldDomain.load()
				
			domain.save(oldDomain)
			# check if corresponding dns file exists.
			
			if conf.getboolean('dns', 'active'):
				fqdn = domain.getFullDomain()
				fileName = '%s.db' % (fqdn,)
				path = os.path.join(conf.get('dns', 'cache'), fileName)
				if domain.state != Domain.STATE_DELETE:
					if not os.path.exists(path):
						try:
							with open(path, 'wb') as f:
								f.write('\n'.encode('utf-8'))
						except:
							pass
						else:
							self.__addZoneFile(domain, path)
					else:
						self.__addZoneFile(domain, path)
				else:
					self.__removeZoneFile(domain, path)
Example #2
0
	def getDomainZoneFile(self, domainId):
		from modules.domain import Domain
		content = ''
		d = Domain(domainId)
		if not d.load():
			log.warning('Could not get the domain %s' % (domainId,))
			return content

		content = d.generateBindFile()
		log.debug('Generated the domain bind file for domain %s' % (domainId,))
		return content
Example #3
0
	def saveDns(self, domain, dns):
		from modules.domain import Domain
		dnsList = DNSList()
		for f in dns['_items']:
			dnsList.add(Dns.fromDict(f))
		log.debug('Want to save %i dns items!' % (len(dnsList),))

		for d in dnsList:
			d.save()

		if domain is not None and (type(domain) == int or len(domain.strip()) > 0) and conf.getboolean('dns', 'active'):
			content = self.getDomainZoneFile(domain)
			# now we need the Domain
			dom = Domain(domain)
			if not dom.load():
				log.warning('Could not load the domain %s for generating zone file!' % (domain,))
				return False

			# we need the fully qualified domain name!
			fqdn = dom.getFullDomain()
			# now try to save it!
			fileName = '%s.db' % (fqdn,)
			path = os.path.join(conf.get('dns', 'cache'), fileName)
			addToZoneFile = False
			if not os.path.exists(path):
				addToZoneFile = True
			try:
				with open(path, 'wb') as f:
					f.write(content.encode('utf-8'))
			except Exception as e:
				log.warning('Could not update the database file for the DNS-Service because of %s' % (str(e),))
			else:
				log.info('Update the DNS-Service-Database %s' % (os.path.join(conf.get('dns', 'cache'), fileName),))
				if addToZoneFile:
					self.__addZoneFile(path)

			# reload 
			try:
				reloadDns()
			except Exception as e:
				log.critical('Could not reload the DNS-Service because of %s!' % (str(e),))
			else:
				log.info('DNS-Service reloaded with success!')

		return True