| Total Complexity | 68 |
| Total Lines | 514 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like DeviceVista7 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 DeviceVista7, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 36 | class DeviceVista7 extends WindowsCommon |
||
| 37 | { |
||
| 38 | |||
| 39 | /** |
||
| 40 | * constructor; tells the world about supported EAP types and device anomalies |
||
| 41 | */ |
||
| 42 | final public function __construct() |
||
| 43 | { |
||
| 44 | parent::__construct(); |
||
| 45 | \core\common\Entity::intoThePotatoes(); |
||
| 46 | $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_SILVERBULLET]); |
||
| 47 | $this->loggerInstance->debug(4, "This device supports the following EAP methods: "); |
||
| 48 | $this->loggerInstance->debug(4, $this->supportedEapMethods); |
||
| 49 | $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."); |
||
| 50 | $this->specialities['media:openroaming'] = _("While OpenRoaming can be configured, it is possible that the Wi-Fi hardware does not support it; then the network definition is ignored."); |
||
| 51 | $this->specialities['media:consortium_OI'] = _("While Passpoint networks can be configured, it is possible that the Wi-Fi hardware does not support it; then the network definition is ignored."); |
||
| 52 | \core\common\Entity::outOfThePotatoes(); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * create the actual installer executable |
||
| 57 | * |
||
| 58 | * @return string filename of the generated installer |
||
| 59 | * |
||
| 60 | */ |
||
| 61 | public function writeInstaller() |
||
| 62 | { |
||
| 63 | $dom = textdomain(NULL); |
||
| 64 | textdomain("devices"); |
||
| 65 | // create certificate files and save their names in $caFiles array |
||
| 66 | $caFiles = $this->saveCertificateFiles('der'); |
||
| 67 | |||
| 68 | $allSSID = $this->attributes['internal:SSID']; |
||
| 69 | $delSSIDs = $this->attributes['internal:remove_SSID']; |
||
| 70 | $this->prepareInstallerLang(); |
||
| 71 | $setWired = isset($this->attributes['media:wired'][0]) && $this->attributes['media:wired'][0] == 'on' ? 1 : 0; |
||
| 72 | // create a list of profiles to be deleted after installation |
||
| 73 | $delProfiles = []; |
||
| 74 | foreach ($delSSIDs as $ssid => $cipher) { |
||
| 75 | if ($cipher == 'DEL') { |
||
| 76 | $delProfiles[] = $ssid; |
||
| 77 | } |
||
| 78 | if ($cipher == 'TKIP') { |
||
| 79 | $delProfiles[] = $ssid . ' (TKIP)'; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($this->selectedEap == \core\common\EAP::EAPTYPE_TLS || $this->selectedEap == \core\common\EAP::EAPTYPE_PEAP_MSCHAP2 || $this->selectedEap == \core\common\EAP::EAPTYPE_PWD || $this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_PAP || $this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2 || $this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) { |
||
| 84 | $windowsProfile = []; |
||
| 85 | $eapConfig = $this->prepareEapConfig($this->attributes); |
||
| 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 ($setWired) { |
||
| 96 | $this->writeLANprofile($eapConfig); |
||
| 97 | } |
||
| 98 | } else { |
||
| 99 | print(" this EAP type is not handled yet.\n"); |
||
| 100 | return; |
||
| 101 | } |
||
| 102 | $this->loggerInstance->debug(4, "windowsProfile"); |
||
| 103 | $this->loggerInstance->debug(4, $windowsProfile); |
||
| 104 | |||
| 105 | $this->writeProfilesNSH($windowsProfile, $caFiles); |
||
| 106 | $this->writeAdditionalDeletes($delProfiles); |
||
| 107 | if ($this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) { |
||
| 108 | $this->writeClientP12File(); |
||
| 109 | } |
||
| 110 | $this->copyFiles($this->selectedEap); |
||
| 111 | $fedLogo = $this->attributes['fed:logo_file'] ?? NULL; |
||
| 112 | $idpLogo = $this->attributes['internal:logo_file'] ?? NULL; |
||
| 113 | $this->combineLogo($idpLogo, $fedLogo); |
||
| 114 | $this->writeMainNSH($this->selectedEap, $this->attributes); |
||
| 115 | $this->compileNSIS(); |
||
| 116 | $installerPath = $this->signInstaller(); |
||
| 117 | |||
| 118 | textdomain($dom); |
||
| 119 | return($installerPath); |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * creates the XML snippet that describes the EAP configuration |
||
| 124 | * |
||
| 125 | * @param array $attr the attributes for the profile |
||
| 126 | * @return array two XML snippets describing the EAP configuration, for Vista and 7 respectively |
||
| 127 | */ |
||
| 128 | private function prepareEapConfig($attr) |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * produce PEAP, TLS and TTLS configuration files for Vista and Windows 7. |
||
| 338 | * Writes XML snippet into file and returns some meta information |
||
| 339 | * |
||
| 340 | * @param string $wlanProfileName name of the WLAN profile |
||
| 341 | * @param string $ssid SSID that is being configured |
||
| 342 | * @param string $auth can be one of "WPA", "WPA2" |
||
| 343 | * @param string $encryption can be one of: "TKIP", "AES" |
||
| 344 | * @param array $eapConfig XML configuration block with EAP config data (two entries, one for Vista, one for 7) |
||
| 345 | * @param int $profileNumber counter, which profile number is this |
||
| 346 | * @return string meta info about generated XML snippet |
||
| 347 | */ |
||
| 348 | private function writeWLANprofile($wlanProfileName, $ssid, $auth, $encryption, $eapConfig, $profileNumber) { |
||
| 401 | } |
||
| 402 | |||
| 403 | /** |
||
| 404 | * writes LAN configuration profile into file |
||
| 405 | * |
||
| 406 | * @param array $eapConfig contains XML snippets for Vista and 7 with the EAP configuration |
||
| 407 | * @return void |
||
| 408 | */ |
||
| 409 | private function writeLANprofile($eapConfig) |
||
| 410 | { |
||
| 411 | $profileFileCont = '<?xml version="1.0"?> |
||
| 412 | <LANProfile xmlns="http://www.microsoft.com/networking/LAN/profile/v1"> |
||
| 413 | <MSM> |
||
| 414 | <security> |
||
| 415 | <OneXEnforced>false</OneXEnforced> |
||
| 416 | <OneXEnabled>true</OneXEnabled> |
||
| 417 | <OneX xmlns="http://www.microsoft.com/networking/OneX/v1"> |
||
| 418 | <cacheUserData>true</cacheUserData> |
||
| 419 | <authMode>user</authMode> |
||
| 420 | '; |
||
| 421 | $closing = ' |
||
| 422 | </OneX> |
||
| 423 | </security> |
||
| 424 | </MSM> |
||
| 425 | </LANProfile> |
||
| 426 | '; |
||
| 427 | if (!is_dir('w7')) { |
||
| 428 | mkdir('w7'); |
||
| 429 | } |
||
| 430 | if (!is_dir('vista')) { |
||
| 431 | mkdir('vista'); |
||
| 432 | } |
||
| 433 | |||
| 434 | file_put_contents("vista/lan_prof.xml", $profileFileCont . $eapConfig['vista'] . $closing); |
||
| 435 | file_put_contents("w7/lan_prof.xml", $profileFileCont . $eapConfig['w7'] . $closing); |
||
| 436 | |||
| 437 | } |
||
| 438 | |||
| 439 | /** |
||
| 440 | * writes the main NSH file |
||
| 441 | * |
||
| 442 | * @param array $eap EAP type that is being configured in array representation |
||
| 443 | * @param array $attr list of attributes |
||
| 444 | * @return void |
||
| 445 | */ |
||
| 446 | private function writeMainNSH($eap, $attr) { |
||
| 447 | $this->loggerInstance->debug(4, "writeMainNSH"); |
||
| 448 | $this->loggerInstance->debug(4, $attr); |
||
| 449 | $this->loggerInstance->debug(4, "MYLANG=" . $this->lang . "\n"); |
||
| 450 | |||
| 451 | $eapOptions = [ |
||
| 452 | \core\common\EAP::PEAP => ['str' => 'PEAP', 'exec' => 'user'], |
||
| 453 | \core\common\EAP::TLS => ['str' => 'TLS', 'exec' => 'user'], |
||
| 454 | // TODO for TW: the following line doesn't work - that constant is an array, which can't be a key for another array |
||
| 455 | // generated a PHP Warning but doesn't seem to have any catastrophic effect? |
||
| 456 | // \core\common\EAP::EAPTYPE_SILVERBULLET => ['str' => 'TLS', 'exec' => 'user'], |
||
| 457 | \core\common\EAP::TTLS => ['str' => 'GEANTLink', 'exec' => 'user'], |
||
| 458 | \core\common\EAP::PWD => ['str' => 'PWD', 'exec' => 'user'], |
||
| 459 | ]; |
||
| 460 | $fcontents = ''; |
||
| 461 | if (\config\ConfAssistant::NSIS_VERSION >= 3) { |
||
| 462 | $fcontents .= "Unicode true\n"; |
||
| 463 | } |
||
| 464 | |||
| 465 | // Uncomment the line below if you want this module to run under XP (only displaying a warning) |
||
| 466 | // $fcontents .= "!define ALLOW_XP\n"; |
||
| 467 | // Uncomment the line below if you want this module to produce debugging messages on the client |
||
| 468 | // $fcontents .= "!define DEBUG_CAT\n"; |
||
| 469 | if ($this->tlsOtherUsername === true) { |
||
| 470 | $fcontents .= "!define PFX_USERNAME\n"; |
||
| 471 | } |
||
| 472 | $execLevel = $eapOptions[$eap["OUTER"]]['exec']; |
||
| 473 | $eapStr = $eapOptions[$eap["OUTER"]]['str']; |
||
| 474 | if ($eap == \core\common\EAP::EAPTYPE_SILVERBULLET) { |
||
| 475 | $fcontents .= "!define SILVERBULLET\n"; |
||
| 476 | } |
||
| 477 | $this->loggerInstance->debug(4, "EAP_STR=$eapStr\n"); |
||
| 478 | $this->loggerInstance->debug(4, $eap); |
||
| 479 | |||
| 480 | $fcontents .= '!define ' . $eapStr; |
||
| 481 | $fcontents .= "\n" . '!define EXECLEVEL "' . $execLevel . '"'; |
||
| 482 | $fcontents .= $this->writeNsisDefines($attr); |
||
| 483 | file_put_contents('main.nsh', $fcontents); |
||
| 484 | } |
||
| 485 | |||
| 486 | /** |
||
| 487 | * writes references to the individual WLAN profile files into main file |
||
| 488 | * @param array $wlanProfiles list of WLAN profiles |
||
| 489 | * @param array $caArray list of CA certificates |
||
| 490 | * @return void |
||
| 491 | * @throws Exception |
||
| 492 | */ |
||
| 493 | private function writeProfilesNSH($wlanProfiles, $caArray) { |
||
| 494 | $this->loggerInstance->debug(4, "writeProfilesNSH"); |
||
| 495 | $this->loggerInstance->debug(4, $wlanProfiles); |
||
| 496 | $contentWlan = ''; |
||
| 497 | foreach ($wlanProfiles as $wlanProfile) { |
||
| 498 | $contentWlan .= "!insertmacro define_wlan_profile $wlanProfile 0 0\n"; |
||
| 499 | } |
||
| 500 | |||
| 501 | file_put_contents('profiles.nsh', $contentWlan); |
||
| 502 | |||
| 503 | $contentCerts = ''; |
||
| 504 | $fileHandleCerts = fopen('certs.nsh', 'w'); |
||
| 505 | if ($fileHandleCerts === false) { |
||
| 506 | throw new Exception("Unable to open new file certs.nsh to write CAs!"); |
||
| 507 | } |
||
| 508 | foreach ($caArray as $certAuthority) { |
||
| 509 | $store = $certAuthority['root'] ? "root" : "ca"; |
||
| 510 | $contentCerts .= '!insertmacro install_ca_cert "' . $certAuthority['file'] . '" "' . $certAuthority['sha1'] . '" "' . $store . "\"\n"; |
||
| 511 | } |
||
| 512 | fwrite($fileHandleCerts, $contentCerts); |
||
| 513 | fclose($fileHandleCerts); |
||
| 514 | } |
||
| 515 | |||
| 516 | /** |
||
| 517 | * copies various files into temp dir for inclusion into installer |
||
| 518 | * |
||
| 519 | * @param array $eap EAP type being configured, in array notation |
||
| 520 | * @return boolean true if things worked (and throws an Exception if not) |
||
| 521 | * @throws Exception |
||
| 522 | */ |
||
| 523 | private function copyFiles($eap) |
||
| 542 | } |
||
| 543 | |||
| 544 | /** |
||
| 545 | * should a different username be prompted for when using EAP-TLS? |
||
| 546 | * |
||
| 547 | * @var boolean |
||
| 548 | */ |
||
| 549 | private $tlsOtherUsername = false; |
||
| 550 | |||
| 552 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths