copyIcon()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 1
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
 /**
24
 * This file is used to display a deployment.
25
 * 
26
 * @author Maja Gorecka-Wolniewicz <[email protected]>
27
 */
28
?>
29
<?php
30
31
$error_message = [
32
    'WRONGCSR' => _('The uploaded file does not contain a valid CSR!'),
33
    'NOCSR' => _('The provided file can not be uploaded.'),
34
];
35
36
$langInstance = new \core\common\Language();
37
$start = $langInstance->rtl ? "right" : "left";
38
$end = $langInstance->rtl ? "left" : "right";
39
$errormsg = [];
40
if (isset($_GET['errormsg'])) {
41
    $msg = explode('_', trim($_GET['errormsg']));
42
    if (count($msg) == 2) {
43
        $errormsg[$msg[1]] = $error_message[$msg[0]];
44
    }
45
}
46
?>
47
<style>
48
    .deployments td:first-child {
49
        padding-right: 15px;
50
    }
51
    img.copy_link {
52
        position: relative;
53
        top: 3px;
54
        <?php echo $start ?>: 3px;
55
        height: 16px;
56
    }
57
</style>
58
<script>
59
function getFile() {
60
    if (confirm('<?php printf(_("Do you really want to replace TLS credentials for this deployment? The current TLS credentials will be revoked in 4 hours.")); ?>')) {
61
    document.getElementById("upfile").click();   
62
    }
63
    event.preventDefault(); 
64
}
65
66
function sendcsr(obj) {
67
    //alert(obj.value);
68
    var file = obj.value;
69
    var fileName = file.split("\\");
70
    //alert(fileName[fileName.length - 1]);
71
    document.getElementById("submitbuttoncsr").value = '<?php echo web\lib\common\FormElements::BUTTON_USECSR; ?>';
72
    document.csrupload.submit();
73
    event.preventDefault();
74
}
75
76
$(function() {
77
    $(".copy_link").tooltip();
78
    
79
    $(".copy_link").on("click", function() {
80
        $(".copy_link").tooltip({
81
            content: "<?php echo _("Copy to clipboard") ?>"
82
        });
83
        var field = $(this).attr("id").replace('_icon', '_data');
84
        var toCopy = $("#"+field).html();        
85
        navigator.clipboard.writeText(toCopy);
86
        $(this).tooltip({
87
            content: "<strong><?php echo _("Copied!") ?></strong>"
88
        });
89
        $(this).fadeOut(150).fadeIn(150);
90
    });
91
});
92
93
94
</script>
95
96
<?php
97
function copyIcon($target) {
98
    return '<img class="copy_link" id="'.$target.'" src="../resources/images/icons/Tabler/copy.svg" title="'. _("Copy to clipboard").'" >';
99
}
100
101
/**
102
 * displays an infocard about a Managed SP deployment
103
 * 
104
 * @param \core\DeploymentManaged $deploymentObject the deployment to work with
105
 * @throws Exception
106
 */
