|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* ***************************************************************************** |
|
5
|
|
|
* Contributions to this work were made on behalf of the GÉANT project, a |
|
6
|
|
|
* project that has received funding from the European Union’s Framework |
|
7
|
|
|
* Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus), |
|
8
|
|
|
* Horizon 2020 research and innovation programme under Grant Agreements No. |
|
9
|
|
|
* 691567 (GN4-1) and No. 731122 (GN4-2). |
|
10
|
|
|
* On behalf of the aforementioned projects, GEANT Association is the sole owner |
|
11
|
|
|
* of the copyright in all material which was developed by a member of the GÉANT |
|
12
|
|
|
* project. GÉANT Vereniging (Association) is registered with the Chamber of |
|
13
|
|
|
* Commerce in Amsterdam with registration number 40535155 and operates in the |
|
14
|
|
|
* UK as a branch of GÉANT Vereniging. |
|
15
|
|
|
* |
|
16
|
|
|
* Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. |
|
17
|
|
|
* UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK |
|
18
|
|
|
* |
|
19
|
|
|
* License: see the web/copyright.inc.php file in the file structure or |
|
20
|
|
|
* <base_url>/copyright.php after deploying the software |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
require_once dirname(dirname(dirname(__DIR__))) . "/config/_config.php"; |
|
24
|
|
|
|
|
25
|
|
|
$auth = new \web\lib\admin\Authentication(); |
|
26
|
|
|
$auth->authenticate(); |
|
27
|
|
|
|
|
28
|
|
|
$catInstance = new \core\CAT(); |
|
29
|
|
|
$loggerInstance = new \core\common\Logging(); |
|
30
|
|
|
$validator = new \web\lib\common\InputValidation(); |
|
31
|
|
|
$uiElements = new \web\lib\admin\UIElements(); |
|
32
|
|
|
$languageInstance = new \core\common\Language(); |
|
33
|
|
|
$languageInstance->setTextDomain("web_admin"); |
|
34
|
|
|
|
|
35
|
|
|
$mgmt = new \core\UserManagement; |
|
36
|
|
|
$new_idp_authorized_fedadmin = FALSE; |
|
37
|
|
|
|
|
38
|
|
|
// check if the user is authenticated, and we have a valid mail address |
|
39
|
|
|
if (!isset($_SESSION['user']) || !isset($_POST['mailaddr'])) { |
|
40
|
|
|
throw new Exception("sendinvite: called either without authentication or without target mail address!"); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$newmailaddress = filter_input(INPUT_POST, 'mailaddr', FILTER_SANITIZE_STRING); |
|
44
|
|
|
$totalSegments = explode(",", $newmailaddress); |
|
45
|
|
|
$validAddresses = core\common\OutsideComm::exfiltrateValidAddresses($newmailaddress); |
|
|
|
|
|
|
46
|
|
|
$newcountry = ""; |
|
47
|
|
|
|
|
48
|
|
|
// fed admin stuff |
|
49
|
|
|
// we are either inviting to co-manage an existing inst ... |
|
50
|
|
|
|
|
51
|
|
|
$userObject = new \core\User($_SESSION['user']); |
|
52
|
|
|
$federation = NULL; |
|
53
|
|
|
|
|
54
|
|
|
const OPERATION_MODE_INVALID = 0; |
|
55
|
|
|
const OPERATION_MODE_EDIT = 1; |
|
56
|
|
|
const OPERATION_MODE_NEWFROMDB = 2; |
|
57
|
|
|
const OPERATION_MODE_NEWUNLINKED = 3; |
|
58
|
|
|
|
|
59
|
|
|
$operationMode = OPERATION_MODE_INVALID; |
|
60
|
|
|
|
|
61
|
|
|
// what did we actually get? |
|
62
|
|
|
if (isset($_GET['inst_id'])) { |
|
63
|
|
|
$operationMode = OPERATION_MODE_EDIT; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if (isset($_POST['creation']) && $_POST['creation'] == "new" && isset($_POST['name']) && isset($_POST['country'])) { |
|
67
|
|
|
$operationMode = OPERATION_MODE_NEWUNLINKED; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (isset($_POST['creation']) && ($_POST['creation'] == "existing") && isset($_POST['externals']) && ($_POST['externals'] != "FREETEXT")) { |
|
71
|
|
|
$operationMode = OPERATION_MODE_NEWFROMDB; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
switch ($operationMode) { |
|
75
|
|
|
case OPERATION_MODE_EDIT: |
|
76
|
|
|
$idp = $validator->existingIdP($_GET['inst_id']); |
|
77
|
|
|
// editing IdPs is done from within the popup. When we're done, send the |
|
78
|
|
|
// user back to the popup (append the result of the operation later) |
|
79
|
|
|
$redirectDestination = "manageAdmins.inc.php?inst_id=" . $idp->identifier . "&"; |
|
80
|
|
|
if (count($validAddresses) == 0) { |
|
81
|
|
|
header("Location: $redirectDestination" . "invitation=INVALIDSYNTAX"); |
|
82
|
|
|
exit(1); |
|
83
|
|
|
} |
|
84
|
|
|
// is the user primary admin of this IdP? |
|
85
|
|
|
$is_owner = $idp->isPrimaryOwner($_SESSION['user']); |
|
86
|
|
|
// check if he is (also) federation admin for the federation this IdP is in. His invitations have more blessing then. |
|
87
|
|
|
$fedadmin = $userObject->isFederationAdmin($idp->federation); |
|
88
|
|
|
// check if he is either one, if not, complain |
|
89
|
|
|
if (!$is_owner && !$fedadmin) { |
|
90
|
|
|
echo "<p>" . sprintf(_("Something's wrong... you are a %s admin, but not for the %s the requested %s belongs to!"), $uiElements->nomenclatureFed, $uiElements->nomenclatureFed, $uiElements->nomenclatureInst) . "</p>"; |
|
91
|
|
|
exit(1); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$prettyprintname = $idp->name; |
|
95
|
|
|
$newtokens = $mgmt->createTokens($fedadmin, $validAddresses, $idp); |
|
96
|
|
|
$loggerInstance->writeAudit($_SESSION['user'], "NEW", "IdP " . $idp->identifier . " - Token created for " . implode(",", $validAddresses)); |
|
97
|
|
|
$introtext = "CO-ADMIN"; |
|
98
|
|
|
$participant_type = $idp->type; |
|
99
|
|
|
break; |
|
100
|
|
|
case OPERATION_MODE_NEWUNLINKED: |
|
101
|
|
|
$redirectDestination = "../overview_federation.php?"; |
|
102
|
|
|
if (count($validAddresses) == 0) { |
|
103
|
|
|
header("Location: $redirectDestination"."invitation=INVALIDSYNTAX"); |
|
104
|
|
|
exit(1); |
|
105
|
|
|
} |
|
106
|
|
|
// run an input check and conversion of the raw inputs... just in case |
|
107
|
|
|
$newinstname = $validator->string($_POST['name']); |
|
108
|
|
|
$newcountry = $validator->string($_POST['country']); |
|
109
|
|
|
$participant_type = $validator->partType($_POST['participant_type']); |
|
110
|
|
|
$new_idp_authorized_fedadmin = $userObject->isFederationAdmin($newcountry); |
|
111
|
|
|
if ($new_idp_authorized_fedadmin !== TRUE) { |
|
112
|
|
|
throw new Exception("Something's wrong... you want to create a new " . $uiElements->nomenclatureInst . ", but are not a " . $uiElements->nomenclatureFed . " admin for the " . $uiElements->nomenclatureFed . " it should be in!"); |
|
113
|
|
|
} |
|
114
|
|
|
$federation = $validator->existingFederation($newcountry); |
|
115
|
|
|
$prettyprintname = $newinstname; |
|
116
|
|
|
$introtext = "NEW-FED"; |
|
117
|
|
|
// send the user back to his federation overview page, append the result of the operation later |
|
118
|
|
|
// do the token creation magic |
|
119
|
|
|
$newtokens = $mgmt->createTokens(TRUE, $validAddresses, $newinstname, 0, $newcountry, $participant_type); |
|
120
|
|
|
$loggerInstance->writeAudit($_SESSION['user'], "NEW", "ORG FUTURE - Token created for $participant_type " . implode(",", $validAddresses)); |
|
121
|
|
|
break; |
|
122
|
|
|
case OPERATION_MODE_NEWFROMDB: |
|
123
|
|
|
$redirectDestination = "../overview_federation.php?"; |
|
124
|
|
|
if (count($validAddresses) == 0) { |
|
125
|
|
|
header("Location: $redirectDestination"."invitation=INVALIDSYNTAX"); |
|
126
|
|
|
exit(1); |
|
127
|
|
|
} |
|
128
|
|
|
// a real external DB entry was submitted and all the required parameters are there |
|
129
|
|
|
$newexternalid = $validator->string($_POST['externals']); |
|
130
|
|
|
$extinfo = $catInstance->getExternalDBEntityDetails($newexternalid); |
|
131
|
|
|
$new_idp_authorized_fedadmin = $userObject->isFederationAdmin($extinfo['country']); |
|
132
|
|
|
if ($new_idp_authorized_fedadmin !== TRUE) { |
|
133
|
|
|
throw new Exception("Something's wrong... you want to create a new " . $uiElements->nomenclatureInst . ", but are not a " . $uiElements->nomenclatureFed . " admin for the " . $uiElements->nomenclatureFed . " it should be in!"); |
|
134
|
|
|
} |
|
135
|
|
|
$federation = $validator->existingFederation($extinfo['country']); |
|
136
|
|
|
$newcountry = $extinfo['country']; |
|
137
|
|
|
// see if the inst name is defined in the currently set language; if not, pick its English name; if N/A, pick the last in the list |
|
138
|
|
|
$prettyprintname = ""; |
|
139
|
|
|
foreach ($extinfo['names'] as $lang => $name) { |
|
140
|
|
|
if ($lang == $languageInstance->getLang()) { |
|
141
|
|
|
$prettyprintname = $name; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
if ($prettyprintname == "" && isset($extinfo['names']['en'])) { |
|
145
|
|
|
$prettyprintname = $extinfo['names']['en']; |
|
146
|
|
|
} |
|
147
|
|
|
if ($prettyprintname == "") { |
|
148
|
|
|
foreach ($extinfo['names'] as $name) { |
|
149
|
|
|
$prettyprintname = $name; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
$participant_type = $extinfo['type']; |
|
153
|
|
|
// fill the rest of the text |
|
154
|
|
|
$introtext = "EXISTING-FED"; |
|
155
|
|
|
// do the token creation magic |
|
156
|
|
|
$newtokens = $mgmt->createTokens(TRUE, $validAddresses, $prettyprintname, $newexternalid); |
|
157
|
|
|
$loggerInstance->writeAudit($_SESSION['user'], "NEW", "IdP FUTURE - Token created for " . implode(",", $validAddresses)); |
|
158
|
|
|
break; |
|
159
|
|
|
default: // includes OPERATION_MODE_INVALID |
|
160
|
|
|
$wrongcontent = print_r($_POST, TRUE); |
|
161
|
|
|
echo "<pre>Wrong parameters in POST: |
|
162
|
|
|
" . htmlspecialchars($wrongcontent) . " |
|
163
|
|
|
</pre>"; |
|
164
|
|
|
exit(1); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
// send, and invalidate the token immediately if the mail could not be sent! |
|
168
|
|
|
|
|
169
|
|
|
$status = []; |
|
170
|
|
|
$allEncrypted = TRUE; |
|
171
|
|
|
$allClear = TRUE; |
|
172
|
|
|
foreach ($newtokens as $onetoken => $oneDest) { |
|
173
|
|
|
$sent = \core\common\OutsideComm::adminInvitationMail($oneDest, $introtext, $onetoken, $prettyprintname, $federation, $participant_type); |
|
174
|
|
|
if ($sent["SENT"] === FALSE) { |
|
175
|
|
|
$mgmt->invalidateToken($onetoken); |
|
176
|
|
|
} else { |
|
177
|
|
|
$status[$onetoken] = $sent["TRANSPORT"]; |
|
178
|
|
|
if (!$sent["TRANSPORT"]) { |
|
179
|
|
|
$allEncrypted = FALSE; |
|
180
|
|
|
} else { |
|
181
|
|
|
$allClear = FALSE; |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
if (count($status) == 0) { |
|
187
|
|
|
header("Location: $redirectDestination" . "invitation=FAILURE"); |
|
188
|
|
|
exit; |
|
189
|
|
|
} |
|
190
|
|
|
$finalDestParams = "invitation=SUCCESS"; |
|
191
|
|
|
if (count($status) < count($totalSegments)) { // only a subset of mails was sent, update status |
|
192
|
|
|
$finalDestParams = "invitation=PARTIAL"; |
|
193
|
|
|
} |
|
194
|
|
|
$finalDestParams .= "&successcount=" . count($status); |
|
195
|
|
|
if ($allEncrypted === TRUE) { |
|
196
|
|
|
$finalDestParams .= "&transportsecurity=ENCRYPTED"; |
|
197
|
|
|
} elseif ($allClear === TRUE) { |
|
198
|
|
|
$finalDestParams .= "&transportsecurity=CLEAR"; |
|
199
|
|
|
} else { |
|
200
|
|
|
$finalDestParams .= "&transportsecurity=PARTIAL"; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
header("Location: $redirectDestination" . $finalDestParams); |
|
204
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.