Test Setup Failed
Push — master ( 5548b8...63dc2d )
by Stefan
16:44
created

DeviceW8W10::writeInstaller()   F

Complexity

Conditions 14
Paths 1920

Size

Total Lines 60
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 60
rs 2.1
c 0
b 0
f 0
cc 14
nc 1920
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
 * Contributions to this work were made on behalf of the GÉANT project, a 
5
 * project that has received funding from the European Union’s Framework 
6
 * Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
7
 * Horizon 2020 research and innovation programme under Grant Agreements No. 
8
 * 691567 (GN4-1) and No. 731122 (GN4-2).
9
 * On behalf of the aforementioned projects, GEANT Association is the sole owner
10
 * of the copyright in all material which was developed by a member of the GÉANT
11
 * project. GÉANT Vereniging (Association) is registered with the Chamber of 
12
 * Commerce in Amsterdam with registration number 40535155 and operates in the 
13
 * UK as a branch of GÉANT Vereniging.
14
 * 
15
 * Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. 
16
 * UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
17
 *
18
 * License: see the web/copyright.inc.php file in the file structure or
19
 *          <base_url>/copyright.php after deploying the software
20
 */
21
22
/**
23
 * This file creates MS Windows 8 installers
24
 * It supports EAP-TLS, TTLS, PEAP and EAP-pwd
25
 * @author Tomasz Wolniewicz <[email protected]>
26
 *
27
 * @package ModuleWriting
28
 */
29
30
namespace devices\ms;
31
use \Exception;
32
33
/**
34
 *
35
 * @author Tomasz Wolniewicz <[email protected]>
36
 * @package ModuleWriting
37
 */
38
 class DeviceW8W10 extends WindowsCommon {
39
    final public function __construct() {
40
        parent::__construct();
41
        \core\common\Entity::intoThePotatoes();
42
        $this->setSupportedEapMethods(
43
                [
44
                    \core\common\EAP::EAPTYPE_TLS,
45
                    \core\common\EAP::EAPTYPE_PEAP_MSCHAP2,
46
                    \core\common\EAP::EAPTYPE_TTLS_PAP,
47
                    \core\common\EAP::EAPTYPE_TTLS_MSCHAP2,
48
                    \core\common\EAP::EAPTYPE_SILVERBULLET
49
                ]);
50
        $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.");
51
        \core\common\Entity::outOfThePotatoes();
52
    }
53
    
54
    /**
55
     * create the actual installer executable
56
     * 
57
     * @return string filename of the generated installer
58
     *
59
     */    
60
    public function writeInstaller() {
61
        $dom = textdomain(NULL);
62
        textdomain("devices");
63
        // create certificate files and save their names in $caFiles arrary
64
        $caFiles = $this->saveCertificateFiles('der');
65
        $this->caArray = $this->getAttribute('internal:CAs')[0];
66
        $outerId = $this->determineOuterIdString();
67
        $this->useAnon = $outerId === NULL ? FALSE : TRUE;
68
        $this->servers = empty($this->attributes['eap:server_name']) ? '' :  implode(';', $this->attributes['eap:server_name']);
69
        $allSSID = $this->attributes['internal:SSID'];
70
        $delSSIDs = $this->attributes['internal:remove_SSID'];
71
        $this->prepareInstallerLang();
72
        $this->setGeantLink();
73
        $setWired = isset($this->attributes['media:wired'][0]) && $this->attributes['media:wired'][0] == 'on' ? 1 : 0;
74
//   create a list of profiles to be deleted after installation
75
        $delProfiles = [];
76
        foreach ($delSSIDs as $ssid => $cipher) {
77
            if ($cipher == 'DEL') {
78
                $delProfiles[] = $ssid;
79
            }
80
            if ($cipher == 'TKIP') {
81
                $delProfiles[] = $ssid . ' (TKIP)';
82
            }
83
        }
84
        $windowsProfile = [];
85
        $eapConfig = $this->prepareEapConfig();
86
        $iterator = 0;
87
        foreach ($allSSID as $ssid => $cipher) {
88
            if ($cipher == 'TKIP') {
89
                $windowsProfile[$iterator] = $this->writeWLANprofile($ssid . ' (TKIP)', $ssid, 'WPA', 'TKIP', $eapConfig, $iterator);
90
                $iterator++;
91
            }
92
            $windowsProfile[$iterator] = $this->writeWLANprofile($ssid, $ssid, 'WPA2', 'AES', $eapConfig, $iterator);
93
            $iterator++;
94
        }
95
        if (($this->device_id !== 'w8') && (count($this->attributes['internal:consortia']) > 0 )) {
96
            // this SSID name is later used in common.inc so if you decide to chage it here change it there as well
97
                $ssid = 'cat-passpoint-profile';
98
                $windowsProfile[$iterator] = $this->writeWLANprofile($ssid, $ssid, 'WPA2', 'AES', $eapConfig, $iterator, TRUE);
99
        }
100
        if ($setWired) {
101
            $this->writeLANprofile($eapConfig);
102
        }
103
        $this->loggerInstance->debug(4, "windowsProfile");
104
        $this->loggerInstance->debug(4, print_r($windowsProfile, true));
105
106
        $this->writeProfilesNSH($windowsProfile, $caFiles);
107
        $this->writeAdditionalDeletes($delProfiles);
108
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
109
            $this->writeClientP12File();
110
        }
111
        $this->copyFiles($this->selectedEap);
112
        $fedLogo = $this->attributes['fed:logo_file'] ?? NULL;
113
        $idpLogo = $this->attributes['internal:logo_file'] ?? NULL;
114
        $this->combineLogo($idpLogo, $fedLogo);
115
        $this->writeMainNSH($this->selectedEap, $this->attributes);
116
        $this->compileNSIS();
117
        $installerPath = $this->signInstaller();
118
        textdomain($dom);
119
        return($installerPath);
120
    }
