diff --git a/__pycache__/main.cpython-311.pyc b/__pycache__/main.cpython-311.pyc index 093220e..0242ac0 100644 Binary files a/__pycache__/main.cpython-311.pyc and b/__pycache__/main.cpython-311.pyc differ diff --git a/list b/list new file mode 100644 index 0000000..8f3be0f --- /dev/null +++ b/list @@ -0,0 +1,4 @@ +toN +jan +Kees +RICK diff --git a/main.py b/main.py index 4f7e43e..368720c 100644 --- a/main.py +++ b/main.py @@ -71,8 +71,30 @@ async def update_post(id: int, post: Post): my_posts[index] = post_dict return {"data": post_dict} +@app.get("/create_env") +async def ping_host(): + # send one packet of data to the host + # this is specified by '-c 1' in the argument list + outputlist = [] + # Iterate over all the servers in the list and ping each server + # get the output as a string + #output = str(os.system(cmd)) + #cmd = subprocess.run(["/bin/ls", "-al"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True) + cmd = subprocess.run(["cat","list"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True) + # store the output in the list + output = (f"{cmd.stdout}") + return output +@app.get("/environment/{id}") +async def get_env(id: str): + #env = find_post(id) + cmd = subprocess.run(["cat list | grep %s" % id],stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + if cmd.returncode != 0: + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Post id {id} not found") + else: + return {"post_detail": cmd} + @app.get("/list") async def ping_host(): # send one packet of data to the host @@ -81,7 +103,12 @@ async def ping_host(): # Iterate over all the servers in the list and ping each server # get the output as a string #output = str(os.system(cmd)) - cmd = subprocess.run(["/bin/ls", "-al"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True) + #cmd = subprocess.run(["/bin/ls", "-al"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True) + cmd = subprocess.run(["cat list"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + #cmd = subprocess.run(["ls /usr/bin"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) # store the output in the list - output = (f"{cmd.stdout}") - return output \ No newline at end of file + #output = (f"{cmd.stdout}") + #output1 = (f'{cmd.stdout.decode("utf-8")}') + output2 = (f'{cmd.stdout.decode("utf-8").lower()}') + print (output2) + return output2 \ No newline at end of file