forked from gmag11/FSBrowserNG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFSWebServerLib.h
140 lines (113 loc) · 4.25 KB
/
FSWebServerLib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// FSWebServerLib.h
#ifndef _FSWEBSERVERLIB_h
#define _FSWEBSERVERLIB_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <TimeLib.h>
#include <NtpClientLib.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ESP8266mDNS.h>
#include <FS.h>
#include <Ticker.h>
#include <ArduinoOTA.h>
#include <ArduinoJson.h>
#define RELEASE // Comment to enable debug output
#define DBG_OUTPUT_PORT Serial
#ifndef RELEASE
#define DEBUGLOG(...) DBG_OUTPUT_PORT.printf(__VA_ARGS__)
#else
#define DEBUGLOG(...)
#endif
#define CONNECTION_LED 2 // Connection LED pin (Built in). -1 to disable
#define AP_ENABLE_BUTTON 4 // Button pin to enable AP during startup for configuration. -1 to disable
#define CONFIG_FILE "/config.json"
#define SECRET_FILE "/secret.json"
typedef struct {
String ssid;
String password;
IPAddress ip;
IPAddress netmask;
IPAddress gateway;
IPAddress dns;
bool dhcp;
String ntpServerName;
long updateNTPTimeEvery;
long timezone;
bool daylight;
String deviceName;
} strConfig;
typedef struct {
String APssid = "ESP"; // ChipID is appended to this name
String APpassword = "12345678";
bool APenable = false; // AP disabled by default
} strApConfig;
typedef struct {
bool auth;
String wwwUsername;
String wwwPassword;
} strHTTPAuth;
class AsyncFSWebServer : public AsyncWebServer {
public:
AsyncFSWebServer(uint16_t port);
void begin(FS* fs);
void handle();
protected:
strConfig _config; // General and WiFi configuration
strApConfig _apConfig; // Static AP config settings
strHTTPAuth _httpAuth;
FS* _fs;
long wifiDisconnectedSince = 0;
String _browserMD5 = "";
uint32_t _updateSize = 0;
WiFiEventHandler onStationModeConnectedHandler, onStationModeDisconnectedHandler;
//uint currentWifiStatus;
Ticker _secondTk;
bool _secondFlag;
AsyncEventSource _evs = AsyncEventSource("/events");
void sendTimeData();
bool load_config();
void defaultConfig();
bool save_config();
bool loadHTTPAuth();
bool saveHTTPAuth();
void configureWifiAP();
void configureWifi();
void ConfigureOTA(String password);
void serverInit();
void onWiFiConnected(WiFiEventStationModeConnected data);
void onWiFiDisconnected(WiFiEventStationModeDisconnected data);
static void s_secondTick(void* arg);
String getMacAddress();
bool checkAuth(AsyncWebServerRequest *request);
void handleFileList(AsyncWebServerRequest *request);
//void handleFileRead_edit_html(AsyncWebServerRequest *request);
bool handleFileRead(String path, AsyncWebServerRequest *request);
void handleFileCreate(AsyncWebServerRequest *request);
void handleFileDelete(AsyncWebServerRequest *request);
void handleFileUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
void send_general_configuration_values_html(AsyncWebServerRequest *request);
void send_network_configuration_values_html(AsyncWebServerRequest *request);
void send_connection_state_values_html(AsyncWebServerRequest *request);
void send_information_values_html(AsyncWebServerRequest *request);
void send_NTP_configuration_values_html(AsyncWebServerRequest *request);
void send_network_configuration_html(AsyncWebServerRequest *request);
void send_general_configuration_html(AsyncWebServerRequest *request);
void send_NTP_configuration_html(AsyncWebServerRequest *request);
void restart_esp(AsyncWebServerRequest *request);
void send_wwwauth_configuration_values_html(AsyncWebServerRequest *request);
void send_wwwauth_configuration_html(AsyncWebServerRequest *request);
void send_update_firmware_values_html(AsyncWebServerRequest *request);
void setUpdateMD5(AsyncWebServerRequest *request);
void updateFirmware(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
static String urldecode(String input); // (based on https://code.google.com/p/avr-netino/)
static unsigned char h2int(char c);
static boolean checkRange(String Value);
};
extern AsyncFSWebServer ESPHTTPServer;
#endif // _FSWEBSERVERLIB_h