107
108
function displayDeploymentPropertyWidget(&$deploymentObject, $errormsg=[], $editMode) {
109
    // RADIUS status icons
110
    $depId = $deploymentObject->identifier;
111
    $radiusMessages = [
112
        \core\AbstractDeployment::RADIUS_OK => ['icon' => '../resources/images/icons/Tabler/square-rounded-check-filled-green.svg', 'text' => _("Successfully set profile")],
113
        \core\AbstractDeployment::RADIUS_FAILURE => ['icon' => '../resources/images/icons/Tabler/square-rounded-x-filled-red.svg', 'text' => _("Some problem occurred during profile update")],
114
    ];
115
    $radius_status = array();
116
    $radius_status[0] = $deploymentObject->radius_status_1;
117
    $radius_status[1] = $deploymentObject->radius_status_2;
118
    $cacert = file_get_contents(ROOT .  "/config/ManagedSPCerts/eduroamSP-CA.pem");
119
    $retry = $deploymentObject->checkRADIUSHostandConfigDaemon();
120
    $isradiusready = radius_ready($deploymentObject);
121
    if (is_array($retry)) {
122
        foreach ($retry as $id => $stat) {
123
            if ($stat) {
124
                $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...
125
            }
126
        }
127
    }    
128
    ?>
129
    <div style='display: table-row_id;'>
130
        <div class='profilebox' id="profilebox_<?php echo $depId;?>" style='display: table-cell;'>
131
            <h2><?php
132
                switch ($deploymentObject->consortium) {
133
                    case "eduroam":
134
                        $displayname = config\ConfAssistant::CONSORTIUM['name'] . " " . core\DeploymentManaged::PRODUCTNAME. ": ".$deploymentObject->name;
135
                        break;
136
                    case "OpenRoaming":
137
                        $displayname = "OpenRoaming ANP";
138
                        break;
139
                    default:
140
                        throw new Exception("We are supposed to operate on a roaming consortium we don't know.");
141
                }
142
                echo $displayname . " (<span style='color:" . ( $deploymentObject->status == \core\AbstractDeployment::INACTIVE ? "red;'>" . _("inactive") : "green;'>" . _("active") ) . "</span>)";
143
                ?></h2>
144
            <table class="deployments">
145
                <caption><?php echo _("Deployment Details"); ?></caption>
146
                <form action="?inst_id=<?php echo $deploymentObject->institution; ?>" method="post">
147
                <tr>
148
                    <th colspan="2"><?php echo("RADIUS over UDP"); ?></th>
149
                </tr>
150
                <tr style="vertical-align:top">
151
                    <td>
152
                        <?php echo _("Your primary RADIUS server") ?>
153
                    </td>
154
                    <td>
155
                        <?php
156
                        if ($deploymentObject->host1_v4 !== NULL) {
157
                            printf(_("IPv4: %s"), "<span id='host1_v4_data_$depId'>".$deploymentObject->host1_v4."</span>");
158
                            echo copyIcon("host1_v4_icon_$depId");
159
                        }
160
                        if ($deploymentObject->host1_v4 !== NULL && $deploymentObject->host1_v6 !== NULL) {
161
                            echo "<br/>";
162
                        }
163
                        if ($deploymentObject->host1_v6 !== NULL) {
164
                            printf(_("IPv6: %s"), "<span id='host1_v6_data_$depId'>".$deploymentObject->host1_v6."</span>");
165
                            echo copyIcon("host1_v6_icon_$depId");                            
166
                        }
167
                        echo "<br/>";
168
                        printf(_("port: %s"), "<span id='port1_data_$depId'>".$deploymentObject->port1."</span>");
169
                        echo copyIcon("port1_icon_$depId");                            
170
                        ?>                        
171
                    </td>
172
                    <td>
173
                        <?php
174
                        if ($deploymentObject->status) {
175
                            echo "<img src='" . $radiusMessages[$deploymentObject->radius_status_1]['icon'] .
176
                                "' alt='" . $radiusMessages[$deploymentObject->radius_status_1]['text'] .
177
                                "' title='" . $radiusMessages[$deploymentObject->radius_status_1]['text'] . "' class='cat-icon'>";
178
                        }
179
                        ?>
180
                    </td>
181
                </tr>
182
                <tr style="vertical-align:top">
183
                    <td>
184
                        <?php echo _("Your secondary RADIUS server") ?>
185
                    </td>
186
                    <td>            
187
                        <?php
188
                        if ($deploymentObject->host2_v4 !== NULL) {
189
                            printf(_("IPv4: %s"), "<span id='host2_v4_data_$depId'>".$deploymentObject->host2_v4."</span>");
190
                            echo copyIcon("host2_v4_icon_$depId");
191
                        }
192
                        if ($deploymentObject->host2_v4 !== NULL && $deploymentObject->host2_v6 !== NULL) {
193
                            echo "<br/>";
194
                        }
195
                        if ($deploymentObject->host2_v6 !== NULL) {
196
                            printf(_("IPv6: %s"), "<span id='host2_v6_data_$depId'>".$deploymentObject->host2_v6."</span>");
197
                            echo copyIcon("host2_v6_icon_$depId");                            
198
                        }
199
                        echo "<br/>";
200
                        printf(_("port: %s"), "<span id='port2_data_$depId'>".$deploymentObject->port2."</span>");
201
                        echo copyIcon("port2_icon_$depId");                            
202
                        ?>
203
                    </td>
204
                    <td>
205
                        <?php
206
                        if ($deploymentObject->status && $deploymentObject->radius_status_2) {
207
                            echo "<img src='" . $radiusMessages[$deploymentObject->radius_status_2]['icon'] .
208
                                "' alt='" . $radiusMessages[$deploymentObject->radius_status_2]['text'] .
209
                            "' title='" . $radiusMessages[$deploymentObject->radius_status_2]['text'] . "' class='cat-icon'>";
210
                        }
211
                        ?>
212
                    </td>
213
                </tr>
214
                <tr style="vertical-align:bottom">
215
                    <td><?php echo _("RADIUS shared secret for both servers"); ?></td>
216
                    <td>
217
                        <span id="shared_data_<?php echo $deploymentObject->identifier;?>"><?php echo $deploymentObject->secret;?></span>
218
                        <?php echo copyIcon("shared_icon_".$deploymentObject->identifier) ?>
219
                    </td>
220
                    <td></td>
221
                </tr>
222
                <tr></tr>
223
                <tr><td colspan="3" style="background-color: #1d4a74; height: 1px"></tr>
224
225
                <tr>
226
                    <th colspan="2"><?php echo("RADIUS over TLS or TLS-PSK"); ?></th>
227
                </tr>
228
                <tr style="vertical-align:top">
229
                    <td>
230
                        <?php echo _("Your primary RADIUS server") ?>
231
                    </td>
232
                    <td>
233
                        <?php
234
                        if ($deploymentObject->host1_v4 !== NULL) {
235
                            printf(_("IPv4: %s"), "<span id='host1_v4_t_data_$depId'>".$deploymentObject->host1_v4."</span>");
236
                            echo copyIcon("host1_v4_t_icon_$depId");                             
237
                        }
238
                        if ($deploymentObject->host1_v4 !== NULL && $deploymentObject->host1_v6 !== NULL) {
239
                            echo "<br/>";
240
                        }
241
                        if ($deploymentObject->host1_v6 !== NULL) {
242
                            printf(_("IPv6: %s"), "<span id='host1_v6_t_data_$depId'>".$deploymentObject->host1_v6."</span>");
243
                            echo copyIcon("host1_v6_t_icon_$depId");  
244
                        }
245
                        echo "<br/>";
246
                        printf(_("port: %s"), "<span id='port1_t_data_$depId'>2083</span>");
247
                        echo copyIcon("port1_t_icon_$depId");                          
248
                        ?>
249
                    </td>
250
                    <td>
251
                        <?php
252
                        if ($deploymentObject->status) {
253
                            echo "<img src='" . $radiusMessages[$deploymentObject->radius_status_1]['icon'] .
254
                                "' alt='" . $radiusMessages[$deploymentObject->radius_status_1]['text'] .
255
                                "' title='" . $radiusMessages[$deploymentObject->radius_status_1]['text'] . "' class='cat-icon'>";
256
                        }
257
                        ?>
258
                    </td>
259
                </tr>
260
                <tr style="vertical-align:top">
261
                    <td>
262
                        <?php echo _("Your secondary RADIUS server") ?>
263
                    </td>
264
                    <td>
265
                        <?php
266
                        if ($deploymentObject->host2_v4 !== NULL) {
267
                            printf(_("IPv4: %s"), "<span id='host2_v4_t_data_$depId'>".$deploymentObject->host2_v4."</span>");
268
                            echo copyIcon("host2_v4_t_icon_$depId");                            
269
                        }
270
                        if ($deploymentObject->host2_v4 !== NULL && $deploymentObject->host2_v6 !== NULL) {
271
                            echo "<br/>";
272
                        }
273
                        if ($deploymentObject->host2_v6 !== NULL) {
274
                            printf(_("IPv6: %s"), "<span id='host2_v6_t_data_$depId'>".$deploymentObject->host2_v6."</span>");
275
                            echo copyIcon("host2_v6_t_icon_$depId");                            
276
                        }
277
                        echo "<br/>";
278
                        printf(_("port: %s"), "<span id='port2_t_data_$depId'>2083</span>");
279
                        echo copyIcon("port2_t_icon_$depId");                          
280
                        ?>
281
                    </td>
282
                    <td>
283
                        <?php
284
                        if ($deploymentObject->status && $deploymentObject->radius_status_2) {
285
                            echo "<img src='" . $radiusMessages[$deploymentObject->radius_status_2]['icon'] .
286
                                "' alt='" . $radiusMessages[$deploymentObject->radius_status_2]['text'] .
287
                            "' title='" . $radiusMessages[$deploymentObject->radius_status_2]['text'] . "' class='cat-icon'>";
288
                        }
289
                        ?>
290
                    </td>
291
                </tr>
292
                
293
294
                
295
                <?php if ($deploymentObject->radsec_cert != '') { 
296
                    $data = openssl_x509_parse($deploymentObject->radsec_cert);
297
                    ?>
298
                <tr style="vertical-align:top">
299
                    <td><?php echo _("RADIUS over TLS credentials"); ?></td>
300
                    <td>
301
                    <?php
302
                    if ($deploymentObject->radsec_priv == '') {
303
                        echo _('The client certificate was created using an uploaded CSR, the private key is not available') . '<br><br>';
304
                    }
305
                    echo _('Subject:') . ' ' . $data['name'] . '<br>';
306
                    echo _('Serial number:') . ' ' . $data['serialNumberHex'] . '<br>';
307
                    $dleft = floor(($data['validTo_time_t']-time())/(24*60*60));
308
                    if ($dleft < 30) {
309
                        echo '<font color="red">';
310
                    }
311
                    echo _('Not valid after:') . ' '. date_create_from_format('ymdGis', substr($data['validTo'], 0, -1))->format('Y-m-d H:i:s') . ' UTC';
312
                    if ($dleft > 2) {
313
                        echo '<br>' . _('Number of days to expiry:') . ' ' . $dleft;
314
                    } else {
315
                        echo '<br>' . _('If you are using RADIUS over TLS you should urgently renew your credentials') . '!';
316
                    }
317
                    if ($dleft < 30) { echo '</font>'; }
318
                    ?></td>
319
                </tr><tr><td></td>
320
321
                    <td>
322
                        <span style="display: none;" id="cert_data_<?php echo $depId;?>"><?php echo $deploymentObject->radsec_cert;?></span>
323
                        <span style="display: none;" id="ca_cert_data_<?php echo $depId;?>"><?php echo $cacert;?></span>
324
                        <?php if ($deploymentObject->radsec_priv != '') {
325
                            echo _("private key").copyIcon("priv_key_icon_$depId")."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
326
                            echo '<span style="display: none;" id="priv_key_data_'.$depId.'">'.$deploymentObject->radsec_priv.'</span>';
327
                            echo '&nbsp;&nbsp;';
328
                        }
329
                            echo _("certificate").copyIcon("cert_icon_$depId")."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
330
                            echo '&nbsp;&nbsp;';
331
                            echo _("CA certificate").copyIcon("ca_cert_icon_$depId");
332
                        ?>
333
                        <br/>
334
                        <button name="sendzip" onclick="location.href='inc/sendZip.inc.php?inst_id=<?php echo $deploymentObject->institution;?>&dep_id=<?php echo $depId?>'" type="button"><?php echo _('download ZIP-file with full data');?></button>
335
336
                    </td>
337
                    <td></td>
338
                </tr>
339
                <tr> 
340
                <td></td>
341
                <td>
342
                    <?php
343
                        if ($deploymentObject->radsec_cert != NULL) {
344
                            echo "<i>";
345
                            echo _('If your certificate is close to expiry or you need to create new RADIUS over TLS credentials') . '<br>' .
346
                                 _('click on "Renew RADIUS over TLS credentials" button') . '<br>';
347
                        
348
                            echo '<br/>' . _('You can upload your own CSR to replace default TLS credentials.') . '<br>' . 
349
                                _('Click on "Upload CSR to sign my own TLS credentials"');
350
                            echo "</i>";
351
                    }
352
                    ?>    
353
                </td>
354
                <td></td>
355
                </tr>
356
                <?php         
357
                  
358
                }
359
                if ($deploymentObject->pskkey != '') {?>
360
                <tr style="vertical-align:top">
361
                        <td><?php echo _("RADIUS over TLS-PSK credentials"); ?></td>
362
                        <td>
363
                            <?php printf(_("PSK Identity: %s"), "<span id='pskid_data_$depId'>SP".$depId.'-'.$deploymentObject->institution.'</span>');
364
                            echo copyIcon("pskid_icon_$depId");
365
                           ?>
366
                            <br>
367
                            <?php printf(_("PSK hexphrase: %s"), "<span id='pskkey_data_$depId'>".$deploymentObject->pskkey."</span>");
368
                            echo copyIcon("pskkey_icon_$depId");
369
                            ?>
370
                        </td>
371
                        <td></td>
372
                </tr>
373
                
374
                
375
                <?php } 
376
                $allRealms = array_values(array_unique(array_column($deploymentObject->getAttributes("managedsp:realmforvlan"), "value")));
377
                $opname = $deploymentObject->getAttributes("managedsp:operatorname")[0]['value'] ?? NULL;
378
                $vlan = $deploymentObject->getAttributes("managedsp:vlan")[0]['value'] ?? NULL;
379
                $guest_vlan = $deploymentObject->getAttributes("managedsp:guest_vlan")[0]['value'] ?? NULL;
380
                
381
                ?>
382
                <tr></tr>
383
                <tr><th colspan="2"><?php echo _('Additional deployment settings');?></th></tr>
384
                    <tr>
385
                        <td>
386
                            <?php
387
                                if ($opname) {
388
                                    echo _("Custom Operator-Name");
389
                                } else {
390
                                    echo _("Default Operator-Name");
391
                                }
392
                            ?>
393
                        </td>
394
                        <td>
395
                        <?php
396
                                if ($opname) { 
397
                                    echo $opname; 
398
                                } else {
399
                                    echo '1sp.'.$depId.'-'.$deploymentObject->institution.'.hosted.eduroam.org';
400
                                }
401
                        ?>
402
                        </td>
403
                    </tr>
404
                <?php
405
                if ($guest_vlan) {
406
                    ?>
407
                    <tr>
408
                        <td><?php echo _("VLAN tag for guests"); ?></td>
409
                        <td>
410
                            <?php 
411
                                if ($guest_vlan) {
412
                                    echo $guest_vlan;
413
                                }
414
                            ?>
415
                        </td>
416
                    </tr>
417
                <?php
418
                }
419
                if (!empty($allRealms) || $vlan) {
420
                    ?>
421
                    <tr>
422
                        <td><?php echo _("VLAN tag for own users"); ?></td>
423
                        <td>
424
                            <?php 
425
                                if ($vlan) {
426
                                    echo $vlan;
427
                                } else {
428
                                    echo _('not set, be aware that realm setting is not used until a VLAN tag is added');
429
                                }
430
                            ?>
431
                        </td>
432
                    </tr>
433
                    <tr>
434
                        <td><?php echo _("Realm to be considered own users"); ?></td>
435
                        <td>
436
                            <?php
437
                                if (!empty($allRealms)) {
438
                                    echo implode(', ', $allRealms);
439
                                } else {
440
                                    echo _('not set, be aware that VLAN setting is not used until a realm is added');
441
                                }
442
                } 
443
                ?>
444
                </td></tr>
445
                </form>
446
            </table>
447
            <div class='buttongroupprofilebox' style='clear:both;'>
448
                <?php if($editMode === 'fullaccess') { ?>
449
                <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
450
                    <br/>
451
                    <button type='submit' name='profile_action' value='edit'><?php echo _("Advanced Configuration"); ?></button>
452
                </form>
453
                <?php } ?>
454
                <?php if ($isradiusready && $deploymentObject->status === \core\AbstractDeployment::ACTIVE && $editMode === 'fullaccess') { ?>
455
                    <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
456
                        <button class='delete' type='submit' 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); ?>')">
457
                            <?php echo _("Deactivate"); ?>
458
                        </button>
459
                        <?php
460
                        if (isset($_GET['res']) && is_array($_GET['res'])) {
461
                            $res = array_count_values($_GET['res']);
462
                            if (array_key_exists('FAILURE', $res) && $res['FAILURE'] > 0) {
463
                                echo '<br>';
464
                                if ($res['FAILURE'] == 2) {
465
                                    echo ' <span style="color: red;">' . _("Activation failure.") . '</span>';
466
                                } else {
467
                                    if (isset($_GET['res'][1]) && $_GET['res']['1'] == 'FAILURE') {
468
                                        echo ' <span style="color: red;">' . _("Activation failure for your primary RADIUS server.") . '</span>';
469
                                    } else {
470
                                        echo ' <span style="color: red;">' . _("Activation failure for your backup RADIUS server.") . '</span>';
471
                                    }
472
                                }
473
                            }
474
                        }
475
                        ?>
476
                    </form>
477
                <?php 
478
                } elseif (count($deploymentObject->getAttributes("hiddenmanagedsp:tou_accepted")) == 0) {
479
                    if ($editMode === 'fullaccess') {
480
                    ?>
481
                    <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
482
                        <button class='delete' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_TERMSOFUSE_NEEDACCEPTANCE; ?>'>
483
                            <?php echo _("Accept Terms of Use"); ?>
484
                        </button>
485
                    </form>
486
                <?php 
487
                    } else {
488
                        echo "<strong>"._("Terms of Use not accepted.")."</strong>";
489
                    }
490
                }
491
                    $discardLabel = _("Return"); ?>
492
                <p><button type='button' class='delete' id=='abortbutton' style='visibility: visible' value='abort' onclick='javascript:window.location = "overview_org.php?inst_id=<?php echo $deploymentObject->institution; ?>"'><?php echo $discardLabel ?></button></p>
493
                    <?php
494
                    if ($isradiusready && $deploymentObject->status == \core\AbstractDeployment::INACTIVE && count($deploymentObject->getAttributes("hiddenmanagedsp:tou_accepted"))) { ?>
495
                        <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
496
                            <button class='delete' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_ACTIVATE; ?>'>
497
                                <?php echo _("Activate"); ?>
498
                            </button>
499
                            <?php
500
                            if (isset($_GET['res']) && is_array($_GET['res'])) {
501
                                $res = array_count_values($_GET['res']);
502
                                if (array_key_exists('FAILURE', $res) && $res['FAILURE'] > 0) {
503
                                    echo '<br>';
504
                                    if ($res['FAILURE'] == 2) {
505
                                        echo ' <span style="color: red;">' . _("Failure during deactivation, your request is queued for handling") . '</span>';
506
                                    } else {
507
                                        if (isset($_GET['res'][1]) && $_GET['res']['1'] == 'FAILURE') {
508
                                            echo ' <span style="color: red;">' . _("Deactivation failure for your primary RADIUS server, your request is queued.") . '</span>';
509
                                        } else {
510
                                            echo ' <span style="color: red;">' . _("Deactivation failure for your backup RADIUS server, your request is queued.") . '</span>';
511
                                        }
512
                                    }
513
                                }
514
                            }
515
                            ?>
516
                        </form>
517
                <?php }
