def _get_influxdb_parameters(): config_key = "influx_tests" return { "host": load_config().get(config_key).get("address"), "port": load_config().get(config_key).get("port"), "user": load_config().get(config_key).get("user"), "password": load_config().get(config_key).get("password"), "database": load_config().get(config_key).get("db"), }
def get_email_configuration(): email_config = load_config().get("mail", {}) return { "smtp_server_url": email_config.get("smtp_address", "smtp.gmail.com"), "smtp_server_port": email_config.get("smtp_port", 587), "email": email_config.get("account", "*****@*****.**"), "password": email_config.get("password", "SeduceCloud+44"), }
def signup(): from database import User from database import db from core.config.config_loader import load_config config = load_config() recaptcha_site_key = config.get("captcha").get("site_key") recaptcha_secret_key = config.get("captcha").get("secret_key") if flask.request.method == 'GET': next_url = flask.request.args.get("next") return render_template("signup.html.jinja2", next_url=next_url, recaptcha_site_key=recaptcha_site_key) email = flask.request.form['email'] firstname = flask.request.form['firstname'] lastname = flask.request.form['lastname'] password = flask.request.form['password'] confirm_password = flask.request.form['confirm_password'] recaptcha_token = flask.request.form['g-recaptcha-response'] remote_ip = None error = False error_msg = "" if ".ru" in email: remote_ip = flask.request.remote_addr error = True error_msg = "russian email detected" if recaptcha_token == "" or recaptcha_token is None: error = True error_msg = "no recaptcha token provided" if not verify_captcha(recaptcha_site_key, recaptcha_secret_key, recaptcha_token, remote_ip): error = True error_msg = "invalid recaptcha token" if not error and password == confirm_password: user = User() user.email = email user.firstname = firstname user.lastname = lastname # The password is ciphered and salted in the database.py file user.password = password db.session.add(user) db.session.commit() redirect_url = flask.url_for("login.confirmation_account_creation") return flask.redirect(redirect_url) else: print("SPAM: %s (%s)" % (remote_ip, error_msg)) return 'Bad login'
def send_authorization_request(user): email_configuration = get_email_configuration() frontend_public_address = load_config().get("frontend", {}).get("public_address", "api.seduce.fr") token = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(TOKEN_LENGTH)) fromaddr = email_configuration.get("email") toaddr = fromaddr msg = MIMEMultipart() msg['From'] = email_configuration.get("email") msg['To'] = toaddr msg['Subject'] = "A user requested a new account" body = """Hello, A user has made a request for an account creation. As he has successfully confirmed his email, you now have to review his request in order to decide the request is accepted. Here are the details of the request: email: %s firstname: %s lastname: %s In the case you approve his account, he we will get access to the Seduce system. Do you approve the request? Yes, I approve the request: https://%s/approve_user/token/%s No, I disapprove the request: https://%s/disapprove_user/token/%s Thanks for taking the time to review this request. Best Regards, Seduce system """ % (user.email, user.firstname, user.lastname, frontend_public_address, token, frontend_public_address, token) msg.attach(MIMEText(body, 'plain')) smtp_server = smtplib.SMTP(email_configuration.get("smtp_server_url"), email_configuration.get("smtp_server_port")) smtp_server.ehlo() smtp_server.starttls() smtp_server.ehlo() smtp_server.login(fromaddr, email_configuration.get("password")) text = msg.as_string() smtp_server.sendmail(fromaddr, toaddr, text) smtp_server.quit() return { "success": True, "token": token }
def send_reset_password_link(user): email_configuration = get_email_configuration() frontend_public_address = load_config().get("frontend", {}).get("public_address", "api.seduce.fr") token = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(TOKEN_LENGTH)) fromaddr = email_configuration.get("email") toaddr = user.email msg = MIMEMultipart() msg['From'] = email_configuration.get("email") msg['To'] = toaddr msg['Subject'] = "Password reset - SeDuCe testbed" body = """Hello %s, Hello, We got a request to reset your password on the SeDuCe testbed. If you ignore this message, your password won't be changed. If you didn't request a password reset, let us know. Here is the link to reset your password: https://%s/reset_password/token/%s Best Regards, Seduce system """ % (user.firstname, frontend_public_address, token) msg.attach(MIMEText(body, 'plain')) smtp_server = smtplib.SMTP(email_configuration.get("smtp_server_url"), email_configuration.get("smtp_server_port")) smtp_server.ehlo() smtp_server.starttls() smtp_server.ehlo() smtp_server.login(fromaddr, email_configuration.get("password")) text = msg.as_string() smtp_server.sendmail(fromaddr, toaddr, text) smtp_server.quit() return { "success": True, "token": token }
def send_confirmation_request(user): email_configuration = get_email_configuration() frontend_public_address = load_config().get("frontend", {}).get("public_address", "api.seduce.fr") token = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(TOKEN_LENGTH)) fromaddr = email_configuration.get("email") toaddr = user.email msg = MIMEMultipart() msg['From'] = email_configuration.get("email") msg['To'] = toaddr msg['Subject'] = "Please confirm your email" body = """Hello %s, Thanks for creating an account on the Seduce system. In order to proceed with your account creation, please confirm your email by browsing on the following link: https://%s/confirm_email/token/%s Best Regards, Seduce administrators """ % (user.firstname, frontend_public_address, token) msg.attach(MIMEText(body, 'plain')) smtp_server = smtplib.SMTP(email_configuration.get("smtp_server_url"), email_configuration.get("smtp_server_port")) smtp_server.ehlo() smtp_server.starttls() smtp_server.ehlo() smtp_server.login(fromaddr, email_configuration.get("password")) text = msg.as_string() smtp_server.sendmail(fromaddr, toaddr, text) smtp_server.quit() return { "success": True, "token": token }
def ensure_admin_user_exists(db): from database import User as DbUser from core.config.config_loader import load_config admin = DbUser.query.filter_by( email=load_config().get("admin").get("user")).first() if admin is None: admin = DbUser() admin.email = load_config().get("admin").get("user") admin.firstname = load_config().get("admin").get("firstname") admin.lastname = load_config().get("admin").get("lastname") admin.password = load_config().get("admin").get("password") admin.state = "authorized" admin.email_confirmed = True admin.user_authorized = True admin.is_admin = True admin.url_picture = load_config().get("admin").get("url_picture") db.session.add(admin) db.session.commit()
def send_authorization_confirmation(user): email_configuration = get_email_configuration() frontend_public_address = load_config().get("frontend", {}).get("public_address", "api.seduce.fr") fromaddr = email_configuration.get("email") toaddr = user.email msg = MIMEMultipart() msg['From'] = email_configuration.get("email") msg['To'] = toaddr msg['Subject'] = "You account has been approved" body = """Hello %s, You account has been approved by an admin, in consequence you can now log in: https://%s/login Best Regards, Seduce system """ % (user.firstname, frontend_public_address) msg.attach(MIMEText(body, 'plain')) smtp_server = smtplib.SMTP(email_configuration.get("smtp_server_url"), email_configuration.get("smtp_server_port")) smtp_server.ehlo() smtp_server.starttls() smtp_server.ehlo() smtp_server.login(fromaddr, email_configuration.get("password")) text = msg.as_string() smtp_server.sendmail(fromaddr, toaddr, text) smtp_server.quit() return { "success": True, }
from flask import Flask from flask import request from flask_apscheduler import APScheduler import logging import flask import json import time import threading from agent_actions import AgentActions from core.config.config_loader import load_config from agent.agent_actions import instantiate_agent_actions logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s') logger = logging.getLogger(__name__) game_name = load_config().get("server_agent", {}).get("game") server_actions = instantiate_agent_actions(game_name) # type: AgentActions DEBUG = True SERVER_INFO = None STATUS_TARGET = None class Config(object): JOBS = [ { 'id': 'job1', 'func': 'agent.base:update_server_info', 'args': (), 'trigger': 'interval', 'seconds': 300
def get_bot_configuration(): bot_config = load_config().get("bot", {}) return { "bot_token": bot_config.get("token"), }
def inject_dict_for_all_templates(): from core.config.config_loader import load_config api_public_address = load_config().get("api", {}).get("public_address", "api.seduce.fr") return dict(api_public_address=api_public_address)
from influxdb import InfluxDBClient from dateutil import parser from datetime import timedelta from core.config.config_loader import load_config import functools import datetime DB_HOST = load_config().get("influx").get("address") DB_PORT = load_config().get("influx").get("port") DB_USER = load_config().get("influx").get("user") DB_PASSWORD = load_config().get("influx").get("password") DB_NAME = load_config().get("influx").get("db") def get_influxdb_parameters(): config_key = "influx" return { "host": load_config().get(config_key).get("address"), "port": load_config().get(config_key).get("port"), "user": load_config().get(config_key).get("user"), "password": load_config().get(config_key).get("password"), "database": load_config().get(config_key).get("db"), } def create_influxdb_connection(): params = get_influxdb_parameters() db_client = InfluxDBClient(params.get("host"), params.get("port"), params.get("user"), params.get("password"),
from core.config.config_loader import load_config SERVER_AGENT_URL = load_config().get("server_agent").get("url")
def get_server_public_url(): public_url = load_config().get("server", {}).get("public_url", "") return public_url
from redis import StrictRedis import json from core.config.config_loader import load_config REDIS_HOST = load_config().get("redis").get("address") REDIS_PORT = load_config().get("redis").get("port") def redis_clear_error_count(): redis_client = StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=0) sensor_key = "sensors_data" redis_client.set(sensor_key, "{}") return True def redis_set_sensor_error_count(sensor_name, error_count): redis_client = StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=0) sensor_key = "sensors_data" sensors_data_resp = redis_client.get(sensor_key) if sensors_data_resp is None: return {} sensors_data_str = sensors_data_resp.decode("utf8") if sensors_data_str is not None: sensors_data = json.loads(sensors_data_str) else: