Passed
Push — master ( 17bffe...10bee5 )
by Stefan
06:13
created

Device_W8   F

Complexity

Total Complexity 69

Size/Duplication

Total Lines 417
Duplicated Lines 43.65 %

Importance

Changes 0
Metric Value
wmc 69
dl 182
loc 417
rs 2.8301
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
D writeInstaller() 0 58 16
B writeLANprofile() 24 24 2
B writeMainNSH() 0 31 4
D prepareEapConfig() 73 180 34
A writeWLANprofile() 50 50 3
A copyFiles() 9 14 3
B writeProfilesNSH() 23 23 6

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Device_W8 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Device_W8, and based on these observations, apply Extract Interface, too.

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 extends WindowsCommon {
29
30
    final public function __construct() {
31
        parent::__construct();
32
        $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]);
33
        $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.");
34
        $this->useGeantLink = 0;
35
    }
36
37
    public function writeInstaller() {
38
        $dom = textdomain(NULL);
39
        textdomain("devices");
40
        // create certificate files and save their names in $caFiles arrary
41
        $caFiles = $this->saveCertificateFiles('der');
42
        $allSSID = $this->attributes['internal:SSID'];
43
        $delSSIDs = $this->attributes['internal:remove_SSID'];
44
        $this->prepareInstallerLang();
45
        $setWired = isset($this->attributes['media:wired'][0]) && $this->attributes['media:wired'][0] == 'on' ? 1 : 0;
46
//   create a list of profiles to be deleted after installation
47
        $delProfiles = [];
48
        foreach ($delSSIDs as $ssid => $cipher) {
49
            if ($cipher == 'DEL') {
50
                $delProfiles[] = $ssid;
51
            }
52
            if ($cipher == 'TKIP') {
53
                $delProfiles[] = $ssid . ' (TKIP)';
54
            }
55
        }
56
57
58
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_TLS || $this->selectedEap == \core\common\EAP::EAPTYPE_PEAP_MSCHAP2 || $this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_PAP || $this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2 || $this->selectedEap == \core\common\EAP::EAPTYPE_PWD || $this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
59
            $windowsProfile = [];
60
            $eapConfig = $this->prepareEapConfig($this->attributes);
61
            $iterator = 0;
62
            foreach ($allSSID as $ssid => $cipher) {
63
                if ($cipher == 'TKIP') {
64
                    $windowsProfile[$iterator] = $this->writeWLANprofile($ssid . ' (TKIP)', $ssid, 'WPA', 'TKIP', $eapConfig, $iterator);
65
                    $iterator++;
66
                }
67
                $windowsProfile[$iterator] = $this->writeWLANprofile($ssid, $ssid, 'WPA2', 'AES', $eapConfig, $iterator);
68
                $iterator++;
69
            }
70
            if ($setWired) {
71
                $this->writeLANprofile($eapConfig);
72
            }
73
        } else {
74
            print("  this EAP type is not handled yet.\n");
75
            return;
76
        }
77
        $this->loggerInstance->debug(4, "windowsProfile");
78
        $this->loggerInstance->debug(4, print_r($windowsProfile, true));
79
80
        $this->writeProfilesNSH($windowsProfile, $caFiles, $setWired);
81
        $this->writeAdditionalDeletes($delProfiles);
82
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
83
            $this->writeClientP12File();
84
        }
85
        $this->copyFiles($this->selectedEap);
86
        $fedLogo = $this->attributes['fed:logo_file'] ?? NULL;
87
        $idpLogo = $this->attributes['internal:logo_file'] ?? NULL;
88
        $this->combineLogo($idpLogo, $fedLogo);
89
        $this->writeMainNSH($this->selectedEap, $this->attributes);
90
        $this->compileNSIS();
91
        $installerPath = $this->signInstaller();
92
93
        textdomain($dom);
94
        return($installerPath);
95
    }
