Commencé à écrire la page HTML pour afficher les résultats du WIFI sniffer sur le mini serveur WEB du NodeMCU

This commit is contained in:
Christian Zufferey
2019-02-15 18:21:13 +01:00
parent bf1b5a8bb8
commit b25fa0ed7c
6 changed files with 224 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
-- Scripts à charger après le boot pour démarrer son appli
print("\n boot.lua zf190202.1527 \n")
print("\n boot.lua zf190215.1814 \n")
function heartbeat()
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
@@ -16,10 +16,10 @@ f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end
f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
--f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
--f= "web_srv.lua" if file.exists(f) then dofile(f) end
f= "web_srv2.lua" if file.exists(f) then dofile(f) end
f= "set_time.lua" if file.exists(f) then dofile(f) end
--f= "dsleep.lua" if file.exists(f) then dofile(f) end
f= "b.lua" if file.exists(f) then dofile(f) end
--f= "b.lua" if file.exists(f) then dofile(f) end

20
WIFI_sniffer/index.html Normal file
View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
<title>ESP8266 home page</title>
</head>
<body>
<h1>ESP8266 home page 190215.1817</h1>
<h2>Différentes pages HTML:</h2>
<h3>
<a href="page1.html">Page 1, affichage de la température dynamique en code Lua inline.</a><br>
<a href="page2.html">Page 2, tableau dynamique écrit en Lua inline.</a><br>
<a href="page3.html">Page 3, affichage des résultats du WIFI sniffer écrit en Lua inline.</a><br>
<a href="page_qui_existe_pag.html">Page qui n'existe pas !</a><br>
</h3>
</body>
</html>

26
WIFI_sniffer/page1.html Normal file
View File

@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
<title>ESP8266 page 1</title>
</head>
<body>
<h1>ESP8266 page 1 190127.1445</h1>
<br>
Coucou c'est la page 1 !<br>
<a href="/">Retour à la home page...</a><br><br><br>
La température est:
<%
ztemp=ztemp+1
zout(ztemp.."°C")
%>
<br>Mais il fait encore trop froid !<br>
</body>
</html>

51
WIFI_sniffer/page2.html Normal file
View File

@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
<title>ESP8266 page 2</title>
</head>
<body>
<h1>ESP8266 page 2 190127.1449</h1>
<br>
Coucou c'est la page 2 !<br>
<a href="/">Retour à la home page...</a><br><br><br>
Voici un tableau dynamique écrit en Lua inline.<br><br>
Le code Lua pour créer ce tableau se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
Les données du tableau viennent du NodeMCU !<br><br>
<%
-- création du tableau sur le NodeMCUjuste juste pour la démo ici !
zmac_adrs={}
zmac_adrs["b8:d7:af:a6:bd:86"]={["zname"]="S7 zf", ["zrssi"]=45, ["ztime"]="12:03:36"}
zmac_adrs["cc:c0:79:7d:f5:d5"]={["zname"]="S7 Mélanie", ["zrssi"]=50, ["ztime"]="14:23:46"}
zmac_adrs["5c:f9:38:a1:f7:f0"]={["zname"]="MAC zf", ["zrssi"]=40, ["ztime"]="11:53:16"}
zmac_adrs["d8:30:62:5a:d6:3a"]={["zname"]="IMAC Maman", ["zrssi"]=55, ["ztime"]="17:07:23"}
%>
<table border='1'>
<tr>
<th>MAC</th><th>Name</th><th>RSSI</th><th>Time</th>
</tr>
<%
for k, v in pairs(zmac_adrs) do
zout("<tr>\n")
zout("\t<td>" .. k .. "</td>\n")
zout("\t<td>" .. tostring(zmac_adrs[k]["zname"]) .. "</td>\n")
zout("\t<td>" .. tostring(zmac_adrs[k]["zrssi"]) .. "</td>\n")
zout("\t<td>" .. tostring(zmac_adrs[k]["ztime"]) .. "</td>\n")
zout("</tr>\n")
end
%>
</table>
<%
-- libère la mémoire du tableau sur le NodeMCU qui avait été créé pour la démo ici !
zmac_adrs=nil
%>
</body>
</html>

51
WIFI_sniffer/page3.html Normal file
View File

