From 1dd95e07576b05f21893ed64d667e6c0350cc3ca Mon Sep 17 00:00:00 2001 From: Sebastian Serfling Date: Wed, 25 Oct 2023 10:54:34 +0200 Subject: [PATCH] Remove API key From Console --- Classes/main_classes.py | 6 +++++- main.py | 32 ++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Classes/main_classes.py b/Classes/main_classes.py index e2438f5..27c7a40 100644 --- a/Classes/main_classes.py +++ b/Classes/main_classes.py @@ -138,12 +138,16 @@ class CL_SET_CPU(BaseModel): class CL_UPDATE_HOST(BaseModel): hostname: str + user: str + ipadresse: str + winver: str + cpuname: str + cores: int dbname: str ram: int hddfree: str hddused: str hddtotal: str - ipadresse: str class CL_SET_LASTLOGON_USER(BaseModel): userID: int diff --git a/main.py b/main.py index 242d774..0f4aeb0 100644 --- a/main.py +++ b/main.py @@ -124,25 +124,25 @@ async def sethost(get: CL.CL_SET_HOST,api_key: APIKey = Depends(auth.get_api_key else: return result[0][0] -@app.post("/host/cpu") -async def setcpu(get: CL.CL_SET_CPU,api_key: APIKey = Depends(auth.get_api_key)): - check = database(f"SELECT id FROM `{get.dbname}`.cpulist WHERE cpuname = '{get.cpuname}' AND ghz") - database(f"INSERT INTO `{get.dbname}`.cpulist (cpuname,ghz,cputyp) VALUES ('{get.cpuname}','{get.ghz}','{get.cputyp}')","","") - result = database( - f"SELECT id FROM `{get.dbname}`.cpulist WHERE cpuname = '{get.cpuname} AND cputyp = {get.cputyp}')", - "", "") - database( - f"INSERT INTO `{get.dbname}`.cpu_to_client (hardwareID,cpulistID) VALUES ('{get.hardwareID}','{result[0][0]}',)", - "", "") - if not result: - return False - else: - return result[0][0] +# @app.post("/host/cpu") +# async def setcpu(get: CL.CL_SET_CPU,api_key: APIKey = Depends(auth.get_api_key)): +# check = database(f"SELECT id FROM `{get.dbname}`.cpulist WHERE cpuname = '{get.cpuname}' AND ghz") +# database(f"INSERT INTO `{get.dbname}`.cpulist (cpuname,ghz,cputyp) VALUES ('{get.cpuname}','{get.ghz}','{get.cputyp}')","","") +# result = database( +# f"SELECT id FROM `{get.dbname}`.cpulist WHERE cpuname = '{get.cpuname} AND cputyp = {get.cputyp}')", +# "", "") +# database( +# f"INSERT INTO `{get.dbname}`.cpu_to_client (hardwareID,cpulistID) VALUES ('{get.hardwareID}','{result[0][0]}',)", +# "", "") +# if not result: +# return False +# else: +# return result[0][0] @app.post("/host/update") async def updatehost(get: CL.CL_UPDATE_HOST,api_key: APIKey = Depends(auth.get_api_key)): - database(f"UPDATE `{get.dbname}`.hardware SET ipadresse = '{get.ipadresse}', ram = '{get.ram}', hddused = '{get.hddused}' ,hddfree = '{get.hddfree}',hddtotal = '{get.hddtotal}' WHERE hostname = '{get.hostname}'","","") - result = database(f"SELECT id FROM `{get.dbname}`.hardware WHERE hostname = '{get.hostname}'","", "") + database(f"UPDATE `{get.dbname}`.Clients SET Username = {get.user},`IP-Adresse` = {get.ipadresse},`Windows-Version` = {get.winver},`CPU-Name` = {get.cpuname}',`Prozessor-Anzahl = '{get.cores}'`,RAM = '{get.ram}',Speichergesamt = '{get.hddtotal}',Speicherfrei = '{get.hddfree}',Speicherbelegt = '{get.hddused}', LastChange = {datetime.now()} WHERE hostname = '{get.hostname}'","","") + result = database(f"SELECT id FROM `{get.dbname}`.Clients WHERE `Host-Name` = '{get.hostname}'","", "") if not result: return False else: