From 1cd85eb9ae8bed0268e53c3a3ce3e593bcc627ab Mon Sep 17 00:00:00 2001 From: trp89 Date: Wed, 20 Mar 2024 09:30:24 -0400 Subject: [PATCH 1/8] Renamed files and removed index --- ClamavPlugin.inc.php => ClamavPlugin.php | 0 ...ingsForm.inc.php => ClamavSettingsForm.php | 0 ...andler.inc.php => ClamavVersionHandler.php | 0 index.php | 22 ------------------- locale/{de_DE => de}/locale.po | 0 locale/{en_US => en}/locale.po | 0 locale/{en_US => en}/locale.xml | 0 locale/{es_ES => es}/locale.po | 0 locale/{fr_FR => fr}/locale.po | 0 locale/{it_IT => it}/locale.po | 0 locale/{pt_PT => pt}/locale.po | 0 locale/{ro_RO => ro}/locale.po | 0 12 files changed, 22 deletions(-) rename ClamavPlugin.inc.php => ClamavPlugin.php (100%) rename ClamavSettingsForm.inc.php => ClamavSettingsForm.php (100%) rename ClamavVersionHandler.inc.php => ClamavVersionHandler.php (100%) delete mode 100644 index.php rename locale/{de_DE => de}/locale.po (100%) rename locale/{en_US => en}/locale.po (100%) rename locale/{en_US => en}/locale.xml (100%) rename locale/{es_ES => es}/locale.po (100%) rename locale/{fr_FR => fr}/locale.po (100%) rename locale/{it_IT => it}/locale.po (100%) rename locale/{pt_PT => pt}/locale.po (100%) rename locale/{ro_RO => ro}/locale.po (100%) diff --git a/ClamavPlugin.inc.php b/ClamavPlugin.php similarity index 100% rename from ClamavPlugin.inc.php rename to ClamavPlugin.php diff --git a/ClamavSettingsForm.inc.php b/ClamavSettingsForm.php similarity index 100% rename from ClamavSettingsForm.inc.php rename to ClamavSettingsForm.php diff --git a/ClamavVersionHandler.inc.php b/ClamavVersionHandler.php similarity index 100% rename from ClamavVersionHandler.inc.php rename to ClamavVersionHandler.php diff --git a/index.php b/index.php deleted file mode 100644 index 460cee3..0000000 --- a/index.php +++ /dev/null @@ -1,22 +0,0 @@ - diff --git a/locale/de_DE/locale.po b/locale/de/locale.po similarity index 100% rename from locale/de_DE/locale.po rename to locale/de/locale.po diff --git a/locale/en_US/locale.po b/locale/en/locale.po similarity index 100% rename from locale/en_US/locale.po rename to locale/en/locale.po diff --git a/locale/en_US/locale.xml b/locale/en/locale.xml similarity index 100% rename from locale/en_US/locale.xml rename to locale/en/locale.xml diff --git a/locale/es_ES/locale.po b/locale/es/locale.po similarity index 100% rename from locale/es_ES/locale.po rename to locale/es/locale.po diff --git a/locale/fr_FR/locale.po b/locale/fr/locale.po similarity index 100% rename from locale/fr_FR/locale.po rename to locale/fr/locale.po diff --git a/locale/it_IT/locale.po b/locale/it/locale.po similarity index 100% rename from locale/it_IT/locale.po rename to locale/it/locale.po diff --git a/locale/pt_PT/locale.po b/locale/pt/locale.po similarity index 100% rename from locale/pt_PT/locale.po rename to locale/pt/locale.po diff --git a/locale/ro_RO/locale.po b/locale/ro/locale.po similarity index 100% rename from locale/ro_RO/locale.po rename to locale/ro/locale.po From 1258ed72dda46f456af2f3b2cd52192cbf0b944d Mon Sep 17 00:00:00 2001 From: trp89 Date: Tue, 16 Apr 2024 10:01:36 -0400 Subject: [PATCH 2/8] Changed imports to use statements and other initial 3.4 changes --- ClamavPlugin.php | 80 +++++++++++++++++++++++++--------------- ClamavSettingsForm.php | 37 ++++++++++++------- ClamavVersionHandler.php | 9 ++++- css/clamav.css | 6 +-- 4 files changed, 84 insertions(+), 48 deletions(-) diff --git a/ClamavPlugin.php b/ClamavPlugin.php index 60c7703..3a19aa1 100644 --- a/ClamavPlugin.php +++ b/ClamavPlugin.php @@ -11,7 +11,26 @@ * * @brief ClamAV plugin class */ -import('lib.pkp.classes.plugins.GenericPlugin'); +//import('lib.pkp.classes.plugins.GenericPlugin'); +namespace APP\plugins\generic\clamav; + +use PKP\plugins\GenericPlugin; +use PKP\config\Config; +use PKP\plugins\Hook; +use PKP\linkAction\LinkAction; +use PKP\linkAction\request\AjaxModal; +use PKP\core\JSONMessage; +use PKP\validation\ValidatorFactory; +use PKP\core\PKPApplication; +use PKP\services\PKPSchemaService; +use Exception; //check this +use APP\core\Request; +use APP\core\Services; +use APP\core\Application; +use APP\plugins\generic\clamav\ClamavSettingsForm as ClamavSettingsForm; +use APP\plugins\generic\clamav\ClamavVersionHandler as ClamavVersionHandler; +use APP\template\TemplateManager; + class ClamScanFailureException extends Exception {}; class ClamavPlugin extends GenericPlugin { @@ -34,9 +53,9 @@ function register($category, $path, $mainContextId = NULL) { return true; if ($success && $this->getEnabled()) { // Enable Clam AV's preprocessing of uploaded files - HookRegistry::register('SubmissionFile::validate', array($this, 'clamscanHandleUpload')); + Hook::add('SubmissionFile::validate', array($this, 'clamscanHandleUpload')); // Create handler for AJAX call - HookRegistry::register('LoadHandler', array($this, 'setPageHandler')); + Hook::add('LoadHandler', array($this, 'setPageHandler')); } return $success; } @@ -72,14 +91,14 @@ function isSitePlugin() { * @return */ function _getBackwardsCompatibleContext() { - if(method_exists('Application', 'get')) { + //if(method_exists('Application', 'get')) { // OJS 3.2 and later $request = Application::get()->getRequest(); $context = $request->getContext(); - } else { + //} else { // OJS 3.1.2 and earlier - $context = Request::getContext(); - } + //$context = Request::getContext(); + //} return $context; } @@ -88,7 +107,7 @@ function _getBackwardsCompatibleContext() { */ function getActions($request, $verb) { $router = $request->getRouter(); - import('lib.pkp.classes.linkAction.request.AjaxModal'); + //import('lib.pkp.classes.linkAction.request.AjaxModal'); return array_merge( $this->getEnabled() ? array( new LinkAction( @@ -106,14 +125,14 @@ function getActions($request, $verb) { function manage($args, $request) { switch ($request->getUserVar('verb')) { case 'settings': - $contextID = (!is_null($this->_getBackwardsCompatibleContext()) ? $this->_getBackwardsCompatibleContext()->getId() : CONTEXT_SITE); + $contextID = (!is_null($this->_getBackwardsCompatibleContext()) ? $this->_getBackwardsCompatibleContext()->getId() : PKPApplication::CONTEXT_SITE); - AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_PKP_MANAGER); + //AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_PKP_MANAGER); $templateMgr = TemplateManager::getManager($request); - $templateMgr->register_function('plugin_url', array($this, 'smartyPluginUrl')); + $templateMgr->registerPlugin('function','plugin_url', array($this, 'smartyPluginUrl')); - $this->import('ClamavSettingsForm'); + //$this->import('ClamavSettingsForm'); $form = new ClamavSettingsForm($this, $contextID); if ($request->getUserVar('save')) { @@ -138,13 +157,13 @@ function manage($args, $request) { * @copydoc PKPPlugin::getTemplatePath */ function getTemplatePath($inCore = false) { - if(method_exists($this, 'getTemplateResource')) { + //if(method_exists($this, 'getTemplateResource')) { // OJS 3.1.2 and later return parent::getTemplatePath($inCore); - } else { - // OJS 3.1.1 and earlier 3.x releases - return parent::getTemplatePath($inCore) . 'templates' . DIRECTORY_SEPARATOR; - } + // } else { + // // OJS 3.1.1 and earlier 3.x releases + // return parent::getTemplatePath($inCore) . 'templates' . DIRECTORY_SEPARATOR; + // } } /** @@ -155,7 +174,7 @@ function getTemplatePath($inCore = false) { * */ function getClamVersion($path = '', $type=self::TYPE_EXECUTABLE) { if ($path === '') { - $path = $this->getSetting(CONTEXT_SITE, 'clamavPath'); + $path = $this->getSetting(PKPApplication::CONTEXT_SITE, 'clamavPath'); } if ($type === self::TYPE_EXECUTABLE && !empty($path) && is_executable($path)) { $version = exec($path . ' --version'); @@ -194,7 +213,7 @@ function _clamscanFile($uploadedFile) { if ($this->getClamVersion() && !empty($uploadedFile)) { $output = ""; $exitCode = ""; - $clamAVPath = $this->getSetting(CONTEXT_SITE, 'clamavPath'); + $clamAVPath = $this->getSetting(PKPApplication::CONTEXT_SITE, 'clamavPath'); $scan = exec($clamAVPath . ' --no-summary -i ' . $uploadedFile, $output, $exitCode); //process the result preg_match('/:(.*)/',$output[0],$matches); @@ -220,7 +239,7 @@ function _clamscanFile($uploadedFile) { * @return boolean|string */ function _clamDaemonFile($uploadedFile) { - $clamavSocketPath = $this->getSetting(CONTEXT_SITE, 'clamavSocketPath'); + $clamavSocketPath = $this->getSetting(PKPApplication::CONTEXT_SITE, 'clamavSocketPath'); $maxInstreamSize = 1024; // TODO: need to universalize this based on a plugin setting $output = ""; $errno = 0; @@ -292,8 +311,8 @@ function _clamDaemonFile($uploadedFile) { function _clamDaemonShortPolling($socket, $delay = 100000000, $intervals = 10) { // author's note: cludge cludge cludge cludge. TODO: look into long polling for unix sockets? $output = ""; - $intervals = $this->getSetting(CONTEXT_SITE, 'clamavSocketTimeout')*10; - $failover = $this->getSetting(CONTEXT_SITE, 'allowUnscannedFiles'); + $intervals = $this->getSetting(PKPApplication::CONTEXT_SITE, 'clamavSocketTimeout')*10; + $failover = $this->getSetting(PKPApplication::CONTEXT_SITE, 'allowUnscannedFiles'); for ($i = 0; $i < $intervals; $i++) { // sleep() does not accept fractional seconds and usleep uses a surprising amount of CPU, leaving us with time_nanosleep(). @@ -323,13 +342,13 @@ function clamscanHandleUpload($hookName, $args) { $uploadedFile = Config::getVar('files', 'files_dir') . '/' . $path; //scan for viruses if file exists if (null !== $file) { - $useSocket = $this->getSetting(CONTEXT_SITE, 'clamavUseSocket'); - import('lib.pkp.classes.validation.ValidatorFactory'); + $useSocket = $this->getSetting(PKPApplication::CONTEXT_SITE, 'clamavUseSocket'); + //import('lib.pkp.classes.validation.ValidatorFactory'); $schemaService = Services::get('schema'); $rejectionMessage = array(); - $validator = \ValidatorFactory::make( + $validator = ValidatorFactory::make( $props, - $schemaService->getValidationRules(SCHEMA_SUBMISSION_FILE, $allowedLocales), + $schemaService->getValidationRules(PKPSchemaService::SCHEMA_SUBMISSION_FILE, $allowedLocales), $rejectionMessage ); try { @@ -355,8 +374,8 @@ function clamscanHandleUpload($hookName, $args) { //Scanning errors will generate a custom exception catch (ClamScanFailureException $e){ //Couldn't scan, but ClamAV plugin settings are permissive, continue with submission anyway - $setting=$this->getSetting(CONTEXT_SITE, 'allowUnscannedFiles'); - if ( $this->getSetting(CONTEXT_SITE, 'allowUnscannedFiles')===self::UNSCANNED_ALLOW) { + $setting=$this->getSetting(PKPApplication::CONTEXT_SITE, 'allowUnscannedFiles'); + if ( $this->getSetting(PKPApplication::CONTEXT_SITE, 'allowUnscannedFiles')===self::UNSCANNED_ALLOW) { return false; } else { //Otherwise notify the user that there was an error @@ -389,9 +408,10 @@ function clamscanHandleUpload($hookName, $args) { public function setPageHandler($hookName, $params) { $page = $params[0]; $op = $params[1]; + $handler = $params[3]; if ($this->getEnabled() && $page === 'clamav' && $op === 'clamavVersion') { - $this->import('ClamavVersionHandler'); - define('HANDLER_CLASS', 'ClamavVersionHandler'); + //$this->import('ClamavVersionHandler'); + $params[3] = new ClamavVersionHandler(); return true; } return false; diff --git a/ClamavSettingsForm.php b/ClamavSettingsForm.php index bb5fe20..b5c97a7 100644 --- a/ClamavSettingsForm.php +++ b/ClamavSettingsForm.php @@ -11,7 +11,16 @@ * * @brief Form for the site admin to modify Clam AV plugin settings */ -import('lib.pkp.classes.form.Form'); +//import('lib.pkp.classes.form.Form'); +namespace APP\plugins\generic\clamav; + +use PKP\form\Form; +use PKP\form\validation\FormValidator; +use PKP\form\validation\FormValidatorPost; +use PKP\form\validation\FormValidatorCSRF; +use PKP\core\PKPApplication; +use APP\core\Application; +use APP\template\TemplateManager; class ClamavSettingsForm extends Form { @@ -38,7 +47,7 @@ function __construct($plugin, $contextId) { parent::__construct($plugin->getTemplatePath() . 'settingsForm.tpl'); } - $this->addCheck(new FormValidator($this, 'clamavPath', FORM_VALIDATOR_OPTIONAL_VALUE, 'plugins.generic.clamav.manager.settings.clamavPathRequired')); + $this->addCheck(new FormValidator($this, 'clamavPath', FormValidator::FORM_VALIDATOR_OPTIONAL_VALUE, 'plugins.generic.clamav.manager.settings.clamavPathRequired')); $this->addCheck(new FormValidatorPost($this)); $this->addCheck(new FormValidatorCSRF($this)); } @@ -48,21 +57,21 @@ function __construct($plugin, $contextId) { */ function initData() { $plugin = $this->_plugin; - $request = Application::getRequest(); + $request = Application::get()->getRequest(); $basePluginUrl = $request->getBaseUrl() . DIRECTORY_SEPARATOR . $plugin->getPluginPath() . DIRECTORY_SEPARATOR; - $this->setData('clamavPath', $plugin->getSetting(CONTEXT_SITE, 'clamavPath')); - $this->setData('clamavUseSocket', $plugin->getSetting(CONTEXT_SITE, 'clamavUseSocket')); - $this->setData('clamavSocketPath', $plugin->getSetting(CONTEXT_SITE, 'clamavSocketPath')); - $this->setData('unscannedFileOption', $plugin->getSetting(CONTEXT_SITE, 'allowUnscannedFiles')); - $this->setData('clamavSocketTimeout', $plugin->getSetting(CONTEXT_SITE, 'clamavSocketTimeout')); + $this->setData('clamavPath', $plugin->getSetting(PKPApplication::CONTEXT_SITE, 'clamavPath')); + $this->setData('clamavUseSocket', $plugin->getSetting(PKPApplication::CONTEXT_SITE, 'clamavUseSocket')); + $this->setData('clamavSocketPath', $plugin->getSetting(PKPApplication::CONTEXT_SITE, 'clamavSocketPath')); + $this->setData('unscannedFileOption', $plugin->getSetting(PKPApplication::CONTEXT_SITE, 'allowUnscannedFiles')); + $this->setData('clamavSocketTimeout', $plugin->getSetting(PKPApplication::CONTEXT_SITE, 'clamavSocketTimeout')); $this->setData('pluginJavascriptURL', $basePluginUrl . 'js' . DIRECTORY_SEPARATOR); $this->setData('pluginStylesheetURL', $basePluginUrl . 'css' . DIRECTORY_SEPARATOR); $this->setData('pluginLoadingImageURL', $basePluginUrl . 'images' . DIRECTORY_SEPARATOR . "spinner.gif"); $this->setData('pluginLoadingImageURL', $basePluginUrl . 'images' . DIRECTORY_SEPARATOR . "spinner.gif"); - $this->setData('pluginAjaxUrl', $request->getDispatcher()->url($request, ROUTE_PAGE, null, 'clamav', 'clamavVersion')); + $this->setData('pluginAjaxUrl', $request->getDispatcher()->url($request, PKPApplication::ROUTE_PAGE, null, 'clamav', 'clamavVersion')); $this->setData('baseUrl', $request->getBaseUrl()); } @@ -106,11 +115,11 @@ function execute(...$functionArgs) { $allowUnscannedFiles = $this->_plugin::UNSCANNED_DEFAULT; } - $this->_plugin->updateSetting(CONTEXT_SITE, 'clamavPath', $this->getData('clamavPath'), 'string'); - $this->_plugin->updateSetting(CONTEXT_SITE, 'clamavUseSocket', $this->getData('clamavUseSocket'), 'bool'); - $this->_plugin->updateSetting(CONTEXT_SITE, 'clamavSocketPath', $this->getData('clamavSocketPath'), 'string'); - $this->_plugin->updateSetting(CONTEXT_SITE, 'clamavSocketTimeout', $clamavSocketTimeout, 'int'); - $this->_plugin->updateSetting(CONTEXT_SITE, 'allowUnscannedFiles', $allowUnscannedFiles, 'string'); + $this->_plugin->updateSetting(PKPApplication::CONTEXT_SITE, 'clamavPath', $this->getData('clamavPath'), 'string'); + $this->_plugin->updateSetting(PKPApplication::CONTEXT_SITE, 'clamavUseSocket', $this->getData('clamavUseSocket'), 'bool'); + $this->_plugin->updateSetting(PKPApplication::CONTEXT_SITE, 'clamavSocketPath', $this->getData('clamavSocketPath'), 'string'); + $this->_plugin->updateSetting(PKPApplication::CONTEXT_SITE, 'clamavSocketTimeout', $clamavSocketTimeout, 'int'); + $this->_plugin->updateSetting(PKPApplication::CONTEXT_SITE, 'allowUnscannedFiles', $allowUnscannedFiles, 'string'); } /** diff --git a/ClamavVersionHandler.php b/ClamavVersionHandler.php index 1274d21..c00c4dc 100644 --- a/ClamavVersionHandler.php +++ b/ClamavVersionHandler.php @@ -17,7 +17,14 @@ * @brief Handle router requests for the clam AV version for the clam AV plugin. */ -import('classes.handler.Handler'); +//import('classes.handler.Handler'); +namespace APP\plugins\generic\clamav; + +use PKP\core\JSONMessage; +use PKP\security\Validation; +use PKP\plugins\PluginRegistry; +use APP\template\TemplateManager; +use APP\handler\Handler; class ClamavVersionHandler extends Handler { /** diff --git a/css/clamav.css b/css/clamav.css index 1182864..9000d64 100644 --- a/css/clamav.css +++ b/css/clamav.css @@ -49,7 +49,7 @@ #clamscanSettingsFormArea #clamavExecutableArea.valid::before, #clamdSettingsFormArea #clamdSocketArea.valid::before { background-color: green; - content: "\2713"; /* checkbox. Remember that CSS uses different entities than HTML. */ + content: "\2713"; /* checkbox. Remember that CSS uses different entities than HTML. */ } #clamscanSettingsFormArea #clamavExecutableArea.invalid::before, #clamdSettingsFormArea #clamdSocketArea.invalid::before { @@ -63,9 +63,9 @@ content: ""; } -#clamdSocketAdvanced div.full_description { +/*#clamdSocketAdvanced div.full_description { -} +}*/ #clamdSocketAdvancedSettings > div.pkp_helpers_quarter.inline { /* From a48e906a76b807f6f663e096ad1deaa95e8d1379 Mon Sep 17 00:00:00 2001 From: trp89 Date: Tue, 4 Jun 2024 13:29:32 -0400 Subject: [PATCH 3/8] Updated upload for clamscan and removed uneeded backwards compatability --- ClamavPlugin.php | 82 +++++++++++++----------------------------- ClamavSettingsForm.php | 12 ++----- 2 files changed, 27 insertions(+), 67 deletions(-) diff --git a/ClamavPlugin.php b/ClamavPlugin.php index 3a19aa1..282b74a 100644 --- a/ClamavPlugin.php +++ b/ClamavPlugin.php @@ -11,7 +11,7 @@ * * @brief ClamAV plugin class */ -//import('lib.pkp.classes.plugins.GenericPlugin'); + namespace APP\plugins\generic\clamav; use PKP\plugins\GenericPlugin; @@ -20,12 +20,9 @@ use PKP\linkAction\LinkAction; use PKP\linkAction\request\AjaxModal; use PKP\core\JSONMessage; -use PKP\validation\ValidatorFactory; use PKP\core\PKPApplication; -use PKP\services\PKPSchemaService; -use Exception; //check this -use APP\core\Request; -use APP\core\Services; +use PKP\file\TemporaryFileManager; +use Exception; use APP\core\Application; use APP\plugins\generic\clamav\ClamavSettingsForm as ClamavSettingsForm; use APP\plugins\generic\clamav\ClamavVersionHandler as ClamavVersionHandler; @@ -53,7 +50,7 @@ function register($category, $path, $mainContextId = NULL) { return true; if ($success && $this->getEnabled()) { // Enable Clam AV's preprocessing of uploaded files - Hook::add('SubmissionFile::validate', array($this, 'clamscanHandleUpload')); + Hook::add('submissionfilesuploadform::validate', array($this, 'clamscanHandleUpload')); // Create handler for AJAX call Hook::add('LoadHandler', array($this, 'setPageHandler')); } @@ -91,14 +88,8 @@ function isSitePlugin() { * @return */ function _getBackwardsCompatibleContext() { - //if(method_exists('Application', 'get')) { - // OJS 3.2 and later - $request = Application::get()->getRequest(); - $context = $request->getContext(); - //} else { - // OJS 3.1.2 and earlier - //$context = Request::getContext(); - //} + $request = Application::get()->getRequest(); + $context = $request->getContext(); return $context; } @@ -107,7 +98,6 @@ function _getBackwardsCompatibleContext() { */ function getActions($request, $verb) { $router = $request->getRouter(); - //import('lib.pkp.classes.linkAction.request.AjaxModal'); return array_merge( $this->getEnabled() ? array( new LinkAction( @@ -127,12 +117,10 @@ function manage($args, $request) { case 'settings': $contextID = (!is_null($this->_getBackwardsCompatibleContext()) ? $this->_getBackwardsCompatibleContext()->getId() : PKPApplication::CONTEXT_SITE); - //AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_PKP_MANAGER); $templateMgr = TemplateManager::getManager($request); $templateMgr->registerPlugin('function','plugin_url', array($this, 'smartyPluginUrl')); - //$this->import('ClamavSettingsForm'); $form = new ClamavSettingsForm($this, $contextID); if ($request->getUserVar('save')) { @@ -157,13 +145,7 @@ function manage($args, $request) { * @copydoc PKPPlugin::getTemplatePath */ function getTemplatePath($inCore = false) { - //if(method_exists($this, 'getTemplateResource')) { - // OJS 3.1.2 and later - return parent::getTemplatePath($inCore); - // } else { - // // OJS 3.1.1 and earlier 3.x releases - // return parent::getTemplatePath($inCore) . 'templates' . DIRECTORY_SEPARATOR; - // } + return parent::getTemplatePath($inCore); } /** @@ -334,40 +316,34 @@ function _clamDaemonShortPolling($socket, $delay = 100000000, $intervals = 10) { * @see submissionfilesuploadform::validate() */ function clamscanHandleUpload($hookName, $args) { - $fileId = $args[2]['fileId']; - $props = $args[2]; - $allowedLocales = $args[3]; - $file = Services::get('file')->get($fileId); - $path = $file->path; - $uploadedFile = Config::getVar('files', 'files_dir') . '/' . $path; + $uploadedFile = $_FILES['uploadedFile']['tmp_name']; //scan for viruses if file exists - if (null !== $file) { + if (null !== $uploadedFile) { $useSocket = $this->getSetting(PKPApplication::CONTEXT_SITE, 'clamavUseSocket'); - //import('lib.pkp.classes.validation.ValidatorFactory'); - $schemaService = Services::get('schema'); $rejectionMessage = array(); - $validator = ValidatorFactory::make( - $props, - $schemaService->getValidationRules(PKPSchemaService::SCHEMA_SUBMISSION_FILE, $allowedLocales), - $rejectionMessage - ); try { if ($useSocket === true) { $message = $this->_clamDaemonFile($uploadedFile); } else { - $message = $this->_clamscanFile($uploadedFile); + $tempFileManager = new TemporaryFileManager(); + $request = Application::get()->getRequest(); + $user = $request->getUser(); + $userId = $user->getId(); + $fileId = $tempFileManager->createTempFileFromExisting($uploadedFile, $userId); + $file = $tempFileManager->getFile($fileId, $userId); + $tempFilePath = $file->getFilePath(); + $message = $this->_clamscanFile($tempFilePath); + $tempFileManager->deleteById($fileId, $userId); } //No viruses found! Continue with submission - if ($message === false) { - return false; - } else { + if ($message !== false) { //ClamAV reported a virus or failed to complete the scan //Prepare to notify the user and halt the upload process $rejectionMessage = ["threatname"=>$message]; //If Clam found a virus, it will return the signature name as a string if ($message == true) { //create a user notification - $validator->errors()->add('clamAV::virusDetected', __('plugins.generic.clamav.uploadBlocked',$rejectionMessage)); + $args[0]->addError('clamAV::virusDetected', __('plugins.generic.clamav.uploadBlocked',$rejectionMessage)); } } } @@ -375,25 +351,16 @@ function clamscanHandleUpload($hookName, $args) { catch (ClamScanFailureException $e){ //Couldn't scan, but ClamAV plugin settings are permissive, continue with submission anyway $setting=$this->getSetting(PKPApplication::CONTEXT_SITE, 'allowUnscannedFiles'); - if ( $this->getSetting(PKPApplication::CONTEXT_SITE, 'allowUnscannedFiles')===self::UNSCANNED_ALLOW) { - return false; - } else { + if ( $this->getSetting(PKPApplication::CONTEXT_SITE, 'allowUnscannedFiles')!==self::UNSCANNED_ALLOW) { //Otherwise notify the user that there was an error //the user will see the general error message from the locale file - $validator->errors()->add('clamAV::failedToScan', __('plugins.generic.clamav.error')); + $args[0]->addError('clamAV::failedToSCan', __('plugins.generic.clamav.error')); } } //The file is considered unsafe. Interrupt submission process and clean up the working copy/metadata - $errors = $schemaService->formatValidationErrors($validator->errors(), $schemaService->get(SCHEMA_SUBMISSION_FILE), $allowedLocales); - - if ($args[0]===null){ - $args[0]=$errors; - } elseif (is_array($args[0])) { - array_push($args[0],$errors); - } - // returning true aborts processing - return true; + $args[1] = false; + return false; } } @@ -410,7 +377,6 @@ public function setPageHandler($hookName, $params) { $op = $params[1]; $handler = $params[3]; if ($this->getEnabled() && $page === 'clamav' && $op === 'clamavVersion') { - //$this->import('ClamavVersionHandler'); $params[3] = new ClamavVersionHandler(); return true; } diff --git a/ClamavSettingsForm.php b/ClamavSettingsForm.php index b5c97a7..303a9a1 100644 --- a/ClamavSettingsForm.php +++ b/ClamavSettingsForm.php @@ -38,15 +38,9 @@ class ClamavSettingsForm extends Form { function __construct($plugin, $contextId) { $this->_contextId = $contextId; $this->_plugin = $plugin; - - if (method_exists($plugin, 'getTemplateResource')) { - // OJS 3.1.2 and later - parent::__construct($plugin->getTemplateResource('settingsForm.tpl')); - } else { - // OJS 3.1.1 and earlier - parent::__construct($plugin->getTemplatePath() . 'settingsForm.tpl'); - } - + + parent::__construct($plugin->getTemplateResource('settingsForm.tpl')); + $this->addCheck(new FormValidator($this, 'clamavPath', FormValidator::FORM_VALIDATOR_OPTIONAL_VALUE, 'plugins.generic.clamav.manager.settings.clamavPathRequired')); $this->addCheck(new FormValidatorPost($this)); $this->addCheck(new FormValidatorCSRF($this)); From 5907d074295da812088ddd02c93710f99bf3eb25 Mon Sep 17 00:00:00 2001 From: trp89 Date: Wed, 17 Jul 2024 09:49:31 -0400 Subject: [PATCH 4/8] Removed some uneeded sections --- ClamavPlugin.php | 4 ++-- css/clamav.css | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/ClamavPlugin.php b/ClamavPlugin.php index 282b74a..233f7b7 100644 --- a/ClamavPlugin.php +++ b/ClamavPlugin.php @@ -24,8 +24,8 @@ use PKP\file\TemporaryFileManager; use Exception; use APP\core\Application; -use APP\plugins\generic\clamav\ClamavSettingsForm as ClamavSettingsForm; -use APP\plugins\generic\clamav\ClamavVersionHandler as ClamavVersionHandler; +use APP\plugins\generic\clamav\ClamavSettingsForm; +use APP\plugins\generic\clamav\ClamavVersionHandler; use APP\template\TemplateManager; class ClamScanFailureException extends Exception {}; diff --git a/css/clamav.css b/css/clamav.css index 9000d64..84058bf 100644 --- a/css/clamav.css +++ b/css/clamav.css @@ -63,10 +63,6 @@ content: ""; } -/*#clamdSocketAdvanced div.full_description { - -}*/ - #clamdSocketAdvancedSettings > div.pkp_helpers_quarter.inline { /* * sets this as a containing block, against which other absolutely- From 20bf343e21d028ffc5975b0228f3cb52fc733ca7 Mon Sep 17 00:00:00 2001 From: trp89 Date: Tue, 17 Sep 2024 10:34:38 -0400 Subject: [PATCH 5/8] removed extra space --- css/clamav.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/clamav.css b/css/clamav.css index 84058bf..e41f8aa 100644 --- a/css/clamav.css +++ b/css/clamav.css @@ -49,7 +49,7 @@ #clamscanSettingsFormArea #clamavExecutableArea.valid::before, #clamdSettingsFormArea #clamdSocketArea.valid::before { background-color: green; - content: "\2713"; /* checkbox. Remember that CSS uses different entities than HTML. */ + content: "\2713"; /* checkbox. Remember that CSS uses different entities than HTML. */ } #clamscanSettingsFormArea #clamavExecutableArea.invalid::before, #clamdSettingsFormArea #clamdSocketArea.invalid::before { From cc82da9fa52c6d0b9e66f7c87da5bceada5c7276 Mon Sep 17 00:00:00 2001 From: trp89 Date: Tue, 17 Sep 2024 10:58:54 -0400 Subject: [PATCH 6/8] removed comments --- ClamavSettingsForm.php | 2 +- ClamavVersionHandler.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ClamavSettingsForm.php b/ClamavSettingsForm.php index 303a9a1..72556e0 100644 --- a/ClamavSettingsForm.php +++ b/ClamavSettingsForm.php @@ -11,7 +11,7 @@ * * @brief Form for the site admin to modify Clam AV plugin settings */ -//import('lib.pkp.classes.form.Form'); + namespace APP\plugins\generic\clamav; use PKP\form\Form; diff --git a/ClamavVersionHandler.php b/ClamavVersionHandler.php index c00c4dc..b646386 100644 --- a/ClamavVersionHandler.php +++ b/ClamavVersionHandler.php @@ -17,7 +17,7 @@ * @brief Handle router requests for the clam AV version for the clam AV plugin. */ -//import('classes.handler.Handler'); + namespace APP\plugins\generic\clamav; use PKP\core\JSONMessage; From 0826ad62f0a89558d2c1da3f43eb5605f41dc79c Mon Sep 17 00:00:00 2001 From: trp89 Date: Wed, 18 Dec 2024 17:10:27 -0500 Subject: [PATCH 7/8] Removed _getBackwardsCompatibleContext --- ClamavPlugin.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/ClamavPlugin.php b/ClamavPlugin.php index 233f7b7..4fe4752 100644 --- a/ClamavPlugin.php +++ b/ClamavPlugin.php @@ -81,17 +81,6 @@ function getDescription() { function isSitePlugin() { return true; } - - /** - * Backwards-compatible method to retrieve the current context across - * multiple versions of PKP applicatiosn - * @return - */ - function _getBackwardsCompatibleContext() { - $request = Application::get()->getRequest(); - $context = $request->getContext(); - return $context; - } /** * @copydoc Plugin::getActions() @@ -115,7 +104,8 @@ function getActions($request, $verb) { function manage($args, $request) { switch ($request->getUserVar('verb')) { case 'settings': - $contextID = (!is_null($this->_getBackwardsCompatibleContext()) ? $this->_getBackwardsCompatibleContext()->getId() : PKPApplication::CONTEXT_SITE); + $context = Application::get()->getRequest()->getContext(); + $contextID = $context->getId(); $templateMgr = TemplateManager::getManager($request); From d4002468be2d2ffd6a2e18880551626ab60437e1 Mon Sep 17 00:00:00 2001 From: trp89 Date: Wed, 18 Dec 2024 17:13:43 -0500 Subject: [PATCH 8/8] Changed version number --- version.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.xml b/version.xml index 2eabe37..3535ff4 100644 --- a/version.xml +++ b/version.xml @@ -12,7 +12,7 @@ clamav plugins.generic - 4.0.0.3 + 4.1.0.0 2024-06-10 1 ClamavPlugin