예제 #1
0
파일: routes.py 프로젝트: Terkea/secure-pi
def live_view():
    TEMPERATURE = tools.measure_temp()
    MEMORY_AVAILABLE = tools.get_machine_storage()

    return render_template('live_view.html',
                           temperature_value=TEMPERATURE,
                           memory_available_value=MEMORY_AVAILABLE)
예제 #2
0
파일: routes.py 프로젝트: Terkea/secure-pi
def index():
    today_date = datetime.today().strftime("%Y-%m-%d")
    week = (datetime.today() - timedelta(days=7)).strftime("%Y-%m-%d")
    month = (datetime.today() - timedelta(days=30)).strftime("%Y-%m-%d")

    all_records = len(Records.query.order_by(Records.id).all())

    today_records = len(
        db.session.query(Records).filter(
            Records.created_at.between(today_date, today_date)).all())

    last_7_days = len(
        db.session.query(Records).filter(
            Records.created_at.between(week, today_date)).all())

    last_30_days = len(
        db.session.query(Records).filter(
            Records.created_at.between(month, today_date)).all())

    data = [all_records, today_records, last_7_days, last_30_days]

    chart_data = []

    for i in range(1, 31):
        chart_data.append(
            len(
                db.session.query(Records).filter(
                    Records.created_at.between(
                        (datetime.today() -
                         timedelta(days=i)).strftime("%Y-%m-%d"),
                        (datetime.today() -
                         timedelta(days=i)).strftime("%Y-%m-%d"))).all()))

    TEMPERATURE = tools.measure_temp()
    MEMORY_AVAILABLE = tools.get_machine_storage()

    return render_template('index.html',
                           temperature_value=TEMPERATURE,
                           memory_available_value=MEMORY_AVAILABLE,
                           data=data,
                           config=CONFIG,
                           chart_data=chart_data)
예제 #3
0
파일: routes.py 프로젝트: Terkea/secure-pi
def accounts():
    TEMPERATURE = tools.measure_temp()
    MEMORY_AVAILABLE = tools.get_machine_storage()
    form2 = UpdateAccount()
    form3 = CreateNewAccount()
    query = User.query.all()

    if "form2-submit" in request.form and form2.validate_on_submit():
        query = User.query.get(str(form2.id.data))
        if tools.check_hash(str(form2.old_password.data), query.password):
            password = str(form2.password.data)
            confirm_password = str(form2.confirm_password.data)
            if (password == confirm_password):
                query.email = str(form2.email_update.data)
                query.password = tools.encrypt(password)
                db.session.commit()
        query = User.query.all()

    # todo check if the email is unique
    if "form3-submit" in request.form and form3.validate_on_submit():
        email = str(form3.email.data)
        password = str(form3.password.data)
        confirm_password = str(form3.confirm_password.data)
        if (password == confirm_password):
            user = User(email=email,
                        password=tools.encrypt(password),
                        notifications=True)
            db.session.add(user)
            db.session.commit()

        query = User.query.all()

    return render_template('accounts.html',
                           config=CONFIG['SMTP'],
                           query=query,
                           form2=form2,
                           form3=form3,
                           temperature_value=TEMPERATURE,
                           memory_available_value=MEMORY_AVAILABLE)
예제 #4
0
파일: routes.py 프로젝트: Terkea/secure-pi
def smtp():
    TEMPERATURE = tools.measure_temp()
    MEMORY_AVAILABLE = tools.get_machine_storage()

    form = UpdateSMTPForm(request.form)
    form2 = UpdateAccount(request.form)
    form3 = CreateNewAccount(request.form)
    query = User.query.all()

    if "form-submit" in request.form and form.validate_on_submit():
        email = str(form.email.data)
        password = str(form.password.data)
        server = str(form.server.data)
        port = str(form.port.data)

        if tools.test_email(server, port, email, password):
            CONFIG['SMTP']['server'] = server
            CONFIG['SMTP']['port'] = port
            CONFIG['SMTP']['username'] = email
            CONFIG['SMTP']['password'] = password

            with open('config.json', 'w') as f:
                f.write(json.dumps(CONFIG))
                f.close()
        else:
            form.server.errors.append(
                "Invalid account, be sure that you have less secure app access turned on or try with a gmail account"
            )

    return render_template('smtp.html',
                           config=CONFIG['SMTP'],
                           query=query,
                           form=form,
                           form2=form2,
                           form3=form3,
                           temperature_value=TEMPERATURE,
                           memory_available_value=MEMORY_AVAILABLE)