350-httpd_redir.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. --- a/include/usage.h
  2. +++ b/include/usage.h
  3. @@ -1558,7 +1558,8 @@
  4. USE_FEATURE_HTTPD_BASIC_AUTH(" [-r realm]") \
  5. USE_FEATURE_HTTPD_AUTH_MD5(" [-m pass]") \
  6. " [-h home]" \
  7. - " [-d/-e string]"
  8. + " [-d/-e string]" \
  9. + " [-R <path> [-H <host>]]"
  10. #define httpd_full_usage "\n\n" \
  11. "Listen for incoming HTTP requests\n" \
  12. "\nOptions:" \
  13. @@ -1576,6 +1577,8 @@
  14. "\n -h HOME Home directory (default .)" \
  15. "\n -e STRING HTML encode STRING" \
  16. "\n -d STRING URL decode STRING" \
  17. + "\n -R PATH Redirect target path" \
  18. + "\n -H HOST Redirect target host" \
  19. #define hwclock_trivial_usage \
  20. USE_GETOPT_LONG( \
  21. --- a/networking/httpd.c
  22. +++ b/networking/httpd.c
  23. @@ -247,6 +247,8 @@
  24. const char *found_mime_type;
  25. const char *found_moved_temporarily;
  26. + const char *redirect_path;
  27. + const char *redirect_host;
  28. Htaccess_IP *ip_a_d; /* config allow/deny lines */
  29. USE_FEATURE_HTTPD_BASIC_AUTH(const char *g_realm;)
  30. @@ -292,6 +294,8 @@
  31. #define index_page (G.index_page )
  32. #define found_mime_type (G.found_mime_type )
  33. #define found_moved_temporarily (G.found_moved_temporarily)
  34. +#define redirect_path (G.redirect_path )
  35. +#define redirect_host (G.redirect_host )
  36. #define last_mod (G.last_mod )
  37. #define ip_a_d (G.ip_a_d )
  38. #define g_realm (G.g_realm )
  39. @@ -991,8 +995,11 @@
  40. }
  41. #endif
  42. if (responseNum == HTTP_MOVED_TEMPORARILY) {
  43. - len += sprintf(iobuf + len, "Location: %s/%s%s\r\n",
  44. + len += sprintf(iobuf + len, "Location: %s%s%s%s%s%s\r\n",
  45. + (redirect_host ? "http://" : ""),
  46. + (redirect_host ? redirect_host : ""),
  47. found_moved_temporarily,
  48. + (redirect_host ? "" : "/"),
  49. (g_query ? "?" : ""),
  50. (g_query ? g_query : ""));
  51. }
  52. @@ -1912,8 +1919,12 @@
  53. } while (*++tptr);
  54. *++urlp = '\0'; /* terminate after last character */
  55. + /* redirect active */
  56. + if (redirect_path && (strncmp(urlcopy, redirect_path, strlen(redirect_path)) != 0))
  57. + found_moved_temporarily = redirect_path;
  58. +
  59. /* If URL is a directory, add '/' */
  60. - if (urlp[-1] != '/') {
  61. + if (!redirect_path && (urlp[-1] != '/')) {
  62. if (is_directory(urlcopy + 1, 1, &sb)) {
  63. found_moved_temporarily = urlcopy;
  64. }
  65. @@ -2263,7 +2274,9 @@
  66. #endif
  67. enum {
  68. - c_opt_config_file = 0,
  69. + R_opt_redirect_path = 0,
  70. + H_opt_redirect_host,
  71. + c_opt_config_file,
  72. d_opt_decode_url,
  73. h_opt_home_httpd,
  74. USE_FEATURE_HTTPD_ENCODE_URL_STR(e_opt_encode_url,)
  75. @@ -2312,12 +2325,13 @@
  76. /* We do not "absolutize" path given by -h (home) opt.
  77. * If user gives relative path in -h,
  78. * $SCRIPT_FILENAME will not be set. */
  79. - opt = getopt32(argv, "c:d:h:"
  80. + opt = getopt32(argv, "R:H:c:d:h:"
  81. USE_FEATURE_HTTPD_ENCODE_URL_STR("e:")
  82. USE_FEATURE_HTTPD_BASIC_AUTH("r:")
  83. USE_FEATURE_HTTPD_AUTH_MD5("m:")
  84. USE_FEATURE_HTTPD_SETUID("u:")
  85. "p:ifv",
  86. + &redirect_path, &redirect_host,
  87. &configFile, &url_for_decode, &home_httpd
  88. USE_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode)
  89. USE_FEATURE_HTTPD_BASIC_AUTH(, &g_realm)