Completed
Push — master ( e4f3ec...362cb3 )
by Tomasz
04:34
created

Device_W8_10::prepareEapConfig()   F

Complexity

Conditions 36
Paths 288

Size

Total Lines 240
Code Lines 112

Duplication

Lines 240
Ratio 100 %

Importance

Changes 0
Metric Value
cc 36
eloc 112
nc 288
nop 1
dl 240
loc 240
rs 3.3842
c 0
b 0
f 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
 * Copyright 2011-2017 DANTE Ltd. and GÉANT on behalf of the GN3, GN3+, GN4-1 
6
 * and GN4-2 consortia
7
 *
8
 * License: see the web/copyright.php file in the file structure
9
 * ******************************************************************************
10
 */
11
12
/**
13
 * This file creates MS Windows 8 installers
14
 * It supports EAP-TLS, TTLS, PEAP and EAP-pwd
15
 * @author Tomasz Wolniewicz <[email protected]>
16
 *
17
 * @package ModuleWriting
18
 */
19
20
namespace devices\ms;
21
use \Exception;
22
23
/**
24
 * 
25
 * @author Tomasz Wolniewicz <[email protected]>
26
 * @package ModuleWriting
27
 */
28
 class Device_W8_10 extends WindowsCommon {
29
    final public function __construct() {
30
        parent::__construct();
31
        $this->setSupportedEapMethods([\core\common\EAP::EAPTYPE_TLS, \core\common\EAP::EAPTYPE_PEAP_MSCHAP2, \core\common\EAP::EAPTYPE_TTLS_PAP, \core\common\EAP::EAPTYPE_TTLS_MSCHAP2, \core\common\EAP::EAPTYPE_PWD, \core\common\EAP::EAPTYPE_SILVERBULLET]);
32
        $this->specialities['internal:use_anon_outer'][serialize(\core\common\EAP::EAPTYPE_PEAP_MSCHAP2)] = _("Anonymous identities do not use the realm as specified in the profile - it is derived from the suffix of the user's username input instead.");
33
    }
34 View Code Duplication
    public function writeInstaller() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
        $dom = textdomain(NULL);
36
        textdomain("devices");
37
        // create certificate files and save their names in $caFiles arrary
38
        $caFiles = $this->saveCertificateFiles('der');
39
        $allSSID = $this->attributes['internal:SSID'];
40
        $delSSIDs = $this->attributes['internal:remove_SSID'];
41
        $this->prepareInstallerLang();
42
        $setWired = isset($this->attributes['media:wired'][0]) && $this->attributes['media:wired'][0] == 'on' ? 1 : 0;
43
//   create a list of profiles to be deleted after installation
44
        $delProfiles = [];
45
        foreach ($delSSIDs as $ssid => $cipher) {
46
            if ($cipher == 'DEL') {
47
                $delProfiles[] = $ssid;
48
            }
49
            if ($cipher == 'TKIP') {
50
                $delProfiles[] = $ssid . ' (TKIP)';
51
            }
52
        }
53
54
55
        if (in_array($this->selectedEap, [\core\common\EAP::EAPTYPE_TLS,
56
                    \core\common\EAP::EAPTYPE_PEAP_MSCHAP2,
57
                    \core\common\EAP::EAPTYPE_TTLS_PAP,
58
                    \core\common\EAP::EAPTYPE_TTLS_MSCHAP2,
59
                    \core\common\EAP::EAPTYPE_PWD,
60
                    \core\common\EAP::EAPTYPE_SILVERBULLET])) {
61
            $windowsProfile = [];
62
            $eapConfig = $this->prepareEapConfig($this->attributes);
63
            $iterator = 0;
64
            foreach ($allSSID as $ssid => $cipher) {
65
                if ($cipher == 'TKIP') {
66
                    $windowsProfile[$iterator] = $this->writeWLANprofile($ssid . ' (TKIP)', $ssid, 'WPA', 'TKIP', $eapConfig, $iterator);
67
                    $iterator++;
68
                }
69
                $windowsProfile[$iterator] = $this->writeWLANprofile($ssid, $ssid, 'WPA2', 'AES', $eapConfig, $iterator);
70
                $iterator++;
71
            }
72
            if ($setWired) {
73
                $this->writeLANprofile($eapConfig);
74
            }
75
        } else {
76
            print("  this EAP type is not handled yet.\n");
77
            return;
78
        }
79
        $this->loggerInstance->debug(4, "windowsProfile");
80
        $this->loggerInstance->debug(4, print_r($windowsProfile, true));
81
82
        $this->writeProfilesNSH($windowsProfile, $caFiles);
83
        $this->writeAdditionalDeletes($delProfiles);
84
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
85
            $this->writeClientP12File();
86
        }