518
                if ($editMode === 'fullaccess') {
519
                    if ($deploymentObject->status === \core\AbstractDeployment::INACTIVE) { ?>
520
                        <div align="right">
521
                        <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
522
                            <button class='delete' 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); ?>')">
523
                                <?php echo _("Remove deployment"); ?>
524
                            </button>
525
                        </form>
526
                        </div>
527
                <?php } ?>
528
                    <div align="right">
529
                    <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
530
                            <button class='renewtls' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_RENEWTLS; ?>' onclick="return confirm('<?php printf(_("Do you really want to replace TLS credentials for this %s deployment? The current TLS credentials will be revoked in 4 hours."), core\DeploymentManaged::PRODUCTNAME); ?>')">
531
                                <?php echo _("Renew RADIUS over TLS credentials"); ?>
532
                            </button>
533
                    </form>           
534
                    <form name="csrupload" enctype="multipart/form-data" action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
535
                           <button class='usecsr' type='submit' onclick="getFile();"); ?>                
536
                                <?php echo _("Upload CSR to sign my own TLS credentials"); ?>
537
                            </button>
538
                    <div style='height: 0px;width: 0px; overflow:hidden;'>
539
                        <input name='submitbutton' id='submitbuttoncsr' value=''>
540
                        <input id="upfile" name="upload" type="file" value="upload" onchange="sendcsr(this);" />
