supla-device
Loading...
Searching...
No Matches
web_server.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_NETWORK_WEB_SERVER_H_
5#define SRC_SUPLA_NETWORK_WEB_SERVER_H_
6
7#include <stddef.h>
8#include <supla/network/html_generator.h>
9#include <supla/network/html_element.h>
10#include <supla/device/security_logger.h>
11#include <stdint.h>
12
14
15#define HTML_KEY_LENGTH 16
16#define HTML_VAL_LENGTH 4000
17
18namespace Supla {
19
20extern const unsigned char favico[1150];
21// 20 decimal digits for a 64-bit size_t, plus the wrapper and terminating NUL.
22constexpr size_t REDACTED_LOG_VALUE_BUFFER_SIZE = 36;
23
24bool isSensitiveLogField(const char *key);
25const char *redactLogValue(const char *key,
26 const char *value,
27 char *buffer,
28 size_t bufferSize);
29
30class WebServer {
31 public:
32 enum class WebServerMode {
33 HttpOnly,
34 HttpsOnly,
35 Auto,
36 };
37
38 static WebServer *Instance();
40 virtual ~WebServer();
41 virtual void start() = 0;
42 virtual void stop() = 0;
43 virtual void setWebServerMode(WebServerMode mode);
44 virtual WebServerMode getWebServerMode() const;
45 virtual WebServerMode resolveWebServerMode() const;
46 void setSuplaDeviceClass(SuplaDeviceClass *);
47 void notifyClientConnected(bool isPost = false);
48 virtual void parsePost(const char *postContent,
49 int size,
50 bool lastChunk = true);
51 virtual void resetParser();
52 const char *getCsrfToken();
53 bool isCsrfTokenValid(const char *token);
54 void setBetaProcessing();
55 void setCsrfFirstFieldRequired(bool required);
56 void addLastStateLog(const char *log) const;
57
58 virtual bool verifyEmbeddedHttpsCertificates();
59
60 Supla::HtmlGenerator *htmlGenerator = nullptr;
61
62 protected:
63 void addSecurityLog(Supla::SecurityLogSource source, const char *log) const;
64 void addSecurityLog(uint32_t source, const char *log) const;
73 bool isSectionAllowed(Supla::HtmlSection section) const;
74 void cleanupParser();
75
76 static WebServer *webServerInstance;
77 bool destroyGenerator = false;
78 SuplaDeviceClass *sdc = nullptr;
79 bool keyFound = false;
80 int partialSize = 0;
81 char key[HTML_KEY_LENGTH] = {};
82 char *value = nullptr;
83 bool betaProcessing = false;
84 bool csrfFirstFieldRequired = true;
85 bool csrfValidated = false;
86 bool csrfRejected = false;
87 uint8_t pendingReboot = 0;
88 uint8_t csrfSecret[16] = {};
89 char csrfToken[33] = {};
90};
91
92}; // namespace Supla
93
94#endif // SRC_SUPLA_NETWORK_WEB_SERVER_H_
Definition SuplaDevice.h:167
Definition html_generator.h:20
Definition web_server.h:30
bool isSectionAllowed(Supla::HtmlSection section) const
Check if section is allowed in current POST request.
Definition web_server.cpp:409