diff --git a/docs/man5/tinyproxy.conf.txt.in b/docs/man5/tinyproxy.conf.txt.in index b3b94ec..764fe3e 100644 --- a/docs/man5/tinyproxy.conf.txt.in +++ b/docs/man5/tinyproxy.conf.txt.in @@ -342,6 +342,11 @@ ReversePath "/example/" "http://www.example.com/" types into his/her browser). If this option is not set then no rewriting of redirects occurs. +*ProxiedHost*:: +*ProxiedPort*:: + + The host name and the port to which all requests from clients + are sent. If ProxiedHost is set, ProxiedPort must be set, too. BUGS ---- diff --git a/etc/tinyproxy.conf.in b/etc/tinyproxy.conf.in index f1b8817..690251b 100644 --- a/etc/tinyproxy.conf.in +++ b/etc/tinyproxy.conf.in @@ -346,5 +346,9 @@ ViaProxyName "tinyproxy" # #ReverseBaseURL "http://localhost:8888/" - - +# +# The host and port to which all requests are sent. +# If ProxiedHost is set, ProxiedPort must be set. +# +#ProxiedHost "some.proxied.host.com" +#ProxiedPort 8080 diff --git a/src/conf.c b/src/conf.c index 5ebf179..0f58c3d 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1,6 +1,7 @@ /* tinyproxy - A fast light-weight HTTP proxy * Copyright (C) 2004 Robert James Kaes * Copyright (C) 2009 Michael Adam + * Copyright (C) 2019 Kaito Yamada * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -169,6 +170,9 @@ static HANDLE_FUNC (handle_upstream_no); static void config_free_regex (void); +static HANDLE_FUNC (handle_proxiedhost); +static HANDLE_FUNC (handle_proxiedport); + /* * This macro can be used to make standard directives in the form: * directive arguments [arguments ...] @@ -210,6 +214,7 @@ struct { STDCONF ("statfile", STR, handle_statfile), STDCONF ("stathost", STR, handle_stathost), STDCONF ("xtinyproxy", BOOL, handle_xtinyproxy), + STDCONF ("proxiedhost", STR, handle_proxiedhost), /* boolean arguments */ STDCONF ("syslog", BOOL, handle_syslog), STDCONF ("bindsame", BOOL, handle_bindsame), @@ -223,6 +228,7 @@ struct { STDCONF ("maxrequestsperchild", INT, handle_maxrequestsperchild), STDCONF ("timeout", INT, handle_timeout), STDCONF ("connectport", INT, handle_connectport), + STDCONF ("proxiedport", INT, handle_proxiedport), /* alphanumeric arguments */ STDCONF ("user", ALNUM, handle_user), STDCONF ("group", ALNUM, handle_group), @@ -731,6 +737,18 @@ static HANDLE_FUNC (handle_viaproxyname) return 0; } +static HANDLE_FUNC (handle_proxiedhost) +{ + int r = set_string_arg (&conf->proxied_host, line, &match[2]); + + if (r) + return r; + log_message (LOG_INFO, + "Setting proxied host to '%s'", + conf->proxied_host); + return 0; +} + static HANDLE_FUNC (handle_disableviaheader) { int r = set_bool_arg (&conf->disable_viaheader, line, &match[2]); @@ -803,6 +821,19 @@ static HANDLE_FUNC (handle_port) return 0; } +static HANDLE_FUNC (handle_proxiedport) +{ + set_int_arg (&conf->proxied_port, line, &match[2]); + + if (conf->proxied_port > 65535) { + fprintf (stderr, "Bad port number (%d) supplied for ProxiedPort.\n", + conf->proxied_port); + return 1; + } + + return 0; +} + static HANDLE_FUNC (handle_maxclients) { child_configure (CHILD_MAXCLIENTS, get_long_arg (line, &match[2])); diff --git a/src/conf.h b/src/conf.h index beb2b01..28539c4 100644 --- a/src/conf.h +++ b/src/conf.h @@ -1,6 +1,7 @@ /* tinyproxy - A fast light-weight HTTP proxy * Copyright (C) 2004 Robert James Kaes * Copyright (C) 2009 Michael Adam + * Copyright (C) 2019 Kaito Yamada * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -111,6 +112,13 @@ struct config_s { * Extra headers to be added to outgoing HTTP requests. */ vector_t add_headers; + + /* + * The proxied host and port. + * All requests are sent to it regardless of their original destination. + */ + char *proxied_host; + unsigned int proxied_port; }; extern int reload_config_file (const char *config_fname, struct config_s *conf, diff --git a/src/reqs.c b/src/reqs.c index 8450cff..b53fca6 100644 --- a/src/reqs.c +++ b/src/reqs.c @@ -3,6 +3,7 @@ * Copyright (C) 1999-2005 Robert James Kaes * Copyright (C) 2000 Chris Lightfoot * Copyright (C) 2002 Petr Lampa + * Copyright (C) 2019 Kaito Yamada * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1679,8 +1680,13 @@ e401: goto fail; } } else { - connptr->server_fd = opensock (request->host, request->port, - connptr->server_ip_addr); + if (config.proxied_host) { + connptr->server_fd = opensock (config.proxied_host, config.proxied_port, + connptr->server_ip_addr); + } else { + connptr->server_fd = opensock (request->host, request->port, + connptr->server_ip_addr); + } if (connptr->server_fd < 0) { indicate_http_error (connptr, 500, "Unable to connect", "detail",