Changeset - 7d58100a9a7f
[Not reviewed]
default
0 3 0
Dennis Fink - 10 years ago 2015-02-16 18:08:58
dennis.fink@c3l.lu
added gnupg support
3 files changed with 29 insertions and 5 deletions:
0 comments (0 inline, 0 general)
ennstatus/__init__.py
Show inline comments
 
@@ -3,12 +3,14 @@ import os.path
 
from flask import Flask, render_template
 
from flask.ext.bootstrap import Bootstrap
 
from flask.ext.compress import Compress
 

	
 
from werkzeug.contrib.fixers import ProxyFix
 

	
 
import gnupg
 

	
 
bootstrap = Bootstrap()
 
compress = Compress()
 

	
 

	
 
def create_app():
 

	
 
@@ -40,11 +42,17 @@ def create_app():
 
    from .stats.views import stats_page
 
    app.register_blueprint(stats_page, url_prefix='/stats')
 

	
 
    from .log import init_logging
 
    init_logging(app)
 

	
 
    if 'ENNSTATUS_GPG_HOME' in app.config:
 
        gpg = gnupg.GPG(gnupghome=app.config['ENNSTATUS_GPG_HOME'])
 
        app.extensions['gnupg'] = gpg
 
    else:
 
        app.extensions['gnupg'] = False
 

	
 
    @app.errorhandler(404)
 
    def page_not_found(e):
 
        return render_template('errorpages/404.html')
 

	
 
    return app
ennstatus/root/functions.py
Show inline comments
 
@@ -5,32 +5,40 @@ from flask_mail import Mail, Message
 
from ennstatus.status.functions import mail
 

	
 

	
 
def send_membership_mail(form):
 
    try:
 
        msg = Message('New membership application', sender='ennstatus@enn.lu')
 
        msg.add_recipient(current_app.config['ENNSTATUS_MEMBERSHIP_MAIL'])
 

	
 
        msg.body = render_template('root/membership_mail.txt',
 
        recipient = current_app.config['ENNSTATUS_MEMBERSHIP_MAIL']
 
        msg.add_recipient(recipient)
 

	
 
        body = render_template('root/membership_mail.txt',
 
                                   username=form.username.data,
 
                                   email=form.email.data,
 
                                   membership=form.membership.data,
 
                                   c3l=form.c3l.data,
 
                                   firstname=form.firstname.data,
 
                                   surname=form.surname.data,
 
                                   street=form.street.data,
 
                                   zip=form.zip.data,
 
                                   city=form.city.data,
 
                                   country=form.country.data,
 
                                   gpg=form.gpg.data
 
                                   )
 

	
 
        if current_app.extensions['gnupg']:
 
            body = current_app.extensions['gnupg'].encrypt(body, recipient,
 
                                                           always_trust=True)
 
        msg.body = body
 

	
 
        mail.send(msg)
 
        flash('Application successfully sended!', 'success')
 
    except KeyError:
 
        flash('Internal server error! Please get in touch with us at info@enn.lu!', 'error')
 
        current_app.logger.error('Membership admin not found!')
 
    except AssertionError:
 
        pass
 
    except Exception as e:
 
        flash('Internal server error! Please get in touch with us at info@enn.lu!', 'error')
 
        current_app.logger.error('Unexpecter error: %s' % e,
 
        current_app.logger.error('Unexpected error: %s' % e,
 
                                 exc_info=True)
ennstatus/status/functions.py
Show inline comments
 
@@ -17,15 +17,23 @@ def _send_mail(server_name, last_updated
 
    current_app.logger.info('Try sending mail')
 
    try:
 
        if subject is None:
 
            subject = '[Ennstatus] %s went offline'
 
        msg = Message(subject % server_name,
 
                      sender='ennstatus@enn.lu')
 
        msg.add_recipient(current_app.config['SERVER_ADMINS'][server_name])
 
        msg.body = ('%s went offline. I received the last update at %s'
 
        recipient = current_app.config['SERVER_ADMINS'][server_name]
 
        msg.add_recipient(recipient)
 

	
 
        body = ('%s went offline. I received the last update at %s'
 
                    % (server_name, last_updated))
 

	
 
        if current_app.extensions['gnupg']:
 
            body = current_app.extensions['gnupg'].encrypt(body, recipient,
 
                                                           always_trust=True)
 
        msg.body = body
 

	
 
        mail.send(msg)
 
    except KeyError:
 
        current_app.logger.error('Admin for %s not found!' % server_name)
 
    except AssertionError:
 
        pass
 
    except Exception as e:
0 comments (0 inline, 0 general)