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];
21constexpr size_t REDACTED_LOG_VALUE_BUFFER_SIZE = 32;
22
23bool isSensitiveLogField(const char *key);
24const char *redactLogValue(const char *key,
25 const char *value,
26 char *buffer,
27 size_t bufferSize);
28
29class WebServer {
30 public:
31 enum class WebServerMode {
32 HttpOnly,
33 HttpsOnly,
34 Auto,
35 };
36
37 static WebServer *Instance();
39 virtual ~WebServer();
40 virtual void start() = 0;
41 virtual void stop() = 0;
42 virtual void setWebServerMode(WebServerMode mode);
43 virtual WebServerMode getWebServerMode() const;
44 virtual WebServerMode resolveWebServerMode() const;
45 void setSuplaDeviceClass(SuplaDeviceClass *);
46 void notifyClientConnected(bool isPost = false);
47 virtual void parsePost(const char *postContent,
48 int size,
49 bool lastChunk = true);
50 virtual void resetParser();
51 const char *getCsrfToken();
52 bool isCsrfTokenValid(const char *token);
53 void setBetaProcessing();
54 void setCsrfFirstFieldRequired(bool required);
55 void addLastStateLog(const char *log) const;
56
57 virtual bool verifyEmbeddedHttpsCertificates();
58
59 Supla::HtmlGenerator *htmlGenerator = nullptr;
60
61 protected:
62 void addSecurityLog(Supla::SecurityLogSource source, const char *log) const;
63 void addSecurityLog(uint32_t source, const char *log) const;
72 bool isSectionAllowed(Supla::HtmlSection section) const;
73 void cleanupParser();
74
75 static WebServer *webServerInstance;
76 bool destroyGenerator = false;
77 SuplaDeviceClass *sdc = nullptr;
78 bool keyFound = false;
79 int partialSize = 0;
80 char key[HTML_KEY_LENGTH] = {};
81 char *value = nullptr;
82 bool betaProcessing = false;
83 bool csrfFirstFieldRequired = true;
84 bool csrfValidated = false;
85 bool csrfRejected = false;
86 uint8_t pendingReboot = 0;
87 uint8_t csrfSecret[16] = {};
88 char csrfToken[33] = {};
89};
90
91}; // namespace Supla
92
93#endif // SRC_SUPLA_NETWORK_WEB_SERVER_H_
Definition SuplaDevice.h:167
Definition html_generator.h:20
Definition web_server.h:29
bool isSectionAllowed(Supla::HtmlSection section) const
Check if section is allowed in current POST request.
Definition web_server.cpp:406