forked from edgardmessias/glpi-singlesignon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.php
132 lines (105 loc) · 5.11 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
<?php
function plugin_singlesignon_display_login() {
global $CFG_GLPI;
$signon_provider = new PluginSinglesignonProvider();
$rows = $signon_provider->find('`is_active` = 1');
$html = [];
foreach ($rows as $row) {
$query = [];
if (isset($_REQUEST['redirect'])) {
$query['redirect'] = $_REQUEST['redirect'];
}
$url = PluginSinglesignonProvider::getCallbackUrl($row['id'], $query);
$html[] = '<a href="' . $url . '" class="singlesignon" style="color: #CFCFCF">' .
sprintf(__sso('[ Login with %s ]'), $row['name']) . '</a>';
}
echo implode("<br />\n", $html);
echo '<script type="text/javascript">
$(".singlesignon").on("click", 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();
}
});
</script>';
}
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());
// $query = "INSERT INTO `glpi_plugin_singlesignon_providers`
// (`id`, `name`, `serial`, `is_deleted`)
// VALUES (1, 'example 1', 'serial 1', 0),
// (2, 'example 2', 'serial 2', 0),
// (3, 'example 3', 'serial 3', 0)";
// $DB->query($query) or die("error populate glpi_plugin_example " . $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');");
}
Config::setConfigurationValues('singlesignon', [
'version' => PLUGIN_SINGLESIGNON_VERSION,
]);
return true;
}
function plugin_singlesignon_uninstall() {
global $DB;
$config = new Config();
$rows = $config->find("`context` LIKE 'singlesignon%'");
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;
}