96
97
    private function prepareEapConfig($attr) {
98
        $outerUser = '';
99
        $eap = $this->selectedEap;
100
        $w8Ext = '';
101
        if ($eap != \core\common\EAP::EAPTYPE_TLS && $eap != \core\common\EAP::EAPTYPE_PEAP_MSCHAP2 && $eap != \core\common\EAP::EAPTYPE_PWD && $eap != \core\common\EAP::EAPTYPE_TTLS_PAP && $eap != \core\common\EAP::EAPTYPE_TTLS_MSCHAP2 && $eap != \core\common\EAP::EAPTYPE_SILVERBULLET) {
102
            $this->loggerInstance->debug(2, "this method only allows TLS, PEAP, TTLS-PAP, TTLS-MSCHAPv2 or EAP-pwd");
103
            throw new Exception("this method only allows TLS, PEAP, TTLS-PAP, TTLS-MSCHAPv2 or EAP-pwd");
104
        }
105
        $useAnon = $attr['internal:use_anon_outer'] [0];
106 View Code Duplication
        if ($useAnon) {
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...
107
            $outerUser = $attr['internal:anon_local_value'][0];
108
            $outerId = $outerUser . '@' . $attr['internal:realm'][0];
109
        }
110
//   $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...
111
        $servers = implode(';', $attr['eap:server_name']);
112
113
        $caArray = $attr['internal:CAs'][0];
114
115
116
        $profileFileCont = '<EAPConfig><EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
117
<EapMethod>
118
';
119
120
        $profileFileCont .= '<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">' .
121
                $this->selectedEap["OUTER"] . '</Type>
122
<VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId>
123
<VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType>
124
';
125
        if ($eap == \core\common\EAP::EAPTYPE_TLS || $eap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
126
            $profileFileCont .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId>
127
</EapMethod>
128
';
129
            $profileFileCont .= '
130
131
<Config xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1" 
132
  xmlns:eapTls="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1">
133
<baseEap:Eap>
134
<baseEap:Type>13</baseEap:Type> 
135
<eapTls:EapType>
136
<eapTls:CredentialsSource>
137
<eapTls:CertificateStore />
138
</eapTls:CredentialsSource>
139
<eapTls:ServerValidation>
140
<eapTls:DisableUserPromptForServerValidation>true</eapTls:DisableUserPromptForServerValidation>
141
<eapTls:ServerNames>' . $servers . '</eapTls:ServerNames>';
142 View Code Duplication
            if ($caArray) {
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...
143
                foreach ($caArray as $certAuthority) {
144
                    if ($certAuthority['root']) {
145
                        $profileFileCont .= "<eapTls:TrustedRootCA>" . $certAuthority['sha1'] . "</eapTls:TrustedRootCA>\n";
146
                    }
147
                }
148
            }
149
            $profileFileCont .= '</eapTls:ServerValidation>
150
';
151 View Code Duplication
            if (isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') {
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...
152
                $profileFileCont .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>';
153
                $this->tlsOtherUsername = 1;
154
            } else {
155
                $profileFileCont .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>';
156
            }
157
            $profileFileCont .= '
158
</eapTls:EapType>
159
</baseEap:Eap>
160
</Config>
161
';
162 View Code Duplication
        } elseif ($eap == \core\common\EAP::EAPTYPE_PEAP_MSCHAP2) {
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...
163
            if (isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') {
164
                $nea = 'true';
165
            } else {
166
                $nea = 'false';
167
            }
168
            $profileFileCont .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId>
169
</EapMethod>
170
';
171
            $w8Ext = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
172
<Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1">
173
<Type>25</Type>
174
<EapType xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1">
175
<ServerValidation>
176
<DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation>
177
<ServerNames>' . $servers . '</ServerNames>';
178
            if ($caArray) {
179
                foreach ($caArray as $certAuthority) {
180
                    if ($certAuthority['root']) {
181
                        $w8Ext .= "<TrustedRootCA>" . $certAuthority['sha1'] . "</TrustedRootCA>\n";
182
                    }
183
                }
184
            }
185
            $w8Ext .= '</ServerValidation>
186
<FastReconnect>true</FastReconnect> 
187
<InnerEapOptional>false</InnerEapOptional> 
188
<Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1">
189
<Type>26</Type>
190
<EapType xmlns="http://www.microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1">
191
<UseWinLogonCredentials>false</UseWinLogonCredentials> 
192
</EapType>
193
</Eap>
194
<EnableQuarantineChecks>' . $nea . '</EnableQuarantineChecks>
195
<RequireCryptoBinding>false</RequireCryptoBinding>
196
';
197
            if ($useAnon == 1) {
198
                $w8Ext .= '<PeapExtensions>
199
<IdentityPrivacy xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2">
200
<EnableIdentityPrivacy>true</EnableIdentityPrivacy>
201
';
202
                if ($outerUser) {
203
                    $w8Ext .= '<AnonymousUserName>' . $outerUser . '</AnonymousUserName>
204
                ';
205
                } else {
206
                    $w8Ext .= '<AnonymousUserName/>
207
                ';
208
                }
209
                $w8Ext .= '</IdentityPrivacy>
210
</PeapExtensions>
211
';
212
            }
213
            $w8Ext .= '</EapType>
214
</Eap>
215
</Config>
216
';
217
        } elseif ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP || $eap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) {
218
            $profileFileCont .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">311</AuthorId>
219
</EapMethod>
220
';
221
            $w8Ext = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
222
<EapTtls xmlns="http://www.microsoft.com/provisioning/EapTtlsConnectionPropertiesV1">
223
<ServerValidation>
224
<ServerNames>' . $servers . '</ServerNames> ';
225
            if ($caArray) {
226
                foreach ($caArray as $certAuthority) {
227
                    if ($certAuthority['root']) {
228
                        $w8Ext .= "<TrustedRootCAHash>" . chunk_split($certAuthority['sha1'], 2, ' ') . "</TrustedRootCAHash>\n";
229
                    }
230
                }
231
            }
232
            $w8Ext .= '<DisablePrompt>true</DisablePrompt> 
233
</ServerValidation>
234
<Phase2Authentication>
235
';
236
            if ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP) {
237
                $w8Ext .= '<PAPAuthentication /> ';
238
            }
