Commit c5d93d53 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Mise en place d'un mouchard configurable pour être averti de toute action...

Mise en place d'un mouchard configurable pour être averti de toute action suspecte survenant sur une application (en prod ou ailleurs).

For more information, please contact laurent.lecluse@nsa.gov
parent 08c3bfea
Loading
Loading
Loading
Loading
+5
Changes for Module.php: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php
namespace UnicaenApp;

use UnicaenApp\Mouchard\MouchardService;
use UnicaenApp\Mouchard\MouchardServiceFactory;
use UnicaenApp\Mvc\Listener\MaintenanceListener;
use UnicaenApp\Options\ModuleOptions;
use Zend\EventManager\EventInterface;
@@ -92,6 +94,9 @@ class Module implements
        $exceptionStrategy->setDisplayExceptions($viewManager->getExceptionStrategy()->displayExceptions());
        $exceptionStrategy->attach($eventManager);

        /* Démarrage des mouchards en fonction de la configuration... */
        $services->get('MouchardService')->createMouchardsFromConfig();

        /* @var $vhm HelperPluginManager */
        $vhm = $services->get('view_helper_manager');

+23 −1
Changes for config/module.config.php: 23 added lines, 1 removed line.
Original line number Diff line number Diff line
<?php

namespace UnicaenApp;

