예제 #1
0
def logout_client(cursor, client_id, utype="user", is_alt=False):
    db_name = "uchs_test" if is_alt else "uchs_db"
    if "user" in utype:
        login_check_query = """
        SELECT login_status FROM {}.user_tbl ut
        WHERE ut.user_id = '{}'
        """.format(db_name, client_id)
        login_status_update = """
        UPDATE {}.user_tbl SET login_status = 0
        WHERE user_id = '{}'
        """.format(db_name, client_id)
    elif "help" in utype:
        login_check_query = """
        SELECT login_status FROM {}.helpline_tbl ut
        WHERE ut.helpline_id = '{}'
        """.format(db_name, client_id)
        login_status_update = """
        UPDATE {}.helpline_tbl SET login_status = 0
        WHERE helpline_id = '{}'
        """.format(db_name, client_id)
    cursor.execute(login_check_query)
    result = cursor.fetchone()
    if not result:
        return False, f"'{client_id}' is unregistered!"
    is_loggedin = byte_to_int(result[0])
    if not is_loggedin:
        print(f"--ALERT: {utype} STACKED LOGOUT by '{client_id}'--")
        return False, f"Stacked logouts from '{client_id}'!"
    cursor.execute(login_status_update)
    return True, "Logout successful!"
예제 #2
0
 def read(self, file_, numBytes, offset, convertToInt=1):
     """a custom read function for file at offset with numBytes, convert to the desired type"""
     file_.seek(offset)
     value = file_.read(numBytes)
     if convertToInt:
         return byte_to_int(value)
     return value.decode("utf-8")
예제 #3
0
 def hash_(self, key):
     """return a integer hashed value"""
     # get the hashed value from the key
     hashFunc = hashlib.md5()
     hashFunc.update(key.encode('utf-8'))
     hashedBytes = hashFunc.digest()
     # conver the byte into integer
     return byte_to_int(hashedBytes)
예제 #4
0
 def __init__(self, dbFile, indexFile):
     super().__init__(dbfile, indexFile)
     indexFile.seek(0)
     # NOTE: the order of reads matters
     self.pSize = byte_to_int(indexFile.read(2))
     self.indexType = byte_to_int(indexFile.read(1))
     self.directoryStartPage = byte_to_int(indexFile.read(1))
     self.globalDepth = byte_to_int(indexFile.read(1))
     self.overflowPointerSize = byte_to_int(indexFile.read(1))
     self.directoryEntrySize = byte_to_int(indexFile.read(1))
     self.recordEntrySize = byte_to_int(indexFile.read(1))
     self.depthOccupiedBytes = byte_to_int(indexFile.read(1))
     # the bytes occupied by the record metadata, both directory and record page
     self.recordCapacityoOccupiedBytes = byte_to_int(indexFile.read(1))
예제 #5
0
 def __init__(self, dbFile, indexFile):
     super().__init__(dbfile, indexFile)
     indexFile.seek(0)
     # NOTE: order of reading the metadata matters
     self.pSize = byte_to_int(
         indexFile.read(2))  # read 2 bytes from the beginning of the file
     self.indexType = byte_to_int(indexFile.read(1))
     self.initialBucketNum = byte_to_int(
         indexFile.read(2))  # read 2 bytes from offset of 3
     self.overflowPointerSize = byte_to_int(indexFile.read(1))
     self.recordEntrySize = byte_to_int(indexFile.read(1))
     self.recordCapacityoOccupiedBytes = byte_to_int(indexFile.read(1))
예제 #6
0
def login_client(cursor, client_id, client_passw, utype="user", is_alt=False):
    db_name = "uchs_test" if is_alt else "uchs_db"
    if "user" in utype:
        login_check_query = """
        SELECT login_status FROM {}.user_tbl ut
        WHERE ut.user_id = '{}'
        """.format(db_name, client_id)
        pass_check_query = """
        select COUNT(AES_DECRYPT(ut.password , UNHEX(SHA2('{}',512))))
        from {}.user_tbl ut where ut.user_id ='{}';
        """.format(client_passw, db_name, client_id)
        login_status_update = """
        UPDATE {}.user_tbl SET login_status = 1
        WHERE user_id = '{}'
        """.format(db_name, client_id)
    elif "help" in utype:
        login_check_query = """
        SELECT login_status FROM {}.helpline_tbl ut
        WHERE ut.helpline_id = '{}'
        """.format(db_name, client_id)
        pass_check_query = """
        select COUNT(AES_DECRYPT(ht.password , UNHEX(SHA2('{}',512))))
        from {}.helpline_tbl ht where ht.helpline_id ='{}';
        """.format(client_passw, db_name, client_id)
        login_status_update = """
        UPDATE {}.helpline_tbl SET login_status = 1
        WHERE helpline_id = '{}'
        """.format(db_name, client_id)
    cursor.execute(login_check_query)
    result = cursor.fetchone()
    if not result:
        return False, f"'{client_id}' is unregistered!"
    is_loggedin = byte_to_int(result[0])
    if is_loggedin:
        return False, f"'{client_id}' has already logged in!"
    cursor.execute(pass_check_query)
    cnt = cursor.fetchone()[0]
    if not cnt:
        return False, f"'{client_id}' password is incorrect!"
    cursor.execute(login_status_update)
    return True, f"Login successful!"
예제 #7
0
    def __init__(self, dbFile, indexFile):
        super().__init__(dbfile, indexFile)

        indexFile.seek(0)
        self.pSize = byte_to_int(
            indexFile.read(2))  # read 2 bytes from the beginning of the file

        indexFile.seek(3, 0)
        self.initialBuckets = byte_to_int(
            indexFile.read(2))  # read 2 bytes from offset of 3

        indexFile.seek(5, 0)
        self.level = byte_to_int(indexFile.read(2))

        indexFile.seek(7, 0)
        self.next = byte_to_int(indexFile.read(2))

        self.overflowPointerSize = byte_to_int(indexFile.read(1))
        self.recordEntrySize = byte_to_int(indexFile.read(1))
        self.recordCapacityoOccupiedBytes = byte_to_int(indexFile.read(1))
예제 #8
0
 def hash_(self, key):
     """a generic hash function for all three hash index file"""
     hashFunc = hashlib.md5()
     hashFunc.update(key.encode('utf-8'))
     hashedBytes = hashFunc.digest()
     return byte_to_int(hashedBytes)