87
        $this->copyFiles($this->selectedEap);
88
        $fedLogo = $this->attributes['fed:logo_file'] ?? NULL;
89
        $idpLogo = $this->attributes['internal:logo_file'] ?? NULL;
90
        $this->combineLogo($idpLogo, $fedLogo);
91
        $this->writeMainNSH($this->selectedEap, $this->attributes);
92
        $this->compileNSIS();
93
        $installerPath = $this->signInstaller();
94
95
        textdomain($dom);
96
        return($installerPath);
97
    }
98
    
99 View Code Duplication
    private function prepareEapConfig($attr) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
        $outerUser = '';
101
        $outerId = '';
102
        $eap = $this->selectedEap;
103
        $wExt = '';
104
        // there is only one caller to this function, and it will always call
105
        // with exactly one of exactly the EAP types below. Let's assert() that
106
        // rather than returning void, otherwise this is a condition that needs
107
        // to be caught later on.
108
        assert(in_array($eap, [\core\common\EAP::EAPTYPE_TLS,
109
            \core\common\EAP::EAPTYPE_PEAP_MSCHAP2,
110
            \core\common\EAP::EAPTYPE_PWD,
111
            \core\common\EAP::EAPTYPE_TTLS_PAP,
112
            \core\common\EAP::EAPTYPE_TTLS_MSCHAP2,
113
            \core\common\EAP::EAPTYPE_SILVERBULLET]), new Exception("prepareEapConfig called for an EAP type it cannot handle!"));
114
115
        $useAnon = $attr['internal:use_anon_outer'] [0];
116
        if ($useAnon) {
117
            $outerUser = $attr['internal:anon_local_value'][0];
118
            $outerId = $outerUser . '@' . $attr['internal:realm'][0];
119
        }
120
//   $servers = preg_quote(implode(';',$attr['eap:server_name']));
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
121
        $servers = implode(';', $attr['eap:server_name']);
122
        $caArray = $attr['internal:CAs'][0];
123
        $authorId = "0";
124
        if ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP || $eap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) {
125
            if ($this->useGeantLink) {
126
                $authorId = "67532";
127
                $servers = implode('</ServerName><ServerName>', $attr['eap:server_name']);
128
            } else {
129
                $authorId = "311";
130
            }
131
        }
132
133
        $profileFileCont = '<EAPConfig><EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
134
<EapMethod>
135
';
136
137
        $profileFileCont .= '<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">' .
138
                $this->selectedEap["OUTER"] . '</Type>
