Jelajahi Sumber

intanto ho aggiornato tutto per funzionare in una struttura con docker
compose
aggiornate le librerie mqtt che richiedono un cambio di parametri
nell'istanziare l'oggetto mqttclient.Client.
Aggiunta la visualizzazione della versione django una volta effettuato
il login solo nella pagina iniziale.
inserite una serie di modifiche nella visualizzazione e nei calcoli
degli spazio occupati.

mauro 4 bulan lalu
induk
melakukan
4829228a8c

+ 1 - 1
alias/templates/Alias.List.html

@@ -46,7 +46,7 @@
 	  <td><button class="btn btn-primary" type="submit" name='edit' value="{{ u.id }}" {% if not u.enabled %} disabled {% endif %}>Edit</button>
 	  <td><button class="btn btn-primary" type="submit" name='edit' value="{{ u.id }}" {% if not u.enabled %} disabled {% endif %}>Edit</button>
   	      <button class="btn btn-primary" type="button" data-toggle="modal" data-target="#ConfirmDisable{{ u.id }}" name='enabledisablebutton' value="{{ u.id }}" >
   	      <button class="btn btn-primary" type="button" data-toggle="modal" data-target="#ConfirmDisable{{ u.id }}" name='enabledisablebutton' value="{{ u.id }}" >
 		      {% if u.enabled %}Disabilita{% else %}Abilita{% endif %}</button>
 		      {% if u.enabled %}Disabilita{% else %}Abilita{% endif %}</button>
-	      <button class="btn btn-primary" type='button' data-toggle='modal' data-target="#ConfirmDelete{{ u.id }}" name='deletebutton' value="{{ u.id }}" {% if not u.locked and u.enabled %} disabled {% endif %}>{% if u.tobedeleted %}Recupera{% else %}Cancella{% endif %}</button></td>
+	      <button class="btn btn-primary" type='button' data-toggle='modal' data-target="#ConfirmDelete{{ u.id }}" name='deletebutton' value="{{ u.id }}" {% if not u.locked and not u.enabled %} disabled {% endif %}>{% if u.tobedeleted %}Recupera{% else %}Cancella{% endif %}</button></td>
         </tr>
         </tr>
 
 
         <!-- Modal -->
         <!-- Modal -->

+ 3 - 2
alias/views.py

@@ -72,9 +72,10 @@ def AliasList(request):
       print('id da disattivare',request.POST['deletebutton'])
       print('id da disattivare',request.POST['deletebutton'])
       idpost = request.POST['deletebutton']
       idpost = request.POST['deletebutton']
       u = Alias.objects.get(pk=idpost)
       u = Alias.objects.get(pk=idpost)
-      if not u.locked and not u.enabled:
+      print('u.tobedelete',u.tobedeleted)
+      if not u.locked: # non deve essere bloccato e non deve essere abilitato
         u.tobedeleted = not u.tobedeleted
         u.tobedeleted = not u.tobedeleted
-        if u.locked: u.save()
+        if not u.locked: u.save()
 
 
   return render(request,"Alias.List.html",value)
   return render(request,"Alias.List.html",value)
 
 

+ 32 - 2
comunicazioni/templates/Controllo.Quota.html

@@ -6,12 +6,42 @@
 {% block body %}
 {% block body %}
 
 
   <p>{% if demo %} Non sono state inviate mail - modalita' demo attiva {% endif %}</p>
   <p>{% if demo %} Non sono state inviate mail - modalita' demo attiva {% endif %}</p>
