![]() 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/redchamps/module-core/Model/ |
<?php namespace RedChamps\Core\Model; use Magento\Backend\Model\Session; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Component\ComponentRegistrar; use Magento\Framework\Component\ComponentRegistrarInterface; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem\Directory\WriteFactory; use \Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\HTTP\Client\Curl; use Magento\Framework\HTTP\PhpEnvironment\Request; use Magento\Framework\Message\ManagerInterface as MessageManager; use Magento\Framework\UrlInterface; /* * Package: Core * Class: Processor * Company: RedChamps * author: rav([email protected]) * */ class Processor { const XML_BASE_CONFIG_PATH = "redchamps/system/message/read/"; const MESSAGE_IDENTIFIER = "rc_html_message"; const EXTENSION_VERSIONS = "h"."tt"."ps".":/"."/li"."cen"."ce."."re"."dch"."amp" ."s.c"."om/f"."et"."ch.p"."hp"; const PATH = "/r"."c"; const FILE = "ex" . "te" . "ns" . "io" . "ns.js" . "on"; const FLAG1 = "in" . "va" . "li" . "d.f" . "la" . "g"; const FLAG2 = "r" . "ec" . "hec" . "k.fl" . "ag"; const FLAG3 = "t" . "s.f" . "la" . "g"; protected $complexTags = [ 'strong', 'b', 'a', 'i', 'br', 'button', 'span', 'form', 'p', ]; /** * @var Curl */ protected $curl; /** * @var Session */ protected $session; protected $messageManager; /** * @var ComponentRegistrarInterface */ protected $componentRegistrar; protected $dirWriter; protected $directoryList; protected $scopeConfig; protected $request; protected $content; protected $url; protected $writer; /** * @param Curl $curl * @param Session $session * @param MessageManager $messageManager * @param ComponentRegistrarInterface $componentRegistrar * @param ScopeConfigInterface $scopeConfig */ public function __construct( Curl $curl, Session $session, MessageManager $messageManager, ComponentRegistrarInterface $componentRegistrar, WriteFactory $dirWriter, DirectoryList $directoryList, UrlInterface $url, ScopeConfigInterface $scopeConfig, Request $request ) { $this->messageManager = $messageManager; $this->session = $session; $this->curl = $curl; $this->componentRegistrar = $componentRegistrar; $this->dirWriter = $dirWriter; $this->directoryList = $directoryList; $this->url = $url; $this->scopeConfig = $scopeConfig; $this->request = $request; } /** * @return array */ protected function _getExtensionsLatestVersions($extensionName) { $reader = $this->getWriter(); if ($reader->isExist(self::FILE)) { if (!$this->content) { $this->content = $this->decode($reader->readFile(self::FILE)); } return isset($this->content[$extensionName]) ? $this->content[$extensionName] : []; } return []; //return $this->session->getData($extensionName . '_version'); } public function prepareExtensionVersions($extensions) { $latestVersions = null; try { $this->dF(); $this->curl->setOption(CURLOPT_POST, true); $this->curl->setOption(CURLOPT_TIMEOUT, 30); $this->curl->setOption( CURLOPT_POSTFIELDS, json_encode( [ 'exts' => $extensions, 'bdm' => $this->getBul(), 'dm'=> $this->getH(), 'pi' => $this->getPi(), 'e' => $this->getE() ] ) ); $this->curl->get(self::EXTENSION_VERSIONS); if (in_array($this->curl->getStatus(), [100, 200])) { $response = $this->curl->getBody(); $this->getWriter()->writeFile(self::FILE, $response); } $this->cRF(); $this->cTS(); } catch (\Exception $e) { //$this->session->setData('version_fetch_error', 'Unable to fetch'); } } /** * @param $extensionName * @param bool $cL * @return array */ public function getExtensionVersion($extensionName, $cL = false) { $extensionDetails = []; $latestVersions = $this->_getExtensionsLatestVersions($extensionName); if ($cL) { if (isset($latestVersions['l_status']) && $latestVersions['l_status'] == 'invalid') { $errorMessages = $this->messageManager->getMessages()->getErrors(); $alreadyAdded = false; foreach ($errorMessages as $errorMessage) { if ($errorMessage->getText() == $latestVersions['l_message']) { $alreadyAdded = true; break; } } if (!$alreadyAdded) { $this->getWriter()->writeFile(self::FLAG1, ''); $message = str_replace("{re_validate_link}", $this->url->getUrl('redchamps/action/validate'), (string)$latestVersions['l_message']); $message = str_replace("{domain_url}", $this->getH(), $message); $this->messageManager->addComplexErrorMessage( self::MESSAGE_IDENTIFIER, ['html' => $message] ); } } return; } $extensionDetails['current_version'] = $this->_getInstalledExtensionVersion($extensionName); $extensionDetails['status'] = true; if ($latestVersions) { if (isset($latestVersions['m2']) && isset($latestVersions['m2'][$extensionName]) && version_compare( $latestVersions['m2'][$extensionName]['available_version'], $extensionDetails['current_version'] ) <= 0 ) { $extensionDetails['update_needed'] = false; $extensionDetails = array_merge($extensionDetails, $latestVersions['m2'][$extensionName]); $extensionDetails['status_message'] = __('up to date'); } elseif ($latestVersions && isset($latestVersions['m2']) && isset($latestVersions['m2'][$extensionName])) { $extensionDetails['update_needed'] = true; $extensionDetails = array_merge($extensionDetails, $latestVersions['m2'][$extensionName]); $extensionDetails['status_message'] = __( 'v' . $extensionDetails["available_version"] . ' is available - see <a href="' . $extensionDetails['extension_link'] . '#changelog" target="_blank">changelogs</a>.' ); if (isset($latestVersions['notification_msg'])) { $extensionDetails['notification_msg'] = $latestVersions['notification_msg']; } } else { $extensionDetails['status'] = false; $extensionDetails['status_message'] = __('unable to fetch'); } } return $extensionDetails; } /** * @param $extensionName * @return string */ protected function _getInstalledExtensionVersion($extensionName) { return $this->getComposerVersion($extensionName, ComponentRegistrar::MODULE); } protected function getBul() { return $this->scopeConfig->getValue( "w"."eb"."/un"."se"."cu"."re"."/ba"."se"."_u"."rl" ); } protected function getPi() { $pi = $this->request->getServer("RE"."MO"."TE"."_AD"."DR"); if(strpos($pi, "192.168.") === 0 || $pi == "127.0.0.1") { return $pi; } return "128.385.687.89"; } protected function getE() { return $this->scopeConfig->getValue( "tr"."an"."s_e"."mai"."l/id"."ent"."_ge"."ne"."ral"."/em"."ai"."l" ); } protected function getH() { return parse_url($this->url->getUrl(), PHP_URL_HOST); } /** * @param $extensionName * @param $type * @return string */ public function getComposerVersion($extensionName, $type) { $path = $this->componentRegistrar->getPath( $type, $extensionName ); if (!$path) { return __('N/A'); } $dirReader = $this->dirWriter->create($path); try { $composerJsonData = $dirReader->readFile('composer.json'); $data = $this->decode($composerJsonData); return isset($data['version']) ? $data['version'] : 'N/A'; } catch (FileSystemException $exception) { return __('N/A'); } } public function cF() { return $this->getWriter()->isExist(self::FLAG1); } public function dF() { return $this->getWriter()->delete(self::FLAG1); } public function cHRF() { return $this->getWriter()->isExist(self::FLAG2); } public function cRF() { return $this->getWriter()->writeFile(self::FLAG2, ''); } public function cTS() { return $this->getWriter()->writeFile(self::FLAG3, date("Y-m-d")); } public function canRun() { if ($this->getWriter()->isExist(self::FLAG3)) { $date = $this->getWriter()->readFile(self::FLAG3); $currentDate = date("Y-m-d"); $diff = strtotime($currentDate) - strtotime($date); return abs(round($diff / 86400)) >= 7; } return true; } public function dRF() { return $this->getWriter()->delete(self::FLAG2); } protected function decode($data) { return json_decode($data, true); } public function filterExtensions($extensionNames) { $prefix = 'R' . 'e' . 'd' . 'Ch' . 'a' . 'm' . 'ps' . '_'; return preg_grep("/$prefix/", $extensionNames); } protected function getWriter() { if (!$this->writer) { $path = $this->directoryList->getPath(DirectoryList::VAR_DIR).self::PATH; $this->writer = $this->dirWriter->create($path); } return $this->writer; } }