/** * Get an IpAddress entity for current session or for passed in IP address * * @param string $ip * * @return IpAddress */ public function getIpAddress($ip = null) { static $ipAddresses = array(); if ($ip === null) { $ip = $this->getIpAddressFromRequest(); } if (empty($ip)) { //assume local as the ip is empty $ip = '127.0.0.1'; } if (empty($ipAddress[$ip])) { $repo = $this->getEntityManager()->getRepository('MauticCoreBundle:IpAddress'); $ipAddress = $repo->findOneByIpAddress($ip); $saveIp = $ipAddress === null; if ($ipAddress === null) { $ipAddress = new IpAddress(); $ipAddress->setIpAddress($ip); } // Ensure the do not track list is inserted $doNotTrack = $this->getParameter('do_not_track_ips', array()); $internalIps = $this->getParameter('do_not_track_internal_ips', array()); $doNotTrack = array_merge(array('127.0.0.1', '::1'), $doNotTrack, $internalIps); $ipAddress->setDoNotTrackList($doNotTrack); $details = $ipAddress->getIpDetails(); if ($ipAddress->isTrackable() && empty($details['city'])) { // Get the IP lookup service if ($ipService = $this->getParameter('ip_lookup_service')) { // Find the service class $bundles = $this->getMauticBundles(true); foreach ($bundles as $bundle) { if (!empty($bundle['config']['ip_lookup_services'][$ipService])) { $class = $bundle['config']['ip_lookup_services'][$ipService]['class']; if (substr($class, 0, 1) !== '\\') { $class = '\\' . $class; } /** @var \Mautic\CoreBundle\IpLookup\AbstractIpLookup $lookupClass */ $lookupClass = new $class($ip, $this->getParameter('ip_lookup_auth'), $this->getLogger()); // Fetch the data $lookupClass->getData(); // Get and set the details $details = get_object_vars($lookupClass); $ipAddress->setIpDetails($details); // Save new details $saveIp = true; unset($lookupClass); break; } } unset($bundles); } } if ($saveIp) { $repo->saveEntity($ipAddress); } $ipAddresses[$ip] = $ipAddress; } return $ipAddresses[$ip]; }
/** * Add ipAddress. * * @param IpAddress $ipAddress * * @return Lead */ public function addIpAddress(IpAddress $ipAddress) { if (!$ipAddress->isTrackable()) { return $this; } $ip = $ipAddress->getIpAddress(); if (!isset($this->ipAddresses[$ip])) { $this->isChanged('ipAddresses', $ipAddress); $this->ipAddresses[$ip] = $ipAddress; } return $this; }
/** * Get an IpAddress entity for current session or for passed in IP address * * @param string $ip * * @return IpAddress */ public function getIpAddress($ip = null) { static $ipAddresses = array(); if ($ip === null) { $ip = $this->getIpAddressFromRequest(); } if (empty($ip)) { //assume local as the ip is empty $ip = '127.0.0.1'; } if (empty($ipAddress[$ip])) { $repo = $this->getEntityManager()->getRepository('MauticCoreBundle:IpAddress'); $ipAddress = $repo->findOneByIpAddress($ip); $saveIp = $ipAddress === null; if ($ipAddress === null) { $ipAddress = new IpAddress(); $ipAddress->setIpAddress($ip); } // Ensure the do not track list is inserted $doNotTrack = $this->getParameter('do_not_track_ips', array()); if (!is_array($doNotTrack)) { $doNotTrack = array(); } $internalIps = $this->getParameter('do_not_track_internal_ips', array()); if (!is_array($internalIps)) { $internalIps = array(); } $doNotTrack = array_merge(array('127.0.0.1', '::1'), $doNotTrack, $internalIps); $ipAddress->setDoNotTrackList($doNotTrack); $details = $ipAddress->getIpDetails(); if ($ipAddress->isTrackable() && empty($details['city'])) { // Get the IP lookup service // Fetch the data /** @var \Mautic\CoreBundle\IpLookup\AbstractLookup $ipLookup */ $ipLookup = $this->container->get('mautic.ip_lookup'); if ($ipLookup) { $details = $ipLookup->setIpAddress($ip)->getDetails(); $ipAddress->setIpDetails($details); // Save new details $saveIp = true; } } if ($saveIp) { $repo->saveEntity($ipAddress); } $ipAddresses[$ip] = $ipAddress; } return $ipAddresses[$ip]; }
/** * Get an IpAddress entity for current session or for passed in IP address. * * @param string $ip * * @return IpAddress */ public function getIpAddress($ip = null) { static $ipAddresses = []; if ($ip === null) { $ip = $this->getIpAddressFromRequest(); } if (empty($ip)) { //assume local as the ip is empty $ip = '127.0.0.1'; } if (empty($ipAddress[$ip])) { $repo = $this->em->getRepository('MauticCoreBundle:IpAddress'); $ipAddress = $repo->findOneByIpAddress($ip); $saveIp = $ipAddress === null; if ($ipAddress === null) { $ipAddress = new IpAddress(); $ipAddress->setIpAddress($ip); } // Ensure the do not track list is inserted if (!is_array($this->doNotTrackIps)) { $this->doNotTrackIps = []; } if (!is_array($this->doNotTrackInternalIps)) { $this->doNotTrackInternalIps = []; } $doNotTrack = array_merge(['127.0.0.1', '::1'], $this->doNotTrackIps, $this->doNotTrackInternalIps); $ipAddress->setDoNotTrackList($doNotTrack); $details = $ipAddress->getIpDetails(); if ($ipAddress->isTrackable() && empty($details['city'])) { // Get the IP lookup service // Fetch the data if ($this->ipLookup) { $details = $this->ipLookup->setIpAddress($ip)->getDetails(); $ipAddress->setIpDetails($details); // Save new details $saveIp = true; } } if ($saveIp) { $repo->saveEntity($ipAddress); } $ipAddresses[$ip] = $ipAddress; } return $ipAddresses[$ip]; }
/** * {@inheritDoc} */ public function isTrackable() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'isTrackable', array()); return parent::isTrackable(); }