Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37736716
en ru br
ALT Linux repos
4.1: 0.5-alt3
4.0: 0.5-alt3
+updates:0.5-alt3

Group :: System/Servers
RPM: apache2-mod_rpaf

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

Patch: mod_rpaf-0.5-realip.patch
Download


diff -uNpar mod_rpaf/mod_rpaf-2.0.c mod_rpaf.realip/mod_rpaf-2.0.c
--- mod_rpaf/mod_rpaf-2.0.c	2004-03-17 18:47:30 +0300
+++ mod_rpaf.realip/mod_rpaf-2.0.c	2007-03-08 13:03:57 +0300
@@ -61,6 +61,9 @@
  * This module does the opposite of mod_proxy_add_forward written by
  * Ask Bjørn Hansen. http://develooper.com/code/mpaf/ or mod_proxy
  * in 1.3.25 and above and mod_proxy from Apache 2.0
+ *
+ * Patched for nginx/mod_realip X-Real-IP header detection
+ * by Konstantin A. Lepikhov <lakostis@altlinux.org>
  * 
  */ 
 
@@ -161,10 +164,26 @@ static int change_remote_ip(request_rec 
                     apr_table_set(r->headers_in, "Host", apr_pstrdup(r->pool, hostvalue));
                     r->hostname = apr_pstrdup(r->pool, hostvalue);
                     ap_update_vhost_from_headers(r);
+                } else if (hostvalue = apr_table_get(r->headers_in, "X-Real-IP")) {
+                    /* nginx proxy frontend or 1.3 mod_realip */
+                    apr_table_set(r->headers_in, "Host", apr_pstrdup(r->pool, hostvalue));
+                    r->hostname = apr_pstrdup(r->pool, hostvalue);
+                    ap_update_vhost_from_headers(r);
                 }
             }
 
-        }
+	} else {
+		if (fwdvalue = apr_table_get(r->headers_in, "X-Real-IP")) {
+			apr_array_header_t *arr = apr_array_make(r->pool, 0, sizeof(char*));
+			while (*fwdvalue && (val = ap_get_token(r->pool, &fwdvalue, 1))) {
+				*(char **)apr_array_push(arr) = apr_pstrdup(r->pool, val);
+				if (*fwdvalue != '\0')
+					++fwdvalue;
+			}
+			r->connection->remote_ip = apr_pstrdup(r->connection->pool, ((char **)arr->elts)[((arr->nelts)-1)]);
+			r->connection->remote_addr->sa.sin.sin_addr.s_addr = inet_addr(r->connection->remote_ip);
+		}
+	}
     }
     return DECLINED;
 }
@@ -182,14 +201,14 @@ static const command_rec rpaf_cmds[] = {
                  rpaf_sethostname,
                  NULL,
                  RSRC_CONF,
-                 "Let mod_rpaf set the hostname from X-Host header and update vhosts"
+                 "Let mod_rpaf set the hostname from X-Host or X-Real-IP header and update vhosts"
                  ),
     AP_INIT_ITERATE(
                     "RPAFproxy_ips",
                     rpaf_set_proxy_ip,
                     NULL,
                     RSRC_CONF,
-                    "IP(s) of Proxy server setting X-Forwarded-For header"
+                    "IP(s) of Proxy server setting X-Forwarded-For or X-Real-IP header"
                     ),
     { NULL }
 };
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin