provider_proxy management added
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Sun, 1 Feb 2015 14:14:12 +0000 (15:14 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Sun, 1 Feb 2015 14:16:03 +0000 (15:16 +0100)
web/Obj/brisk.conf-templ.pho
web/Obj/brisk.phh
web/Obj/provider_proxy.phh
web/Obj/sac-a-push.phh
web/brisk.css
web/index.php
web/room.css
web/spush/brisk-spush.php

index 92fe8ee..6854d6a 100644 (file)
@@ -1,4 +1,11 @@
 <?php
+if (file_exists("$DOCUMENT_ROOT/Etc/provider_proxy.phh")) {
+    require_once("$DOCUMENT_ROOT/Etc/provider_proxy.phh");
+}
+else {
+    $G_provider_proxy = array();
+}
+
 // G_dbasetype value can be "pgsql" or "file"
 $G_dbasetype="pgsql";
 
index 896c28b..62b80a7 100644 (file)
@@ -447,6 +447,7 @@ function versions_cmp($v1, $v2)
     return 0;
 }
 
+// return string with IPV4 address
 function addrtoipv4($addr)
 {
     $ipv4addr_arr = explode(':' , $addr);
@@ -1174,9 +1175,9 @@ class Brisk
         return ($this->black_list->check($ip_str));
     }
 
-    function pproxy_realip($ip_str)
+    function pproxy_realip($header, $ip_str)
     {
-        return ($this->provider_proxy->realip($ip_str));
+        return ($this->provider_proxy->realip($header, $ip_str));
     }
 
     function users_cleanup()
@@ -2613,16 +2614,16 @@ 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;
+      GLOBAL $G_ban_list, $G_black_list, $G_provider_proxy;
 
       printf("NEW_SOCKET (root): %d PATH [%s]\n", intval($new_socket), $path);
       // $remote_addr = addrtoipv4($addr);
-      $remote_addr = $this->pproxy_realip(addrtoipv4($addr));
+      $remote_addr = $this->pproxy_realip($header, addrtoipv4($addr));
 
       fprintf(STDERR, "\n\n\n PRE_BLACK_CHECK \n\n\n");
       if ($this->black_check($remote_addr)) {
           // TODO: waiting async 5 sec before close
-          fprintf(STDERR, "\n\n\n BLACK_CHECK \n\n\n");
+          fprintf(STDERR, "\n\n\n BLACK CHECK\n\n\n");
           return (FALSE);
       }
 
index 7542802..eb4b12e 100644 (file)
 
 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;
@@ -79,8 +61,9 @@ class ProviderProxy
     function clean()
     {
         if ($this->pp != NULL) {
-            foreach ($this->pp as $pp_name) {
-                unset($this->pp[$pp_name]);
+            foreach ($this->pp as $pp_key => $pp_value) {
+                fprintf(STDERR, "PHP PPN: %s\n", $pp_key);
+                unset($this->pp[$pp_key]);
             }
             unset($this->pp);
             $this->pp = NULL;
@@ -92,19 +75,19 @@ class ProviderProxy
         $this->clean();
 
         $this->pp = array();
-        foreach ($pproxy as $pp_name => $pp_descr) {
-            $this->pp[$pp_name] = new ProviderProxyItem($pp_name, $pp_descr);
+        foreach ($pproxy as $pp_key => $pp_value) {
+            $this->pp[$pp_key] = new ProviderProxyItem($pp_key, $pp_value);
         }
     }
 
-    function realip($headers, $ip)
+    function realip($header, $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]);
+                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]);
+                        return ($header[$pp_item->headitem]);
                     }
                 }
             }