139
<VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId>
140
<VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType>
141
<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">' . $authorId . '</AuthorId>
142
</EapMethod>
143
';
144
        if ($eap == \core\common\EAP::EAPTYPE_TLS || $eap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
145
            $profileFileCont .= '
146
147
<Config xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1" 
148
  xmlns:eapTls="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1">
149
<baseEap:Eap>
150
<baseEap:Type>13</baseEap:Type> 
151
<eapTls:EapType>
152
<eapTls:CredentialsSource>
153
<eapTls:CertificateStore />
154
</eapTls:CredentialsSource>
155
<eapTls:ServerValidation>
156
<eapTls:DisableUserPromptForServerValidation>true</eapTls:DisableUserPromptForServerValidation>
157
<eapTls:ServerNames>' . $servers . '</eapTls:ServerNames>';
158
            if ($caArray) {
159
                foreach ($caArray as $certAuthority) {
160
                    if ($certAuthority['root']) {
161
                        $profileFileCont .= "<eapTls:TrustedRootCA>" . $certAuthority['sha1'] . "</eapTls:TrustedRootCA>\n";
162
                    }
163
                }
164
            }
165
            $profileFileCont .= '</eapTls:ServerValidation>
166
';
167
            if (isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') {
168
                $profileFileCont .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>';
169
                $this->tlsOtherUsername = 1;
170
            } else {
171
                $profileFileCont .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>';
172
            }
173
            $profileFileCont .= '
174
</eapTls:EapType>
175
</baseEap:Eap>
176
</Config>
177
';
178
        } elseif ($eap == \core\common\EAP::EAPTYPE_PEAP_MSCHAP2) {
179
            if (isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') {
180
                $nea = 'true';
181
            } else {
182
                $nea = 'false';
183
            }
184
            $wExt = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
185
<Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1">
186
<Type>25</Type>
187
<EapType xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1">
188
<ServerValidation>
189
<DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation>
190
<ServerNames>' . $servers . '</ServerNames>';
191
            if ($caArray) {
192
                foreach ($caArray as $certAuthority) {
193
                    if ($certAuthority['root']) {
194
                        $wExt .= "<TrustedRootCA>" . $certAuthority['sha1'] . "</TrustedRootCA>\n";
195
                    }
196
                }
197
            }
198
            $wExt .= '</ServerValidation>
199
<FastReconnect>true</FastReconnect> 
200
<InnerEapOptional>false</InnerEapOptional>
201
<Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1">
202
<Type>26</Type>
203
<EapType xmlns="http://www.microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1">
204
<UseWinLogonCredentials>false</UseWinLogonCredentials> 
205
</EapType>
206
</Eap>
207
<EnableQuarantineChecks>' . $nea . '</EnableQuarantineChecks>
208
<RequireCryptoBinding>false</RequireCryptoBinding>
209
';
210
            if ($useAnon == 1) {
211
                $wExt .= '<PeapExtensions>
212
<IdentityPrivacy xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2">
213
<EnableIdentityPrivacy>true</EnableIdentityPrivacy>
214
';
215
                if ($outerUser) {
216
                    $wExt .= '<AnonymousUserName>' . $outerUser . '</AnonymousUserName>
217
                ';
218
                } else {
219
                    $wExt .= '<AnonymousUserName/>
220
                ';
221
                }
222
                $wExt .= '</IdentityPrivacy>
223
</PeapExtensions>
224
';
225
            }
226
            $wExt .= '</EapType>
227
</Eap>
228
</Config>
229
';
230
        } elseif ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP || $eap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) {
231
            if ($this->useGeantLink) {
232
                $innerMethod = 'MSCHAPv2';
233
                if ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP) {
234
                    $innerMethod = 'PAP';
235
                }
236
                $profileFileCont .= '
237
<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
238
<EAPIdentityProviderList xmlns="urn:ietf:params:xml:ns:yang:ietf-eap-metadata">
239
<EAPIdentityProvider ID="' . $this->deviceUUID . '" namespace="urn:UUID">
240
241
<ProviderInfo>
242
<DisplayName>' . $this->translateString($attr['general:instname'][0], $this->codePage) . '</DisplayName>
243
</ProviderInfo>
244
<AuthenticationMethods>
245
<AuthenticationMethod>
246
<EAPMethod>21</EAPMethod>
247
<ClientSideCredential>
248
<allow-save>true</allow-save>
249
';
250
                if ($useAnon == 1) {
251
                    if ($outerUser == '') {
252
                        $profileFileCont .= '<AnonymousIdentity>@</AnonymousIdentity>';
253
                    } else {
254
                        $profileFileCont .= '<AnonymousIdentity>' . $outerId . '</AnonymousIdentity>';
255
                    }
256
                }
257
                $profileFileCont .= '</ClientSideCredential>
258
<ServerSideCredential>
259
';
260
261
                foreach ($caArray as $ca) {
262
                    $profileFileCont .= '<CA><format>PEM</format><cert-data>';
263
                    $profileFileCont .= base64_encode($ca['der']);
264
                    $profileFileCont .= '</cert-data></CA>
265
';
266
                }
267
                $profileFileCont .= "<ServerName>$servers</ServerName>\n";
268
269
                $profileFileCont .= '
270
</ServerSideCredential>
271
<InnerAuthenticationMethod>
272
<NonEAPAuthMethod>' . $innerMethod . '</NonEAPAuthMethod>
273
</InnerAuthenticationMethod>
274
<VendorSpecific>
275
<SessionResumption>false</SessionResumption>
276
</VendorSpecific>
277
</AuthenticationMethod>
278
</AuthenticationMethods>
279
</EAPIdentityProvider>
280
</EAPIdentityProviderList>
281
</Config>
282
';
283
            } else {
284
                $wExt = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
285
<EapTtls xmlns="http://www.microsoft.com/provisioning/EapTtlsConnectionPropertiesV1">
286
<ServerValidation>
287
<ServerNames>' . $servers . '</ServerNames> ';
288
                if ($caArray) {
289
                    foreach ($caArray as $certAuthority) {
290
                        if ($certAuthority['root']) {
291
                            $wExt .= "<TrustedRootCAHash>" . chunk_split($certAuthority['sha1'], 2, ' ') . "</TrustedRootCAHash>\n";
292
                        }
293
                    }
294
                }
295
                $wExt .= '<DisablePrompt>true</DisablePrompt> 
296
</ServerValidation>
297
<Phase2Authentication>
298
';
299
                if ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP) {
300
                    $wExt .= '<PAPAuthentication /> ';
301
                }
