From b170b07ef5615f774b0c525b4258aa509548922b Mon Sep 17 00:00:00 2001 From: deflax Date: Fri, 15 Dec 2017 02:36:32 +0200 Subject: [PATCH] create-activate phase 3 --- app/email.py | 6 +- app/templates/main/dashboard.html | 106 +------------------------ app/templates/main/dashboard_pool.html | 101 +++++++++++++++++++++++ manage.py | 30 ++++--- 4 files changed, 129 insertions(+), 114 deletions(-) create mode 100644 app/templates/main/dashboard_pool.html diff --git a/app/email.py b/app/email.py index 14b8774..f0d7c49 100644 --- a/app/email.py +++ b/app/email.py @@ -10,8 +10,12 @@ def send_async_email(app, msg): mail.send(msg) def send_email(to, subject, template, **kwargs): + if len(subject) > 50: + newsubject = subject[:50] + '...' + else: + newsubject = subject app = current_app._get_current_object() - msg = Message(app.config['MAIL_SUBJECT_PREFIX'] + ' ' + subject, sender=app.config['MAIL_SENDER'], recipients=[to]) + msg = Message(app.config['MAIL_SUBJECT_PREFIX'] + ' ' + newsubject, sender=app.config['MAIL_SENDER'], recipients=[to]) msg.body = render_template(template + '.txt', **kwargs) msg.html = render_template(template + '.html', **kwargs) thr = Thread(target=send_async_email, args=[app, msg]) diff --git a/app/templates/main/dashboard.html b/app/templates/main/dashboard.html index 8a4790a..5f92ac2 100644 --- a/app/templates/main/dashboard.html +++ b/app/templates/main/dashboard.html @@ -143,119 +143,17 @@ addEventListener("DOMContentLoaded", function() {
Device Manager

- {% if inv_deployments != [] %} -

- {% for deploy in inv_deployments %} - {% if deploy.enabled == False %} -
- {% else %} - {% if deploy.warning == True %} -
- {% else %} -
- {% endif %} - {% endif %} -
- - {% if deploy.enabled == False or deploy.warning == True %} -
- {% else %} -
- {% endif %} -
- - -
-
-


- {% if deploy.enabled == True %} - - {% if status[deploy.machine_id] == 'running' %} - - -

-

- - - {% else %} - - {% endif %} - {% endif %} -

-

- - {% if deploy.enabled == False %} - - {% else %} - {% if deploy.warning == True %} - - {% else %} - {{ deploy.daysleft }} day(s) - {% endif %} - {% endif %} -

- -
- -
-

-

-
- - Processor {{ deploy.machine_cpu }} {% if deploy.machine_cpu > 1 %}cores{% else %}core{% endif %} -
-
- - Allocated memory {{ deploy.machine_mem }} MB
-
-
-
-
- - Network traffic -
-
- - IOPS of {{ deploy.machine_hdd }} GB storage
-
-

-
- -
-
-

- Unit: {{ deploy.machine_id }}
- State: {{ status[deploy.machine_id] }}
- Protected: {{ deploy.protected }}
-

-
- -
-
-
- - {% endfor %} -
- + {% include "main/dashboard_pool.html" %} - {% else %} - {% endif %}
+ {% if inv_domains != [] %}
diff --git a/app/templates/main/dashboard_pool.html b/app/templates/main/dashboard_pool.html new file mode 100644 index 0000000..97d0d48 --- /dev/null +++ b/app/templates/main/dashboard_pool.html @@ -0,0 +1,101 @@ +
+ {% for deploy in inv_deployments %} + {% if deploy.enabled == False %} +
+ {% else %} + {% if deploy.warning == True %} +
+ {% else %} +
+ {% endif %} + {% endif %} +
+ + {% if deploy.enabled == False or deploy.warning == True %} +
+ {% else %} +
+ {% endif %} +
+ + +
+
+


+ {% if deploy.enabled == True %} + + {% if status[deploy.machine_id] == 'running' %} + + +

+

+ + + {% else %} + + {% endif %} + {% endif %} +

+

+ + {% if deploy.enabled == False %} + + {% else %} + {% if deploy.warning == True %} + + {% else %} + {{ deploy.daysleft }} day(s) + {% endif %} + {% endif %} +

+ +
+ +
+

+

+
+ + Processor {{ deploy.machine_cpu }} {% if deploy.machine_cpu > 1 %}cores{% else %}core{% endif %} +
+
+ + Allocated memory {{ deploy.machine_mem }} MB
+
+
+
+
+ + Network traffic +
+
+ + IOPS of {{ deploy.machine_hdd }} GB storage
+
+

+
+ +
+
+

+ Unit: {{ deploy.machine_id }}
+ State: {{ status[deploy.machine_id] }}
+ Protected: {{ deploy.protected }}
+

+
+ +
+
+
+ + {% endfor %} +
+ diff --git a/manage.py b/manage.py index fed64d5..5f0be64 100644 --- a/manage.py +++ b/manage.py @@ -47,9 +47,9 @@ def autoremove(): daysleft = draft.daysleft daysleft -= 1 draft.daysleft = daysleft - print('Draft {} will be autoremoved after {} days.'.format(draft.machine_alias, daysleft)) - email_content = draft.owner + ' draft days left: ' + daysleft - send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=user, content=str(email_content)) + email_content = 'Draft {} has {} days left.'.format(draft.machine_alias, daysleft) + print(str(email_content)) + send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=draft.owner, content=str(email_content)) db.session.commit() @manager.command @@ -67,7 +67,9 @@ def autodisable(): lastcharge = deploy.date_last_charge expiry = lastcharge + relativedelta(lastcharge, months=+(deploy.period)) if today > expiry: - print('Deployment "' + deploy.machine_alias + '" is past expiration date and will be marked INACTIVE. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c')) + email_content = 'Deployment "' + deploy.machine_alias + '" is past expiration date and will be marked INACTIVE. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c') + print(str(email_content)) + send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=deploy.owner, content=str(email_content)) deploy.warning = False deploy.enabled = False deploy.daysleft = 0 @@ -79,7 +81,9 @@ def autodisable(): lastcharge = service.date_last_charge expiry = lastcharge + relativedelta(lastcharge, months=+(service.period)) if today > expiry: - print('Service "' + service.description + '" is past expiration date and will be marked INACTIVE. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c')) + email_content = 'Service "' + service.description + '" is past expiration date and will be marked INACTIVE. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c') + print(str(email_content)) + send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=service.owner, content=str(email_content)) service.warning = False service.enabled = False service.daysleft = 0 @@ -90,7 +94,9 @@ def autodisable(): for domain in domains_ena: expiry = domain.date_expire if today > expiry: - print('Domain "' + domain.fqdn + '" is past expiration date and will be marked as INACTIVE. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c')) + email_content = 'Domain "' + domain.fqdn + '" is past expiration date and will be marked as INACTIVE. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c') + print(str(email_content)) + send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=domain.owner, content=str(email_content)) domain.warning = False domain.enabled = False domain.daysleft = 0 @@ -113,7 +119,9 @@ def autowarn(): db.session.commit() warndays = deploy.period * 5 if daysleft.days < warndays: - print('Deployment "' + deploy.machine_alias + '" is ' + str(daysleft.days) + ' days until expiration. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c')) + email_content = 'Deployment "' + deploy.machine_alias + '" is ' + str(daysleft.days) + ' days until expiration. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c') + print(str(email_content)) + send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=deploy.owner, content=str(email_content)) deploy.warning = True db.session.commit() @@ -127,7 +135,9 @@ def autowarn(): db.session.commit() warndays = service.period * 5 if daysleft.days < warndays: - print('Service "' + service.description + '" is ' + str(daysleft.days) + ' days until expiration. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c')) + email_content = 'Service "' + service.description + '" is ' + str(daysleft.days) + ' days until expiration. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c') + print(str(email_content)) + send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=service.owner, content=str(email_content)) service.warning = True db.session.commit() @@ -139,7 +149,9 @@ def autowarn(): db.session.commit() warndays = domain.period * 5 if daysleft.days < warndays: - print('Domain "' + domain.fqdn + '" is ' + str(daysleft.days)+ ' days until expiration. Expiry date: ' + expiry.strftime('%c')) + email_content = 'Domain "' + domain.fqdn + '" is ' + str(daysleft.days)+ ' days until expiration. Expiry date: ' + expiry.strftime('%c') + print(str(email_content)) + send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=domain.owner, content=str(email_content)) domain.warning = True db.session.commit()