예제 #1
0
def init_pool_users(CONFIG, LOGGER, database):
    ##
    # WebUI
    LOGGER.warn("Validate WebUI user account")
    try:
        webui_user = os.environ["GRIN_POOL_WEBUI_USER"]
        webui_pass = os.environ["GRIN_POOL_WEBUI_PASSWORD"]
    except KeyError:
        LOGGER.warn("We dont have WebUI account info, skipping...")
        return
    # Verify / create the account
    user = Users.get_by_id(1)
    if user is None:
        user = User(
            id=1,
            username=webui_user,
            password=webui_pass,
        )
        database.db.getSession().add(user)
        database.db.getSession().commit()
    ##
    # Admin
    try:
        admin_user = os.environ["GRIN_POOL_ADMIN_USER"]
        admin_pass = os.environ["GRIN_POOL_ADMIN_PASSWORD"]
    except KeyError:
        LOGGER.warn("We dont have Admin account info, skipping...")
        return
    # Verify / create the account
    user = Users.get_by_id(2)
    if user is None:
        user = User(
            id=2,
            username=admin_user,
            password=admin_pass,
        )
        database.db.getSession().add(user)
        database.db.getSession().commit()
    ##
    # Grin Developers Fund
    try:
        devfund_user = "******"
        devfund_pass = "******"
    except KeyError:
        LOGGER.warn("We dont have Admin account info, skipping...")
        return
    # Verify / create the account
    user = Users.get_by_id(3)
    if user is None:
        user = User(
            id=3,
            username=admin_user,
            password=admin_pass,
        )
        database.db.getSession().add(user)
        database.db.getSession().commit()
예제 #2
0
파일: lib.py 프로젝트: waosman/grin-pool
def get_db():
    global DATABASE
    rlock = threading.RLock()
    with rlock:
        if DATABASE is None:
            print("INIT DB")
            mysqlcontsraints = get_db_constraints()
            database.db = database_details(MYSQL_CONSTANTS=mysqlcontsraints)
            database.db.initialize()
            try:
                GRIN_POOL_ADMIN_USER = os.environ['GRIN_POOL_ADMIN_USER']
                GRIN_POOL_ADMIN_PASSWORD = os.environ[
                    'GRIN_POOL_ADMIN_PASSWORD']
                from grinbase.model.users import Users
                try:
                    user = Users.get_by_id(1)
                    if user is None:
                        user = Users(
                            id=1,
                            username=GRIN_POOL_ADMIN_USER,
                            password=GRIN_POOL_ADMIN_PASSWORD,
                        )
                        database.db.createDataObj(user)
                except:
                    pass
            except KeyError:
                pass
            DATABASE = database
    DATABASE.db.initializeSession()
    return DATABASE
예제 #3
0
def main():
    CONFIG = lib.get_config()
    LOGGER = lib.get_logger(PROCESS)
    LOGGER.warn("=== Starting {}".format(PROCESS))

    ##
    # Update user records in MySQL and REDIS
    database = lib.get_db()
    database.db.initializeSession()

    redisdb = lib.get_redis_db()
    redis_userid_key = "userid."

    id = 1
    try:
        while True:
            thisuser = Users.get_by_id(id)
            if thisuser is None:
                if id > 2358:
                    LOGGER.warn("last id = {}".format(id))
                    break
                id = id + 1
                continue
            if thisuser.username == "bjg62hj8byyksphuw95vqc3f74.lionm1":
                orig_username = thisuser.username
                thisuser.username = "******"
                LOGGER.warn("Updated: {} to {}".format(orig_username,
                                                       thisuser.username))
            if thisuser.username == "[email protected]_d1":
                orig_username = thisuser.username
                thisuser.username = "******"
                LOGGER.warn("Updated: {} to {}".format(orig_username,
                                                       thisuser.username))
            if thisuser.username == "*****@*****.**":
                orig_username = thisuser.username
                thisuser.username = "******"
                LOGGER.warn("Updated: {} to {}".format(orig_username,
                                                       thisuser.username))
            if "." in thisuser.username:
                orig_username = thisuser.username
                # Update mysql
                thisuser.username = thisuser.username.replace(".", "_")
                # Update redis
                redis_key = redis_userid_key + orig_username
                COMMIT and redisdb.delete(redis_key)
                redis_key = redis_userid_key + thisuser.username
                COMMIT and redisdb.set(redis_key, id)
                LOGGER.warn("Updated: {} to {}".format(orig_username,
                                                       thisuser.username))
            id = id + 1
    except Exception as e:  # AssertionError as e:
        LOGGER.error("Something went wrong: {} - {}".format(
            e, traceback.print_stack()))

    COMMIT or LOGGER.warn("XXX No Commit - Edit for final run")
    COMMIT and database.db.getSession().commit()
    LOGGER.warn("=== Completed {}".format(PROCESS))
