示例#1
0
 /**
  * Check if a given remote address (IP address) is allowed based on allow and deny arrays
  * 
  * @param string $remoteaddr
  * @param array $allow
  * @param array $deny
  * @return boolean
  */
 public static function checkRemoteAddress($remoteaddr, $arr_allow, $arr_deny)
 {
     $allowed = true;
     if (count($arr_allow)) {
         // only allow these addresses
         $allowed = false;
         foreach ($arr_allow as $allow) {
             if (false !== strpos($allow, '/')) {
                 // CIDR notation
                 if (QuickBooks_Utilities::_checkCIDR($remoteaddr, $allow)) {
                     $allowed = true;
                     break;
                 }
             } else {
                 if (ereg('^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$', $allow)) {
                     // IPv4 address
                     if ($remoteaddr == $allow) {
                         $allowed = true;
                         break;
                     }
                 }
             }
         }
         if (!$allowed) {
             return false;
         }
     }
     if (count($arr_deny)) {
         // do *not* allow these addresses
         foreach ($arr_deny as $deny) {
             if (false !== strpos($deny, '/')) {
                 // CIDR notation
                 if (QuickBooks_Utilities::_checkCIDR($remoteaddr, $deny)) {
                     return false;
                 }
             } else {
                 if (ereg('^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$', $deny)) {
                     // IPv4 address
                     if ($remoteaddr == $deny) {
                         return false;
                     }
                 }
             }
         }
     }
     return $allowed;
 }