Passed
Push — release_2_1 ( 7e3d98...d14b98 )
by Maja
10:45 queued 17s
created

RADIUSTestsUI::printStatic()   C

Complexity

Conditions 12
Paths 25

Size

Total Lines 54
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 54
rs 6.9666
c 0
b 0
f 0
cc 12
nc 25
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
        if (isset($this->allReachabilityResults['capath'])) {
163
            foreach ($this->allReachabilityResults['capath'] as $capath) {
164
                $this->globalLevelDynamic = max($this->globalLevelDynamic, $capath->level);
165
            }
166
        }
167
        if (isset($this->allReachabilityResults['clients'])) {
168
            foreach ($this->allReachabilityResults['clients'] as $clients) {
169
                $srefused = FALSE;
170
                $level = \core\common\Entity::L_OK;
171
                foreach ($clients->ca as $ca) {
172
                    foreach ($ca->certificate as $certificate) {
173
                        if ($certificate->returncode == \core\diag\RADIUSTests::RETVAL_CONNECTION_REFUSED) {
174
                            $srefused = $this->areFailed = TRUE;
175
                        }
176
                    }
177
                    if (!$srefused) {
178
                        foreach ($clients->ca as $cca) {
179
                            foreach ($cca->certificate as $certificate) {
180
                                $level = $certificate->returncode;
181
                                if ($level < 0) {
182
                                    $level = \core\common\Entity::L_ERROR;
183
                                    $this->areFailed = TRUE;
184
                                }
185
                                if ($certificate->expected != 'PASS') {
186
                                    if ($certificate->connected == 1) {
187
                                        $level = \core\common\Entity::L_WARN;
188
                                    } else {
189
                                        $level = \core\common\Entity::L_OK;
190
                                    }
191
                                }
192
                            }
193
                        }   
194
                    } 
195
                }
196
                $this->globalLevelDynamic = max($this->globalLevelDynamic, $level);
197
            }
198
        }
199
    }           
200
201
    public function isDynamic()
202
    {
203
        if ($this->naptr > 0) {
204
            return TRUE;
205
        }
206
        return FALSE;
207
    }
208
    /**
209
     * prints tabs-1
210
     * 
211
     * 
212
     */
213
    public function printOverview()
