require_once("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
require_once("${G_base}Obj/ipclass.phh");
+require_once("${G_base}Obj/provider_proxy.phh");
$mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
'en' => 'back standing' ),
var $ban_list; // ban list (authized allowed)
var $black_list; // black list (anti-dos, noone allowed)
+ var $provider_proxy; // list of provider/browser that offer proxy service
var $ghost_sess;
var $delay_mgr;
}
// constructor
- static function create($crystal_filename, $ban_list, $black_list) {
+ static function create($crystal_filename, $ban_list, $black_list, $prov_proxy) {
if (($brisk_ser = @file_get_contents($crystal_filename)) != FALSE) {
if (($brisk = unserialize($brisk_ser)) != FALSE) {
fprintf(STDERR, "ROOM FROM FILE\n");
rename($crystal_filename, $crystal_filename.".old");
- $brisk->reload(TRUE, $ban_list, $black_list);
+ $brisk->reload(TRUE, $ban_list, $black_list, $prov_proxy);
return($brisk);
}
$thiz->ban_list = IpClass::create();
$thiz->black_list = IpClass::create();
+ $thiz->provider_proxy = ProviderProxy::create();
$thiz->ghost_sess = new GhostSess();
for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
static::$sess_cur = FALSE;
- $thiz->reload(TRUE, $ban_list, $black_list);
+ $thiz->reload(TRUE, $ban_list, $black_list, $prov_proxy);
return ($thiz);
}
- function reload($is_first, $ban_list, $black_list)
+ function reload($is_first, $ban_list, $black_list, $prov_proxy)
{
- fprintf(STDERR, "RELOAD STUFF (%d)(%d)\n", count($ban_list), count($black_list));
+ fprintf(STDERR, "RELOAD STUFF (%d)(%d)(%d)\n", count($ban_list), count($black_list), count($prov_proxy));
if (defined('CURL_DE_SAC_VERS')) {
if (brisk_cds_reload($this) == FALSE) {
}
$this->ban_list->update($ban_list);
$this->black_list->update($black_list);
+ $this->provider_proxy->update($prov_proxy);
if (!$is_first) {
$this->banned_kickoff();
return ($this->black_list->check($ip_str));
}
+ function pproxy_realip($ip_str)
+ {
+ return ($this->provider_proxy->realip($ip_str));
+ }
+
function users_cleanup()
{
for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
GLOBAL $G_ban_list, $G_black_list;
printf("NEW_SOCKET (root): %d PATH [%s]\n", intval($new_socket), $path);
- $remote_addr = addrtoipv4($addr);
+ // $remote_addr = addrtoipv4($addr);
+ $remote_addr = $this->pproxy_realip(addrtoipv4($addr));
fprintf(STDERR, "\n\n\n PRE_BLACK_CHECK \n\n\n");
if ($this->black_check($remote_addr)) {
--- /dev/null
+<?php
+/*
+ * brisk - Obj/provider_proxy.phh
+ *
+ * Copyright (C) 2015 Matteo Nastasi
+ * mailto: nastasi@alternativeoutput.it
+ * matteo.nastasi@milug.org
+ * web: http://www.alternativeoutput.it
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details. You should have received a
+ * copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc, 59 Temple Place -
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+require_once("${G_base}Obj/ipclass.phh");
+
+$G_pproxy = array( "samosa" => 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);
+ }
+}
+
+?>
\ No newline at end of file