Ticket #1111: ipv6.patch

File ipv6.patch, 4.2 KB (added by veretcle, 21 months ago)

Basic IPv6 integration patch with Live Plugin

  • plugins/Live/Visitor.php

     
    9191        } 
    9292 
    9393        function getIp() 
    94         { 
    95                 if(isset($this->details['location_ip'])) 
    96                 { 
    97                         return long2ip($this->details['location_ip']); 
    98                 } 
    99                 return false; 
    100         } 
     94        { 
     95                if(isset($this->details['location_ip'])) 
     96                { 
     97                        if($this->details['location_ip'] !== '0') 
     98                        { 
     99                                return long2ip($this->details['location_ip']); 
     100                        } 
     101                } 
     102                if(isset($this->details['location_ipv6'])) 
     103                { 
     104                        return $this->details['location_ipv6']; 
     105                } 
     106                return false; 
     107        } 
    101108 
    102109        function getIdVisit() 
    103110        { 
  • core/Tracker/Visit.php

     
    5757        // can be overwritten in constructor 
    5858        protected $timestamp; 
    5959        protected $ipString; 
     60        protected $ipv6String; 
    6061 
    61         public function __construct($forcedIpString = null, $forcedDateTime = null) 
     62        public function __construct($forcedIpString = null, $forcedDateTime = null, $forcedIpv6String = null) 
    6263        { 
    6364                $this->timestamp = time(); 
    6465                if(!empty($forcedDateTime)) 
     
    7273                } 
    7374                 
    7475                $this->ipString = Piwik_Common::getIp($ipString); 
     76 
     77                $ipv6String = $forcedIpv6String; 
     78                if(empty($ipv6String)) 
     79                { 
     80                        $ipv6String = Piwik_Common::getIpv6(); 
     81                } 
     82 
     83                $this->ipv6String = $ipv6String; 
    7584        } 
    7685         
    7786        function setRequest($requestArray) 
     
    120129        { 
    121130                // the IP is needed by isExcluded() and GoalManager->recordGoals() 
    122131                $this->visitorInfo['location_ip'] = $this->ipString; 
     132                $this->visitorInfo['location_ipv6'] = $this->ipv6String; 
    123133                 
    124134                if($this->isExcluded()) 
    125135                { 
     
    407417                        'config_silverlight'            => $userInfo['config_silverlight'], 
    408418                        'config_cookie'                         => $userInfo['config_cookie'], 
    409419                        'location_ip'                           => $this->getVisitorIp(), 
     420                        'location_ipv6'                         => $this->getVisitorIpv6(), 
    410421                        'location_browser_lang'         => $userInfo['location_browser_lang'], 
    411422                        'location_country'                      => $country, 
    412423                ); 
     
    477488                return $this->visitorInfo['location_ip'];  
    478489        } 
    479490         
     491        /** 
     492         * Returns the visitor's IPv6 address 
     493         * 
     494         * @return string 
     495         */ 
     496        protected function getVisitorIpv6() 
     497        { 
     498                return $this->visitorInfo['location_ipv6']; 
     499        } 
    480500 
    481501        /** 
    482502         * Returns the visitor's browser (user agent) 
  • core/Db/Schema/Myisam.php

     
    200200                                                          config_silverlight TINYINT(1) NOT NULL, 
    201201                                                          config_cookie TINYINT(1) NOT NULL, 
    202202                                                          location_ip INT UNSIGNED NOT NULL, 
     203                                                          location_ipv6 CHAR(39) NOT NULL, 
    203204                                                          location_browser_lang VARCHAR(20) NOT NULL, 
    204205                                                          location_country CHAR(3) NOT NULL, 
    205206                                                          location_continent CHAR(3) NOT NULL, 
  • core/Common.php

     
    736736 
    737737                return sprintf("%u", ip2long($ipStringFrom)); 
    738738        } 
     739         
     740        /** 
     741         * Convert dotted IP to a stringified integer representation 
     742         * 
     743         * @return string ip 
     744         */ 
     745        static public function getIpv6($ipv6StringFrom = false) 
     746        { 
     747                if($ipv6StringFrom === false) 
     748                { 
     749                        $ipv6StringFrom = self::getIpString(); 
     750                } 
     751                // Is an IPv6 regular string (contains at least one colon char) 
     752                if(strpos($ipv6StringFrom, ':')) 
     753                { 
     754                        return $ipv6StringFrom; 
     755                } 
     756                // Is not an IPv6 regular string, generic IPv6 address used 
     757                else 
     758                { 
     759                        return '::'; 
     760                } 
     761        } 
    739762 
    740763        /** 
    741764         * Returns the best possible IP of the current user, in the format A.B.C.D