2020-03-08 23:09:32 +01:00
|
|
|
"""Initial loading script"""
|
2020-07-04 23:18:30 +02:00
|
|
|
from app.config import ALIAS_DOMAINS
|
|
|
|
from app.models import Mailbox, Contact, PublicDomain
|
2020-03-08 23:09:32 +01:00
|
|
|
from app.log import LOG
|
|
|
|
from app.extensions import db
|
|
|
|
from app.pgp_utils import load_public_key
|
|
|
|
from server import create_app
|
|
|
|
|
|
|
|
|
2020-06-07 12:46:59 +02:00
|
|
|
def load_pgp_public_keys():
|
2020-03-08 23:09:32 +01:00
|
|
|
"""Load PGP public key to keyring"""
|
2020-06-07 12:46:59 +02:00
|
|
|
for mailbox in Mailbox.query.filter(Mailbox.pgp_public_key != None).all():
|
|
|
|
LOG.d("Load PGP key for mailbox %s", mailbox)
|
|
|
|
fingerprint = load_public_key(mailbox.pgp_public_key)
|
2020-03-08 23:09:32 +01:00
|
|
|
|
2020-06-07 12:46:59 +02:00
|
|
|
# sanity check
|
|
|
|
if fingerprint != mailbox.pgp_finger_print:
|
2020-07-17 12:59:07 +02:00
|
|
|
LOG.exception(
|
|
|
|
"fingerprint %s different for mailbox %s", fingerprint, mailbox
|
|
|
|
)
|
2020-06-07 12:46:59 +02:00
|
|
|
mailbox.pgp_finger_print = fingerprint
|
2020-06-07 00:09:06 +02:00
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
for contact in Contact.query.filter(Contact.pgp_public_key != None).all():
|
|
|
|
LOG.d("Load PGP key for %s", contact)
|
|
|
|
fingerprint = load_public_key(contact.pgp_public_key)
|
|
|
|
|
|
|
|
# sanity check
|
|
|
|
if fingerprint != contact.pgp_finger_print:
|
2020-07-17 12:59:07 +02:00
|
|
|
LOG.exception(
|
|
|
|
"fingerprint %s different for contact %s", fingerprint, contact
|
|
|
|
)
|
2020-06-07 00:09:06 +02:00
|
|
|
contact.pgp_finger_print = fingerprint
|
2020-03-08 23:09:32 +01:00
|
|
|
|
2020-06-07 12:46:59 +02:00
|
|
|
db.session.commit()
|
2020-03-08 23:09:32 +01:00
|
|
|
|
2020-03-14 22:24:02 +01:00
|
|
|
LOG.d("Finish load_pgp_public_keys")
|
|
|
|
|
2020-03-08 23:09:32 +01:00
|
|
|
|
2020-07-04 23:18:30 +02:00
|
|
|
def add_public_domains():
|
|
|
|
for alias_domain in ALIAS_DOMAINS:
|
|
|
|
if PublicDomain.get_by(domain=alias_domain):
|
|
|
|
LOG.d("%s is already a public domain", alias_domain)
|
|
|
|
else:
|
|
|
|
LOG.info("Add %s to public domain", alias_domain)
|
|
|
|
PublicDomain.create(domain=alias_domain)
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
2020-03-08 23:09:32 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
app = create_app()
|
|
|
|
|
|
|
|
with app.app_context():
|
2020-06-07 12:46:59 +02:00
|
|
|
load_pgp_public_keys()
|
2020-07-04 23:18:30 +02:00
|
|
|
add_public_domains()
|