ヤミRoot VoidGate
User / IP
:
216.73.216.143
Host / Server
:
146.88.233.70 / dev.loger.cm
System
:
Linux hybrid1120.fr.ns.planethoster.net 3.10.0-957.21.2.el7.x86_64 #1 SMP Wed Jun 5 14:26:44 UTC 2019 x86_64
Command
|
Upload
|
Create
Mass Deface
|
Jumping
|
Symlink
|
Reverse Shell
Ping
|
Port Scan
|
DNS Lookup
|
Whois
|
Header
|
cURL
:
/
home
/
itrave
/
api
/
src
/
AppBundle
/
Manager
/
Viewing: ImageManager.php
<?php namespace AppBundle\Manager; use Doctrine\ORM\EntityManager; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; use Symfony\Component\Security\Core\Authorization\AuthorizationChecker; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Filesystem\Filesystem; use AppBundle\Entity\Image\CabImage; use AppBundle\Entity\Image\BusImage; use AppBundle\Entity\Image\AgencyImage; use AppBundle\Entity\Image\CompanyLogo; use AppBundle\Entity\Bus; use AppBundle\Entity\Cab; class ImageManager extends AbstractResourceManager { private $tokenStorage; private $authChecker; private $projectDir; private $imagesWebPath; private $busImageWebPath; private $CabImageWebPath; private $agencyImageWebPath; private $companyLogoWebPath; private $maxImageCount = 3; public function __construct(EntityManager $manager,TokenStorage $tokenStorage, AuthorizationChecker $authChecker, $projectDir, $imagesWebPath) { parent::__construct($manager); $this->tokenStorage = $tokenStorage; $this->authChecker = $authChecker; $this->projectDir = $projectDir; $this->imagesWebPath = $imagesWebPath; $this->busImagesWebPath = $imagesWebPath.'/bus'; $this->cabImagesWebPath = $imagesWebPath.'/cab'; $this->agencyImageWebPath = $imagesWebPath.'/agency'; $this->companyLogoWebPath = $imagesWebPath.'/company_logo'; } /** * Creates a new image * * @return Image */ public function createImage($imageFile, $resourceId, $imageType){ if( $imageFile->getMimeType() != "image/png" AND $imageFile->getMimeType() != "image/jpeg") throw new BadRequestHttpException("Expecting an image but '".$imageFile->getMimeType()."' supplied"); if( $imageFile->getClientSize() > 2000000) throw new BadRequestHttpException('File size too large: size must not exceed 2Mb'); if($imageType == "cab-image") return $this->createCabImage($imageFile, $resourceId); if($imageType == "bus-image") return $this->createBusImage($imageFile, $resourceId); if($imageType == "agency-image") return $this->createAgencyImage($imageFile, $resourceId); if($imageType == "company-logo") return $this->createCompanyLogo($imageFile, $resourceId); } /** * Creates a CabImage entity * * @return CabImage */ public function createCabImage($imageFile, $cabId){ // checks if the cab exists $cab = $this->manager->getRepository('AppBundle:Cab')->find($cabId); if( $cab == null) throw new NotFoundHttpException('Cab not found: ( with cabId = '.$cabId . ')'); // check if the cab has already 3 images if(count ($cab->getCabImages()) >= $this->maxImageCount) throw new BadRequestHttpException("Cab already has '".$this->maxImageCount . "' images."); // uploads the file $fileName = 'cab_'.$cabId.'_'.md5(uniqid()).'.'.$imageFile->guessExtension(); $targetDirectory = $this->projectDir. '/web'. $this->cabImagesWebPath; $uploaded = $this->uploadImageFile($imageFile, $fileName, $targetDirectory); // create and save the BusImage entity if($uploaded){ $fileWebPath = $this->cabImagesWebPath. '/'. $fileName; $cabImage = new CabImage(); $cabImage->setName($fileName); $cabImage->setWebPath($fileWebPath); $cabImage->setCab($cab); $this->manager->persist($cabImage); $this->manager->flush(); return $cabImage; } } /** * Create a BusImage entity * * @return BusImage */ public function createBusImage($imageFile, $busId){ // checks if the bus exists $bus = $this->manager->getRepository('AppBundle:Bus')->find($busId); if( $bus == null) throw new NotFoundHttpException('Bus not found: ( with busId = '.$busId . ')'); // check if the bus has already 3 images if(count ($bus->getBusImages()) >= $this->maxImageCount) throw new BadRequestHttpException("Bus already has '".$this->maxImageCount . "' images."); // uploads the file $fileName = 'bus_'.$busId.'_'.md5(uniqid()).'.'.$imageFile->guessExtension(); $targetDirectory = $this->projectDir. '/web'. $this->busImagesWebPath; $uploaded = $this->uploadImageFile($imageFile, $fileName, $targetDirectory); // create and save the BusImage entity if($uploaded){ $fileWebPath = $this->busImagesWebPath. '/'. $fileName; $busImage = new BusImage(); $busImage->setName($fileName); $busImage->setWebPath($fileWebPath); $busImage->setBus($bus); $this->manager->persist($busImage); $this->manager->flush(); return $busImage; } } /** * Create a AgencyImage entity * * @return AgencyImage */ public function createAgencyImage($imageFile, $agencyId){ // checks if the Agency exists $agency = $this->manager->getRepository('AppBundle:Agency')->find($agencyId); if( $agency == null) throw new NotFoundHttpException('Agency not found: ( with agencyId = '.$agencyId . ')'); // check if the agency has already 3 images if(count ($agency->getAgencyImages()) >= $this->maxImageCount) throw new BadRequestHttpException("Agency already has '".$this->maxImageCount . "' images."); // uploads the file $fileName = 'agency_'.$agencyId.'_'.md5(uniqid()).'.'.$imageFile->guessExtension(); $targetDirectory = $this->projectDir. '/web'. $this->agencyImageWebPath; $uploaded = $this->uploadImageFile($imageFile, $fileName, $targetDirectory); // create and save the AgencyImage entity if($uploaded){ $fileWebPath = $this->agencyImageWebPath. '/'. $fileName; $agencyImage = new AgencyImage(); $agencyImage->setName($fileName); $agencyImage->setWebPath($fileWebPath); $agencyImage->setAgency($agency); $this->manager->persist($agencyImage); $this->manager->flush(); return $agencyImage; } } /** * Create a CompanyLogo entity * * @return CompanyLogo */ public function createCompanyLogo($imageFile, $companyId){ // checks if the Company exists $company = $this->manager->getRepository('AppBundle:Company')->find($companyId); if( $company == null) throw new NotFoundHttpException('Company not found: ( with companyId = '.$companyId . ')'); // check if the company has a logo already if($company->getCompanyLogo()) throw new BadRequestHttpException("Company already has a logo."); // uploads the file $fileName = 'company'.$companyId.'_'.md5(uniqid()).'.'.$imageFile->guessExtension(); $targetDirectory = $this->projectDir. '/web'. $this->companyLogoWebPath; $uploaded = $this->uploadImageFile($imageFile, $fileName, $targetDirectory); // create and save the CompanyLogo entity if($uploaded){ $fileWebPath = $this->companyLogoWebPath. '/'. $fileName; $companyLogo = new CompanyLogo(); $companyLogo->setName($fileName); $companyLogo->setWebPath($fileWebPath); $companyLogo->setCompany($company); $this->manager->persist($companyLogo); $this->manager->flush(); return $companyLogo; } } /** * Saves an uploaded file and returns the * * @return uri of the file */ public function uploadImageFile($imageFile, $fileName, $directory){ $imageFile->move($directory, $fileName); return true; } /** * Delete an image * * @return boolean */ public function deleteImage($imageId, $imageType){ if($imageType == "cab-image") return $this->deleteCabImage($imageId); if($imageType == "bus-image") return $this->deleteBusImage($imageId); if($imageType == "agency-image") return $this->deleteAgencyImage($imageId); if($imageType == "company-logo") return $this->deleteCompanyLogo($imageId); } /** * Delete a bus image * * @return true */ public function deleteBusImage($imageId){ $image = $this->manager->getRepository('AppBundle:Image\\BusImage')->find($imageId); if( $image == null) throw new NotFoundHttpException('BusImage not found: ( with imageId = '.$imageId . ')'); // delete the image file $fileFullPath = $this->projectDir. '/web'.$image->getWebPath(); $deleted = $this->deleteImageFile($fileFullPath); if($deleted){ $this->manager->remove($image); $this->manager->flush(); return true; } } /** * Delete a cab image * * @return true */ public function deleteCabImage($imageId){ $image = $this->manager->getRepository('AppBundle:Image\\CabImage')->find($imageId); if( $image == null) throw new NotFoundHttpException('CabImage not found: ( with imageId = '.$imageId . ')'); // delete the image file $fileFullPath = $this->projectDir. '/web'.$image->getWebPath(); $deleted = $this->deleteImageFile($fileFullPath); if($deleted){ $this->manager->remove($image); $this->manager->flush(); return true; } } /** * Delete a AgencyImage image * * @return true */ public function deleteAgencyImage($imageId){ $image = $this->manager->getRepository('AppBundle:Image\\AgencyImage')->find($imageId); if( $image == null) throw new NotFoundHttpException('AgencyImage not found: ( with imageId = '.$imageId . ')'); // delete the image file $fileFullPath = $this->projectDir. '/web'.$image->getWebPath(); $deleted = $this->deleteImageFile($fileFullPath); if($deleted){ $this->manager->remove($image); $this->manager->flush(); return true; } } /** * Delete a CompanyLogo image * * @return true */ public function deleteCompanyLogo($imageId){ $image = $this->manager->getRepository('AppBundle:Image\\CompanyLogo')->find($imageId); if( $image == null) throw new NotFoundHttpException('CompanyLogo not found: ( with imageId = '.$imageId . ')'); // delete the image file $fileFullPath = $this->projectDir. '/web'.$image->getWebPath(); $deleted = $this->deleteImageFile($fileFullPath); if($deleted){ $this->manager->remove($image); $this->manager->flush(); return true; } } /** * Deletes an image file * * @return boolean */ public function deleteImageFile($fileFullPath){ $fileSystem = new FileSystem(); $fileSystem->remove($fileFullPath); return true; } /** * List Images * * @return array */ public function listImages($resourceId, $imageType){ if($imageType == "cab-image") return $this->listCabImages($resourceId); if($imageType == "bus-image") return $this->listBusImages($resourceId); if($imageType == "agency-image") return $this->listAgencyImages($resourceId); if($imageType == "company-logo") return $this->getCompanyLogo($resourceId); } /** * List CabImage of a Cab * * @return array<CabImage> */ public function listCabImages($cabId){ // checks if the cab exists $cab = $this->manager->getRepository('AppBundle:Cab')->find($cabId); if( $cab == null) throw new NotFoundHttpException('Cab not found: ( with cabId = '.$cabId . ')'); return $cab->getCabImages(); } /** * List BusImage of a Bus * * @return array<BusImage> */ public function listBusImages($busId){ // checks if the bus exists $bus = $this->manager->getRepository('AppBundle:Bus')->find($busId); if( $bus == null) throw new NotFoundHttpException('Bus not found: ( with busId = '.$busId . ')'); return $bus->getBusImages(); } /** * List AgencyImage of an Agency * * @return array<AgencyImage> */ public function listAgencyImages($agencyId){ // checks if the Agency exists $agency = $this->manager->getRepository('AppBundle:Agency')->find($agencyId); if( $agency == null) throw new NotFoundHttpException('Agency not found: ( with agencyId = '.$agencyId . ')'); return $agency->getAgencyImages(); } /** * Get the CompanyLogo of a Company. * * @return CompanyLogo */ public function getCompanyLogo($companyId){ // checks if the Company exists $company = $this->manager->getRepository('AppBundle:Company')->find($companyId); if( $company == null) throw new NotFoundHttpException('Company not found: ( with companyId = '.$companyId . ')'); return $company->getCompanyLogo(); } }
Coded With 💗 by
0x6ick