Skip to content

Commit

Permalink
Branch 2171. Added the web server "hide_files" option in settings.json
Browse files Browse the repository at this point in the history
(Issue 17).

Updated version to 39.2.
  • Loading branch information
cztomczak committed Feb 13, 2015
1 parent 1afd0c8 commit c1ba05c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
11 changes: 8 additions & 3 deletions phpdesktop-chrome-cef2171/mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions phpdesktop-chrome-cef2171/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion phpdesktop-chrome-cef2171/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 18 additions & 4 deletions phpdesktop-chrome-cef2171/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand All @@ -126,7 +139,7 @@ bool StartWebServer() {
<< cgi_temp_dir;
}
cgi_temp_dir.assign(GetAnsiTempDirectory());
}
}

// CGI environment variables.
std::string cgiEnvironment = "";
Expand Down Expand Up @@ -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
};

Expand All @@ -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;
Expand Down Expand Up @@ -210,4 +224,4 @@ std::string GetWwwDirectory() {
}
std::string GetCgiInterpreter() {
return g_cgiInterpreter;
}
}

0 comments on commit c1ba05c

Please sign in to comment.