121
122
    private function setAuthorId() {
123
        if ($this->selectedEap['OUTER'] === \core\common\EAP::TTLS) {
124
            if ($this->useGeantLink) {
125
                $authorId = "67532";
126
            } else {
127
                $authorId = "311";
128
            }
129
        } else {
130
            $authorId = 0;
131
        }
132
        return($authorId);
133
    }
134
135
    private function addConsortia() {
136
        if ($this->device_id == 'w8') {
137
            return('');
138
        }
139
        $retval = '<Hotspot2>';
140
        $retval .= '<DomainName>';
141
        if (empty($this->attributes['internal:realm'][0])) {
142
            $retval .= CONFIG_CONFASSISTANT['CONSORTIUM']['interworking-domainname-fallback'];
143
        } else {
144
            $retval .=  $this->attributes['internal:realm'][0];
145
        }
146
        $retval .= '</DomainName>';
147
        $retval .= '<RoamingConsortium><OUI>' . 
148
            implode('</OUI><OUI>', $this->attributes['internal:consortia']) .
149
            '</OUI></RoamingConsortium>';
150
        $retval .=  '</Hotspot2>';
151
        return($retval);
152
    }
153
    
154
    private function eapConfigHeader() {
155
        $authorId = $this->setAuthorId();
156
        $profileFileCont = '<EAPConfig><EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
157
<EapMethod>
158
';
159
        $profileFileCont .= '<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">' .
160
                $this->selectedEap["OUTER"] . '</Type>
161
<VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId>
162
<VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType>
163
<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">' . $authorId . '</AuthorId>
164
</EapMethod>
165
';
166
        return($profileFileCont);
167
    }
168
169
    private function tlsServerValidation() {
170
        $profileFileCont = '
171
<eapTls:ServerValidation>
172
<eapTls:DisableUserPromptForServerValidation>true</eapTls:DisableUserPromptForServerValidation>
173
';
174
        $profileFileCont .= '<eapTls:ServerNames>' . $this->servers . '</eapTls:ServerNames>';
175
        foreach ($this->caArray as $certAuthority) {
176
            if ($certAuthority['root']) {
177
                $profileFileCont .= "<eapTls:TrustedRootCA>" . $certAuthority['sha1'] . "</eapTls:TrustedRootCA>\n";
178
            }
179
        }
180
        $profileFileCont .= '</eapTls:ServerValidation>
181
';
182
        return($profileFileCont);
183
    }
184
    
