update realip log
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Sun, 8 Feb 2015 09:40:27 +0000 (10:40 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Sun, 8 Feb 2015 09:44:17 +0000 (10:44 +0100)
web/Obj/brisk.phh
web/Obj/provider_proxy.phh
web/Obj/sac-a-push.phh
web/spush/brisk-spush.php

index 7d9d719..676dd70 100644 (file)
@@ -90,7 +90,6 @@ define('DEBUGGING', "no-debugging");
 
 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' ),
@@ -1042,7 +1041,6 @@ class Brisk
     var $ban_list;       // ban list (authized allowed)
     var $black_list;     // black list (anti-dos, noone allowed)
     var $cloud_smasher;  // list of cloud ip ranges to be rejected
-    var $provider_proxy; // list of provider/browser that offer proxy service
     var $ghost_sess;
     var $delay_mgr;
 
@@ -1062,7 +1060,7 @@ class Brisk
                 fprintf(STDERR, "ROOM FROM FILE\n");
                 rename($crystal_filename, $crystal_filename.".old");
 
-                $brisk->reload(TRUE, $ban_list, $black_list, $cloud_smasher, $prov_proxy);
+                $brisk->reload(TRUE, $ban_list, $black_list, $cloud_smasher);
 
                 return($brisk);
             }
@@ -1079,7 +1077,6 @@ class Brisk
         $thiz->ban_list = IpClass::create();
         $thiz->black_list = IpClass::create();
         $thiz->cloud_smasher = IpClass::create();
-        $thiz->provider_proxy = ProviderProxy::create();
         $thiz->ghost_sess = new GhostSess();
 
         for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
@@ -1096,15 +1093,15 @@ class Brisk
 
         static::$sess_cur = FALSE;
 
-        $thiz->reload(TRUE, $ban_list, $black_list, $cloud_smasher, $prov_proxy);
+        $thiz->reload(TRUE, $ban_list, $black_list, $cloud_smasher);
 
         return ($thiz);
     }
 