-  <table class='table'>
+
+  <p>DOMINI CHE HANNO SUPERATO LA SOGLIA</p>
+  <table class='table table-striped table-hover'>
+    <tr>
+      <th scope='col'>dominio</th>
+      <th scope='col'>rilevamento</th>
+      <th scope='col'>target</th>
+      <th scope='col'>Attuale</th>
+      <th scope='col'>Precedente</th>
+      <th scope='col'>Variazione</th>
+      <th scope='col'>Extra Target</th>
+    </tr>
+    {% for i in  domini %}
+      {% if i|QuotaAlert %}
+        <tr>
+          <td>{{ i.nome }}</td>
+          <td>{{ i.date_mail_quota }}</td>
+          <td>{{ i.target.spazio|Giga }} - {{ i.target.nome }}</td>
+          <td>{{ i|SumQuota|Giga }}</td>
+          <td>{{ i|SumLast|Giga }}</td>
+          <td>{{ i|DiffQuota|Giga }}</td>
+          <td>{{ i|QuotaAlert|Giga }}</td>
+        </tr>
+      {% endif %}
+    {% endfor %}
+  </table>
+
+  <br><br>
+  <p>Lista domini in essere</p>
+
+  <table class='table table-striped table-hover'>
     <thead>
     <thead>
       <tr>
       <tr>
         <th scope='col'>Dominio</th>
         <th scope='col'>Dominio</th>
 	<th scope='col'>Target</th>
 	<th scope='col'>Target</th>
-        <th scope='col'>Quota</th>
+        <th scope='col'>Attuale</th>
         <th scope='col'>Precedente</th>
         <th scope='col'>Precedente</th>
         <th scope='col'>Differenza</th>
         <th scope='col'>Differenza</th>
 	<th scope='col'>Extra Target</th>
 	<th scope='col'>Extra Target</th>

+ 18 - 1
comunicazioni/templatetags/commtags.py

@@ -3,27 +3,44 @@ from datetime import date
 
 
 register = template.Library()
 register = template.Library()
 
 
+'''
 @register.filter(name='Sum')
 @register.filter(name='Sum')
 def sum(v):
 def sum(v):
   totale = v.mail_quota + v.http_quota + v.ftp_quota + v.sql_quota + v.nextcloud_quota
   totale = v.mail_quota + v.http_quota + v.ftp_quota + v.sql_quota + v.nextcloud_quota
   return totale
   return totale
+'''
 
 
 @register.filter(name='SumQuota')
 @register.filter(name='SumQuota')
 def sumQuota(v):
 def sumQuota(v):
+  # quota attuale
   totale = v.mail_quota + v.http_quota + v.ftp_quota + v.sql_quota + v.nextcloud_quota
   totale = v.mail_quota + v.http_quota + v.ftp_quota + v.sql_quota + v.nextcloud_quota
   return totale
   return totale
 
 
 @register.filter(name='SumLast')
 @register.filter(name='SumLast')
 def sumLast(v):
 def sumLast(v):
+  # quota precedente
   totale = v.last_mail_quota + v.last_http_quota + v.last_ftp_quota + v.last_sql_quota + v.last_nextcloud_quota
   totale = v.last_mail_quota + v.last_http_quota + v.last_ftp_quota + v.last_sql_quota + v.last_nextcloud_quota
   return totale
   return totale
 
 
 @register.filter(name='DiffQuota')
 @register.filter(name='DiffQuota')
 def diffQuota(v):
 def diffQuota(v):
-  totale_attuale = v.mail_quota + v.http_quota + v.ftp_quota + v.sql_quota + v.nextcloud_quota
+  # differenza tra quota attuale e quota precedente
+  totale_attuale =    v.mail_quota +      v.http_quota +      v.ftp_quota +      v.sql_quota +      v.nextcloud_quota
+  print('totale_attuale',totale_attuale)
   totale_precedente = v.last_mail_quota + v.last_http_quota + v.last_ftp_quota + v.last_sql_quota + v.last_nextcloud_quota
   totale_precedente = v.last_mail_quota + v.last_http_quota + v.last_ftp_quota + v.last_sql_quota + v.last_nextcloud_quota
+  print('totale_precedente',totale_precedente)
+  print(totale_attuale - totale_precedente)
   return totale_attuale - totale_precedente
   return totale_attuale - totale_precedente
 
 