185
    private function msTtlsServerValidation() {
186
        $profileFileCont = '
187
        <ServerValidation>
188
';
189
        $profileFileCont .= '<ServerNames>' . $this->servers . '</ServerNames> ';
190
        foreach ($this->caArray as $certAuthority) {
191
            if ($certAuthority['root']) {
192
                $profileFileCont .= "<TrustedRootCAHash>" . chunk_split($certAuthority['sha1'], 2, ' ') . "</TrustedRootCAHash>\n";
193
            }
194
        }
195
        $profileFileCont .= '<DisablePrompt>true</DisablePrompt>
196
</ServerValidation>
197
';
198
        return($profileFileCont);
199
    }
200
    
201
    private function glTtlsServerValidation() {
202
        $servers = implode('</ServerName><ServerName>', $this->attributes['eap:server_name']);
203
        $profileFileCont = '
204
<ServerSideCredential>
205
';
206
        foreach ($this->caArray as $ca) {
207
            $profileFileCont .= '<CA><format>PEM</format><cert-data>';
208
            $profileFileCont .= base64_encode($ca['der']);
209
            $profileFileCont .= '</cert-data></CA>
210
';
211
        }
212
        $profileFileCont .= "<ServerName>$servers</ServerName>\n";
213
214
        $profileFileCont .= '
215
</ServerSideCredential>
216
';
217
        return($profileFileCont);
218
    }
219
    
220
    private function peapServerValidation() {
221
        $profileFileCont = '
222
        <ServerValidation>
223
<DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation>
224
<ServerNames>' . $this->servers . '</ServerNames>';
225
        foreach ($this->caArray as $certAuthority) {
226
            if ($certAuthority['root']) {
227
                $profileFileCont .= "<TrustedRootCA>" . $certAuthority['sha1'] . "</TrustedRootCA>\n";
228
            }
229
        }
230
        $profileFileCont .= '</ServerValidation>
231
';
232
        return($profileFileCont);
233
    }
234
    
235
    private function tlsConfig() {
236
        $profileFileCont = '
237
<Config xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"
238
  xmlns:eapTls="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1">
239
<baseEap:Eap>
240
<baseEap:Type>13</baseEap:Type>
241
<eapTls:EapType>
242
<eapTls:CredentialsSource>
243
<eapTls:CertificateStore />
244
</eapTls:CredentialsSource>
245
';    
246
        $profileFileCont .= $this->tlsServerValidation();
247
        if (\core\common\Entity::getAttributeValue($this->attributes, 'eap-specific:tls_use_other_id', 0) === 'on') {
248
            $profileFileCont .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>';
249
            $this->tlsOtherUsername = 1;
250
        } else {
251
            $profileFileCont .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>';
252
        }
253
        $profileFileCont .= '
254
</eapTls:EapType>
255
</baseEap:Eap>
256
</Config>
257
';
258
        return($profileFileCont);
259
    }
260
261
    private function msTtlsConfig() {        
262
        $profileFileCont = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
263
<EapTtls xmlns="http://www.microsoft.com/provisioning/EapTtlsConnectionPropertiesV1">
264
';
265
        $profileFileCont .= $this->msTtlsServerValidation();
266
        $profileFileCont .= '<Phase2Authentication>
267
';
268
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_PAP) {
269
            $profileFileCont .= '<PAPAuthentication /> ';
270
        }
271
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) {
272
            $profileFileCont .= '<MSCHAPv2Authentication>
273
<UseWinlogonCredentials>false</UseWinlogonCredentials>
274
</MSCHAPv2Authentication>
275
';
276
        }
277
        $profileFileCont .= '</Phase2Authentication>
278
<Phase1Identity>
279
';
280
        if ($this->useAnon) {
281
            $profileFileCont .= '<IdentityPrivacy>true</IdentityPrivacy>
282
';
283
            $profileFileCont .= '<AnonymousIdentity>' . $this->outerId . '</AnonymousIdentity>
284
                ';
285
        } else {
286
            $profileFileCont .= '<IdentityPrivacy>false</IdentityPrivacy>
287
';
288
        }
289
        $profileFileCont .= '</Phase1Identity>
290
</EapTtls>
291
</Config>
292
';
293
        return($profileFileCont);
294
    }
295
    
