-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathClamavSettingsForm.php
More file actions
139 lines (116 loc) · 5.12 KB
/
Copy pathClamavSettingsForm.php
File metadata and controls
139 lines (116 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* @file plugins/generic/clamav/ClamavSettingsForm.inc.php
*
* Copyright (c) 2018 University of Pittsburgh
* Distributed under the GNU GPL v2 or later. For full terms see the LICENSE file.
*
* @class ClamavSettingsForm
* @ingroup plugins_generic_clamav
*
* @brief Form for the site admin to modify Clam AV plugin settings
*/
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 {
/** @var int */
var $_contextId;
/** @var object */
var $_plugin;
/**
* Constructor
* @param $plugin ClamavSettingsForm
* @param $contextId int
*/
function __construct($plugin, $contextId) {
$this->_contextId = $contextId;
$this->_plugin = $plugin;
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));
}
/**
* Initialize form data.
*/
function initData() {
$plugin = $this->_plugin;
$request = Application::get()->getRequest();
$basePluginUrl = $request->getBaseUrl() . DIRECTORY_SEPARATOR . $plugin->getPluginPath() . DIRECTORY_SEPARATOR;
$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, PKPApplication::ROUTE_PAGE, null, 'clamav', 'clamavVersion'));
$this->setData('baseUrl', $request->getBaseUrl());
}
/**
* Assign form data to user-submitted data.
*/
function readInputData() {
$this->readUserVars(array('clamavPath', 'clamavUseSocket', 'clamavSocketPath', 'clamavSocketTimeout', 'allowUnscannedFiles',));
}
/**
* Fetch the form.
* @copydoc Form::fetch()
*/
function fetch($request, $template = NULL, $display = false) {
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pluginName', $this->_plugin->getName());
$unscannedFileOptions = array(
'allow' => __('plugins.generic.clamav.manager.settings.allowUnscannedFiles.allow'),
'block' => __('plugins.generic.clamav.manager.settings.allowUnscannedFiles.block')
);
$templateMgr->assign('unscannedFileOptions', $unscannedFileOptions);
return parent::fetch($request);
}
/**
* Save settings.
*/
function execute(...$functionArgs) {
// set defaults if we have them. Not using built-in validation because
// these fields aren't mandatory.
$clamavSocketTimeout = $this->getData('clamavSocketTimeout');
if((int) $clamavSocketTimeout < 1) {
$clamavSocketTimeout = $this->_plugin::TIMEOUT_DEFAULT;
}
$allowUnscannedFiles = $this->getData('allowUnscannedFiles');
if((string) $allowUnscannedFiles !== $this->_plugin::UNSCANNED_ALLOW && (string) $allowUnscannedFiles !== $this->_plugin::UNSCANNED_BLOCK) {
$allowUnscannedFiles = $this->_plugin::UNSCANNED_DEFAULT;
}
$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');
}
/**
* Get a version for display from a clamscan path
* @param $path string
* @return string
*/
function displayVersion($path) {
$plugin = $this->_plugin;
$useSocket = $plugin->getSetting(\PKP\core\PKPApplication::CONTEXT_SITE, 'clamavUseSocket');
$type = $useSocket
? \APP\plugins\generic\clamav\ClamavPlugin::TYPE_SOCKET
: \APP\plugins\generic\clamav\ClamavPlugin::TYPE_EXECUTABLE;
$version = $plugin->getClamVersion($path, $type);
if ($version === '') {
$version = __('plugins.generic.clamav.manager.settings.noversion');
}
return $version;
}
}
?>