supla-device
Toggle main menu visibility
Loading...
Searching...
No Matches
src
supla
network
web_server.h
1
/*
2
Copyright (C) AC SOFTWARE SP. Z O.O.
3
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
*/
18
19
#ifndef SRC_SUPLA_NETWORK_WEB_SERVER_H_
20
#define SRC_SUPLA_NETWORK_WEB_SERVER_H_
21
22
#include <stddef.h>
23
#include <supla/network/html_generator.h>
24
#include <supla/network/html_element.h>
25
#include <supla/device/security_logger.h>
26
#include <stdint.h>
27
28
class
SuplaDeviceClass
;
29
30
#define HTML_KEY_LENGTH 16
31
#define HTML_VAL_LENGTH 4000
32
33
namespace
Supla {
34
35
extern
const
unsigned
char
favico[1150];
36
constexpr
size_t
REDACTED_LOG_VALUE_BUFFER_SIZE = 32;
37
38
bool
isSensitiveLogField(
const
char
*key);
39
const
char
*redactLogValue(
const
char
*key,
40
const
char
*value,
41
char
*buffer,
42
size_t
bufferSize);
43
44
class
WebServer {
45
public
:
46
enum class
WebServerMode {
47
HttpOnly,
48
HttpsOnly,
49
Auto,
50
};
51
52
static
WebServer *Instance();
53
explicit
WebServer(
Supla::HtmlGenerator
*);
54
virtual
~WebServer();
55
virtual
void
start() = 0;
56
virtual
void
stop() = 0;
57
virtual
void
setWebServerMode(WebServerMode mode);
58
virtual
WebServerMode getWebServerMode()
const
;
59
virtual
WebServerMode resolveWebServerMode()
const
;
60
void
setSuplaDeviceClass(
SuplaDeviceClass
*);
61
void
notifyClientConnected(
bool
isPost =
false
);
62
virtual
void
parsePost(
const
char
*postContent,
63
int
size,
64
bool
lastChunk =
true
);
65
virtual
void
resetParser();
66
const
char
*getCsrfToken();
67
bool
isCsrfTokenValid(
const
char
*token);
68
void
setBetaProcessing();
69
void
setCsrfFirstFieldRequired(
bool
required);
70
71
virtual
bool
verifyEmbeddedHttpsCertificates();
72
73
Supla::HtmlGenerator
*htmlGenerator =
nullptr
;
74
75
protected
:
76
void
addSecurityLog(Supla::SecurityLogSource source,
const
char
*log)
const
;
77
void
addSecurityLog(uint32_t source,
const
char
*log)
const
;
86
bool
isSectionAllowed
(Supla::HtmlSection section)
const
;
87
void
cleanupParser();
88
89
static
WebServer *webServerInstance;
90
bool
destroyGenerator =
false
;
91
SuplaDeviceClass
*sdc =
nullptr
;
92
bool
keyFound =
false
;
93
int
partialSize = 0;
94
char
key[HTML_KEY_LENGTH] = {};
95
char
*value =
nullptr
;
96
bool
betaProcessing =
false
;
97
bool
csrfFirstFieldRequired =
true
;
98
bool
csrfValidated =
false
;
99
bool
csrfRejected =
false
;
100
uint8_t csrfSecret[16] = {};
101
char
csrfToken[33] = {};
102
};
103
104
};
// namespace Supla
105
106
#endif
// SRC_SUPLA_NETWORK_WEB_SERVER_H_
SuplaDeviceClass
Definition
SuplaDevice.h:163
Supla::HtmlGenerator
Definition
html_generator.h:35
Supla::WebServer::isSectionAllowed
bool isSectionAllowed(Supla::HtmlSection section) const
Check if section is allowed in current POST request.
Definition
web_server.cpp:407
Generated by
1.17.0