Root/package/busybox/patches/350-httpd_redir.patch

1--- a/networking/httpd.c
2+++ b/networking/httpd.c
3@@ -105,6 +105,7 @@
4 //usage: IF_FEATURE_HTTPD_BASIC_AUTH(" [-r REALM]")
5 //usage: " [-h HOME]\n"
6 //usage: "or httpd -d/-e" IF_FEATURE_HTTPD_AUTH_MD5("/-m") " STRING"
7+//usage: " [-R <path> [-H <host>]]"
8 //usage:#define httpd_full_usage "\n\n"
9 //usage: "Listen for incoming HTTP requests\n"
10 //usage: "\n -i Inetd mode"
11@@ -121,6 +122,8 @@
12 //usage: "\n -m STRING MD5 crypt STRING")
13 //usage: "\n -e STRING HTML encode STRING"
14 //usage: "\n -d STRING URL decode STRING"
15+//usage: "\n -R PATH Redirect target path"
16+//usage: "\n -H HOST Redirect target host"
17 
18 #include "libbb.h"
19 #if ENABLE_FEATURE_HTTPD_USE_SENDFILE
20@@ -272,6 +275,8 @@ struct globals {
21 
22     const char *found_mime_type;
23     const char *found_moved_temporarily;
24+ const char *redirect_path;
25+ const char *redirect_host;
26     Htaccess_IP *ip_a_d; /* config allow/deny lines */
27 
28     IF_FEATURE_HTTPD_BASIC_AUTH(const char *g_realm;)
29@@ -322,6 +327,8 @@ struct globals {
30 #define index_page (G.index_page )
31 #define found_mime_type (G.found_mime_type )
32 #define found_moved_temporarily (G.found_moved_temporarily)
33+#define redirect_path (G.redirect_path )
34+#define redirect_host (G.redirect_host )
35 #define last_mod (G.last_mod )
36 #define ip_a_d (G.ip_a_d )
37 #define g_realm (G.g_realm )
38@@ -956,8 +963,11 @@ static void send_headers(int responseNum
39     }
40 #endif
41     if (responseNum == HTTP_MOVED_TEMPORARILY) {
42- len += sprintf(iobuf + len, "Location: %s/%s%s\r\n",
43+ len += sprintf(iobuf + len, "Location: %s%s%s%s%s%s\r\n",
44+ (redirect_host ? "http://" : ""),
45+ (redirect_host ? redirect_host : ""),
46                 found_moved_temporarily,
47+ (redirect_host ? "" : "/"),
48                 (g_query ? "?" : ""),
49                 (g_query ? g_query : ""));
50     }
51@@ -1925,8 +1935,12 @@ static void handle_incoming_and_exit(con
52     } while (*++tptr);
53     *++urlp = '\0'; /* terminate after last character */
54 
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, NULL)) {
63             found_moved_temporarily = urlcopy;
64         }
65@@ -2283,7 +2297,9 @@ static void sighup_handler(int sig UNUSE
66 }
67 
68 enum {
69- c_opt_config_file = 0,
70+ R_opt_redirect_path = 0,
71+ H_opt_redirect_host,
72+ c_opt_config_file,
73     d_opt_decode_url,
74     h_opt_home_httpd,
75     IF_FEATURE_HTTPD_ENCODE_URL_STR(e_opt_encode_url,)
76@@ -2332,12 +2348,13 @@ int httpd_main(int argc UNUSED_PARAM, ch
77     /* We do not "absolutize" path given by -h (home) opt.
78      * If user gives relative path in -h,
79      * $SCRIPT_FILENAME will not be set. */
80- opt = getopt32(argv, "c:d:h:"
81+ opt = getopt32(argv, "R:H:c:d:h:"
82             IF_FEATURE_HTTPD_ENCODE_URL_STR("e:")
83             IF_FEATURE_HTTPD_BASIC_AUTH("r:")
84             IF_FEATURE_HTTPD_AUTH_MD5("m:")
85             IF_FEATURE_HTTPD_SETUID("u:")
86             "p:ifv",
87+ &redirect_path, &redirect_host,
88             &opt_c_configFile, &url_for_decode, &home_httpd
89             IF_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode)
90             IF_FEATURE_HTTPD_BASIC_AUTH(, &g_realm)
91

Archive Download this file



interactive