Passed
Push — release_2_1 ( 76c21d...ea18cf )
by Maja
10:14
created

RADIUSTestsUI::printStatic()   B

Complexity

Conditions 11
Paths 13

Size

Total Lines 52
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 52
rs 7.3166
c 0
b 0
f 0
cc 11
nc 13
nop 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
 * *****************************************************************************
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 contains code for testing presenting tests result
25
 *
26
 * @author Maja Gorecka-Wolniewicz <[email protected]>
27
 *
28
 * @package Developer
29
 * 
30
 */
31
32
namespace core\diag;
33
34
use \Exception;
0 ignored issues
show
Bug introduced by
The type \Exception was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
36
class RADIUSTestsUI extends AbstractTest
37
{
38
39
    /**
40
     * This private variable contains the realm to be checked. Is filled in the
41
     * class constructor.
42
     * 
43
     * @var string
44
     */
45
    public $realm = NULL;
46
    public $outerUser = NULL;
47
48
    /**
49
     * result of the reachability tests
50
     * 
51
     * @var array
52
     */
53
    public $allReachabilityResults = [];
54
    
55
    private $hostMap = [];
56
    private $protocolsMap = [];
57
    private $globalLevelStatic = \core\common\Entity::L_OK;
58
    private $globalLevelDynamic = \core\common\Entity::L_OK;
59
    private $rfc7585suite = NULL;
60
    private $srv;
61
    private $naptr;
62
    private $naptrValid;
63
    private $hosts;
64
    private $testSuite;
65
    private $areFailed = FALSE;
66
    private $globalInfo = [];
67
    private $stateIcons = [];
68
    private $states;
69
    private $certFields;
70
    private $timestamp;
71
    const RADIUS_TEST_OPERATION_MODE_SHALLOW = 1;
72
    const RADIUS_TEST_OPERATION_MODE_THOROUGH = 2;
73
    
74
    
75
76
    /**
77
     * Constructor for the RADIUSTestsUI class. The single mandatory parameter is the
78
     * token indicating tests that were carried out and saved as JSON files.
79
     * 
80
     * @param string $token                  the token which points to a directory
81
     * @throws Exception
82
     */
83
    public function __construct($token)
84
    {
85
        parent::__construct();
86
        $this->globalInfo = [
87
            \core\common\Entity::L_OK => _("All tests passed."),
88
            \core\common\Entity::L_WARN => _("There were some warnings."),
89
            \core\common\Entity::L_ERROR => _("There were some errors."),
90
            \core\common\Entity::L_REMARK => _("There were some remarks.")
91
        ]; 
92
        $this->stateIcons = [
93
            \core\common\Entity::L_OK => '../resources/images/icons/Tabler/square-rounded-check-filled-green.svg',
94
            \core\common\Entity::L_WARN => '../resources/images/icons/Tabler/alert-square-rounded-filled-yellow.svg',
95
            \core\common\Entity::L_ERROR => '../resources/images/icons/Tabler/square-rounded-x-filled-red.svg',
96
            \core\common\Entity::L_REMARK => '../resources/images/icons/Tabler/info-square-rounded-filled-blue.svg'
97
        ];
98
        $this->states = [
99
            'PASS' => _("PASS"),
100
            'FAIL' => _("FAIL")
101
        ];
102
        $this->certFields = [
103
            'subject' => _("Subject:"),
104
            'issuer' => _("Issuer:"),
105
            'validFrom' =>  _("Valid from:"),
106
            'validTo' => _("Valid to:"),
107
            'serialNumber' => _("Serial number:"),
108
            'sha1' => _("SHA1 fingerprint:"),
109
            'title' => _("Server certificate"),
110
            'policies' => _("Policies:"),
111
            'crldistributionpoints' =>  _("crlDistributionPoint:"),
112
            'authorityinfoaccess' => _("authorityInfoAccess:"),
113
            'subjectaltname' => _("SubjectAltName:"),
114
        ];
115
        $jsondir = dirname(dirname(dirname(__FILE__)))."/var/json_cache";
116
        if ($token && is_dir($jsondir.'/'.$token)) {
117
            foreach (['realm', 'udp', 'clients', 'capath'] as $test_type) {
118
                foreach (glob("$jsondir/$token/$test_type*") as $filename) {
119
                    $this->loggerInstance->debug(4, "\nIS_DIR $filename\n");
120
                    if (!array_key_exists($test_type, $this->allReachabilityResults)) {
121
                        $this->allReachabilityResults[$test_type] = array();
122
                    }
123
                    $this->allReachabilityResults[$test_type][] = json_decode(file_get_contents($filename));
124
                }   
125
            }
126
            if ($this->allReachabilityResults['realm'][0]->realm) {
127
                $this->realm = $this->allReachabilityResults['realm'][0]->realm;
128
                $this->outerUser = $this->allReachabilityResults['realm'][0]->outeruser;
129
                foreach ($this->allReachabilityResults['realm'][0]->totest as $totest) {
130
                    $this->hostMap[$totest->host] = $totest->bracketaddr;
131
                    if (property_exists($totest, 'protocols')) {
132
                        $this->protocolsMap[$totest->host] = $totest->protocols;
133
                    }
134
                }
135
                $this->rfc7585suite = unserialize(base64_decode($this->allReachabilityResults['realm'][0]->rfc7585suite));
136
                $this->srv = $this->allReachabilityResults['realm'][0]->srv;
137
                $this->naptr = $this->allReachabilityResults['realm'][0]->naptr;
138
                $this->naptrValid = $this->allReachabilityResults['realm'][0]->naptr_valid;
139
                $this->hosts = $this->allReachabilityResults['realm'][0]->hosts;
140
                $this->testSuite = unserialize(base64_decode($this->allReachabilityResults['realm'][0]->testsuite));
141
            }
142
            $this->timestamp = $this->allReachabilityResults['realm'][0]->datetime;
143
        }
144
    }
145
    
146
    public function getTimeStamp()
147
    { 
148
        return $this->timestamp;
149
    }
150
    /**
151
     * sets the global status for static tests
152
     */
153
    public function setGlobalStaticResult()
154
    { 
155
        foreach ($this->allReachabilityResults['udp'] as $udp) {
156
            $this->globalLevelStatic = max($this->globalLevelStatic, $udp->result[0]->level);
157
        }
158
    }
159
    
160
    public function setGlobalDynamicResult()
161
    {
162
        foreach ($this->allReachabilityResults['capath'] as $capath) {
163
            $this->globalLevelDynamic = max($this->globalLevelDynamic, $capath->level);
164
        }
165
        foreach ($this->allReachabilityResults['clients'] as $clients) {
166
            $srefused = FALSE;
167
            $level = \core\common\Entity::L_OK;
168
            foreach ($clients->ca as $ca) {
169
                foreach ($ca->certificate as $certificate) {
170
                    if ($certificate->returncode == \core\diag\RADIUSTests::RETVAL_CONNECTION_REFUSED) {
171
                        $srefused = $this->areFailed = TRUE;
172
                    }
173
                }
174
                if (!$srefused) {
175
                    foreach ($clients->ca as $cca) {
176
                        foreach ($cca->certificate as $certificate) {
177
                            $level = $certificate->returncode;
178
                            if ($level < 0) {
179
                                $level = \core\common\Entity::L_ERROR;
180
                                $this->areFailed = TRUE;
181
                            }
182
                            if ($certificate->expected != 'PASS') {
183
                                if ($certificate->connected == 1) {
184
                                    $level = \core\common\Entity::L_WARN;
185
                                } else {
186
                                    $level = \core\common\Entity::L_OK;
187
                                }
188
                            }
189
                        }
190
                    }   
191
                } 
192
            }
193
            $this->globalLevelDynamic = max($this->globalLevelDynamic, $level);
194
        }
195
    }           
196
197
    public function isDynamic()
198
    {
199
        if ($this->naptr > 0) {
200
            return TRUE;
201
        }
202
        return FALSE;
203
    }
204
    /**
205
     * prints tabs-1
206
     * 
207
     * 
208
     */
209
    public function printOverview()
210
    {
211
        $out = [];
212
        $out[] = "<fieldset class='option_container'>
213
        <legend>
214
        <strong>"._("Overview").'</strong> 
215
        </legend>';
216
        $out[] = "<strong>"._("DNS checks")."</strong><div>";
217
        if ($this->naptr != \core\diag\RADIUSTests::RETVAL_NOTCONFIGURED) {
218
            $out[] = "<table>";
219
            $out[] = "<tr><td>"._("Checking NAPTR existence:")."</td><td>";
220
            switch ($this->naptr) {
221
                case \core\diag\RFC7585Tests::RETVAL_NONAPTR:
222
                    $out[] = _("This realm has no NAPTR records.");
223
                    break;
224
                case \core\diag\RFC7585Tests::RETVAL_ONLYUNRELATEDNAPTR:
225
                    $out[] = _("This realm has NAPTR records, but none are related to this roaming consortium.");
226
                    break;
227
                default: // if none of the possible negative retvals, then we have matching NAPTRs
228
                    $out[] = sprintf(_("This realm has %d NAPTR records relating to this roaming consortium."), $this->naptr);
229
            }
230
            $out[] = "</td></tr>";
231
          
232
            if ($this->naptr > 0) {
233
                $out[] = "<tr><td>"._("Checking NAPTR compliance (flag = S and regex = {empty}):")."</td><td>";
234
                switch ($this->naptrValid) {
235
                    case \core\diag\RADIUSTests::RETVAL_OK:
236
                        $out[] = "No issues found.";
237
                        break;
238
                    case \core\diag\RADIUSTests::RETVAL_INVALID:
239
                        $out[] = _("At least one NAPTR with invalid content found!");
240
                        break;
241
                }
242
                $out[] = "</td></tr>";
243
            }
244
            // SRV resolution
245
            if ($this->naptr > 0 && $this->naptrValid == \core\diag\RADIUSTests::RETVAL_OK) {
246
                $out[] = "<tr><td>"._("Checking SRVs:")."</td><td>";
247
                switch ($this->srv) {
248
                    case \core\diag\RADIUSTests::RETVAL_SKIPPED:
249
                        $out[] = _("This check was skipped.");
250
                        break;
251
                    case \core\diag\RADIUSTests::RETVAL_INVALID:
252
                        $out[] = _("At least one NAPTR with invalid content found!");
253
                        break;
254
                    default: // print number of successfully retrieved SRV targets
255
                        $out[] = sprintf(_("%d host names discovered."), $this->srv);
256
                }
257
                $out[] = "</td></tr>";
258
            }
259
            // IP addresses for the hosts
260
            if ($this->naptr > 0 && $this->naptrValid == \core\diag\RADIUSTests::RETVAL_OK && $this->srv > 0) {
261
                $out[] = "<tr><td>"._("Checking IP address resolution:")."</td><td>";
262
                switch ($this->srv) {
263
                    case \core\diag\RADIUSTests::RETVAL_SKIPPED:
264
                        $out[] = _("This check was skipped.");
265
                        break;
266
                    case \core\diag\RADIUSTests::RETVAL_INVALID:
267
                        $out[] = _("At least one hostname could not be resolved!");
268
                        break;
269
                    default: // print number of successfully retrieved SRV targets
270
                        $out[] = sprintf(_("%d IP addresses resolved."), $this->hosts);
271
                }
272
                $out[] = "</td></tr>";
273
            }
274
275
            $out[] = "</table><br/>";
276
            $out[] = sprintf(_("Realm is <strong>%s</strong> "), _(($this->naptr > 0 ? "DYNAMIC" : "STATIC")));
277
            if (count($this->testSuite->listerrors()) == 0) {
278
                $out[] = _("with no DNS errors encountered. Congratulations!");
279
            } else {
280
                $out[] = _("but there were DNS errors! Check them!")." "._("You should re-run the tests after fixing the errors; more errors might be uncovered at that point. The exact error causes are listed below.");
281
                $out[] = "<div class='notacceptable'><table>";
282
                foreach ($this->testSuite->listerrors() as $details) {
283
                    $out[] = "<tr><td>".$details['TYPE']."</td><td>".$details['TARGET']."</td></tr>";
284
                }
285
                $out[] = "</table></div>";
286
            }
287
            $out[] = '</div>';
288
        } else {
289
            $out[] = "<tr><td>"._("Dynamic discovery test is not configured")."</td><td>";
290
        }
291
        $out[] = "<hr><strong>"._("Static connectivity tests")."</strong>
292
         <table><tr>
293
         <td class='icon_td'>";
294
        $out[] = "<img src='".$this->stateIcons[$this->globalLevelStatic]."' id='main_static_ico' class='icon'></td><td id='main_static_result'>".
295
                            $this->globalInfo[$this->globalLevelStatic].' '. _("See the appropriate tab for details.").'</td>
296
         </tr></table>';
297
        if ($this->naptr > 0) {
298
            $out[] = "<hr><strong>"._("Dynamic connectivity tests")."</strong>
299
            <table><tr>
300
            <td class='icon_td'><img src='".$this->stateIcons[$this->globalLevelDynamic]."' id='main_dynamic_ico' class='icon'></td><td id='main_dynamic_result'>".
301
            $this->globalInfo[$this->globalLevelDynamic].' '._("See the appropriate tab for details.").'</td></tr></table>';
302
        }
303
        $out[] = '</fieldset>';
304
        return join('', $out);
305
    }
306
    
307
    public function printStatic()
308
    {
309
        $out = [];
310
        $out[] = '<fieldset class="option_container" id="static_tests">
311
                  <legend><strong>';
312
        $out[] = _("STATIC connectivity tests");
313
        $out[] = '</strong> </legend>';
314
        $out[] = _("This check sends a request for the realm through various entry points of the roaming consortium infrastructure. The request will contain the 'Operator-Name' attribute, and will be larger than 1500 Bytes to catch two common configuration problems.<br/>Since we don't have actual credentials for the realm, we can't authenticate successfully - so the expected outcome is to get an Access-Reject after having gone through an EAP conversation.");
315
        $out[] = '<p>';
316
        foreach ($this->allReachabilityResults['udp'] as $udp) {
317
            $hostindex = $udp->hostindex;
318
            $result = $udp->result[0];
319
            $out[] = '<hr>';
320
            $out[] = sprintf(_("Testing from: <strong>%s"), \config\Diagnostics::RADIUSTESTS['UDP-hosts'][$hostindex]['display_name']).'</strong>';
321
            $out[] = '<ul style="list-style-type: none;"><li>';
322
            $out[] = "<table id='results$hostindex'  style='width:100%' class='udp_results'>
323
<tr>
324
<td class='icon_td'><img src='".$this->stateIcons[$result->level]."' id='src".$hostindex."_img'></td>
325
<td id='src$hostindex' colspan=2>
326
";
327
            $out[] = '<strong>'.($result->server ? $result->server : _("Connected to undetermined server")).'</strong><br/>'.sprintf (_("elapsed time: %sms."), $result->time_millisec).'<div>'.$result->message.'</div>';
328
                    
329
            if ($result->level > \core\common\Entity::L_OK && property_exists($result, 'cert_oddities')) {
330
                foreach ($result->cert_oddities as $oddities) {
331
                    $out[] = '<tr class="results_tr"><td>&nbsp;</td><td class="icon_td"><img src="'.$this->stateIcons[$oddities->level].'"></td><td>'.$oddities->message.'</td></tr>';
332
                }
333
            }
334
            $more = '';
335
            if ($result->server_cert) {
336
                $more .= '<div class="more">';
337
                $certdesc = '<br>'.$this->certFields['title'].'<ul>';
338
                foreach ($result->server_cert as $sckey => $sc) {
339
                    if (array_key_exists($sckey, $this->certFields)) {
340
                        $certdesc .= '<li>'.$this->certFields[$sckey].' '.$sc;
341
                    }
342
                }
343
                if ($result->server_cert->extensions) {
344
                    $certdesc .= '<li>' . _('Extensions') . '<ul>';
345
                    foreach ($result->server_cert->extensions as $ekey => $eval) {
346
                        $certdesc .= '<li>' . $ekey . ': ' . $eval;
347
                    }
348
                    $certdesc .= '</ul>';
349
                }
350
                $certdesc .= '</ul>';
351
                $more .= '<span class="morecontent"><span>'.$certdesc.
352
                        '</span>&nbsp;&nbsp;<a href="" class="morelink">'._("show server certificate details").'&raquo;</a></span></td></tr>';
353
                $out[] = $more . '</ul>';
354
            }            
355
            $out[] = "</td></tr></table></ul>";
356
        }
357
        $out[] = '</fieldset>';
358
        return join('', $out);            
359
    }
360
    
361
    private function collectCAPath()
362
    {
363
        $capathtest = [];
364
        $capathtest[] = '<p><strong>'._("Checking server handshake...")."</strong><p>";
365
        foreach ($this->allReachabilityResults['capath'] as $capath) {
366
            $hostindex = $capath->hostindex;
367
            $level = $capath->level;
368
            if ($capath->level == \core\common\Entity::L_OK && $capath->result == \core\diag\RADIUSTests::RETVAL_INVALID) {
369
                $level = \core\common\Entity::L_WARN;
370
            }
371
            $capathtest[] = '<p><strong>'.$this->hostMap[$capath->IP].'</strong> ('.$capath->name.') ';
372
            $prots = [];
373
            if (isset($this->protocolsMap[$capath->IP]) && $this->protocolsMap[$capath->IP] != '') {
374
                $prots = explode(';', $this->protocolsMap[$capath->IP]);
375
                if (!empty($prots)) {
376
                    $capathtest[] = ' ' . _("supported TLS protocols: ");
377
                    $capathtest[] = implode(', ', $prots);
378
                    if (!in_array("TLS1.3", $prots)) {
379
                        $capathtest[] =  ' ' . '<font color="red">' . _("not supported: ") . 'TLS1.3</font>';
380
                    }
381
                }
382
            }
383
            $capathtest[] = '<ul style="list-style-type: none;" class="caresult"><li>';
384
            $capathtest[] = "<table id='caresults$hostindex'  style='width:100%'>
385
<tr>
386
<td class='icon_td'><img src='";
387
            $capathtest[] = $this->stateIcons[$level]."' id='srcca".$hostindex."_img'></td>
388
<td id='srcca$hostindex'>";
389
            $more = '';
390
            if ($capath->certdata && $capath->certdata->subject != '') {
391
                $more .= '<div class="more">';
392
                $certdesc = '<br>'.$this->certFields['title'].'<ul>';
393
                if ($capath->certdata->subject) {
394
                    $certdesc .= '<li>'.$this->certFields['subject'].' '.$capath->certdata->subject;
395
                }
396
                if ($capath->certdata->issuer) {
397
                    $certdesc .= '<li>'.$this->certFields['issuer'].' '.$capath->certdata->issuer;
398
                }
399
                if ($capath->certdata->validTo) {
400
                    $certdesc .= '<li>'.$this->certFields['validTo'].' '.
401
                            date_create_from_format('ymdGis', 
402
                                    substr($capath->certdata->validTo, 0, -1))->format('Y-m-d H:i:s'). ' UTC';
403
                }
404
                if ($capath->certdata->extensions) {
405
                    if ($capath->certdata->extensions->subjectaltname) {                     
406
                        $certdesc .= '<li>'.$this->certFields['subjectaltname'].' '.$capath->certdata->extensions->subjectaltname;
407
                    }
408
                }
409
                if ($capath->certdata->extensions->policies) {
410
                    $certdesc .= '<li>'.$this->certFields['policies'].' '.$capath->certdata->extensions->policies;
411
                }
412
                if ($capath->certdata->extensions->crldistributionpoints) {
413
                    $certdesc .= '<li>'.$this->certFields['crldistributionpoints'].' '.$capath->certdata->extensions->crldistributionpoints;
414
                }
415
                if ($capath->certdata->extensions->authorityinfoaccess) {
416
                    $certdesc .= '<li>'.$this->certFields['authorityinfoaccess'].' '.$capath->certdata->extensions->authorityinfoaccess;
417
                }
418
                            
419
                $certdesc .= '</ul>';
420
                $more .= '<span class="morecontent"><span>'.$certdesc.$protocoldesc.
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $protocoldesc seems to be never defined.
Loading history...
421
                        '</span>&nbsp;&nbsp;<a href="" class="morelink">'._("more").'&raquo;</a></span></td></tr>';
422
            } else {
423
                $certdesc = '<br>';
424
            }
425
            $capathtest[] = '<div>'.($capath->message!='' ? $capath->message : _('Test failed')).'</div>'.$more;
426
            $capathtest[] = '</td>
427
</tr>
428
</table>';
429
            $capathtest[] = '</li></ul>';
430
        }
431
        return $capathtest;
432
    }
433
434
    private function collectClients()
435
    {
436
        $clientstest = [];
437
        foreach ($this->allReachabilityResults['clients'] as $clients) {
438
            if ($clients->result == RADIUSTests::RETVAL_SKIPPED) {
439
                continue;
440
            }
441
            $hostindex = $clients->hostindex; 
442
            $clientstest[] = '<p><strong>'.$this->hostMap[$clients->IP].'</strong></p>';
443
            $clientstest[] = "<span id='clientresults$hostindex'>";
444
            $clientstest[] = '<p></p>';
445
            if ($this->globalLevelDynamic != \core\common\Entity::L_ERROR) {
446
                if (property_exists($clients, 'ca')) {
447
                    $clientstest[] = '<ol>';
448
                    foreach ($clients->ca as $ca) {                     
449
                        $srefused = 0;
450
                        $cliinfo = '';
451
                        $cliinfo .= '<li>'._('Client certificate').' <b>'.$ca->clientcertinfo->from.
452
                                    '</b>'.', '.$ca->clientcertinfo->message .
453
                                    '<br> (CA: '.$ca->clientcertinfo->issuer.')<ul>';
454
                        foreach ($ca->certificate as $certificate) {
455
                            if ($certificate->returncode == \core\diag\RADIUSTests::RETVAL_CONNECTION_REFUSED) {
456
                                $srefused = 1;
457
                            }
458
                        }
459
                        if ($srefused == 0) {
460
                            foreach ($ca->certificate as $certificate) {                           
461
                                $cliinfo .= '<li><i>'.$certificate->message. 
462
                                            ', '._("expected result: ").$this->states[$certificate->expected].'</i>';
463
                                $cliinfo .= '<ul style="list-style-type: none;">';
464
                                if (property_exists($certificate, 'finalerror') && $certificate->finalerror == 2) {
465
                                        $cliinfo .= '<li>'._('this test was skipped - no appropriate client certificate').'</li></ul>';
466
                                        continue;
467
                                }
468
                                $level = $certificate->returncode;
469
                                if ($level < 0) {
470
                                    $level = \core\common\Entity::L_ERROR;
471
                                }
472
                                $add = '';
473
                                if ($certificate->expected == 'PASS') {
474
                                    if ($certificate->connected == 1) {
475
                                        $state = _("Server accepted this client certificate");
476
                                    } else {
477
                                        if (property_exists($certificate, 'reason') && $certificate->reason == \core\diag\RADIUSTests::CERTPROB_UNKNOWN_CA) {
478
                                            $add = '<br>'._('You should update your list of accredited CAs').
479
                                                            ' <a href=\"'.\config\Diagnostics::RADIUSTESTS['accreditedCAsURL'].'\">'.
480
                                                            _('Get it from here.').'</a>';
481
                                        }
482
                                        $state = _('Server did not accept this client certificate - reason').': '.
483
                                                    $certificate->resultcomment;
484
                                    }
485
                                } else {
486
                                    if ($certificate->connected == 1) {
487
                                        $level = \core\common\Entity::L_WARN;
488
                                        $state = _('Server accepted this client certificate, but should not have');
489
                                    } else {
490
                                        $level = \core\common\Entity::L_OK;
491
                                        $state = _('Server did not accept this client certificate').': '.$certificate->resultcomment;
492
                                    }
493
                                }
494
                                $cliinfo .= '<li><table><tbody><tr><td class="icon_td"><img class="icon" src="'.$this->stateIcons[$level].'" style="width: 24px;"></td><td>'.$state;
495
                                $cliinfo .= ' ('.sprintf(_('elapsed time: %sms.'), $certificate->time_millisec).'&nbsp;) '.$add.'</td></tr>';
496
                                $cliinfo .= '</tbody></table></ul></li>';
497
                                if (property_exists($certificate, 'finalerror')) {
498
                                    if ($certificate->finalerror == 1) {
499
                                        $cliinfo .= '<li>'._('Rest of tests for this CA skipped').'</li>';
500
                                    }
501
                                }
502
                            }
503
                            $cliinfo .= '</ul>';
504
                        }
505
                                    
506
                        if ($srefused > 0) {
507
                            $cliinfo = _('Connection refused');
508
                            $clientstest[] = "<table><tr><td class='icon_td' id='srcclient".$hostindex."_img'><img src='".$this->stateIcons[\core\common\Entity::L_ERROR]."'></td>".
509
                                        "<td id='srcclient$hostindex'><p>$cliinfo</p></td></tr></table>";
510
                        } else {
511
                            $clientstest[] = "<p>$cliinfo</p>";
512
                        }
513
                    }
514
                    
515
                } else {
516
                    $cliinfo = _('Test failed');
517
                    $clientstest[] = "<table><tr><td class='icon_td' id='srcclient".$hostindex."_img'><img src='".
518
                                    $this->stateIcons[\core\common\Entity::L_WARN]."'></td>" .
519
                                    "<td id='srcclient$hostindex'>$cliinfo</td></tr></table>";
520
                }
521
            } else {
522
                $clientstest[] = '<ul style="list-style-type: none;" class="clientsresult"><li>';
523
                $clientstest[] = "<table id='clientsresults$hostindex'  style='width:100%'>
524
<tr>
525
<td class='icon_td'><img src='";
526
                $clientstest[] = $this->stateIcons[\core\common\Entity::L_ERROR]."' id='srcclients".$hostindex."_img'></td>
527
<td id='srcclient$hostindex'>";
528
                $clientstest[] = _("These tests were skipped because of previous errors.").'</td></tr></table></ul>';
529
            }
530
            $clientstest[] = '</ol><p></p>';
531
        }
532
        return $clientstest;
533
    }
534
    
535
    public function printDynamic()
536
    {
537
        $out = [];
538
        $out[] = "<div id='dynamic_tests'><fieldset class='option_container'>
539
            <legend><strong>"._("DYNAMIC connectivity tests")."</strong></legend>";
540
        
541
        if (count($this->rfc7585suite->NAPTR_hostname_records) > 0) {    
542
            $capathtest = $this->collectCAPath();
543
            $clientstest = $this->collectClients();
544
            $out[] = '<div style="align:right;">';            
545
            $out[] = '<div style="align:right; display: ';
546
            if ($this->globalLevelDynamic == \core\common\Entity::L_OK && !$this->areFailed) {
547
                $out[] = 'none';
548
            }
549
            $out[] = ';" id="dynamic_result_fail"><b>'._("Some errors were found during the tests, see below").'</b></div>';
550
            $out[] = '<div style="align:right; display: ';
551
            if ($this->globalLevelDynamic != \core\common\Entity::L_OK || $this->areFailed) {
552
                $out[] = 'none';
553
            }
554
            $out[] = '" id="dynamic_result_pass"><b>'.
555
                                _("All tests passed, congratulations!").'</b></div>'.
556
                                '<div style="align:left;"><a href="" class="moreall"><i>'._('Show detailed information for all tests').'&raquo;</i></a></div>';
557
            $out[] = join('', $capathtest);
558
            if (!empty($clientstest)) {
559
                $out[] = '<span id="clientstest" style="display: ;"><p><hr><b>'._('Checking if certificates from CAs are accepted...').'</b><p>'._('A few client certificates will be tested to check if servers are resistant to some certificate problems.').'<p>';
560
                $out[] = join('', $clientstest);
561
                $out[] = '</span>';
562
            }
563
            $out[] = '</div>';
564
        }
565
        $out[] = "</fieldset></div></div>";
566
        return join('', $out);
567
    }
568
    
569
}
570