541
                    </div>
542
                    </form>
543
                <?php } ?>
544
                        <!--
545
                    <label for="csr"><?php echo _("Upload CSR to sign my own TLS credentials"); ?></label>
546
                    <div align="right">
547
                    <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
548
                    <!--<input type="file" id="csr" class='usecsr' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_USECSR; ?>' onclick="return confirm('<?php printf(_("Do you really want to replace TLS credentials for this %s deployment? The current TLS credentials will be revoked in 4 hours."), core\DeploymentManaged::PRODUCTNAME); ?>')">-->
549
                    
550
  <!-- this is your file input tag, so i hide it!-->
551
  <!-- i used the onchange event to fire the form submission-->
552
  
553
  <!-- here you can have file submit button or you can write a simple script to upload the file automatically-->
554
  <!-- <input type="submit" value='submit' > -->
555
                    
556
                    </div>
557
            </div>
558
            <?php 
559
            if (!$isradiusready) { 
560
                echo '<p>'. _("We are not able to handle a new configuration request requiring contact with RADIUS servers now.") . '<br>' . _("Check later.");
561
                
562
            } 
563
            if (count($errormsg) > 0 && array_key_exists($deploymentObject->identifier, $errormsg)) {
564
            ?>
565
            <div style='color: red'>
566
                <b>
567
                    <?php echo $errormsg[$deploymentObject->identifier]; ?>
568
                </b>
569
            </div>
570
            <?php
571
            }
