PHP Classes

File: vault/rules_as6939.php

Recommend this page to a friend!
  Classes of Caleb   CIDRAM   vault/rules_as6939.php   Download  
File: vault/rules_as6939.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_as6939.php
Date: 4 years ago
Size: 2,980 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 AS6939 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_as6939.php'] = function (array $Factors = [], int $FactorIndex = 0, string $LN = '', string $Tag = '') use (&$CIDRAM) {

   
/** Skip further processing if the "block_cloud" directive is false. */
   
if (!$CIDRAM['Config']['signatures']['block_cloud']) {
        return;
    }

   
/** Access provider block bypass. */
   
if ($Factors[23] === '65.49.67.0/24') {
        return;
    }

   
/** Feedly/Feedspot bypass. */
   
if (
       
preg_match('/\.getpebble\.com$/i', $CIDRAM['BlockInfo']['UALC']) ||
       
strpos($CIDRAM['BlockInfo']['UA'], 'Feedspot http://www.feedspot.com') !== false ||
       
strpos($CIDRAM['BlockInfo']['UA'], 'Feedly') !== false
   
) {
        return;
    }

   
/**
     * Puffin browser bypass (Affected ranges: 45.33.128.0/20 and 107.178.32.0/20. Don't need to bypass
     * 101.127.206.0/23 and 101.127.208.0/23, because they belong to AS4657, which isn't blocked anyway).
     * See: https://www.puffinbrowser.com/help/developer/#article-how-can-i-block-puffin-web-browser
     */
   
if (strpos($CIDRAM['BlockInfo']['UA'], 'Puffin') !== false && (
       
$Factors[19] === '45.33.128.0/20' || $Factors[19] === '107.178.32.0/20'
   
)) {
        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_as6939.php']($Factors, $FactorIndex, $LN, $Tag);