Add ProxiedHost and ProxiedPort options.

This commit is contained in:
kaitoy 2019-11-07 23:25:31 +09:00
parent c2d3470a35
commit 30fc3d3efe
5 changed files with 58 additions and 4 deletions

View File

@ -342,6 +342,11 @@ ReversePath "/example/" "http://www.example.com/"
types into his/her browser). If this option is not set then types into his/her browser). If this option is not set then
no rewriting of redirects occurs. 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 BUGS
---- ----

View File

@ -346,5 +346,9 @@ ViaProxyName "tinyproxy"
# #
#ReverseBaseURL "http://localhost:8888/" #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

View File

@ -1,6 +1,7 @@
/* tinyproxy - A fast light-weight HTTP proxy /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2004 Robert James Kaes <rjkaes@users.sourceforge.net> * Copyright (C) 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2009 Michael Adam <obnox@samba.org> * Copyright (C) 2009 Michael Adam <obnox@samba.org>
* Copyright (C) 2019 Kaito Yamada <kaitoy@pcap4j.org>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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 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: * This macro can be used to make standard directives in the form:
* directive arguments [arguments ...] * directive arguments [arguments ...]
@ -210,6 +214,7 @@ struct {
STDCONF ("statfile", STR, handle_statfile), STDCONF ("statfile", STR, handle_statfile),
STDCONF ("stathost", STR, handle_stathost), STDCONF ("stathost", STR, handle_stathost),
STDCONF ("xtinyproxy", BOOL, handle_xtinyproxy), STDCONF ("xtinyproxy", BOOL, handle_xtinyproxy),
STDCONF ("proxiedhost", STR, handle_proxiedhost),
/* boolean arguments */ /* boolean arguments */
STDCONF ("syslog", BOOL, handle_syslog), STDCONF ("syslog", BOOL, handle_syslog),
STDCONF ("bindsame", BOOL, handle_bindsame), STDCONF ("bindsame", BOOL, handle_bindsame),
@ -223,6 +228,7 @@ struct {
STDCONF ("maxrequestsperchild", INT, handle_maxrequestsperchild), STDCONF ("maxrequestsperchild", INT, handle_maxrequestsperchild),
STDCONF ("timeout", INT, handle_timeout), STDCONF ("timeout", INT, handle_timeout),
STDCONF ("connectport", INT, handle_connectport), STDCONF ("connectport", INT, handle_connectport),
STDCONF ("proxiedport", INT, handle_proxiedport),
/* alphanumeric arguments */ /* alphanumeric arguments */
STDCONF ("user", ALNUM, handle_user), STDCONF ("user", ALNUM, handle_user),
STDCONF ("group", ALNUM, handle_group), STDCONF ("group", ALNUM, handle_group),
@ -731,6 +737,18 @@ static HANDLE_FUNC (handle_viaproxyname)
return 0; 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) static HANDLE_FUNC (handle_disableviaheader)
{ {
int r = set_bool_arg (&conf->disable_viaheader, line, &match[2]); int r = set_bool_arg (&conf->disable_viaheader, line, &match[2]);
@ -803,6 +821,19 @@ static HANDLE_FUNC (handle_port)
return 0; 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) static HANDLE_FUNC (handle_maxclients)
{ {
child_configure (CHILD_MAXCLIENTS, get_long_arg (line, &match[2])); child_configure (CHILD_MAXCLIENTS, get_long_arg (line, &match[2]));

View File

@ -1,6 +1,7 @@
/* tinyproxy - A fast light-weight HTTP proxy /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2004 Robert James Kaes <rjkaes@users.sourceforge.net> * Copyright (C) 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2009 Michael Adam <obnox@samba.org> * Copyright (C) 2009 Michael Adam <obnox@samba.org>
* Copyright (C) 2019 Kaito Yamada <kaitoy@pcap4j.org>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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. * Extra headers to be added to outgoing HTTP requests.
*/ */
vector_t add_headers; 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, extern int reload_config_file (const char *config_fname, struct config_s *conf,

View File

@ -3,6 +3,7 @@
* Copyright (C) 1999-2005 Robert James Kaes <rjkaes@users.sourceforge.net> * Copyright (C) 1999-2005 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2000 Chris Lightfoot <chris@ex-parrot.com> * Copyright (C) 2000 Chris Lightfoot <chris@ex-parrot.com>
* Copyright (C) 2002 Petr Lampa <lampa@fit.vutbr.cz> * Copyright (C) 2002 Petr Lampa <lampa@fit.vutbr.cz>
* Copyright (C) 2019 Kaito Yamada <kaitoy@pcap4j.org>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -1679,8 +1680,13 @@ e401:
goto fail; goto fail;
} }
} else { } else {
connptr->server_fd = opensock (request->host, request->port, if (config.proxied_host) {
connptr->server_ip_addr); 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) { if (connptr->server_fd < 0) {
indicate_http_error (connptr, 500, "Unable to connect", indicate_http_error (connptr, 500, "Unable to connect",
"detail", "detail",