Beispiel #1
0
def request_user_token(orgtok):
    if request.method != 'POST':
       return 'Invalid, no data provided'

    all_org_keys = [r_org.hmget(x.decode('UTF-8'), 'Organization Token')[0].decode('UTF-8') for x in r_org.keys()]
    if orgtok not in all_org_keys:
       return 'Organization key invalid, access denied'

    dictdata = ImmutableMultiDict(request.form).to_dict(flat='')
    NAME = str(dictdata['name'][0])
    LAST_NAME = str(dictdata['last_name'][0])
    EMAIL = str(dictdata['email'][0])
    if '' in [NAME, LAST_NAME, EMAIL]:
       return 'Invalid request, not all information has been provided'
    # Creates a temporary token, sent to the user's email
    SEQ = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
    temptok = ''
    for qq in range(0, 24):
        temptok += random.choice(SEQ)

    Text = "Your token request has been approved.\nYour token is:    "+temptok+"\n\n\nInsert this token in the second step when prompted\n\n"
    Text += "Note: This is an automated message, all messages sent to this address will be ignored."
    r_temp.setex(temptok, 'valid', 24*3600) # Redis documentation is faulty, time goes at the end
    pp.send_mail(EMAIL, 'Temporary token requested', Text)
    return 'An automatic email has been sent to the provided email address, this token will remain valid for 24 hours.'
