-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhook.php
More file actions
130 lines (117 loc) · 4.65 KB
/
hook.php
File metadata and controls
130 lines (117 loc) · 4.65 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
<?php
/*
-------------------------------------------------------------------------
LibreSign plugin for GLPI
Copyright (C) 2021 by the LibreSign Development Team.
https://github.com/pluginsGLPI/libresign
-------------------------------------------------------------------------
LICENSE
This file is part of LibreSign.
LibreSign is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LibreSign is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LibreSign. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/**
* Plugin install process
*
* @return boolean
*/
function plugin_libresign_install() {
global $DB;
if (!$DB->tableExists("glpi_plugin_libresign_files")) {
$query = "CREATE TABLE glpi.glpi_plugin_libresign_files (
ticket_id int(11) NOT NULL,
request_date timestamp DEFAULT now() NOT NULL,
response_date timestamp DEFAULT NULL NULL,
user_id int(11) NOT NULL,
file_uuid varchar(36) NOT NULL
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci;";
if ($DB->doQuery($query) === false) {
throw new RuntimeException($DB->error());
}
}
if (!$DB->tableExists('glpi_plugin_libresign_configs')) {
$query = "CREATE TABLE `glpi_plugin_libresign_configs`(
`id` int(11) NOT NULL,
`nextcloud_url` VARCHAR(255) NULL,
`username` VARCHAR(255) NULL,
`password` VARCHAR(255) NULL,
`callback_token` VARCHAR(64) NULL,
`default_display_name` VARCHAR(255) NULL,
`default_filename` VARCHAR(255) NULL,
`default_request_comment` TEXT NULL,
`default_accept_comment` TEXT NULL,
`system_user_id` int(11) NOT NULL DEFAULT 0,
`date_mod` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
if ($DB->doQuery($query) === false) {
throw new RuntimeException(
'Error in creating glpi_plugin_libresign_configs<br>' . $DB->error()
);
}
$DB->insertOrDie(
'glpi_plugin_libresign_configs', [
'id' => 1,
'nextcloud_url' => '$DOMAIN/apps/libresign/api/0.1/sign/register',
'username' => null,
'password' => null,
'callback_token' => bin2hex(random_bytes(32)),
'default_display_name' => 'firstname',
'default_filename' => t_libresign('Accept'),
'default_request_comment' => t_libresign('Validate GLPI Ticket'),
'default_accept_comment' => t_libresign('Digitally signed on LibreSign'),
'system_user_id' => 0,
'date_mod' => null
],
'Error during update glpi_plugin_pdf_configs<br>' . $DB->error()
);
} elseif (!$DB->fieldExists('glpi_plugin_libresign_configs', 'callback_token')) {
$query = "ALTER TABLE `glpi_plugin_libresign_configs`
ADD COLUMN `callback_token` VARCHAR(64) NULL
AFTER `password`";
if ($DB->doQuery($query) === false) {
throw new RuntimeException(
'Error while adding callback_token to glpi_plugin_libresign_configs<br>' . $DB->error()
);
}
$DB->update('glpi_plugin_libresign_configs', [
'callback_token' => bin2hex(random_bytes(32))
], [
'id' => 1
]);
}
return true;
}
/**
* Plugin uninstall process
*
* @return boolean
*/
function plugin_libresign_uninstall() {
global $DB;
if ($DB->tableExists("glpi_plugin_libresign_files")) {
$query = "DROP TABLE `glpi_plugin_libresign_files`";
if ($DB->doQuery($query) === false) {
throw new RuntimeException("error deleting glpi_plugin_libresign_files");
}
}
if ($DB->tableExists('glpi_plugin_libresign_configs')) {
$query = "DROP TABLE `glpi_plugin_libresign_configs`";
if ($DB->doQuery($query) === false) {
throw new RuntimeException("error deleting glpi_plugin_libresign_configs");
}
}
return true;
}