displayRadiusPropertyWidget()   F
last analyzed

Complexity

Conditions 31
Paths > 20000

Size

Total Lines 190
Code Lines 154

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 31
eloc 154
c 2
b 0
f 0
nc 622080
nop 4
dl 0
loc 190
rs 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 page displays the dashboard overview of an entire IdP.
24
 * 
25
 * @author Stefan Winter <[email protected]>
26
 */
27
?>
28
<?php
29
require_once dirname(dirname(dirname(__FILE__))) . "/config/_config.php";
30
31
function displaySilverbulletPropertyWidget(&$theProfile, $readonly, &$uiElements) {
32
    ?>
33
    <div style='padding-bottom:20px;'>
34
        <h2><?php echo $theProfile->name; ?></h2>
35
        <?php
36
        $maxusers = $theProfile->getAttributes("internal:silverbullet_maxusers");
37
        $completeness = $theProfile->isEapTypeDefinitionComplete(new core\common\EAP(core\common\EAP::INTEGER_SILVERBULLET));
38
        // do we have all info needed for showtime? particularly: support email
39
        if (is_array($completeness)) {
40
            ?>
41
            <div class='notacceptable'>
42
                <?php echo _("Information needed!"); ?>
43
                <ul style='margin:1px'>
44
                    <?php
45
                    foreach ($completeness as $missing_attrib) {
46
                        echo "<li>" . $uiElements->displayName($missing_attrib) . "</li>";
47
                    }
48
                    ?>
49
                </ul>
50
            </div>
51
            <?php
52
        } else {
53
            echo sprintf(_("You can create up to %d users."), $maxusers[0]['value']) . "<br/>" . sprintf(_("Their credentials will carry the name <strong>%s</strong>."), $theProfile->realm);
54
        }
55
        ?>
56
        <br/>
57
        <br/>
58
        <?php
59
        if ($readonly === FALSE) {
60
            ?>
61
            <form action='edit_silverbullet.php?inst_id=<?php echo $theProfile->institution; ?>&amp;profile_id=<?php echo $theProfile->identifier; ?>' method='POST'>
62
                <button <?php echo ( is_array($completeness) ? "disabled" : "" ); ?> type='submit' name='sb_action' value='sb_edit'><?php echo _("Manage User Base"); ?></button>
63
            </form>
64
            <?php
65
        }
66
        ?>
67
    </div>
68
    <?php
69
}
70
71
/**
72
 * display an infocard with overview data of a RADIUS profile
73
 * 
74
 * @param \core\Profile             $theProfile the profile we display
75
 * @param boolean                   $readonly     are we in readonly mode? No edit buttons then...
76
 * @param \web\lib\admin\UIElements $uiElements   some UI elements
77
 * @param string                    $editMode 'fullaccess', 'readonly'
78
 * @throws Exception
79
 */
