array("headitem" => "X-Forwarded-For", "ipclass" => array("107.178.33.0/24", "107.178.34.0/24", "107.178.35.0/24", "107.178.37.0/24", "107.178.38.0/24", "107.178.39.0/24", "107.178.41.0/24", "107.178.42.0/24", "107.178.43.0/24", "107.178.45.0/24", "107.178.46.0/24", "107.178.47.0/24", "206.173.221.0/24") ), "mytest" => array("headitem" => "X-Forwarded-For", "ipclass" => array("192.168.2.3/24") ) ); class ProviderProxyItem { var $name; var $headitem; var $ipclass; function ProviderProxyItem($pp_name, $pp_descr) { $this->name = $pp_name; $this->headitem = $pp_descr['headitem']; $this->ipclass = IPClass::create($pp_descr['ipclass']); } } class ProviderProxy { var $pp; function ProviderProxy() { $this->pp = NULL; } static function create($pproxy = NULL) { $thiz = new ProviderProxy(); if ($pproxy != NULL) $thiz->update($pproxy); return ($thiz); } function clean() { if ($this->pp != NULL) { foreach ($this->pp as $pp_name) { unset($this->pp[$pp_name]); } unset($this->pp); $this->pp = NULL; } } function update($pproxy) { $this->clean(); $this->pp = array(); foreach ($pproxy as $pp_name => $pp_descr) { $this->pp[$pp_name] = new ProviderProxyItem($pp_name, $pp_descr); } } function realip($headers, $ip) { if ($this->pp != NULL) { foreach ($this->pp as $pp_name => $pp_item) { if ($pp_item->match($ip)) { if (isset($headers[$pp_item->headitem])) { fprintf(STDERR, "Match public proxy [%s]\n", $pp_name); return ($headers[$pp_item->headitem]); } } } } return ($ip); } } ?>