-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathhook.php
224 lines (187 loc) · 8.13 KB
/
hook.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
function plugin_singlesignon_display_login() {
global $CFG_GLPI;
$signon_provider = new PluginSinglesignonProvider();
$condition = '`is_active` = 1';
if (version_compare(GLPI_VERSION, '9.4', '>=')) {
$condition = [$condition];
}
$rows = $signon_provider->find($condition);
$html = [];
foreach ($rows as $row) {
$query = [];
if (isset($_REQUEST['redirect'])) {
$query['redirect'] = $_REQUEST['redirect'];
}
$url = PluginSinglesignonToolbox::getCallbackUrl($row['id'], $query);
$html[] = PluginSinglesignonToolbox::renderButton($url, $row);
}
if (!empty($html)) {
echo '<div class="singlesignon-box">';
echo implode(" \n", $html);
echo PluginSinglesignonToolbox::renderButton('#', ['name' => __('GLPI')], 'vsubmit old-login');
echo '</div>';
?>
<style>
#display-login .singlesignon-box span {
display: inline-block;
margin: 5px;
}
#display-login .singlesignon-box .old-login {
display: none;
}
#boxlogin .singlesignon-box span {
display: block;
}
#boxlogin .singlesignon-box .vsubmit {
width: 100%;
height: 30px;
font-size: 1.3em !important;
text-align: center;
box-sizing: border-box;
}
#boxlogin .singlesignon-box .vsubmit img {
max-height: 20px;
max-width: 100px;
vertical-align: sub;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
// On click, open a popup
$(document).on("click", ".singlesignon.oauth-login", function(e) {
e.preventDefault();
var url = $(this).attr("href");
var left = ($(window).width() / 2) - (600 / 2);
var top = ($(window).height() / 2) - (800 / 2);
var newWindow = window.open(url, "singlesignon", "width=600,height=800,left=" + left + ",top=" + top);
if (window.focus) {
newWindow.focus();
}
});
var $boxLogin = $('#boxlogin');
var $form = $boxLogin.find('form');
var $boxButtons = $('.singlesignon-box');
// Move the buttons to before form
$boxButtons.prependTo($boxLogin);
$boxButtons.find('span').addClass('login_input');
// Show old form
$(document).on("click", ".singlesignon.old-login", function(e) {
e.preventDefault();
$boxButtons.slideToggle();
$form.slideToggle(function() {
$('#login_name').focus();
});
});
var $line = $('<p />', {
class: 'login_input'
}).prependTo($form);
var $backLogin = $('<label />', {
css: {
cursor: 'pointer'
},
text: "<< " + <?php echo json_encode(__('Back')) ?>,
}).appendTo($line);
$backLogin.on('click', function(e) {
e.preventDefault();
$boxButtons.slideToggle();
$form.slideToggle();
});
$form.hide();
});
</script>
<?php
}
}
function plugin_singlesignon_install() {
/* @var $DB DB */
global $DB;
$currentVersion = '0.0.0';
$default = [];
$current = Config::getConfigurationValues('singlesignon');
if (isset($current['version'])) {
$currentVersion = $current['version'];
}
foreach ($default as $key => $value) {
if (!isset($current[$key])) {
$current[$key] = $value;
}
}
Config::setConfigurationValues('singlesignon', $current);
if (!sso_TableExists("glpi_plugin_singlesignon_providers")) {
$query = "CREATE TABLE `glpi_plugin_singlesignon_providers` (
`id` int(11) NOT NULL auto_increment,
`type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`client_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`client_secret` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`scope` varchar(255) COLLATE utf8_unicode_ci NULL,
`extra_options` varchar(255) COLLATE utf8_unicode_ci NULL,
`url_authorize` varchar(255) COLLATE utf8_unicode_ci NULL,
`url_access_token` varchar(255) COLLATE utf8_unicode_ci NULL,
`url_resource_owner_details` varchar(255) COLLATE utf8_unicode_ci NULL,
`is_active` tinyint(1) NOT NULL DEFAULT '0',
`is_deleted` tinyint(1) NOT NULL default '0',
`comment` text COLLATE utf8_unicode_ci,
`date_mod` datetime DEFAULT NULL,
`date_creation` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `date_mod` (`date_mod`),
KEY `date_creation` (`date_creation`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->query($query) or die("error creating glpi_plugin_singlesignon_providers " . $DB->error());
}
// add display preferences
$query_display_pref = "SELECT id
FROM glpi_displaypreferences
WHERE itemtype = 'PluginSinglesignonProvider'";
$res_display_pref = $DB->query($query_display_pref);
if ($DB->numrows($res_display_pref) == 0) {
$DB->query("INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginSinglesignonProvider','2','1','0');");
$DB->query("INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginSinglesignonProvider','3','2','0');");
$DB->query("INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginSinglesignonProvider','5','4','0');");
$DB->query("INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginSinglesignonProvider','6','5','0');");
$DB->query("INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginSinglesignonProvider','10','6','0');");
}
if (version_compare($currentVersion, "1.2.0", '<')) {
$query = "ALTER TABLE `glpi_plugin_singlesignon_providers`
ADD `picture` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
ADD `bgcolor` varchar(7) DEFAULT NULL,
ADD `color` varchar(7) DEFAULT NULL";
$DB->query($query) or die("error adding picture column " . $DB->error());
}
if (version_compare($currentVersion, "1.3.0", '<')) {
$query = "CREATE TABLE `glpi_plugin_singlesignon_providers_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`plugin_singlesignon_providers_id` int(11) NOT NULL DEFAULT '0',
`users_id` int(11) NOT NULL DEFAULT '0',
`remote_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`plugin_singlesignon_providers_id`,`users_id`),
UNIQUE KEY `unicity_remote` (`plugin_singlesignon_providers_id`,`remote_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->query($query) or die("error creating glpi_plugin_singlesignon_providers_users " . $DB->error());
}
Config::setConfigurationValues('singlesignon', [
'version' => PLUGIN_SINGLESIGNON_VERSION,
]);
return true;
}
function plugin_singlesignon_uninstall() {
global $DB;
$config = new Config();
$condition = "`context` LIKE 'singlesignon%'";
if (version_compare(GLPI_VERSION, '9.4', '>=')) {
$condition = [$condition];
}
$rows = $config->find($condition);
foreach ($rows as $id => $row) {
$config->delete(['id' => $id]);
}
// Old version tables
if (sso_TableExists("glpi_plugin_singlesignon_providers")) {
$query = "DROP TABLE `glpi_plugin_singlesignon_providers`";
$DB->query($query) or die("error deleting glpi_plugin_singlesignon_providers");
}
return true;
}