/**
     * checks banned IP
     *
     * @return boolean
     */
    private function checkBannedIps(Pap_Signup_SignupFormContext $context) {
        $checkIt = Gpf_Settings::get(Pap_Settings::BANNEDIPS_SIGNUPS);
        if($checkIt != Gpf::YES) {
            return true;
        }

        $bannedIPAddresses = Gpf_Net_Ip::getBannedIPAddresses(Pap_Settings::BANNEDIPS_LIST_SIGNUPS);
        $checkAction = Gpf_Settings::get(Pap_Settings::BANNEDIPS_SIGNUPS_ACTION);
        if($bannedIPAddresses === false) {
            return true;
        }
        if($checkAction != self::ACTION_DECLINE && $checkAction != self::ACTION_DONTSAVE) {
            return true;
        }

        $userObject = new Pap_Common_User();

        if (Gpf_Net_Ip::ipMatchRange($context->getIp(), $bannedIPAddresses)) {
            if($checkAction == self::ACTION_DONTSAVE) {
                $context->getForm()->setErrorMessage($this->_("Not saved by fraud protection - your IP address is banned"));
                $context->setAllowSave(false);
                return false;
            } else if ($checkAction == self::ACTION_DECLINE) {
                $context->getRow()->setStatus(Gpf_Db_User::DECLINED);
            }
        }
        return true;
    }
    /**
     * checks for banned IP
     *
     * @param Pap_Contexts_Click $context
     * @return string
     */
    private function checkBannedIP(Pap_Contexts_Click $context) {
        if(Gpf_Settings::get(Pap_Settings::BANNEDIPS_CLICKS) != Gpf::YES) {
            $context->debug('Check for banned IP address is not turned on');
            return true;
        }

        $context->debug('Checking banned IP started');


        $bannedIPAddresses = Gpf_Net_Ip::getBannedIPAddresses(Pap_Settings::BANNEDIPS_LIST_CLICKS);

        if($bannedIPAddresses === false) {
            $context->debug('List of banned IP addresses is invalid or empty, stop checking');
            return true;
        }

        $checkAction = Gpf_Settings::get(Pap_Settings::BANNEDIPS_CLICKS_ACTION);
        if($checkAction != self::ACTION_DECLINE && $checkAction != self::ACTION_DONTSAVE) {
            $context->debug("Action after check is not correct: '$checkAction'");
            return true;
        }


        $ip = $context->getVisit()->getIp();

        if(Gpf_Net_Ip::ipMatchRange($ip, $bannedIPAddresses)) {
            if($checkAction == self::ACTION_DONTSAVE) {
                $context->debug("    STOPPING (setting setDoTrackerSave(false), IP: $ip is banned");
                $context->setDoTrackerSave(false);
                $context->debug('      Checking banned IP endeded');
                return false;

            } else {
                $context->debug("  DECLINING, IP: $ip is banned");

                $this->declineClick($context);

                $context->debug('      Checking banned IP endeded');
                return true;
            }
        } else {
            $context->debug("    IP: $ip is not banned");
        }

        $context->debug('      Checking banned IP endeded');
        return true;
    }
