Passed
Push — master ( a7425d...dd80fa )
by Tomasz
03:35
created

Device_W10::writeLANprofile()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 10

Duplication

Lines 27
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 27
loc 27
rs 8.8571
c 0
b 0
f 0
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_W10 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
    }
35
36
    public function writeInstaller() {
37
        $dom = textdomain(NULL);
38
        textdomain("devices");
39
        // create certificate files and save their names in $caFiles arrary
40
        $caFiles = $this->saveCertificateFiles('der');
41
        $allSSID = $this->attributes['internal:SSID'];
42
        $delSSIDs = $this->attributes['internal:remove_SSID'];
43
        $this->prepareInstallerLang();
44
        $setWired = isset($this->attributes['media:wired'][0]) && $this->attributes['media:wired'][0] == 'on' ? 1 : 0;
45
//   create a list of profiles to be deleted after installation
46
        $delProfiles = [];
47
        foreach ($delSSIDs as $ssid => $cipher) {
48
            if ($cipher == 'DEL') {
49
                $delProfiles[] = $ssid;
50
            }
51
            if ($cipher == 'TKIP') {
52
                $delProfiles[] = $ssid . ' (TKIP)';
53
            }
54
        }
55
56
57
        if (in_array($this->selectedEap, [\core\common\EAP::EAPTYPE_TLS,
58
                    \core\common\EAP::EAPTYPE_PEAP_MSCHAP2,
59
                    \core\common\EAP::EAPTYPE_TTLS_PAP,
60
                    \core\common\EAP::EAPTYPE_TTLS_MSCHAP2,
61
                    \core\common\EAP::EAPTYPE_PWD,
62
                    \core\common\EAP::EAPTYPE_SILVERBULLET])) {
63
            $windowsProfile = [];
64
            $eapConfig = $this->prepareEapConfig($this->attributes);
65
            $iterator = 0;
66
            foreach ($allSSID as $ssid => $cipher) {
67
                if ($cipher == 'TKIP') {
68
                    $windowsProfile[$iterator] = $this->writeWLANprofile($ssid . ' (TKIP)', $ssid, 'WPA', 'TKIP', $eapConfig, $iterator);
69
                    $iterator++;
70
                }
71
                $windowsProfile[$iterator] = $this->writeWLANprofile($ssid, $ssid, 'WPA2', 'AES', $eapConfig, $iterator);
72
                $iterator++;
73
            }
74
            if ($setWired) {
75
                $this->writeLANprofile($eapConfig);
76
            }
77
        } else {
78
            print("  this EAP type is not handled yet.\n");
79
            return;
80
        }
81
        $this->loggerInstance->debug(4, "windowsProfile");
82
        $this->loggerInstance->debug(4, print_r($windowsProfile, true));
83
84
        $this->writeProfilesNSH($windowsProfile, $caFiles, $setWired);
85
        $this->writeAdditionalDeletes($delProfiles);
86
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
87
            $this->writeClientP12File();
88
        }
89
        $this->copyFiles($this->selectedEap);
90
        $fedLogo = $this->attributes['fed:logo_file'] ?? NULL;
91
        $idpLogo = $this->attributes['internal:logo_file'] ?? NULL;
92
        $this->combineLogo($idpLogo, $fedLogo);
93
        $this->writeMainNSH($this->selectedEap, $this->attributes);
94
        $this->compileNSIS();
95
        $installerPath = $this->signInstaller();
96
97
        textdomain($dom);
98
        return($installerPath);
99
    }
100
101
    private function prepareEapConfig($attr) {
102
        $eap = $this->selectedEap;
103
        $w10Ext = '';
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 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...
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 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...
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 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...
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 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...
179
            if (isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') {
180
                $nea = 'true';
181
            } else {
182
                $nea = 'false';
183
            }
184
            $w10Ext = '<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
                        $w10Ext .= "<TrustedRootCA>" . $certAuthority['sha1'] . "</TrustedRootCA>\n";
195
                    }
196
                }
197
            }
198
            $w10Ext .= '</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
                $w10Ext .= '<PeapExtensions>