214
    {
215
        $out = [];
216
        $out[] = "<fieldset class='option_container'>
217
        <legend>
218
        <strong>"._("Overview").'</strong> 
219
        </legend>';
220
        $out[] = "<strong>"._("DNS checks")."</strong><div>";
221
        if ($this->naptr != \core\diag\RADIUSTests::RETVAL_NOTCONFIGURED) {
222
            $out[] = "<table>";
223
            $out[] = "<tr><td>"._("Checking NAPTR existence:")."</td><td>";
224
            switch ($this->naptr) {
225
                case \core\diag\RFC7585Tests::RETVAL_NONAPTR:
226
                    $out[] = _("This realm has no NAPTR records.");
227
                    break;
228
                case \core\diag\RFC7585Tests::RETVAL_ONLYUNRELATEDNAPTR:
229
                    $out[] = _("This realm has NAPTR records, but none are related to this roaming consortium.");
230
                    break;
231
                default: // if none of the possible negative retvals, then we have matching NAPTRs
232
                    $out[] = sprintf(_("This realm has %d NAPTR records relating to this roaming consortium."), $this->naptr);
233
            }
234
            $out[] = "</td></tr>";
235
          
236
            if ($this->naptr > 0) {
237
                $out[] = "<tr><td>"._("Checking NAPTR compliance (flag = S and regex = {empty}):")."</td><td>";
238
                switch ($this->naptrValid) {
239
                    case \core\diag\RADIUSTests::RETVAL_OK:
240
                        $out[] = "No issues found.";
241
                        break;
242
                    case \core\diag\RADIUSTests::RETVAL_INVALID:
243
                        $out[] = _("At least one NAPTR with invalid content found!");
244
                        break;
245
                }
246
                $out[] = "</td></tr>";
247
            }
248
            // SRV resolution
249
            if ($this->naptr > 0 && $this->naptrValid == \core\diag\RADIUSTests::RETVAL_OK) {
250
                $out[] = "<tr><td>"._("Checking SRVs:")."</td><td>";
251
                switch ($this->srv) {
252
                    case \core\diag\RADIUSTests::RETVAL_SKIPPED:
253
                        $out[] = _("This check was skipped.");
254
                        break;
255
                    case \core\diag\RADIUSTests::RETVAL_INVALID:
256
                        $out[] = _("At least one NAPTR with invalid content found!");
257
                        break;
258
                    default: // print number of successfully retrieved SRV targets
259
                        $out[] = sprintf(_("%d host names discovered."), $this->srv);
260
                }
261
                $out[] = "</td></tr>";
262
            }
263
            // IP addresses for the hosts
264
            if ($this->naptr > 0 && $this->naptrValid == \core\diag\RADIUSTests::RETVAL_OK && $this->srv > 0) {
265
                $out[] = "<tr><td>"._("Checking IP address resolution:")."</td><td>";
266
                switch ($this->srv) {
267
                    case \core\diag\RADIUSTests::RETVAL_SKIPPED:
268
                        $out[] = _("This check was skipped.");
269
                        break;
270
                    case \core\diag\RADIUSTests::RETVAL_INVALID:
271
                        $out[] = _("At least one hostname could not be resolved!");
272
                        break;
273
                    default: // print number of successfully retrieved SRV targets
274
                        $out[] = sprintf(_("%d IP addresses resolved."), $this->hosts);
275
                }
276
                $out[] = "</td></tr>";
277
            }
278
279
            $out[] = "</table><br/>";
280
            $out[] = sprintf(_("Realm is <strong>%s</strong> "), _(($this->naptr > 0 ? "DYNAMIC" : "STATIC")));
281
            if (count($this->testSuite->listerrors()) == 0) {
282
                $out[] = _("with no DNS errors encountered. Congratulations!");
283
            } else {
284
                $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.");
285
                $out[] = "<div class='notacceptable'><table>";
286
                foreach ($this->testSuite->listerrors() as $details) {
287
                    $out[] = "<tr><td>".$details['TYPE']."</td><td>".$details['TARGET']."</td></tr>";
288
                }
289
                $out[] = "</table></div>";
290
            }
291
            $out[] = '</div>';
292
        } else {
293
            $out[] = "<tr><td>"._("Dynamic discovery test is not configured")."</td><td>";
294
        }
295
        $out[] = "<hr><strong>"._("Static connectivity tests")."</strong>
296
         <table><tr>
297
         <td class='icon_td'>";
298
        $out[] = "<img src='".$this->stateIcons[$this->globalLevelStatic]."' id='main_static_ico' class='icon'></td><td id='main_static_result'>".
299
                            $this->globalInfo[$this->globalLevelStatic].' '. _("See the appropriate tab for details.").'</td>
300
         </tr></table>';
301
        if ($this->naptr > 0) {
302
            $out[] = "<hr><strong>"._("Dynamic connectivity tests")."</strong>
303
            <table><tr>
304
            <td class='icon_td'><img src='".$this->stateIcons[$this->globalLevelDynamic]."' id='main_dynamic_ico' class='icon'></td><td id='main_dynamic_result'>".
305
            $this->globalInfo[$this->globalLevelDynamic].' '._("See the appropriate tab for details.").'</td></tr></table>';
306
        }
307
        $out[] = '</fieldset>';
308
        return join('', $out);
309
    }
310
    
311
    public function printStatic()
312
    {
313
        $out = [];
314
        $out[] = '<fieldset class="option_container" id="static_tests">
315
                  <legend><strong>';
316
        $out[] = _("STATIC connectivity tests");
317
        $out[] = '</strong> </legend>';
318
        $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.");
319
        $out[] = '<p>';
320
        foreach ($this->allReachabilityResults['udp'] as $udp) {
321
            $hostindex = $udp->hostindex;
322
            $result = $udp->result[0];
323
            $out[] = '<hr>';
324
            $out[] = sprintf(_("Testing from: <strong>%s"), \config\Diagnostics::RADIUSTESTS['UDP-hosts'][$hostindex]['display_name']).'</strong>';
325
            $out[] = '<ul style="list-style-type: none;"><li>';
326
            $out[] = "<table id='results$hostindex'  style='width:100%' class='udp_results'>
327
<tr>
328
<td class='icon_td'><img src='".$this->stateIcons[$result->level]."' id='src".$hostindex."_img'></td>
329
<td id='src$hostindex' colspan=2>
330
";
331
            $out[] = '<strong>'.($result->server ? $result->server : _("Connected to undetermined server")).'</strong><br/>'.sprintf (_("elapsed time: %sms."), $result->time_millisec).'<div>'.$result->message.'</div>';
332
                    
333
            if ($result->level > \core\common\Entity::L_OK && property_exists($result, 'cert_oddities')) {
334
                foreach ($result->cert_oddities as $oddities) {
335
                    $out[] = '<tr class="results_tr"><td>&nbsp;</td><td class="icon_td"><img src="'.$this->stateIcons[$oddities->level].'"></td><td>'.$oddities->message.'</td></tr>';
336
                }
337
            }
338
            $more = '';
339
            if ($result->server_cert) {
340
                $more .= '<div class="more">';
341
                $certdesc = '<br>'.$this->certFields['title'].'<ul>';
342
                foreach ($result->server_cert as $sckey => $sc) {
343
                    if (array_key_exists($sckey, $this->certFields)) {
344
                        $certdesc .= '<li>'.$this->certFields[$sckey].' '.$sc;
345
                    }
346
                }
347
                if ($result->server_cert->extensions) {
348
                    $certdesc .= '<li>' . _('Extensions') . '<ul>';
349
                    foreach ($result->server_cert->extensions as $ekey => $eval) {
350
                        $certdesc .= '<li>' . $ekey . ': ' . $eval;
351
                    }
352
                    $certdesc .= '</ul>';
353
                }
354
                $certdesc .= '</ul>';
355
                $more .= '<span class="morecontent"><span>'.$certdesc.
356
                        '</span><a href="" class="morelink">'._("show server certificate details").'&raquo;</a></span></div>';
357
            }     
358
            if ($more != '' ) {
359
                $out[] = '<tr><td>&nbsp;</td><td colspan="2">'.$more.'</td></tr>';
360
            }
361
            $out[] = "</table></ul>";
362
        }
363
        $out[] = '</fieldset>';
364
        return join('', $out);            
365
    }
366
    
367
    private function collectCAPath()
368
    {
369
        $capathtest = [];
370
        $capathtest[] = '<p><strong>'._("Checking server handshake...")."</strong><p>";
371
        foreach ($this->allReachabilityResults['capath'] as $capath) {
372
            $hostindex = $capath->hostindex;
373
            $level = $capath->level;
374
            if ($capath->level == \core\common\Entity::L_OK && $capath->result == \core\diag\RADIUSTests::RETVAL_INVALID) {
375
                $level = \core\common\Entity::L_WARN;
376
            }
377
            $capathtest[] = '<p><strong>'.$this->hostMap[$capath->IP].'</strong> ('.$capath->name.') ';
378
            $prots = [];
379
            if (isset($this->protocolsMap[$capath->IP]) && $this->protocolsMap[$capath->IP] != '') {
380
                $prots = explode(';', $this->protocolsMap[$capath->IP]);
381
                if (!empty($prots)) {
382
                    $capathtest[] = ' ' . _("supported TLS protocols: ");
383
                    $capathtest[] = implode(', ', $prots);
384
                    if (!in_array("TLS1.3", $prots)) {
385
                        $capathtest[] =  ' ' . '<font color="red">' . _("not supported: ") . 'TLS1.3</font>';
386
                    }
387
                }
388
            }
389
            $capathtest[] = '<ul style="list-style-type: none;" class="caresult"><li>';
390
            $capathtest[] = "<table id='caresults$hostindex'  style='width:100%'>
391
<tr>
392
<td class='icon_td'><img src='";
393
            $capathtest[] = $this->stateIcons[$level]."' id='srcca".$hostindex."_img'></td>
394
<td id='srcca$hostindex'>";
395
            $more = '';
396
            if ($capath->certdata && $capath->certdata->subject != '') {
397
                $more .= '<div class="more">';
398
                $certdesc = '<br>'.$this->certFields['title'].'<ul>';
399
                if ($capath->certdata->subject) {
400
                    $certdesc .= '<li>'.$this->certFields['subject'].' '.$capath->certdata->subject;
401
                }
402
                if ($capath->certdata->issuer) {
403
                    $certdesc .= '<li>'.$this->certFields['issuer'].' '.$capath->certdata->issuer;
404
                }
405
                if ($capath->certdata->validTo) {
406
                    $certdesc .= '<li>'.$this->certFields['validTo'].' '.
407
                            date_create_from_format('ymdGis', 
408
                                    substr($capath->certdata->validTo, 0, -1))->format('Y-m-d H:i:s'). ' UTC';
409
                }
410
                if ($capath->certdata->extensions) {
411
                    if ($capath->certdata->extensions->subjectaltname) {                     
412
                        $certdesc .= '<li>'.$this->certFields['subjectaltname'].' '.$capath->certdata->extensions->subjectaltname;
413
                    }
414
                }
415
                if ($capath->certdata->extensions->policies) {
416
                    $certdesc .= '<li>'.$this->certFields['policies'].' '.$capath->certdata->extensions->policies;
417
                }
418
                if ($capath->certdata->extensions->crldistributionpoints) {
419
                    $certdesc .= '<li>'.$this->certFields['crldistributionpoints'].' '.$capath->certdata->extensions->crldistributionpoints;
420
                }
421
                if ($capath->certdata->extensions->authorityinfoaccess) {
422
                    $certdesc .= '<li>'.$this->certFields['authorityinfoaccess'].' '.$capath->certdata->extensions->authorityinfoaccess;
423
                }
424
                            
425
                $certdesc .= '</ul>';
426
                $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...
427
                        '</span>&nbsp;&nbsp;<a href="" class="morelink">'._("more").'&raquo;</a></span></td></tr>';
428
            } else {
429
                $certdesc = '<br>';
430
            }
431
            $capathtest[] = '<div>'.($capath->message!='' ? $capath->message : _('Test failed')).'</div>'.$more;
432
            $capathtest[] = '</td>
433
</tr>
434
</table>';
435
            $capathtest[] = '</li></ul>';
436
        }
437
        return $capathtest;
438
    }