80
function displayRadiusPropertyWidget(&$theProfile, $readonly, &$uiElements, $editMode) {
81
    ?>
82
    <div style='padding-bottom:20px;'>
83
        <?php $profile_name = $theProfile->name; ?>
84
        <div style='margin-bottom:10px; display:block;'>
85
            <h2 style='overflow:auto; display:inline; padding-bottom: 10px;'><?php printf(_("Profile: %s"), $profile_name); ?></h2>
86
        </div>
87
        <?php
88
        // see if there are any profile-level overrides
89
        $attribs = $theProfile->getAttributes();
90
        // write things into a buffer; we need some function calls to determine
91
        // readiness - but want to display it before!
92
        $has_overrides = FALSE;
93
        foreach ($attribs as $attrib) {
94
            if ($attrib['level'] == \core\Options::LEVEL_PROFILE && !preg_match("/^(internal:|profile:name|profile:description|eap:)/", $attrib['name'])) {
95
                $has_overrides = TRUE;
96
            }
97
        }
98
        $buffer_eaptypediv = "<div style='margin-bottom:40px; float:left;'>" . _("<strong>EAP Types</strong> (in order of preference):") . "<br/>";
99
        $typelist = $theProfile->getEapMethodsinOrderOfPreference();
100
        $allcomplete = TRUE;
101
        foreach ($typelist as $eaptype) {
102
            $buffer_eaptypediv .= $eaptype->getPrintableRep();
103
            $completeness = $theProfile->isEapTypeDefinitionComplete($eaptype);
104
            if ($completeness === true) {
105
                $buffer_eaptypediv .= " <div class='acceptable'>" . _("OK") . "</div>";
106
            } else {
107
                $buffer_eaptypediv .= " <div class='notacceptable'>";
108
                $buffer_eaptypediv .= _("Information needed!");
109
                if (is_array($completeness)) {
110
                    $buffer_eaptypediv .= "<ul style='margin:1px'>";
111
                    foreach ($completeness as $missing_attrib) {
112
                        $buffer_eaptypediv .= "<li>" . $uiElements->displayName($missing_attrib) . "</li>";
113
                    }
114
                    $buffer_eaptypediv .= "</ul>";
115
                }
116
                $buffer_eaptypediv .= "</div>";
117
                $allcomplete = FALSE;
118
            }
119
            $attribs = $theProfile->getAttributes();
120
            $justOnce = FALSE;
121
            foreach ($attribs as $attrib) {
122
                if ($attrib['level'] == \core\Options::LEVEL_METHOD && !preg_match("/^internal:/", $attrib['name']) && !$justOnce) {
123
                    $justOnce = TRUE;
124
                    $buffer_eaptypediv .= "<img src='../resources/images/icons/Tabler/square-rounded-letter-e-blue.svg' alt='" . _("Options on EAP Method/Device level are in effect.") . "'>";
125
                }
126
            }
127
            $buffer_eaptypediv .= "<br/>";
128
        }
129
        $buffer_eaptypediv .= "</div>";
130
131
        $buffer_headline = "<div style='float:right;padding-left:10px'>";
132
        $readiness = $theProfile->readinessLevel();
133
        if ($has_overrides) {
134
            $buffer_headline .= $uiElements->boxRemark("", _("Option override on profile level is in effect."), TRUE);
135
        }
136
        $buffer_headline .= "<br/>";
137
        if (!$allcomplete) {
138
            $buffer_headline .= $uiElements->boxError("", _("The information in this profile is incomplete."), TRUE);
139
        }
140
        switch ($readiness) {
141
            case core\AbstractProfile::READINESS_LEVEL_SHOWTIME:
142
                $buffer_headline .= $uiElements->boxOkay("", _("This profile is shown on the user download interface."), TRUE);
143
                break;
144
            case core\AbstractProfile::READINESS_LEVEL_SUFFICIENTCONFIG:
145
                $buffer_headline .= $uiElements->boxWarning("", sprintf(_("This profile is NOT shown on the user download interface, even though we have enough information to show. To enable the profile, add the attribute \"%s\" and tick the corresponding box."), $uiElements->displayName("profile:production")), TRUE);
146
        }
147
        if ($theProfile->isRedirected()) {
148
            $iconData = $uiElements->iconData('PROFILES_REDIRECTED');
149
            $iconData['text'] = _("Profile redirected");
150
            $buffer_headline .= "<br/>" . $uiElements->catIcon(($iconData));
151
            
152
        } 
153
        
154
        $certStatus = $theProfile->certificateStatus();
155
        switch ($certStatus) {
156
            case core\AbstractProfile::CERT_STATUS_OK:
157
                $iconData = $uiElements->iconData('CERT_STATUS_OK');
158
                $buffer_headline .= "<br/>" . $uiElements->catIcon(($iconData));
159
                break;
160
            case core\AbstractProfile::CERT_STATUS_WARN:
161
                $iconData = $uiElements->iconData('CERT_STATUS_WARN');
162
                $buffer_headline .= "<br/>" . $uiElements->catIcon(($iconData));                
163
                break;
164
            case core\AbstractProfile::CERT_STATUS_ERROR:
165
                $iconData = $uiElements->iconData('CERT_STATUS_ERROR');
166
                $buffer_headline .= "<br/>" . $uiElements->catIcon(($iconData));
167
                break;            
168
        }
169
        $buffer_headline .= "</div>";
170
171
        echo $buffer_headline;
172
        echo $buffer_eaptypediv;
173
174
        $has_eaptypes = count($theProfile->getEapMethodsInOrderOfPreference(1));
175
        $hasRealmArray = $theProfile->getAttributes("internal:realm");
176
        $has_realm = $hasRealmArray[0]['value'];
177
178
        // our own base location, to give to diag URLs
179
        if (isset($_SERVER['HTTPS'])) {
180
            $link = 'https://';
181
        } else {
182
            $link = 'http://';
183
        }
184
        $link .= $_SERVER['SERVER_NAME'];
185
        ?>
186
        <div class='profilemodulebuttons' style='float:right;'>
187
            <?php
188
            if (\config\Master::FUNCTIONALITY_LOCATIONS['DIAGNOSTICS'] !== NULL) {
189
                if (\config\Master::FUNCTIONALITY_LOCATIONS['DIAGNOSTICS'] == "LOCAL") {
190
                    $diagUrl = "../diag/";
191
                } else {
192
                    $diagUrl = \config\Master::FUNCTIONALITY_LOCATIONS['DIAGNOSTICS'] . "/diag/";
193
                }
194
                ?>
195
                <form action='<?php echo $diagUrl . "action_realmcheck.php?inst_id=" . $theProfile->institution . "&profile_id=" . $theProfile->identifier ?>' method='post' accept-charset='UTF-8'>
196
                    <input type='hidden' name='comefrom' value='<?php echo htmlspecialchars($link . $_SERVER['SCRIPT_NAME']); ?>'/>
197
                    <button type='submit' name='profile_action' value='check' <?php echo ($has_realm ? "" : "disabled='disabled'"); ?> title='<?php echo _("The realm can only be checked if you configure the realm!"); ?>'>
198
                        <?php echo _("Check realm reachability"); ?>
199
                    </button>
200
                </form>
201
                <?php
202
            }
203
            ?>
204
            <form action='overview_installers.php?inst_id=<?php echo $theProfile->institution; ?>&amp;profile_id=<?php echo $theProfile->identifier; ?>' method='post' accept-charset='UTF-8'>
205
                <button type='submit' name='profile_action' value='check' <?php echo ($has_eaptypes ? "" : "disabled='disabled'"); ?> title='<?php echo _("You have not fully configured any supported EAP types!"); ?>'>
206
                    <?php echo _("Installer Fine-Tuning and Download"); ?>
207
                </button>
208
            </form>
209
        </div>
210
        <div class='buttongroupprofilebox' style='clear:both; display: flex;'>
211
            <?php 
212
                if ($editMode == 'readonly') {
213
                    $editLabel = _("View");
214
                }
215
                if ($editMode == 'fullaccess') {
216
                    $editLabel = _("Edit");
217
                }
218
            if ($readonly === FALSE) { ?>
219
                <div style='margin-right: 200px; display: ruby'>
220
                    <form action='edit_profile.php?inst_id=<?php echo $theProfile->institution; ?>&amp;profile_id=<?php echo $theProfile->identifier; ?>' method='post' accept-charset='UTF-8'>
221
                        <hr/>
222
                        <button type='submit' name='profile_action' value='edit'><?php echo $editLabel; ?></button>
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $editLabel does not seem to be defined for all execution paths leading up to this point.
Loading history...
223
                    </form>
224
                    <?php if ($editMode == 'fullaccess') { ?>
225
                    <form action='edit_profile_result.php?inst_id=<?php echo $theProfile->institution; ?>&amp;profile_id=<?php echo $theProfile->identifier; ?>' method='post' accept-charset='UTF-8'>
226
                        <button class='delete' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_DELETE; ?>' onclick="return confirm('<?php echo sprintf(_("Do you really want to delete the profile %s?"), $profile_name); ?>')">
227
                            <?php echo _("Delete") ?>
228
                        </button>
229
                    </form>
230
                    
231
                    <form action='duplicate_profile.php?inst_id=<?php echo $theProfile->institution; ?>&amp;profile_id=<?php echo $theProfile->identifier; ?>' method='post' accept-charset='UTF-8'>
232
                        <button type='submit' name='profile_duplicate'>
233
                    <?php echo _("Duplicate this profile"); ?>
234
                </button>
235
            </form>
236
                    <?php } ?>
237
                </div>
238
                <?php
239
            }
240
            if ($readiness == core\AbstractProfile::READINESS_LEVEL_SHOWTIME) {
241
                ?>
242
                <div style='display: flex;'>
243
                    <?php
244
                    $idpLevelUrl = $link . dirname(dirname($_SERVER['SCRIPT_NAME'])) . "?idp=" . $theProfile->institution;
245
                    $displayurl = $idpLevelUrl . "&amp;profile=" . $theProfile->identifier;
246
                    $QRurl = $idpLevelUrl . "&profile=" . $theProfile->identifier;
247
                    $qrCode = new \chillerlan\QRCode\QRCode(new \chillerlan\QRCode\QROptions([
248
                                'outputType' => \chillerlan\QRCode\QRCode::OUTPUT_IMAGE_PNG,
249
                                'eccLevel' => \chillerlan\QRCode\QRCode::ECC_H,
250
                                'scale' => web\lib\admin\UIElements::QRCODE_PIXELS_PER_SYMBOL,
251
                                'imageBase64' => false,
252
                    ]));
253
                    echo "<a href='$displayurl' style='white-space: nowrap; text-align: center;'>";
254
                    $rawQr = $qrCode->render($QRurl);
255
                    if (empty($rawQr)) {
256
                        throw new Exception("Something went seriously wrong during QR code generation!");
257
                    }
258
                    $uri = "data:image/png;base64," . base64_encode($uiElements->pngInjectConsortiumLogo($rawQr, web\lib\admin\UIElements::QRCODE_PIXELS_PER_SYMBOL));
259
                    $size = getimagesize($uri);
260
                    echo "<img width='" . ($size[0] / 4) . "' height='" . ($size[1] / 4) . "' src='$uri' alt='QR-code'/>";
261
262
                    //echo "<nobr>$displayurl</nobr></a>";
263
                    echo "<p>$displayurl</p></a>";
264
                    ?>
265
                </div>
266
                <?php
267
            }
268
            ?>
269
        </div>
270
    </div>
271
    <?php
272
}
273
274
/**
275
 * displays an infocard about a Managed SP deployment
276
 * 
277
 * @param \core\DeploymentManaged $deploymentObject the deployment to work with
278
 * @throws Exception
279
 */
280
function displayDeploymentPropertyWidget(&$deploymentObject) {
281
    // RADIUS status icons
282
    $radiusMessages = [
283
        \core\AbstractDeployment::RADIUS_OK => ['icon' => '../resources/images/icons/Tabler/square-rounded-check-filled-green.svg', 'text' => _("Successfully set profile")],
284
        \core\AbstractDeployment::RADIUS_FAILURE => ['icon' => '../resources/images/icons/Tabler/square-rounded-x-filled-red.svg', 'text' => _("Some problem occurred during profile update")],
285
    ];
286
287
    $radius_status = array();
288
    $radius_status[0] = $deploymentObject->radius_status_1;
289
    $radius_status[1] = $deploymentObject->radius_status_2;
290
    $retry = $deploymentObject->checkRADIUSHostandConfigDaemon();
291
    if (is_array($retry)) {
292
        foreach ($retry as $id => $stat) {
293
            if ($stat) {
294
                $response = $deploymentObject->setRADIUSconfig($id, 1);
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
295
            }
296
        }
297
    }
298
    ?>
299
    <div style='display: table-row_id;'>
300
        <div class='profilebox' style='display: table-cell;'>
301
            <h2><?php
302
                switch ($deploymentObject->consortium) {
303
                    case "eduroam":
304
                        $displayname = config\ConfAssistant::CONSORTIUM['name'] . " " . core\DeploymentManaged::PRODUCTNAME;
305
                        break;
306
                    case "OpenRoaming":
307
                        $displayname = "OpenRoaming ANP";
308
                        break;
309
                    default:
310
                        throw new Exception("We are supposed to operate on a roaming consortium we don't know.");
311
                }
312
                echo $displayname . " (<span style='color:" . ( $deploymentObject->status == \core\AbstractDeployment::INACTIVE ? "red;'>" . _("inactive") : "green;'>" . _("active") ) . "</span>)";
313
                ?></h2>
314
            <table>
315
                <caption><?php echo _("Deployment Details"); ?></caption>
316
                <tr>
317
                    <th class='wai-invisible' scope='col'><?php echo("Server IP addresses"); ?></th>
318
                    <th class='wai-invisible' scope='col'><?php echo("Server Port label"); ?></th>
319
                    <th class='wai-invisible' scope='col'><?php echo("Server Port value"); ?></th>
320
                    <th class='wai-invisible' scope='col'><?php echo("Deployment Status"); ?></th>
321
                </tr>
322
                <tr>
323
                    <td><strong><?php echo _("Your primary RADIUS server") ?></strong><br/>
324
                        <?php
325
                        if ($deploymentObject->host1_v4 !== NULL) {
326
                            echo _("IPv4") . ": " . $deploymentObject->host1_v4;
327
                        }
328
                        if ($deploymentObject->host1_v4 !== NULL && $deploymentObject->host1_v6 !== NULL) {
329
                            echo "<br/>";
330
                        }
331
                        if ($deploymentObject->host1_v6 !== NULL) {
332
                            echo _("IPv6") . ": " . $deploymentObject->host1_v6;
333
                        }
334
                        ?>
335
                    </td>
336
                    <td><?php echo _("RADIUS port number: ") ?></td>
337
                    <td><?php echo $deploymentObject->port1; ?></td>
338
                    <td>
339
                        <?php
340
                        echo "<img src='" . $radiusMessages[$deploymentObject->radius_status_1]['icon'] .
341
                        "' alt='" . $radiusMessages[$deploymentObject->radius_status_1]['text'] .
342
                        "' title='" . $radiusMessages[$deploymentObject->radius_status_1]['text'] . "' class='cat-icon'>";
343
                        ?>
344
                    </td>
345
                </tr>
346
                <tr>
347
                    <td><strong><?php echo _("Your backup RADIUS server") ?><br/></strong>
348
                        <?php
349
                        if ($deploymentObject->host2_v4 !== NULL) {
350
                            echo _("IPv4") . ": " . $deploymentObject->host2_v4;
351
                        }
352
                        if ($deploymentObject->host2_v4 !== NULL && $deploymentObject->host2_v6 !== NULL) {
353
                            echo "<br/>";
354
                        }
355
                        if ($deploymentObject->host2_v6 !== NULL) {
356
                            echo _("IPv6") . ": " . $deploymentObject->host2_v6;
357
                        }
358
                        ?></td>
359
                    <td><?php echo _("RADIUS port number: ") ?></td>
360
                    <td><?php echo $deploymentObject->port2; ?></td>
361
                    <td>
362
                        <?php
363
                        echo "<img src='" . $radiusMessages[$deploymentObject->radius_status_2]['icon'] .
364
                        "' alt='" . $radiusMessages[$deploymentObject->radius_status_2]['text'] .
365
                        "' title='" . $radiusMessages[$deploymentObject->radius_status_2]['text'] . "' class='cat-icon'>";
366
                        ?>
367
                    </td>
368
                </tr>
369
370
                <tr>
371
                    <td><strong><?php echo _("RADIUS shared secret"); ?></strong></td>
372
                    <td><?php echo $deploymentObject->secret; ?></td>
373
                </tr>
374
                <tr><td colspan="4"><hr></td></tr>
375
                <?php if ($opname = $deploymentObject->getAttributes("managedsp:operatorname")[0]['value'] ?? NULL) { ?>
376
                    <tr>
377
                        <td><strong><?php echo _("Custom Operator-Name"); ?></strong></td>
378
                        <td><?php echo $opname; ?></td>
379
                    </tr>
380
                    <?php
381
                }
382
                if ($vlan = $deploymentObject->getAttributes("managedsp:vlan")[0]['value'] ?? NULL) {
383
                    ?>
384
                    <tr>
385
                        <td><strong><?php echo _("VLAN tag for own users"); ?></strong></td>
386
                        <td><?php echo $vlan; ?></td>
387
                    </tr>
388
                <?php } ?>
389
                <?php
390
                $allRealms = array_values(array_unique(array_column($deploymentObject->getAttributes("managedsp:realmforvlan"), "value")));
391
                if (!empty($allRealms)) {
392
                    ?>
393
                    <tr>
394
                        <td><strong><?php echo _("Realm to be considered own users"); ?></strong></td>
395
                        <td><?php echo implode(', ', $allRealms); ?></td>
396
                    </tr>
397
                    <?php
398
                }
399
                ?>
400
            </table>
401
            <div class='buttongroupprofilebox' style='clear:both;'>
402
                <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
403
                    <br/>
404
                    <button type='submit' name='profile_action' style='cursor:pointer;' value='edit'><?php echo _("Advanced Configuration"); ?></button>
405
                </form>
406
                <?php if ($deploymentObject->status == \core\AbstractDeployment::ACTIVE) { ?>
407
                    <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
408
                        <button class='delete' type='submit' style='cursor:pointer;' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_DELETE; ?>' onclick="return confirm('<?php printf(_("Do you really want to deactivate the %s deployment?"), core\DeploymentManaged::PRODUCTNAME); ?>')">
409
                            <?php echo _("Deactivate"); ?>
410
                        </button>
411
                        <?php
412
                        if (isset($_GET['res']) && is_array($_GET['res'])) {
413
                            $res = array_count_values($_GET['res']);
414
                            if (array_key_exists('FAILURE', $res) && $res['FAILURE'] > 0) {
415
                                echo '<br>';
416
                                if ($res['FAILURE'] == 2) {
417
                                    echo ' <span style="color: red;">' . _("Activation failure.") . '</span>';
418
                                } else {
419
                                    if (isset($_GET['res'][1]) && $_GET['res']['1'] == 'FAILURE') {
420
                                        echo ' <span style="color: red;">' . _("Activation failure for your primary RADIUS server.") . '</span>';
421
                                    } else {
422
                                        echo ' <span style="color: red;">' . _("Activation failure for your backup RADIUS server.") . '</span>';
423
                                    }
424
                                }
425
                            }
426
                        }
427
                        ?>
428
                    </form>
429
                    <?php
430
                } elseif (count($deploymentObject->getAttributes("hiddenmanagedsp:tou_accepted")) == 0) {
431
                    ?>
432
                    <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
433
                        <button class='delete' style='background-color: yellow; color: black;' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_TERMSOFUSE_NEEDACCEPTANCE; ?>'>
434
                            <?php echo _("Accept Terms of Use"); ?>
435
                        </button>
436
                    </form>
437
                    <div align="right">
438
                    <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
439
                            <button class='delete' style='background-color: yellow; color: black' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_REMOVESP; ?>' onclick="return confirm('<?php printf(_("Do you really want to remove this %s deployment?"), core\DeploymentManaged::PRODUCTNAME); ?>')">
440
                                <?php echo _("Remove deployment"); ?>
441
                            </button>
442
                    </form>
443
                    </div>
444
                    <?php
445
                    } else {
446
                        ?>
447
                        <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
448
                            <button class='delete' style='background-color: green;' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_ACTIVATE; ?>'>
449
                                <?php echo _("Activate"); ?>
450
                            </button>
451
                            <?php
452
                            if (isset($_GET['res']) && is_array($_GET['res'])) {
453
                                $res = array_count_values($_GET['res']);
454
                                if ($res['FAILURE'] > 0) {
455
                                    echo '<br>';
456
                                    if ($res['FAILURE'] == 2) {
457
                                        echo ' <span style="color: red;">' . _("Failure during deactivation, your request is queued for handling") . '</span>';
458
                                    } else {
459
                                        if (isset($_GET['res'][1]) && $_GET['res']['1'] == 'FAILURE') {
460
                                            echo ' <span style="color: red;">' . _("Deactivation failure for your primary RADIUS server, your request is queued.") . '</span>';
461
                                        } else {
462
                                            echo ' <span style="color: red;">' . _("Deactivation failure for your backup RADIUS server, your request is queued.") . '</span>';
463
                                        }
464
                                    }
465
                                }
466
                            }
467
                            ?>
468
                        </form>
469
                        <div align="right">
470
                        <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
471
                            <button class='delete' style='background-color: yellow; color: black' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_REMOVESP; ?>' onclick="return confirm('<?php printf(_("Do you really want to remove this %s deployment?"), core\DeploymentManaged::PRODUCTNAME); ?>')">
472
                                <?php echo _("Remove deployment"); ?>
473
                            </button>
474
                        </form>
475
                        </div>
476
                        <?php
477
                    }
478
                    ?>
479
            </div>
480
        </div>
481
        <div style='width:20px;'></div> <!-- QR code space, reserved -->
482
        <div style='display: table-cell; min-width:200px;'>
483
            <?php $tablecaption = _("Hotspot Usage Statistics");?>
484
            <h1><?php echo $tablecaption; ?></h1>
485
            <h2><?php echo _("5 most recent authentications");?></h2>
486
            <p><?php echo _("(AP Identifier is a /-separated tuple of NAS-Identifier/NAS-IP-Address/NAS-IPv6-Address/Called-Station-Id)");?></p>
487
            <table class='authrecord'>
488
    <caption><?php echo $tablecaption;?></caption>
489
    <tr style='text-align: left;'>
490
        <th scope="col"><strong><?php echo _("Timestamp (UTC)");?></strong></th>
491
        <th scope="col"><strong><?php echo _("Realm");?></strong></th>
492
        <th scope="col"><strong><?php echo _("MAC Address");?></strong></th>
493
        <th scope="col"><strong><?php echo _("Chargeable-User-Identity");?></strong></th>
494
        <th scope="col"><strong><?php echo _("Result");?></strong></th>
495
        <th scope="col"><strong><?php echo _("AP Identifier");?></strong></th>
496
    </tr>
497
    <?php
498
    $userAuthData = $deploymentObject->retrieveStatistics(0,5);
499
    foreach ($userAuthData as $oneRecord) {
500
        echo "<tr class='".($oneRecord['result'] == "OK" ? "auth-success" : "auth-fail" )."'>"
501
                . "<td>".$oneRecord['activity_time']."</td>"
502
                . "<td>".$oneRecord['realm']."</td>"
503
                . "<td>".$oneRecord['mac']."</td>"
504
                . "<td>".$oneRecord['cui']."</td>"
505
                . "<td>".($oneRecord['result'] == "OK" ? _("Success") : _("Failure"))."</td>"
506
                . "<td>".$oneRecord['ap_id']."</td>"
507
                . "</tr>";
508
    }
509
    ?>
510
</table>
511
            <div style='display: ruby;'><form action="inc/deploymentStats.inc.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>" onsubmit='popupRedirectWindow(this); return false;' accept-charset='UTF-8' method='post'>
512
                <button type='submit' id='stats-hour' name='stats' value='HOUR'><?php echo _("Last hour"); ?></button>
513
            </form>
514
            <form action="inc/deploymentStats.inc.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>" onsubmit='popupRedirectWindow(this); return false;' accept-charset='UTF-8' method='post'>
515
                <button type='submit' id='stats-month' name='stats' value='MONTH'><?php echo _("Last 30 days"); ?></button>
516
            </form>
517
            <form action="inc/deploymentStats.inc.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>" onsubmit='popupRedirectWindow(this); return false;' accept-charset='UTF-8' method='post'>
518
                <button type='submit' id='stats-full' name='stats' value='FULL'><?php echo _("Last 6 months"); ?></button>
519
            </form>
520
            </div>
521
        </div><!-- statistics space -->
522
    </div> 
523
    <!-- dummy div to keep a little distance-->
524
    <div style='height:20px'></div>
525
    <?php
526
}
527
528
/**
529
 * displays a eduroam DB entry for SPs. Not implemented yet.
530
 * 
531
 * @param \core\DeploymentClassic $deploymentObject the deployment to work with
532
 */
