This commit is contained in:
Untriex Programming 2021-05-11 08:55:16 +02:00
parent d80346df5f
commit 9b30e7a3d3
11 changed files with 65 additions and 195 deletions

@ -17,8 +17,7 @@ from pydantic import BaseModel
devs = { devs = {
"Matej Justus": { "Matej Justus": {
"git": "https://github.com/UntriexTv", "mail": "maco.justus@gmail.com" "git": "https://github.com/UntriexTv", "mail": "maco.justus@gmail.com"},
},
"Benjamin Kojda": { "Benjamin Kojda": {
"git": "https://github.com/Tucan444", "mail": "ben4442004@gmail.com" "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["location"].append(location)
heartbeat_table["file_system"].append(filesystem) heartbeat_table["file_system"].append(filesystem)
heartbeat_table["last_heartbeat"].append(time_to_heartbeat) 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 class ServerTable(BaseModel): # table of content for heartbeat request
ID: list ID: list
@ -97,6 +103,7 @@ class ServerTable(BaseModel): # table of content for heartbeat request
location: list location: list
file_system: list file_system: list
last_heartbeat: list last_heartbeat: list
my_ip: str
class Sensor(BaseModel): class Sensor(BaseModel):
@ -116,7 +123,8 @@ def read_root():
@app.post("/heartbeat") @app.post("/heartbeat")
def heartbeat(s_table: ServerTable, request: Request): 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}") log.debug(f"Recieved server table: {s_table}")
try: try:
@ -132,8 +140,8 @@ def heartbeat(s_table: ServerTable, request: Request):
elif server_id == ID: elif server_id == ID:
log.debug(f"Updated my heartbeat from {s_table.last_heartbeat[position]} to {time_to_heartbeat}") 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 heartbeat_table["last_heartbeat"][heartbeat_table["ID"].index(ID)] = time_to_heartbeat
else: elif server_id not in heartbeat_table["ID"]:
log.message(f"Heartbeat from new server:\n ID: {server_id} IP: {request.client}") 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["ID"].append(int(s_table.ID[position]))
heartbeat_table["IP"].append(s_table.IP[position]) heartbeat_table["IP"].append(s_table.IP[position])
heartbeat_table["location"].append(s_table.location[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]}") log.debug(f"Created {server_id}`s heartbeat: {s_table.last_heartbeat[position]}")
except Exception as error: except Exception as error:
log.error(f"heartbeat > {error}") log.error(f"heartbeat > {error}")
try:
if heartbeat_table["ID"][heartbeat_table["IP"].index(request.client.host)] in offline: if heartbeat_table["ID"][heartbeat_table["IP"].index(s_table.my_ip)] in offline:
offline.remove(heartbeat_table["ID"][heartbeat_table["IP"].index(request.client.host)]) offline.remove(heartbeat_table["ID"][heartbeat_table["IP"].index(s_table.my_ip)])
log.warning(f"{request.client.host} gone online") 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} 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}") @app.get("/files/{IDx}/{file}")
def get_file(IDx: int, file: str, request: Request): 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}"}""") 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 IDx == ID:
if os.path.isfile(f"files/{file}"): if os.path.isfile(f"files/{file}"):
return FileResponse(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.") log.warning(f"{request.client} tried to access id ({IDx}) that does not exist.")
return f"ERROR: {IDx} does not exist." return f"ERROR: {IDx} does not exist."
else: else:
server_ip = heartbeat_table["IP"][heartbeat_table["ID"].index(IDx)]
if os.path.isdir(f"cache/{IDx}"): if os.path.isdir(f"cache/{IDx}"):
if os.path.isfile(f"cache/{IDx}/{file}"): if os.path.isfile(f"cache/{IDx}/{file}"):
with open(f"cache/{IDx}/{file}", "rb") as compared_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") @app.post("/{IDx}/update_sensor")
def update_sensors(data: Sensor, request: Request, IDx: int): def update_sensors(data: Sensor, request: Request, IDx: int):
global sensors global sensors
if IDx == ID: if IDx == ID or IDx == -1:
if data.name in sensors: if data.name in sensors:
if not data.value: if not data.value:
log.message(f"{request.client.host} removed sensor {data.name}") 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}") log.warning(f"{request.client} created new sensor.\n SENSOR: {data}")
sensors[data.name] = data.value sensors[data.name] = data.value
return f"Successfuly made new sensor" 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""", r = requests.post(f"""http://{heartbeat_table["IP"][heartbeat_table["ID"].index(IDx)]}:8000/{IDx}/update_sensor""",
json={"name": data.name, "value": data.value}) json={"name": data.name, "value": data.value})
return r.text return r.text
else:
return f"ERROR: server {IDx} does not exist."
@app.get("/compare/{file}") @app.get("/compare/{file}")

@ -6,13 +6,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="WikiSpotCSS.css"> <link rel="stylesheet" href="WikiSpotCSS.css">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Add icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="appjs.js"></script> <script src="appjs.js"></script>
</head> </head>
<header> <header>
<nav> <nav>
<!-- Navigačná lišta /veľká obrazovka/ --> <!-- Navigačná lišta /veľká obrazovka/ -->
<ul class="list"> <ul class="list">
<img src="wikispot-white.png" alt="" class="itemImg"> <img src="wikispot-white.png" alt="" class="itemImg" onclick="location.href = 'WikiSpot.html'">
<li class="item" onclick="location.href = 'WikiSpot.html'">DOMOV</li> <li class="item" onclick="location.href = 'WikiSpot.html'">DOMOV</li>
<li class="item" onclick="location.href = 'WikiSpotWS.html'">WIKISPOT</li> <li class="item" onclick="location.href = 'WikiSpotWS.html'">WIKISPOT</li>
<li class="item" onclick="location.href = 'WikiSpotPro.html'">O PROJEKTE</li> <li class="item" onclick="location.href = 'WikiSpotPro.html'">O PROJEKTE</li>
@ -30,7 +32,7 @@
</header> </header>
<body> <body>
<div id="downloadHolder"> <div id="downloadHolder">
<a href=""></a><div id="appDownload">SŤIAHNUŤ &#9660</div></a> <a href=""></a><div id="appDownload">SŤIAHNUŤ <i class="fa fa-download"></i></div></a>
<img src="wikispotphone.png" alt="" id="phoneImg"> <img src="wikispotphone.png" alt="" id="phoneImg">
</div> </div>
</body> </body>

@ -28,6 +28,7 @@ body {
margin-left: 1.3rem; margin-left: 1.3rem;
} }
.itemImg { .itemImg {
cursor: pointer;
margin-right: auto; margin-right: auto;
margin-left: 1.3rem; margin-left: 1.3rem;
} }
@ -37,7 +38,7 @@ body {
font-size: 20px; font-size: 20px;
} }
.list li:hover { .list li:hover {
color: chartreuse; color: rgba(255, 255, 255, 0.418);
transition: color 0.2s ease-in-out; transition: color 0.2s ease-in-out;
} }
.wsImg { .wsImg {
@ -90,7 +91,7 @@ body {
} }
/* ---------- Hlavná stránka ---------- */ /* ---------- Hlavná stránka ---------- */
#downloadHolder { #downloadHolder {
margin-top: 5%; margin-top: 10px;
margin-left: 35%; margin-left: 35%;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@ -104,20 +105,21 @@ body {
color: white; color: white;
border: 4px white solid; border: 4px white solid;
border-radius: 50px; border-radius: 50px;
margin-right: -100px; margin-right: 0px;
width: auto; width: auto;
height: 20px; height: 30px;
padding: 10px; padding: 10px;
position: static; position: static;
font-size: 20px; font-size: 25px;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; 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; background-color: white;
color: rgb(47, 40, 150) ; color: rgb(47, 40, 150) ;
} }
#phoneImg { #phoneImg {
width: 250px; width: 350px;
height: auto; height: auto;
} }
#conHolder { #conHolder {
@ -131,9 +133,15 @@ body {
} }
/* ---------- O projekte ---------- */ /* ---------- O projekte ---------- */
#projectInfo { #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; font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
color: black; color: rgb(255, 255, 255);
width: 300px; padding: 15px;
border-radius: 20px;
width: 470px;
height: auto; height: auto;
font-size: 40px;
} }

@ -1,158 +0,0 @@
<!DOCTYPE html>
<html lang="sk">
<head>
<title>WikiSpot</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="WikiSpotLoc.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="desc_short.js"></script>
<script src="click1.js"></script>
<script src="sensors.js"></script>
</head>
<body>
<header>
<img src="wikispot-white.png" alt="wikispot" id="logo" usemap="#navhome">
<map name="navhome">
<area shape="rect" coords="20, 15, 255, 100" href="http://www.spspb.sk/kontakt.html?page_id=91" alt="home">
</map>
<nav>
<ul id="container">
<li id="home" onclick="location.href = 'WikiSpot.html';"><a href="WikiSpot.html">DOMOV</a></li>
<li id="about" onclick="location.href = 'WikiSpotLoc.html';"><a href="WikiSpotLoc.html">WIKISPOT</a></li>
<li id="project" onclick="location.href = 'WikiSpotPro.html';"><a href="WikiSpotPro.html">O PROJEKTE</a></li>
<li id="contact" onclick="location.href = 'http://www.spspb.sk/kontakt.html?page_id=91';"><a href="http://www.spspb.sk/kontakt.html?page_id=91">KONTAKT</a></li>
</ul>
<div class="nav">
<label for="check" id="bmenu">&#9776</label>
<input type="checkbox" id="check">
<table class="menu">
<tr><td><a href="WikiSpot.html" class="expandable">DOMOV</a></td></tr>
<tr><td><a href="WikiSpotLoc.html" class="expandable">WIKISPOT</a></td></tr>
<tr><td><a href="WikiSpotPro.html" class="expandable">PROJEKT</a></td></tr>
<tr><td><a href="#" class="expandable">KOTAKT</a></td></tr>
</table>
</div>
</nav>
</header>
<!--Device select-->
<input type="radio" id="checkExp1" name="pick" class="pickNone">
<input type="radio" id="checkExp2" name="pick" class="pickNone">
<!--1st device-->
<label for="checkExp1">
<section id="wsData1">
<div id="wsBackGround1" class="round_s"></div>
<section id="myData"></section>
<section id="myTitle"></section>
<div id="imgData1">
<img src="http://192.168.1.105:8000/files/0/library.jpg" alt="wsimage1" style="width: 100px; height: 100px;">
</div>
<input type="checkbox" id="checkDesc1" class="none">
<label for="checkDesc1" id="descIcon1" onclick="lul1()"><div id="fuckme1">&#9660</div></label>
<div id="dataExpand1"></div>
</section>
</label>
<section id="wsData1Exp" class="round">
<article id="wsData1desc_l">
<div id="desc_l1"></div>
</article>
<article>
<img src="http://192.168.1.105:8000/files/0/library.jpg" alt="wsData1img" id="wsData1img" style="height: 300px; width: 500px;">
</article>
</section>
<!--2nd device-->
<label for="checkExp2">
<section id="wsData2">
<div id="wsBackGround2" class="round_s"></div>
<section id="myData2"></section>
<section id="myTitle2"></section>
<div id="imgData2">
<img src="http://192.168.1.105:8000/files/0/test.jpg" alt="wsimage2" style="width: 100px; height: 100px;">
</div>
<label for="checkDesc2" id="descIcon2" onclick="lul2()"><div id="fuckme2">&#9660</div></label>
<input type="checkbox" id="checkDesc2" class="none">
<div id="dataExpand2" class="round_s"></div>
</section>
</label>
<section id="wsData2Exp" class="round">
<article id="wsData2desc_l">
<div id="desc_l2"></div>
</article>
<article>
<img src="http://192.168.1.105:8000/files/0/test.jpg" alt="wsData2img" id="wsData2img" style="height: 300px; width: 500px;">
</article>
</section>
</body>
</html>
<!--3rd device-->
<label for="checkExp3">
<section id="wsData3">
<div id="wsBackGround3" class="round_s"></div>
<section id="myData3"></section>
<section id="myTitle3"></section>
<div id="imgData3">
<img src="http://192.168.1.105:8000/files/0/test.jpg" alt="wsimage3" style="width: 100px; height: 100px;">
</div>
<label for="checkDesc3" id="descIcon3" onclick="lul2()"><div id="fuckme3">&#9660</div></label>
<input type="checkbox" id="checkDesc3" class="none">
<div id="dataExpand3"></div>
</section>
</label>
<section id="wsData3Exp" class="round">
<article id="wsData3desc_l">
<div id="desc_l3"></div>
</article>
<article>
<img src="http://192.168.1.105:8000/files/0/test.jpg" alt="wsData3img" id="wsData3img" style="height: 300px; width: 500px;">
</article>
</section>
</body>
</html>
<!--4th device-->
<label for="checkExp4">
<section id="wsData4">
<div id="wsBackGround4" class="round_s"></div>
<section id="myData4"></section>
<section id="myTitle4"></section>
<div id="imgData4">
<img src="http://192.168.1.105:8000/files/0/test.jpg" alt="wsimage4" style="width: 100px; height: 100px;">
</div>
<label for="checkDesc4" id="descIcon4" onclick="lul4()"><div id="fuckme4">&#9660</div></label>
<input type="checkbox" id="checkDesc4" class="none">
<div id="dataExpand4"></div>
</section>
</label>
<section id="wsData4Exp" class="round">
<article id="wsData4desc_l">
<div id="desc_l4"></div>
</article>
<article>
<img src="http://192.168.1.105:8000/files/0/test.jpg" alt="wsData4img" id="wsData4img" style="height: 300px; width: 500px;">
</article>
</section>
</body>
</html>
<!--5th device-->
<label for="checkExp5">
<section id="wsData5">
<div id="wsBackGround5" class="round_s"></div>
<section id="myData5"></section>
<section id="myTitle5"></section>
<div id="imgData5">
<img src="http://192.168.1.105:8000/files/0/test.jpg" alt="wsimage5" style="width: 100px; height: 100px;">
</div>
<label for="checkDesc5" id="descIcon5" onclick="lul5()"><div id="fuckme5">&#9660</div></label>
<input type="checkbox" id="checkDesc5">
<div id="dataExpand5"></div>
</section>
</label>
<section id="wsData5Exp" class="round">
<article id="wsData5desc_l">
<div id="desc_l5"></div>
</article>
<article>
<img src="http://192.168.1.105:8000/files/0/test.jpg" alt="wsData5img" id="wsData5img" style="height: 300px; width: 500px;">
</article>
</section>
</body>
</html>

@ -13,7 +13,7 @@
<nav> <nav>
<!-- Navigačná lišta /veľká obrazovka/ --> <!-- Navigačná lišta /veľká obrazovka/ -->
<ul class="list"> <ul class="list">
<img src="wikispot-white.png" alt="" class="itemImg"> <img src="wikispot-white.png" alt="" class="itemImg" onclick="location.href = 'WikiSpot.html'">
<li class="item" onclick="location.href = 'WikiSpot.html'">DOMOV</li> <li class="item" onclick="location.href = 'WikiSpot.html'">DOMOV</li>
<li class="item" onclick="location.href = 'WikiSpotWS.html'">WIKISPOT</li> <li class="item" onclick="location.href = 'WikiSpotWS.html'">WIKISPOT</li>
<li class="item" onclick="location.href = 'WikiSpotPro.html'">O PROJEKTE</li> <li class="item" onclick="location.href = 'WikiSpotPro.html'">O PROJEKTE</li>

@ -13,7 +13,7 @@
<nav> <nav>
<!-- Navigačná lišta /veľká obrazovka/ --> <!-- Navigačná lišta /veľká obrazovka/ -->
<ul class="list"> <ul class="list">
<img src="wikispot-white.png" alt="" class="itemImg"> <img src="wikispot-white.png" alt="" class="itemImg" onclick="location.href = 'WikiSpot.html'">
<li class="item" onclick="location.href = 'WikiSpot.html'">DOMOV</li> <li class="item" onclick="location.href = 'WikiSpot.html'">DOMOV</li>
<li class="item" onclick="location.href = 'WikiSpotWS.html'">WIKISPOT</li> <li class="item" onclick="location.href = 'WikiSpotWS.html'">WIKISPOT</li>
<li class="item" onclick="location.href = 'WikiSpotPro.html'">O PROJEKTE</li> <li class="item" onclick="location.href = 'WikiSpotPro.html'">O PROJEKTE</li>

@ -27,6 +27,7 @@ body {
margin-left: 1.3rem; margin-left: 1.3rem;
} }
.itemImg { .itemImg {
cursor: pointer;
margin-right: auto; margin-right: auto;
margin-left: 1.3rem; margin-left: 1.3rem;
} }
@ -36,7 +37,7 @@ body {
font-size: 20px; font-size: 20px;
} }
.list li:hover { .list li:hover {
color: chartreuse; color: rgba(75, 61, 204, 0.459);
transition: color 0.2s ease-in-out; transition: color 0.2s ease-in-out;
} }
/* ---------- Burger Menu ---------- */ /* ---------- Burger Menu ---------- */
@ -310,6 +311,14 @@ body {
height: 350px; height: 350px;
} }
/* ---------- Responzívnosť (media tag) ---------- */ /* ---------- Responzívnosť (media tag) ---------- */
@media (min-width: 1350px) {
.arrow {
display: none;
}
.wsList {
width: 481px;
}
}
@media (max-width: 1550px) { @media (max-width: 1550px) {
.obrazok_big { .obrazok_big {
width: 400px; width: 400px;

@ -109,4 +109,4 @@ $(document).ready(function() {
}) })
} }
}) })

@ -1 +1 @@
192.168.1.105 127.0.0.1

File diff suppressed because one or more lines are too long

@ -1,8 +1 @@
sf Lorem ipsum dolor sit amet consectetur adipisicing elit. Error placeat optio facere nobis, ex tempore aut illo ipsum modi deserunt doloremque, harum ad ipsa perferendis assumenda cum magni perspiciatis delectus.
fsd
f
sdf
sd
fsd
f
sd