|
|
@@ -8,7 +8,7 @@ from django.core.mail import EmailMultiAlternatives
|
|
|
from django.template.loader import get_template
|
|
|
from django.template import Context
|
|
|
from django.template import engines, TemplateSyntaxError
|
|
|
-from datetime import date
|
|
|
+from datetime import date,datetime
|
|
|
from uuid import uuid4,UUID
|
|
|
import json
|
|
|
from mqtt import views as m
|
|
|
@@ -19,22 +19,6 @@ import re
|
|
|
from django.db.models import Sum
|
|
|
from .templatetags.commtags import *
|
|
|
|
|
|
-def template_from_string(template_string, using=None):
|
|
|
- """
|
|
|
- Convert a string into a template object,
|
|
|
- using a given template engine or using the default backends
|
|
|
- from settings.TEMPLATES if no engine was specified.
|
|
|
- """
|
|
|
- # This function is based on django.template.loader.get_template,
|
|
|
- # but uses Engine.from_string instead of Engine.get_template.
|
|
|
- chain = []
|
|
|
- engine_list = engines.all() if using is None else [engines[using]]
|
|
|
- for engine in engine_list:
|
|
|
- try:
|
|
|
- return engine.from_string(template_string)
|
|
|
- except TemplateSyntaxError as e:
|
|
|
- chain.append(e)
|
|
|
- raise TemplateSyntaxError(template_string, chain=chain)
|
|
|
|
|
|
class ServizioMail:
|
|
|
def __init__(self,debug=False):
|
|
|
@@ -47,6 +31,22 @@ class ServizioMail:
|
|
|
self.corpo_html = ""
|
|
|
self.set_data()
|
|
|
self.json = None
|
|
|
+ def template_from_string(self,template_string, using=None):
|
|
|
+ """
|
|
|
+ Convert a string into a template object,
|
|
|
+ using a given template engine or using the default backends
|
|
|
+ from settings.TEMPLATES if no engine was specified.
|
|
|
+ """
|
|
|
+ # This function is based on django.template.loader.get_template,
|
|
|
+ # but uses Engine.from_string instead of Engine.get_template.
|
|
|
+ chain = []
|
|
|
+ engine_list = engines.all() if using is None else [engines[using]]
|
|
|
+ for engine in engine_list:
|
|
|
+ try:
|
|
|
+ return engine.from_string(template_string)
|
|
|
+ except TemplateSyntaxError as e:
|
|
|
+ chain.append(e)
|
|
|
+ raise TemplateSyntaxError(template_string, chain=chain)
|
|
|
|
|
|
def set_listadestinatari(self,lista=[]):
|
|
|
self._to_ = []
|
|
|
@@ -96,11 +96,11 @@ class ServizioMail:
|
|
|
if self.debug: print("destinatari:",self._to_complete)
|
|
|
|
|
|
#rendering del soggetto
|
|
|
- soggetto = template_from_string(self.soggetto)
|
|
|
+ soggetto = self.template_from_string(self.soggetto)
|
|
|
soggetto_render = soggetto.render(self.data)
|
|
|
if self.debug: print("soggetto",soggetto)
|
|
|
|
|
|
- oggetto = template_from_string(self.oggetto)
|
|
|
+ oggetto = self.template_from_string(self.oggetto)
|
|
|
oggetto_render = None
|
|
|
try:
|
|
|
oggetto_render = oggetto.render(self.data)
|
|
|
@@ -802,7 +802,9 @@ def ConfermaScadenza(request,uuid=None):
|
|
|
return render(request,'richiesta.conferma.html',value)
|
|
|
|
|
|
return render(request,"notfound.html")
|
|
|
-
|
|
|
+
|
|
|
+# misurazioni e occupazioni
|
|
|
+
|
|
|
def CheckQuotaMail(request,dominio=None,mail=None,quota=None):
|
|
|
value = {}
|
|
|
|
|
|
@@ -822,14 +824,20 @@ def CheckQuotaMail(request,dominio=None,mail=None,quota=None):
|
|
|
print('Trovato',d.nome,u.id,int(quota))
|
|
|
u.quota = int(quota)
|
|
|
u.save()
|
|
|
+
|
|
|
result = d.user_set.all().aggregate(Sum('mail_quota'))
|
|
|
- if not d.mail_quota: d.mail_quota = 0
|
|
|
+ if not d.mail_quota:
|
|
|
+ d.mail_quota = 0
|
|
|
+
|
|
|
d.last_mail_quota = d.mail_quota
|
|
|
d.date_mail_quota = date.today()
|
|
|
d.last_mail_check = True
|
|
|
+
|
|
|
if result['quota__sum']:
|
|
|
d.mail_quota = result['mail_quota__sum']
|
|
|
- else: d.mail_quota = 0
|
|
|
+ #else:
|
|
|
+ # d.mail_quota = 0
|
|
|
+
|
|
|
d.last_mail_quota_check = True
|
|
|
print('Quota mail',d.mail_quota)
|
|
|
d.save()
|
|
|
@@ -856,8 +864,12 @@ def CheckQuotaHttp(request,dominio=None,quota=None):
|
|
|
|
|
|
if result['quota__sum']:
|
|
|
d.http_quota = result['quota__sum']
|
|
|
- else: d.http_quota = 0
|
|
|
- if not d.http_quota: d.http_quota = 0
|
|
|
+ #else:
|
|
|
+ # d.http_quota = 0
|
|
|
+
|
|
|
+ if not d.http_quota:
|
|
|
+ d.http_quota = 0
|
|
|
+
|
|
|
d.last_http_quota_check = True
|
|
|
print('Quota http',d.http_quota)
|
|
|
d.save()
|
|
|
@@ -889,8 +901,12 @@ def CheckQuotaSql(request,database=None,quota=None):
|
|
|
|
|
|
if result['quota__sum']:
|
|
|
dd.sql_quota = result['quota__sum']
|
|
|
- else: dd.sql_quota = 0
|
|
|
- if not dd.sql_quota: dd.sql_quota = 0
|
|
|
+ #else:
|
|
|
+ # dd.sql_quota = 0
|
|
|
+
|
|
|
+ if not dd.sql_quota:
|
|
|
+ dd.sql_quota = 0
|
|
|
+
|
|
|
dd.last_sql_quota_check = True
|
|
|
dd.save()
|
|
|
print('Quota sql ',dd.sql_quota)
|
|
|
@@ -920,19 +936,36 @@ def CheckQuotaFtp(request,dominio=None,ftp=None,quota=None):
|
|
|
|
|
|
if result['quota__sum']:
|
|
|
d.ftp_quota = result['quota__sum']
|
|
|
- else: d.ftp_quota = 0
|
|
|
- if not d.ftp_quota: d.ftp_quota = 0
|
|
|
+ else:
|
|
|
+ d.ftp_quota = 0
|
|
|
+ if not d.ftp_quota:
|
|
|
+ d.ftp_quota = 0
|
|
|
d.last_ftp_quota_check = True
|
|
|
d.save()
|
|
|
print('Quota ftp ',d.ftp_quota)
|
|
|
|
|
|
return render(request,'Controllo.Quota.html',value)
|
|
|
|
|
|
-def ComunicazioneControlloQuota(request,demo=0):
|
|
|
+def ComunicazioneControlloQuota(request,demo=False,dominio=None):
|
|
|
value = {}
|
|
|
|
|
|
+ try:
|
|
|
+ dominio = int(dominio)
|
|
|
+ print('dominio indicato:',dominio)
|
|
|
+ except ValueError as ve:
|
|
|
+ print("dominio non valido:", dominio)
|
|
|
+ print(ve)
|
|
|
+ dominio = None
|
|
|
+
|
|
|
lista_quota = {}
|
|
|
- d = Domini.objects.all().order_by('nome')
|
|
|
+ d = None
|
|
|
+ try:
|
|
|
+ d = Domini.objects.filter(pk=dominio)
|
|
|
+ print(d)
|
|
|
+ except Domini.DoesNotExist as dne:
|
|
|
+ d = Domini.objects.all().order_by('nome')
|
|
|
+ print(d)
|
|
|
+
|
|
|
value['domini'] = d
|
|
|
|
|
|
sm = ServizioMail()
|
|
|
@@ -981,6 +1014,9 @@ def OccupazioneControlloQuota(request,dominio=None):
|
|
|
|
|
|
domini = None
|
|
|
|
|
|
+ dtask = datetime.now().timestamp()
|
|
|
+ dc = 0
|
|
|
+
|
|
|
if not dominio:
|
|
|
domini = Domini.objects.all().filter(tobedeleted=False)
|
|
|
else:
|
|
|
@@ -993,7 +1029,7 @@ def OccupazioneControlloQuota(request,dominio=None):
|
|
|
mq.build('richiesta','quota')
|
|
|
mq.build('stampa',False)
|
|
|
tmp = dict()
|
|
|
- tmp['numero'] = len(domini)
|
|
|
+ tmp['dtask'] = dtask
|
|
|
tmpdom = list()
|
|
|
for d in domini:
|
|
|
tmpdom.append({'id':d.id,'nome':d.nome})
|
|
|
@@ -1005,7 +1041,7 @@ def OccupazioneControlloQuota(request,dominio=None):
|
|
|
|
|
|
listadomini = list() #contiene la lista dei domini da pubblicare
|
|
|
|
|
|
- #cazz
|
|
|
+ #cazz - inizio operazioni
|
|
|
for dominio in domini:
|
|
|
listadomini.append(dominio)
|
|
|
ftpdict = dict()
|
|
|
@@ -1020,10 +1056,12 @@ def OccupazioneControlloQuota(request,dominio=None):
|
|
|
for lf in listaftp:
|
|
|
# le sezioni si possono dividere in tre, due accorpabili
|
|
|
# http e stor, enb (enb: enbass, da verificare) 01.12.22
|
|
|
-
|
|
|
ftpdict['ftpid'] = lf.id
|
|
|
ftpdict['ftpuser']= lf.utente
|
|
|
- #print('ftp id',lf.id)
|
|
|
+ dc = dc +1
|
|
|
+ ftpdict['dc'] = dc
|
|
|
+ ftpdict['dtask'] = dtask
|
|
|
+ print('ftp id',lf.id,'counter',dc,'dtask',dtask)
|
|
|
try:
|
|
|
#print('ftpgroup',lf.ftpgroup.id)
|
|
|
#construisce la stringa che deve essere inviata via mqtt
|
|
|
@@ -1052,12 +1090,16 @@ def OccupazioneControlloQuota(request,dominio=None):
|
|
|
maildict['mailid'] = lm.id
|
|
|
maildict['mailuser'] = lm.mail
|
|
|
maildict['mailserver'] = dominio.mail_server.fisico
|
|
|
+ dc = dc +1
|
|
|
+ maildict['dc'] = dc
|
|
|
+ maildict['dtask'] = dtask
|
|
|
try:
|
|
|
maildict['mailserver'] = lm.mail_server.fisico
|
|
|
except MailServer.DoesNotExist as dne:
|
|
|
print('mail server non indicato nel record mail')
|
|
|
|
|
|
print('stringa da inviare per la mail: ',maildict)
|
|
|
+
|
|
|
try:
|
|
|
print('richiesta su server specifico',lm.id)
|
|
|
m.publish(c,"Richiesta/Quota/Mail/{}".format(dominio.mail_server.nome),json.dumps(maildict))
|
|
|
@@ -1068,10 +1110,12 @@ def OccupazioneControlloQuota(request,dominio=None):
|
|
|
u = User.objects.get(pk=lm.id)
|
|
|
u.mail_quota=0
|
|
|
u.save()
|
|
|
+
|
|
|
dominio.mail_quota=0
|
|
|
dominio.save()
|
|
|
|
|
|
value['domini'] = listadomini
|
|
|
print('value',value)
|
|
|
+
|
|
|
return render(request,'Controllo.Quota.html',value)
|
|
|
|