533
function displayClassicHotspotPropertyWidget($deploymentObject) {
0 ignored issues
show
Unused Code introduced by
The parameter $deploymentObject is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

533
function displayClassicHotspotPropertyWidget(/** @scrutinizer ignore-unused */ $deploymentObject) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
534
    
535
}
536
537
$deco = new \web\lib\admin\PageDecoration();
538
$validator = new \web\lib\common\InputValidation();
539
$uiElements = new web\lib\admin\UIElements();
540
541
echo $deco->defaultPagePrelude(sprintf(_("%s: %s Dashboard"), \config\Master::APPEARANCE['productname'], $uiElements->nomenclatureParticipant));
542
require_once "inc/click_button_js.php";
543
544
// let's check if the inst handle actually exists in the DB
545
[$my_inst, $editMode] = $validator->existingIdPInt($_GET['inst_id'], $_SESSION['user']);
546
547
$myfed = new \core\Federation($my_inst->federation);
548
549
// delete stored realm
550
551
if (isset($_SESSION['check_realm'])) {
552
    unset($_SESSION['check_realm']);
553
}
554
$mapCode = web\lib\admin\AbstractMap::instance($my_inst, TRUE);
555
echo $mapCode->htmlHeadCode();
556
?>
557
<script src="js/XHR.js" type="text/javascript"></script>    
558
<script src="js/popup_redirect.js" type="text/javascript"></script>
559
<script type="text/javascript" src="../external/jquery/jquery-ui.js"></script> 
560
<link rel="stylesheet" type="text/css" href="../external/jquery/jquery-ui.css" />
561
<script>
562
$(document).ready(function() {    
563
    $("img.cat-icon").tooltip();
564
});
565
</script>        
566
        