239
            if ($eap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) {
240
                $w8Ext .= '<MSCHAPv2Authentication>
241
<UseWinlogonCredentials>false</UseWinlogonCredentials>
242
</MSCHAPv2Authentication>
243
';
244
            }
245
            $w8Ext .= '</Phase2Authentication>
246
<Phase1Identity>
247
';
248
            if ($useAnon == 1) {
249
                $w8Ext .= '<IdentityPrivacy>true</IdentityPrivacy> 
250
';
251
                if (isset($outerId) && $outerId) {
252
                    $w8Ext .= '<AnonymousIdentity>' . $outerId . '</AnonymousIdentity>
253
                ';
254
                } else {
255
                    $w8Ext .= '<AnonymousIdentity/>
256
                ';
257
                }
258
            } else {
259
                $w8Ext .= '<IdentityPrivacy>false</IdentityPrivacy>
260
';
261
            }
262
            $w8Ext .= '</Phase1Identity>
263
</EapTtls>
264
</Config>
265
';
266
        } elseif ($eap == \core\common\EAP::EAPTYPE_PWD) {
267
            $profileFileCont .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId>
268
</EapMethod>
269
';
270
            $profileFileCont .= '<ConfigBlob></ConfigBlob>';
271
        }
272
273
        $profileFileContEnd = '</EapHostConfig></EAPConfig>';
274
        $returnArray = [];
275
        $returnArray['w8'] = $profileFileCont . $w8Ext . $profileFileContEnd;
