@cryptotaxi247 / netdata-1 / commits / 800dc8e6b

option to configure web directory

Costa Tsaousis (ktsaou) committed Apr 29, 2014 at 21:22 UTC 800dc8e6bde31b52254c540d7a88c4bf9f9c84a3
1 file changed +7 -6
netdata.c
+7 -6
@@ -1794,10 +1794,13 @@ void generate_config(struct web_buffer *wb)
1794
1795 int mysendfile(struct web_client *w, char *filename)
1796 {
1797 + static char *web_dir = NULL;
1798 + if(!web_dir) web_dir = config_get("global", "web files directory", "web");
1799 +
1800 debug(D_WEB_CLIENT, "%llu: Looking for file '%s'...", w->id, filename);
1801
1802 // skip leading slashes
1800 - while (filename[0] == '/') filename = &filename[1];
1803 + while (*filename == '/') filename++;
1804
1805 // if the filename contain known paths, skip them
1806 if(strncmp(filename, WEB_PATH_DATA "/", strlen(WEB_PATH_DATA) + 1) == 0) filename = &filename[strlen(WEB_PATH_DATA) + 1];
@@ -1806,17 +1809,15 @@ int mysendfile(struct web_client *w, char *filename)
1809 else if(strncmp(filename, WEB_PATH_FILE "/", strlen(WEB_PATH_FILE) + 1) == 0) filename = &filename[strlen(WEB_PATH_FILE) + 1];
1810
1811 // if the filename contains a / or a .., refuse to serve it
1809 - if(strstr(filename, "/") != 0 || strstr(filename, "..") != 0) {
1812 + if(strchr(filename, '/') != 0 || strstr(filename, "..") != 0) {
1813 debug(D_WEB_CLIENT_ACCESS, "%llu: File '%s' is not acceptable.", w->id, filename);
1814 web_buffer_printf(w->data, "File '%s' cannot be served. Filenames cannot contain / or ..", filename);
1815 return 400;
1816 }
1817
1815 - // access the file in web/*
1818 + // access the file
1819 char webfilename[FILENAME_MAX + 1];
1817 - strcpy(webfilename, "web/");
1818 - strncpy(&webfilename[4], filename, FILENAME_MAX - 4);
1819 - webfilename[FILENAME_MAX] = '\0';
1820 + snprintf(webfilename, FILENAME_MAX, "%s/%s", web_dir, filename);
1821
1822 // check if the file exists
1823 struct stat stat;