예제 #4
0
if new_state == "1":
    new_state = "canceled"
elif new_state == "2":
    new_state = "expired"
else:
    print("Invalid state choice")
    sys.exit(1)

# Get the payout record
payout_record = Pool_payment.get_by_id(payout_id)
print("{}".format(payout_record))
amount = payout_record.amount / float(NANOGRIN)

# Get the user id
user_id = payout_record.user_id
user_record = Users.get_by_id(user_id)
username = user_record.username
print("User: {}".format(username))

# Get the users UTXO record
user_utxo = Pool_utxo.get_by_userid(user_id)

# Print a report
print("Will update account for {} on {}".format(username, poolname))
print(
    "Will cancel payout {} and add {} to users current balance of {} for a new balance of {}"
    .format(payout_id, amount,
            float(user_utxo.amount) / NANOGRIN,
            float(user_utxo.amount) / NANOGRIN + amount))

# Confirm action
예제 #5
0
def main():
    CONFIG = lib.get_config()
    LOGGER = lib.get_logger(PROCESS)
    LOGGER.warn("=== Starting {}".format(PROCESS))

    # Get DB Config
    db_address = CONFIG["db"]["address"]
    db_port = CONFIG["db"]["port"]
    db_user = CONFIG["db"]["user"]
    db_password = os.environ['MYSQL_ROOT_PASSWORD']
    db_name = CONFIG["db"]["db_name"]
    LOGGER.warn("Got Config: db_address: {}, db_port: {}, db_user: {}, db_password: {}, db_name: {}".format(db_address, db_port, db_user, db_password, db_name))

    # Create the DB if it does not already exist
    mysql_engine_string = "mysql+pymysql://{user}:{password}@{host}:{port}".format(
        user = db_user,
        password = db_password,
        host = db_address,
        port = db_port)
    sys.stdout.flush()


    # Create db if needed
    tmp_engine = create_engine(mysql_engine_string)
    conn = tmp_engine.connect()
    conn.execute("commit")
    conn.execute("CREATE DATABASE IF NOT EXISTS {};".format(db_name))
    conn.close()
    LOGGER.warn("Created db: {}".format(db_name))

    # Connect to the DB
    mysql_string = "mysql+pymysql://{user}:{passwd}@{host}:{port}/{db_name}".format(
            user = db_user,
            passwd = db_password,
            host = db_address,
            db_name = db_name,
            port = db_port)
    engine = create_engine(
            mysql_string,
            echo=False,
            pool_recycle=3600,
            isolation_level="READ_COMMITTED",
            max_overflow=125,
            pool_size=32
        )
    LOGGER.warn("Get Engine")

    # Create Special Users
    database = lib.get_db()

    ##
    # Admin
    LOGGER.warn("Validate Admin user account")
    try:
        admin_user = os.environ["GRIN_POOL_ADMIN_USER"]
        admin_pass = os.environ["GRIN_POOL_ADMIN_PASSWORD"]
    except KeyError:
        LOGGER.error("We dont have Admin account info, failed...")
        sys.exit(1)
    # Create the account
    user = Users.get_by_id(1)
    if user is not None:
        database.db.deleteDataObj(user)
    user = Users(
            id = 1,
            username = admin_user,
            password = admin_pass,
        )
    database.db.createDataObj(user)
예제 #6
0
import os
import sys
import json
import time
import redis
from datetime import datetime
import requests


from grinbase.model.users import Users

from grinlib import lib
from grinlib import grin
from grinlib import pool

redis_userid_key = "userid."


r = redis.Redis(
    host='redis-master',
    port=6379)

database = lib.get_db()


for id in range(1, 9999):
    user_rec = Users.get_by_id(id)
    redis_key = redis_userid_key + user_rec.username
    r.set(redis_key, user_rec.id)