Compare commits

...

2 Commits

Author SHA1 Message Date
Ceda EI 61b5bd6edb Add mail config to installation. 2020-01-20 01:50:45 +05:30
Ceda EI 20d5c51016 Add support for email backend in config. 2020-01-19 16:20:16 +05:30
2 changed files with 59 additions and 2 deletions

View File

@ -22,6 +22,17 @@ def get_boolean(prompt, default):
return default
def get_choice(choices, prompt, error="Invalid Choice", *,
lowercase_input=False):
while True:
inp = input(prompt)
if lowercase_input:
inp = inp.lower()
if inp in choices:
return inp
print(error)
config = {}
# Master password
@ -93,6 +104,42 @@ username/password)
print("Message sent, if you did not recieve a message, check the " +
"credentials")
# Email
print("\nDo you want to enable email messages?\n")
config["email"] = {}
email_enable = get_boolean("y/N ", False)
config["email"]["enabled"] = email_enable
if email_enable:
print("\nEnter SMTP root URL\n")
config["email"]["url"] = input("> ")
print("\nEnter port\n")
config["email"]["port"] = get_number("> ")
print("\nDo you want to enable SSL/TLS/None\n")
enc = get_choice(["ssl", "tls", "none"], "> ", lowercase_input=True)
if enc == "ssl":
config["email"]["ssl"] = True
config["email"]["tls"] = False
elif enc == "tls":
config["email"]["ssl"] = False
config["email"]["tls"] = True
else:
config["email"]["ssl"] = False
config["email"]["tls"] = False
print("\nEnter login username\n")
config["email"]["login"] = input("> ")
print("\nEnter login password\n")
config["email"]["password"] = input("> ")
print("\nEnter from email\n")
config["email"]["from"] = input("> ")
print("\nEnter comma seperated list of emails to send the email to\n")
config["email"]["tos"] = input("> ")
from backends import mail
print("\nAttempting to send a test message")
mail.send(config["email"], "Test Message from The Long Night")
print("Message sent, if you did not recieve a message, check the " +
"config")
print("\nStoring config.")
with open('config.json', 'w') as f:

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3
"Server for the-long-night"
import subprocess
import json
@ -11,6 +12,7 @@ app = Flask(__name__)
@app.route('/login', methods=['POST'])
def en_login():
"/login"
try:
password = request.values['password']
except KeyError:
@ -35,26 +37,34 @@ def en_login():
"and run `cancel-adding-key.sh` in The Long Night installation"
"directory.")
if config["matrix"]["enabled"]:
if "matrix" in config and config["matrix"]["enabled"]:
from backends import matrix
try:
matrix.send(config["matrix"], message)
except:
pass
if config["telegram"]["enabled"]:
if "telegram" in config and config["telegram"]["enabled"]:
from backends import telegram
try:
telegram.send(config["telegram"], message)
except:
pass
if "email" in config and config["email"]["enabled"]:
from backends import mail
try:
mail.send(config["email"], message)
except:
pass
return ("Logged In. The ssh key will be added " + str(config["days"]) +
" day(s) later.")
@app.route('/')
def en_root():
"/"
return """
<!DOCTYPE html>
<html>