Developed with love by KnpLabs Hire us for your project!
41

EoHoneypotBundle

by eymengunay

Honeypot type for Symfony forms

EoHoneypotBundle

Build Status
Scrutinizer Code Quality
Code Coverage
Latest Stable Version
Total Downloads

Honeypot for Symfony2 forms.

What is Honey pot?

A honey pot trap involves creating a form with an extra field that is hidden to human visitors but readable by robots.
The robot fills out the invisible field and submits the form, leaving you to simply ignore their spammy submission or blacklist their IP.
It’s a very simple concept that can be implemented in a few minutes and it just works – add them to your contact and submission forms to help reduce spam.

Prerequisites

This version of the bundle requires Symfony 2.1+

Installation

Step 1: Download EoHoneypotBundle using composer

Add EoHoneypotBundle in your composer.json:

{
"require": {
"eo/honeypot-bundle": "dev-master"
}
}

Now tell composer to download the bundle by running the command:

$ php composer.phar update eo/honeypot-bundle

Composer will install the bundle to your project's vendor/eo directory.

Step 2: Enable the bundle

Enable the bundle in the kernel:
```
<?php
// app/AppKernel.php

public function registerBundles()
{
$bundles = array(
// ...
new Eo\HoneypotBundle\EoHoneypotBundle(),
);
}
```

Step 3 (optional): Configure bundle to use database

To save honeypot catched requests into database you have to enable it in your configuration file:
All parameters are optional

# app/config.yml
...
eo_honeypot:
    storage:
        database:
            enabled: false
            driver: mongodb # orm and mongodb are supported
            class: ApplicationEoHoneypotBundle:HoneypotPrey
        # You can also use file format to store honeypot preys.
        # This may come handy if you need to parse logs with fail2ban
        # file:
            # enabled: false
            # output: /var/log/honeypot.log
    redirect:
        enabled: true
        url: "/"
        # route: homepage
        # route_parameters: ~

If you enable the database storage, you must create a class which extends
the Eo\HoneypotBundle\<Entity|Document>\HoneypotPrey base class :

<?php
namespace Application\Eo\HoneypotBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Eo\HoneypotBundle\Entity\HoneypotPrey as BaseHoneypotPrey;

/**
 * @ORM\Entity
 */
class HoneypotPrey extends BaseHoneypotPrey
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function getId()
    {
        return $this->id;
    }
}

or

<?php
namespace Application\Eo\HoneypotBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Eo\HoneypotBundle\Document\HoneypotPrey as BaseHoneypotPrey;

/**
 * @MongoDB\Document
 */
class HoneypotPrey extends BaseHoneypotPrey
{
    /**
     * @MongoDB\Id
     */
    protected $id;

    public function getId()
    {
        return $this->id;
    }
}

Usage

Once installed and configured you can start using honeypot type in your forms.

Basic usage example:

<?php

namespace Acme\DemoBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class FooType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('name', 'text');
        $builder->add('email', 'text');

        // Honeypot field
        $builder->add('SOME-FAKE-NAME', 'honeypot');
    }

    public function getName()
    {
        return 'foo';
    }
}

Events

If the hidden honeypot field has some data bundle will dispatch a bird.in.cage event. You can create an event listener to execute custom actions. See Eo\HoneypotBundle\Event\BirdInCage and How to Register Event Listeners and Subscribers for more information.

License

This bundle is under the MIT license. See the complete license in the bundle:

Resources/meta/LICENSE

Reporting an issue or a feature request

Issues and feature requests related to this bundle are tracked in the Github issue tracker https://github.com/eymengunay/EoHoneypotBundle/issues.

Copyright (c) Eymen Gunay <eymen@egunay.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
eo_honeypot:
redirect:
enabled: false
url: ~
route: ~
route_parameters:

# Prototype
name: []
storage:
database:
enabled: false
class: ApplicationEoHoneypotBundle:HoneypotPrey
driver: mongodb
file:
enabled: false
output: /var/log/honeypot.log
  • Merge pull request #18 from janopae/master
    By web-flow, 1 month ago
  • Fixed problem when using the web browser's autocomplete feature
    By , 1 month ago
  • Merge pull request #14 from iisisrael/patch-13
    By eymengunay, 2 years ago
  • Upgraded to Symfony 3.
    By iisisrael, 2 years ago
  • Updated form type unit test to match dependency injection change.
    By iisisrael, 2 years ago
  • Fixed dependency injection of request to use the request stack service instead.
    By iisisrael, 2 years ago
  • Updated FormType for Symfony 3.
    By iisisrael, 2 years ago
  • Merge pull request #9 from stefantalen/master
    By eymengunay, 3 years ago
  • Setting position to fixed instead of absolute
    By stefantalen, 3 years ago
  • Allow to extends HoneypotPrey entity/document
    By emmanuelvella, 3 years ago
  • Fix HoneypotType test for php 5.3
    By emmanuelvella, 3 years ago
  • Add HoneypotType test
    By emmanuelvella, 3 years ago
  • Fix data check
    By emmanuelvella, 3 years ago
  • Merge pull request #8 from EmmanuelVella/request
    By emmanuelvella, 3 years ago
  • Remove request from RedirectListener
    By emmanuelvella, 3 years ago
  • Check request type in RedirectListener
    By emmanuelvella, 3 years ago
  • Merge pull request #7 from EmmanuelVella/redirect-listener
    By eymengunay, 3 years ago
  • Add redirect listener
    By emmanuelvella, 3 years ago
  • Merge pull request #6 from EmmanuelVella/form-type-refactoring
    By eymengunay, 3 years ago
  • Refactored HoneypotType
    By emmanuelvella, 3 years ago
  • [Minor] Missing class property declaration added
    By eymengunay, 3 years ago
  • Readme badges updated
    By eymengunay, 4 years ago
  • Travis configuration added
    By eymengunay, 4 years ago
  • Scrutinizer code coverage enabled
    By eymengunay, 4 years ago
  • Scrutinizer configuration added
    By eymengunay, 4 years ago
  • Bundle tests created
    By eymengunay, 4 years ago
  • [Minor] Docblock update
    By eymengunay, 4 years ago
  • Merge pull request #5 from stefantalen/patch-1
    By eymengunay, 4 years ago
  • Adding negative tabindex
    By stefantalen, 4 years ago
  • Entity fix
    By eymengunay, 4 years ago