302
                if ($eap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) {
303
                    $wExt .= '<MSCHAPv2Authentication>
304
<UseWinlogonCredentials>false</UseWinlogonCredentials>
305
</MSCHAPv2Authentication>
306
';
307
                }
308
                $wExt .= '</Phase2Authentication>
309
<Phase1Identity>
310
';
311
                if ($useAnon == 1) {
312
                    $wExt .= '<IdentityPrivacy>true</IdentityPrivacy> 
313
';
314
                    if (isset($outerId) && $outerId) {
315
                        $wExt .= '<AnonymousIdentity>' . $outerId . '</AnonymousIdentity>
316
                ';
317
                    } else {
318
                        $wExt .= '<AnonymousIdentity/>
319
                ';
320
                    }
321
                } else {
322
                    $wExt .= '<IdentityPrivacy>false</IdentityPrivacy>
323
';
324
                }
325
                $wExt .= '</Phase1Identity>
326
</EapTtls>
327
</Config>
328
';
329
            }
330
        } elseif ($eap == \core\common\EAP::EAPTYPE_PWD) {
331
            $profileFileCont .= '<ConfigBlob></ConfigBlob>';
332
        }
333
334
        $profileFileContEnd = '</EapHostConfig></EAPConfig>';
335
        $returnArray = [];
336
        $returnArray['win'] = $profileFileCont . $wExt . $profileFileContEnd;
337
        return $returnArray;
338
    }
339
    
340
    /**
341
     * produce PEAP, TLS and TTLS configuration files for Windows 8
342
     * 
343
     * @param string $wlanProfileName
344
     * @param string $ssid
345
     * @param string $auth can be one of "WPA", "WPA2"
346
     * @param string $encryption can be one of: "TKIP", "AES"
347
     * @param array $eapConfig XML configuration block with EAP config data
348
     * @param int $profileNumber counter, which profile number is this
349
     * @return string
350
     */
