diff --git a/server/main.py b/server/main.py index eceaa69..243c395 100644 --- a/server/main.py +++ b/server/main.py @@ -17,8 +17,7 @@ from pydantic import BaseModel devs = { "Matej Justus": { - "git": "https://github.com/UntriexTv", "mail": "maco.justus@gmail.com" - }, + "git": "https://github.com/UntriexTv", "mail": "maco.justus@gmail.com"}, "Benjamin Kojda": { "git": "https://github.com/Tucan444", "mail": "ben4442004@gmail.com" }, @@ -89,7 +88,14 @@ if ID not in heartbeat_table["ID"]: heartbeat_table["location"].append(location) heartbeat_table["file_system"].append(filesystem) heartbeat_table["last_heartbeat"].append(time_to_heartbeat) +else: + index_server_run = heartbeat_table["ID"].index(ID) + heartbeat_table["IP"][index_server_run] = IP + heartbeat_table["location"][index_server_run] = location + heartbeat_table["file_system"][index_server_run] = filesystem + heartbeat_table["last_heartbeat"][index_server_run] = time_to_heartbeat +heartbeat_table["my_ip"] = IP class ServerTable(BaseModel): # table of content for heartbeat request ID: list @@ -97,6 +103,7 @@ class ServerTable(BaseModel): # table of content for heartbeat request location: list file_system: list last_heartbeat: list + my_ip: str class Sensor(BaseModel): @@ -116,7 +123,8 @@ def read_root(): @app.post("/heartbeat") def heartbeat(s_table: ServerTable, request: Request): - log.message(f"server requested heartbeat {request.client.host}:{request.client.port}") + global heartbeat_table + log.message(f"server requested heartbeat {s_table.my_ip}:{request.client.port}") log.debug(f"Recieved server table: {s_table}") try: @@ -132,8 +140,8 @@ def heartbeat(s_table: ServerTable, request: Request): elif server_id == ID: log.debug(f"Updated my heartbeat from {s_table.last_heartbeat[position]} to {time_to_heartbeat}") heartbeat_table["last_heartbeat"][heartbeat_table["ID"].index(ID)] = time_to_heartbeat - else: - log.message(f"Heartbeat from new server:\n ID: {server_id} IP: {request.client}") + elif server_id not in heartbeat_table["ID"]: + log.message(f"Heartbeat from new server:\n ID: {server_id} IP: {s_table.my_ip}") heartbeat_table["ID"].append(int(s_table.ID[position])) heartbeat_table["IP"].append(s_table.IP[position]) heartbeat_table["location"].append(s_table.location[position]) @@ -142,10 +150,12 @@ def heartbeat(s_table: ServerTable, request: Request): log.debug(f"Created {server_id}`s heartbeat: {s_table.last_heartbeat[position]}") except Exception as error: log.error(f"heartbeat > {error}") - - if heartbeat_table["ID"][heartbeat_table["IP"].index(request.client.host)] in offline: - offline.remove(heartbeat_table["ID"][heartbeat_table["IP"].index(request.client.host)]) - log.warning(f"{request.client.host} gone online") + try: + if heartbeat_table["ID"][heartbeat_table["IP"].index(s_table.my_ip)] in offline: + offline.remove(heartbeat_table["ID"][heartbeat_table["IP"].index(s_table.my_ip)]) + log.warning(f"{s_table.my_ip} gone online") + except Exception as error: + log.error(f"heartbeat > {error}") return heartbeat_table, {"ID": ID, "file_system": filesystem, "location": location} @@ -169,7 +179,6 @@ def get_sensors(IDx: int, request: Request): @app.get("/files/{IDx}/{file}") def get_file(IDx: int, file: str, request: Request): log.debug(f"""{request.client} requested {file} from {"this server" if IDx == ID else f"id {IDx}"}""") - server_ip = heartbeat_table["IP"][heartbeat_table["ID"].index(IDx)] if IDx == ID: if os.path.isfile(f"files/{file}"): return FileResponse(f"files/{file}") @@ -180,6 +189,7 @@ def get_file(IDx: int, file: str, request: Request): log.warning(f"{request.client} tried to access id ({IDx}) that does not exist.") return f"ERROR: {IDx} does not exist." else: + server_ip = heartbeat_table["IP"][heartbeat_table["ID"].index(IDx)] if os.path.isdir(f"cache/{IDx}"): if os.path.isfile(f"cache/{IDx}/{file}"): with open(f"cache/{IDx}/{file}", "rb") as compared_file: @@ -212,7 +222,7 @@ def get_file(IDx: int, file: str, request: Request): @app.post("/{IDx}/update_sensor") def update_sensors(data: Sensor, request: Request, IDx: int): global sensors - if IDx == ID: + if IDx == ID or IDx == -1: if data.name in sensors: if not data.value: log.message(f"{request.client.host} removed sensor {data.name}") @@ -224,10 +234,12 @@ def update_sensors(data: Sensor, request: Request, IDx: int): log.warning(f"{request.client} created new sensor.\n SENSOR: {data}") sensors[data.name] = data.value return f"Successfuly made new sensor" - else: + elif IDx in heartbeat_table["ID"]: r = requests.post(f"""http://{heartbeat_table["IP"][heartbeat_table["ID"].index(IDx)]}:8000/{IDx}/update_sensor""", json={"name": data.name, "value": data.value}) return r.text + else: + return f"ERROR: server {IDx} does not exist." @app.get("/compare/{file}") diff --git a/website/WikiSpot.html b/website/WikiSpot.html index a76d969..c27921b 100644 --- a/website/WikiSpot.html +++ b/website/WikiSpot.html @@ -6,13 +6,15 @@ + +
-
SŤIAHNUŤ ▼
+
SŤIAHNUŤ
diff --git a/website/WikiSpotCSS.css b/website/WikiSpotCSS.css index dcf2d11..51e0f2e 100644 --- a/website/WikiSpotCSS.css +++ b/website/WikiSpotCSS.css @@ -28,6 +28,7 @@ body { margin-left: 1.3rem; } .itemImg { + cursor: pointer; margin-right: auto; margin-left: 1.3rem; } @@ -37,7 +38,7 @@ body { font-size: 20px; } .list li:hover { - color: chartreuse; + color: rgba(255, 255, 255, 0.418); transition: color 0.2s ease-in-out; } .wsImg { @@ -90,7 +91,7 @@ body { } /* ---------- Hlavná stránka ---------- */ #downloadHolder { - margin-top: 5%; + margin-top: 10px; margin-left: 35%; display: flex; justify-content: space-between; @@ -104,20 +105,21 @@ body { color: white; border: 4px white solid; border-radius: 50px; - margin-right: -100px; + margin-right: 0px; width: auto; - height: 20px; + height: 30px; padding: 10px; position: static; - font-size: 20px; + font-size: 25px; font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; + transition: background-color 0.5s, color 0.5s; } -#download:hover { +#appDownload:hover { background-color: white; color: rgb(47, 40, 150) ; } #phoneImg { - width: 250px; + width: 350px; height: auto; } #conHolder { @@ -131,9 +133,15 @@ body { } /* ---------- O projekte ---------- */ #projectInfo { - background-color: rgb(255, 255, 255); + position: absolute; + top: 250px; + left: 450px; + background-color: rgba(255, 255, 255, 0.322); font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; - color: black; - width: 300px; + color: rgb(255, 255, 255); + padding: 15px; + border-radius: 20px; + width: 470px; height: auto; + font-size: 40px; } \ No newline at end of file diff --git a/website/WikiSpotLoc.html b/website/WikiSpotLoc.html deleted file mode 100644 index b2b0f3a..0000000 --- a/website/WikiSpotLoc.html +++ /dev/null @@ -1,158 +0,0 @@ - - - - WikiSpot - - - - - - - - - -
- - - home - - -
- - - - - -
-
-
-
-
- wsData1img -
-
- - -
-
-
-
-
- wsData2img -
-
- - - - -
-
-
-
-
- wsData3img -
-
- - - - -
-
-
-
-
- wsData4img -
-
- - - - -
-
-
-
-
- wsData5img -
-
- - diff --git a/website/WikiSpotPro.html b/website/WikiSpotPro.html index 8bd1249..6129d72 100644 --- a/website/WikiSpotPro.html +++ b/website/WikiSpotPro.html @@ -13,7 +13,7 @@