From c5be1882f857b7fe2b14854540327b2cf2fd44e6 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Fri, 17 May 2019 12:58:07 +0530 Subject: [PATCH] Add installation.py for generating config. --- installation.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 installation.py diff --git a/installation.py b/installation.py new file mode 100755 index 0000000..2878d23 --- /dev/null +++ b/installation.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 + +import bcrypt +import json + + +def get_number(prompt): + while True: + try: + num = int(input(prompt)) + return num + except ValueError: + print("Not a number!\n") + + +def get_boolean(prompt, default): + string = input(prompt).lower() + if string in ["y", "yes", "true", "t", "1"]: + return True + elif string in ["n", "no", "false", "f", "0"]: + return False + return default + + +config = {} + +# Master password +print(""" +Enter master password. Master password is the password you provide to your bus +factor. When the master password is entered, The Long Night will send messages +to you via all the configured mediums. If you do not respond within 2 days +(configurable), The Long Night will add the supplied key as an authorized key +for the user it is running as. +""") +password = input("> ").encode() +config["password"] = bcrypt.hashpw(password, bcrypt.gensalt()).decode() + +print("\nEnter number of days to wait before adding the ssh key\n") +config["days"] = get_number("> ") + + +# SSH key +print("\nEnter ssh key to add\n") +config["ssh_key"] = input("> ") + +print("\nConfiguring mediums for contact when the master password is entered.") + +# Telegram +print("\nDo you want to enable Telegram messages?\n") +config["telegram"] = {} +tg_enable = get_boolean("Y/n ", True) +config["telegram"]["enabled"] = tg_enable + +if tg_enable: + print("\nEnter bot token\n") + config["telegram"]["bot_token"] = input("> ") + print("\nEnter userid\n") + config["telegram"]["user_id"] = get_number("> ") + +print("\nStoring config.") +with open('config.json', 'w') as f: + json.dump(config, f) +print("Stored config.")