From c1ba05c26abf5ea84f903a21ad9fbd84b3ebceea Mon Sep 17 00:00:00 2001 From: Czarek Tomczak Date: Fri, 13 Feb 2015 12:12:07 +0100 Subject: [PATCH] Branch 2171. Added the web server "hide_files" option in settings.json (Issue 17). Updated version to 39.2. --- phpdesktop-chrome-cef2171/mongoose.c | 11 ++++++++--- phpdesktop-chrome-cef2171/resource.rc | 10 +++++----- phpdesktop-chrome-cef2171/settings.json | 3 ++- phpdesktop-chrome-cef2171/web_server.cpp | 22 ++++++++++++++++++---- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/phpdesktop-chrome-cef2171/mongoose.c b/phpdesktop-chrome-cef2171/mongoose.c index 3e45a30..abe1f75 100644 --- a/phpdesktop-chrome-cef2171/mongoose.c +++ b/phpdesktop-chrome-cef2171/mongoose.c @@ -2773,15 +2773,20 @@ static int scan_directory(struct mg_connection *conn, const char *dir, de.conn = conn; while ((dp = readdir(dirp)) != NULL) { + // PHP Desktop fix (Issue 17): + // In handle_request() a full path is passed to must_hide_file. But + // when scanning directory only directory name was passed. This causes + // problems with hide_files_patterns. Fix it by providing full directory + // path to must_hide_file(). + mg_snprintf(conn, path, sizeof(path), "%s%c%s", dir, '/', dp->d_name); + // Do not show current dir and hidden files if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..") || - must_hide_file(conn, dp->d_name)) { + must_hide_file(conn, path)) { continue; } - mg_snprintf(conn, path, sizeof(path), "%s%c%s", dir, '/', dp->d_name); - // If we don't memset stat structure to zero, mtime will have // garbage and strftime() will segfault later on in // print_dir_entry(). memset is required only if mg_stat() diff --git a/phpdesktop-chrome-cef2171/resource.rc b/phpdesktop-chrome-cef2171/resource.rc index e4e87b5..c902c04 100644 --- a/phpdesktop-chrome-cef2171/resource.rc +++ b/phpdesktop-chrome-cef2171/resource.rc @@ -47,8 +47,8 @@ IDR_MAINWINDOW ICON "icon.ico" // VS_VERSION_INFO VERSIONINFO - FILEVERSION 39,1,0,0 - PRODUCTVERSION 39,1,0,0 + FILEVERSION 39,2,0,0 + PRODUCTVERSION 39,2,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -65,12 +65,12 @@ BEGIN BEGIN VALUE "CompanyName", "PHP Desktop" VALUE "FileDescription", "PHP Desktop Chrome" - VALUE "FileVersion", "39.1.0.0" + VALUE "FileVersion", "39.2.0.0" VALUE "InternalName", "phpdesktop" - VALUE "LegalCopyright", "(c) Czarek Tomczak 2012-2015" + VALUE "LegalCopyright", "(c) Czarek Tomczak 2012" VALUE "OriginalFilename", "phpdesktop-chrome.exe" VALUE "ProductName", "PHP Desktop Chrome" - VALUE "ProductVersion", "39.1.0.0" + VALUE "ProductVersion", "39.2.0.0" END END BLOCK "VarFileInfo" diff --git a/phpdesktop-chrome-cef2171/settings.json b/phpdesktop-chrome-cef2171/settings.json index edec412..cbabe7a 100644 --- a/phpdesktop-chrome-cef2171/settings.json +++ b/phpdesktop-chrome-cef2171/settings.json @@ -34,7 +34,8 @@ "cgi_interpreter": "../php/php-cgi.exe", "cgi_extensions": ["php"], "cgi_temp_dir": "", - "404_handler": "/pretty-urls.php" + "404_handler": "/pretty-urls.php", + "hide_files": [] }, "chrome": { "log_file": "debug.log", diff --git a/phpdesktop-chrome-cef2171/web_server.cpp b/phpdesktop-chrome-cef2171/web_server.cpp index de54102..f95cc41 100644 --- a/phpdesktop-chrome-cef2171/web_server.cpp +++ b/phpdesktop-chrome-cef2171/web_server.cpp @@ -55,7 +55,7 @@ bool StartWebServer() { // 404_handler std::string _404_handler = (*appSettings)["web_server"]["404_handler"]; - + // Ip address and port. If port was set to 0, then real port // will be known only after the webserver was started. std::string ipAddress = (*appSettings)["web_server"]["listen_on"][0]; @@ -117,6 +117,19 @@ bool StartWebServer() { cgiPattern = "**.php$"; LOG_INFO << "CGI pattern: " << cgiPattern; + // Hide files patterns. + const json_value hide_files = (*appSettings)["web_server"]["hide_files"]; + std::string hide_files_patterns = ""; + for (int i = 0; i < 100; i++) { + const char* pattern = hide_files[i]; + if (strlen(pattern)) { + if (hide_files_patterns.length()) + hide_files_patterns.append("|"); + hide_files_patterns.append("**/").append(pattern).append("$"); + } + } + LOG_INFO << "Hide files patterns: " << hide_files_patterns; + // Temp directory. std::string cgi_temp_dir = (*appSettings)["web_server"]["cgi_temp_dir"]; cgi_temp_dir = GetAbsolutePath(cgi_temp_dir); @@ -126,7 +139,7 @@ bool StartWebServer() { << cgi_temp_dir; } cgi_temp_dir.assign(GetAnsiTempDirectory()); - } + } // CGI environment variables. std::string cgiEnvironment = ""; @@ -154,6 +167,7 @@ bool StartWebServer() { "cgi_pattern", cgiPattern.c_str(), "cgi_environment", cgiEnvironment.c_str(), "404_handler", _404_handler.c_str(), + "hide_files_patterns", hide_files_patterns.c_str(), NULL }; @@ -167,7 +181,7 @@ bool StartWebServer() { g_mongooseContext = mg_start(&callbacks, NULL, options); if (g_mongooseContext == NULL) return false; - + // When port was set to 0 then a random free port was assigned. g_webServerPort = mg_get_listening_port(g_mongooseContext); g_webServerIpAddress = ipAddress; @@ -210,4 +224,4 @@ std::string GetWwwDirectory() { } std::string GetCgiInterpreter() { return g_cgiInterpreter; -} \ No newline at end of file +}