Apply Pi-hole CivetWeb patches

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2023-04-11 12:23:52 +02:00
parent 9bda9f4cd6
commit db0157451f
8 changed files with 92 additions and 19 deletions
+2
View File
@@ -3,3 +3,5 @@ set -e
patch -p1 < patch/civetweb/0001-add-pihole-mods.patch
patch -p1 < patch/civetweb/0001-Add-NO_DLOPEN-option-to-civetweb-s-LUA-routines.patch
echo "ALL PATCHES APPLIED OKAY"
@@ -5,13 +5,13 @@ Subject: [PATCH] Add NO_DLOPEN option to civetweb's LUA routines
Signed-off-by: DL6ER <dl6er@dl6er.de>
---
src/civetweb/mod_lua.inl | 4 ++--
src/webserver/civetweb/mod_lua.inl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/civetweb/mod_lua.inl b/src/civetweb/mod_lua.inl
diff --git a/src/webserver/civetweb/mod_lua.inl b/src/webserver/civetweb/mod_lua.inl
index 5cc94318..59c4f2b3 100644
--- a/src/civetweb/mod_lua.inl
+++ b/src/civetweb/mod_lua.inl
--- a/src/webserver/civetweb/mod_lua.inl
+++ b/src/webserver/civetweb/mod_lua.inl
@@ -3634,7 +3634,7 @@ lua_init_optional_libraries(void)
lua_shared_init();
+14 -13
View File
@@ -5,14 +5,14 @@ Subject: [PATCH] Add Pi-hole specific method to send HTTP headers
Signed-off-by: DL6ER <dl6er@dl6er.de>
---
src/civetweb/civetweb.c | 53 +++++++++++++++++++++++++++++++++++++++++
src/civetweb/civetweb.h | 11 +++++++++
src/webserver/civetweb/civetweb.c | 53 +++++++++++++++++++++++++++++++++++++++++
src/webserver/civetweb/civetweb.h | 11 +++++++++
2 files changed, 64 insertions(+)
diff --git a/src/civetweb/civetweb.c b/src/civetweb/civetweb.c
diff --git a/src/webserver/civetweb/civetweb.c b/src/webserver/civetweb/civetweb.c
index 81f642be..ed360a76 100644
--- a/src/civetweb/civetweb.c
+++ b/src/civetweb/civetweb.c
--- a/src/webserver/civetweb/civetweb.c
+++ b/src/webserver/civetweb/civetweb.c
@@ -4135,6 +4135,14 @@ send_additional_header(struct mg_connection *conn)
if (header && header[0]) {
mg_response_header_add_lines(conn, header);
@@ -28,14 +28,15 @@ index 81f642be..ed360a76 100644
}
@@ -4530,6 +4538,47 @@ mg_send_http_error_impl(struct mg_connection *conn,
@@ -4530,6 +4538,48 @@ mg_send_http_error_impl(struct mg_connection *conn,
}
+/************************************** Pi-hole method **************************************/
+int my_send_http_error_headers(struct mg_connection *conn,
+ int status, const char* mime_type,
+ long long content_length)
+CIVETWEB_API int
+my_send_http_error_headers(struct mg_connection *conn,
+ int status, const char* mime_type,
+ long long content_length)
+{
+ if ((mime_type == NULL) || (*mime_type == 0)) {
+ /* No content type defined: default to text/html */
@@ -73,7 +74,7 @@ index 81f642be..ed360a76 100644
+}
+/********************************************************************************************/
+
int
CIVETWEB_API int
mg_send_http_error(struct mg_connection *conn, int status, const char *fmt, ...)
{
@@ -10649,6 +10649,10 @@ parse_http_request(char *buf, int len, struct mg_request_info *ri)
@@ -87,10 +88,10 @@ index 81f642be..ed360a76 100644
/* RFC says that all initial whitespaces should be ignored */
/* This included all leading \r and \n (isspace) */
/* See table: http://www.cplusplus.com/reference/cctype/ */
diff --git a/src/civetweb/civetweb.h b/src/civetweb/civetweb.h
diff --git a/src/webserver/civetweb/civetweb.h b/src/webserver/civetweb/civetweb.h
index 7ea45fb2..f879ff3e 100644
--- a/src/civetweb/civetweb.h
+++ b/src/civetweb/civetweb.h
--- a/src/webserver/civetweb/civetweb.h
+++ b/src/webserver/civetweb/civetweb.h
@@ -186,6 +186,8 @@ struct mg_request_info {
const char *acceptedWebSocketSubprotocol; /* websocket subprotocol,
+2
View File
@@ -2,3 +2,5 @@
set -e
patch -p1 < patch/lua/0001-add-pihole-library.patch
echo "ALL PATCHES APPLIED OKAY"
+2
View File
@@ -3,3 +3,5 @@ set -e
patch -p1 < patch/sqlite3/0001-print-FTL-version-in-interactive-shell.patch
patch -p1 < patch/sqlite3/0002-make-sqlite3ErrName-public.patch
echo "ALL PATCHES APPLIED OKAY"
+54
View File
@@ -4142,6 +4142,14 @@ send_additional_header(struct mg_connection *conn)
if (header && header[0]) {
mg_response_header_add_lines(conn, header);
}
/*************** Pi-hole modification ****************/
if (pi_hole_extra_headers[0] != '\0') {
mg_response_header_add_lines(conn, pi_hole_extra_headers);
// Invalidate extra headers after having sent them to avoid repetitions
pi_hole_extra_headers[0] = '\0';
}
/*****************************************************/
}
@@ -4558,6 +4566,48 @@ mg_send_http_error_impl(struct mg_connection *conn,
}
/************************************** Pi-hole method **************************************/
CIVETWEB_API int
my_send_http_error_headers(struct mg_connection *conn,
int status, const char* mime_type,
long long content_length)
{
if ((mime_type == NULL) || (*mime_type == 0)) {
/* No content type defined: default to text/html */
mime_type = "text/html";
}
mg_response_header_start(conn, status);
send_no_cache_header(conn);
send_additional_header(conn);
mg_response_header_add(conn, "Content-Type", mime_type, -1);
if (content_length < 0) {
/* Size not known. Use chunked encoding (HTTP/1.x) */
if (conn->protocol_type == PROTOCOL_TYPE_HTTP1) {
/* Only HTTP/1.x defines "chunked" encoding, HTTP/2 does not*/
mg_response_header_add(conn, "Transfer-Encoding", "chunked", -1);
}
} else {
char len[32];
int trunc = 0;
mg_snprintf(conn,
&trunc,
len,
sizeof(len),
"%" UINT64_FMT,
(uint64_t)content_length);
if (!trunc) {
/* Since 32 bytes is enough to hold any 64 bit decimal number,
* !trunc is always true */
mg_response_header_add(conn, "Content-Length", len, -1);
}
}
mg_response_header_send(conn);
return 0;
}
/********************************************************************************************/
CIVETWEB_API int
mg_send_http_error(struct mg_connection *conn, int status, const char *fmt, ...)
{
@@ -10923,6 +10973,10 @@ parse_http_request(char *buf, int len, struct mg_request_info *ri)
NULL;
ri->num_headers = 0;
/******************** Pi-hole modification ********************/
strncpy(ri->raw_http_head, buf, sizeof(ri->raw_http_head));
/**************************************************************/
/* RFC says that all initial whitespaces should be ignored */
/* This included all leading \r and \n (isspace) */
/* See table: http://www.cplusplus.com/reference/cctype/ */
+12
View File
@@ -183,6 +183,8 @@ struct mg_request_info {
const char *acceptedWebSocketSubprotocol; /* websocket subprotocol,
* accepted during handshake */
// Pi-hole modification
char raw_http_head[16384];
};
@@ -928,6 +930,16 @@ CIVETWEB_API int mg_send_http_error(struct mg_connection *conn,
PRINTF_FORMAT_STRING(const char *fmt),
...) PRINTF_ARGS(3, 4);
/************************************** Pi-hole method **************************************/
int my_send_http_error_headers(struct mg_connection *conn,
int status, const char* mime_type,
long long content_length);
// Buffer used for additional "Set-Cookie" headers
#define PIHOLE_HEADERS_MAXLEN 1024
extern char pi_hole_extra_headers[PIHOLE_HEADERS_MAXLEN];
/********************************************************************************************/
/* Send "HTTP 200 OK" response header.
* After calling this function, use mg_write or mg_send_chunk to send the
+2 -2
View File
@@ -3664,7 +3664,7 @@ lua_init_optional_libraries(void)
lua_shared_init();
/* UUID library */
#if !defined(_WIN32)
#if !defined(_WIN32) && !defined(NO_DLOPEN)
lib_handle_uuid = dlopen("libuuid.so", RTLD_LAZY);
pf_uuid_generate.p =
(lib_handle_uuid ? dlsym(lib_handle_uuid, "uuid_generate") : 0);
@@ -3678,7 +3678,7 @@ static void
lua_exit_optional_libraries(void)
{
/* UUID library */
#if !defined(_WIN32)
#if !defined(_WIN32) && !defined(NO_DLOPEN)
if (lib_handle_uuid) {
dlclose(lib_handle_uuid);
}