eo/honeypot-bundle

Symfony3表单的蜜罐陷阱。

安装数: 175,814

依赖项: 0

建议者: 0

安全: 0

星标: 33

关注者: 1

分支: 21

公开问题: 4

类型:symfony-bundle

v2.2.0 2024-05-16 06:42 UTC

This package is auto-updated.

Last update: 2024-09-16 08:30:26 UTC


README

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

Symfony2表单的蜜罐。

什么是蜜罐?

蜜罐陷阱涉及创建一个表单,其中包含一个隐藏的额外字段,该字段对人类访客隐藏但对机器人可见。机器人填写不可见的字段并提交表单,你只需简单地忽略他们的垃圾邮件提交或将其IP列入黑名单。这是一个非常简单的概念,可以在几分钟内实现,并且效果非常好——将它们添加到你的联系和提交表单中,以帮助减少垃圾邮件。

先决条件

此版本的包需要Symfony 2.1+

安装

步骤1:使用Composer下载EoHoneypotBundle

通过运行以下命令将EoHoneypotBundle添加到您的项目中:

$ composer require eo/honeypot-bundle

Composer会将该包安装到您的项目的vendor/eo目录中。

步骤2:启用包

如果您使用Symfony Flex,请跳过此步骤。否则,在bundles.php中启用包。

<?php
// config/bundles.php

<?php
return [
    // ...
    Eo\HoneypotBundle\EoHoneypotBundle::class => ['all' => true],
];

步骤3(可选):将包配置为使用数据库

要将蜜罐捕获的请求保存到数据库中,您必须在配置文件中启用它: 所有参数都是可选的

# config/packages/eo_honeypot.yaml
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: ~

如果您启用了数据库存储,则必须创建一个扩展Eo\HoneypotBundle\<Entity|Document>\HoneypotPrey基本类的类

<?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;
    }
}

<?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;
    }
}

使用方法

一旦安装和配置完成,您就可以开始在您的表单中使用Eo\HoneypotBundle\Form\Type\HoneypotType表单类型了。

基本使用示例

<?php

namespace Acme\DemoBundle\Form\Type;

use Eo\HoneypotBundle\Form\Type\HoneypotType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

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

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

事件

如果隐藏的蜜罐字段中有数据,则包将触发一个bird.in.cage事件。您可以创建一个事件监听器来执行自定义操作。有关更多信息,请参阅Eo\HoneypotBundle\Event\BirdInCage如何注册事件监听器和订阅者

许可证

此包受MIT许可证的约束。请参阅包中的完整许可证。

Resources/meta/LICENSE

报告问题或功能请求

与此包相关的问题和功能请求在Github问题跟踪器中跟踪:https://github.com/eymengunay/EoHoneypotBundle/issues