296
    private function glTtlsConfig() {        
297
        $profileFileCont = '
298
<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
299
<EAPIdentityProviderList xmlns="urn:ietf:params:xml:ns:yang:ietf-eap-metadata">
300
<EAPIdentityProvider ID="' . $this->deviceUUID . '" namespace="urn:UUID">
301
302
<ProviderInfo>
303
<DisplayName>' . $this->translateString($this->attributes['general:instname'][0], $this->codePage) . '</DisplayName>
304
</ProviderInfo>
305
<AuthenticationMethods>
306
<AuthenticationMethod>
307
<EAPMethod>21</EAPMethod>
308
<ClientSideCredential>
309
<allow-save>true</allow-save>
310
';
311
        if ($this->useAnon) {
312
            if ($this->outerUser == '') {
313
                $profileFileCont .= '<AnonymousIdentity>@</AnonymousIdentity>';
314
            } else {
315
                $profileFileCont .= '<AnonymousIdentity>' . $this->outerId . '</AnonymousIdentity>';
316
            }
317
        }
318
        $profileFileCont .= '</ClientSideCredential>
319
';
320
        $profileFileCont .= $this->glTtlsServerValidation();
321
        $profileFileCont .= '
322
<InnerAuthenticationMethod>
323
<NonEAPAuthMethod>' . \core\common\EAP::eapDisplayName($this->selectedEap)['INNER'] . '</NonEAPAuthMethod>
324
</InnerAuthenticationMethod>
325
<VendorSpecific>
326
<SessionResumption>false</SessionResumption>
327
</VendorSpecific>
328
</AuthenticationMethod>
329
</AuthenticationMethods>
330
</EAPIdentityProvider>
331
</EAPIdentityProviderList>
332
</Config>
333
';
334
        return($profileFileCont);
335
    }
336
337
    private function peapConfig() {
338
        $nea = (\core\common\Entity::getAttributeValue($this->attributes, 'media:wired', 0) == 'on') ? 'true' : 'false';
339
        $profileFileCont = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
340
<Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1">
341
<Type>25</Type>
342
<EapType xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1">
343
';
344
        $profileFileCont .= $this->peapServerValidation();
345
        $profileFileCont .= '
346
<FastReconnect>true</FastReconnect>
347
<InnerEapOptional>false</InnerEapOptional>
348
<Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1">
349
<Type>26</Type>
350
<EapType xmlns="http://www.microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1">
351
<UseWinLogonCredentials>false</UseWinLogonCredentials>
352
</EapType>
353
</Eap>
354
<EnableQuarantineChecks>' . $nea . '</EnableQuarantineChecks>
355
<RequireCryptoBinding>false</RequireCryptoBinding>
356
';
357
        if ($this->useAnon) {
358
            $profileFileCont .= '<PeapExtensions>
359
<IdentityPrivacy xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2">
360
<EnableIdentityPrivacy>true</EnableIdentityPrivacy>
361
';
362
            if ($this->outerUser == '') {
363
                $profileFileCont .= '<AnonymousUserName/>
364
';
365
            } else {
366
                $profileFileCont .= '<AnonymousUserName>' . $this->outerUser . '</AnonymousUserName>
367
                ';
368
            }
369
            $profileFileCont .= '</IdentityPrivacy>
370
</PeapExtensions>
371
';
372
        }
373
        $profileFileCont .= '</EapType>
374
</Eap>
375
</Config>
376
';
377
        return($profileFileCont);
378
    }
379
    
380
    private function pwdConfig() {
381
        return('<ConfigBlob></ConfigBlob>');
382
    }
383
384
    private function setGeantLink() {
385
        $this->useGeantLink = FALSE;
386
        if (\core\common\Entity::getAttributeValue($this->attributes, 'device-specific:geantlink', 0) === 'on') {
387
            $this->useGeantLink = TRUE;
388
        }
389
        if (isset($this->options['args']) && $this->options['args'] == 'gl') {
390
            $this->useGeantLink = TRUE;
391
        }
392
        if (\core\common\Entity::getAttributeValue($this->attributes, 'device-specific:builtin_ttls', 0) === 'on') {
393
            $this->useGeantLink = FALSE;
394
        }
395
    }
