ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
authentication_service.h
Go to the documentation of this file.
1 /*
2  authentication_service.h - authentication functions class
3 
4  Copyright (c) 2014 Luc Lebosse. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 
22 
23 #ifndef _AUTHENTICATION_SERVICE_H
24 #define _AUTHENTICATION_SERVICE_H
25 typedef enum {
30 
31 const char DEFAULT_ADMIN_LOGIN [] = "admin";
32 const char DEFAULT_USER_LOGIN [] = "user";
33 
34 #include "../../include/esp3d_config.h"
35 #if defined (AUTHENTICATION_FEATURE)
36 #if defined (HTTP_FEATURE)
37 #include <IPAddress.h>
38 struct auth_ip {
39  IPAddress ip;
41  char userID[17];
42  char sessionID[17];
43  uint32_t last_time;
44  auth_ip * _next;
45 };
46 #if defined (ARDUINO_ARCH_ESP32)
47 class WebServer;
48 typedef WebServer Authwebserver;
49 #endif //ARDUINO_ARCH_ESP32
50 #if defined (ARDUINO_ARCH_ESP8266)
51 #include <ESP8266WebServer.h>
52 typedef ESP8266WebServer Authwebserver;
53 #endif //ARDUINO_ARCH_ESP8266
54 #else
55 typedef void Authwebserver;
56 #endif // HTTP_FEATURE
57 #endif //AUTHENTICATION_FEATURE
59 {
60 public:
63  static level_authenticate_type authenticated_level(const char * pwd = nullptr);
64 #ifdef AUTHENTICATION_FEATURE
65  static bool begin(Authwebserver * webserver);
66  static void end();
67  static void handle();
68  static bool isadmin (const char *pwd);
69  static void update();
70  static bool isuser (const char *pwd);
71 #if defined (HTTP_FEATURE)
72  static uint32_t setSessionTimeout(uint32_t timeout);
73  static uint32_t getSessionTimeout();
74  static char * create_session_ID();
75  static bool ClearCurrentSession ();
76  static bool ClearAllSessions ();
77  static bool CreateSession(level_authenticate_type auth_level, const char * username, const char* session_ID);
78 #endif //HTTP_FEATURE
79 private:
80  static String _adminpwd;
81  static String _userpwd;
82 #if defined (HTTP_FEATURE)
83  static bool AddAuthIP (auth_ip * item);
84  static bool ClearAuthIP (IPAddress ip, const char * sessionID);
85  static auth_ip * GetAuth (IPAddress ip, const char * sessionID);
86  static level_authenticate_type ResetAuthIP (IPAddress ip, const char * sessionID);
87  static Authwebserver * _webserver;
88  static uint32_t _sessionTimeout;
89  static auth_ip * _head;
90  static uint8_t _current_nb_ip;
91 #endif //HTTP_FEATURE
92 #endif //AUTHENTICATION_FEATURE
93 };
94 
95 #endif //_ESP3DSECURITY_H
96 
AuthenticationService::AuthenticationService
AuthenticationService()
Definition: authentication_service.cpp:50
AuthenticationService::~AuthenticationService
~AuthenticationService()
Definition: authentication_service.cpp:53
AuthenticationService::authenticated_level
static level_authenticate_type authenticated_level(const char *pwd=nullptr)
Definition: authentication_service.cpp:61
DEFAULT_USER_LOGIN
const char DEFAULT_USER_LOGIN[]
Definition: authentication_service.h:32
LEVEL_GUEST
@ LEVEL_GUEST
Definition: authentication_service.h:26
AuthenticationService
Definition: authentication_service.h:58
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
DEFAULT_ADMIN_LOGIN
const char DEFAULT_ADMIN_LOGIN[]
Definition: authentication_service.h:31
LEVEL_ADMIN
@ LEVEL_ADMIN
Definition: authentication_service.h:28
LEVEL_USER
@ LEVEL_USER
Definition: authentication_service.h:27