Beispiel #2
0
def complete_build(IMTAG, UTOK, MIDIR, COMMAND_TXT, FILES_PATH='.'):

    researcher_email = pp.obtain_email(UTOK)
    try:
        user_image(IMTAG)

        # Reduces the corresponding user's allocation
        # Docker represents image size in GB
        imsiz = float(image.get(IMTAG).attrs['Size']) / (10**9)
        r.incrbyfloat(UTOK, -imsiz)
        # Moves the file
        shutil.move(
            COMMAND_TXT + ".txt",
            "/root/project/html/user/token_data/process_files/" + COMMAND_TXT +
            ".txt")
        # Deletes the key
        r.delete(UTOK + '.' + MIDIR)
        MESSAGE = Success_Message.replace(
            "DATETIME",
            datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        pp.send_mail(researcher_email, 'Succesful MIDAS build', MESSAGE)
    except Exception as e:
        print(e)
        MESSAGE = Failure_Message.replace(
            "DATETIME",
            datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        pp.send_mail(researcher_email, 'Failed MIDAS build', MESSAGE)
Beispiel #3
0
def authenticated_request_token(temptok):

    if r_temp.get(temptok) is None:
        return 'INVALID, temporary token not valid, already used, or expired, access denied'

    DATA_PROV = r_temp.get(temptok).decode('UTF-8').split(';')
    user_org = DATA_PROV[0]
    NAME = DATA_PROV[1]
    LAST_NAME = DATA_PROV[2]
    EMAIL = DATA_PROV[3]
    ALLOCATION = DATA_PROV[4]

    maxalloc = r_org.hget(user_org, 'Data Plan').decode('UTF-8')
    if float(ALLOCATION) > float(maxalloc):
        r_temp.delete(temptok)
        return 'INVALID, User requested allocation is larger than organization allows'

    # Creates a final token for the user
    SEQ = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
    user_tok = ''
    for qq in range(0, 14):
        user_tok += random.choice(SEQ)

    # Replaces single quotes by double quotes
    Org_Users_Data = json.loads(
        r_org.hget(user_org,
                   'Users').decode('UTF-8').replace('\"', 'UHJKNM').replace(
                       '\'', '\"').replace('UHJKLM', '\''))
    Org_Users_Data[user_tok] = {
        'name': NAME,
        'last name': LAST_NAME,
        'email': EMAIL,
        'allocation': ALLOCATION
    }
    r_org.hset(user_org, 'Users', Org_Users_Data)
    r_temp.delete(temptok)
    r_org.hincrby(user_org, 'No. Users', 1)

    Text = "Your researcher account has been approved.\nUser token: " + user_tok + "\n\nSincerely,\nthe TACC BOINC development team"

    pp.send_mail(EMAIL, 'Approved researcher account', Text)

    # Adds the token to the token file
    with open("/root/project/html/user/token_data/Tokens.txt", "a") as tokfile:
        tokfile.write(NAME + " " + LAST_NAME + ", " + user_tok + ", " + EMAIL +
                      '\n')

    # Also creates a Reef directory
    os.makedirs('/root/project/api/sandbox_files/DIR_' + str(user_tok))
    os.makedirs('/root/project/api/sandbox_files/DIR_' + str(user_tok) +
                '/___RESULTS')

    # Adds the allocation details
    r_alloc.set(user_tok, ALLOCATION)

    return 'Your request has been approved, you may now submit BOINC jobs. Check your email for a token if you need terminal access.'
Beispiel #4
0
def authenticated_request_token(temptok):

    if r_temp.get(temptok) is None:
        return 'INVALID, temporary token not valid, already used, or expired, access denied'

    DATA_PROV = r_temp.get(temptok).decode('UTF-8').split(';')
    user_org = DATA_PROV[0]
    NAME = DATA_PROV[1]
    LAST_NAME = DATA_PROV[2]
    EMAIL = DATA_PROV[3]
    ALLOCATION = DATA_PROV[4]

    maxalloc = r_org.hget(user_org, 'Data Plan').decode('UTF-8')
    if float(ALLOCATION) > float(maxalloc):
        r_temp.delete(temptok)
        return 'INVALID, User requested allocation is larger than organization allows'

    user_tok = EMAIL

    # Replaces single quotes by double quotes
    Org_Users_Data = json.loads(
        r_org.hget(user_org,
                   'Users').decode('UTF-8').replace('\"', 'UHJKNM').replace(
                       '\'', '\"').replace('UHJKLM', '\''))
    Org_Users_Data[user_tok] = {
        'name': NAME,
        'last name': LAST_NAME,
        'email': EMAIL,
        'allocation': ALLOCATION
    }
    r_org.hset(user_org, 'Users', Org_Users_Data)
    r_temp.delete(temptok)
    r_org.hincrby(user_org, 'No. Users', 1)

    Text = "Your researcher account has been approved.\nUser token: " + user_tok + "\n\nSincerely,\nthe TACC BOINC development team"

    pp.send_mail(EMAIL, 'Approved researcher account', Text)

    # Adds the token to the token file
    with open("/root/project/html/user/token_data/Tokens.txt", "a") as tokfile:
        tokfile.write(NAME + " " + LAST_NAME + ", " + user_tok + ", " + EMAIL +
                      '\n')

    # Also creates a Reef directory
    requests.get('http://' + os.environ['Reef_IP'] +
                 ':2002/reef/create_user/' + user_tok + '/' +
                 os.environ['Reef_Key'])

    # Adds the allocation details
    r_alloc.set(user_tok, ALLOCATION)

    return 'Your request has been approved, you may now submit BOINC jobs. Check your email for a token if you need terminal access.'
Beispiel #5
0
def request_user_token():

    if request.method != 'POST':
        return 'INVALID, no data provided'

    all_orgs = [x.decode('UTF-8') for x in r_org.keys()]
    all_org_emails = [
        r_org.hmget(x, 'Allowed Email')[0].decode('UTF-8') for x in all_orgs
    ]

    dictdata = ImmutableMultiDict(request.form).to_dict(flat='')
    NAME = str(dictdata['name'][0])
    LAST_NAME = str(dictdata['last_name'][0])
    EMAIL = str(dictdata['email'][0])
    EMLAST = '@' + EMAIL.split('@')[-1]

    ALLOCATION = str(dictdata['allocation'][0])
    if '' in [NAME, LAST_NAME, EMAIL, ALLOCATION]:
        return 'Invalid request, not all information has been provided'

    # Obtains the actual emails
    # Finds if the user's email is valid
    invalid_email = True

    for hh in range(0, len(all_orgs)):
        if EMLAST in all_org_emails[hh].split(';'):
            user_org = all_orgs[hh]
            invalid_email = False
            break

    if invalid_email:
        return "INVALID, user email does not correspond to an allowed organization"

    # Creates a temporary token, sent to the user's email
    SEQ = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
    temptok = ''

    for qq in range(0, 24):
        temptok += random.choice(SEQ)

    Text = "Your token request has been approved.\nClick on the following link to activate your account as a BOINC researcher: \n\n"
    Text += os.environ[
        "SERVER_IP"] + ":5054/boincserver/v2/api/authenticated_request_token/" + temptok
    Text += "\nThe link will be active for a period of 24 hours and will be deactivated upon clicking on it.\n\n"
    Text += "Note: This is an automated message, all messages sent to this address will be ignored."
    r_temp.setex(temptok, ';'.join([
        user_org, NAME, LAST_NAME, EMAIL, ALLOCATION
    ]), 24 * 3600)  # Redis documentation is faulty, time goes at the end
    pp.send_mail(EMAIL, 'Researcher account requested', Text)
    return 'An automatic email has been sent to the provided email address, this link will remain valid for 24 hours.'
Beispiel #6
0
def complete_build(IMTAG, UTOK, MIDIR, COMMAND_TXT, DOCK_DOCK, BOCOM, FILES_PATH='.'):

    researcher_email = pp.obtain_email(UTOK)
    try:
        user_image(IMTAG)

        # Reduces the corresponding user's allocation
        # Docker represents image size in GB
        # Moves the file
        boapp = r.get(UTOK+'.'+MIDIR).decode("UTF-8")
        if boapp == "boinc2docker":
            shutil.move(COMMAND_TXT+".txt", "/root/project/html/user/token_data/process_files/"+COMMAND_TXT+".txt")
        if boapp == "adtdp":
            shutil.move(COMMAND_TXT+".txt", "/root/project/adtd-protocol/process_files/"+COMMAND_TXT+".txt")

        # Deletes the key
        r.delete(UTOK+'.'+MIDIR)

        # Saves the docker image and sends the user the dockerfile and a link to the tar ball
        # docker-py documentation was erronous

        img = image.get(IMTAG)
        resp = img.save()

        # Creates a file, recycled everytime the program runs
        saved_name = "image."+hashlib.sha256(str(datetime.datetime.now()).encode('UTF-8')).hexdigest()[:4:]+".tar.gz"
        ff = open(saved_name, 'wb')
        for salmon in resp:
            ff.write(salmon)
        ff.close()

        # Moves the file to the user's result folders
        shutil.move(saved_name, "/root/project/api/sandbox_files/DIR_"+UTOK+"/___RESULTS/"+saved_name)

        MESSAGE = Success_Message.replace("DATETIME", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        MESSAGE += "\n\nClick on the following link to obtain a compressed version of the application docker image.\n"
        MESSAGE += "You are welcome to upload the image on dockerhub in order to reduce the future job processing time for the same application (no allocation will be discounted): \n"
        MESSAGE += os.environ["SERVER_IP"]+":5060/boincserver/v2/reef/results/"+UTOK+"/"+saved_name
        MESSAGE += "\n\nRun the following command on the image: \n"+' '.join(BOCOM.split(' ')[1::])
        MESSAGE += "\n\nThis is the Dockerfile we used to process your job: \n\n"+DOCK_DOCK
        pp.send_mail(researcher_email, 'Succesful MIDAS build', MESSAGE)
    except Exception as e:
        print(e)
        r.delete(UTOK+'.'+MIDIR)
        # Deletes the unused container
        client.containers.prune()
        MESSAGE = Failure_Message.replace("DATETIME", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        MESSAGE += "\n\nDockerfile created below: \n\n"+DOCK_DOCK
        pp.send_mail(researcher_email, 'Failed MIDAS build', MESSAGE)
Beispiel #7
0
def complete_build(IMTAG,
                   UTOK,
                   MIDIR,
                   COMMAND_TXT,
                   DOCK_DOCK,
                   BOCOM,
                   FILES_PATH='.'):

    researcher_email = pp.obtain_email(UTOK)
    try:
        user_image(IMTAG)

        # Reduces the corresponding user's allocation
        # Docker represents image size in GB
        # Moves the file
        boapp = r.get(UTOK + ';' + MIDIR).decode("UTF-8")

        if boapp == "boinc2docker":

            # Reads tag information from json file
            # Image is the user ID because:
            #    | - Traceable
            #    | - MID is a random token
            with open("tag_info.json", 'r') as J:
                TAGS = json.load(J)

            cus.complete_tag_work(UTOK, TAGS)
            shutil.move(
                COMMAND_TXT + ".txt",
                "/home/boincadm/project/html/user/token_data/process_files/" +
                COMMAND_TXT + ".txt")

        if boapp == "adtdp":
            shutil.move(
                COMMAND_TXT + ".txt",
                "/home/boincadm/project/adtd-protocol/process_files/" +
                COMMAND_TXT + ".txt")

        # Deletes the key
        r.delete(UTOK + ';' + MIDIR)

        # Saves the docker image and sends the user the dockerfile and a link to the tar ball
        # docker-py documentation was erronous

        img = image.get(IMTAG)
        resp = img.save()

        # Creates a file, recycled everytime the program runs
        saved_name = "image." + hashlib.sha256(
            str(datetime.datetime.now()).encode(
                'UTF-8')).hexdigest()[:4:] + ".tar.gz"
        ff = open(saved_name, 'wb')
        for salmon in resp:
            ff.write(salmon)
        ff.close()

        # Moves the file to reef and deletes the local copy
        requests.post('http://' + os.environ['Reef_IP'] +
                      ':2001/reef/result_upload/' + os.environ['Reef_Key'] +
                      '/' + UTOK,
                      files={"file": open(saved_name, "rb")})
        os.remove(saved_name)
        MESSAGE = Success_Message.replace(
            "DATETIME",
            datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        MESSAGE += "\n\nClick on the following link to obtain a compressed version of the application docker image.\n"
        MESSAGE += "You are welcome to upload the image on dockerhub in order to reduce the future job processing time for the same application (no allocation will be discounted): \n"
        MESSAGE += os.environ[
            "SERVER_IP"] + ":5060/boincserver/v2/reef/results/" + UTOK + "/" + saved_name
        MESSAGE += "\n\nRun the following command on the image: \n" + ' '.join(
            BOCOM.split(' ')[1::])
        MESSAGE += "\n\nThis is the Dockerfile we used to process your job: \n\n" + DOCK_DOCK
        pp.send_mail(researcher_email, 'Succesful MIDAS build', MESSAGE)

    except Exception as e:
        print(e)
        r.delete(UTOK + ';' + MIDIR)
        # Deletes the unused container
        client.containers.prune()
        MESSAGE = Failure_Message.replace(
            "DATETIME",
            datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        MESSAGE += "\n\nDockerfile created below: \n\n" + DOCK_DOCK
        pp.send_mail(researcher_email, 'Failed MIDAS build', MESSAGE)