Passed
Push — master ( 3d7ab7...c6cd3b )
by Maja
07:26
created

check_url()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 12
dl 0
loc 15
rs 9.8666
c 1
b 1
f 0
cc 3
nc 3
nop 1
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
$deco = new \web\lib\admin\PageDecoration();
32
$validator = new \web\lib\common\InputValidation();
33
$uiElements = new web\lib\admin\UIElements();
34
35
// our own location, to give to diag URLs
36
if (isset($_SERVER['HTTPS'])) {
37
    $link = 'https://';
38
} else {
39
    $link = 'http://';
40
}
41
$link .= $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
42
$link = htmlspecialchars($link);
43
44
echo $deco->defaultPagePrelude(sprintf(_("%s: %s Dashboard"), \config\Master::APPEARANCE['productname'], $uiElements->nomenclatureHotspot));
45
require_once "inc/click_button_js.php";
46
47
// RADIUS status icons
48
$radiusMessages = [
49
    \core\AbstractDeployment::RADIUS_OK => ['icon' => '../resources/images/icons/Quetto/check-icon.png', 'text' => _("Successfully set profile")],
50
    \core\AbstractDeployment::RADIUS_FAILURE => ['icon' => '../resources/images/icons/Quetto/no-icon.png', 'text' => _("Some problem occured during profile update")],
51
    ];
52
// let's check if the inst handle actually exists in the DB
53
$my_inst = $validator->existingIdP($_GET['inst_id'], $_SESSION['user']);
54
55
// delete stored realm
56
57
if (isset($_SESSION['check_realm'])) {
58
    unset($_SESSION['check_realm']);
59
}
60
$mapCode = web\lib\admin\AbstractMap::instance($my_inst, TRUE);
61
echo $mapCode->htmlHeadCode();
62
?>
63
</head>
64
<body 
65
    <?php echo $mapCode->bodyTagCode(); ?>>
66
    <?php
67
    echo $deco->productheader("ADMIN-SP");
68
    // Sanity check complete. Show what we know about this IdP.
69
    $idpoptions = $my_inst->getAttributes();
70
    ?>
71
    <h1><?php echo sprintf(_("%s Overview"), $uiElements->nomenclatureHotspot); ?></h1>
72
    <div>
73
        <h2><?php echo sprintf(_("%s general settings"), $uiElements->nomenclatureHotspot); ?></h2>
74
        <?php
75
        echo $uiElements->instLevelInfoBoxes($my_inst);
76
        ?>
77
        <?php
78
        foreach ($idpoptions as $optionname => $optionvalue) {
79
            if ($optionvalue['name'] == "general:geo_coordinates") {
80
                echo '<div class="infobox">';
81
                echo $mapCode->htmlShowtime();
82
                echo '</div>';
83
                break;
84
            }
85
        }
86
        ?>
87
    </div>
88
    <?php
89
    $readonly = \config\Master::DB['INST']['readonly'];
90
    ?>
91
    <hr><h2><?php echo _("Available Support actions"); ?></h2>
92
    <table>
93
        <?php
94
        if (\config\Master::FUNCTIONALITY_LOCATIONS['DIAGNOSTICS'] !== NULL) {
95
            echo "<tr>
96
                        <td>" . _("Check another realm's reachability") . "</td>
97
                        <td><form method='post' action='../diag/action_realmcheck.php?inst_id=$my_inst->identifier' accept-charset='UTF-8'>
98
                              <input type='text' name='realm' id='realm'>
99
                              <input type='hidden' name='comefrom' id='comefrom' value='$link'/>
100
                              <button type='submit'>" . _("Go!") . "</button>
101
                            </form>
102
                        </td>
103
                    </tr>";
104
        }
