1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* ****************************************************************************** |
5
|
|
|
* Copyright 2011-2017 DANTE Ltd. and GÉANT on behalf of the GN3, GN3+, GN4-1 |
6
|
|
|
* and GN4-2 consortia |
7
|
|
|
* |
8
|
|
|
* License: see the web/copyright.php file in the file structure |
9
|
|
|
* ****************************************************************************** |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* |
14
|
|
|
* |
15
|
|
|
* This is the definition of the CAT class |
16
|
|
|
* @author Stefan Winter <[email protected]> |
17
|
|
|
* @author Tomasz Wolniewicz <[email protected]> |
18
|
|
|
* |
19
|
|
|
* @package Developer |
20
|
|
|
*/ |
21
|
|
|
/** |
22
|
|
|
* necessary includes |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace core; |
26
|
|
|
|
27
|
|
|
if (session_status() != PHP_SESSION_ACTIVE) { |
28
|
|
|
session_start(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Define some variables which need to be globally accessible |
33
|
|
|
* and some general purpose methods |
34
|
|
|
* |
35
|
|
|
* @author Stefan Winter <[email protected]> |
36
|
|
|
* @author Tomasz Wolniewicz <[email protected]> |
37
|
|
|
* |
38
|
|
|
* @package Developer |
39
|
|
|
*/ |
40
|
|
|
class CAT extends \core\common\Entity { |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* which version is this? |
44
|
|
|
* even if we are unreleased, keep track of internal version-to-be |
45
|
|
|
* developers need to set this in code. The user-displayed string |
46
|
|
|
* is generated into $CAT_VERSION_STRING and $CAT_COPYRIGHT below |
47
|
|
|
*/ |
48
|
|
|
const VERSION_MAJOR = 2; |
49
|
|
|
const VERSION_MINOR = 0; |
50
|
|
|
const VERSION_PATCH = 0; |
51
|
|
|
const VERSION_EXTRA = "alpha2"; |
52
|
|
|
const RELEASE_VERSION = FALSE; |
53
|
|
|
const USER_API_VERSION = 2; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* trying to keep up with the name changes of copyright holder and consortia |
57
|
|
|
* updating those on *one* place should change display everywhere! |
58
|
|
|
*/ |
59
|
|
|
const COPYRIGHT_HOLDER = "DANTE Ltd. and GÉANT"; |
60
|
|
|
const COPYRIGHT_CONSORTIA = "the GN3, GN3+, GN4-1 and GN4-2 consortia"; |
61
|
|
|
const COPYRIGHT_MIN_YEAR = 2011; |
62
|
|
|
const COPYRIGHT_MAX_YEAR = 2017; |
63
|
|
|
|
64
|
|
|
/* |
65
|
|
|
* This is the user-displayed string; controlled by the four options above |
66
|
|
|
* It is generated in the constructor. |
67
|
|
|
* |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
|
71
|
|
|
public $CAT_VERSION_STRING; |
72
|
|
|
|
73
|
|
|
/* |
74
|
|
|
* The entire copyright line, generated in constructor |
75
|
|
|
*/ |
76
|
|
|
public $CAT_COPYRIGHT; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* the custom displayable variant of the term 'federation' |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
public $nomenclature_fed; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* the custom displayable variant of the term 'institution' |
86
|
|
|
* @var string |
87
|
|
|
*/ |
88
|
|
|
public $nomenclature_inst; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* all known federation, in an array with ISO short name as an index, and localised version of the pretty-print name as value. |
92
|
|
|
* The static value is only filled with meaningful content after the first object has been instantiated. That is because it is not |
93
|
|
|
* possible to define static properties with function calls like _(). |
94
|
|
|
* |
95
|
|
|
* @var array of all known federations |
96
|
|
|
*/ |
97
|
|
|
public $knownFederations; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* the default database to query in this class. |
101
|
|
|
*/ |
102
|
|
|
const DB_TYPE = "INST"; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Constructor sets the language by calling set_lang |
106
|
|
|
* and stores language settings in object properties |
107
|
|
|
*/ |
108
|
|
|
public function __construct() { |
109
|
|
|
parent::__construct(); |
110
|
|
|
$olddomain = $this->languageInstance->setTextDomain("user"); |
111
|
|
|
$this->CAT_VERSION_STRING = _("Unreleased <a href='https://github.com/GEANT/CAT/tree/master/Changes.md'>Git Revision</a>"); |
112
|
|
|
if (CAT::RELEASE_VERSION) { |
113
|
|
|
$temp_version = "CAT-" . CAT::VERSION_MAJOR . "." . CAT::VERSION_MINOR; |
114
|
|
|
$branch = "release_" . CAT::VERSION_MAJOR . "_" . CAT::VERSION_MINOR; |
115
|
|
|
if (CAT::VERSION_PATCH != 0) { |
116
|
|
|
$temp_version .= "." . CAT::VERSION_PATCH; |
117
|
|
|
} |
118
|
|
|
if (CAT::VERSION_EXTRA != "") { |
119
|
|
|
$temp_version .= "-" . CAT::VERSION_EXTRA; |
120
|
|
|
} |
121
|
|
|
$this->CAT_VERSION_STRING = sprintf(_("Release <a href='%s'>%s</a>"), "https://github.com/GEANT/CAT/tree/" . $branch . "/Changes.md", $temp_version); |
122
|
|
|
} |
123
|
|
|
$this->CAT_COPYRIGHT = CONFIG['APPEARANCE']['productname'] . " - " . $this->CAT_VERSION_STRING . " © " . CAT::COPYRIGHT_MIN_YEAR . "-" . CAT::COPYRIGHT_MAX_YEAR . " " . CAT::COPYRIGHT_HOLDER . "<br/>on behalf of " . CAT::COPYRIGHT_CONSORTIA . "; and others <a href='copyright.php'>Full Copyright and Licenses</a>"; |
124
|
|
|
$this->languageInstance->setTextDomain($olddomain); |
125
|
|
|
|
126
|
|
|
/* Federations are created in DB with bootstrapFederation, and listed via listFederations |
127
|
|
|
*/ |
128
|
|
|
$oldlocale = $this->languageInstance->setTextDomain('core'); |
129
|
|
|
|
130
|
|
|
// some config elements are displayable. We need some dummies to |
131
|
|
|
// translate the common values for them. If a deployment chooses a |
132
|
|
|
// different wording, no translation, sorry |
133
|
|
|
|
134
|
|
|
$dummy_NRO = _("National Roaming Operator"); |
135
|
|
|
$dummy_inst1 = _("identity provider"); |
136
|
|
|
$dummy_inst2 = _("organisation"); |
137
|
|
|
$dummy_inst3 = _("Identity Provider"); |
138
|
|
|
// and do something useless with the strings so that there's no "unused" complaint |
139
|
|
|
if (strlen($dummy_NRO . $dummy_inst1 . $dummy_inst2 . $dummy_inst3) < 0) { |
140
|
|
|
throw new \Exception("Strings are usually not shorter than 0 characters. We've encountered a string blackhole."); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$this->nomenclature_fed = _(CONFIG_CONFASSISTANT['CONSORTIUM']['nomenclature_federation']); |
144
|
|
|
$this->nomenclature_inst = _(CONFIG_CONFASSISTANT['CONSORTIUM']['nomenclature_institution']); |
145
|
|
|
$this->knownFederations = [ |
146
|
|
|
'AD' => _("Andorra"), |
147
|
|
|
'AT' => _("Austria"), |
148
|
|
|
'BE' => _("Belgium"), |
149
|
|
|
'BG' => _("Bulgaria"), |
150
|
|
|
'CY' => _("Cyprus"), |
151
|
|
|
'CZ' => _("Czech Republic"), |
152
|
|
|
'DK' => _("Denmark"), |
153
|
|
|
'EE' => _("Estonia"), |
154
|
|
|
'FI' => _("Finland"), |
155
|
|
|
'FR' => _("France"), |
156
|
|
|
'DE' => _("Germany"), |
157
|
|
|
'GR' => _("Greece"), |
158
|
|
|
'HR' => _("Croatia"), |
159
|
|
|
'IE' => _("Ireland"), |
160
|
|
|
'IS' => _("Iceland"), |
161
|
|
|
'IT' => _("Italy"), |
162
|
|
|
'HU' => _("Hungary"), |
163
|
|
|
'LU' => _("Luxembourg"), |
164
|
|
|
'LV' => _("Latvia"), |
165
|
|
|
'LT' => _("Lithuania"), |
166
|
|
|
'MK' => _("Macedonia"), |
167
|
|
|
'RS' => _("Serbia"), |
168
|
|
|
'NL' => _("Netherlands"), |
169
|
|
|
'NO' => _("Norway"), |
170
|
|
|
'PL' => _("Poland"), |
171
|
|
|
'PT' => _("Portugal"), |
172
|
|
|
'RO' => _("Romania"), |
173
|
|
|
'SI' => _("Slovenia"), |
174
|
|
|
'ES' => _("Spain"), |
175
|
|
|
'SE' => _("Sweden"), |
176
|
|
|
'SK' => _("Slovakia"), |
177
|
|
|
'CH' => _("Switzerland"), |
178
|
|
|
'TR' => _("Turkey"), |
179
|
|
|
'UK' => _("United Kingdom"), |
180
|
|
|
'TEST' => 'TEST Country', |
181
|
|
|
'AU' => _("Australia"), |
182
|
|
|
'CA' => _("Canada"), |
183
|
|
|
'IL' => _("Israel"), |
184
|
|
|
'JP' => _("Japan"), |
185
|
|
|
'NZ' => _("New Zealand"), |
186
|
|
|
'US' => _("U.S.A."), |
187
|
|
|
'BR' => _("Brazil"), |
188
|
|
|
'CL' => _("Chile"), |
189
|
|
|
'PE' => _("Peru"), |
190
|
|
|
'VE' => _("Venezuela"), |
191
|
|
|
'DEFAULT' => _("Default"), |
192
|
|
|
'AM' => _("Armenia"), |
193
|
|
|
'AZ' => _("Azerbaijan"), |
194
|
|
|
'BY' => _("Belarus"), |
195
|
|
|
'EC' => _("Ecuador"), |
196
|
|
|
'HK' => _("Hong Kong"), |
197
|
|
|
'KE' => _("Kenya"), |
198
|
|
|
'KG' => _("Kyrgyzstan"), |
199
|
|
|
'KR' => _("Korea"), |
200
|
|
|
'KZ' => _("Kazakhstan"), |
201
|
|
|
'MA' => _("Morocco"), |
202
|
|
|
'MD' => _("Moldova"), |
203
|
|
|
'ME' => _("Montenegro"), |
204
|
|
|
'MO' => _("Macau"), |
205
|
|
|
'MT' => _("Malta"), |
206
|
|
|
'RU' => _("Russia"), |
207
|
|
|
'SG' => _("Singapore"), |
208
|
|
|
'TH' => _("Thailand"), |
209
|
|
|
'TW' => _("Taiwan"), |
210
|
|
|
'ZA' => _("South Africa"), |
211
|
|
|
'AF' => 'Afghanistan', |
212
|
|
|
'AL' => 'Albania', |
213
|
|
|
'DZ' => 'Algeria', |
214
|
|
|
'AS' => 'American Samoa', |
215
|
|
|
'AO' => 'Angola', |
216
|
|
|
'AI' => 'Anguilla', |
217
|
|
|
'AQ' => 'Antarctica', |
218
|
|
|
'AG' => 'Antigua And Barbuda', |
219
|
|
|
'AR' => 'Argentina', |
220
|
|
|
'AW' => 'Aruba', |
221
|
|
|
'BS' => 'Bahamas, The', |
222
|
|
|
'BH' => 'Bahrain', |
223
|
|
|
'BD' => 'Bangladesh', |
224
|
|
|
'BB' => 'Barbados', |
225
|
|
|
'BZ' => 'Belize', |
226
|
|
|
'BJ' => 'Benin', |
227
|
|
|
'BM' => 'Bermuda', |
228
|
|
|
'BT' => 'Bhutan', |
229
|
|
|
'BO' => 'Bolivia', |
230
|
|
|
'BA' => 'Bosnia And Herzegovina', |
231
|
|
|
'BW' => 'Botswana', |
232
|
|
|
'BV' => 'Bouvet Island', |
233
|
|
|
'IO' => 'British Indian Ocean Territory', |
234
|
|
|
'BN' => 'Brunei', |
235
|
|
|
'BF' => 'Burkina Faso', |
236
|
|
|
'MM' => 'Burma', |
237
|
|
|
'BI' => 'Burundi', |
238
|
|
|
'KH' => 'Cambodia', |
239
|
|
|
'CM' => 'Cameroon', |
240
|
|
|
'CV' => 'Cape Verde', |
241
|
|
|
'KY' => 'Cayman Islands', |
242
|
|
|
'CF' => 'Central African Republic', |
243
|
|
|
'TD' => 'Chad', |
244
|
|
|
'CN' => 'China', |
245
|
|
|
'CX' => 'Christmas Island', |
246
|
|
|
'CC' => 'Cocos (keeling) Islands', |
247
|
|
|
'CO' => 'Colombia', |
248
|
|
|
'KM' => 'Comoros', |
249
|
|
|
'CG' => 'Congo (brazzaville) ', |
250
|
|
|
'CD' => 'Congo (kinshasa)', |
251
|
|
|
'CK' => 'Cook Islands', |
252
|
|
|
'CR' => 'Costa Rica', |
253
|
|
|
'CI' => 'CÔte D’ivoire', |
254
|
|
|
'CU' => 'Cuba', |
255
|
|
|
'CW' => 'CuraÇao', |
256
|
|
|
'DJ' => 'Djibouti', |
257
|
|
|
'DM' => 'Dominica', |
258
|
|
|
'DO' => 'Dominican Republic', |
259
|
|
|
'EG' => 'Egypt', |
260
|
|
|
'SV' => 'El Salvador', |
261
|
|
|
'GQ' => 'Equatorial Guinea', |
262
|
|
|
'ER' => 'Eritrea', |
263
|
|
|
'ET' => 'Ethiopia', |
264
|
|
|
'FK' => 'Falkland Islands (islas Malvinas)', |
265
|
|
|
'FO' => 'Faroe Islands', |
266
|
|
|
'FJ' => 'Fiji', |
267
|
|
|
'GF' => 'French Guiana', |
268
|
|
|
'PF' => 'French Polynesia', |
269
|
|
|
'TF' => 'French Southern And Antarctic Lands', |
270
|
|
|
'GA' => 'Gabon', |
271
|
|
|
'GM' => 'Gambia, The', |
272
|
|
|
'GE' => 'Georgia', |
273
|
|
|
'GEANT' => 'The GEANT country', |
274
|
|
|
'GH' => 'Ghana', |
275
|
|
|
'GI' => 'Gibraltar', |
276
|
|
|
'GL' => 'Greenland', |
277
|
|
|
'GD' => 'Grenada', |
278
|
|
|
'GP' => 'Guadeloupe', |
279
|
|
|
'GU' => 'Guam', |
280
|
|
|
'GT' => 'Guatemala', |
281
|
|
|
'GG' => 'Guernsey', |
282
|
|
|
'GN' => 'Guinea', |
283
|
|
|
'GW' => 'Guinea-bissau', |
284
|
|
|
'GY' => 'Guyana', |
285
|
|
|
'HT' => 'Haiti', |
286
|
|
|
'HM' => 'Heard Island And Mcdonald Islands', |
287
|
|
|
'HN' => 'Honduras', |
288
|
|
|
'IN' => 'India', |
289
|
|
|
'ID' => 'Indonesia', |
290
|
|
|
'IR' => 'Iran', |
291
|
|
|
'IQ' => 'Iraq', |
292
|
|
|
'IM' => 'Isle Of Man', |
293
|
|
|
'JM' => 'Jamaica', |
294
|
|
|
'JE' => 'Jersey', |
295
|
|
|
'JO' => 'Jordan', |
296
|
|
|
'KI' => 'Kiribati', |
297
|
|
|
'KP' => 'Korea, North', |
298
|
|
|
'KW' => 'Kuwait', |
299
|
|
|
'LA' => 'Laos', |
300
|
|
|
'LB' => 'Lebanon', |
301
|
|
|
'LS' => 'Lesotho', |
302
|
|
|
'LR' => 'Liberia', |
303
|
|
|
'LY' => 'Libya', |
304
|
|
|
'LI' => 'Liechtenstein', |
305
|
|
|
'MG' => 'Madagascar', |
306
|
|
|
'MW' => 'Malawi', |
307
|
|
|
'MY' => 'Malaysia', |
308
|
|
|
'MV' => 'Maldives', |
309
|
|
|
'ML' => 'Mali', |
310
|
|
|
'MH' => 'Marshall Islands', |
311
|
|
|
'MQ' => 'Martinique', |
312
|
|
|
'MR' => 'Mauritania', |
313
|
|
|
'MU' => 'Mauritius', |
314
|
|
|
'YT' => 'Mayotte', |
315
|
|
|
'MX' => 'Mexico', |
316
|
|
|
'FM' => 'Micronesia, Federated States Of', |
317
|
|
|
'MC' => 'Monaco', |
318
|
|
|
'MN' => 'Mongolia', |
319
|
|
|
'MS' => 'Montserrat', |
320
|
|
|
'MZ' => 'Mozambique', |
321
|
|
|
'NA' => 'Namibia', |
322
|
|
|
'NR' => 'Nauru', |
323
|
|
|
'NP' => 'Nepal', |
324
|
|
|
'NC' => 'New Caledonia', |
325
|
|
|
'NI' => 'Nicaragua', |
326
|
|
|
'NE' => 'Niger', |
327
|
|
|
'NG' => 'Nigeria', |
328
|
|
|
'NU' => 'Niue', |
329
|
|
|
'NF' => 'Norfolk Island', |
330
|
|
|
'MP' => 'Northern Mariana Islands', |
331
|
|
|
'OM' => 'Oman', |
332
|
|
|
'PK' => 'Pakistan', |
333
|
|
|
'PW' => 'Palau', |
334
|
|
|
'PA' => 'Panama', |
335
|
|
|
'PG' => 'Papua New Guinea', |
336
|
|
|
'PY' => 'Paraguay', |
337
|
|
|
'PH' => 'Philippines', |
338
|
|
|
'PN' => 'Pitcairn Islands', |
339
|
|
|
'PR' => 'Puerto Rico', |
340
|
|
|
'QA' => 'Qatar', |
341
|
|
|
'RE' => 'Reunion', |
342
|
|
|
'RW' => 'Rwanda', |
343
|
|
|
'BL' => 'Saint Barthelemy', |
344
|
|
|
'SH' => 'Saint Helena, Ascension, And Tristan Da Cunha', |
345
|
|
|
'KN' => 'Saint Kitts And Nevis', |
346
|
|
|
'LC' => 'Saint Lucia', |
347
|
|
|
'MF' => 'Saint Martin', |
348
|
|
|
'PM' => 'Saint Pierre And Miquelon', |
349
|
|
|
'VC' => 'Saint Vincent And The Grenadines', |
350
|
|
|
'WS' => 'Samoa', |
351
|
|
|
'SM' => 'San Marino', |
352
|
|
|
'ST' => 'Sao Tome And Principe', |
353
|
|
|
'SA' => 'Saudi Arabia', |
354
|
|
|
'SN' => 'Senegal', |
355
|
|
|
'SC' => 'Seychelles', |
356
|
|
|
'SL' => 'Sierra Leone', |
357
|
|
|
'SX' => 'Sint Maarten', |
358
|
|
|
'SB' => 'Solomon Islands', |
359
|
|
|
'SO' => 'Somalia', |
360
|
|
|
'GS' => 'South Georgia And South Sandwich Islands', |
361
|
|
|
'SS' => 'South Sudan', |
362
|
|
|
'LK' => 'Sri Lanka', |
363
|
|
|
'SD' => 'Sudan', |
364
|
|
|
'SR' => 'Suriname', |
365
|
|
|
'SZ' => 'Swaziland', |
366
|
|
|
'SY' => 'Syria', |
367
|
|
|
'TJ' => 'Tajikistan', |
368
|
|
|
'TZ' => 'Tanzania', |
369
|
|
|
'TL' => 'Timor-leste', |
370
|
|
|
'TG' => 'Togo', |
371
|
|
|
'TK' => 'Tokelau', |
372
|
|
|
'TO' => 'Tonga', |
373
|
|
|
'TT' => 'Trinidad And Tobago', |
374
|
|
|
'TN' => 'Tunisia', |
375
|
|
|
'TM' => 'Turkmenistan', |
376
|
|
|
'TC' => 'Turks And Caicos Islands', |
377
|
|
|
'TV' => 'Tuvalu', |
378
|
|
|
'UG' => 'Uganda', |
379
|
|
|
'UA' => 'Ukraine', |
380
|
|
|
'AE' => 'United Arab Emirates', |
381
|
|
|
'GB' => 'United Kingdom', |
382
|
|
|
'UY' => 'Uruguay', |
383
|
|
|
'UZ' => 'Uzbekistan', |
384
|
|
|
'VU' => 'Vanuatu', |
385
|
|
|
'VA' => 'Vatican City', |
386
|
|
|
'VN' => 'Vietnam', |
387
|
|
|
'VG' => 'Virgin Islands, British', |
388
|
|
|
'VI' => 'Virgin Islands, United States ', |
389
|
|
|
'WF' => 'Wallis And Futuna', |
390
|
|
|
'EH' => 'Western Sahara', |
391
|
|
|
'YE' => 'Yemen', |
392
|
|
|
'ZM' => 'Zambia', |
393
|
|
|
'ZW' => 'Zimbabwe', |
394
|
|
|
]; |
395
|
|
|
|
396
|
|
|
$this->languageInstance->setTextDomain($oldlocale); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* Calculates the number of IdPs overall in the system |
401
|
|
|
* |
402
|
|
|
* @param string $level completeness level of IdPs that are to be taken into consideration for counting |
403
|
|
|
* @return int |
404
|
|
|
*/ |
405
|
|
|
public function totalIdPs($level) { |
406
|
|
|
$handle = DBConnection::handle(CAT::DB_TYPE); |
407
|
|
|
switch ($level) { |
408
|
|
|
case "ALL": |
409
|
|
|
$idpcount = $handle->exec("SELECT COUNT(inst_id) AS instcount FROM institution"); |
410
|
|
|
break; |
411
|
|
|
case "VALIDPROFILE": |
412
|
|
|
$idpcount = $handle->exec("SELECT COUNT(DISTINCT institution.inst_id) AS instcount FROM institution,profile WHERE institution.inst_id = profile.inst_id AND profile.sufficient_config = 1"); |
413
|
|
|
break; |
414
|
|
|
case "PUBLICPROFILE": |
415
|
|
|
$idpcount = $handle->exec("SELECT COUNT(DISTINCT institution.inst_id) AS instcount FROM institution,profile WHERE institution.inst_id = profile.inst_id AND profile.showtime = 1"); |
416
|
|
|
break; |
417
|
|
|
default: |
418
|
|
|
return -1; |
419
|
|
|
} |
420
|
|
|
// SELECTs never return a booleans, always an object |
421
|
|
|
$dbresult = mysqli_fetch_object(/** @scrutinizer ignore-type */ $idpcount); |
422
|
|
|
return $dbresult->instcount; |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* Lists all identity providers in the database |
427
|
|
|
* adding information required by DiscoJuice. |
428
|
|
|
* |
429
|
|
|
* @param int $activeOnly if set to non-zero will cause listing of only those institutions which have some valid profiles defined. |
430
|
|
|
* @param string $country if set, only list IdPs in a specific country |
431
|
|
|
* @return array the list of identity providers |
432
|
|
|
* |
433
|
|
|
*/ |
434
|
|
|
public function listAllIdentityProviders($activeOnly = 0, $country = "") { |
435
|
|
|
$handle = DBConnection::handle("INST"); |
436
|
|
|
$handle->exec("SET SESSION group_concat_max_len=10000"); |
437
|
|
|
$query = "SELECT distinct institution.inst_id AS inst_id, institution.country AS country, |
438
|
|
|
group_concat(concat_ws('===',institution_option.option_name,LEFT(institution_option.option_value,200), institution_option.option_lang) separator '---') AS options |
439
|
|
|
FROM institution "; |
440
|
|
|
if ($activeOnly == 1) { |
441
|
|
|
$query .= "JOIN v_active_inst ON institution.inst_id = v_active_inst.inst_id "; |
442
|
|
|
} |
443
|
|
|
$query .= "JOIN institution_option ON institution.inst_id = institution_option.institution_id "; |
444
|
|
|
$query .= "WHERE (institution_option.option_name = 'general:instname' |
445
|
|
|
OR institution_option.option_name = 'general:geo_coordinates' |
446
|
|
|
OR institution_option.option_name = 'general:logo_file') "; |
447
|
|
|
|
448
|
|
|
$query .= ($country != "" ? "AND institution.country = ? " : ""); |
449
|
|
|
|
450
|
|
|
$query .= "GROUP BY institution.inst_id ORDER BY inst_id"; |
451
|
|
|
|
452
|
|
|
$allIDPs = ($country != "" ? $handle->exec($query, "s", $country) : $handle->exec($query)); |
453
|
|
|
$returnarray = []; |
454
|
|
|
// SELECTs never return a booleans, always an object |
455
|
|
|
while ($queryResult = mysqli_fetch_object(/** @scrutinizer ignore-type */ $allIDPs)) { |
456
|
|
|
$institutionOptions = explode('---', $queryResult->options); |
457
|
|
|
$oneInstitutionResult = []; |
458
|
|
|
$geo = []; |
459
|
|
|
$names = []; |
460
|
|
|
|
461
|
|
|
$oneInstitutionResult['entityID'] = $queryResult->inst_id; |
462
|
|
|
$oneInstitutionResult['country'] = strtoupper($queryResult->country); |
463
|
|
|
foreach ($institutionOptions as $institutionOption) { |
464
|
|
|
$opt = explode('===', $institutionOption); |
465
|
|
|
switch ($opt[0]) { |
466
|
|
|
case 'general:logo_file': |
467
|
|
|
$oneInstitutionResult['icon'] = $queryResult->inst_id; |
468
|
|
|
break; |
469
|
|
|
case 'general:geo_coordinates': |
470
|
|
|
$at1 = json_decode($opt[1], true); |
471
|
|
|
$geo[] = $at1; |
472
|
|
|
break; |
473
|
|
|
case 'general:instname': |
474
|
|
|
$names[] = [ |
475
|
|
|
'lang' => $opt[2], |
476
|
|
|
'value' => $opt[1] |
477
|
|
|
]; |
478
|
|
|
break; |
479
|
|
|
default: |
480
|
|
|
break; |
481
|
|
|
} |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
$name = _("Unnamed Entity"); |
485
|
|
|
if (count($names) != 0) { |
486
|
|
|
$langObject = new \core\common\Language(); |
487
|
|
|
$name = $langObject->getLocalisedValue($names); |
488
|
|
|
} |
489
|
|
|
$oneInstitutionResult['title'] = $name; |
490
|
|
|
if (count($geo) > 0) { |
491
|
|
|
$oneInstitutionResult['geo'] = $geo; |
492
|
|
|
} |
493
|
|
|
$returnarray[] = $oneInstitutionResult; |
494
|
|
|
} |
495
|
|
|
return $returnarray; |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* Prepares a list of countries known to the CAT. |
500
|
|
|
* |
501
|
|
|
* @param int $activeOnly is set and nonzero will cause that only countries with some institutions underneath will be listed |
502
|
|
|
* @return array Array indexed by (uppercase) lang codes and sorted according to the current locale |
503
|
|
|
*/ |
504
|
|
|
public function printCountryList($activeOnly = 0) { |
505
|
|
|
$olddomain = $this->languageInstance->setTextDomain("core"); |
506
|
|
|
$handle = DBConnection::handle(CAT::DB_TYPE); |
507
|
|
|
$returnArray = []; // in if -> the while might never be executed, so initialise |
508
|
|
|
if ($activeOnly) { |
509
|
|
|
$federations = $handle->exec("SELECT DISTINCT UPPER(institution.country) AS country FROM institution JOIN profile |
510
|
|
|
ON institution.inst_id = profile.inst_id WHERE profile.showtime = 1 ORDER BY country"); |
511
|
|
|
// SELECT never returns a boolean, always a mysqli_object |
512
|
|
View Code Duplication |
while ($activeFederations = mysqli_fetch_object(/** @scrutinizer ignore-type */ $federations)) { |
|
|
|
|
513
|
|
|
$fedIdentifier = $activeFederations->country; // UPPER() has capitalised this for us |
514
|
|
|
$returnArray[$fedIdentifier] = isset($this->knownFederations[$fedIdentifier]) ? $this->knownFederations[$fedIdentifier] : $fedIdentifier; |
515
|
|
|
} |
516
|
|
|
} else { |
517
|
|
|
$returnArray = $this->knownFederations; |
518
|
|
|
} |
519
|
|
|
asort($returnArray, SORT_LOCALE_STRING); |
520
|
|
|
$this->languageInstance->setTextDomain($olddomain); |
521
|
|
|
return($returnArray); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* get additional details about an institution from the EXTERNAL customer DB |
526
|
|
|
* (if any; for eduroam, this would be the official eduroam database) |
527
|
|
|
* |
528
|
|
|
* @param string $externalId the ID of the institution in the external DB |
529
|
|
|
* @param string $realm the function can also try to find an inst by its realm in the external DB |
530
|
|
|
* @return array a list of institutions, ideally with only one member |
531
|
|
|
*/ |
532
|
|
|
public function getExternalDBEntityDetails($externalId, $realm = NULL) { |
533
|
|
|
$list = []; |
534
|
|
|
if (CONFIG_CONFASSISTANT['CONSORTIUM']['name'] == "eduroam" && isset(CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo']) && CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo'] == "Operations Team") { // SW: APPROVED |
535
|
|
|
$scanforrealm = ""; |
536
|
|
|
if ($realm !== NULL) { |
537
|
|
|
$scanforrealm = "OR inst_realm LIKE '%$realm%'"; |
538
|
|
|
} |
539
|
|
|
$externalHandle = DBConnection::handle("EXTERNAL"); |
540
|
|
|
$infoList = $externalHandle->exec("SELECT name AS collapsed_name, inst_realm as realmlist, contact AS collapsed_contact, country FROM view_active_idp_institution WHERE id_institution = $externalId $scanforrealm"); |
541
|
|
|
// split names and contacts into proper pairs |
542
|
|
|
// SELECT never returns a boolean, always a mysqli_object |
543
|
|
|
while ($externalEntityQuery = mysqli_fetch_object(/** @scrutinizer ignore-type */ $infoList)) { |
544
|
|
|
$names = explode('#', $externalEntityQuery->collapsed_name); |
545
|
|
|
foreach ($names as $name) { |
546
|
|
|
$perlang = explode(': ', $name, 2); |
547
|
|
|
$list['names'][$perlang[0]] = $perlang[1]; |
548
|
|
|
} |
549
|
|
|
$contacts = explode('#', $externalEntityQuery->collapsed_contact); |
550
|
|
|
foreach ($contacts as $contact) { |
551
|
|
|
$email1 = explode('e: ', $contact); |
552
|
|
|
$email2 = explode(',', $email1[1]); |
553
|
|
|
$list['admins'][] = ["email" => $email2[0]]; |
554
|
|
|
} |
555
|
|
|
$list['country'] = strtoupper($externalEntityQuery->country); |
556
|
|
|
$list['realmlist'] = $externalEntityQuery->realmlist; |
557
|
|
|
} |
558
|
|
|
} |
559
|
|
|
return $list; |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
/** |
563
|
|
|
* the list of countries as per external DB |
564
|
|
|
* @return array the list |
565
|
|
|
*/ |
566
|
|
|
public function getExternalCountriesList() { |
567
|
|
|
$olddomain = $this->languageInstance->setTextDomain("core"); |
568
|
|
|
$returnArray = []; // in if -> the while might never be executed, so initialise |
569
|
|
|
if (CONFIG_CONFASSISTANT['CONSORTIUM']['name'] == "eduroam" && isset(CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo']) && CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo'] == "Operations Team") { // SW: APPROVED |
570
|
|
|
$handle = DBConnection::handle("EXTERNAL"); |
571
|
|
|
$timeStart = microtime(true); |
572
|
|
|
$federations = $handle->exec("SELECT DISTINCT UPPER(country) AS country FROM view_active_idp_institution ORDER BY country"); |
573
|
|
|
$timeEnd = microtime(true); |
574
|
|
|
$timeElapsed = $timeEnd - $timeStart; |
575
|
|
View Code Duplication |
while ($eduroamFederations = mysqli_fetch_object($federations)) { |
|
|
|
|
576
|
|
|
$fedIdentifier = $eduroamFederations->country; |
577
|
|
|
$returnArray[$fedIdentifier] = isset($this->knownFederations[$fedIdentifier]) ? $this->knownFederations[$fedIdentifier] : $fedIdentifier; |
578
|
|
|
} |
579
|
|
|
asort($returnArray, SORT_LOCALE_STRING); |
580
|
|
|
$returnArray['time'] = $timeElapsed; |
581
|
|
|
} |
582
|
|
|
$this->languageInstance->setTextDomain($olddomain); |
583
|
|
|
return($returnArray); |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
public static function getRootUrlPath() { |
587
|
|
|
return substr(CONFIG['PATHS']['cat_base_url'], -1) === '/' ? substr(CONFIG['PATHS']['cat_base_url'], 0, -1) : CONFIG['PATHS']['cat_base_url']; |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
} |
591
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.