ESP3D Lib  1.0
3D Printer WiFi Library
web_server.h
Go to the documentation of this file.
1 /*
2  web_server.h - wifi services 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 #ifndef _WEB_SERVER_H
23 #define _WEB_SERVER_H
24 
25 
26 #include "wificonfig.h"
27 class WebSocketsServer;
28 class WebServer;
29 
30 //Authentication level
31 typedef enum {
36 
37 #ifdef ENABLE_AUTHENTICATION
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 
47 #endif
48 
49 
50 
51 
53  public:
54  void print(const char *data);
55  void println(const char *data);
56  void flush();
57  ESPResponseStream(WebServer * webserver);
58  private:
59  bool _header_sent;
60  WebServer * _webserver;
61  String _buffer;
62 };
63 
64 class Web_Server {
65  public:
66  Web_Server();
67  ~Web_Server();
68  bool begin();
69  void end();
70  static void handle();
71  static long get_client_ID();
72  private:
73  static bool _setupdone;
74  static WebServer * _webserver;
75  static long _id_connection;
76  static WebSocketsServer * _socket_server;
77  static uint16_t _port;
78  static uint16_t _data_port;
79  static String _hostname;
80  static uint8_t _upload_status;
81  static char * mac2str (uint8_t mac [8]);
82  static String formatBytes (uint32_t bytes);
83  static String getContentType (String filename);
84  static String get_Splited_Value(String data, char separator, int index);
85  static level_authenticate_type is_authenticated();
86 #ifdef ENABLE_AUTHENTICATION
87  static auth_ip * _head;
88  static uint8_t _nb_ip;
89  static bool AddAuthIP (auth_ip * item);
90  static char * create_session_ID();
91  static bool ClearAuthIP (IPAddress ip, const char * sessionID);
92  static auth_ip * GetAuth (IPAddress ip, const char * sessionID);
93  static level_authenticate_type ResetAuthIP (IPAddress ip, const char * sessionID);
94  static bool isLocalPasswordValid (const char * password);
95 #endif
96  static String get_param (String & cmd_params, const char * id, bool withspace);
97  static bool execute_internal_command (int cmd, String cmd_params, level_authenticate_type auth_level, ESPResponseStream *espresponse);
98 #ifdef ENABLE_SSDP
99  static void handle_SSDP ();
100 #endif
101  static void handle_root();
102  static void handle_login();
103  static void handle_not_found ();
104  static void handle_web_command ();
105  static void handle_web_command_silent ();
106  static void handle_Websocket_Event(uint8_t num, uint8_t type, uint8_t * payload, size_t length);
107  static void SPIFFSFileupload ();
108  static void handleFileList ();
109  static void handleUpdate ();
110  static void WebUpdateUpload ();
111 #if ENABLED(SDSUPPORT)
112  static void handle_direct_SDFileList();
113  static void SDFile_direct_upload();
114 #endif
115 };
116 
117 extern Web_Server web_server;
118 
119 #endif
120 
Web_Server::Web_Server
Web_Server()
level_authenticate_type
level_authenticate_type
Definition: web_server.h:31
LEVEL_GUEST
@ LEVEL_GUEST
Definition: web_server.h:32
Web_Server::handle
static void handle()
ESPResponseStream
Definition: web_server.h:52
Web_Server::begin
bool begin()
Web_Server::~Web_Server
~Web_Server()
Web_Server::end
void end()
LEVEL_ADMIN
@ LEVEL_ADMIN
Definition: web_server.h:34
LEVEL_USER
@ LEVEL_USER
Definition: web_server.h:33
ESPResponseStream::print
void print(const char *data)
Web_Server
Definition: web_server.h:64
ESPResponseStream::flush
void flush()
ESPResponseStream::ESPResponseStream
ESPResponseStream(WebServer *webserver)
Web_Server::get_client_ID
static long get_client_ID()
wificonfig.h
ESPResponseStream::println
void println(const char *data)
web_server
Web_Server web_server