Informing user about key submitting status. Needs some rework.

This commit is contained in:
fkrone 2015-01-18 17:04:12 +01:00
parent 8eebbbb3fd
commit fd1b7517db

View file

@ -22,6 +22,8 @@
from ConfigParser import RawConfigParser
import GnuPG
import MySQLdb
import smtplib
from email.MIMEText import MIMEText
def appendLog(msg):
if cfg.has_key('logging') and cfg['logging'].has_key('file'):
@ -29,6 +31,16 @@ def appendLog(msg):
log.write(msg + "\n")
log.close()
def send_msg( mailsubject, mailbody, recipients = None ):
msg = MIMEText(mailbody)
msg["From"] = cfg['smime']['register_email']
msg["To"] = recipients
msg["Subject"] = mailsubject
relay = ("127.0.0.1", 10028)
smtp = smtplib.SMTP(relay[0], relay[1])
smtp.sendmail( cfg['smime']['register_email'], recipients, msg.as_string() )
# Read configuration from /etc/gpg-mailgate.conf
_cfg = RawConfigParser()
_cfg.read('/etc/gpg-mailgate.conf')
@ -57,12 +69,15 @@ if cfg.has_key('database') and cfg['database'].has_key('enabled') and cfg['datab
GnuPG.add_key(cfg['gpg']['keyhome'], row[0]) # import the key to gpg
cursor.execute("UPDATE gpgmw_keys SET status = 1 WHERE id = %s", (row[1],)) # mark key as accepted
appendLog('Imported key from <' + row[2] + '>')
send_msg( "PGP key registration successful", "Your PGP key has been imported successfully. Don't be worried if this mail is not encrypted. The following mails will be encrypted.", row[2] )
else:
cursor.execute("DELETE FROM gpgmw_keys WHERE id = %s", (row[1],)) # delete key
appendLog('Import confirmation failed for <' + row[2] + '>')
send_msg( "PGP key registration failed", "Your PGP key could not be validated. Please try again with a valid key.", row[2] )
else:
# delete key so we don't continue processing it
cursor.execute("DELETE FROM gpgmw_keys WHERE id = %s", (row[1],))
send_msg( "PGP key deleted", "Your PGP key has been deleted from our gateway. From now on you will receive mails from us unencrypted.", row[2])
connection.commit()