Compare commits
2 Commits
5f8dff42c3
...
aff3f76fc1
Author | SHA1 | Date | |
---|---|---|---|
aff3f76fc1 | |||
1ce8c0d712 |
39
modules/mailer.py
Normal file
39
modules/mailer.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
from smtplib import SMTP, SMTP_SSL
|
||||||
|
from traceback import print_exc
|
||||||
|
from ssl import create_default_context
|
||||||
|
from modules.utils import configGet, logWrite
|
||||||
|
|
||||||
|
try:
|
||||||
|
if configGet("use_ssl", "mailer", "smtp") is True:
|
||||||
|
mail_sender = SMTP_SSL(
|
||||||
|
configGet("host", "mailer", "smtp"),
|
||||||
|
configGet("port", "mailer", "smtp"),
|
||||||
|
)
|
||||||
|
logWrite(f"Initialized SMTP SSL connection")
|
||||||
|
elif configGet("use_tls", "mailer", "smtp") is True:
|
||||||
|
mail_sender = SMTP(
|
||||||
|
configGet("host", "mailer", "smtp"),
|
||||||
|
configGet("port", "mailer", "smtp"),
|
||||||
|
)
|
||||||
|
mail_sender.starttls(context=create_default_context())
|
||||||
|
mail_sender.ehlo()
|
||||||
|
logWrite(f"Initialized SMTP TLS connection")
|
||||||
|
else:
|
||||||
|
mail_sender = SMTP(
|
||||||
|
configGet("host", "mailer", "smtp"),
|
||||||
|
configGet("port", "mailer", "smtp")
|
||||||
|
)
|
||||||
|
mail_sender.ehlo()
|
||||||
|
logWrite(f"Initialized SMTP connection")
|
||||||
|
except Exception as exp:
|
||||||
|
logWrite(f"Could not initialize SMTP connection to: {exp}")
|
||||||
|
print_exc()
|
||||||
|
|
||||||
|
try:
|
||||||
|
mail_sender.login(
|
||||||
|
configGet("login", "mailer", "smtp"),
|
||||||
|
configGet("password", "mailer", "smtp")
|
||||||
|
)
|
||||||
|
logWrite(f"Successfully initialized mailer")
|
||||||
|
except Exception as exp:
|
||||||
|
logWrite(f"Could not login into provided SMTP account due to: {exp}")
|
11
sync_gen.py
11
sync_gen.py
@@ -11,6 +11,8 @@ parser = ArgumentParser(
|
|||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument("-u", "--username", help="Enter username without input prompt", action="store")
|
parser.add_argument("-u", "--username", help="Enter username without input prompt", action="store")
|
||||||
|
parser.add_argument("-e", "--email", help="Enter email without input prompt", action="store")
|
||||||
|
parser.add_argument("-l", "--local", help="Do not save user's email to make it completely local and unrecoverable", action="store_trues")
|
||||||
parser.add_argument("-j", "--json", help="Return output as a json. Username must be provided as an argument", action="store_true")
|
parser.add_argument("-j", "--json", help="Return output as a json. Username must be provided as an argument", action="store_true")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@@ -18,8 +20,15 @@ args = parser.parse_args()
|
|||||||
|
|
||||||
username = input("Enter username: ") if args.username is None else args.username
|
username = input("Enter username: ") if args.username is None else args.username
|
||||||
|
|
||||||
|
if args.local is False:
|
||||||
|
email = input("Enter email: ") if args.email is None else args.email
|
||||||
|
if email.strip() == "":
|
||||||
|
email = None
|
||||||
|
else:
|
||||||
|
email = None
|
||||||
|
|
||||||
new_key = str(uuid4())
|
new_key = str(uuid4())
|
||||||
col_apikeys.insert_one({"user": username, "hash": passEncode(new_key)})
|
col_apikeys.insert_one({"user": username, "email": email, "hash": passEncode(new_key)})
|
||||||
|
|
||||||
if args.json is True and args.username is not None:
|
if args.json is True and args.username is not None:
|
||||||
print(dumps({"apikey": new_key}))
|
print(dumps({"apikey": new_key}))
|
||||||
|
Reference in New Issue
Block a user