<commit_before><?php
/**
 * @title            BannedIP Cron Class
 *
 * @author           <NAME> <<EMAIL>>, <NAME> <<EMAIL>>
 * @copyright        (c) 2013-2018, <NAME>. All Rights Reserved.
 * @license          GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
 * @package          PH7 / App / System / Core / Asset / Cron / 24H
 * @version          1.0
 */

namespace PH7;

defined('PH7') or exit('Restricted access');

use Exception;
use GuzzleHttp\Client;
use PH7\Framework\Error\Logger;
use PH7\Framework\Security\Ban\Ban;

/** Reset time limit and increase memory **/
@set_time_limit(0);
@ini_set('memory_limit', '528M');

class BannedCoreCron extends Cron
{
    const BANNED_IP_FILE_PATH = PH7_PATH_APP_CONFIG . Ban::DIR . Ban::IP_FILE;

    const ERROR_CALLING_WEB_SERVICE_MESSAGE = 'Error calling web service for banned IP URL name: %s';
    const ERROR_ADD_BANNED_IP_MESSAGE = 'Error writing new banned IP addresses.';

    /**
     * Web client used to fetch IPs
     *
     * @var Client
     */
    private $oWebClient;

    /**
     * Contain new blocked IP just fetched
     *
     * @var array
     */
    private $aNewIps;

    /**
     * Contain existing blocked IP
     *
     * @var array
     */
    private $aOldIps;

    /**
     * IP extracting regular expression.
     *
     * @var string
     */
    private $sIpRegExp;

    /**
     * Contain the URL of the remote services we call to get the list of accurate banned IPs.
     * Currently filled at instantiation statically, will use config file later
     *
     * @var array
     */
    const SVC_URLS = [
        'https://www.blocklist.de/downloads/export-ips_all.txt',
        'http://www.badips.com/get/list/ssh/2'
    ];

    public function __construct()
    {
        parent::__construct();

        /**
         * Set valid IP regular expression using lazy mode (false)
         */
        $this->sIpRegExp = self::regexpIps();

        $this->doProcess();
    }

    protected function doProcess()
    {
        /**
         * Process each web url we have in the $svcUrl array<commit_msg>[BannedCronCore] Update IP DB provider URL (to fewer IPs)<commit_after><?php
/**
 * @title            BannedIP Cron Class
 *
 * @author           <NAME> <<EMAIL>>, <NAME> <<EMAIL>>
 * @copyright        (c) 2013-2018, <NAME>. All Rights Reserved.
 * @license          GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
 * @package          PH7 / App / System / Core / Asset / Cron / 24H
 * @version          1.0
 */

namespace PH7;

defined('PH7') or exit('Restricted access');

use Exception;
use GuzzleHttp\Client;
use PH7\Framework\Error\Logger;
use PH7\Framework\Security\Ban\Ban;

/** Reset time limit and increase memory **/
@set_time_limit(0);
@ini_set('memory_limit', '528M');

class BannedCoreCron extends Cron
{
    const BANNED_IP_FILE_PATH = PH7_PATH_APP_CONFIG . Ban::DIR . Ban::IP_FILE;

    const ERROR_CALLING_WEB_SERVICE_MESSAGE = 'Error calling web service for banned IP URL name: %s';
    const ERROR_ADD_BANNED_IP_MESSAGE = 'Error writing new banned IP addresses.';

    /**
     * Web client used to fetch IPs
     *
     * @var Client
     */
    private $oWebClient;

    /**
     * Contain new blocked IP just fetched
     *
     * @var array
     */
    private $aNewIps;

    /**
     * Contain existing blocked IP
     *
     * @var array
     */
    private $aOldIps;

    /**
     * IP extracting regular expression.
     *
     * @var string
     */
    private $sIpRegExp;

    /**
     * Contain the URL of the remote services we call to get the list of accurate banned IPs.
     * Currently filled at instantiation statically, will use config file later
     *
     * @var array
     */
    const SVC_URLS = [
        'https://www.blocklist.de/downloads/export-ips_all.txt',
        'https://www.badips.com/get/list/ssh/2?age=30d'
    ];

    public function __construct()
    {
        parent::__construct();

        /**
         * Set valid IP regular expression using lazy mode (false)
         */
        $this->sIpRegExp = self::regexpIps();

        $this->doProcess();
    }

    protected function doProcess()
    {
        /**
         * Process each web url we have in the $svcUrl array
{'fraction_non_alphanumeric': 0.11424574492888785, 'fraction_numerical': 0.012124038237351364, 'mean_word_length': 2.2524639878695982, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 3, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '136343', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1318, 'n_words': 387}