105
        if (\config\ConfAssistant::CONSORTIUM['name'] == "eduroam") { // SW: APPROVED
106
            echo "<tr>
107
                        <td>" . sprintf(_("Check %s server status"), $uiElements->nomenclatureFed) . "</td>
108
                        <td>
109
                           <form action='https://monitor.eduroam.org/mon_direct.php' accept-charset='UTF-8'>
110
                              <button type='submit'>" . _("Go!") . "</button>
111
                           </form>
112
                        </td>
113
                    </tr>";
114
        }
115
        ?>
116
    </table>
117
    <hr/>
118
    <?php
119
    $hotspotProfiles = $my_inst->listDeployments();
120
    if (count($hotspotProfiles) == 0) { // no profiles yet.
121
        echo "<h2>" . sprintf(_("There are not yet any known deployments for your %s."), $uiElements->nomenclatureHotspot) . "</h2>";
122
    }
123
    if (count($hotspotProfiles) > 0) { // no profiles yet.
124
        echo "<h2>" . sprintf(_("Deployments for this %s"), $uiElements->nomenclatureHotspot) . "</h2>";
125
        // display an info box with the connection data
126
    }
127
   
128
    foreach ($hotspotProfiles as $counter => $deploymentObject) {
129
        $radius_status = array();
130
        $radius_status[0] = $deploymentObject->radius_status_1;
131
        $radius_status[1] = $deploymentObject->radius_status_2;
132
        $retry = $deploymentObject->checkRADIUSconfigDaemon();
0 ignored issues
show
Bug introduced by
The method checkRADIUSconfigDaemon() does not exist on core\AbstractDeployment. It seems like you code against a sub-type of core\AbstractDeployment such as core\DeploymentManaged. ( Ignorable by Annotation )

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

132
        /** @scrutinizer ignore-call */ 
133
        $retry = $deploymentObject->checkRADIUSconfigDaemon();
Loading history...
133
        $deploymentObject->checkRADIUSHost(1);
0 ignored issues
show
Bug introduced by
The method checkRADIUSHost() does not exist on core\AbstractDeployment. It seems like you code against a sub-type of core\AbstractDeployment such as core\DeploymentManaged. ( Ignorable by Annotation )

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

133
        $deploymentObject->/** @scrutinizer ignore-call */ 
134
                           checkRADIUSHost(1);
Loading history...
134
        ?>
135
        <div style='display: table-row; margin-bottom: 20px;'>
136
            <div class='profilebox' style='display: table-cell;'>
137
                <h2><?php echo core\DeploymentManaged::PRODUCTNAME . " (<span style='color:" . ( $deploymentObject->status == \core\AbstractDeployment::INACTIVE ? "red;'>" . _("inactive") : "green;'>" . _("active") ) . "</span>)"; ?></h2>
138
                <table>
139
                    <tr>
140
                        <td><strong><?php echo _("Your primary RADIUS server") ?></strong><br/>
141
                        <?php
142
                            if ($deploymentObject->host1_v4 !== NULL) {
143
                                echo _("IPv4") . ": " . $deploymentObject->host1_v4;
144
                            }
145
                            if ($deploymentObject->host1_v4 !== NULL && $deploymentObject->host1_v6 !== NULL) {
146
                                echo "<br/>";
147
                            }
148
                            if ($deploymentObject->host1_v6 !== NULL) {
149
                                echo _("IPv6") . ": " . $deploymentObject->host1_v6;
150
                            }
151
                            ?>
152
                        </td>
153
                        <td><?php echo _("RADIUS port number: ") ?></td>
154
                        <td><?php echo $deploymentObject->port1; ?></td>
155
                        <td>
156
                            <?php
157
                                echo "<img src='" . $radiusMessages[$deploymentObject->radius_status_1]['icon'] . 
158
                                     "' alt='" . $radiusMessages[$deploymentObject->radius_status_1]['text'] . 
159
                                     "' title='" . $radiusMessages[$deploymentObject->radius_status_1]['text'] . "'>";
160
                            ?>
161
                        </td>
162
                    </tr>
163
                    <tr>
164
                        <td><strong><?php echo _("Your backup RADIUS server") ?><br/></strong>
165
                            <?php
166
                            if ($deploymentObject->host2_v4 !== NULL) {
167
                                echo _("IPv4") . ": " . $deploymentObject->host2_v4;
168
                            }
169
                            if ($deploymentObject->host2_v4 !== NULL && $deploymentObject->host2_v6 !== NULL) {
170
                                echo "<br/>";
171
                            }
172
                            if ($deploymentObject->host2_v6 !== NULL) {
173
                                echo _("IPv6") . ": " . $deploymentObject->host2_v6;
174
                            }
175
                            ?></td>
176
                        <td><?php echo _("RADIUS port number: ") ?></td>
177
                        <td><?php echo $deploymentObject->port2; ?></td>
178
                        <td>
179
                            <?php
180
                                echo "<img src='" . $radiusMessages[$deploymentObject->radius_status_2]['icon'] .
181
                                     "' alt='" . $radiusMessages[$deploymentObject->radius_status_2]['text'] . 
182
                                     "' title='" . $radiusMessages[$deploymentObject->radius_status_2]['text'] . "'>";
183
                            ?>
184
                        </td>
185
                    </tr>
186
                    
187
                    <tr>
188
                        <td><strong><?php echo _("RADIUS shared secret"); ?></strong></td>
189
                        <td><?php echo $deploymentObject->secret; ?></td>
190
                    </tr>
191
                    
192
                    <?php if ($opname = $deploymentObject->getAttributes("managedsp:operatorname")[0]['value'] ?? NULL) { ?>
193
                    <tr>
194
                        <td><strong><?php echo _("Custom Operator-Name"); ?></strong></td>
195
                        <td><?php echo $opname; ?></td>
196
                    </tr>
197
                    <?php
198
                    }
199
                        if ($vlan = $deploymentObject->getAttributes("managedsp:vlan")[0]['value'] ?? NULL) { ?>
200
                    <tr>
201
                        <td><strong><?php echo _("VLAN tag for own users"); ?></strong></td>
202
                        <td><?php echo $vlan; ?></td>
203
                    </tr>
204
                        <?php } ?>
205
                    <?php
206
                    $allRealms = array_values(array_unique(array_column($deploymentObject->getAttributes("managedsp:realmforvlan"), "value")));
207
                    if (!empty($allRealms)) {
208
                    ?>
209
                    <tr>
210
                        <td><strong><?php echo _("Realm to be considered own users"); ?></strong></td>
211
                        <td><?php echo implode(', ', $allRealms); ?></td>
212
                    </tr>
213
                    <?php
214
                    }
215
                    ?>
216
                </table>
217
                <div class='buttongroupprofilebox' style='clear:both;'>
218
                    <form action='edit_hotspot.php?inst_id=<?php echo $my_inst->identifier; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
219
                        <hr/>
220
                        <button type='submit' name='profile_action' value='edit'><?php echo _("Advanced Configuration"); ?></button>
221
                    </form>
222
                    <?php if ($deploymentObject->status == \core\AbstractDeployment::ACTIVE) { ?>
223
                        <form action='edit_hotspot.php?inst_id=<?php echo $my_inst->identifier; ?>&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_DELETE; ?>' onclick="return confirm('<?php printf(_("Do you really want to deactivate the %s deployment?"), core\DeploymentManaged::PRODUCTNAME); ?>')">
225
                                <?php echo _("Deactivate"); ?>
226
                            </button>
227
                            <?php 
228
                                if (isset($_GET['res']) && is_array($_GET['res'])) {
229
                                    $res = array_count_values($_GET['res']);
230
                                    if (isset($res['FAILURE']) && $res['FAILURE'] > 0) {
231
                                        echo '<br>';
232
                                        if ($res['FAILURE'] == 2) {
233
                                            echo ' <span style="color: red;">' . _("Activation failure.") . '</span>';
234
                                        } else {
235
                                            if (isset($_GET['res'][1]) && $_GET['res']['1'] == 'FAILURE') {
236
                                                echo ' <span style="color: red;">' . _("Activation failure for your primary RADIUS server.") . '</span>';
237
                                            } else {
238
                                                echo ' <span style="color: red;">' . _("Activation failure for your backup RADIUS server.") . '</span>';
239
                                            }
240
                                        }
241
                                    }
242
                                }
243
                            ?>
244
                        </form>
245
                        <?php
246
                        } else {
247
                        ?>
248
                        <form action='edit_hotspot.php?inst_id=<?php echo $my_inst->identifier; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
249
                            <button class='delete' style='background-color: green;' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_ACTIVATE; ?>'>
250
                                <?php echo _("Activate"); ?>
251
                            </button>
252
                            <?php 
253
                                if (isset($_GET['res']) && is_array($_GET['res'])) {
254
                                    $res = array_count_values($_GET['res']);
255
                                    if ($res['FAILURE'] > 0) {
256
                                        echo '<br>';
257
                                        if ($res['FAILURE'] == 2) {
258
                                            echo ' <span style="color: red;">' . _("Failure during deactivation, your request is queued for handling") . '</span>';
259
                                        } else {
260
                                            if (isset($_GET['res'][1]) && $_GET['res']['1'] == 'FAILURE') {
261
                                                echo ' <span style="color: red;">' . _("Deactivation failure for your primary RADIUS server, your request is queued.") . '</span>';
262
                                            } else {
263
                                                echo ' <span style="color: red;">' . _("Deactivation failure for your backup RADIUS server, your request is queued.") . '</span>';
264
                                            }
265
                                        }
266
                                    }
267
                                }
268
                            ?>
269
                        </form>
270
                    <?php
271
                    }
272
                    if (in_array(1, $retry)) {
273
                    ?>
274
                         <form action='edit_hotspot.php?inst_id=<?php echo $my_inst->identifier; ?>&amp;deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'>
275
                            <button class='delete' style='background-color: green;' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_RETRY; ?>'>
276
                                <?php echo _("Push missing configuration update"); ?>
277
                            </button>
278
                            <?php
279
                                foreach ($retry as $key => $value) {
280
                                    if ($value == 1) {
281
                                    ?>
282
                                    <input type="hidden" name='update[]' value='<?php echo $key;?>'>
283
                                    <?php
284
                                    }
285
                                }
286
                            ?>
287
                         </form>
288
                    <?php
289
                    }
290
                    ?>
291
                </div>
292
            </div>
293
            <div style='width:20px;'></div> <!-- QR code space, reserved -->
294
            <div style='display: table-cell; min-width:200px;'></div> <!-- statistics space, reserved -->
295
        </div>
296
297
        <?php
298
    }
299
    if ($readonly === FALSE) {
300
        // the opportunity to add a new silverbullet profile is only shown if
301
        // a) there is no SB profile yet
302
        // b) federation wants this to happen
303
304
        $myfed = new \core\Federation($my_inst->federation);
305
        if (\config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_SILVERBULLET'] == "LOCAL" && count($myfed->getAttributes("fed:silverbullet")) > 0 && $my_inst->deploymentCount() == 0) {
306
            // the button is grayed out if there's no support email address configured...
307
            $hasMail = count($my_inst->getAttributes("support:email"));
308
            ?>
309
            <form action='edit_hotspot.php?inst_id=<?php echo $my_inst->identifier; ?>' method='post' accept-charset='UTF-8'>
310
                <div>
311
                    <button type='submit' <?php echo ($hasMail > 0 ? "" : "disabled"); ?> name='profile_action' value='new'>
312
                        <?php echo sprintf(_("Add %s deployment ..."), \core\DeploymentManaged::PRODUCTNAME); ?>
313
                    </button>
314
                </div>
315
            </form>
316
            <?php
317
        }
318
319
        // adding a normal profile is always possible if we're configured for it
320
    }
321
    echo $deco->footer();
322
    
323