567
<body <?php echo $mapCode->bodyTagCode(); ?>>
568
    <?php
569
    echo $deco->productheader("ADMIN-PARTICIPANT");
570
571
// Sanity check complete. Show what we know about this IdP.
572
    $idpoptions = $my_inst->getAttributes();
573
    if ($editMode == 'readonly') {
574
        $editLabel = _("View ...");
575
    }
576
    if ($editMode == 'fullaccess') {
577
        $editLabel = _("Edit ...");
578
    }
579
    ?>
580
    <h1><?php echo sprintf(_("%s Overview"), $uiElements->nomenclatureParticipant); ?></h1>
581
    <hr/>
582
    <div>
583
        <h2 style='display: flex;'><?php echo sprintf(_("%s general settings"), $uiElements->nomenclatureParticipant); ?>&nbsp;
584
            <form action='edit_participant.php?inst_id=<?php echo $my_inst->identifier; ?>' method='post' accept-charset='UTF-8'>
585
                <button type='submit' name='submitbutton' value='<?php echo \web\lib\common\FormElements::BUTTON_EDIT; ?>'><?php echo $editLabel; ?></button>
586
            </form>
587
        </h2>
588
        <?php
589
        echo $uiElements->instLevelInfoBoxes($my_inst);
590
        ?>