351
    private function writeWLANprofile($wlanProfileName, $ssid, $auth, $encryption, $eapConfig, $profileNumber) {
352
        $profileFileCont = '<?xml version="1.0"?>
353
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
354
<name>' . $wlanProfileName . '</name>
355
<SSIDConfig>
356
<SSID>
357
<name>' . $ssid . '</name>
358
</SSID>
359
<nonBroadcast>true</nonBroadcast>
360
</SSIDConfig>
361
<connectionType>ESS</connectionType>
362
<connectionMode>auto</connectionMode>
363
<autoSwitch>false</autoSwitch>
364
<MSM>
365
<security>
366
<authEncryption>
367
<authentication>' . $auth . '</authentication>
368
<encryption>' . $encryption . '</encryption>
369
<useOneX>true</useOneX>
370
</authEncryption>
371
';
372
        if ($auth == 'WPA2') {
373
            $profileFileCont .= '<PMKCacheMode>enabled</PMKCacheMode> 
374
<PMKCacheTTL>720</PMKCacheTTL> 
375
<PMKCacheSize>128</PMKCacheSize> 
376
<preAuthMode>disabled</preAuthMode> 
377
        ';
378
        }
379
        $profileFileCont .= '<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
380
<cacheUserData>true</cacheUserData>
381
<authMode>user</authMode>
382
';
383
384
        $closing = '
385
</OneX>
386
</security>
387
</MSM>
388
</WLANProfile>
389
';
390
391
        if (!is_dir('w8')) {
392
            mkdir('w8');
393
        }
394
        $xmlFname = "w8/wlan_prof-$profileNumber.xml";
395
        file_put_contents($xmlFname, $profileFileCont . $eapConfig['win'] . $closing);
396
        $this->loggerInstance->debug(2, "Installer has been written into directory $this->FPATH\n");
397
        $this->loggerInstance->debug(4, "WWWWLAN_Profile:$wlanProfileName:$encryption\n");
398
        return("\"$wlanProfileName\" \"$encryption\"");
399
    }
400
    
401
    private function writeLANprofile($eapConfig) {
402
        $profileFileCont = '<?xml version="1.0"?>
403
<LANProfile xmlns="http://www.microsoft.com/networking/LAN/profile/v1">
404
<MSM>
405
<security>
406
<OneXEnforced>false</OneXEnforced>
407
<OneXEnabled>true</OneXEnabled>
408
<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
409
<cacheUserData>true</cacheUserData>
410
<authMode>user</authMode>
411
';
412
        $closing = '
413
</OneX>
414
</security>
415
</MSM>
416
</LANProfile>
417
';
418
419
        if (!is_dir('w8')) {
420
            mkdir('w8');
421
        }
422
        $xmlFname = "w8/lan_prof.xml";
423
        file_put_contents($xmlFname, $profileFileCont . $eapConfig['win'] . $closing);
424
        $this->loggerInstance->debug(2, "Installer has been written into directory $this->FPATH\n");
425
    }
426
427 View Code Duplication
    private function writeProfilesNSH($wlanProfiles, $caArray) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
428
        $this->loggerInstance->debug(4, "writeProfilesNSH");
429
        $this->loggerInstance->debug(4, $wlanProfiles);
430
        $fcontentsProfile = '';
431
        foreach ($wlanProfiles as $wlanProfile) {
432
            $fcontentsProfile .= "!insertmacro define_wlan_profile $wlanProfile\n";
433
        }
434
435
        file_put_contents('profiles.nsh', $fcontentsProfile);        
436
437
        $fcontentsCerts = '';
438
        $fileHandleCerts = fopen('certs.nsh', 'w');
439
        if ($fileHandleCerts === FALSE) {
440
            throw new Exception("Unable to open new certs.nsh file for writing CAs.");
441
        }