439
440
    private function collectClients()
441
    {
442
        $clientstest = [];
443
        foreach ($this->allReachabilityResults['clients'] as $clients) {
444
            if ($clients->result == RADIUSTests::RETVAL_SKIPPED) {
445
                continue;
446
            }
447
            $hostindex = $clients->hostindex; 
448
            $clientstest[] = '<p><strong>'.$this->hostMap[$clients->IP].'</strong></p>';
449
            $clientstest[] = "<span id='clientresults$hostindex'>";
450
            $clientstest[] = '<p></p>';
451
            if ($this->globalLevelDynamic != \core\common\Entity::L_ERROR) {
452
                if (property_exists($clients, 'ca')) {
453
                    $clientstest[] = '<ol>';
454
                    foreach ($clients->ca as $ca) {                     
455
                        $srefused = 0;
456
                        $cliinfo = '';
457
                        $cliinfo .= '<li>'._('Client certificate').' <b>'.$ca->clientcertinfo->from.
458
                                    '</b>'.', '.$ca->clientcertinfo->message .
459
                                    '<br> (CA: '.$ca->clientcertinfo->issuer.')<ul>';
460
                        foreach ($ca->certificate as $certificate) {
461
                            if ($certificate->returncode == \core\diag\RADIUSTests::RETVAL_CONNECTION_REFUSED) {
462
                                $srefused = 1;
463
                            }
464
                        }
465
                        if ($srefused == 0) {
466
                            foreach ($ca->certificate as $certificate) {                           
467
                                $cliinfo .= '<li><i>'.$certificate->message. 
468
                                            ', '._("expected result: ").$this->states[$certificate->expected].'</i>';
469
                                $cliinfo .= '<ul style="list-style-type: none;">';
470
                                if (property_exists($certificate, 'finalerror') && $certificate->finalerror == 2) {
471
                                        $cliinfo .= '<li>'._('this test was skipped - no appropriate client certificate').'</li></ul>';
472
                                        continue;
473
                                }
474
                                $level = $certificate->returncode;
475
                                if ($level < 0) {
476
                                    $level = \core\common\Entity::L_ERROR;
477
                                }
478
                                $add = '';
479
                                if ($certificate->expected == 'PASS') {
480
                                    if ($certificate->connected == 1) {
481
                                        $state = _("Server accepted this client certificate");
482
                                    } else {
483
                                        if (property_exists($certificate, 'reason') && $certificate->reason == \core\diag\RADIUSTests::CERTPROB_UNKNOWN_CA) {
484
                                            $add = '<br>'._('You should update your list of accredited CAs').
485
                                                            ' <a href=\"'.\config\Diagnostics::RADIUSTESTS['accreditedCAsURL'].'\">'.
486
                                                            _('Get it from here.').'</a>';
487
                                        }
488
                                        $state = _('Server did not accept this client certificate - reason').': '.
489
                                                    $certificate->resultcomment;
490
                                    }
491
                                } else {
492
                                    if ($certificate->connected == 1) {
493
                                        $level = \core\common\Entity::L_WARN;
494
                                        $state = _('Server accepted this client certificate, but should not have');
495
                                    } else {
496
                                        $level = \core\common\Entity::L_OK;
497
                                        $state = _('Server did not accept this client certificate').': '.$certificate->resultcomment;
498
                                    }
499
                                }
500
                                $cliinfo .= '<li><table><tbody><tr><td class="icon_td"><img class="icon" src="'.$this->stateIcons[$level].'" style="width: 24px;"></td><td>'.$state;
501
                                $cliinfo .= ' ('.sprintf(_('elapsed time: %sms.'), $certificate->time_millisec).'&nbsp;) '.$add.'</td></tr>';
502
                                $cliinfo .= '</tbody></table></ul></li>';
503
                                if (property_exists($certificate, 'finalerror')) {
504
                                    if ($certificate->finalerror == 1) {
505
                                        $cliinfo .= '<li>'._('Rest of tests for this CA skipped').'</li>';
506
                                    }
507
                                }
508
                            }
509
                            $cliinfo .= '</ul>';
510
                        }
511
                                    
512
                        if ($srefused > 0) {
513
                            $cliinfo = _('Connection refused');
514
                            $clientstest[] = "<table><tr><td class='icon_td' id='srcclient".$hostindex."_img'><img src='".$this->stateIcons[\core\common\Entity::L_ERROR]."'></td>".
515
                                        "<td id='srcclient$hostindex'><p>$cliinfo</p></td></tr></table>";
516
                        } else {
517
                            $clientstest[] = "<p>$cliinfo</p>";
518
                        }
519
                    }
520
                    
521
                } else {
522
                    $cliinfo = _('Test failed');
523
                    $clientstest[] = "<table><tr><td class='icon_td' id='srcclient".$hostindex."_img'><img src='".
524
                                    $this->stateIcons[\core\common\Entity::L_WARN]."'></td>" .
525
                                    "<td id='srcclient$hostindex'>$cliinfo</td></tr></table>";
526
                }
527
            } else {
528
                $clientstest[] = '<ul style="list-style-type: none;" class="clientsresult"><li>';
529
                $clientstest[] = "<table id='clientsresults$hostindex'  style='width:100%'>
530
<tr>
531
<td class='icon_td'><img src='";
532
                $clientstest[] = $this->stateIcons[\core\common\Entity::L_ERROR]."' id='srcclients".$hostindex."_img'></td>
533
<td id='srcclient$hostindex'>";
534
                $clientstest[] = _("These tests were skipped because of previous errors.").'</td></tr></table></ul>';
535
            }
536
            $clientstest[] = '</ol><p></p>';
537
        }
538
        return $clientstest;
539
    }
