3 * brisk - Obj/provider_proxy.phh
5 * Copyright (C) 2015 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details. You should have received a
19 * copy of the GNU General Public License along with this program; if
20 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21 * Suite 330, Boston, MA 02111-1307, USA.
25 require_once("${G_base}Obj/ipclass.phh");
27 class ProviderProxyItem
33 function ProviderProxyItem($pp_name, $pp_descr)
35 $this->name = $pp_name;
36 $this->headitem = $pp_descr['headitem'];
37 $this->ipclass = IPClass::create($pp_descr['ipclass']);
46 function ProviderProxy()
51 static function create($pproxy = NULL)
53 $thiz = new ProviderProxy();
56 $thiz->update($pproxy);
63 if ($this->pp != NULL) {
64 foreach ($this->pp as $pp_key => $pp_value) {
65 fprintf(STDERR, "PHP PPN: %s\n", $pp_key);
66 unset($this->pp[$pp_key]);
73 function update($pproxy)
78 foreach ($pproxy as $pp_key => $pp_value) {
79 $this->pp[$pp_key] = new ProviderProxyItem($pp_key, $pp_value);
83 function realip(&$header, $ip)
85 fprintf(STDERR, "PP realip: [%d]\n", count($this->pp));
86 if ($this->pp != NULL) {
87 foreach ($this->pp as $pp_name => $pp_item) {
88 // fprintf(STDERR, "PP loop: [%s][%s]\n", $pp_name, $ip);
89 if ($pp_item->ipclass->check($ip)) {
90 if (isset($header[$pp_item->headitem])) {
91 fprintf(STDERR, "PP: match public proxy [%s][%s]\n", $pp_name, $header[$pp_item->headitem]);
92 $ret = $header['POST_'.$pp_item->headitem] = $header[$pp_item->headitem];
93 unset($header[$pp_item->headitem]);