- /* Send our default page */
- if (!strcmp(uri, "/") || !strcmp(uri, "/index.html")) {
- SilcBuffer php;
- const char *php_data = NULL;
-
- /* Execute PHP data */
- php = silc_http_php("<small>"
- "UPDATED <?php echo getcwd(); echo date(\"Y/m/d\", filemtime(\"test_silchttpserver.c\")); ?>"
- "| VERSION 4.0 | A HANDMADE WEB-SITE | (C) 1995 - 2006 PEKKA RIIKONEN");
- if (php)
- php_data = silc_buffer_data(php);
-
- memset(&page, 0, sizeof(page));
- silc_buffer_strformat(&page,
- "<html><head></head><body>",
- silc_http_server_get_header(httpd, conn,
- "User-Agent"),
- "<p><img src=\"pr_1995.jpg\">",
- "<p>OUR DEFAULT PAGE IS THIS: ",
- silc_time_string(silc_time()),
- "<P><FORM action=\"/posttest\" method=\"post\"><P>"
- "<LABEL>First name: </LABEL>"
- "<INPUT type=\"text\" name=\"firstname\"><BR>"
- "<INPUT type=\"radio\" name=\"sex\" value=\"Male\"> Male<BR>"
- "<INPUT type=\"radio\" name=\"sex\" value=\"Female\"> Female<BR>"
- "<INPUT type=\"submit\" value=\"Send\"> <INPUT type=\"reset\">"
- "</P></FORM>",
- php_data,
- "</body></html>",
- SILC_STRFMT_END);
- silc_http_server_add_header(httpd, conn, "X-Date",
- silc_time_string(silc_time()));
- silc_http_server_send(httpd, conn, &page);
- silc_buffer_purge(&page);
- silc_buffer_free(php);
- return;
- }
-
- if (!strcmp(uri, "/pr_1995.jpg")) {
- SilcUInt32 data_len;
- unsigned char *data = silc_file_readfile("pr_1995.jpg", &data_len);
- if (!data) {
- silc_http_server_send_error(httpd, conn, "404 Not Found", NULL);
- return;
+ if (strstr(uri, ".php"))
+ usephp = TRUE;
+
+ if (!strcmp(uri, "/"))
+ snprintf(filename, sizeof(filename), "%s/index.html", htdocs);
+ else
+ snprintf(filename, sizeof(filename), "%s%s", htdocs, uri);
+
+ if (strchr(filename, '?'))
+ *strchr(filename, '?') = ' ';
+ while (strchr(filename, '&'))
+ *strchr(filename, '&') = ' ';
+
+ SILC_LOG_DEBUG(("Filename: '%s'", filename));
+
+ if (!usephp) {
+ filedata = silc_file_readfile(filename, &data_len);
+ if (!filedata) {
+ silc_http_server_send_error(httpd, conn, "404 Not Found",
+ "<body><h1>404 Not Found</h1><p>The page you are looking for cannot be located</body>");
+ return;