From 308c80bc5ab5c8f5e2011d49c86f4ee42ef6e695 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 28 May 2020 23:59:52 +0200 Subject: [PATCH] Add PHP support in Pi-hole' HTTP server. Signed-off-by: DL6ER --- src/api/http-common.c | 3 +++ src/civetweb/CMakeLists.txt | 3 +-- src/config.c | 11 +++++++++++ src/config.h | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/api/http-common.c b/src/api/http-common.c index 440459e1..b9df1d07 100644 --- a/src/api/http-common.c +++ b/src/api/http-common.c @@ -324,6 +324,9 @@ void http_init(void) "X-Xss-Protection: 1; mode=block\r\n" "X-Content-Type-Options: nosniff\r\n" "Referrer-Policy: same-origin", + "cgi_interpreter", httpsettings.php_location, + "cgi_pattern", "**.php$", // ** allows the files to by anywhere inside the web root + "index_files", "index.html,index.htm,index.php", NULL }; diff --git a/src/civetweb/CMakeLists.txt b/src/civetweb/CMakeLists.txt index 672f8caa..139f33b7 100644 --- a/src/civetweb/CMakeLists.txt +++ b/src/civetweb/CMakeLists.txt @@ -14,7 +14,6 @@ set(sources ) # We can remove the NO_SSL later on. It adds additional constraints to the build system (availablity of libSSL-dev) -# NO_CGI = no CGI support (we don't need it) # NO_SSL_DL NO_SSL = no SSL support (for now) # USE_SERVER_STATS = makes a few anonymous statistics available, such as # - Number of connections (currently and total) @@ -26,5 +25,5 @@ set(CIVETWEB_OPTS add_library(civetweb OBJECT ${sources}) -target_compile_definitions(civetweb PRIVATE NO_CGI NO_SSL_DL NO_SSL USE_SERVER_STATS USE_IPV6) +target_compile_definitions(civetweb PRIVATE NO_SSL_DL NO_SSL USE_SERVER_STATS USE_IPV6) target_include_directories(civetweb PRIVATE ${PROJECT_SOURCE_DIR}/src) diff --git a/src/config.c b/src/config.c index ae72feba..9a767eae 100644 --- a/src/config.c +++ b/src/config.c @@ -448,6 +448,17 @@ void read_FTLconf(void) else logg(" API_PRETTY_JSON: Disabled. Compact API output."); + // PHP-CGI + // defaults to: /usr/bin/php-cgi + // Path to an executable to use as CGI interpreter for all CGI scripts + // regardless of the script file extension. We use this for PHP. It + // needs to point at php-cgi. php-cli will not work + httpsettings.php_location = "/usr/bin/php-cgi"; + buffer = parse_FTLconf(fp, "PHP.CGI"); + if(buffer != NULL) + httpsettings.php_location = strdup(buffer); + logg(" PHP-CGI: Using %s", httpsettings.php_location); + // Read DEBUG_... setting from pihole-FTL.conf // This option should be the last one as it causes // some rather verbose output into the log when diff --git a/src/config.h b/src/config.h index ed52edf8..3b7fbb9d 100644 --- a/src/config.h +++ b/src/config.h @@ -56,6 +56,7 @@ typedef struct { typedef struct httpsettings { char *webroot; char *webhome; + const char *php_location; const char *acl; bool api_auth_for_localhost; bool prettyJSON;