591
        <?php
592
        foreach ($idpoptions as $optionname => $optionvalue) {
593
            if ($optionvalue['name'] == "general:geo_coordinates") {
594
                echo '<div class="infobox">';
595
                echo $mapCode->htmlShowtime();
596
                echo '</div>';
597
                break;
598
            }
599
        }
600
        ?>
601
602
    </div>
603
    <hr/>
604
    <?php
605
    $readonly = \config\Master::DB['INST']['readonly'];
606
    if (preg_match("/IdP/", $my_inst->type)) {
607
        ?>
608
        <h2 style='display: flex;'><?php printf(_("%s: %s Deployment Details"), $uiElements->nomenclatureParticipant, $uiElements->nomenclatureIdP); ?>&nbsp;
609
            <?php
610
            $profiles_for_this_idp = $my_inst->listProfiles();
611
            if ($readonly === FALSE) {
612
613
                // the opportunity to add a new silverbullet profile is only shown if
614
                // a) there is no SB profile yet
615
                // b) federation wants this to happen
616
                // first find out if we already have SB profiles
617
                $sbProfileExists = FALSE;
618
                foreach ($profiles_for_this_idp as $profilecount => $profile_list) {
619
                    switch (get_class($profile_list)) {
620
                        case "core\ProfileSilverbullet":
621
                            $sbProfileExists = TRUE;
622
                            break;
623
                        default:
624
                    }
625
                }
626
627
                if (\config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_SILVERBULLET'] == "LOCAL" && count($myfed->getAttributes("fed:silverbullet")) > 0 && $sbProfileExists === FALSE) {
628
                    // the button is greyed out if there's no support email address configured...
629
                    $hasMail = count($my_inst->getAttributes("support:email"));
630
                    ?>
631
                    <form action='edit_silverbullet.php?inst_id=<?php echo $my_inst->identifier; ?>' method='post' accept-charset='UTF-8'>
632
                            <button type='submit' <?php echo ($hasMail > 0 ? "" : "disabled"); ?> name='profile_action' value='new'>
633
                                <?php echo sprintf(_("Add %s profile ..."), \core\ProfileSilverbullet::PRODUCTNAME); ?>
634
                            </button>
635
                    </form>&nbsp;
636
                    <?php
637
                }
638
                ?>
639
640
                <?php
641
                // adding a normal profile is always possible if we're configured for it
642
                if (\config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_RADIUS'] == "LOCAL" && $editMode === 'fullaccess') {
643
                    ?>
644
                    <form action='edit_profile.php?inst_id=<?php echo $my_inst->identifier; ?>' method='post' accept-charset='UTF-8'>
645
                        <div>
646
                            <button type='submit' name='profile_action' value='new'>
647
                                <?php echo _("New RADIUS/EAP profile (manual setup) ..."); ?>
648
                            </button>
649
                        </div>
650
                    </form>&nbsp;
651
                    <form method='post' action='inc/profileAutodetectCA.inc.php?inst_id=<?php echo $my_inst->identifier; ?>' onsubmit='popupRedirectWindow(this); return false;' accept-charset='UTF-8'>
652
                        <div>
653
                            <button type='submit' name='profile_action' value='new'>
654
                                <?php echo _("New RADIUS/EAP profile (autodetect server details) ..."); ?>
655
                            </button>
656
                        </div>
657
                    </form>
658
                    <?php
659
                }
660
            }
661
            ?>
662
        </h2>
663
    <?php if(count($profiles_for_this_idp) > 1 && $readonly === FALSE && $editMode === 'fullaccess') { ?>
664
                    <form method='post' action='sort_profiles.php?inst_id=<?php echo $my_inst->identifier; ?>' accept-charset='UTF-8'>
665
                        <div>
666
                            <button type='submit' name='profile_sorting'>
667
                                <?php echo _("Change the order of profiles"); ?>
668
                            </button>
669
                        </div>
670
                    </form>  <p>  
671
    <?php }
672
        if (count($profiles_for_this_idp) == 0) { // no profiles yet.
673
            printf(_("There are not yet any profiles for your %s."), $uiElements->nomenclatureIdP);
674
        }
675
// if there is one profile and it is of type Silver Bullet, display a very
676
// simple widget with just a "Manage" button
677
        foreach ($profiles_for_this_idp as $profilecount => $profile_list) {
678
            ?>
679
            <div style='display: table-row_id; margin-bottom: 20px;'>
680
                <div class='profilebox' style='display: table-cell; min-width: 650px;'>
681
                    <?php
682
                    switch (get_class($profile_list)) {
683
                        case "core\ProfileSilverbullet":
684
                            displaySilverbulletPropertyWidget($profile_list, $readonly, $uiElements);
685
                            break;
686
                        case "core\ProfileRADIUS":
687
                            displayRadiusPropertyWidget($profile_list, $readonly, $uiElements, $editMode);
688
                            break;
689
                        default:
690
                            throw new Exception("We were asked to operate on something that is neither a RADIUS nor Silverbullet profile!");
691
                    }
692
                    ?>
693
                </div>
694
                <!-- dummy width to keep a little distance -->
695
                <div style='width:20px;'></div>
696
                <div style='display: table-cell; min-width:200px;'>
697
                    <p>
698
                        <strong><?php echo _("User Downloads"); ?></strong>
699
                    </p>
700
                    <table class="downloads">
701
                        <tr><td></td>
702
                        <?php
703
                        echo "<td>"._("global")."</td><td>"._("this month")."</td></tr>";
704
                        $stats = $profile_list->getUserDownloadStats();
705
                        foreach ($stats as $dev => $count) {
706
                            echo "<tr><td><strong>$dev</strong></td><td>".$count['current']."</td><td>".$count['monthly']."</td></tr>";
707
                        }
708
                        ?>
709
                    </table>
710
                </div>
711
            </div>
712
            <!-- dummy div to keep a little distance-->
713
            <div style='height:20px'></div>
714
            <?php
715
        }
716
        ?>
717
        <hr/>
718
        <?php
719
    }