@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
<title>ESP8266 page 2</title>
</head>
<body>
<h1>ESP8266 page 2 190215.1819</h1>
<br>
Coucou c'est la page 3 !<br>
<a href="/">Retour à la home page...</a><br><br><br>
Voici le résultat du WIFI sniffer, dans un tableau dynamique écrit en Lua inline.<br><br>
Le code Lua pour créer ce tableau se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
Les données du tableau viennent du NodeMCU !<br><br>
<%
-- création du tableau sur le NodeMCUjuste juste pour la démo ici !
zmac_adrs={}
zmac_adrs["b8:d7:af:a6:bd:86"]={["zname"]="S7 zf", ["zrssi"]=45, ["ztime"]="12:03:36"}
zmac_adrs["cc:c0:79:7d:f5:d5"]={["zname"]="S7 Mélanie", ["zrssi"]=50, ["ztime"]="14:23:46"}
zmac_adrs["5c:f9:38:a1:f7:f0"]={["zname"]="MAC zf", ["zrssi"]=40, ["ztime"]="11:53:16"}
zmac_adrs["d8:30:62:5a:d6:3a"]={["zname"]="IMAC Maman", ["zrssi"]=55, ["ztime"]="17:07:23"}
%>
<table border='1'>
<tr>
<th>MAC</th><th>Name</th><th>RSSI</th><th>Time</th>
</tr>
<%
for k, v in pairs(zmac_adrs) do
zout("<tr>\n")
zout("\t<td>" .. k .. "</td>\n")
zout("\t<td>" .. tostring(zmac_adrs[k]["zname"]) .. "</td>\n")
zout("\t<td>" .. tostring(zmac_adrs[k]["zrssi"]) .. "</td>\n")
zout("\t<td>" .. tostring(zmac_adrs[k]["ztime"]) .. "</td>\n")
zout("</tr>\n")
end
%>
</table>
<%
-- libère la mémoire du tableau sur le NodeMCU qui avait été créé pour la démo ici !
zmac_adrs=nil
%>
</body>
</html>

73
WIFI_sniffer/web_srv2.lua Normal file
View File

@@ -0,0 +1,73 @@
-- petit script de serveur WEB avec Active Server Page ZYX
-- pour l'instant la partie ASP n'est que mono tâche !
print("\n web_srv2.lua zf190127.1458 \n")
ztemp=12
-- envoie sur le port ouvert mais depuis l'environnement global !
function zout(zstring)
zzclient:send(zstring) -- envoie le résultat du code lua inline
end
-- envoie un fichier HTML sur le port. ATTENTION: longueur de la ligne maximale de 1'024 bytes !
function send_file(zclient, zfilename)
zzclient = zclient -- export le port sur l'environnement global !
if zfilename == "" then zfilename = "index.html" end
if file.open(zfilename, "r") then
repeat
local line = file.read('\n')
if line then
if string.find(line, "<%%") then
-- print("start lua...")
flag_lua_code = true -- bascule sur le code lua inline
lua_code = ""
elseif string.find(line, "%%>") then
-- print("stop lua...")
flag_lua_code = false -- revient sur le code HTML
-- print("Et voici le code lua inline:\n"..lua_code)
loadstring(lua_code)() --on exécute ici le code lua inline !
elseif flag_lua_code then
-- print(line)
lua_code = lua_code..line -- récupère le code lua inline
else
zclient:send(line) -- envoie le code HTML
end
end
until not line
file.close()
else
zclient:send("<html><h1>"..zfilename.." not found - 404 error</h1><a href='/'>Home</a><br></html>")
end
end
srv = net.createServer()
srv:listen(80, function(conn)
conn:on("receive", function(client, request)
_, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
-- print("request: \n---\n"..request.."---")
-- print("method: ", method) print("path: ", path) print("vars: ", vars)
if not string.find(request, "/favicon.ico") then
print("coucou")
if (method == nil) then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP")
end
_GET = {}
if (vars ~= nil) then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
print(k..": "..v)
end
end
file_html=string.gsub(path, "/", "")
-- print("file_html: ",file_html)
send_file(client, file_html)
end
end)
conn:on("sent", function(c) c:close() end)
end)