示例#1
0
 /**
  * Get target to be used for the client's IP range + sub domain
  *
  * @param   String     $overrideIP      Simulate request from given instead of detecting real IP
  * @param   String       $overrideHost    Simulate request from given instead of detecting from real URL
  * @return    Boolean   Target detected or not?
  */
 public function detectTarget($overrideIP = '', $overrideHost = '')
 {
     $this->targetKey = false;
     // Key of detected target config
     $this->targetApiId = false;
     $this->targetApiKey = false;
     $targetKeys = explode(',', $this->config->get('TargetsProxy')->get('targetKeys' . $this->searchClass));
     // Check whether the current IP address matches against any of the configured targets' IP / sub domain patterns
     $ipAddress = !empty($overrideIP) ? $overrideIP : $this->getClientIpV4();
     if (empty($overrideHost)) {
         $url = $this->getClientUrl();
     } else {
         $url = new \Zend\Uri\Http();
         $url->setHost($overrideHost);
     }
     $IpMatcher = new IpMatcher();
     $UrlMatcher = new UrlMatcher();
     foreach ($targetKeys as $targetKey) {
         $isMatchingIP = false;
         $isMatchingUrl = false;
         /** @var    \Zend\Config\Config    $targetConfig */
         $targetConfig = $this->config->get($targetKey);
         $patternsIP = '';
         $patternsURL = '';
         // Check match of IP address if any pattern configured.
         // If match is found, set corresponding keys and continue matching
         if ($targetConfig->offsetExists('patterns_ip')) {
             $patternsIP = $targetConfig->get('patterns_ip');
             if (!empty($patternsIP)) {
                 $targetPatternsIp = explode(',', $patternsIP);
                 $isMatchingIP = $IpMatcher->isMatching($ipAddress, $targetPatternsIp);
                 if ($isMatchingIP === true) {
                     $this->setConfigKeys($targetKey);
                 }
             }
         }
         // Check match of URL hostname if any pattern configured.
         // If match is found, set corresponding keys and exit immediately
         if ($targetConfig->offsetExists('patterns_url')) {
             $patternsURL = $targetConfig->get('patterns_url');
             if (!empty($patternsURL)) {
                 $targetPatternsUrl = explode(',', $patternsURL);
                 $isMatchingUrl = $UrlMatcher->isMatching($url->getHost(), $targetPatternsUrl);
                 if ($isMatchingUrl === true) {
                     $this->setConfigKeys($targetKey);
                     return true;
                 }
             }
         }
     }
     return $this->targetKey != "" ? true : false;
 }