-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.php
126 lines (101 loc) · 4.52 KB
/
setup.php
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
<?php
/**
* @package encryptfile
* @author Charlene Auger
* @copyright Copyright (c) 2015-2023 FactorFX
* @license AGPL License 3.0 or (at your option) any later version
* http://www.gnu.org/licenses/agpl-3.0-standalone.html
* @link https://www.factorfx.com
* @since 2023
*
* --------------------------------------------------------------------------
*/
define('PLUGIN_ENCRYPTFILE_VERSION', '1.1.1');
define('PLUGIN_ENCRYPTFILE_MIN_ITSMNG', '1.5.1');
define('PLUGIN_ENCRYPTFILE_MAX_ITSMNG', '1.5.1');
/**
* Init the hooks of the plugins -Needed
**/
function plugin_init_encryptfile() {
global $PLUGIN_HOOKS;
$PLUGIN_HOOKS['csrf_compliant']['encryptfile'] = true;
Plugin::registerClass(PluginEncryptfileProfile::class, ['addtabon' => ['Profile']]);
Plugin::registerClass(PluginEncryptfileEncrypt::class);
$PLUGIN_HOOKS['change_profile']['encryptfile'] = array(PluginEncryptfileProfile::class, 'initProfile');
if(Session::haveRight("plugin_encryptfile_configs", READ)) {
$PLUGIN_HOOKS['menu_toadd']['encryptfile'] = array('tools' => PluginEncryptfileConfig::class);
}
// Document
$PLUGIN_HOOKS['pre_item_add']['encryptfile']['Document'] = array(PluginEncryptfileEncrypt::class, 'beforeAddDocument');
$PLUGIN_HOOKS['item_add']['encryptfile']['Document'] = array(PluginEncryptfileEncrypt::class, 'afterAddDocument');
$PLUGIN_HOOKS['item_purge']['encryptfile']['Document'] = array(PluginEncryptfileConfig::class, 'afterPurgeDocument');
// Ticket attachment
$PLUGIN_HOOKS['pre_item_add']['encryptfile']['Ticket'] = array(PluginEncryptfileEncrypt::class, 'beforeAddTicket');
// Followup attachment
$PLUGIN_HOOKS['pre_item_add']['encryptfile']['ITILFollowup'] = array(PluginEncryptfileEncrypt::class, 'beforeAddFollowup');
//Task attachment
$PLUGIN_HOOKS['pre_item_add']['encryptfile']['TicketTask'] = array(PluginEncryptfileEncrypt::class, 'beforeAddTask');
// Formcreator submission
if ((new Plugin())->isActivated('formcreator')) {
$PLUGIN_HOOKS['pre_item_add']['encryptfile']['PluginFormcreatorFormAnswer'] = array(PluginEncryptfileEncrypt::class, 'beforeAddFormAnswer');
}
$canDecrypt = false;
$canEncrypt = false;
if(isset($_SESSION["glpiID"]) && isset($_SESSION["glpiactiveprofile"]["interface"]) && $_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
$canDecrypt = Profile::haveUserRight($_SESSION["glpiID"], "plugin_encryptfile_encrypt", READ, $_SESSION["glpiactive_entity"]);
$canEncrypt = Profile::haveUserRight($_SESSION["glpiID"], "plugin_encryptfile_encrypt", UPDATE, $_SESSION["glpiactive_entity"]);
}
// Load js only if read right checked
if(Session::haveRight("plugin_encryptfile_encrypt", READ) || $canDecrypt) {
$PLUGIN_HOOKS['add_javascript']['encryptfile'][] = 'js/read.js';
}
if(Session::haveRight("plugin_encryptfile_configs", READ)) {
$PLUGIN_HOOKS['add_javascript']['encryptfile'][] = 'js/function.js';
}
if ((new Plugin())->isInstalled('encryptfile')) {
$PluginEncryptfileConfig = new PluginEncryptfileConfig();
if(isset($_SESSION["glpiactiveprofile"]["id"])) {
$secretKeyId = $PluginEncryptfileConfig->getSecretKeyId($_SESSION["glpiactiveprofile"]["id"]);
}
// Load js only if write right checked and have a configured key
if((Session::haveRight("plugin_encryptfile_encrypt", UPDATE) || $canEncrypt) && !is_null($secretKeyId)) {
if(in_array(explode("?", $_SERVER['REQUEST_URI'])[0], $PluginEncryptfileConfig->getAuthorizedItem($secretKeyId))) {
$PLUGIN_HOOKS['add_javascript']['encryptfile'][] = 'js/write.js';
}
}
}
}
/**
* Get the name and the version of the plugin - Needed
**/
function plugin_version_encryptfile() {
return [
'name' => __("Encrypted file", "encryptfile"),
'version' => PLUGIN_ENCRYPTFILE_VERSION,
'author' => 'Charlène AUGER',
'license' => 'GPLv2+',
'homepage' => 'https://github.com/itsmng/encryptfile',
'requirements' => [
'glpi' => [
'min' => PLUGIN_ENCRYPTFILE_MIN_ITSMNG,
'dev' => false
]
]
];
}
/**
* Optional : check prerequisites before install : may print errors or add to message after redirect
**/
function plugin_encryptfile_check_prerequisites() {
if (version_compare(ITSM_VERSION, PLUGIN_ENCRYPTFILE_MIN_ITSMNG, 'lt') && version_compare(ITSM_VERSION, PLUGIN_ENCRYPTFILE_MAX_ITSMNG, 'ge')) {
return false;
}
return true;
}
// Uninstall process for plugin : need to return true if succeeded : may display messages or add to message after redirect
/**
* @return bool
*/
function plugin_encryptfile_check_config() {
return true;
}