396
397
    private function prepareEapConfig() {
398
        if ($this->useAnon) {
399
            $this->outerUser = $this->attributes['internal:anon_local_value'][0];
400
            $this->outerId = $this->outerUser . '@' . $this->attributes['internal:realm'][0];
401
        }
402
403
        $profileFileCont = $this->eapConfigHeader();
404
405
        switch ($this->selectedEap['OUTER']) {
406
            case \core\common\EAP::TLS:
407
                $profileFileCont .= $this->tlsConfig();
408
                break;
409
            case \core\common\EAP::PEAP:
410
                $profileFileCont .= $this->peapConfig();
411
                break;
412
            case \core\common\EAP::TTLS:
413
                if ($this->useGeantLink) {
414
                    $profileFileCont .= $this->glTtlsConfig();
415
                } else {
416
                    $profileFileCont .= $this->msTtlsConfig();
417
                }
418
                break;
419
            case \core\common\EAP::PWD:
420
                $profileFileCont .= $this->pwdConfig();
421
                break;
422
            default:
423
                break;
424
        }
425
        return(['win' => $profileFileCont . '</EapHostConfig></EAPConfig>']);
426
    }
427
428
    /**
429
     * produce PEAP, TLS and TTLS configuration files for Windows 8
430
     *
431
     * @param string $wlanProfileName
432
     * @param string $ssid
433
     * @param string $auth can be one of "WPA", "WPA2"
434
     * @param string $encryption can be one of: "TKIP", "AES"
435
     * @param array $eapConfig XML configuration block with EAP config data
436
     * @param int $profileNumber counter, which profile number is this
437
     * @return string
438
     */
439
    private function writeWLANprofile($wlanProfileName, $ssid, $auth, $encryption, $eapConfig, $profileNumber, $hs20 = FALSE) {
440
        $profileFileCont = '<?xml version="1.0"?>
441
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
442
<name>' . $wlanProfileName . '</name>
443
<SSIDConfig>
444
<SSID>
445
<name>' . $ssid . '</name>
446
</SSID>
447
<nonBroadcast>true</nonBroadcast>
448
</SSIDConfig>';
449
        if ($hs20) {
450
            $profileFileCont .= $this->addConsortia();
451
        }
452
        $profileFileCont .= '
453
<connectionType>ESS</connectionType>
454
<connectionMode>auto</connectionMode>
455
<autoSwitch>false</autoSwitch>
456
<MSM>
457
<security>
458
<authEncryption>
459
<authentication>' . $auth . '</authentication>
460
<encryption>' . $encryption . '</encryption>
461
<useOneX>true</useOneX>
462
</authEncryption>
463
';
464
        if ($auth == 'WPA2') {
465
            $profileFileCont .= '<PMKCacheMode>enabled</PMKCacheMode>
466
<PMKCacheTTL>720</PMKCacheTTL>
467
<PMKCacheSize>128</PMKCacheSize>
468
<preAuthMode>disabled</preAuthMode>
469
        ';
470
        }
471
        $profileFileCont .= '<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
472
<cacheUserData>true</cacheUserData>
473
<authMode>user</authMode>
474
';
475
476
        $closing = '
477
</OneX>
478
</security>
479
</MSM>
480
</WLANProfile>
481
';
482
483
        if (!is_dir('w8')) {
484
            mkdir('w8');
485
        }
486
        $xmlFname = "w8/wlan_prof-$profileNumber.xml";
487
        file_put_contents($xmlFname, $profileFileCont . $eapConfig['win'] . $closing);
488
        $this->loggerInstance->debug(2, "Installer has been written into directory $this->FPATH\n");
489
        return("\"$wlanProfileName\" \"$encryption\"");
490
    }
491
492
    private function writeLANprofile($eapConfig) {
493
        $profileFileCont = '<?xml version="1.0"?>
494
<LANProfile xmlns="http://www.microsoft.com/networking/LAN/profile/v1">
495
<MSM>
496
<security>
497
<OneXEnforced>false</OneXEnforced>
498
<OneXEnabled>true</OneXEnabled>
499
<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
500
<cacheUserData>true</cacheUserData>
501
<authMode>user</authMode>
502
';
503
        $closing = '
504
</OneX>
505
</security>
506
</MSM>
507
</LANProfile>
508
';
509
510
        if (!is_dir('w8')) {
511
            mkdir('w8');
512
        }
513
        $xmlFname = "w8/lan_prof.xml";
514
        file_put_contents($xmlFname, $profileFileCont . $eapConfig['win'] . $closing);
515
        $this->loggerInstance->debug(2, "Installer has been written into directory $this->FPATH\n");
516
    }