572
            ?>
573
        </div>
574
        <div style='width:20px;'></div> <!-- QR code space, reserved -->
575
        <div style='display: table-cell; min-width:200px;'>
576
            <?php $tablecaption = _("Hotspot Usage Statistics");?>
577
            <h1><?php echo $tablecaption; ?></h1>
578
            <h2><?php echo _("5 most recent authentications");?></h2>
579
            <p><?php echo _("<b>AP Identifier</b> is a /-separated tuple of NAS-Identifier/NAS-IP-Address/NAS-IPv6-Address/Called-Station-Id") .'<br>';
580
                     echo _("<b>Protocol</b> is a protocol used between a client and RADIUS server, for TLS it is a /-separated tuple TLS/<i>TLS-Client-Cert-Serial</i>"); ?></p>
581
            <table class='authrecord'>
582
    <caption><?php echo $tablecaption;?></caption>
583
    <tr style='text-align: left;'>
584
        <th scope="col"><strong><?php echo _("Timestamp (UTC)");?></strong></th>
585
        <th scope="col"><strong><?php echo _("Outer-Identity");?></strong></th>
586
        <th scope="col"><strong><?php echo _("Result");?></strong></th>
587
        <th scope="col"><strong><?php echo _("MAC Address");?></strong></th>
588
        <th scope="col"><strong><?php echo _("Chargeable-User-Identity");?></strong></th> 