276
        return $returnArray;
277
    }
278
279
    /**
280
     * produce PEAP, TLS and TTLS configuration files for Windows 8
281
     * 
282
     * @param string $wlanProfileName
283
     * @param string $ssid
284
     * @param string $auth can be one of "WPA", "WPA2"
285
     * @param string $encryption can be one of: "TKIP", "AES"
286
     * @param array $eapConfig XML configuration block with EAP config data
287
     * @param int $profileNumber counter, which profile number is this
288
     * @return string
289
     */
290 View Code Duplication
    private function writeWLANprofile($wlanProfileName, $ssid, $auth, $encryption, $eapConfig, $profileNumber) {
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...
291
        $profileFileCont = '<?xml version="1.0"?>
292
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
293
<name>' . $wlanProfileName . '</name>
294
<SSIDConfig>
295
<SSID>
296
<name>' . $ssid . '</name>
297
</SSID>
298
<nonBroadcast>true</nonBroadcast>
299
</SSIDConfig>
300
<connectionType>ESS</connectionType>
301
<connectionMode>auto</connectionMode>
302
<autoSwitch>false</autoSwitch>
303
<MSM>
304
<security>
305
<authEncryption>
306
<authentication>' . $auth . '</authentication>
307
<encryption>' . $encryption . '</encryption>
308
<useOneX>true</useOneX>
309
</authEncryption>
310
';
311
        if ($auth == 'WPA2') {
312
            $profileFileCont .= '<PMKCacheMode>enabled</PMKCacheMode> 
313
<PMKCacheTTL>720</PMKCacheTTL> 
314
<PMKCacheSize>128</PMKCacheSize> 
315
<preAuthMode>disabled</preAuthMode> 
316
        ';
317
        }
318
        $profileFileCont .= '<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
319
<cacheUserData>true</cacheUserData>
320
<authMode>user</authMode>
321
';
322
323
        $closing = '
324
</OneX>
325
</security>
326
</MSM>
327
</WLANProfile>
328
';
329
330
        if (!is_dir('w8')) {
331
            mkdir('w8');
332
        }
333
        $xmlFname = "w8/wlan_prof-$profileNumber.xml";
334
        
335
        file_put_contents($xmlFname, $profileFileCont . $eapConfig['w8'] . $closing);
336
        
337
        $this->loggerInstance->debug(2, "Installer has been written into directory $this->FPATH\n");
338
        $this->loggerInstance->debug(4, "WWWWLAN_Profile:$wlanProfileName:$encryption\n");
339
        return("\"$wlanProfileName\" \"$encryption\"");
340
    }
341
342 View Code Duplication
    private function writeLANprofile($eapConfig) {
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...
343
        $profileFileCont = '<?xml version="1.0"?>
344
<LANProfile xmlns="http://www.microsoft.com/networking/LAN/profile/v1">
345
<MSM>
346
<security>
347
<OneXEnforced>false</OneXEnforced>
348
<OneXEnabled>true</OneXEnabled>
349
<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
350
<cacheUserData>true</cacheUserData>
351
<authMode>user</authMode>
352
';
353
        $closing = '
354
</OneX>
355
</security>
356
</MSM>
357
</LANProfile>
358
';
359
360
        if (!is_dir('w8')) {
361
            mkdir('w8');
362
        }
363
        $xmlFname = "w8/lan_prof.xml";
364
        file_put_contents($xmlFname, $profileFileCont . $eapConfig['w8'] . $closing);
365
        $this->loggerInstance->debug(2, "Installer has been written into directory $this->FPATH\n");
366
    }
