@cryptotaxi247 / netdata-1 / commits / d6e99d06f

new mime types and minor fixes

Costa Tsaousis (ktsaou) committed Mar 28, 2014 at 01:46 UTC d6e99d06f402e0bc858e018d4bbbb3665bc91308
2 files changed +48 -5
netdata.c
+45 -2
@@ -72,6 +72,12 @@
72 #define CT_TEXT_XML 6
73 #define CT_APPLICATION_XML 7
74 #define CT_TEXT_XSL 8
75 +#define CT_APPLICATION_OCTET_STREAM 9
76 +#define CT_APPLICATION_X_FONT_TRUETYPE 10
77 +#define CT_APPLICATION_X_FONT_OPENTYPE 11
78 +#define CT_APPLICATION_FONT_WOFF 12
79 +#define CT_APPLICATION_VND_MS_FONTOBJ 13
80 +#define CT_IMAGE_SVG_XML 14
81
82 // configuration
83 #define DEBUG (D_WEB_CLIENT_ACCESS|D_LISTENER|D_RRD_STATS)
@@ -962,7 +968,7 @@ int mysendfile(struct web_client *w, char *filename)
968
969 if(errno == EBUSY || errno == EAGAIN) {
970 error("%llu: File '%s' is busy, sending 307 Moved Temporarily to force retry.", w->id, filename);
965 - sprintf(w->response_header, "Location: " WEB_PATH_FILE "/%s\r\n", filename);
971 + sprintf(w->response_header, "Location: /" WEB_PATH_FILE "/%s\r\n", filename);
972 w->data->bytes = sprintf(w->data->buffer, "The file '%s' is currently busy. Please try again later.", filename);
973 return 307;
974 }
@@ -979,6 +985,13 @@ int mysendfile(struct web_client *w, char *filename)
985 else if(strstr(filename, ".css") != NULL) w->data->contenttype = CT_TEXT_CSS;
986 else if(strstr(filename, ".xml") != NULL) w->data->contenttype = CT_TEXT_XML;
987 else if(strstr(filename, ".xsl") != NULL) w->data->contenttype = CT_TEXT_XSL;
988 + else if(strstr(filename, ".txt") != NULL) w->data->contenttype = CT_TEXT_PLAIN;
989 + else if(strstr(filename, ".svg") != NULL) w->data->contenttype = CT_IMAGE_SVG_XML;
990 + else if(strstr(filename, ".ttf") != NULL) w->data->contenttype = CT_APPLICATION_X_FONT_TRUETYPE;
991 + else if(strstr(filename, ".otf") != NULL) w->data->contenttype = CT_APPLICATION_X_FONT_OPENTYPE;
992 + else if(strstr(filename, ".woff") != NULL) w->data->contenttype = CT_APPLICATION_FONT_WOFF;
993 + else if(strstr(filename, ".eot") != NULL) w->data->contenttype = CT_APPLICATION_VND_MS_FONTOBJ;
994 + else w->data->contenttype = CT_APPLICATION_OCTET_STREAM;
995
996 debug(D_WEB_CLIENT_ACCESS, "%llu: Sending file '%s' (%ld bytes, ifd %d, ofd %d).", w->id, filename, stat.st_size, w->ifd, w->ofd);
997
@@ -1159,7 +1172,13 @@ void web_client_process(struct web_client *w)
1172 w->data->bytes = rrd_stats_all_xml(w->data->buffer, w->data->size);
1173 }
1174 else if(strcmp(tok, WEB_PATH_FILE) == 0) { // "file"
1162 - code = mysendfile(w, url);
1175 + tok = mystrsep(&url, "/?&");
1176 + if(tok && *tok) code = mysendfile(w, tok);
1177 + else {
1178 + code = 400;
1179 + strcpy(w->data->buffer, "You have to give a filename to get.\r\n");
1180 + w->data->bytes = strlen(w->data->buffer);
1181 + }
1182 }
1183 else if(!tok[0]) {
1184 code = mysendfile(w, "index.html");
@@ -1209,6 +1228,30 @@ void web_client_process(struct web_client *w)
1228 content_type_string = "text/xsl";
1229 break;
1230
1231 + case CT_APPLICATION_OCTET_STREAM:
1232 + content_type_string = "application/octet-stream";
1233 + break;
1234 +
1235 + case CT_IMAGE_SVG_XML:
1236 + content_type_string = "image/svg+xml";
1237 + break;
1238 +
1239 + case CT_APPLICATION_X_FONT_TRUETYPE:
1240 + content_type_string = "application/x-font-truetype";
1241 + break;
1242 +
1243 + case CT_APPLICATION_X_FONT_OPENTYPE:
1244 + content_type_string = "application/x-font-opentype";
1245 + break;
1246 +
1247 + case CT_APPLICATION_FONT_WOFF:
1248 + content_type_string = "application/font-woff";
1249 + break;
1250 +
1251 + case CT_APPLICATION_VND_MS_FONTOBJ:
1252 + content_type_string = "application/vnd.ms-fontobject";
1253 + break;
1254 +
1255 default:
1256 case CT_TEXT_PLAIN:
1257 content_type_string = "text/plain";
netdata.start
+3 -3
@@ -38,7 +38,7 @@ NETDATA_CONFIG_PORT=19999
38 # get user configuration
39 if [ -f netdata.conf ]
40 then
41 - source netdata.conf
41 + . netdata.conf
42 fi
43
44 # how many history lines to keep in netdata
@@ -68,7 +68,7 @@ then
68 else
69 echo >&2 "WARNING: NOT RUNNING AS ROOT - CANNOT SWITCH TO USER $NETDATA_CONFIG_USER"
70 echo >&2 "WARNING: MAKE SURE FILES IN web/ ARE OWNED BY $USER - or it will not work"
71 - ./netdata -d -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
71 + `pwd`/netdata -d -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
72 fi
73 sleep 2
74
@@ -147,7 +147,7 @@ do
147 if [ ! "$p" = "IGNORE" ]
148 then
149 cat >>web/index.html <<EOF2
150 - addChart('${x}', '${y}_div', 0, 0, "data/${x}/${NETDATA_CONFIG_HISTORY_POINTS}/${NETDATA_CONFIG_UPDATE_EVERY}/average/", "${title}${t} (${x})", "${vtitle}");
150 + addChart('${x}', '${y}_div', 0, 0, "/data/${x}/${NETDATA_CONFIG_HISTORY_POINTS}/${NETDATA_CONFIG_UPDATE_EVERY}/average/", "${title}${t} (${x})", "${vtitle}");
151 EOF2
152 fi
153 done