589
        <th scope="col"><strong><?php echo _("AP Identifier");?></strong></th>
590
        <th scope="col"><strong><?php echo _("Protocol");?></strong></th>
591
    </tr>
592
    <?php
593
    $userAuthData = $deploymentObject->retrieveStatistics(0,5);
594
    $i = 0;	   
595
    foreach ($userAuthData as $oneRecord) {
596
        echo "<tr class='".($oneRecord['result'] == "OK" ? "auth-success" : "auth-fail" )."'>"
597
                . "<td>".$oneRecord['activity_time']."</td>"
598
                . "<td>".$oneRecord['outer_user']."</td>"
599
                . "<td>".($oneRecord['result'] == "OK" ? _("Success") : _("Failure"))."</td>"
600
                . "<td>".$oneRecord['mac']."</td>"
601
		. "<td>".substr($oneRecord['cui'], 0, 18)
602
		. ($oneRecord['cui']=='' ? "" : "... " . copyIcon("cui_icon_".$deploymentObject->identifier."_$i") 
603
	        . "<span style='display: none;' id='cui_data_".$deploymentObject->identifier."_$i'>".$oneRecord['cui'].'</span>')."</td>"
604
                . "<td>".$oneRecord['ap_id']."</td>"
605
                . "<td>".$oneRecord['prot']."</td>"
606
                . "</tr>";
607
        if ($oneRecord['cui']!='') {
608
            $i++;
609
        }
610
    }
611
    ?>
612
</table>
613
            <div style='display: ruby;'>
614
            <form style="display: inline;" 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'>
615
                <button type='submit' id='stats-hour' name='stats' value='HOUR'><?php echo _("Last hour"); ?></button>
616
            </form>
617
            <form style="display: inline;" 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'>
618
                <button type='submit' id='stats-month' name='stats' value='MONTH'><?php echo _("Last 30 days"); ?></button>
619
            </form>
620
            <form style="display: inline;" 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'>
621
                <button type='submit' id='stats-full' name='stats' value='FULL'><?php echo _("Last 6 months"); ?></button>
622
            </form>
623
            </div>
624
            </br>
625
            <?php 
626
            echo _('Get statistics as CSV file:').' '; 
627
            $query = 'inc/deploymentStats.inc.php?inst_id='.$deploymentObject->institution."&deployment_id=$depId&as=csv&backlog=";
628
            ?>
629
	    <button name="sendcsv" type="button" onclick="location.href='<?php echo $query;?>WEEK';"><?php echo _('Last week');?>
630
            </button>
631
	    <button name="sendcsv" type="button" onclick="location.href='<?php echo $query;?>MONTH';"><?php echo _('Last 30 days');?>
632
            </button>
633
	    <button name="sendcsv" type="button" onclick="location.href='<?php echo $query;?>FULL';"><?php echo _('Last 6 months');?>
634
            </button>
635
        </div><!-- statistics space -->
636
        <div style='height:5px'></div>
637
        <div style='display: table-cell; min-width:200px;'>
638
            <h1><?php echo _("Hotspot Debug Logs"); ?></h1>
639
            <h2><?php echo _('To get detailed logs from RADIUS sites click a button below.'); 
640
            $query = 'inc/deploymentLogs.inc.php?inst_id='.$deploymentObject->institution."&deployment_id=$depId&backlog=";
641
            ?></h2>
642
            <?php echo _('You will receive zip file with logs from both RADIUS servers: primary (folder named radius-1) and secondary (folder named radius-2).') . '<br>' .
