src/Subscriber/EventSubscriber/Request/RequestSubscriber.php line 49

  1. <?php
  2. namespace App\Subscriber\EventSubscriber\Request;
  3. use App\Entity\System\Log\RequestLog;
  4. use App\Security\AppCustomAuthenticator;
  5. use App\Services\Php\System\GlobalFunctions;
  6. use App\Services\Php\System\SystemService;
  7. use App\Services\Php\Traits\LoggedDataTrait;
  8. use Doctrine\ORM\EntityManager;
  9. use Psr\Container\ContainerInterface;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  13. use Symfony\Component\HttpKernel\Event\RequestEvent;
  14. use Symfony\Component\HttpKernel\KernelEvents;
  15. use Symfony\Component\Security\Http\Util\TargetPathTrait;
  16. use Symfony\Component\Security\Csrf\CsrfToken;
  17. class RequestSubscriber implements EventSubscriberInterface
  18. {
  19.     use TargetPathTrait;
  20.     use LoggedDataTrait;
  21.     
  22.     private $container;
  23.     private $em;
  24.     private $ss;
  25.     
  26.     public function __construct(ContainerInterface $container)
  27.     {
  28.         $this->container $container;
  29.         
  30.         $this->em $this->container->get('doctrine')->getManager();
  31.         
  32.     }
  33.     
  34.     public static function getSubscribedEvents()
  35.     {
  36.         return [
  37.             RequestEvent::class => 'onKernelRequest',
  38.         ];
  39.     }
  40.     /**
  41.      * @Security("user.isEnabled()")
  42.      */
  43.     public function onKernelRequest(RequestEvent $event): void
  44.     {
  45.         
  46.         $gf = new GlobalFunctions();
  47.         
  48.         $request $event->getRequest();
  49.         if (
  50.             !$event->isMainRequest()
  51.             || $request->isXmlHttpRequest()
  52.             || AppCustomAuthenticator::LOGIN_ROUTE === $request->attributes->get('_route')
  53.         ) {
  54.             return;
  55.         }
  56.         
  57.         return;
  58.         
  59.         
  60.         $request $event->getRequest();
  61.         
  62.         $queryDATA = array();
  63.         foreach ($request->query->all() as $key => $query) {
  64.             if (is_array($query)) {
  65.                 foreach ($query as $arrayKey => $q) {
  66.                     if (is_array($q)) {
  67.                         foreach ($q as $key2 => $s) {
  68.                             if (is_array($s)) {
  69.                                 foreach ($s as $key3 => $t) {
  70.                                     $tc $gf->xss_clean($t);
  71.                                     $queryDATA[$key][$arrayKey][$key2][$key3] = $tc;
  72.                                 }
  73.                             } else {
  74.                                 $sc $gf->xss_clean($s);
  75.                                 $queryDATA[$key][$arrayKey][$key2] = $sc;
  76.                             }
  77.                         }
  78.                     } else {
  79.                         $qc $gf->xss_clean($q);
  80.                         $queryDATA[$key][$arrayKey] = $qc;
  81.                     }
  82.                 }
  83.             } else {
  84.                 $query $gf->xss_clean($query);
  85.                 $queryDATA[$key] = $query;
  86.             }
  87.         }
  88.         $request->query->replace($queryDATA);
  89.         
  90.         
  91.         $postDATA = array();
  92.         foreach ($request->request->all() as $key => $post_data) {
  93.             if (is_array($post_data)) {
  94.                 foreach ($post_data as $arrayKey => $q) {
  95.                     if (is_array($q)) {
  96.                         foreach ($q as $key2 => $s) {
  97.                             if (is_array($s)) {
  98.                                 foreach ($s as $key3 => $t) {
  99.                                     $tc $gf->xss_clean($t);
  100.                                     $postDATA[$key][$arrayKey][$key2][$key3] = $tc;
  101.                                 }
  102.                             } else {
  103.                                 $sc $gf->xss_clean($s);
  104.                                 $postDATA[$key][$arrayKey][$key2] = $sc;
  105.                             }
  106.                         }
  107.                     } else {
  108.                         $qc $gf->xss_clean($q);
  109.                         $postDATA[$key][$arrayKey] = $qc;
  110.                     }
  111.                 }
  112.             } else {
  113.                 $post_data $gf->xss_clean($post_data);
  114.                 $postDATA[$key] = $post_data;
  115.             }
  116.         }
  117.         
  118.         $request->request->replace($postDATA);
  119.         
  120.         
  121.         $status 0;
  122.         if ($event->isMainRequest()) {
  123.             $controller $event->getRequest()->attributes->get("_controller");
  124.             
  125.             $explodeController explode("\\"$controller);
  126.             $explodeControllerNameAndFunction explode("::"end($explodeController));
  127.             $controller_path $explodeControllerNameAndFunction[0];
  128.             $controller_function $explodeControllerNameAndFunction[1];
  129.             
  130.             
  131.             if ($controller_path and $controller_function and $status 1) {
  132.                 
  133.                 
  134.                 $disabled_url_path = array(
  135.                     "",
  136.                 );
  137. //                $security = $this->container->get('security.cont');
  138. //                $user = $security->getToken()->getUser();
  139.                 
  140.                 $ip_address $this->get_ip_address();
  141.                 $method $event->getRequest()->getMethod();
  142.                 $url $event->getRequest()->getPathInfo();
  143.                 
  144.                 $controller_name explode("\\"$controller_path);
  145.                 $bundle $controller_name[0];
  146.                 $controller end($controller_name);
  147.                 $url str_replace(strtolower($bundle) . "/"""ltrim(rtrim($url"/"), "/"));
  148.                 $url ltrim($url'/');
  149.              
  150.                 
  151.                 $localhost 1;
  152.                 if ($this->getLoggedUser(1) and $this->getLoggedUser() != "anon."
  153.                     and $this->getLoggedUser() > 0
  154.                     and ($ip_address != "127.0.0.1" or $localhost == 1) and (!in_array($url$disabled_url_path) and strpos($url"favicon.ico") === false)) {
  155.                     
  156.                     $sub_user_id $this->getLoggedUser();
  157.                     $user_id $this->getKullanici();
  158.                     
  159.                     
  160.                     if ($user_id == $sub_user_id$sub_user_id null;
  161.                     
  162.                     
  163.                     $methodID 0;
  164.                     if ($method === "GET"$methodID 1;
  165.                     if ($method === "POST"$methodID 2;
  166.                     
  167.                     
  168.                     $queryDATA = array();
  169.                     foreach ($event->getRequest()->query->all() as $key => $q) {
  170.                         if ($q != "*" and $q != ""$queryDATA["get"][$key] = $q;
  171.                     }
  172.                     
  173.                     
  174.                     foreach ($event->getRequest()->request->all() as $key => $q) {
  175.                         if ($q != "*" and $q != ""$queryDATA["post"][$key] = $q;
  176.                     }
  177.                     
  178.                     
  179.                     /** @var EntityManager $em */
  180.                     $em $this->em;
  181.                     
  182.                     if ($ip_address == null) {
  183.                         $ip_address $event->getRequest()->getClientIp();
  184.                     }
  185.                     
  186.                     $adminLog = new RequestLog();
  187.                     $adminLog->setBusinessId($user_id);
  188.                     $adminLog->setUserId($user_id);
  189.                     $adminLog->setCreatedAt(new \DateTime("now"));
  190.                     $adminLog->setIp($ip_address);
  191.                     $adminLog->setMethod($methodID);
  192.                     $adminLog->setUrlPath($url);
  193.                     $adminLog->setQuerys($queryDATA);
  194.                     $em->persist($adminLog);
  195.                     $em->flush();
  196.                     
  197.                 }
  198.             }
  199.         }
  200.         
  201.         
  202.         $this->saveTargetPath($request->getSession(), 'main'$request->getUri());
  203.     }
  204.     
  205.     
  206. }