-    function reload($is_first, $ban_list, $black_list, $cloud_smasher, $prov_proxy)
+    function reload($is_first, $ban_list, $black_list, $cloud_smasher)
     {
-        fprintf(STDERR, "RELOAD STUFF (%d)(%d)(%d)(%d)\n",
-                count($ban_list), count($black_list), count($cloud_smasher), count($prov_proxy));
+        fprintf(STDERR, "RELOAD STUFF (%d)(%d)(%d)\n",
+                count($ban_list), count($black_list), count($cloud_smasher));
 
         if (defined('CURL_DE_SAC_VERS')) {
             if (brisk_cds_reload($this) == FALSE) {
@@ -1114,7 +1111,6 @@ class Brisk
         $this->ban_list->update($ban_list);
         $this->black_list->update($black_list);
         $this->cloud_smasher->update($cloud_smasher);
-        $this->provider_proxy->update($prov_proxy);
 
         if (!$is_first) {
             $this->banned_kickoff();
@@ -1185,11 +1181,6 @@ class Brisk
         return ($this->cloud_smasher->check($ip_str));
     }
 
-    function pproxy_realip($header, $ip_str)
-    {
-        return ($this->provider_proxy->realip($header, $ip_str));
-    }
-
     function users_cleanup()
     {
         for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
@@ -2626,20 +2617,18 @@ class Brisk
 
   function request_mgr(&$s_a_p, $header, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie)
   {
-      GLOBAL $G_ban_list, $G_black_list, $G_cloud_smasher, $G_provider_proxy;
+      GLOBAL $G_ban_list, $G_black_list, $G_cloud_smasher;
 
       printf("NEW_SOCKET (root): %d PATH [%s]\n", intval($new_socket), $path);
-      // $remote_addr = addrtoipv4($addr);
-      $remote_addr = $this->pproxy_realip($header, addrtoipv4($addr));
 
-      fprintf(STDERR, "\n\n\n PRE_BLACK [%s]\n\n\n", $remote_addr);
-      if ($this->black_check($remote_addr)) {
+      fprintf(STDERR, "\n\n\n PRE_BLACK [%s]\n\n\n", $addr);
+      if ($this->black_check($addr)) {
           // TODO: waiting async 5 sec before close
           fprintf(STDERR, "\n\n\n BLACK CHECK\n\n\n");
           return (FALSE);
       }
       if ($path != "" && $path != "index.php") {
-          if ($this->cloud_check($remote_addr)) {
+          if ($this->cloud_check($addr)) {
               // TODO: waiting async 5 sec before close
               return (FALSE);
           }
index eb4b12e..b1a4d95 100644 (file)
@@ -82,11 +82,13 @@ class ProviderProxy
 
     function realip($header, $ip)
     {
+        fprintf(STDERR, "PP realip: [%d]\n", count($this->pp));
         if ($this->pp != NULL) {
             foreach ($this->pp as $pp_name => $pp_item) {
+                // fprintf(STDERR, "PP loop: [%s][%s]\n", $pp_name, $ip);
                 if ($pp_item->ipclass->check($ip)) {
                     if (isset($header[$pp_item->headitem])) {
-                        fprintf(STDERR, "Match public proxy [%s][%s]\n", $pp_name, $header[$pp_item->headitem]);
+                        fprintf(STDERR, "PP: match public proxy [%s][%s]\n", $pp_name, $header[$pp_item->headitem]);
                         return ($header[$pp_item->headitem]);
                     }
                 }
index 240a48a..66b340d 100644 (file)
@@ -401,6 +401,8 @@ class Sac_a_push {
     static $fixed_fd = 3;
     static $cnt_master = NULL;
     static $cnt_slave  = NULL;
+
+    var $provider_proxy; // list of provider/browser that offer proxy service
     
     var $file_socket;
     var $unix_socket;
@@ -455,9 +457,14 @@ class Sac_a_push {
 
     static function create(&$app, $sockname, $debug, $blocking_mode, $argv)
     {        
+        GLOBAL $G_provider_proxy;
+
         $thiz = new Sac_a_push();
         
         $thiz->app = $app;
+
+        $thiz->provider_proxy = ProviderProxy::create();
+
         $thiz->file_socket = $sockname;
         $thiz->unix_socket = "unix://$sockname";
         $thiz->direct_socket = "unix://${sockname}2";
@@ -517,6 +524,7 @@ class Sac_a_push {
         }
 
         $thiz->main_loop = FALSE;
+        $thiz->reload(TRUE, $G_provider_proxy);
 
         return ($thiz);
     }
@@ -709,7 +717,10 @@ class Sac_a_push {
                                 == FALSE) {
                                 fprintf(STDERR, "TODO: fix wrong header management\n");
                             }
-                            $addr = stream_socket_get_name($new_socket, TRUE);
+                            $addr_full = stream_socket_get_name($new_socket, TRUE);
+                            // FOR TEST $header['X-Forwarded-For'] = '154.155.22.33';
+                            $addr = $this->pproxy_realip($header, addrtoipv4($addr_full));
+
                             printf("PATH: [%s]\n", $path);
                             if ($method == "POST" && $rest > 0) {
                                 if (isset($header['Expect']) && $header['Expect'] == '100-continue') {
@@ -800,8 +811,9 @@ class Sac_a_push {
                                 $line = trim($buf);
                                 if ($line == "reload") {
                                     require("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
+                                    $this->reload(FALSE, $G_provider_proxy);
                                     $this->app->reload(FALSE, $G_ban_list, $G_black_list,
-                                                       $G_cloud_smasher, $G_provider_proxy);
+                                                       $G_cloud_smasher);
                                     global_dump();
                                 }
                                 else if ($line == "shutdown" || $line == "sd") {
@@ -953,6 +965,18 @@ class Sac_a_push {
         }  // while (...
     }  // function run(...
 
+    function pproxy_realip($header, $ip_str)
+    {
+        return ($this->provider_proxy->realip($header, $ip_str));
+    }
+
+    function reload($is_first, $prov_proxy)
+    {
+        fprintf(STDERR, "SAP RELOAD STUFF (%d)\n", count($prov_proxy));
+
+        $this->provider_proxy->update($prov_proxy);
+    }
+
     function direct_command($cmdstr)
     {
         GLOBAL $G_alarm_passwd;
index 93957c8..22def38 100755 (executable)
@@ -33,6 +33,7 @@ require_once($G_base."Obj/brisk.phh");
 require_once($G_base."Obj/auth.phh");
 require_once($G_base."Obj/zlibstream.phh");
 require_once($G_base."Obj/mail.phh");
+require_once($G_base."Obj/provider_proxy.phh");
 require_once($G_base."index.php");
 require_once($G_base."index_wr.php");
 require_once($G_base."briskin5/Obj/briskin5.phh");