Example #1
0
 function getAllObjects()
 {
     $object = new subnet();
     $object->orderBy('ip');
     $object->find();
     $objectList = array();
     while ($object->fetch()) {
         $objectList[$object->id] = clone $object;
     }
     return $objectList;
 }
Example #2
0
 function createDefaultIpRanges()
 {
     require_once ROOT_DIR . '/Drivers/marmot_inc/ipcalc.php';
     require_once ROOT_DIR . '/Drivers/marmot_inc/subnet.php';
     $subnet = new subnet();
     $subnet->find();
     while ($subnet->fetch()) {
         $subnet->update();
     }
 }
Example #3
0
 function getIPLocation()
 {
     if ($this->ipLocation != 'unset') {
         return $this->ipLocation;
     }
     global $timer;
     /** @var Memcache $memCache */
     global $memCache;
     global $configArray;
     global $logger;
     //Check the current IP address to see if we are in a branch
     $activeIp = $this->getActiveIp();
     //$logger->log("Active IP is $activeIp", PEAR_LOG_DEBUG);
     $this->ipLocation = $memCache->get('location_for_ip_' . $activeIp);
     $this->ipId = $memCache->get('ipId_for_ip_' . $activeIp);
     if ($this->ipId == -1) {
         $this->ipLocation = false;
     }
     if ($this->ipLocation == false || $this->ipId == false) {
         $timer->logTime('Starting getIPLocation');
         //echo("Active IP is $activeIp");
         require_once ROOT_DIR . '/Drivers/marmot_inc/subnet.php';
         $subnet = new subnet();
         $ipVal = ip2long($activeIp);
         $this->ipLocation = null;
         $this->ipId = -1;
         if (is_numeric($ipVal)) {
             disableErrorHandler();
             $subnet->whereAdd('startIpVal <= ' . $ipVal);
             $subnet->whereAdd('endIpVal >= ' . $ipVal);
             if ($subnet->find(true)) {
                 //$logger->log("Found {$subnet->N} matching IP addresses {$subnet->location}", PEAR_LOG_DEBUG);
                 $matchedLocation = new Location();
                 $matchedLocation->locationId = $subnet->locationid;
                 if ($matchedLocation->find(true)) {
                     //Only use the physical location regardless of where we are
                     //$logger->log("Active location is {$matchedLocation->displayName}", PEAR_LOG_DEBUG);
                     $this->ipLocation = clone $matchedLocation;
                     $this->ipId = $subnet->id;
                 } else {
                     $logger->log("Did not find location for ip location id {$subnet->locationid}", PEAR_LOG_WARNING);
                 }
             }
             enableErrorHandler();
         }
         $memCache->set('ipId_for_ip_' . $activeIp, $this->ipId, 0, $configArray['Caching']['ipId_for_ip']);
         $memCache->set('location_for_ip_' . $activeIp, $this->ipLocation, 0, $configArray['Caching']['location_for_ip']);
         $timer->logTime('Finished getIPLocation');
     }
     return $this->ipLocation;
 }