517
518
    private function writeProfilesNSH($wlanProfiles, $caArray) {
519
        $this->loggerInstance->debug(4, "writeProfilesNSH");
520
        $this->loggerInstance->debug(4, $wlanProfiles);
521
        $fcontentsProfile = '';
522
        foreach ($wlanProfiles as $wlanProfile) {
523
            $fcontentsProfile .= "!insertmacro define_wlan_profile $wlanProfile\n";
524
        }
525
526
        file_put_contents('profiles.nsh', $fcontentsProfile);
527
528
        $fcontentsCerts = '';
529
        $fileHandleCerts = fopen('certs.nsh', 'w');
530
        if ($fileHandleCerts === FALSE) {
531
            throw new Exception("Unable to open new certs.nsh file for writing CAs.");
532
        }
533
        foreach ($caArray as $certAuthority) {
534
            $store = $certAuthority['root'] ? "root" : "ca";
535
            $fcontentsCerts .= '!insertmacro install_ca_cert "' . $certAuthority['file'] . '" "' . $certAuthority['sha1'] . '" "' . $store . "\"\n";
536
        }
537
        fwrite($fileHandleCerts, $fcontentsCerts);
538
        fclose($fileHandleCerts);
539
    }
540
541
    private function writeMainNSH($eap, $attr) {
542
        $this->loggerInstance->debug(4, "writeMainNSH");
543
        $this->loggerInstance->debug(4, $attr);
544
        $this->loggerInstance->debug(4, "Device_id = " . $this->device_id . "\n");
545
        $fcontents = "!define W8\n";
546
        if ($this->device_id == 'w10') {
547
            $fcontents .= "!define W10\n";
548
        }
549
        if (CONFIG_CONFASSISTANT['NSIS_VERSION'] >= 3) {
550
            $fcontents .= "Unicode true\n";
551
        }
552
        $eapOptions = [
553
            \core\common\EAP::PEAP => ['str' => 'PEAP', 'exec' => 'user'],
554
            \core\common\EAP::TLS => ['str' => 'TLS', 'exec' => 'user'],
555
            \core\common\EAP::TTLS => ['str' => 'TTLS', 'exec' => 'user'],
556
            \core\common\EAP::PWD => ['str' => 'PWD', 'exec' => 'user'],
557
        ];
558
        if ($this->useGeantLink) {
559
            $eapOptions[\core\common\EAP::TTLS]['str'] = 'GEANTLink';
560
        }
561
562
// Uncomment the line below if you want this module to run under XP (only displaying a warning)
563
// $fcontents .= "!define ALLOW_XP\n";
564
// Uncomment the line below if you want this module to produce debugging messages on the client
565
// $fcontents .= "!define DEBUG_CAT\n";
566
        if ($this->tlsOtherUsername == 1) {
567
            $fcontents .= "!define PFX_USERNAME\n";
568
        }
569
        $execLevel = $eapOptions[$eap["OUTER"]]['exec'];
570
        $eapStr = $eapOptions[$eap["OUTER"]]['str'];
571
        if ($eap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
572
            $fcontents .= "!define SILVERBULLET\n";
573
        }
574
        $fcontents .= '!define ' . $eapStr;
575
        $fcontents .= "\n" . '!define EXECLEVEL "' . $execLevel . '"';
576
        $fcontents .= $this->writeNsisDefines($attr);
577
        file_put_contents('main.nsh', $fcontents);
578
    }
579
580
    private function copyStandardNsi() {
581
        if (!$this->translateFile('eap_w8.inc', 'cat.NSI', $this->codePage)) {
582
            throw new Exception("Translating needed file eap_w8.inc failed!");
583
        }
584
    }
585
586
    private function copyFiles($eap) {
587
        $this->loggerInstance->debug(4, "copyFiles start\n");
588
        $this->copyBasicFiles();
589
        switch ($eap["OUTER"]) {
590
            case \core\common\EAP::TTLS:
591
                if ($this->useGeantLink) {
592
                    $this->copyGeantLinkFiles();
593
                } else {
594
                    $this->copyStandardNsi();
595
                }
596
                break;
597
            case \core\common\EAP::PWD:
598
                $this->copyPwdFiles();
599
                break;
600
            default:
601
                $this->copyStandardNsi();
602
        }
603
        $this->loggerInstance->debug(4, "copyFiles end\n");
604
        return TRUE;
605
    }
606
607
    private $tlsOtherUsername = 0;
608
    private $caArray;
609
    private $useAnon;
610
    private $servers;
611
    private $outerUser;
612
    private $outerId;
613
614
}
615
616