540
    
541
    public function printDynamic()
542
    {
543
        $out = [];
544
        $out[] = "<div id='dynamic_tests'><fieldset class='option_container'>
545
            <legend><strong>"._("DYNAMIC connectivity tests")."</strong></legend>";
546
        
547
        if (count($this->rfc7585suite->NAPTR_hostname_records) > 0) {    
548
            $capathtest = $this->collectCAPath();
549
            $clientstest = $this->collectClients();
550
            $out[] = '<div style="align:right;">';            
551
            $out[] = '<div style="align:right; display: ';
552
            if ($this->globalLevelDynamic == \core\common\Entity::L_OK && !$this->areFailed) {
553
                $out[] = 'none';
554
            }
555
            $out[] = ';" id="dynamic_result_fail"><b>'._("Some errors were found during the tests, see below").'</b></div>';
556
            $out[] = '<div style="align:right; display: ';
557
            if ($this->globalLevelDynamic != \core\common\Entity::L_OK || $this->areFailed) {
558
                $out[] = 'none';
559
            }
560
            $out[] = '" id="dynamic_result_pass"><b>'.
561
                                _("All tests passed, congratulations!").'</b></div>'.
562
                                '<div style="align:left;"><a href="" class="moreall"><i>'._('Show detailed information for all tests').'&raquo;</i></a></div>';
563
            $out[] = join('', $capathtest);
564
            if (!empty($clientstest)) {
565
                $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>';
566
                $out[] = join('', $clientstest);
567
                $out[] = '</span>';
568
            }
569
            $out[] = '</div>';
570
        }
571
        $out[] = "</fieldset></div></div>";
572
        return join('', $out);
573
    }
574
    
575
}
576