442
        if ($caArray) {
443
            foreach ($caArray as $certAuthority) {
444
                $store = $certAuthority['root'] ? "root" : "ca";
445
                $fcontentsCerts .= '!insertmacro install_ca_cert "' . $certAuthority['file'] . '" "' . $certAuthority['sha1'] . '" "' . $store . "\"\n";
446
            }
447
            fwrite($fileHandleCerts, $fcontentsCerts);
448
        }
449
        fclose($fileHandleCerts);
450
    }
451
    
452
    private function writeMainNSH($eap, $attr) {
453
        $this->loggerInstance->debug(4, "writeMainNSH");
454
        $this->loggerInstance->debug(4, $attr);
455
        $this->loggerInstance->debug(4, "Device_id = " . $this->device_id . "\n");
456
        if ($this->device_id == 'w10') {
457
            $fcontents = "!define W10\n";
458
        }
459
        $fcontents .= "!define W8\n";
0 ignored issues
show
Bug introduced by
The variable $fcontents does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
460
        if (CONFIG_CONFASSISTANT['NSIS_VERSION'] >= 3) {
461
            $fcontents .= "Unicode true\n";
462
        }
463
464
        $eapOptions = [
465
            \core\common\EAP::PEAP => ['str' => 'PEAP', 'exec' => 'user'],
466
            \core\common\EAP::TLS => ['str' => 'TLS', 'exec' => 'user'],
467
            \core\common\EAP::TTLS => ['str' => 'TTLS', 'exec' => 'user'],
468
            \core\common\EAP::PWD => ['str' => 'PWD', 'exec' => 'user'],
469
        ];
470 View Code Duplication
        if (isset($this->options['args']) && $this->options['args'] == 'gl') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
471
            $eapOptions[\core\common\EAP::TTLS]['str'] = 'GEANTLink';
472
        }
473
474
// Uncomment the line below if you want this module to run under XP (only displaying a warning)
475
// $fcontents .= "!define ALLOW_XP\n";
476
// Uncomment the line below if you want this module to produce debugging messages on the client
477
// $fcontents .= "!define DEBUG_CAT\n";
478
        if ($this->tlsOtherUsername == 1) {
479
            $fcontents .= "!define PFX_USERNAME\n";
480
        }
481
        $execLevel = $eapOptions[$eap["OUTER"]]['exec'];
482
        $eapStr = $eapOptions[$eap["OUTER"]]['str'];
483
        if ($eap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
484
            $fcontents .= "!define SILVERBULLET\n";
485
        }
486
        $fcontents .= '!define ' . $eapStr;
487
        $fcontents .= "\n" . '!define EXECLEVEL "' . $execLevel . '"';
488
        $fcontents .= $this->writeNsisDefines($eap, $attr);
489
        file_put_contents('main.nsh', $fcontents);
490
    }
491
492
    private function copyStandardNsi() {
493
        if (!$this->translateFile('eap_w8.inc', 'cat.NSI', $this->codePage)) {
494
            throw new Exception("Translating needed file eap_w8.inc failed!");
495
        }
496
    }
497
498 View Code Duplication
    private function copyFiles($eap) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
499
        $this->loggerInstance->debug(4, "copyFiles start\n");
500
        $this->copyBasicFiles();
501
        switch ($eap["OUTER"]) {
502
            case \core\common\EAP::TTLS:
503
                if (isset($this->options['args']) && $this->options['args'] == 'gl') {
504
                    $this->copyGeantLinkFiles();
505
                } else {
506
                    $this->copyStandardNsi();
507
                }
508
                break;
509
            case \core\common\EAP::PWD:
510
                $this->copyPwdFiles();
511
                break;
512
            default:
513
                $this->copyStandardNsi();
514
        }
515
        $this->loggerInstance->debug(4, "copyFiles end\n");
516
        return TRUE;
517
    }
518
519
    private $tlsOtherUsername = 0;
520
521
}
522
523