367
368
    private function writeMainNSH($eap, $attr) {
369
        $this->loggerInstance->debug(4, "writeMainNSH");
370
        $this->loggerInstance->debug(4, $attr);
371
        $fcontents = "!define W8\n";
372
        if (CONFIG_CONFASSISTANT['NSIS_VERSION'] >= 3) {
373
            $fcontents .= "Unicode true\n";
374
        }
375
        $eapOptions = [
376
            \core\common\EAP::PEAP => ['str' => 'PEAP', 'exec' => 'user'],
377
            \core\common\EAP::TLS => ['str' => 'TLS', 'exec' => 'user'],
378
            \core\common\EAP::TTLS => ['str' => 'TTLS', 'exec' => 'user'],
379
            \core\common\EAP::PWD => ['str' => 'PWD', 'exec' => 'user'],
380
        ];
381
382
// Uncomment the line below if you want this module to run under XP (only displaying a warning)
383
// $fcontents .= "!define ALLOW_XP\n";
384
// Uncomment the line below if you want this module to produce debugging messages on the client
385
// $fcontents .= "!define DEBUG_CAT\n";
386
        if ($this->tlsOtherUsername == 1) {
387
            $fcontents .= "!define PFX_USERNAME\n";
388
        }
389
        $execLevel = $eapOptions[$eap["OUTER"]]['exec'];
390
        $eapStr = $eapOptions[$eap["OUTER"]]['str'];
391
        if ($eap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
392
            $fcontents .= "!define SILVERBULLET\n";
393
        }
394
        $fcontents .= '!define ' . $eapStr;
395
        $fcontents .= "\n" . '!define EXECLEVEL "' . $execLevel . '"';
396
        $fcontents .= $this->writeNsisDefines($eap, $attr);
397
        
398
        file_put_contents('main.nsh', $fcontents);
399
    }
400
401 View Code Duplication
    private function writeProfilesNSH($wlanProfiles, $caArray, $wired = 0) {
0 ignored issues
show
Unused Code introduced by
The parameter $wired is not used and could be removed. ( Ignorable by Annotation )

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

401
    private function writeProfilesNSH($wlanProfiles, $caArray, /** @scrutinizer ignore-unused */ $wired = 0) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
402
        $this->loggerInstance->debug(4, "writeProfilesNSH");
403
        $this->loggerInstance->debug(4, $wlanProfiles);
404
        $fcontentsProfile = '';
405
        foreach ($wlanProfiles as $wlanProfile) {
406
            $fcontentsProfile .= "!insertmacro define_wlan_profile $wlanProfile\n";
407
        }
408
409
        file_put_contents('profiles.nsh', $fcontentsProfile);
410
411
        $fcontentsCerts = '';
412
        $fileHandleCerts = fopen('certs.nsh', 'w');
413
        if ($fileHandleCerts === FALSE) {
414
            throw new Exception("Unable to open new certs.nsh file for writing CAs.");
415
        }
416
        if ($caArray) {
417
            foreach ($caArray as $certAuthority) {
418
                $store = $certAuthority['root'] ? "root" : "ca";
419
                $fcontentsCerts .= '!insertmacro install_ca_cert "' . $certAuthority['file'] . '" "' . $certAuthority['sha1'] . '" "' . $store . "\"\n";
420
            }
421
            fwrite($fileHandleCerts, $fcontentsCerts);
422
        }
423
        fclose($fileHandleCerts);
424
    }
425
426
//private function write
427
428
    private function copyFiles($eap) {
429
        $this->loggerInstance->debug(4, "copyFiles start\n");
430
        $this->copyBasicFiles();
431 View Code Duplication
        switch ($eap["OUTER"]) {
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...
432
            case \core\common\EAP::PWD:
433
                $this->copyPwdFiles();
434
                break;
435
            default:
436
                if (!$this->translateFile('eap_w8.inc', 'cat.NSI', $this->codePage)) {
437
                    throw new Exception("Translating needed file eap_w8.inc failed!");
438
                }
439
        }
440
        $this->loggerInstance->debug(4, "copyFiles end\n");
441
        return TRUE;
442
    }
443
444
    private $tlsOtherUsername = 0;
445
446
}
447