KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64
User : www-data ( 33)
PHP Version : 8.2.12
Disable Function : NONE
Directory :  /var/www/parasoffline.edukrypt.in/application/modules/admin/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //var/www/parasoffline.edukrypt.in/application/modules/admin/controllers/Dospace.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
define('VIDEO_FOLDER_NAME', 'parasoffline');
define('PDF_FOLDER_NAME', 'parasoffline');

require(APPPATH . "third_party/vendor/autoload.php");

use AWS\S3\S3Client;
use Aws\S3\S3Client as S3S3Client;
use Aws\CognitoIdentity\CognitoIdentityClient;
use Aws\Exception\AwsException;
use Aws\S3\Exception\S3Exception;
use Aws\S3\PostObjectV4;


class Dospace extends Admin_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->library('form_builder');
        $this->load->model(['lecture_model', 'Main_model']);
        if (empty($this->session->userdata('user_id'))) {
            redirect('admin/panel/logout');
        }
    }

    public function do_upload()
    {
        $this->mViewData['p_type']  = "list";
        $this->mViewData['message'] = $this->session->flashdata('upload_success');

        $admin_id = $this->session->userdata('user_id');
        $query_c  = $this->db->where('admin_id', $admin_id)->get('courses');

        $courses = [];

        if ($query_c->num_rows() > 0) {
            $courses  = $query_c->result();
        }
        $this->mViewData['token']           = $this->Main_model->token();

        $this->mViewData['class']           = $this->Main_model->get('class');
        $this->mViewData['language']        = $this->Main_model->get('languages');
        $this->mViewData['language_groups'] = $this->Main_model->get('language_groups');

        $this->mViewData['video_folder_name']     = VIDEO_FOLDER_NAME;
        $this->mViewData['courses']         = $courses;
        $this->mTitle                       = 'DO Space Upload';

        $this->render('do_space/do_upload_view');
    }

    public function aws_temp_url()
    {
		
		
        if (empty($_POST['file']) && empty($_POST['type'])) {
            echo json_encode(['code' => 201, 'status' => false]);
            exit;
        }

        $accessKey = "FE5BNXOOPWNOWFVTIC6A";
        $secretKey = "WHm2+naAHIISj2/B1dzKixvpZ+3smaJdmaGeohr0efI";
        $region = "sgp1";
        $host = "https://sgp1.digitaloceanspaces.com";
        $bucket = "paras-storage";


        $s3 = new S3S3Client([
            'version' => 'latest',
            'region' => $region,
            'endpoint' => $host,
            'credentials' => [
                'key' => $accessKey,
                'secret' => $secretKey
            ]
        ]);

        $s3->putBucketCors([
            'Bucket' => $bucket, // REQUIRED
            'CORSConfiguration' => [ // REQUIRED
                'CORSRules' => [ // REQUIRED
                    [
                        'AllowedMethods' => ['POST', 'GET', 'HEAD', 'DELETE', 'PUT'], // REQUIRED
                        'AllowedHeaders' => ['*'],
                        'AllowedOrigins' => ['*'], // REQUIRED
                        'ExposeHeaders' => ['ETag'],
                        'MaxAgeSeconds' => 0
                    ],
                ],
            ]
        ]);


        $fileName = $_POST['file'];
        $uploadType = $_POST['type'];
		
		$fileType = "application/octet-stream";
		if($_POST['type']=='pdf')
		{
			$fileType = "application/pdf";
		}

        $formInputs = ['acl' => 'private'];

        if ($uploadType == 'video') {
            $fileKeyVal = 'videofile/' . $fileName;
        } else {
            $fileKeyVal = 'pdffile/' . $fileName;
        }

        $options = [
            ['acl' => 'private'],
            ['bucket' => $bucket],
            ['starts-with', '$key', $fileKeyVal],
            ['success_action_status' => '201'],
            ['x-amz-expires' => '3600'],
            ['Content-Type' => $fileType]
        ];

        $expires = '+2 hours';

        $postObject = new PostObjectV4($s3, $bucket, $formInputs, $options, $expires);

        $formAttributes = $postObject->getFormAttributes();

        $formInputs = $postObject->getFormInputs();

        echo json_encode(['code' => 200, 'status' => true, 'formAttributes' => $formAttributes, 'formInputs' => $formInputs]);
    }
	
	
    public function deleteAllObject()
    {
        if ($this->input->server('REQUEST_METHOD') === 'POST') {

            $len = count($this->input->post('videoids'));

            if ($len > 0) {
                $values = $this->input->post('videoids');
                foreach ($values as $value) {
                    $this->deleteObjectEtag($value);
                }
                echo true;
            } else {
                echo false;
            }
        }
    }

    public function deleteObjectEtag($etag)
    {
        if (!empty($etag)) {
            $videos =   $this->db->where('etag', $etag)->get('s3bucket')->row();
            if (!empty($videos)) {
                $path = $videos->path;

                $accessKey = "FE5BNXOOPWNOWFVTIC6A";
                $secretKey = "WHm2+naAHIISj2/B1dzKixvpZ+3smaJdmaGeohr0efI";
                $region = "sgp1";
                $host = "https://sgp1.digitaloceanspaces.com";
                $bucket = "paras-storage";

                $s3 = new S3S3Client([
                    'version' => 'latest',
                    'region' => $region,
                    'endpoint' => $host,
                    'credentials' => [
                        'key' => $accessKey,
                        'secret' => $secretKey
                    ]
                ]);

                $s3->putBucketCors([
                    'Bucket' => $bucket, // REQUIRED
                    'CORSConfiguration' => [ // REQUIRED
                        'CORSRules' => [ // REQUIRED
                            [
                                'AllowedMethods' => ['POST', 'GET', 'HEAD', 'DELETE', 'PUT'], // REQUIRED
                                'AllowedHeaders' => ['*'],
                                'AllowedOrigins' => ['*'], // REQUIRED
                                'ExposeHeaders' => ['ETag'],
                                'MaxAgeSeconds' => 0
                            ],
                        ],
                    ]
                ]);

                try {
                    $result = $s3->deleteObject([
                        'Bucket' => $bucket,
                        'Key' => $path
                    ]);
                    $deleteData = $this->db->where('path', $path)->delete('s3bucket');
                    // echo json_encode([['code' => 200], ['status' => true]]);
                } catch (S3Exception $e) {
                    // echo json_encode([['code' => 201], ['status' => false]]);
                }
            }
        }
    }

    public function deleteObject()
    {
        $jsonPost = file_get_contents('php://input');
        $arrayPost = json_decode($jsonPost);
        if (!empty($arrayPost)) {

            $accessKey = "FE5BNXOOPWNOWFVTIC6A";
            $secretKey = "WHm2+naAHIISj2/B1dzKixvpZ+3smaJdmaGeohr0efI";
            $region = "sgp1";
            $host = "https://sgp1.digitaloceanspaces.com";
            $bucket = "paras-storage";

            $s3 = new S3S3Client([
                'version' => 'latest',
                'region' => $region,
                'endpoint' => $host,
                'credentials' => [
                    'key' => $accessKey,
                    'secret' => $secretKey
                ]
            ]);

            $s3->putBucketCors([
                'Bucket' => $bucket, // REQUIRED
                'CORSConfiguration' => [ // REQUIRED
                    'CORSRules' => [ // REQUIRED
                        [
                            'AllowedMethods' => ['POST', 'GET', 'HEAD', 'DELETE', 'PUT'], // REQUIRED
                            'AllowedHeaders' => ['*'],
                            'AllowedOrigins' => ['*'], // REQUIRED
                            'ExposeHeaders' => ['ETag'],
                            'MaxAgeSeconds' => 0
                        ],
                    ],
                ]
            ]);

            try {
                $result = $s3->deleteObject([
                    'Bucket' => $bucket,
                    'Key' => $arrayPost->path
                ]);
                echo json_encode([['code' => 200], ['status' => true]]);
            } catch (S3Exception $e) {
                echo $e->getMessage() . PHP_EOL;
            }
        }
    }

    public function listObjects()
    {
        $accessKey = "FE5BNXOOPWNOWFVTIC6A";
        $secretKey = "WHm2+naAHIISj2/B1dzKixvpZ+3smaJdmaGeohr0efI";
        $region = "sgp1";
        $host = "https://sgp1.digitaloceanspaces.com";
        $bucket = "paras-storage";


        $s3 = new S3S3Client([
            'version' => 'latest',
            'region' => $region,
            'endpoint' => $host,
            'credentials' => [
                'key' => $accessKey,
                'secret' => $secretKey
            ]
        ]);

        $s3->putBucketCors([
            'Bucket' => $bucket, // REQUIRED
            'CORSConfiguration' => [ // REQUIRED
                'CORSRules' => [ // REQUIRED
                    [
                        'AllowedMethods' => ['POST', 'GET', 'HEAD', 'DELETE', 'PUT'], // REQUIRED
                        'AllowedHeaders' => ['*'],
                        'AllowedOrigins' => ['*'], // REQUIRED
                        'ExposeHeaders' => ['ETag'],
                        'MaxAgeSeconds' => 0
                    ],
                ],
            ]
        ]);

        $batchInsert = array();
        $admin_id = $this->session->userdata('user_id');

        try {
            $videos = $s3->getPaginator('ListObjects', [
                'Bucket' => $bucket,
                'Prefix' => 'videofile/'
            ]);

            $pdfs = $s3->getPaginator('ListObjects', [
                'Bucket' => $bucket,
                'Prefix' => 'pdffile/'
            ]);

            foreach ($videos as $video) {
                foreach ($video['Contents'] as $object) {
                    $aInsert = array(
                        'filename'  => basename($object['Key']),
                        'path'      => $object['Key'],
                        'size'      => $object['Size'],
                        'etag'      => trim($object['ETag'], '"'),
                        'type'      => 'video',
                        'admin_id'  => $admin_id,
                        'date'      => $object['LastModified']->format(\DateTime::ISO8601),
                    );
                    array_push($batchInsert, $aInsert);
                }
            }

            foreach ($pdfs as $pdf) {
                foreach ($pdf['Contents'] as $object) {
                    $aInsert = array(
                        'filename'  => basename($object['Key']),
                        'path'      => $object['Key'],
                        'size'      => $object['Size'],
                        'etag'      => trim($object['ETag'], '"'),
                        'type'      => 'pdf',
                        'admin_id'  => $admin_id,
                        'date'      => $object['LastModified']->format(\DateTime::ISO8601),
                    );
                    array_push($batchInsert, $aInsert);
                }
            }

            if (!empty($batchInsert)) {
                $this->db->where('admin_id', $admin_id)->delete('s3bucket');
            }
            $this->db->insert_batch('s3bucket', $batchInsert);
        } catch (S3Exception $e) {
            echo $e->getMessage() . PHP_EOL;
        }
    }

    public function do_list()
    {
        $this->mViewData['p_type']  = "list";
        $this->mViewData['message'] = $this->session->flashdata('upload_success');

        $admin_id = $this->session->userdata('user_id');

        $this->db->where('size > "0"');
        $do_list_query = $this->db->where('admin_id', $admin_id)->get('s3bucket');
        $do_list_result = false;
        if ($do_list_query->num_rows() > 0) {
            $do_list_result = $do_list_query->result();
        }

        $this->mViewData['do_lists'] = $do_list_result;
        $this->mViewData['folder_name'] = 'parasoffline';

        $this->mTitle = 'Video List';

        $this->render('do_space/do_list_view');
    }


    public function getObjectlink()
    {
        $jsonPost = file_get_contents('php://input');
        $arrayPost = json_decode($jsonPost);
        if (!empty($arrayPost)) {

            $accessKey = "FE5BNXOOPWNOWFVTIC6A";
            $secretKey = "WHm2+naAHIISj2/B1dzKixvpZ+3smaJdmaGeohr0efI";
            $region = "sgp1";
            $host = "https://sgp1.digitaloceanspaces.com";
            $bucket = "paras-storage";

            $s3 = new S3S3Client([
                'version' => 'latest',
                'region' => $region,
                'endpoint' => $host,
                'credentials' => [
                    'key' => $accessKey,
                    'secret' => $secretKey
                ]
            ]);

            $s3->putBucketCors([
                'Bucket' => $bucket, // REQUIRED
                'CORSConfiguration' => [ // REQUIRED
                    'CORSRules' => [ // REQUIRED
                        [
                            'AllowedMethods' => ['POST', 'GET', 'HEAD', 'DELETE', 'PUT'], // REQUIRED
                            'AllowedHeaders' => ['*'],
                            'AllowedOrigins' => ['*'], // REQUIRED
                            'ExposeHeaders' => ['ETag'],
                            'MaxAgeSeconds' => 0
                        ],
                    ],
                ]
            ]);

            try {
                //Creating a presigned URL
                $cmd = $s3->getCommand('GetObject', [
                    'Bucket' => $bucket,
                    'Key' => $arrayPost->path
                ]);

                $request = $s3->createPresignedRequest($cmd, '+55 minutes');

                // Get the actual presigned-url
                $presignedUrl = (string)$request->getUri();
                echo json_encode(['code' => 200, 'status' => true, 'url' => $presignedUrl]);
            } catch (S3Exception $e) {
                echo $e->getMessage() . PHP_EOL;
            }
        }
    }
}

Anon7 - 2021