Compare commits
2 Commits
432f2854d5
...
61b5bd6edb
Author | SHA1 | Date |
---|---|---|
Ceda EI | 61b5bd6edb | |
Ceda EI | 20d5c51016 |
|
@ -22,6 +22,17 @@ def get_boolean(prompt, default):
|
||||||
return 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 = {}
|
config = {}
|
||||||
|
|
||||||
# Master password
|
# Master password
|
||||||
|
@ -93,6 +104,42 @@ username/password)
|
||||||
print("Message sent, if you did not recieve a message, check the " +
|
print("Message sent, if you did not recieve a message, check the " +
|
||||||
"credentials")
|
"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.")
|
print("\nStoring config.")
|
||||||
with open('config.json', 'w') as f:
|
with open('config.json', 'w') as f:
|
||||||
|
|
14
server.py
14
server.py
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
"Server for the-long-night"
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
|
@ -11,6 +12,7 @@ app = Flask(__name__)
|
||||||
|
|
||||||
@app.route('/login', methods=['POST'])
|
@app.route('/login', methods=['POST'])
|
||||||
def en_login():
|
def en_login():
|
||||||
|
"/login"
|
||||||
try:
|
try:
|
||||||
password = request.values['password']
|
password = request.values['password']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -35,26 +37,34 @@ def en_login():
|
||||||
"and run `cancel-adding-key.sh` in The Long Night installation"
|
"and run `cancel-adding-key.sh` in The Long Night installation"
|
||||||
"directory.")
|
"directory.")
|
||||||
|
|
||||||
if config["matrix"]["enabled"]:
|
if "matrix" in config and config["matrix"]["enabled"]:
|
||||||
from backends import matrix
|
from backends import matrix
|
||||||
try:
|
try:
|
||||||
matrix.send(config["matrix"], message)
|
matrix.send(config["matrix"], message)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if config["telegram"]["enabled"]:
|
if "telegram" in config and config["telegram"]["enabled"]:
|
||||||
from backends import telegram
|
from backends import telegram
|
||||||
try:
|
try:
|
||||||
telegram.send(config["telegram"], message)
|
telegram.send(config["telegram"], message)
|
||||||
except:
|
except:
|
||||||
pass
|
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"]) +
|
return ("Logged In. The ssh key will be added " + str(config["days"]) +
|
||||||
" day(s) later.")
|
" day(s) later.")
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def en_root():
|
def en_root():
|
||||||
|
"/"
|
||||||
return """
|
return """
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
Loading…
Reference in New Issue