Beispiel #1
0
def delete_miner(id):
    miner = Miner.query.filter_by(id=int(id)).first()
    if miner:
        db_session.delete(miner)
        db_session.commit()
        flash("Miner {} removed successfully".format(miner.ip), "info")
    return redirect(url_for('antminer.miners'))
Beispiel #2
0
def create_db():
    """
        Create database. Add miner models and settings.
    """
    from sqlalchemy.exc import IntegrityError

    init_db()

    settings = []
    settings.append(
        Settings(name="temperature_alert", value="80", description=""))
    settings.append(
        Settings(
            name="email_alert",
            value="True",
            description="Whether to send an email on alert"))

    try:
         for setting in settings:
            db_session.add(setting)
            db_session.commit()
    except IntegrityError:
        print("[INFO] Database already exists.")
    else:
        print("[INFO] Database successfully created.")
Beispiel #3
0
def add_miner(miner_ip, miner_model_id, miner_remarks):
    try:
        miner = Miner(
            ip=miner_ip, model_id=miner_model_id, remarks=miner_remarks)
        db_session.add(miner)
        db_session.commit()
        current_app.logger.info("Miner with IP Address {} added successfully".format(miner.ip))
        flash("Miner with IP Address {} added successfully".format(miner.ip),
              "success")
    except IntegrityError:
        db_session.rollback()
        current_app.logger.info("IP Address {} already added".format(miner.ip))
        flash("IP Address {} already added".format(miner.ip), "error")
Beispiel #4
0
def password_update():
    form = PasswordResetForm()
    form.username.choices = [(u.username, u.username)
                             for u in User.query.all()]
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            password = form.password.data
            user.set_password(password)
            db_session.commit()
            flash(
                "[INFO] Password updated for user '{}'".format(user.username),
                "info")
            next = request.args.get('next')
            if not is_safe_url(next):
                abort(400)
            return redirect(next or url_for('user.password_update'))
        flash("[ERROR] User '{}' does not exist".format(form.username.data),
              "error")
        return render_template('user/password_update.html', form=form)

    return render_template('user/password_update.html', form=form)
Beispiel #5
0
def create_admin():
    """
        Create admin user if not exist with default password 'antminermonitor'
    """
    init_db()
    print("[INFO] Checking if admin user exists...")
    admin = User.query.filter_by(username='******').first()

    if not admin:
        print("[INFO] Creating admin user with password 'antminermonitor'...")
        admin = User(
            username='******',
            email='*****@*****.**',
            surname='admin',
            firstname='admin',
            active=0)
        admin.set_password('antminermonitor')
        db_session.add(admin)
        db_session.commit()
    elif admin:
        print("[INFO] Admin user already exists.")
    else:
        print("[INFO] Something went wrong.")