index d9ee5ad..fdf5541 100644 (file)
@@ -623,7 +623,8 @@ class Sac_a_push {
     {
         GLOBAL $DOCUMENT_ROOT, $HTTP_HOST;
 
-        GLOBAL $G_alarm_passwd, $G_ban_list, $G_black_list, $G_btrace_pref_sub, $G_dbauth;
+        GLOBAL $G_alarm_passwd, $G_ban_list, $G_black_list, $G_provider_proxy;
+        GLOBAL $G_btrace_pref_sub, $G_dbauth;
         GLOBAL $G_dbpfx, $G_donors_all, $G_donors_cur, $G_is_local, $G_lang;
         GLOBAL $G_poll_entries, $G_poll_name, $G_poll_title, $G_proxy_white_list;
         GLOBAL $G_room_roadmap, $G_shutdown;
@@ -799,7 +800,8 @@ class Sac_a_push {
                                 $line = trim($buf);
                                 if ($line == "reload") {
                                     require("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
-                                    $this->app->reload(FALSE, $G_ban_list, $G_black_list);
+                                    $this->app->reload(FALSE, $G_ban_list, $G_black_list,
+                                                       $G_provider_proxy);
                                     global_dump();
                                 }
                                 else if ($line == "shutdown" || $line == "sd") {
index 0539984..d886215 100644 (file)
@@ -263,3 +263,7 @@ span.au1 {
 span.au2 {
     background-color: #bafcba;
 }
+
+div.bye_msg {
+    font-weigth: bold;
+}
\ No newline at end of file
index 9486808..c2c4be1 100644 (file)
@@ -27,14 +27,16 @@ require_once("Obj/brisk.phh");
 require_once("Obj/auth.phh");
 require_once("Obj/proxyscan.phh");
 
-$mlang_room = array( 'userpasserr'  => array('it' => 'Utente e/o password errati.',
-                                             'en' => 'Wrong user and/or password.'),
-                     'userpassmust' => array('it' => 'Il nickname deve contenere almeno una lettera o una cifra.',
-                                             'en' => 'The nickname have to contain at least one letter or one number.'),
+$mlang_room = array( 'userpassuse'  => array('it' => 'Il tuo nickname &egrave; gi&agrave; in uso.',
+                                             'en' => 'Your nickname is already in use.'),
                      'userpassend'  => array('it' => 'Spiacenti, non ci sono pi&ugrave; posti liberi. Riprova pi&ugrave; tardi.',
                                              'en' => 'We are sorry, there aren\'t free place. Try again later.'),
-                     'userpassuse'  => array('it' => 'Il tuo nickname &egrave; gi&agrave; in uso.',
-                                             'en' => 'Your nickname is already in use.'),
+                     'userpassmust' => array('it' => 'Il nickname deve contenere almeno una lettera o una cifra.',
+                                             'en' => 'The nickname have to contain at least one letter or one number.'),
+                     'userpasserr'  => array('it' => 'Utente e/o password errati.',
+                                             'en' => 'Wrong user and/or password.'),
+                     'userpassban'  => array('it' => 'Il tuo indirizzo IP è stato bannato perché precedentemente utilizzato da qualche molestatore.',
+                                             'en' => 'Your IP address is banned because trolling activity was detected from it.'),
                      'standing'     => array('it' => 'Giocatori in piedi',
                                              'en' => 'Standing players'),
                      'headline'     => array('it' => 'briscola chiamata in salsa ajax',
@@ -53,6 +55,9 @@ $mlang_room = array( 'userpasserr'  => array('it' => 'Utente e/o password errati
                                              'en' => 'EN L\' accesso attraverso sistemi di anonimizzazione non è consentito.'),
                      'reas_anot'    => array('it' => 'La tua sessione è stata assegnata ad un altro browser.',
                                              'en' => 'EN La tua sessione è stata assegnata ad un altro browser.'),
+                     'reas_cloud'   => array('it' => 'La connessione dai computer di una cloud non è ammessa.',
+                                             'en' => 'Connection from cloud computers is not allowed.'),
+
                      'btn_enter'    => array('it' => 'entra',
                                              'en' => 'enter'),
                      'passwarn'     => array('it' => 'Se non hai ancora una password, lascia il campo in bianco ed entra.',
@@ -342,6 +347,7 @@ function index_main(&$brisk, $transp_type, $header, &$header_out, $remote_addr_f
     $standup = "";
     $ACTION = "login";
     $last_msg = "";
+    $banned = FALSE;
 
     if (isset($BRISK_SHOWHTML) == FALSE) {
         $is_table = FALSE;
@@ -391,9 +397,7 @@ function index_main(&$brisk, $transp_type, $header, &$header_out, $remote_addr_f
                 }
             }
         }
-
-        $banned = FALSE;
-        if ($ACTION == "login" && isset($name)) {
+        if (!$banned && $ACTION == "login" && isset($name)) {
             log_main("pre garbage_manager DUE");
 
             if (isset($pass_private) == FALSE || $pass_private == "") {
@@ -402,7 +406,7 @@ function index_main(&$brisk, $transp_type, $header, &$header_out, $remote_addr_f
                 if ($brisk->ban_check($remote_addr)) {
                     // TODO: find a way to add a nonblocking sleep(5) here
                     $banned = TRUE;
-                    $idx = -1;
+                    $idx = -4;
                 }
             }
 
@@ -432,15 +436,24 @@ function index_main(&$brisk, $transp_type, $header, &$header_out, $remote_addr_f
                 }
             }
             else {
+                fprintf(STDERR, "POST CHECK QUI\n");
                 /* Login Rendering */
-                if ($idx == -3)
+                switch($idx) {
+                case -4:
+                    $sfx = 'ban';
+                    break;
+                case -3:
                     $sfx = 'err';
-                else if ($idx == -2)
+                    break;
+                case -2:
                     $sfx = 'must';
-                else if ($idx == -1)
+                    break;
+                case -1:
                     $sfx = 'end';
-                else
+                    break;
+                default:
                     $sfx = 'use';
+                }
 
                 $body .= '<div class="urgmsg"><b>'.$mlang_room['userpass'.$sfx][$G_lang].'</b></div>';
             }
index 73cb799..d3af1ab 100644 (file)
@@ -456,3 +456,4 @@ img.tickbut {
     cursor: pointer;
     margin-top:4px;
 }
+
index 76db91f..3a43b19 100755 (executable)
@@ -42,11 +42,11 @@ require_once($G_base."briskin5/index_wr.php");
 
 function main($argv)
 {
-    GLOBAL $G_ban_list, $G_black_list, $G_prov_proxy;
+    GLOBAL $G_ban_list, $G_black_list, $G_provider_proxy;
 
     pid_save();
     do {
-        if (($brisk = Brisk::create(LEGAL_PATH."/brisk-crystal.data", $G_ban_list, $G_black_list, $G_prov_proxy)) == FALSE) {
+        if (($brisk = Brisk::create(LEGAL_PATH."/brisk-crystal.data", $G_ban_list, $G_black_list, $G_provider_proxy)) == FALSE) {
             log_crit("Brisk::create failed");
             $ret = 1;
             break;