Example #3
0
 /**
  * Parse a formatted IP address
  *
  * Given a network qualified IP address, attempt to parse out the parts
  * and calculate qualities of the address.
  *
  * The following formats are possible:
  *
  * [dot quad ip]/[ bitmask ]
  * [dot quad ip]/[ dot quad netmask ]
  * [dot quad ip]/[ hex string netmask ]
  *
  * The first would be [IP Address]/[BitMask]:
  * 192.168.0.0/16
  *
  * The second would be [IP Address] [Subnet Mask in dot quad notation]:
  * 192.168.0.0/255.255.0.0
  *
  * The third would be [IP Address] [Subnet Mask as Hex string]
  * 192.168.0.0/ffff0000
  *
  * Usage:
  *
  * $cidr = '192.168.0.50/16';
  * $net = Net_IPv4::parseAddress($cidr);
  * echo $net->network; // 192.168.0.0
  * echo $net->ip; // 192.168.0.50
  * echo $net->broadcast; // 192.168.255.255
  * echo $net->bitmask; // 16
  * echo $net->long; // 3232235520 (long/double version of 192.168.0.50)
  * echo $net->netmask; // 255.255.0.0
  *
  * @param  string $ip IP address netmask combination
  * @return Gpf_Net_Ip     true if syntax is valid, otherwise false
  */
 public static function parseAddress($address)
 {
     $myself = new Gpf_Net_Ip();
     if (strchr($address, "/")) {
         $parts = explode("/", $address);
         if (!self::validateIP($parts[0])) {
             throw new Exception('Invalid IP address');
         }
         $myself->ip = $parts[0];
         // Check the style of netmask that was entered
         /*
          *  a hexadecimal string was entered
          */
         if (preg_match("/^([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})\$/i", $parts[1], $regs)) {
             // hexadecimal string
             $myself->netmask = hexdec($regs[1]) . "." . hexdec($regs[2]) . "." . hexdec($regs[3]) . "." . hexdec($regs[4]);
             /*
              *  a standard dot quad netmask was entered.
              */
         } else {
             if (strchr($parts[1], ".")) {
                 if (!self::validateNetmask($parts[1])) {
                     throw new Exception("invalid netmask value");
                 }
                 $myself->netmask = $parts[1];
                 /*
                  *  a CIDR bitmask type was entered
                  */
             } else {
                 if (ctype_digit($parts[1]) && $parts[1] >= 0 && $parts[1] <= 32) {
                     // bitmask was entered
                     $myself->bitmask = $parts[1];
                     /*
                      *  Some unknown format of netmask was entered
                      */
                 } else {
                     throw new Exception("invalid netmask value");
                 }
             }
         }
         $myself->calculate();
         return $myself;
     } else {
         if (self::validateIP($address)) {
             $myself->ip = $address;
             return $myself;
         } else {
             throw new Exception("invalid IP address");
         }
     }
 }
    /**
     * checks for duplicate records from same IP
     *
     * @param Pap_Contexts_Action $context
     * @return string
     */
    private function checkSalesFromBannedIP(Pap_Contexts_Action $context) {
        $checkIt = Gpf_Settings::get(Pap_Settings::BANNEDIPS_SALES);
        if($checkIt != Gpf::YES) {
            $context->debug('    Check for sales / leads with banned IP is not turned on');
            return true;
        }

        $context->debug('    Checking banned IP address of sales / leads started');


        $bannedIPAddresses = Gpf_Net_Ip::getBannedIPAddresses(Pap_Settings::BANNEDIPS_LIST_SALES);

        if($bannedIPAddresses === false) {
            $context->debug("List of banned IP addresses is invalid or empty, stop checking");
            return true;
        }

        $checkAction = Gpf_Settings::get(Pap_Settings::BANNEDIPS_SALES_ACTION);
        if($checkAction != self::ACTION_DECLINE && $checkAction != self::ACTION_DONTSAVE) {
            $context->debug("Action after check is not correct: '$checkAction'");
            return true;
        }

        $ip = $context->getIp();
        if(Gpf_Net_Ip::ipMatchRange($ip, $bannedIPAddresses)) {
            if($checkAction == self::ACTION_DONTSAVE) {
                $context->debug("    STOPPING (setting setDoCommissionsSave(false), IP: $ip is banned");
                $context->setDoCommissionsSave(false);
                $context->debug('      Checking banned IP of sales / leads endeded');
                return false;

            } else {
                $context->debug("  DECLINING, IP is banned: $ip");

                $message = Gpf_Settings::get(Pap_Settings::BANNEDIPS_SALES_MESSAGE);

                $this->declineAction($context, $message);

                $context->debug('      Checking banned IP of sales / leads endeded');
                return true;
            }
        } else {
            $context->debug("    IP $ip is not banned");
        }

        $context->debug('      Checking banned IP of sales / leads endeded');
        return true;
    }