PHP code example of nguyenanhung / basic-firewall

1. Go to this page and download the library: Download nguyenanhung/basic-firewall library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nguyenanhung / basic-firewall example snippets



/**
 * Project basic-firewall
 * Created by PhpStorm
 * User: 713uk13m <[email protected]>
 * Copyright: 713uk13m <[email protected]>
 * Date: 09/01/2021
 * Time: 00:50
 */
 define('HUNGNG_IP_WHITELIST', array(
    '127.0.0.1',
    '192.168.0.*',
));
// Or Whitelist Array
$whiteList = array(
    '127.0.0.1',
    '192.168.0.*',
);

// ==================================== Setup List IP Blacklist
// Setup constants HUNGNG_IP_BLACKLIST
defined('HUNGNG_IP_BLACKLIST') or define('HUNGNG_IP_BLACKLIST', array(
    '127.0.0.1',
    '192.168.0.*',
));
// Or Blacklist Array
$blackList = array(
    '192.168.0.50',
);

// ==================================== Start Firewall

$firewall = new FirewallIP();
$firewall->setLogDestination(__DIR__ . '/logs/FirewallLog.log')
         ->setIpWhiteList($whiteList)
         ->setIpBlackList($blackList)
         ->checkUserConnect(false);

if (true !== $firewall->isAccess()) {
    $firewall->writeErrorLog($firewall->errorLogMessage()); // Write log to /tmp/FirewallLog.log
    $firewall->accessDeniedResponse(); // Response 403 http code, Access Denied message
}

// ==================================== End Firewall

// Pass qua firewall sẽ là các đoạn code thực hiện nghiệp vụ của bạn


/**
 * Project basic-firewall
 * Created by PhpStorm
 * User: 713uk13m <[email protected]>
 * Copyright: 713uk13m <[email protected]>
 * Date: 09/01/2021
 * Time: 00:55
 */
->checkExtension('curl');
$system->checkExtension('pdo');
$system->checkExtension('mysqli');
$system->checkExtension('gd');
$system->checkExtension('mbstring');
$system->checkExtension('json');
$system->checkExtension('session');
$system->checkExtension('sockets');
$system->checkExtension('bcmath');

// Kiểm tra kết nối tới 1 server nào đó
$system->phpTelnet('127.0.0.1', 3306);
$system->phpTelnet('127.0.0.1', 2842);

// Kiểm tra kết nối CSDL
$system->checkConnectDatabase('127.0.0.1', '3306', 'my_data', 'root', 'hungna');