Commit 9134a08d authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Mise en place d'un système de détection de localisation pour savoir si le...

Mise en place d'un système de détection de localisation pour savoir si le client est dans l'établissement ou non
parent 0063bdff
Pipeline #6064 failed with stage
in 14 seconds
......@@ -6,6 +6,8 @@ use UnicaenApp\Controller\CacheControllerFactory;
use UnicaenApp\Controller\InstadiaControllerFactory;
use UnicaenApp\Form\View\Helper\FormControlGroup;
use UnicaenApp\Form\View\Helper\FormControlGroupFactory;
use UnicaenApp\HostLocalization\HostLocalizationUnicaen;
use UnicaenApp\HostLocalization\HostLocalizationUnicaenFactory;
use UnicaenApp\Message\View\Helper\MessageHelper;
use UnicaenApp\Message\View\Helper\MessageHelperFactory;
use UnicaenApp\Service\InstadiaServiceFactory;
......@@ -314,6 +316,7 @@ return [
MailerService::class => MailerServiceFactory::class,
RunSQLService::class => RunSQLServiceFactory::class,
'instadia' => InstadiaServiceFactory::class,
HostLocalizationUnicaen::class => HostLocalizationUnicaenFactory::class,
],
'shared' => [
'MouchardListenerErrorHandler' => false,
......@@ -336,6 +339,7 @@ return [
],
'aliases' => [
'MailerService' => MailerService::class,
'HostLocalization' => HostLocalizationUnicaen::class,
]
],
'form_elements' => [
......
<?php
namespace UnicaenApp\HostLocalization;
/**
* Description of HostLocalizationAwareTrait
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
trait HostLocalizationAwareTrait
{
/**
* @var HostLocalizationInterface
*/
private $hostLocalization;
/**
* @param HostLocalizationInterface $hostLocalization
*
* @return self
*/
public function setHostLocalization(HostLocalizationInterface $hostLocalization)
{
$this->hostLocalization = $hostLocalization;
return $this;
}
/**
* @return HostLocalizationInterface
*/
public function getHostLocalization(): HostLocalizationInterface
{
return $this->hostLocalization;
}
}
\ No newline at end of file
<?php
namespace UnicaenApp\HostLocalization;
interface HostLocalizationInterface
{
/**
* Renvoie true si le'utilisateur utilise une machine connectée au réseau de l'établissement
* ou bien si la machine est hors réseau
*
* @return bool
*/
public function inEtablissement(): bool;
}
\ No newline at end of file
<?php
namespace UnicaenApp\HostLocalization;
class HostLocalizationUnicaen implements HostLocalizationInterface
{
/**
* Renvoie true si le'utilisateur utilise une machine connectée au réseau de l'établissement
* ou bien si la machine est hors réseau
*
* @return bool
*/
public function inEtablissement(): bool
{
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$forwarded = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
$ipInterne = '10.';
$proxies = [
'10.14.128.39',
'10.14.128.100',
'10.14.128.100',
'10.14.128.101',
'10.14.128.137',
];
$reverseProxies = [
'193.55.120.23',
'193.55.120.24',
'193.55.120.25',
];
// Si on est en direct et en interne sans passer par le proxy (pas de redirection)
if (0 === strpos($ip,$ipInterne) && $forwarded === '') return true;
// Si on est en interne, que l'on sort puis on re-rentre en passant par le reverse proxy
if (in_array($ip,$reverseProxies) && 0 === strpos($forwarded,$ipInterne)) return true;
// Si on est en interne, que l'on passe par le proxy en interne
if (in_array($ip,$proxies) && 0 === strpos($forwarded,$ipInterne)) return true;
// Sinon, on vient de l'extérieur
return false;
}
}
\ No newline at end of file
<?php
namespace UnicaenApp\HostLocalization;
use Interop\Container\ContainerInterface;
class HostLocalizationUnicaenFactory
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$service = new HostLocalizationUnicaen();
return $service;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment