File: vault/rules_specific.php

Recommend this page to a friend!
  Classes of Caleb  >  CIDRAM  >  vault/rules_specific.php  >  Download  
File: vault/rules_specific.php
Role: Example script
Content type: text/plain
Description: Example script
Class: CIDRAM
Check if an IP address is a bad source of traffic
Author: By
Last change: Update of vault/rules_specific.php
Date: 2 years ago
Size: 4,133 bytes
 

Contents

Class file image Download
<?php
/**
 * This file is a part of the CIDRAM package.
 * Homepage: https://cidram.github.io/
 *
 * CIDRAM COPYRIGHT 2016 and beyond by Caleb Mazalevskis (Maikuolan).
 *
 * License: GNU/GPLv2
 * @see LICENSE.txt
 *
 * This file: Extended rules for some specific CIDRs (last modified: 2019.05.17).
 */

/** Prevents execution from outside of CIDRAM. */
if (!defined('CIDRAM')) {
    die(
'[CIDRAM] This should not be accessed directly.');
}

/** Prevents execution from outside of the CheckFactors closure. */
if (!isset($Factors[$FactorIndex])) {
    die(
'[CIDRAM] This should not be accessed directly.');
}

/** Safety. */
if (!isset($CIDRAM['RunParamResCache'])) {
   
$CIDRAM['RunParamResCache'] = [];
}

/**
 * Define object for these rules for later recall (all parameters inherited from CheckFactors).
 *
 * @param array $Factors All CIDR factors of the IP being checked.
 * @param int $FactorIndex The index of the CIDR factor of the triggered rule.
 * @param string $LN The line information generated by CheckFactors.
 * @param string $Tag The triggered rule's section's name (if there's any).
 */
$CIDRAM['RunParamResCache']['rules_specific.php'] = function (array $Factors = [], int $FactorIndex = 0, string $LN = '', string $Tag = '') use (&$CIDRAM) {

   
/** Handle PSINet prefixes here. */
   
if ($Tag === 'PSINet, Inc') {

       
/** Skip processing if signatures have already been triggered or if the "block_generic" directive is false. */
       
if ($CIDRAM['BlockInfo']['SignatureCount'] > 0 || !$CIDRAM['Config']['signatures']['block_generic']) {
            return;
        }

       
$CIDRAM['BlockInfo']['ReasonMessage'] = $CIDRAM['L10N']->getString('ReasonMessage_Generic');
        if (!empty(
$CIDRAM['BlockInfo']['WhyReason'])) {
           
$CIDRAM['BlockInfo']['WhyReason'] .= ', ';
        }
       
$CIDRAM['BlockInfo']['WhyReason'] .= $CIDRAM['L10N']->getString('Short_Generic') . $LN;
        if (!empty(
$CIDRAM['BlockInfo']['Signatures'])) {
           
$CIDRAM['BlockInfo']['Signatures'] .= ', ';
        }
       
$CIDRAM['BlockInfo']['Signatures'] .= $Factors[$FactorIndex];
       
$CIDRAM['BlockInfo']['SignatureCount']++;

       
/** Exit. */
       
return;

    }

   
/** Skip further processing if the "block_cloud" directive is false, or if no section tag has been defined. */
   
if (!$CIDRAM['Config']['signatures']['block_cloud'] || !$Tag) {
        return;
    }

   
/** Amazon AWS bypasses. */
   
if ($Tag === 'Amazon.com, Inc') {
       
/** DuckDuckGo bypass. */
       
if (preg_match('~duckduck(?:go-favicons-)?bot~', $CIDRAM['BlockInfo']['UALC'])) {
            return;
        }
       
/** Pinterest bypass. */
       
if (strpos($CIDRAM['BlockInfo']['UALC'], 'pinterest') !== false) {
            return;
        }
       
/** Embedly bypass. */
       
if (strpos($CIDRAM['BlockInfo']['UALC'], 'embedly') !== false) {
            return;
        }
    }

   
/** Bingbot bypasses. */
   
if ($Tag === 'Azure' && preg_match('~(?:msn|bing)bot|bingpreview~', $CIDRAM['BlockInfo']['UALC'])) {
       
$CIDRAM['Flag-Bypass-Bingbot-Check'] = true;
        return
2;
    }

   
/** Bypass for "googlealert.com", "gigaalert.com", "copyscape.com". **/
   
if ($Tag === 'Rackspace Hosting' && $Factors[31] === '162.13.83.46/32') {
        return;
    }

   
/** Ensure that Jetpack isn't blocked via Automattic. */
   
if ($Tag === 'Automattic' && strpos($CIDRAM['BlockInfo']['UALC'], 'jetpack') !== false) {
        return;
    }

   
$CIDRAM['BlockInfo']['ReasonMessage'] = $CIDRAM['L10N']->getString('ReasonMessage_Cloud');
    if (!empty(
$CIDRAM['BlockInfo']['WhyReason'])) {
       
$CIDRAM['BlockInfo']['WhyReason'] .= ', ';
    }
   
$CIDRAM['BlockInfo']['WhyReason'] .= $CIDRAM['L10N']->getString('Short_Cloud') . $LN;
    if (!empty(
$CIDRAM['BlockInfo']['Signatures'])) {
       
$CIDRAM['BlockInfo']['Signatures'] .= ', ';
    }
   
$CIDRAM['BlockInfo']['Signatures'] .= $Factors[$FactorIndex];
   
$CIDRAM['BlockInfo']['SignatureCount']++;

};

/** Execute object. */
$RunExitCode = $CIDRAM['RunParamResCache']['rules_specific.php']($Factors, $FactorIndex, $LN, $Tag);

For more information send a message to info at phpclasses dot org.