mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 16:59:00 +08:00
Allow to have admin and user authentication
admin is for wifi / esp settings user is for printer settings admin and user ID can be defined in config.h [ESP555]<admin password> allows to reset user password to default one
This commit is contained in:
parent
3575652099
commit
5296770703
@ -69,6 +69,9 @@ Web Page refresh: 3 secondes
|
|||||||
User: admin
|
User: admin
|
||||||
Password: admin
|
Password: admin
|
||||||
|
|
||||||
|
User:user
|
||||||
|
Password: user
|
||||||
|
|
||||||
These are the pages defined using template:
|
These are the pages defined using template:
|
||||||
Home page :
|
Home page :
|
||||||
<img src=https://raw.githubusercontent.com/luc-github/ESP3D/master/images/UI/Page1.png><br>
|
<img src=https://raw.githubusercontent.com/luc-github/ESP3D/master/images/UI/Page1.png><br>
|
||||||
@ -98,10 +101,11 @@ Because SPIFFS is flat filesystem, no directory management is necessary, so it i
|
|||||||
Additionally 404.tpl (the page not found) and restart.tpl(restart page when applying changes) are not mandatory, a fail safe version is embeded if they are not present.
|
Additionally 404.tpl (the page not found) and restart.tpl(restart page when applying changes) are not mandatory, a fail safe version is embeded if they are not present.
|
||||||
|
|
||||||
##Direct commands:
|
##Direct commands:
|
||||||
|
```
|
||||||
-restart module from host/printer: [ESP888]RESTART
|
-restart module from host/printer: [ESP888]RESTART
|
||||||
-Get IP (only printer see answer): [ESP111]M117
|
-Get IP (only printer see answer): [ESP111]M117
|
||||||
-reset EEPROM and restart: [ESP444]RESET
|
-reset EEPROM and restart: [ESP444]RESET
|
||||||
|
-reset user password: [ESP555]<admin password>
|
||||||
-display EEPROM content: [ESP444]CONFIG
|
-display EEPROM content: [ESP444]CONFIG
|
||||||
-go to safe mode without restart: [ESP444]SAFEMODE
|
-go to safe mode without restart: [ESP444]SAFEMODE
|
||||||
-SSID: [ESP100]<SSID>
|
-SSID: [ESP100]<SSID>
|
||||||
@ -110,7 +114,7 @@ Additionally 404.tpl (the page not found) and restart.tpl(restart page when appl
|
|||||||
-AP mode: [ESP103]AP
|
-AP mode: [ESP103]AP
|
||||||
-IP Static: [ESP104]STATIC
|
-IP Static: [ESP104]STATIC
|
||||||
-IP DHCP: [ESP104]DHCP
|
-IP DHCP: [ESP104]DHCP
|
||||||
|
```
|
||||||
##Installation
|
##Installation
|
||||||
* For stable:
|
* For stable:
|
||||||
Please use [Arduino IDE 1.6.5](http://arduino.cc/en/Main/Software) with the esp8266 module from board manager use 2.0.0 stable version by adding in your preferences http://arduino.esp8266.com/version/2.0.0/package_esp8266com_index.json
|
Please use [Arduino IDE 1.6.5](http://arduino.cc/en/Main/Software) with the esp8266 module from board manager use 2.0.0 stable version by adding in your preferences http://arduino.esp8266.com/version/2.0.0/package_esp8266com_index.json
|
||||||
|
@ -100,6 +100,23 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
CONFIG::print_config();
|
CONFIG::print_config();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 555:
|
||||||
|
{
|
||||||
|
String sadminPassword;
|
||||||
|
if (!CONFIG::read_string(EP_ADMIN_PWD, sadminPassword , MAX_LOCAL_PASSWORD_LENGTH)) {
|
||||||
|
sadminPassword=FPSTR(DEFAULT_ADMIN_PWD);
|
||||||
|
}
|
||||||
|
if (cmd_params == sadminPassword.c_str()) {
|
||||||
|
if(CONFIG::write_string(EP_USER_PWD,FPSTR(DEFAULT_USER_PWD))) {
|
||||||
|
Serial.println("\nOk");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.println("\nFailed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else Serial.println("\nFailed");
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 888:
|
case 888:
|
||||||
if (cmd_params=="RESTART") {
|
if (cmd_params=="RESTART") {
|
||||||
Serial.print("\r");
|
Serial.print("\r");
|
||||||
|
@ -229,7 +229,10 @@ bool CONFIG::reset_config()
|
|||||||
if(!CONFIG::write_buffer(EP_E_FEEDRATE,(const byte *)&DEFAULT_E_FEEDRATE,INTEGER_LENGTH)) {
|
if(!CONFIG::write_buffer(EP_E_FEEDRATE,(const byte *)&DEFAULT_E_FEEDRATE,INTEGER_LENGTH)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!CONFIG::write_string(EP_ADMIN_PWD,FPSTR(DEFAULT_ADMIN))) {
|
if(!CONFIG::write_string(EP_ADMIN_PWD,FPSTR(DEFAULT_ADMIN_PWD))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_string(EP_USER_PWD,FPSTR(DEFAULT_USER_PWD))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -57,7 +57,6 @@
|
|||||||
//#define DEBUG_ESP3D
|
//#define DEBUG_ESP3D
|
||||||
|
|
||||||
#ifdef DEBUG_ESP3D
|
#ifdef DEBUG_ESP3D
|
||||||
|
|
||||||
#define LOG(string) {File logfile = SPIFFS.open("/log.txt", "a+");logfile.print(string);logfile.close();}
|
#define LOG(string) {File logfile = SPIFFS.open("/log.txt", "a+");logfile.print(string);logfile.close();}
|
||||||
#else
|
#else
|
||||||
#define LOG(string) {}
|
#define LOG(string) {}
|
||||||
@ -69,7 +68,7 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
//version and sources location
|
//version and sources location
|
||||||
#define FW_VERSION "0.7.52"
|
#define FW_VERSION "0.7.7"
|
||||||
#define REPOSITORY "https://github.com/luc-github/ESP8266"
|
#define REPOSITORY "https://github.com/luc-github/ESP8266"
|
||||||
|
|
||||||
|
|
||||||
@ -105,8 +104,9 @@
|
|||||||
#define EP_Z_FEEDRATE 168//4 bytes = int
|
#define EP_Z_FEEDRATE 168//4 bytes = int
|
||||||
#define EP_E_FEEDRATE 172//4 bytes = int
|
#define EP_E_FEEDRATE 172//4 bytes = int
|
||||||
#define EP_ADMIN_PWD 176//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
|
#define EP_ADMIN_PWD 176//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
|
||||||
|
#define EP_USER_PWD 197//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
|
||||||
|
//next available is 218
|
||||||
|
//space left 256 - 218 = 38
|
||||||
|
|
||||||
//default values
|
//default values
|
||||||
#define DEFAULT_WIFI_MODE AP_MODE
|
#define DEFAULT_WIFI_MODE AP_MODE
|
||||||
@ -131,7 +131,11 @@ const int DEFAULT_DATA_PORT = 8888;
|
|||||||
const int DEFAULT_XY_FEEDRATE=1000;
|
const int DEFAULT_XY_FEEDRATE=1000;
|
||||||
const int DEFAULT_Z_FEEDRATE =100;
|
const int DEFAULT_Z_FEEDRATE =100;
|
||||||
const int DEFAULT_E_FEEDRATE=400;
|
const int DEFAULT_E_FEEDRATE=400;
|
||||||
const char DEFAULT_ADMIN [] PROGMEM = "admin";
|
const char DEFAULT_ADMIN_PWD [] PROGMEM = "admin";
|
||||||
|
const char DEFAULT_USER_PWD [] PROGMEM = "user";
|
||||||
|
const char DEFAULT_ADMIN_LOGIN [] PROGMEM = "admin";
|
||||||
|
const char DEFAULT_USER_LOGIN [] PROGMEM = "user";
|
||||||
|
|
||||||
|
|
||||||
//sizes
|
//sizes
|
||||||
#define EEPROM_SIZE 256 //max is 512
|
#define EEPROM_SIZE 256 //max is 512
|
||||||
@ -139,8 +143,8 @@ const char DEFAULT_ADMIN [] PROGMEM = "admin";
|
|||||||
#define MIN_SSID_LENGTH 1
|
#define MIN_SSID_LENGTH 1
|
||||||
#define MAX_PASSWORD_LENGTH 64
|
#define MAX_PASSWORD_LENGTH 64
|
||||||
#define MIN_PASSWORD_LENGTH 8
|
#define MIN_PASSWORD_LENGTH 8
|
||||||
#define MAX_ADMIN_PASSWORD_LENGTH 16
|
#define MAX_LOCAL_PASSWORD_LENGTH 16
|
||||||
#define MIN_ADMIN_PASSWORD_LENGTH 1
|
#define MIN_LOCAL_PASSWORD_LENGTH 1
|
||||||
#define IP_LENGTH 4
|
#define IP_LENGTH 4
|
||||||
#define INTEGER_LENGTH 4
|
#define INTEGER_LENGTH 4
|
||||||
#define MAX_HOSTNAME_LENGTH 32
|
#define MAX_HOSTNAME_LENGTH 32
|
||||||
|
@ -17,7 +17,7 @@ $INCLUDE[css.inc]$
|
|||||||
<td class="$MENU_PRINTER$"><a href="http://$WEB_ADDRESS$/PRINTER">3D Printer</a></td>
|
<td class="$MENU_PRINTER$"><a href="http://$WEB_ADDRESS$/PRINTER">3D Printer</a></td>
|
||||||
<td class="$MENU_SETTINGS$"><a href="http://$WEB_ADDRESS$/SETTINGS">Extra Settings</a></td>
|
<td class="$MENU_SETTINGS$"><a href="http://$WEB_ADDRESS$/SETTINGS">Extra Settings</a></td>
|
||||||
<td width=100%> </td>
|
<td width=100%> </td>
|
||||||
<td class="$MENU_ADMIN$"><a href="/PASSWORD" style="$DISCONNECT_VISIBILITY$">Admin</a></td>
|
<td class="$MENU_ADMIN$"><a href="/PASSWORD" style="$DISCONNECT_VISIBILITY$">$LOGIN_ID$</a></td>
|
||||||
<td style="padding:0px;"><a href="/LOGIN?DISCONNECT=YES"><div class="btnroundimg" style="$DISCONNECT_VISIBILITY$"><svg width="30" height="30" viewBox="0 0 40 40">
|
<td style="padding:0px;"><a href="/LOGIN?DISCONNECT=YES"><div class="btnroundimg" style="$DISCONNECT_VISIBILITY$"><svg width="30" height="30" viewBox="0 0 40 40">
|
||||||
<circle style="fill:white" cx="20" cy="20" r="20"/>
|
<circle style="fill:white" cx="20" cy="20" r="20"/>
|
||||||
<circle style="fill:white;stroke:black;stroke-width:4" cx="20" cy="15" r="10"/>
|
<circle style="fill:white;stroke:black;stroke-width:4" cx="20" cy="15" r="10"/>
|
||||||
|
@ -40,11 +40,14 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAX_AUTH_IP 10
|
#define MAX_AUTH_IP 10
|
||||||
#define UPLOAD_STATUS_NONE 0
|
|
||||||
#define UPLOAD_STATUS_FAILED 1
|
typedef enum {
|
||||||
#define UPLOAD_STATUS_CANCELLED 2
|
UPLOAD_STATUS_NONE = 0,
|
||||||
#define UPLOAD_STATUS_SUCCESSFUL 3
|
UPLOAD_STATUS_FAILED = 1,
|
||||||
#define UPLOAD_STATUS_ONGOING 4
|
UPLOAD_STATUS_CANCELLED = 2,
|
||||||
|
UPLOAD_STATUS_SUCCESSFUL = 3,
|
||||||
|
UPLOAD_STATUS_ONGOING =4
|
||||||
|
} upload_status_type;
|
||||||
|
|
||||||
const char PAGE_404 [] PROGMEM ="<HTML>\n<HEAD>\n<title>Redirecting...</title> \n</HEAD>\n<BODY>\n<CENTER>Unknown page - you will be redirected...\n<BR><BR>\nif not redirected, <a href='http://$WEB_ADDRESS$'>click here</a>\n<BR><BR>\n<PROGRESS name='prg' id='prg'></PROGRESS>\n\n<script>\nvar i = 0; \nvar x = document.getElementById(\"prg\"); \nx.max=5; \nvar interval=setInterval(function(){\ni=i+1; \nvar x = document.getElementById(\"prg\"); \nx.value=i; \nif (i>5) \n{\nclearInterval(interval);\nwindow.location.href='/';\n}\n},1000);\n</script>\n</CENTER>\n</BODY>\n</HTML>\n\n";
|
const char PAGE_404 [] PROGMEM ="<HTML>\n<HEAD>\n<title>Redirecting...</title> \n</HEAD>\n<BODY>\n<CENTER>Unknown page - you will be redirected...\n<BR><BR>\nif not redirected, <a href='http://$WEB_ADDRESS$'>click here</a>\n<BR><BR>\n<PROGRESS name='prg' id='prg'></PROGRESS>\n\n<script>\nvar i = 0; \nvar x = document.getElementById(\"prg\"); \nx.max=5; \nvar interval=setInterval(function(){\ni=i+1; \nvar x = document.getElementById(\"prg\"); \nx.value=i; \nif (i>5) \n{\nclearInterval(interval);\nwindow.location.href='/';\n}\n},1000);\n</script>\n</CENTER>\n</BODY>\n</HTML>\n\n";
|
||||||
const char PAGE_RESTART [] PROGMEM ="<HTML>\n<HEAD>\n<title>Restarting...</title> \n</HEAD>\n<BODY>\n<CENTER>Restarting, please wait....\n<BR>\n<PROGRESS name='prg' id='prg'></PROGRESS>\n</CENTER>\n<script>\nvar i = 0;\nvar interval; \nvar x = document.getElementById(\"prg\"); \nx.max=40; \ninterval = setInterval(function(){\ni=i+1; \nvar x = document.getElementById(\"prg\"); \nx.value=i; \nif (i>40) \n{\nclearInterval(interval);\nwindow.location.href='/';\n}\n},1000);\n</script>\n</BODY>\n</HTML>\n";
|
const char PAGE_RESTART [] PROGMEM ="<HTML>\n<HEAD>\n<title>Restarting...</title> \n</HEAD>\n<BODY>\n<CENTER>Restarting, please wait....\n<BR>\n<PROGRESS name='prg' id='prg'></PROGRESS>\n</CENTER>\n<script>\nvar i = 0;\nvar interval; \nvar x = document.getElementById(\"prg\"); \nx.max=40; \ninterval = setInterval(function(){\ni=i+1; \nvar x = document.getElementById(\"prg\"); \nx.value=i; \nif (i>40) \n{\nclearInterval(interval);\nwindow.location.href='/';\n}\n},1000);\n</script>\n</BODY>\n</HTML>\n";
|
||||||
@ -207,6 +210,7 @@ const char EEPROM_NOWRITE [] PROGMEM = "Error: Cannot write to EEPROM";
|
|||||||
const char KEY_WEB_UPDATE [] PROGMEM = "$WEB_UPDATE_VISIBILITY$";
|
const char KEY_WEB_UPDATE [] PROGMEM = "$WEB_UPDATE_VISIBILITY$";
|
||||||
const char KEY_STA_SIGNAL [] PROGMEM = "$STA_SIGNAL$";
|
const char KEY_STA_SIGNAL [] PROGMEM = "$STA_SIGNAL$";
|
||||||
const char KEY_DATA_PORT_VISIBILITY [] PROGMEM = "$DATA_PORT_VISIBILITY$";
|
const char KEY_DATA_PORT_VISIBILITY [] PROGMEM = "$DATA_PORT_VISIBILITY$";
|
||||||
|
const char KEY_LOGIN_ID [] PROGMEM = "$LOGIN_ID$";
|
||||||
|
|
||||||
bool WEBINTERFACE_CLASS::isHostnameValid(const char * hostname)
|
bool WEBINTERFACE_CLASS::isHostnameValid(const char * hostname)
|
||||||
{
|
{
|
||||||
@ -261,11 +265,11 @@ bool WEBINTERFACE_CLASS::isPasswordValid(const char * password)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WEBINTERFACE_CLASS::isAdminPasswordValid(const char * password)
|
bool WEBINTERFACE_CLASS::isLocalPasswordValid(const char * password)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
//limited size
|
//limited size
|
||||||
if ((strlen(password)>MAX_ADMIN_PASSWORD_LENGTH)|| (strlen(password)<MIN_ADMIN_PASSWORD_LENGTH)) {
|
if ((strlen(password)>MAX_LOCAL_PASSWORD_LENGTH)|| (strlen(password)<MIN_LOCAL_PASSWORD_LENGTH)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//no space allowed
|
//no space allowed
|
||||||
@ -529,6 +533,25 @@ void GetFreeMem(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList)
|
|||||||
KeysList.add(FPSTR(KEY_FW_VER));
|
KeysList.add(FPSTR(KEY_FW_VER));
|
||||||
ValuesList.add(FPSTR(VALUE_FW_VERSION));
|
ValuesList.add(FPSTR(VALUE_FW_VERSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Helper for Login ID
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
void GeLogin(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList,level_authenticate_type auth_level)
|
||||||
|
{
|
||||||
|
KeysList.add(FPSTR(KEY_DISCONNECT_VISIBILITY));
|
||||||
|
if (auth_level != LEVEL_GUEST) {
|
||||||
|
ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE));
|
||||||
|
KeysList.add(FPSTR(KEY_LOGIN_ID));
|
||||||
|
if (auth_level == LEVEL_ADMIN) ValuesList.add(FPSTR(DEFAULT_ADMIN_LOGIN));
|
||||||
|
else ValuesList.add(FPSTR(DEFAULT_USER_LOGIN));
|
||||||
|
} else {
|
||||||
|
ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN));
|
||||||
|
KeysList.add(FPSTR(KEY_LOGIN_ID));
|
||||||
|
ValuesList.add("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Helper for IP+Web address
|
// Helper for IP+Web address
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -704,12 +727,8 @@ void handle_web_interface_home()
|
|||||||
struct ip_info info;
|
struct ip_info info;
|
||||||
uint8_t mac [WL_MAC_ADDR_LENGTH];
|
uint8_t mac [WL_MAC_ADDR_LENGTH];
|
||||||
|
|
||||||
KeysList.add(FPSTR(KEY_DISCONNECT_VISIBILITY));
|
//login
|
||||||
if (web_interface->is_authenticated()) {
|
GeLogin(KeysList, ValuesList,web_interface->is_authenticated());
|
||||||
ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE));
|
|
||||||
} else {
|
|
||||||
ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN));
|
|
||||||
}
|
|
||||||
|
|
||||||
//IP+Web
|
//IP+Web
|
||||||
GetIpWeb(KeysList, ValuesList);
|
GetIpWeb(KeysList, ValuesList);
|
||||||
@ -1041,11 +1060,13 @@ void handle_web_interface_configSys()
|
|||||||
STORESTRINGS_CLASS KeysList ;
|
STORESTRINGS_CLASS KeysList ;
|
||||||
STORESTRINGS_CLASS ValuesList ;
|
STORESTRINGS_CLASS ValuesList ;
|
||||||
|
|
||||||
if (!web_interface->is_authenticated()) {
|
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||||
|
if (auth_level != LEVEL_ADMIN) {
|
||||||
web_interface->WebServer.sendContent_P(NOT_AUTH_CS);
|
web_interface->WebServer.sendContent_P(NOT_AUTH_CS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//login
|
||||||
|
GeLogin(KeysList, ValuesList,auth_level);
|
||||||
//IP+Web
|
//IP+Web
|
||||||
GetIpWeb(KeysList, ValuesList);
|
GetIpWeb(KeysList, ValuesList);
|
||||||
//mode
|
//mode
|
||||||
@ -1232,12 +1253,13 @@ void handle_password()
|
|||||||
//int ipos;
|
//int ipos;
|
||||||
STORESTRINGS_CLASS KeysList ;
|
STORESTRINGS_CLASS KeysList ;
|
||||||
STORESTRINGS_CLASS ValuesList ;
|
STORESTRINGS_CLASS ValuesList ;
|
||||||
|
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||||
if (!web_interface->is_authenticated()) {
|
if (auth_level == LEVEL_GUEST) {
|
||||||
web_interface->WebServer.sendContent_P(NOT_AUTH_PW);
|
web_interface->WebServer.sendContent_P(NOT_AUTH_PW);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//login
|
||||||
|
GeLogin(KeysList, ValuesList,auth_level);
|
||||||
//IP+Web
|
//IP+Web
|
||||||
GetIpWeb(KeysList, ValuesList);
|
GetIpWeb(KeysList, ValuesList);
|
||||||
//mode
|
//mode
|
||||||
@ -1256,7 +1278,7 @@ void handle_password()
|
|||||||
//Password
|
//Password
|
||||||
sPassword =web_interface->WebServer.arg("PASSWORD");
|
sPassword =web_interface->WebServer.arg("PASSWORD");
|
||||||
sPassword2 = web_interface->WebServer.arg("PASSWORD2");
|
sPassword2 = web_interface->WebServer.arg("PASSWORD2");
|
||||||
if (!web_interface->isAdminPasswordValid(sPassword.c_str()) ) {
|
if (!web_interface->isLocalPasswordValid(sPassword.c_str()) ) {
|
||||||
msg_alert_error=true;
|
msg_alert_error=true;
|
||||||
smsg.concat(F("Error: Incorrect password<BR>"));
|
smsg.concat(F("Error: Incorrect password<BR>"));
|
||||||
KeysList.add(FPSTR(KEY_USER_PASSWORD_STATUS));
|
KeysList.add(FPSTR(KEY_USER_PASSWORD_STATUS));
|
||||||
@ -1276,7 +1298,10 @@ void handle_password()
|
|||||||
//if no error apply the change
|
//if no error apply the change
|
||||||
if (msg_alert_error==false) {
|
if (msg_alert_error==false) {
|
||||||
//save
|
//save
|
||||||
if(!CONFIG::write_string(EP_ADMIN_PWD,sPassword.c_str())) {
|
bool res;
|
||||||
|
if (auth_level == LEVEL_ADMIN) res = CONFIG::write_string(EP_ADMIN_PWD,sPassword.c_str()) ;
|
||||||
|
else res = CONFIG::write_string(EP_USER_PWD,sPassword.c_str()) ;
|
||||||
|
if (!res) {
|
||||||
msg_alert_error=true;
|
msg_alert_error=true;
|
||||||
smsg = FPSTR(EEPROM_NOWRITE);
|
smsg = FPSTR(EEPROM_NOWRITE);
|
||||||
} else {
|
} else {
|
||||||
@ -1352,11 +1377,13 @@ void handle_web_interface_configAP()
|
|||||||
STORESTRINGS_CLASS KeysList ;
|
STORESTRINGS_CLASS KeysList ;
|
||||||
STORESTRINGS_CLASS ValuesList ;
|
STORESTRINGS_CLASS ValuesList ;
|
||||||
|
|
||||||
if (!web_interface->is_authenticated()) {
|
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||||
|
if (auth_level != LEVEL_ADMIN) {
|
||||||
web_interface->WebServer.sendContent_P(NOT_AUTH_AP);
|
web_interface->WebServer.sendContent_P(NOT_AUTH_AP);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//login
|
||||||
|
GeLogin(KeysList, ValuesList,auth_level);
|
||||||
//IP+Web
|
//IP+Web
|
||||||
GetIpWeb(KeysList, ValuesList);
|
GetIpWeb(KeysList, ValuesList);
|
||||||
//mode
|
//mode
|
||||||
@ -1692,11 +1719,13 @@ void handle_web_interface_configSTA()
|
|||||||
STORESTRINGS_CLASS KeysList ;
|
STORESTRINGS_CLASS KeysList ;
|
||||||
STORESTRINGS_CLASS ValuesList ;
|
STORESTRINGS_CLASS ValuesList ;
|
||||||
|
|
||||||
if (!web_interface->is_authenticated()) {
|
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||||
|
if (auth_level != LEVEL_ADMIN) {
|
||||||
web_interface->WebServer.sendContent_P(NOT_AUTH_STA);
|
web_interface->WebServer.sendContent_P(NOT_AUTH_STA);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//login
|
||||||
|
GeLogin(KeysList, ValuesList,auth_level);
|
||||||
//IP+Web
|
//IP+Web
|
||||||
GetIpWeb(KeysList, ValuesList);
|
GetIpWeb(KeysList, ValuesList);
|
||||||
//mode
|
//mode
|
||||||
@ -1998,11 +2027,15 @@ void handle_web_interface_printer()
|
|||||||
STORESTRINGS_CLASS KeysList ;
|
STORESTRINGS_CLASS KeysList ;
|
||||||
STORESTRINGS_CLASS ValuesList ;
|
STORESTRINGS_CLASS ValuesList ;
|
||||||
|
|
||||||
if (!web_interface->is_authenticated()) {
|
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||||
|
if (auth_level == LEVEL_GUEST) {
|
||||||
web_interface->WebServer.sendContent_P(NOT_AUTH_PRT);
|
web_interface->WebServer.sendContent_P(NOT_AUTH_PRT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//login
|
||||||
|
GeLogin(KeysList, ValuesList,auth_level);
|
||||||
|
|
||||||
//IP+Web
|
//IP+Web
|
||||||
GetIpWeb(KeysList, ValuesList);
|
GetIpWeb(KeysList, ValuesList);
|
||||||
//mode
|
//mode
|
||||||
@ -2069,12 +2102,14 @@ void handle_web_settings()
|
|||||||
int ixy_feedrate,iz_feedrate,ie_feedrate;
|
int ixy_feedrate,iz_feedrate,ie_feedrate;
|
||||||
STORESTRINGS_CLASS KeysList ;
|
STORESTRINGS_CLASS KeysList ;
|
||||||
STORESTRINGS_CLASS ValuesList ;
|
STORESTRINGS_CLASS ValuesList ;
|
||||||
|
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||||
if (!web_interface->is_authenticated()) {
|
if (auth_level != LEVEL_ADMIN) {
|
||||||
web_interface->WebServer.sendContent_P(NOT_AUTH_SET);
|
web_interface->WebServer.sendContent_P(NOT_AUTH_SET);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
web_interface->blockserial = false;
|
web_interface->blockserial = false;
|
||||||
|
//login
|
||||||
|
GeLogin(KeysList, ValuesList,auth_level);
|
||||||
//IP+Web
|
//IP+Web
|
||||||
GetIpWeb(KeysList, ValuesList);
|
GetIpWeb(KeysList, ValuesList);
|
||||||
//mode
|
//mode
|
||||||
@ -2196,6 +2231,7 @@ void handle_web_settings()
|
|||||||
void handle_web_interface_status()
|
void handle_web_interface_status()
|
||||||
{
|
{
|
||||||
static const char NO_TEMP_LINE[] PROGMEM = "\"temperature\":\"0\",\"target\":\"0\",\"active\":\"0\"";
|
static const char NO_TEMP_LINE[] PROGMEM = "\"temperature\":\"0\",\"target\":\"0\",\"active\":\"0\"";
|
||||||
|
//we do not care if need authentication - just reset counter
|
||||||
web_interface->is_authenticated();
|
web_interface->is_authenticated();
|
||||||
Serial.println(F("M114"));
|
Serial.println(F("M114"));
|
||||||
int tagpos,tagpos2;
|
int tagpos,tagpos2;
|
||||||
@ -2699,6 +2735,7 @@ void WebUpdateUpload()
|
|||||||
|
|
||||||
void handleUpdate()
|
void handleUpdate()
|
||||||
{
|
{
|
||||||
|
//upload can be long so better to reset time out
|
||||||
web_interface->is_authenticated();
|
web_interface->is_authenticated();
|
||||||
String jsonfile = "{\"status\":\"" ;
|
String jsonfile = "{\"status\":\"" ;
|
||||||
jsonfile+=intTostr(web_interface->_upload_status);
|
jsonfile+=intTostr(web_interface->_upload_status);
|
||||||
@ -2715,7 +2752,7 @@ void handleUpdate()
|
|||||||
|
|
||||||
void handleFileList()
|
void handleFileList()
|
||||||
{
|
{
|
||||||
if (!web_interface->is_authenticated()) {
|
if (web_interface->is_authenticated() != LEVEL_ADMIN) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String path = "/";
|
String path = "/";
|
||||||
@ -2769,7 +2806,7 @@ void handleFileList()
|
|||||||
|
|
||||||
void handleSDFileList()
|
void handleSDFileList()
|
||||||
{
|
{
|
||||||
if (!web_interface->is_authenticated()) {
|
if (web_interface->is_authenticated() == LEVEL_GUEST) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String jsonfile = "{\"status\":\"" ;
|
String jsonfile = "{\"status\":\"" ;
|
||||||
@ -2810,7 +2847,7 @@ void handle_not_found()
|
|||||||
{
|
{
|
||||||
static const char NOT_AUTH_NF [] PROGMEM = "HTTP/1.1 301 OK\r\nLocation: /HOME\r\nCache-Control: no-cache\r\n\r\n";
|
static const char NOT_AUTH_NF [] PROGMEM = "HTTP/1.1 301 OK\r\nLocation: /HOME\r\nCache-Control: no-cache\r\n\r\n";
|
||||||
|
|
||||||
if (!web_interface->is_authenticated()) {
|
if (web_interface->is_authenticated() == LEVEL_GUEST) {
|
||||||
web_interface->WebServer.sendContent_P(NOT_AUTH_NF);
|
web_interface->WebServer.sendContent_P(NOT_AUTH_NF);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2895,7 +2932,7 @@ void handle_login()
|
|||||||
//USER
|
//USER
|
||||||
sUser = web_interface->WebServer.arg("USER");
|
sUser = web_interface->WebServer.arg("USER");
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
if (sUser!="admin") {
|
if ( !((sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) || (sUser==FPSTR(DEFAULT_USER_LOGIN)))) {
|
||||||
msg_alert_error=true;
|
msg_alert_error=true;
|
||||||
smsg.concat(F("Error : Incorrect User<BR>"));
|
smsg.concat(F("Error : Incorrect User<BR>"));
|
||||||
KeysList.add(FPSTR(KEY_USER_STATUS));
|
KeysList.add(FPSTR(KEY_USER_STATUS));
|
||||||
@ -2903,13 +2940,20 @@ void handle_login()
|
|||||||
}
|
}
|
||||||
//Password
|
//Password
|
||||||
sPassword = web_interface->WebServer.arg("PASSWORD");
|
sPassword = web_interface->WebServer.arg("PASSWORD");
|
||||||
String scurrentPassword;
|
String sadminPassword;
|
||||||
|
|
||||||
if (!CONFIG::read_string(EP_ADMIN_PWD, scurrentPassword , MAX_ADMIN_PASSWORD_LENGTH)) {
|
if (!CONFIG::read_string(EP_ADMIN_PWD, sadminPassword , MAX_LOCAL_PASSWORD_LENGTH)) {
|
||||||
scurrentPassword=FPSTR(DEFAULT_ADMIN);
|
sadminPassword=FPSTR(DEFAULT_ADMIN_PWD);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(sPassword.c_str(),scurrentPassword.c_str())!=0) {
|
String suserPassword;
|
||||||
|
|
||||||
|
if (!CONFIG::read_string(EP_USER_PWD, suserPassword , MAX_LOCAL_PASSWORD_LENGTH)) {
|
||||||
|
suserPassword=FPSTR(DEFAULT_USER_PWD);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(((sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) && (strcmp(sPassword.c_str(),sadminPassword.c_str())==0)) ||
|
||||||
|
((sUser==FPSTR(DEFAULT_USER_LOGIN)) && (strcmp(sPassword.c_str(),suserPassword.c_str()) == 0)))) {
|
||||||
msg_alert_error=true;
|
msg_alert_error=true;
|
||||||
smsg.concat(F("Error: Incorrect password<BR>"));
|
smsg.concat(F("Error: Incorrect password<BR>"));
|
||||||
KeysList.add(FPSTR(KEY_USER_PASSWORD_STATUS));
|
KeysList.add(FPSTR(KEY_USER_PASSWORD_STATUS));
|
||||||
@ -2925,6 +2969,8 @@ void handle_login()
|
|||||||
if (msg_alert_error==false) {
|
if (msg_alert_error==false) {
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
auth_ip * current_auth = new auth_ip;
|
auth_ip * current_auth = new auth_ip;
|
||||||
|
if(sUser==FPSTR(DEFAULT_ADMIN_LOGIN))current_auth->level = LEVEL_ADMIN;
|
||||||
|
else current_auth->level = LEVEL_USER;
|
||||||
current_auth->ip=web_interface->WebServer.client().remoteIP();
|
current_auth->ip=web_interface->WebServer.client().remoteIP();
|
||||||
strcpy(current_auth->sessionID,web_interface->create_session_ID());
|
strcpy(current_auth->sessionID,web_interface->create_session_ID());
|
||||||
current_auth->last_time=millis();
|
current_auth->last_time=millis();
|
||||||
@ -2955,12 +3001,10 @@ void handle_login()
|
|||||||
KeysList.add(FPSTR(KEY_RETURN));
|
KeysList.add(FPSTR(KEY_RETURN));
|
||||||
ValuesList.add(sReturn);
|
ValuesList.add(sReturn);
|
||||||
|
|
||||||
KeysList.add(FPSTR(KEY_DISCONNECT_VISIBILITY));
|
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||||
if (web_interface->is_authenticated()) {
|
//login
|
||||||
ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE));
|
GeLogin(KeysList, ValuesList,auth_level);
|
||||||
} else {
|
|
||||||
ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN));
|
|
||||||
}
|
|
||||||
//IP+Web
|
//IP+Web
|
||||||
GetIpWeb(KeysList, ValuesList);
|
GetIpWeb(KeysList, ValuesList);
|
||||||
//mode
|
//mode
|
||||||
@ -3022,7 +3066,7 @@ void handle_restart()
|
|||||||
|
|
||||||
void handle_web_command()
|
void handle_web_command()
|
||||||
{
|
{
|
||||||
if (!web_interface->is_authenticated()) {
|
if (web_interface->is_authenticated() == LEVEL_GUEST) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//check we have proper parameter
|
//check we have proper parameter
|
||||||
@ -3152,7 +3196,7 @@ char * WEBINTERFACE_CLASS::create_session_ID()
|
|||||||
return sessionID;
|
return sessionID;
|
||||||
}
|
}
|
||||||
//check authentification
|
//check authentification
|
||||||
bool WEBINTERFACE_CLASS::is_authenticated()
|
level_authenticate_type WEBINTERFACE_CLASS::is_authenticated()
|
||||||
{
|
{
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
if (WebServer.hasHeader("Cookie")) {
|
if (WebServer.hasHeader("Cookie")) {
|
||||||
@ -3166,9 +3210,9 @@ bool WEBINTERFACE_CLASS::is_authenticated()
|
|||||||
return ResetAuthIP(ip,sessionID.c_str());
|
return ResetAuthIP(ip,sessionID.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return LEVEL_GUEST;
|
||||||
#else
|
#else
|
||||||
return true;
|
return LEVEL_ADMIN;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3184,9 +3228,8 @@ bool WEBINTERFACE_CLASS::AddAuthIP(auth_ip * item)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WEBINTERFACE_CLASS::ResetAuthIP(IPAddress ip,const char * sessionID)
|
level_authenticate_type WEBINTERFACE_CLASS::ResetAuthIP(IPAddress ip,const char * sessionID)
|
||||||
{
|
{
|
||||||
bool done=false;
|
|
||||||
auth_ip * current = _head;
|
auth_ip * current = _head;
|
||||||
auth_ip * previous = NULL;
|
auth_ip * previous = NULL;
|
||||||
//get time
|
//get time
|
||||||
@ -3210,14 +3253,14 @@ bool WEBINTERFACE_CLASS::ResetAuthIP(IPAddress ip,const char * sessionID)
|
|||||||
if (strcmp(sessionID,current->sessionID)==0) {
|
if (strcmp(sessionID,current->sessionID)==0) {
|
||||||
//reset time
|
//reset time
|
||||||
current->last_time=millis();
|
current->last_time=millis();
|
||||||
return true;
|
return current->level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
previous = current;
|
previous = current;
|
||||||
current=current->_next;
|
current=current->_next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return done;
|
return LEVEL_GUEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
WEBINTERFACE_CLASS * web_interface;
|
WEBINTERFACE_CLASS * web_interface;
|
||||||
|
@ -29,8 +29,15 @@
|
|||||||
|
|
||||||
#define MAX_EXTRUDERS 4
|
#define MAX_EXTRUDERS 4
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
LEVEL_GUEST = 0,
|
||||||
|
LEVEL_USER = 1,
|
||||||
|
LEVEL_ADMIN = 2
|
||||||
|
} level_authenticate_type;
|
||||||
|
|
||||||
struct auth_ip {
|
struct auth_ip {
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
|
level_authenticate_type level;
|
||||||
char sessionID[17];
|
char sessionID[17];
|
||||||
uint32_t last_time;
|
uint32_t last_time;
|
||||||
auth_ip * _next;
|
auth_ip * _next;
|
||||||
@ -45,7 +52,7 @@ public:
|
|||||||
File fsUploadFile;
|
File fsUploadFile;
|
||||||
bool isSSIDValid(const char * ssid);
|
bool isSSIDValid(const char * ssid);
|
||||||
bool isPasswordValid(const char * password);
|
bool isPasswordValid(const char * password);
|
||||||
bool isAdminPasswordValid(const char * password);
|
bool isLocalPasswordValid(const char * password);
|
||||||
bool isHostnameValid(const char * hostname);
|
bool isHostnameValid(const char * hostname);
|
||||||
bool isIPValid(const char * IP);
|
bool isIPValid(const char * IP);
|
||||||
String answer4M105;
|
String answer4M105;
|
||||||
@ -59,10 +66,10 @@ public:
|
|||||||
STORESTRINGS_CLASS status_msg;
|
STORESTRINGS_CLASS status_msg;
|
||||||
bool restartmodule;
|
bool restartmodule;
|
||||||
char * create_session_ID();
|
char * create_session_ID();
|
||||||
bool is_authenticated();
|
level_authenticate_type is_authenticated();
|
||||||
bool AddAuthIP(auth_ip * item);
|
bool AddAuthIP(auth_ip * item);
|
||||||
bool blockserial;
|
bool blockserial;
|
||||||
bool ResetAuthIP(IPAddress ip,const char * sessionID);
|
level_authenticate_type ResetAuthIP(IPAddress ip,const char * sessionID);
|
||||||
uint8_t _upload_status;
|
uint8_t _upload_status;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user