+@register.filter(name='DiffExtraContratto')
+def diffExtraContratto(v):
+  # differenza da contratto
+  totale_attuale = v.mail_quota + v.http_quota + v.ftp_quota + v.sql_quota + v.nextcloud_quota
+  risultato = totale_attuale - v.target.spazio
+  if risultato < 0:
+    return 0
+  return risultato
+
 @register.filter(name='DiffPercento')
 @register.filter(name='DiffPercento')
 def diffPercento(v):
 def diffPercento(v):
   totale_attuale =    v.mail_quota      + v.http_quota      + v.ftp_quota      + v.sql_quota      + v.nextcloud_quota
   totale_attuale =    v.mail_quota      + v.http_quota      + v.ftp_quota      + v.sql_quota      + v.nextcloud_quota

+ 5 - 6
comunicazioni/views.py

@@ -2,8 +2,6 @@ from django.shortcuts import render
 from django.core.mail import send_mail
 from django.core.mail import send_mail
 from django.core.mail import SafeMIMEText
 from django.core.mail import SafeMIMEText
 from configurazione.views import getConfigurazione
 from configurazione.views import getConfigurazione
-#from domini.views import Aggiorna_Dominio_Da_Causale
-
 from django.core.mail import EmailMultiAlternatives
 from django.core.mail import EmailMultiAlternatives
 from django.template.loader import get_template
 from django.template.loader import get_template
 from django.template import Context
 from django.template import Context
@@ -13,6 +11,7 @@ from uuid import uuid4,UUID
 import json
 import json
 from mqtt import views as m
 from mqtt import views as m
 from mqtt.views  import mqtt
 from mqtt.views  import mqtt
+#from domini.views import Aggiorna_Dominio_Da_Causale
 
 
 from .models import *
 from .models import *
 import re
 import re
@@ -330,7 +329,9 @@ def ControlloScadenzeContratto(request,demo=0,dominio=None,causale=None):
               d.renew_code = uuid4()
               d.renew_code = uuid4()
 
 
             if d.rinnovo_automatico:
             if d.rinnovo_automatico:
-                Aggiorna_Dominio_Da_Causale(d,getConfigurazione('Rinnovo:Automatico'))
+                c = Causale.objects.get(pk=getConfigurazione('Rinnovo:Automatico'))
+                print("Causale:",c.nome)
+                #Aggiorna_Dominio_Da_Causale(d,c,sm=ServizioMail())
 
 
             if not demo: 
             if not demo: 
               d.save()
               d.save()
@@ -338,7 +339,6 @@ def ControlloScadenzeContratto(request,demo=0,dominio=None,causale=None):
               print("Non salvo - modalita' demo")
               print("Non salvo - modalita' demo")
               listalog.append(("Non salvo - modalità demo"))
               listalog.append(("Non salvo - modalità demo"))
 
 
-
   data={}
   data={}
 
 
   #if demo:
   #if demo:
@@ -605,7 +605,6 @@ def ControlloScadenzaVicina(request,demo=0,dominio=None):
 
 
   return render(request,"Controllo.Vicino.html",data)
   return render(request,"Controllo.Vicino.html",data)
 
 
-
   
   
 def ConfermaScadenza(request,uuid=None):
 def ConfermaScadenza(request,uuid=None):
   # primo step, verifichiamo uuid
   # primo step, verifichiamo uuid
@@ -786,7 +785,7 @@ def ConfermaScadenza(request,uuid=None):
 
 
           if causale.send_email_account:
           if causale.send_email_account:
             ac = getConfigurazione("mail:accounting")
             ac = getConfigurazione("mail:accounting")
-            re.split(' |,',ac)
+            ac = re.split(' |,',ac)
             sm.set_rcptto(ac)
             sm.set_rcptto(ac)
             te = getConfigurazione("mail:accounting_template")
             te = getConfigurazione("mail:accounting_template")
             template = Template.objects.get(pk=te)
             template = Template.objects.get(pk=te)

+ 5 - 0
dashboard4/settings.py

@@ -168,3 +168,8 @@ FORCE_SCRIPT_NAME = '/dashboard4'
 
 
 #la sessione comunque scade alla chiusura del browser
 #la sessione comunque scade alla chiusura del browser
 SESSION_EXPIRE_AT_BROWSER_CLOSE=True
 SESSION_EXPIRE_AT_BROWSER_CLOSE=True
