mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-03 05:10:48 +08:00
Add ping response with session ID and time remaing if authentication
This commit is contained in:
parent
901c13be6f
commit
be1b47f9ac
@ -22,7 +22,7 @@
|
|||||||
#define _VERSION_ESP3D_H
|
#define _VERSION_ESP3D_H
|
||||||
|
|
||||||
//version and sources location
|
//version and sources location
|
||||||
#define FW_VERSION "3.0.0.a61"
|
#define FW_VERSION "3.0.0.a62"
|
||||||
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
||||||
|
|
||||||
#endif //_VERSION_ESP3D_H
|
#endif //_VERSION_ESP3D_H
|
||||||
|
@ -269,9 +269,6 @@ bool AuthenticationService::ClearAuthIP (IPAddress ip, const char * sessionID)
|
|||||||
auth_ip * AuthenticationService::GetAuth (IPAddress ip, const char * sessionID)
|
auth_ip * AuthenticationService::GetAuth (IPAddress ip, const char * sessionID)
|
||||||
{
|
{
|
||||||
auth_ip * current = _head;
|
auth_ip * current = _head;
|
||||||
//auth_ip * previous = NULL;
|
|
||||||
//get time
|
|
||||||
//uint32_t now = millis();
|
|
||||||
while (current) {
|
while (current) {
|
||||||
if (ip == current->ip) {
|
if (ip == current->ip) {
|
||||||
if (strcmp (sessionID, current->sessionID) == 0) {
|
if (strcmp (sessionID, current->sessionID) == 0) {
|
||||||
@ -285,6 +282,28 @@ auth_ip * AuthenticationService::GetAuth (IPAddress ip, const char * sessionID)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get time left for specific session
|
||||||
|
uint32_t AuthenticationService::getSessionRemaining(const char * sessionID)
|
||||||
|
{
|
||||||
|
auth_ip * current = _head;
|
||||||
|
if ((sessionID == nullptr) || (strlen(sessionID) == 0)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
while (current) {
|
||||||
|
if (strcmp (sessionID, current->sessionID) == 0) {
|
||||||
|
//found
|
||||||
|
uint32_t now = millis();
|
||||||
|
if ((now - current->last_time) > _sessionTimeout) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return _sessionTimeout - (now-current->last_time);
|
||||||
|
}
|
||||||
|
//previous = current;
|
||||||
|
current = current->_next;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//Review all IP to reset timers
|
//Review all IP to reset timers
|
||||||
level_authenticate_type AuthenticationService::ResetAuthIP (IPAddress ip, const char * sessionID)
|
level_authenticate_type AuthenticationService::ResetAuthIP (IPAddress ip, const char * sessionID)
|
||||||
{
|
{
|
||||||
|
@ -69,6 +69,7 @@ public:
|
|||||||
#if defined (HTTP_FEATURE)
|
#if defined (HTTP_FEATURE)
|
||||||
static uint32_t setSessionTimeout(uint32_t timeout);
|
static uint32_t setSessionTimeout(uint32_t timeout);
|
||||||
static uint32_t getSessionTimeout();
|
static uint32_t getSessionTimeout();
|
||||||
|
static uint32_t getSessionRemaining(const char * sessionID);
|
||||||
static char * create_session_ID();
|
static char * create_session_ID();
|
||||||
static bool ClearCurrentSession ();
|
static bool ClearCurrentSession ();
|
||||||
static bool ClearAllSessions ();
|
static bool ClearAllSessions ();
|
||||||
|
@ -49,8 +49,7 @@ void HTTP_Server::handle_web_command ()
|
|||||||
esp3d_commands.process((uint8_t*)cmd.c_str(), cmd.length(), &output, auth_level);
|
esp3d_commands.process((uint8_t*)cmd.c_str(), cmd.length(), &output, auth_level);
|
||||||
} else if (_webserver->hasArg ("ping")) {
|
} else if (_webserver->hasArg ("ping")) {
|
||||||
_webserver->send (200);
|
_webserver->send (200);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
_webserver->send (400, "text/plain", "Invalid command");
|
_webserver->send (400, "text/plain", "Invalid command");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "../../core/settings_esp3d.h"
|
#include "../../core/settings_esp3d.h"
|
||||||
#include "../../core/esp3doutput.h"
|
#include "../../core/esp3doutput.h"
|
||||||
#include "../../core/commands.h"
|
#include "../../core/commands.h"
|
||||||
|
#include "../authentication/authentication_service.h"
|
||||||
|
|
||||||
WebSocket_Server websocket_terminal_server;
|
WebSocket_Server websocket_terminal_server;
|
||||||
#if defined(WS_DATA_FEATURE)
|
#if defined(WS_DATA_FEATURE)
|
||||||
@ -89,23 +90,35 @@ void handle_Websocket_Terminal_Event(uint8_t num, uint8_t type, uint8_t * payloa
|
|||||||
{
|
{
|
||||||
(void)payload;
|
(void)payload;
|
||||||
(void)length;
|
(void)length;
|
||||||
|
String msg;
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case WStype_DISCONNECTED:
|
case WStype_DISCONNECTED:
|
||||||
log_esp3d("[%u] Socket Disconnected port %d!", num,websocket_terminal_server.port());
|
log_esp3d("[%u] Socket Disconnected port %d!", num,websocket_terminal_server.port());
|
||||||
break;
|
break;
|
||||||
case WStype_CONNECTED: {
|
case WStype_CONNECTED: {
|
||||||
String s = "currentID:" + String(num);
|
msg = "currentID:" + String(num);
|
||||||
// send message to client
|
// send message to client
|
||||||
websocket_terminal_server.set_currentID(num);
|
websocket_terminal_server.set_currentID(num);
|
||||||
websocket_terminal_server.pushMSG(num, s.c_str());
|
websocket_terminal_server.pushMSG(num, msg.c_str());
|
||||||
s = "activeID:" + String(num);
|
msg = "activeID:" + String(num);
|
||||||
websocket_terminal_server.pushMSG(s.c_str());
|
websocket_terminal_server.pushMSG(msg.c_str());
|
||||||
log_esp3d("[%u] Socket connected port %d", num,websocket_terminal_server.port());
|
log_esp3d("[%u] Socket connected port %d", num,websocket_terminal_server.port());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WStype_TEXT:
|
case WStype_TEXT:
|
||||||
//we do not expect any input
|
#if defined (AUTHENTICATION_FEATURE)
|
||||||
//log_esp3d("[IGNORED][%u] get Text: %s port %d", num, payload, websocket_terminal_server.port());
|
//we do not expect any input but ping to get session timeout if any
|
||||||
|
if (AuthenticationService::getSessionTimeout() != 0) {
|
||||||
|
msg = (const char*)payload;
|
||||||
|
if (msg.startsWith("PING:")) {
|
||||||
|
String session = msg.substring(5);
|
||||||
|
String response = "PING:"+String(AuthenticationService::getSessionRemaining(session.c_str()));
|
||||||
|
response += ":"+String(AuthenticationService::getSessionTimeout());
|
||||||
|
websocket_terminal_server.pushMSG(num, response.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif //AUTHENTICATION_FEATURE
|
||||||
|
log_esp3d("[IGNORED][%u] get Text: %s port %d", num, payload, websocket_terminal_server.port());
|
||||||
break;
|
break;
|
||||||
case WStype_BIN:
|
case WStype_BIN:
|
||||||
//we do not expect any input
|
//we do not expect any input
|
||||||
|
Loading…
x
Reference in New Issue
Block a user