Passed
Push — master ( 3e6070...95d24c )
by Stefan
06:34
created

bailout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * *****************************************************************************
4
 * Contributions to this work were made on behalf of the GÉANT project, a 
5
 * project that has received funding from the European Union’s Framework 
6
 * Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
7
 * Horizon 2020 research and innovation programme under Grant Agreements No. 
8
 * 691567 (GN4-1) and No. 731122 (GN4-2).
9
 * On behalf of the aforementioned projects, GEANT Association is the sole owner
10
 * of the copyright in all material which was developed by a member of the GÉANT
11
 * project. GÉANT Vereniging (Association) is registered with the Chamber of 
12
 * Commerce in Amsterdam with registration number 40535155 and operates in the 
13
 * UK as a branch of GÉANT Vereniging.
14
 * 
15
 * Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. 
16
 * UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
17
 *
18
 * License: see the web/copyright.inc.php file in the file structure or
19
 *          <base_url>/copyright.php after deploying the software
20
 */
21
22
/**
23
 * This file executes the enrollment of a new admin to the system.
24
 * 
25
 * The administrator authenticates and then presents an invitation token via
26
 * the $_GET['token'] parameter.
27
 * 
28
 * @author Stefan Winter <[email protected]>
29
 */
30
?>
31
<?php
32
33
require_once dirname(dirname(dirname(__FILE__))) . "/config/_config.php";
34
35
$auth = new \web\lib\admin\Authentication();
36
$deco = new \web\lib\admin\PageDecoration();
37
$validator = new \web\lib\common\InputValidation();
38
$elements = new \web\lib\admin\UIElements();
39
$usermgmt = new \core\UserManagement();
40
41
$auth->authenticate();
42
43
if (!isset($_GET['token'])) {
44
    $elements->errorPage(_("Error creating new IdP binding!"),_("This page needs to be called with a valid invitation token!"));
45
}
46
47
if (\config\ConfAssistant::CONFIG['CONSORTIUM']['selfservice_registration'] === NULL && $_GET['token'] == "SELF-REGISTER") {
48
    $elements->errorPage(_("Error creating new IdP binding!"),_("You tried to register in self-service, but this deployment does not allow self-service!"));
49
}
50
51
switch ($_GET['token']) {
52
    case "SELF-REGISTER":
53
        $token = "SELF-REGISTER";
54
        $checkval = \core\UserManagement::TOKENSTATUS_OK_NEW;
55
        $federation = \config\ConfAssistant::CONFIG['CONSORTIUM']['selfservice_registration'];
56
        break;
57
    default:
58
        $token = $validator->token(filter_input(INPUT_GET,'token',FILTER_SANITIZE_STRING));
59
        $checkval = $usermgmt->checkTokenValidity($token);
60
}
61
62
if ($checkval < 0) {
63
    echo $deco->pageheader(_("Error creating new IdP binding!"), "ADMIN-IDP");
64
    echo "<h1>" . _("Error creating new IdP binding!") . "</h1>";
65
    switch ($checkval) {
66
        case \core\UserManagement::TOKENSTATUS_FAIL_ALREADYCONSUMED:
67
            echo "<p>" . sprintf(_("Sorry... this token has already been used. The %s is already created. If you got the invitation from a mailing list, probably someone else used it before you."), $elements->nomenclatureInst) . "</p>";
68
            break;
69
        case \core\UserManagement::TOKENSTATUS_FAIL_EXPIRED:
70
            echo "<p>" . sprintf(_("Sorry... this token has expired. Invitation tokens are valid for 24 hours. The %s administrator can create a new one for you."), $elements->nomenclatureFed) . "</p>";
71
            break;
72
        default:
73
            echo "<p>" . _("Sorry... you have come to the enrollment page without a valid token. Are you a nasty person? If not, you should go to <a href='overview_user.php'>your profile page</a> instead.") . "</p>";
74
    }
75
    echo $deco->footer();
76
    throw new Exception("Terminating because something is wrong with the token we received.");
77
}
78
79
// token is valid. Get meta-info and create inst
80
$user = $validator->syntaxConformUser($_SESSION['user']);
81
82
$loggerInstance = new \core\common\Logging();
83
84
switch ($token) {
85
    case "SELF-REGISTER":
86
        $fed = new \core\Federation($federation);
87
        $newidp = new \core\IdP($fed->newIdP(core\IdP::TYPE_IDPSP, $user, "FED", "SELFSERVICE"));
88
        $loggerInstance->writeAudit($user, "MOD", "IdP " . $newidp->identifier . " - selfservice registration");
89
        break;
90
    default:
91
        $newidp = $usermgmt->createIdPFromToken($token, $user);
92
        $usermgmt->invalidateToken($token);
93
        $loggerInstance->writeAudit($user, "MOD", "IdP " . $newidp->identifier . " - Token used and invalidated");
94
        break;
95
}
96
97
if ($checkval == \core\UserManagement::TOKENSTATUS_OK_EXISTING) {
98
    header("Location: overview_user.php");
99
} else {
100
    header("Location: edit_participant.php?inst_id=$newidp->identifier&wizard=true");
101
}
102