643
                  _('If no logs are available an empty zip file is provided.');?>
644
            <div style='height:3px'></div>
645
            <button name="logs" type="button" onclick="location.href='<?php echo $query;?>1';"><?php echo _('Today');?>
646
            </button>
647
            <button name="logs" type="button" onclick="location.href='<?php echo $query;?>2';"><?php echo _('Last 2 days');?>
648
            </button>
649
            <button name="logs" type="button" onclick="location.href='<?php echo $query;?>7';"><?php echo _('Last 7 days');?>
650
            </button>
651
        </div>
652
    </div> 
653
    <!-- dummy div to keep a little distance-->
654
    <div style='height:20px'></div>
655
    
656
    <?php
657
}
658
659
/**
660
 * displays a eduroam DB entry for SPs. Not implemented yet.
661
 * 
662
 * @param \core\DeploymentClassic $deploymentObject the deployment to work with
663
 */
664
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

664
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...
665
    
666
}
667
668
/**
669
 * checks if both RADIUS servers are ready to accept reconfiguration requests
670
 * 
671
 * 
672
 */
673
function radius_ready($dsp) {
674
    foreach (array($dsp->host1_v4, $dsp->host2_v4) as $host) {
675
        $connection = @fsockopen($host, \config\Master::MANAGEDSP['radiusconfigport']);
0 ignored issues
show
Bug introduced by
The constant config\Master::MANAGEDSP was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
676
        if (is_resource($connection)) {
677
           fclose($connection);
678
        } else {
679
           return false;
680
        }
681
    }
682
    return true;
683
}
684
685
?>
686
<h2 style='display: flex;'><?php printf(_("%s: %s Deployment Details"), $uiElements->nomenclatureParticipant, $uiElements->nomenclatureHotspot); ?>&nbsp;
687
            <?php
688
                if ($readonly === FALSE && $editMode === 'fullaccess') {
689
                if (\core\CAT::hostedSPEnabled() && count($myfed->getAttributes("fed:silverbullet")) > 0) {
690
                    ?>
691
                    <form action='edit_hotspot.php?inst_id=<?php echo $my_inst->identifier; ?>' method='post' accept-charset='UTF-8'>
692
                        <div>
693
                            <input type="hidden" name="consortium" value="eduroam"/>
694
                            <button type='submit' <?php echo ($hasMail > 0 ? "" : "disabled"); ?> name='profile_action' value='new'>
695
                                <?php echo sprintf(_("Add %s deployment ..."), \config\ConfAssistant::CONSORTIUM['name'] . " " . \core\DeploymentManaged::PRODUCTNAME); ?>
696
                            </button>
697
                            <span style='color: red;'>
698
                            <?php if ($hasMail == 0) { 
699
                              echo _("Helpdesk mail address is required but missing!");  
700
                            }
701
                            ?>
702
                            </span>
703
                        </div>
704
                    </form>
705
                    
706
                    <?php 
707
                    /*
708
                    if (count($myfed->getAttributes("fed:openroaming")) > 0) {
709
                        ?>
710
                        &nbsp;
711
                        <form action='edit_hotspot.php?inst_id=<?php echo $my_inst->identifier; ?>' method='post' accept-charset='UTF-8'>
712
                            <div>
713
                                <input type="hidden" name="consortium" value="OpenRoaming"/>
714
                                <button type='submit' <?php echo ($hasMail > 0 ? "" : "disabled"); ?> name='profile_action' value='new'>
715
                                    <?php echo sprintf(_("Add %s deployment ..."), "OpenRoaming ANP"); ?>
716
                                </button>
717
718
                            </div>
719
                        </form>
720
                        <?php
721
                    }
722
                    */
723
                }
724
            }
725
            ?>
726
        </h2>
727
<?php
728
        $hotspotProfiles = [];
729
        if (isset($_GET['deployment_id'])) {
730
           $hotspotProfiles = [ $validator->existingDeploymentManaged($_GET['deployment_id'], $my_inst) ];
731
        } else {
732
           $hotspotProfiles = $my_inst->listDeployments();
733
        }
734
        if (count($hotspotProfiles) == 0) { // no profiles yet.
735
            echo sprintf(_("There are not yet any known deployments for your %s."), $uiElements->nomenclatureHotspot);
736
        }
737
738
        foreach ($hotspotProfiles as $counter => $deploymentObject) {
739
            displayDeploymentPropertyWidget($deploymentObject, $errormsg, $editMode);
740
        }
741
?>
742