displayDeploymentPropertyWidget()   F
last analyzed

Complexity

Conditions 41
Paths > 20000

Size

Total Lines 207
Code Lines 175

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 175
c 1
b 0
f 0
dl 0
loc 207
rs 0
cc 41
nc 92162
nop 3

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
 * *****************************************************************************
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
32
$langInstance = new \core\common\Language();
33
$start = $langInstance->rtl ? "right" : "left";
34
$end = $langInstance->rtl ? "left" : "right";
35
36
?>
37
<style>
38
    .deployments td:first-child {
39
        padding-right: 15px;
40
    }
41
    img.copy_link {
42
        position: relative;
43
        top: 3px;
44
        <?php echo $start ?>: 3px;
45
        height: 16px;
46
    }
47
</style>
48
49
50
<?php
51
52
/**
53
 * displays an infocard about a Managed SP deployment
54
 * 
55
 * @param \core\DeploymentManaged $deploymentObject the deployment to work with
56
 * @throws Exception
57
 */
58
function displayDeploymentPropertyWidget(&$deploymentObject, $errormsg=[], $editMode) {
0 ignored issues
show
Unused Code introduced by
The parameter $errormsg 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

58
function displayDeploymentPropertyWidget(&$deploymentObject, /** @scrutinizer ignore-unused */ $errormsg=[], $editMode) {

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...
59
    // RADIUS status icons
60
    $depId = $deploymentObject->identifier;
61
    $radiusMessages = [
0 ignored issues
show
Unused Code introduced by
The assignment to $radiusMessages is dead and can be removed.
Loading history...
62
        \core\AbstractDeployment::RADIUS_OK => ['icon' => '../resources/images/icons/Tabler/square-rounded-check-filled-green.svg', 'text' => _("Successfully set profile")],
63
        \core\AbstractDeployment::RADIUS_FAILURE => ['icon' => '../resources/images/icons/Tabler/square-rounded-x-filled-red.svg', 'text' => _("Some problem occurred during profile update")],
64
    ];
65
    $radius_status = array();
66
    $radius_status[0] = $deploymentObject->radius_status_1;
67
    $radius_status[1] = $deploymentObject->radius_status_2;
68
    $cacert = file_get_contents(ROOT .  "/config/ManagedSPCerts/eduroamSP-CA.pem");
0 ignored issues
show
Unused Code introduced by
The assignment to $cacert is dead and can be removed.
Loading history...
69
    $retry = $deploymentObject->checkRADIUSHostandConfigDaemon();
70
    $isradiusready = radius_ready($deploymentObject);
71
    if (is_array($retry)) {
72
        foreach ($retry as $id => $stat) {
73
            if ($stat) {
74
                $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...
75
            }
76
        }
77
    }
78
    ?>
79
    <div style='display: table-row_id;'>
80
        <div class='profilebox' id="profilebox_<?php echo $depId;?>" style='display: table-cell;'>
81
            <h2><?php
82
                switch ($deploymentObject->consortium) {
83
                    case "eduroam":
84
                        $displayname = config\ConfAssistant::CONSORTIUM['name'] . " " . core\DeploymentManaged::PRODUCTNAME. ": SP$depId-".$deploymentObject->institution;
85
                        break;
86
                    case "OpenRoaming":
87
                        $displayname = "OpenRoaming ANP";
88
                        break;
89
                    default:
90
                        throw new Exception("We are supposed to operate on a roaming consortium we don't know.");
91
                }
92
                echo $displayname . " (<span style='color:" . ( $deploymentObject->status == \core\AbstractDeployment::INACTIVE ? "red;'>" . _("inactive") : "green;'>" . _("active") ) . "</span>)";
93
                ?></h2>
94
            <table class="deployments">
95
                <caption><?php echo _("Deployment Details"); ?></caption>
96
                <tr><td>
97
                <?php 
98
                echo _("Last seen:").' </td><td>';
99
                $when = $deploymentObject->getLastActivity();
100
                if (! $when ) {
101
                    echo _("never");
102
                } else {
103
                    echo $when; 
104
                }
105
                ?>     
106
                </td></tr>
107
                <tr> 
108
                <?php         
109
                $allRealms = array_values(array_unique(array_column($deploymentObject->getAttributes("managedsp:realmforvlan"), "value")));
110
                $opname = $deploymentObject->getAttributes("managedsp:operatorname")[0]['value'] ?? NULL;
111
                $vlan = $deploymentObject->getAttributes("managedsp:vlan")[0]['value'] ?? NULL;
112
                $guest_vlan = $deploymentObject->getAttributes("managedsp:guest_vlan")[0]['value'] ?? NULL;
113
                
114
                ?>
115
                <tr></tr>
116
                <tr><th colspan="2"><?php echo _('Settings');?></th></tr>
117
                    <tr>
118
                        <td>
119
                            <?php
120
                                if ($opname) {
121
                                    echo _("Custom Operator-Name");
122
                                } else {
123
                                    echo _("Default Operator-Name");
124
                                }
125
                            ?>
126
                        </td>
127
                        <td>
128
                        <?php
129
                                if ($opname) { 
130
                                    echo $opname; 
131
                                } else {
132
                                    echo '1sp.'.$depId.'-'.$deploymentObject->institution.'.hosted.eduroam.org';
133
                                }
134
                        ?>
135
                        </td>
136
                    </tr>
137
                <?php
138
                if ($guest_vlan) {
139
                    ?>
140
                    <tr>
141
                        <td><?php echo _("VLAN tag for guests"); ?></td>
142
                        <td>
143
                            <?php 
144
                                if ($guest_vlan) {
145
                                    echo $guest_vlan;
146
                                }
147
                            ?>
148
                        </td>
149
                    </tr>
150
                <?php
151
                }
152
                if (!empty($allRealms) || $vlan) {
153
                    ?>
154
                    <tr>
155
                        <td><?php echo _("VLAN tag for own users"); ?></td>
156
                        <td>
157
                            <?php 
158
                                if ($vlan) {
159
                                    echo $vlan;
160
                                } else {
161
                                    echo _('not set, be aware that realm setting is not used until a VLAN tag is added');
162
                                }
163
                            ?>
164
                        </td>
165
                    </tr>
166
                    <tr>
167
                        <td><?php echo _("Realm to be considered own users"); ?></td>
168
                        <td>
169
                            <?php
170
                                if (!empty($allRealms)) {
171
                                    echo implode(', ', $allRealms);
172
                                } else {
173
                                    echo _('not set, be aware that VLAN setting is not used until a realm is added');
174
                                }
175
                } 
176
                ?>
177
                </td></tr>
178
                </form>
179
            </table>
180
            <div class='buttongroupprofilebox' style='clear:both;'>
181
                <form action='overview_sp_wrapper.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
182
                    <br/>
183
                    <button type='submit' name='profile_action' value='edit'><?php echo _("Details"); ?></button>
184
                </form>
185
                <?php if ($isradiusready && $deploymentObject->status == \core\AbstractDeployment::ACTIVE && $editMode === 'fullaccess') { ?>
186
                    <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
187
                        <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); ?>')">
188
                            <?php echo _("Deactivate"); ?>
189
                        </button>
190
                        <?php
191
                        if (isset($_GET['res']) && is_array($_GET['res'])) {
192
                            $res = array_count_values($_GET['res']);
193
                            if (array_key_exists('FAILURE', $res) && $res['FAILURE'] > 0) {
194
                                echo '<br>';
195
                                if ($res['FAILURE'] == 2) {
196
                                    echo ' <span style="color: red;">' . _("Activation failure.") . '</span>';
197
                                } else {
198
                                    if (isset($_GET['res'][1]) && $_GET['res']['1'] == 'FAILURE') {
199
                                        echo ' <span style="color: red;">' . _("Activation failure for your primary RADIUS server.") . '</span>';
200
                                    } else {
201
                                        echo ' <span style="color: red;">' . _("Activation failure for your backup RADIUS server.") . '</span>';
202
                                    }
203
                                }
204
                            }
205
                        }
206
                        ?>
207
                    </form>
208
                    <?php
209
                } elseif (count($deploymentObject->getAttributes("hiddenmanagedsp:tou_accepted")) == 0) {
210
                    if ($editMode === 'fullaccess') {
211
                    ?>
212
                    <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
213
                        <button class='delete' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_TERMSOFUSE_NEEDACCEPTANCE; ?>'>
214
                            <?php echo _("Accept Terms of Use"); ?>
215
                        </button>
216
                    </form>
217
                <?php 
218
                    } else {
219
                        echo "<strong>"._("Terms of Use not accepted.")."</strong>";
220
                    }
221
                    }
222
                    if ($isradiusready && $deploymentObject->status == \core\AbstractDeployment::INACTIVE && count($deploymentObject->getAttributes("hiddenmanagedsp:tou_accepted"))) { ?>
223
                        <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
224
                            <button class='delete' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_ACTIVATE; ?>'>
225
                                <?php echo _("Activate"); ?>
226
                            </button>
227
                            <?php
228
                            if (isset($_GET['res']) && is_array($_GET['res'])) {
229
                                $res = array_count_values($_GET['res']);
230
                                if (array_key_exists('FAILURE', $res) && $res['FAILURE'] > 0) {
231
                                    echo '<br>';
232
                                    if ($res['FAILURE'] == 2) {
233
                                        echo ' <span style="color: red;">' . _("Failure during deactivation, your request is queued for handling") . '</span>';
234
                                    } else {
235
                                        if (isset($_GET['res'][1]) && $_GET['res']['1'] == 'FAILURE') {
236
                                            echo ' <span style="color: red;">' . _("Deactivation failure for your primary RADIUS server, your request is queued.") . '</span>';
237
                                        } else {
238
                                            echo ' <span style="color: red;">' . _("Deactivation failure for your backup RADIUS server, your request is queued.") . '</span>';
239
                                        }
240
                                    }
241
                                }
242
                            }
243
                            ?>
244
                        </form>
245
                <?php } 
246
                    if ($deploymentObject->status == \core\AbstractDeployment::INACTIVE && $editMode === 'fullaccess') { ?>
247
                        <div align="right">
248
                        <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
249
                            <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); ?>')">
250
                                <?php echo _("Remove deployment"); ?>
251
                            </button>
252
                        </form>
253
                        </div>
254
                <?php } ?>
255
                    
256
            </div>
257
            <?php 
258
            if (!$isradiusready) { 
259
                echo '<p>'. _("We are not able to handle a new configuration request requiring contact with RADIUS servers now.") . '<br>' . _("Check later.");
260
                
261
            } 
262
            
263
            ?>
264
            
265
            
266
        </div>
267
</table>
268
</div>    
269
    <!-- dummy div to keep a little distance-->
270
    <div style='height:20px'></div>
271
    
272
    <?php
273
}
274
275
/**
276
 * displays a eduroam DB entry for SPs. Not implemented yet.
277
 * 
278
 * @param \core\DeploymentClassic $deploymentObject the deployment to work with
279
 */
280
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

280
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...
281
    
282
}
283
284
/**
285
 * checks if both RADIUS servers are ready to accept reconfiguration requests
286
 * 
287
 * 
288
 */
289
function radius_ready($dsp) {
290
    foreach (array($dsp->host1_v4, $dsp->host2_v4) as $host) {
291
        $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...
292
        if (is_resource($connection)) {
293
           fclose($connection);
294
        } else {
295
           return false;
296
        }
297
    }
298
    return true;
299
}
300
301
?>
302
<h2 style='display: flex;'><?php printf(_("%s: %s Deployment Details"), $uiElements->nomenclatureParticipant, $uiElements->nomenclatureHotspot); ?>&nbsp;
303
            <?php
304
            if ($readonly === FALSE && $editMode === 'fullaccess') {
305
                if (\core\CAT::hostedSPEnabled() && count($myfed->getAttributes("fed:silverbullet")) > 0) {
306
                    // the button is greyed out if there's no support email address configured...
307
                    ?>
308
                    <form action='edit_hotspot.php?inst_id=<?php echo $my_inst->identifier; ?>' method='post' accept-charset='UTF-8'>
309
                        <div>
310
                            <input type="hidden" name="consortium" value="eduroam"/>
311
                            <button type='submit' name='profile_action' value='new'>
312
                                <?php echo sprintf(_("Add %s deployment ..."), \config\ConfAssistant::CONSORTIUM['name'] . " " . \core\DeploymentManaged::PRODUCTNAME); ?>
313
                            </button>
314
                        </div>
315
                    </form>
316
                    
317
                    <?php 
318
                    /*
319
                    if (count($myfed->getAttributes("fed:openroaming")) > 0) {
320
                        ?>
321
                        &nbsp;
322
                        <form action='edit_hotspot.php?inst_id=<?php echo $my_inst->identifier; ?>' method='post' accept-charset='UTF-8'>
323
                            <div>
324
                                <input type="hidden" name="consortium" value="OpenRoaming"/>
325
                                <button type='submit' <?php echo ($hasMail > 0 ? "" : "disabled"); ?> name='profile_action' value='new'>
326
                                    <?php echo sprintf(_("Add %s deployment ..."), "OpenRoaming ANP"); ?>
327
                                </button>
328
329
                            </div>
330
                        </form>
331
                        <?php
332
                    }
333
                    */
334
                }
335
            }
336
            ?>
337
        </h2>
338
<?php
339
        $hotspotProfiles = $my_inst->listDeployments();
340
        if (count($hotspotProfiles) == 0) { // no profiles yet.
341
            echo sprintf(_("There are not yet any known deployments for your %s."), $uiElements->nomenclatureHotspot);
342
        }
343
344
        foreach ($hotspotProfiles as $counter => $deploymentObject) {
345
            switch (get_class($deploymentObject)) {
346
                case "core\DeploymentManaged":
347
                    displayDeploymentPropertyWidget($deploymentObject, '', $editMode);
348
                    break;
349
                case "core\DeploymentClassic":
350
                    displayClassicHotspotPropertyWidget($deploymentObject);
351
                    break;
352
                default:
353
                    throw new Exception("We were asked to operate on something that is neither a classic nor a Managed hotspot deployment!");
354
            }
355
        }
356
?>
357