return [
@@ -241,6 +242,27 @@ return [
            'MessageConfig'     => 'UnicaenApp\Message\MessageConfigFactory',
            'MessageRepository' => 'UnicaenApp\Message\MessageRepositoryFactory',
            'MessageService'    => 'UnicaenApp\Message\MessageServiceFactory',

            'MouchardService'              => 'UnicaenApp\Mouchard\MouchardServiceFactory',
            'MouchardListenerErrorHandler' => 'UnicaenApp\Mouchard\MouchardListenerErrorHandlerFactory',
            'MouchardListenerException'    => 'UnicaenApp\Mouchard\MouchardListenerExceptionFactory',
            'MouchardListenerMessenger'    => 'UnicaenApp\Mouchard\MouchardListenerMessengerFactory',
            'MouchardFormaterHtml'         => 'UnicaenApp\Mouchard\MouchardFormaterHtmlFactory',
            'MouchardSenderMail'           => 'UnicaenApp\Mouchard\MouchardSenderMailFactory',
            'MouchardSenderException'      => 'UnicaenApp\Mouchard\MouchardSenderExceptionFactory',
            'MouchardCompleterHttp'        => 'UnicaenApp\Mouchard\MouchardCompleterHttpFactory',
            'MouchardCompleterMvc'         => 'UnicaenApp\Mouchard\MouchardCompleterMvcFactory',

        ],
        'shared' => [
            'MouchardListenerErrorHandler' => false,
            'MouchardListenerException'    => false,
            'MouchardListenerMessenger'    => false,
            'MouchardFormaterHtml'         => false,
            'MouchardSenderMail'           => false,
            'MouchardSenderException'      => false,
            'MouchardCompleterHttp'        => false,
            'MouchardCompleterMvc'         => false,
        ],
        'invokables'         => [
            'UnicaenApp\HistoriqueListener' => 'UnicaenApp\ORM\Event\Listeners\HistoriqueListener',
@@ -272,10 +294,10 @@ return [
            'appLink'           => 'UnicaenApp\View\Helper\AppLinkFactory',
            'userProfileSelect' => 'UnicaenAuth\View\Helper\UserProfileSelectFactory',
            'Message'           => 'UnicaenApp\Message\View\Helper\MessageHelperFactory',
            'messenger'         => 'UnicaenApp\View\Helper\MessengerFactory',
        ],
        'invokables'   => [
            'appConnection'             => 'UnicaenApp\View\Helper\AppConnection',
            'messenger'                 => 'UnicaenApp\View\Helper\Messenger',
            'modalAjaxDialog'           => 'UnicaenApp\View\Helper\ModalAjaxDialog',
            'confirm'                   => 'UnicaenApp\View\Helper\ConfirmHelper',
            'toggleDetails'             => 'UnicaenApp\View\Helper\ToggleDetails',
+223
Changes for src/UnicaenApp/Mouchard/Mouchard.php: 223 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace UnicaenApp\Mouchard;

/**
 * Class MouchardService
 *
 * @author  Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
 * @package UnicaenApp\Mouchard
 */
class Mouchard
{

    /**
     * @var string
     */
    private $name;

    /**
     * @var MouchardListenerInterface[]
     */
    private $listeners = [];

    /**
     * @var MouchardSenderInterface[]
     */
    private $senders = [];

    /**
     * @var MouchardFormaterInterface
     */
    private $formater;

    /**
     * @var MouchardCompleterInterface[]
     */
    private $completers = [];



    /**
     * Mouchard constructor.
     *
     * @param string $name
     */
    public function __construct($name)
    {
        $this->name = $name;
    }



    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }



    /**
     * @param string $name
     *
     * @return Mouchard
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }



    /**
     * @param MouchardListenerInterface $listener
     *
     * @return $this
     */
    public function addListener(MouchardListenerInterface $listener)
    {
        $this->listeners[] = $listener;
        $listener->setMouchard($this);
        $listener->start();

        return $this;
    }



    /**
     * @param MouchardListenerInterface $listener
     *
     * return $this
     */
    public function removeListener(MouchardListenerInterface $listener)
    {
        foreach ($this->listeners as $i => $l) {
            if ($l === $listener) {
                $this->listeners[$i]->stop();
                unset($this->listeners[$i]);
            }
        }

        return $this;
    }



    /**
     * @param MouchardSenderInterface $sender
     *
     * @return $this
     */
    public function addSender(MouchardSenderInterface $sender)
    {
        $this->senders[] = $sender;

        return $this;
    }



    /**
     * @param MouchardSenderInterface $sender
     *
     * return $this
     */
    public function removeSender(MouchardSenderInterface $sender)
    {
        foreach ($this->senders as $i => $s) {
            if ($s === $sender) {
                unset($this->senders[$i]);
            }
        }

        return $this;
    }



    /**
     * @param MouchardCompleterInterface $completer
     *
     * @return $this
     */
    public function addCompleter(MouchardCompleterInterface $completer)
    {
        $this->completers[] = $completer;

        return $this;
    }



    /**
     * @param MouchardCompleterInterface $completer
     *
     * return $this
     */
    public function removeCompleter(MouchardCompleterInterface $completer)
    {
        foreach ($this->completers as $i => $c) {
            if ($c === $completer) {
                unset($this->completerss[$i]);
            }
        }

        return $this;
    }



    /**
     * @return MouchardFormaterInterface
     */
    public function getFormater()
    {
        return $this->formater;
    }



    /**
     * @param MouchardFormaterInterface $formater
     *
     * return $this
     */
    public function setFormater(MouchardFormaterInterface $formater)
    {
        $this->formater = $formater;

        return $this;
    }



    /**
     * @param MouchardMessage $message
     *
     * @return $this
     */
    public function envoyer(MouchardMessage $message)
    {
        if (!$this->getFormater()) {
            throw new \Exception('Aucun formateur n\'a été défini pour le mouchard');
        }

        $message->setAlias($this->getName());

        foreach ($this->completers as $completer) {
            $completer->complete($message);
        }

        foreach ($this->senders as $sender) {
            $sender->envoyer($message, $this->getFormater());
        }

        return $this;
    }
}
 No newline at end of file
+43
Changes for src/UnicaenApp/Mouchard/MouchardAwareTrait.php: 43 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace UnicaenApp\Mouchard;

/**
 * Trait MouchardServiceAwareTrait
 *
 * @author  Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
 * @package UnicaenApp\Mouchard
 */
trait MouchardAwareTrait
{

    /**
     * @var Mouchard
     */
    private $mouchard;



    /**
     * @return Mouchard
     */
    public function getMouchard()
    {
        return $this->mouchard;
    }



    /**
     * @param Mouchard $mouchard
     *
     * @return MouchardAwareTrait
     */
    public function setMouchard(Mouchard $mouchard)
    {
        $this->mouchard = $mouchard;

        return $this;
    }

}
 No newline at end of file
+27
Changes for src/UnicaenApp/Mouchard/MouchardCompleterHttp.php: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace UnicaenApp\Mouchard;


/**
 * Interface MouchardCompleterInterface
 *
 * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
 * @package UnicaenApp\Mouchard
 */
class MouchardCompleterHttp implements MouchardCompleterInterface
{

    /**
     * @return $this
     */
    public function complete(MouchardMessage $message)
    {
        $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        $message->setUrl( $url);
        $message->setPost( $_POST);

        return $this;
    }

}
 No newline at end of file
Loading