212
<IdentityPrivacy xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2">
213
<EnableIdentityPrivacy>true</EnableIdentityPrivacy>
214
';
215
                if (isset($outerUser) && $outerUser) {
216
                    $w10Ext .= '<AnonymousUserName>' . $outerUser . '</AnonymousUserName>
217
                ';
218
                } else {
219
                    $w10Ext .= '<AnonymousUserName/>
220
                ';
221
                }
222
                $w10Ext .= '</IdentityPrivacy>
223
</PeapExtensions>
224
';
225
            }
226
            $w10Ext .= '</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->code_page) . '</DisplayName>
0 ignored issues
show
Bug introduced by
The property code_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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 ($outer_user == '')
0 ignored issues
show
Bug introduced by
The variable $outer_user does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
252
                        $profileFileCont .= '<AnonymousIdentity>@</AnonymousIdentity>';
253
                    else
254
                        $profileFileCont .= '<AnonymousIdentity>' . $outer_id . '</AnonymousIdentity>';
0 ignored issues
show
Bug introduced by
The variable $outer_id does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
255
                }
256
                $profileFileCont .= '</ClientSideCredential>
257
<ServerSideCredential>
258
';
259
260 View Code Duplication
                foreach ($caArray as $ca) {
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...
261
                    $profileFileCont .= '<CA><format>PEM</format><cert-data>';
262
                    $profileFileCont .= base64_encode($ca['der']);
263
                    $profileFileCont .= '</cert-data></CA>
264
';
265
                }
266
                $profileFileCont .= "<ServerName>$servers</ServerName>\n";
267
268
                $profileFileCont .= '
269
</ServerSideCredential>
270
<InnerAuthenticationMethod>
271
<NonEAPAuthMethod>' . $innerMethod . '</NonEAPAuthMethod>
272
</InnerAuthenticationMethod>
273
<VendorSpecific>
274
<SessionResumption>false</SessionResumption>
275
</VendorSpecific>
276
</AuthenticationMethod>
277
</AuthenticationMethods>
278
</EAPIdentityProvider>
279
</EAPIdentityProviderList>
280
</Config>
281
';
282
            } else {
283
                $w10Ext = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
284
<EapTtls xmlns="http://www.microsoft.com/provisioning/EapTtlsConnectionPropertiesV1">
285
<ServerValidation>
286
<ServerNames>' . $servers . '</ServerNames> ';
287
                if ($caArray) {
288
                    foreach ($caArray as $certAuthority) {
289
                        if ($certAuthority['root']) {
290
                            $w10Ext .= "<TrustedRootCAHash>" . chunk_split($certAuthority['sha1'], 2, ' ') . "</TrustedRootCAHash>\n";
291
                        }
292
                    }
293
                }
294
                $w10Ext .= '<DisablePrompt>true</DisablePrompt> 
295
</ServerValidation>
296
<Phase2Authentication>
297
';
298
                if ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP) {
299
                    $w10Ext .= '<PAPAuthentication /> ';
300
                }
301
                if ($eap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) {
302
                    $w10Ext .= '<MSCHAPv2Authentication>
303
<UseWinlogonCredentials>false</UseWinlogonCredentials>
304
</MSCHAPv2Authentication>
305
';
306
                }
307
                $w10Ext .= '</Phase2Authentication>
308
<Phase1Identity>
309
';
310
                if ($useAnon == 1) {
311
                    $w10Ext .= '<IdentityPrivacy>true</IdentityPrivacy> 
312
';
313
                    if (isset($outerId) && $outerId) {
314
                        $w10Ext .= '<AnonymousIdentity>' . $outerId . '</AnonymousIdentity>
315
                ';
316
                    } else {
317
                        $w10Ext .= '<AnonymousIdentity/>
318
                ';
319
                    }
320
                } else {
321
                    $w10Ext .= '<IdentityPrivacy>false</IdentityPrivacy>
322
';
323
                }
324
                $w10Ext .= '</Phase1Identity>
325
</EapTtls>
326
</Config>
327
';
328
            }
