Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/extmag/shiplab/Controller/Adminhtml/Logs/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/extmag/shiplab/Controller/Adminhtml/Logs/Download.php
<?php
/**
 * Copyright © Extmag. All rights reserved.
 */

namespace Extmag\Shiplab\Controller\Adminhtml\Logs;

use Error;
use Extmag\Shiplab\Controller\Adminhtml\Logs;
use Exception;
use Extmag\Shiplab\Model\ResourceModel\Logs\Collection;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Filesystem\DirectoryList;
use ZipArchive;

class Download extends Logs
{
    /**
     * Authorization level of a basic admin session
     *
     * @see _isAllowed()
     */
    public const ADMIN_RESOURCE = 'Extmag_Shiplab::shiplab_logs_download';

    /**
     * @return ResponseInterface|Redirect|ResultInterface
     */
    public function execute()
    {
        try {
            $fileName = $this->directoryList->getPath('var') . '/extmag-shipping-label-' . date("Y-m-d_H-i") . '.log';
            /**
             * @var Collection $collection
             */
            $collection = $this->logsCollectionFactory->create();
            $collection->setOrder('created_time', 'ASC');
            $collection->setPageSize(100);
            $size = $collection->getSize();
            $pages = ceil($size / 100);
            $fileData = '';
            /**
             * @var \Extmag\Shiplab\Model\Logs $model
             */
            for ($page = 1; $page <= $pages; $page++) {
                $collection->clear();
                $collection->setCurPage($page);
                $fileData = '';
                foreach ($collection as $model) {
                    $req = $this->manager->filterPrivateKeys(json_encode($model->getRequest()));
                    if (is_array($req)) {
                        $req = json_encode($req);
                    }

                    $resp = $this->manager->filterPrivateKeys(json_encode($model->getResponse()));
                    if (is_array($resp)) {
                        $resp = json_encode($resp);
                    }

                    $fileData .= $model->getCreatedTime() . ' ' . $model->getMode() . ' ' . $model->getType() . ' '
                        . $req
                        . "\n" . $resp . "\n\n";
                }

                $this->driver->filePutContents($fileName, $fileData, FILE_APPEND);
            }

            $zip = new ZipArchive();
            if ($this->driver->isExists($fileName.'.zip')) {
                $this->driver->deleteFile($fileName.'.zip');
            }

            if ($zip->open($fileName.'.zip', ZipArchive::CREATE) === true) {
                $zip->addFile($fileName, 'shipping-logs.log');
                $zip->close();
            }

            $fileData = $this->driver->fileGetContents($fileName.'.zip');
            $this->driver->deleteFile($fileName);
            $this->driver->deleteFile($fileName.'.zip');

            return $this->fileFactory->create(
                'extmag-shipping-label-' . date("Y-m-d_H-i") . '.zip',
                $fileData,
                DirectoryList::SYS_TMP,
                'application/zip'
            );
        } catch (Exception|Error $e) {
            $this->messageManager->addErrorMessage($e->getMessage());

            return $this->resultRedirectFactory->create()->setRefererOrBaseUrl();
        }
    }
}

Spamworldpro Mini