720
    if (\config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_SILVERBULLET'] == "LOCAL" && count($myfed->getAttributes("fed:silverbullet")) > 0) {
721
    if (preg_match("/SP/", $my_inst->type)) {
722
        ?>
723
        <h2 style='display: flex;'><?php printf(_("%s: %s Deployment Details"), $uiElements->nomenclatureParticipant, $uiElements->nomenclatureHotspot); ?>&nbsp;
724
            <?php
725
            if ($readonly === FALSE && $editMode === 'fullaccess') {
726
                if (\config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_SILVERBULLET'] == "LOCAL" && count($myfed->getAttributes("fed:silverbullet")) > 0) {
727
                    // the button is greyed out if there's no support email address configured...
728
                    $hasMail = count($my_inst->getAttributes("support:email"));
729
                    ?>
730
                    <form action='edit_hotspot.php?inst_id=<?php echo $my_inst->identifier; ?>' method='post' accept-charset='UTF-8'>
731
                        <div>
732
                            <input type="hidden" name="consortium" value="eduroam"/>
733
                            <button type='submit' <?php echo ($hasMail > 0 ? "" : "disabled"); ?> name='profile_action' value='new'>
734
                                <?php echo sprintf(_("Add %s deployment ..."), \config\ConfAssistant::CONSORTIUM['name'] . " " . \core\DeploymentManaged::PRODUCTNAME); ?>
735
                            </button>
736
                            <span style='color: red;'>
737
                            <?php if ($hasMail == 0) { 
738
                              echo _("Helpdesk mail address is required but missing!");  
739
                            }
740
                            ?>
741
                            </span>
742
                        </div>
743
                    </form>
744
                    
745
                    <?php 
746
                    /*
747
                    if (count($myfed->getAttributes("fed:openroaming")) > 0) {
748
                        ?>
749
                        &nbsp;
750
                        <form action='edit_hotspot.php?inst_id=<?php echo $my_inst->identifier; ?>' method='post' accept-charset='UTF-8'>
751
                            <div>
752
                                <input type="hidden" name="consortium" value="OpenRoaming"/>
753
                                <button type='submit' <?php echo ($hasMail > 0 ? "" : "disabled"); ?> name='profile_action' value='new'>
754
                                    <?php echo sprintf(_("Add %s deployment ..."), "OpenRoaming ANP"); ?>
755
                                </button>
756
757
                            </div>
758
                        </form>
759
                        <?php
760
                    }
761
                    */
762
                }
763
            }
764
            ?>
765
        </h2>
766
        <?php
767
        $hotspotProfiles = $my_inst->listDeployments();
768
        if (count($hotspotProfiles) == 0) { // no profiles yet.
769
            echo sprintf(_("There are not yet any known deployments for your %s."), $uiElements->nomenclatureHotspot);
770
        }
771
772
        foreach ($hotspotProfiles as $counter => $deploymentObject) {
773
            switch (get_class($deploymentObject)) {
774
                case "core\DeploymentManaged":
775
                    displayDeploymentPropertyWidget($deploymentObject);
776
                    break;
777
                case "core\DeploymentClassic":
778
                    displayClassicHotspotPropertyWidget($deploymentObject);
779
                    break;
780
                default:
781
                    throw new Exception("We were asked to operate on something that is neither a classic nor a Managed hotspot deployment!");
782
            }
783
        }
784
    }
785
    }
786
    echo $deco->footer();
787
    
788