329
        } elseif ($eap == \core\common\EAP::EAPTYPE_PWD) {
330
            $profileFileCont .= '<ConfigBlob></ConfigBlob>';
331
        }
332
333
        $profileFileContEnd = '</EapHostConfig></EAPConfig>';
334
        $returnArray = [];
335
        $returnArray['w10'] = $profileFileCont . $w10Ext . $profileFileContEnd;
336
        return $returnArray;
337
    }
338
339
    /**
340
     * produce PEAP, TLS and TTLS configuration files for Windows 8
341
     * 
342
     * @param string $wlanProfileName
343
     * @param string $ssid
344
     * @param string $auth can be one of "WPA", "WPA2"
345
     * @param string $encryption can be one of: "TKIP", "AES"
346
     * @param array $eapConfig XML configuration block with EAP config data
347
     * @param int $profileNumber counter, which profile number is this
348
     * @return string
349
     */
350 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...
351
        $profileFileCont = '<?xml version="1.0"?>
352
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
353
<name>' . $wlanProfileName . '</name>
354
<SSIDConfig>
355
<SSID>
356
<name>' . $ssid . '</name>
357
</SSID>
358
<nonBroadcast>true</nonBroadcast>
359
</SSIDConfig>
360
<connectionType>ESS</connectionType>
361
<connectionMode>auto</connectionMode>
362
<autoSwitch>false</autoSwitch>
363
<MSM>
364
<security>
365
<authEncryption>
366
<authentication>' . $auth . '</authentication>
367
<encryption>' . $encryption . '</encryption>
368
<useOneX>true</useOneX>
369
</authEncryption>
370
';
371
        if ($auth == 'WPA2') {
372
            $profileFileCont .= '<PMKCacheMode>enabled</PMKCacheMode> 
373
<PMKCacheTTL>720</PMKCacheTTL> 
374
<PMKCacheSize>128</PMKCacheSize> 
375
<preAuthMode>disabled</preAuthMode> 
376
        ';
377
        }
378
        $profileFileCont .= '<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
379
<cacheUserData>true</cacheUserData>
380
<authMode>user</authMode>
381
';
382
383
        $closing = '
384
</OneX>
385
</security>
386
</MSM>
387
</WLANProfile>
388
';
389
390
        if (!is_dir('w8')) {
391
            mkdir('w8');
392
        }
393
        $xmlFname = "w8/wlan_prof-$profileNumber.xml";
394
        $xmlF = fopen($xmlFname, 'w');
395
        fwrite($xmlF, $profileFileCont . $eapConfig['w10'] . $closing);
396
        fclose($xmlF);
397
        $this->loggerInstance->debug(2, "Installer has been written into directory $this->FPATH\n");
398
        $this->loggerInstance->debug(4, "WWWWLAN_Profile:$wlanProfileName:$encryption\n");
399
        return("\"$wlanProfileName\" \"$encryption\"");
400
    }
401
402 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...
403
        $profileFileCont = '<?xml version="1.0"?>
404
<LANProfile xmlns="http://www.microsoft.com/networking/LAN/profile/v1">
405
<MSM>
406
<security>
407
<OneXEnforced>false</OneXEnforced>
408
<OneXEnabled>true</OneXEnabled>
409
<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
410
<cacheUserData>true</cacheUserData>
411
<authMode>user</authMode>
412
';
413
        $closing = '
414
</OneX>
415
</security>
416
</MSM>
417
</LANProfile>
418
';
419
420
        if (!is_dir('w8')) {
421
            mkdir('w8');
422
        }
423
        $xmlFname = "w8/lan_prof.xml";
424
        $xmlF = fopen($xmlFname, 'w');
425
        fwrite($xmlF, $profileFileCont . $eapConfig['w10'] . $closing);
426
        fclose($xmlF);
427
        $this->loggerInstance->debug(2, "Installer has been written into directory $this->FPATH\n");
428
    }
429
430
    private function writeMainNSH($eap, $attr) {
431
        $this->loggerInstance->debug(4, "writeMainNSH");
432
        $this->loggerInstance->debug(4, $attr);
433
        $fcontents = "!define W10\n";
434
        $fcontents .= "!define W8\n";
435
        if (CONFIG_CONFASSISTANT['NSIS_VERSION'] >= 3) {
436
            $fcontents .= "Unicode true\n";
437
        }
438
439
        $eapOptions = [
440
            \core\common\EAP::PEAP => ['str' => 'PEAP', 'exec' => 'user'],
441
            \core\common\EAP::TLS => ['str' => 'TLS', 'exec' => 'user'],
442
            \core\common\EAP::TTLS => ['str' => 'TTLS', 'exec' => 'user'],
443
            \core\common\EAP::PWD => ['str' => 'PWD', 'exec' => 'user'],
444
        ];
445
        if (isset($this->options['args']) && $this->options['args'] == 'gl') {
446
            $eapOptions[\core\common\EAP::TTLS]['str'] = 'GEANTLink';
447
        }
448
449
// Uncomment the line below if you want this module to run under XP (only displaying a warning)
450
// $fcontents .= "!define ALLOW_XP\n";
451
// Uncomment the line below if you want this module to produce debugging messages on the client
452
// $fcontents .= "!define DEBUG_CAT\n";
453
        if ($this->tlsOtherUsername == 1) {
454
            $fcontents .= "!define PFX_USERNAME\n";
455
        }
456
        $execLevel = $eapOptions[$eap["OUTER"]]['exec'];
457
        $eapStr = $eapOptions[$eap["OUTER"]]['str'];
458
        if ($eap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
459
            $fcontents .= "!define SILVERBULLET\n";
460
        }
461
        $fcontents .= '!define ' . $eapStr;
462
        $fcontents .= "\n" . '!define EXECLEVEL "' . $execLevel . '"';
463
        $fcontents .= $this->writeNsisDefines($eap, $attr);
464
        $fileHandle = fopen('main.nsh', 'w');
465
        fwrite($fileHandle, $fcontents);
466
        fclose($fileHandle);
467
    }
468
469 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.

This check looks from 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...
470
        $this->loggerInstance->debug(4, "writeProfilesNSH");
471
        $this->loggerInstance->debug(4, $wlanProfiles);
472
        $fcontentsProfile = '';
473
        foreach ($wlanProfiles as $wlanProfile) {
474
            $fcontentsProfile .= "!insertmacro define_wlan_profile $wlanProfile\n";
475
        }
476
477
        $fileHandleProfiles = fopen('profiles.nsh', 'w');
478
        fwrite($fileHandleProfiles, $fcontentsProfile);
479
        fclose($fileHandleProfiles);
480
481
        $fcontentsCerts = '';
482
        $fileHandleCerts = fopen('certs.nsh', 'w');
483
        if ($caArray) {
484
            foreach ($caArray as $certAuthority) {
485
                $store = $certAuthority['root'] ? "root" : "ca";
486
                $fcontentsCerts .= '!insertmacro install_ca_cert "' . $certAuthority['file'] . '" "' . $certAuthority['sha1'] . '" "' . $store . "\"\n";
487
            }
488
            fwrite($fileHandleCerts, $fcontentsCerts);
489
        }
490
        fclose($fileHandleCerts);
491
    }
492
493
//private function write
494
495
    private function copyFiles($eap) {
496
        $this->loggerInstance->debug(4, "copyFiles start\n");
497
        $this->copyBasicFiles();
498
        switch ($eap["OUTER"]) {
499
            case \core\common\EAP::TTLS:
500
                if (isset($this->options['args']) && $this->options['args'] == 'gl') {
501
                    $this->copyGeantLinkFiles();
502
                }
503
                break;
504
            case \core\common\EAP::PWD:
505
                $this->copyPwdFiles();
506
                break;
507
            default:
508
                if (!$this->translateFile('eap_w8.inc', 'cat.NSI', $this->codePage)) {
509
                    throw new Exception("Translating needed file eap_w8.inc failed!");
510
                }
511
        }
512
        $this->loggerInstance->debug(4, "copyFiles end\n");
513
        return TRUE;
514
    }
515
516
    private $tlsOtherUsername = 0;
517
518
}
519