Skip to content

FatFree Framework

Terry L edited this page Aug 21, 2020 · 2 revisions

Not like other frameworks, Fat-Free is an extremely light-weight PHP framework.

Firewall in FatFree Framework

Installation

Use PHP Composer:

composer require shieldon/shieldon ^2

This will also install dependencies built for Shieldon:

Implementing

Assuming your code is supposed to look like this.

<?php

require dirname(__DIR__) . '/vendor/autoload.php';

$f3 = \Base::instance();
$f3->route('GET /',
    function() {
        echo 'Hello, world!';
    }
);
$f3->run();

Steps

1. Initialize Shieldon Firewall

After this line:

require dirname(__DIR__) . '/vendor/autoload.php';

Add the following code:

Example:

// Prevent error when running in CLI environment.
if (isset($_SERVER['REQUEST_URI'])) {

    // This directory must be writable.
    $storage = dirname($_SERVER['SCRIPT_FILENAME']) . '/../shieldon_firewall';

    $firewall = new \Shieldon\Firewall\Firewall();
    $firewall->configure($storage);
    $firewall->controlPanel('/firewall/panel');
    $response = $firewall->run();

    if ($response->getStatusCode() !== 200) {
        $httpResolver = new \Shieldon\Firewall\HttpResolver();
        $httpResolver($response);
    }
}

Note:

Please create a wriable directory named it with shieldon_firewall at above directory, Shieldon Firewall stores data in that.

2. Define a Route for Firewall Panel.

Example:

$f3->route('GET|POST /firewall/panel*', function() {
    $panel = new \Shieldon\Firewall\Panel();
    $panel->entry();
});

That's it.

Now, you can access the Firewall Panel via URL:

https://yoursite.com/firewall/panel

The default login is shieldon_user and password is shieldon_pass. After logging in the Firewall Panel, the first thing you need to do is to change the login and password.

Shieldon Firewall will start watching your website if it get enabled in Deamon setting section, make sure you have set up the settings correctly.