+
+#impostazioni di posta.
+EMAIL_HOST = '10.132.0.8'
+EMAIL_PORT = 25
+

+ 6 - 3
domini/views.py

@@ -13,12 +13,10 @@ import re
 from .models import *
 from .models import *
 from .forms import *
 from .forms import *
 from sicurezza.views import *
 from sicurezza.views import *
-
 from comunicazioni.views import *
 from comunicazioni.views import *
 
 
-def Aggiorna_Dominio_Da_Causale(d,c):
+def Aggiorna_Dominio_Da_Causale(d,c,sm=None):
 
 
-  sm = ServizioMail()
 
 
   dominio = d
   dominio = d
   print('dominio nome',dominio.nome)
   print('dominio nome',dominio.nome)
@@ -60,6 +58,9 @@ def Aggiorna_Dominio_Da_Causale(d,c):
   dominio.last_causale = causale
   dominio.last_causale = causale
   dominio.save()
   dominio.save()
 
 
+  if not sm:
+    return
+
   #imposta i destinatari
   #imposta i destinatari
   listadestinatari=[]
   listadestinatari=[]
   PresenteContattoDestinatari=False
   PresenteContattoDestinatari=False
@@ -454,6 +455,8 @@ def DomainEdit(request):
             for i in accountdft:
             for i in accountdft:
               listadestinatari.append(i)
               listadestinatari.append(i)
 
 
+      if causale.domain_tobedeleted:
+        dominio.tobedeleted = True
 
 
       dominio.last_causale = causale
       dominio.last_causale = causale
       dominio.save()
       dominio.save()

+ 2 - 0
login/views.py

@@ -11,6 +11,7 @@ from datetime import date,datetime
 from comunicazioni.views import *
 from comunicazioni.views import *
 from configurazione.views import *
 from configurazione.views import *
 from supporto import managepassword
 from supporto import managepassword
+import django as dd
 
 
 from mqtt.views import mqtt
 from mqtt.views import mqtt
 
 
@@ -143,6 +144,7 @@ def welcome(request):
   value={}
   value={}
   value['utenteautorizzato'] = record
   value['utenteautorizzato'] = record
   value['securitylevel'] = securitylevel
   value['securitylevel'] = securitylevel
+  value['versione'] = dd.get_version()
   print("id",record.securitylevel_id)
   print("id",record.securitylevel_id)
 
 
   securitylevel = getSecurityLevel(record.securitylevel_id)
   securitylevel = getSecurityLevel(record.securitylevel_id)

+ 2 - 2
mqtt/views.py

@@ -59,7 +59,7 @@ class mqtt(object):
     self.check['notifica_numero'] = False
     self.check['notifica_numero'] = False
 
 
   def login(self):
   def login(self):
-    self.client = mqttclient.Client(self.client_id)
+    self.client = mqttclient.Client(mqttclient.CallbackAPIVersion.VERSION1,self.client_id)
     self.client.username_pw_set(self.username,self.password)
     self.client.username_pw_set(self.username,self.password)
     self.client.on_connect = self.on_connect
     self.client.on_connect = self.on_connect
 
 
@@ -212,7 +212,7 @@ def start():
     else:
     else:
       print('mqtt failed')
       print('mqtt failed')
 
 
-  client = mqttclient.Client(client_id)
+  client = mqttclient.Client(mqttclient.CallbackAPIVersion.VERSION1,client_id)
   client.username_pw_set(username,password)
   client.username_pw_set(username,password)
   client.on_connect = on_connect
   client.on_connect = on_connect
 
 

+ 1 - 1
static/basic/base.html

@@ -113,7 +113,7 @@
       {% block bottom %}
       {% block bottom %}
 
 
         <a href='http://altemica.net'>Powered by Altemica Srl -</a>
         <a href='http://altemica.net'>Powered by Altemica Srl -</a>
-        Icons made by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon"> www.flaticon.com</a>
+	Icons by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon"> www.flaticon.com</a> - Django {{ versione }}
       {% endblock %}
       {% endblock %}
 </div>
 </div>