| Total Complexity | 59 |
| Total Lines | 332 |
| Duplicated Lines | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
Complex classes like DeviceW8W10 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 DeviceW8W10, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 45 | class DeviceW8W10 extends \devices\ms\WindowsCommon |
||
| 46 | { |
||
| 47 | public function __construct() |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * create the actual installer executable |
||
| 67 | * |
||
| 68 | * @return string filename of the generated installer |
||
| 69 | * |
||
| 70 | */ |
||
| 71 | public function writeInstaller() |
||
| 72 | { |
||
| 73 | \core\common\Entity::intoThePotatoes(); |
||
| 74 | $this->prepareInstallerLang(); |
||
| 75 | $this->setupEapConfig(); |
||
| 76 | $setWired = isset($this->attributes['media:wired'][0]) && $this->attributes['media:wired'][0] == 'on' ? 1 : 0; |
||
| 77 | $this->iterator = 0; |
||
| 78 | $fcontentsProfile = ''; |
||
| 79 | $this->createProfileDir(); |
||
| 80 | foreach ($this->attributes['internal:networks'] as $networkName => $oneNetwork) { |
||
| 81 | if ($this::separateHS20profiles === true) { |
||
| 82 | $fcontentsProfile .= $this->saveNetworkProfileSeparateHS($networkName, $oneNetwork); |
||
| 83 | } else { |
||
| 84 | $fcontentsProfile .= $this->saveNetworkProfileJoinedHS($networkName, $oneNetwork); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | file_put_contents('profiles.nsh', $fcontentsProfile); |
||
| 88 | $delSSIDs = $this->attributes['internal:remove_SSID']; |
||
| 89 | $delProfiles = []; |
||
| 90 | foreach ($delSSIDs as $ssid => $cipher) { |
||
| 91 | if ($cipher == 'DEL') { |
||
| 92 | $delProfiles[] = $ssid; |
||
| 93 | } |
||
| 94 | if ($cipher == 'TKIP') { |
||
| 95 | $delProfiles[] = $ssid.' (TKIP)'; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | // this removes the profile container that we used in CAT 2.1 and removed in 2.1.1 |
||
| 99 | $delProfiles[] = sprintf('%s Custom Network', \core\CAT::$nomenclature_participant); |
||
| 100 | $this->writeAdditionalDeletes($delProfiles); |
||
| 101 | if ($setWired) { |
||
| 102 | $this->loggerInstance->debug(4, "Saving LAN profile\n"); |
||
| 103 | $windowsProfile = $this->generateLANprofile(); |
||
| 104 | $this->saveProfile($windowsProfile); |
||
| 105 | } |
||
| 106 | $this->saveCerts(); |
||
| 107 | if ($this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) { |
||
| 108 | $this->writeClientP12File(); |
||
| 109 | } |
||
| 110 | $this->copyFiles($this->selectedEap); |
||
| 111 | $this->saveLogo(); |
||
| 112 | $this->writeMainNSH($this->selectedEap, $this->attributes); |
||
| 113 | $this->compileNSIS(); |
||
| 114 | $installerPath = $this->signInstaller(); |
||
| 115 | \core\common\Entity::outOfThePotatoes(); |
||
| 116 | return $installerPath; |
||
| 117 | } |
||
| 118 | |||
| 119 | private function createProfileDir() |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * If separateHS20profiles is true then we should be saving OID and SSID |
||
| 128 | * profiles separately. OID profiles should be considered optionl, i.e. |
||
| 129 | * the installer should not report installation failure (??). If we decide |
||
| 130 | * that such installation failures should be silent then it is enough if |
||
| 131 | * these profiles are marked as hs20 and no "nohs" profiles are created |
||
| 132 | */ |
||
| 133 | |||
| 134 | private function saveNetworkProfileSeparateHS($profileName, $network) |
||
| 135 | { |
||
| 136 | $out = ''; |
||
| 137 | if (!empty($network['ssid'])) { |
||
| 138 | if ($this::separateSSIDprofiles === true && !empty($network['condition']) && $network['condition'] === 'locally_defined') { |
||
| 139 | $out = ""; |
||
| 140 | foreach ($network['ssid'] as $ssid) { |
||
| 141 | $this->loggerInstance->debug(4, "SSID network: $ssid\n"); |
||
| 142 | $windowsProfileSSID = $this->generateWlanProfile($ssid, [$ssid], 'WPA2', 'AES', [], false); |
||
| 143 | $this->saveProfile($windowsProfileSSID, $this->iterator, true); |
||
| 144 | $out .= "!insertmacro define_wlan_profile \"$ssid\" \"AES\" 0 \"0\"\n"; |
||
| 145 | $this->iterator++; |
||
| 146 | } |
||
| 147 | } else { |
||
| 148 | $this->loggerInstance->debug(4, "SSID network: $profileName\n"); |
||
| 149 | $windowsProfileSSID = $this->generateWlanProfile($profileName, $network['ssid'], 'WPA2', 'AES', [], false); |
||
| 150 | $this->saveProfile($windowsProfileSSID, $this->iterator, true); |
||
| 151 | $ssids = ''; |
||
| 152 | foreach ($network['ssid'] as $ssid) { |
||
| 153 | if ($ssid != $profileName) { |
||
| 154 | $ssids .= '|'.$ssid; |
||
| 155 | } |
||
| 156 | } |
||
| 157 | $out = "!insertmacro define_wlan_profile \"$profileName\" \"AES\" 0 \"$ssids\"\n"; |
||
| 158 | $this->iterator++; |
||
| 159 | } |
||
| 160 | $profileName .= " via partner"; |
||
| 161 | } |
||
| 162 | if (!empty($network['oi'])) { |
||
| 163 | $this->loggerInstance->debug(4, "RCOI network: $profileName\n"); |
||
| 164 | $windowsProfileHS = $this->generateWlanProfile($profileName, ['cat-passpoint-profile'], 'WPA2', 'AES', $network['oi'], true); |
||
| 165 | $this->saveProfile($windowsProfileHS, $this->iterator, true); |
||
| 166 | $out .= "!insertmacro define_wlan_profile \"$profileName\" \"AES\" 1 \"0\"\n"; |
||
| 167 | $this->iterator++; |
||
| 168 | } |
||
| 169 | return($out); |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * If separateHS20profiles is false then we should be saving a hs20 profile |
||
| 174 | * containing both OIDs and SSIDs. In addition we should also be saving |
||
| 175 | * a nohs_... profile. When the installer runs it first tries the normal |
||
| 176 | * profile and if this fails it will try the nohs (if one exists) |
||
| 177 | */ |
||
| 178 | |||
| 179 | private function saveNetworkProfileJoinedHS($profileName, $network) |
||
| 180 | { |
||
| 181 | $oiOnly = false; |
||
| 182 | if ($network['ssid'] == []) { |
||
| 183 | $oiOnly = true; |
||
| 184 | $network['ssid'] = ['cat-passpoint-profile']; |
||
| 185 | } |
||
| 186 | $windowsProfile = $this->generateWlanProfile($profileName, $network['ssid'], 'WPA2', 'AES', $network['oi'], true); |
||
| 187 | $this->saveProfile($windowsProfile, $this->iterator, true); |
||
| 188 | if (!$oiOnly) { |
||
| 189 | $windowsProfile = $this->generateWlanProfile($profileName, $network['ssid'], 'WPA2', 'AES', [], false); |
||
| 190 | $this->saveProfile($windowsProfile, $this->iterator, false); |
||
| 191 | } |
||
| 192 | $this->iterator++; |
||
| 193 | return("!insertmacro define_wlan_profile \"$profileName\" \"AES\" 2 \"".implode('|', $network['ssid'])."\"\n"); |
||
| 194 | } |
||
| 195 | |||
| 196 | private function saveLogo() |
||
| 201 | } |
||
| 202 | |||
| 203 | private function writeMainNSH($eap, $attr) |
||
| 204 | { |
||
| 205 | $this->loggerInstance->debug(4, "writeMainNSH"); |
||
| 206 | $this->loggerInstance->debug(4, $attr); |
||
| 207 | $this->loggerInstance->debug(4, "Device_id = ".$this->device_id."\n"); |
||
| 208 | $fcontents = "!define W8\n"; |
||
| 209 | if ($this->device_id == 'w10') { |
||
| 210 | $fcontents .= "!define W10\n"; |
||
| 211 | } |
||
| 212 | $fcontents .= "Unicode true\n"; |
||
| 213 | if ($this->useGeantLink && $this->selectedEap['OUTER'] == \core\common\EAP::TTLS) { |
||
| 214 | $eapStr = 'GEANTLink'; |
||
| 215 | } else { |
||
| 216 | $eapStr = \core\common\EAP::eapDisplayName($this->selectedEap)['OUTER']; |
||
| 217 | } |
||
| 218 | if (isset($this->tlsOtherUsername) && $this->tlsOtherUsername == 1) { |
||
| 219 | $fcontents .= "!define PFX_USERNAME\n"; |
||
| 220 | } |
||
| 221 | if ($eap == \core\common\EAP::EAPTYPE_SILVERBULLET) { |
||
| 222 | $fcontents .= "!define SILVERBULLET\n"; |
||
| 223 | } |
||
| 224 | $fcontents .= '!define '.$eapStr; |
||
| 225 | $fcontents .= "\n".'!define EXECLEVEL "user"'; |
||
| 226 | $fcontents .= $this->writeNsisDefines($attr); |
||
| 227 | file_put_contents('main.nsh', $fcontents); |
||
| 228 | } |
||
| 229 | |||
| 230 | |||
| 231 | private function copyFiles($eap) |
||
| 248 | } |
||
| 249 | |||
| 250 | private function copyStandardNsi() |
||
| 251 | { |
||
| 252 | if (!$this->translateFile('eap_w8.inc', 'cat.NSI')) { |
||
| 253 | throw new Exception("Translating needed file eap_w8.inc failed!"); |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | private function saveCerts() |
||
| 271 | } |
||
| 272 | |||
| 273 | /* saveProvile writes a LAN or WLAN profile |
||
| 274 | * @param string $profile the XML content to be saved |
||
| 275 | * @param int $profileNumber the profile index or NULL to indicate a LAN profile |
||
| 276 | * @param boolean $hs20 for WLAN profiles indicates if use the nohs prefix |
||
| 277 | */ |
||
| 278 | private function saveProfile($profile, $profileNumber = NULL, $hs20 = false) |
||
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Selects the appropriate handler for a given EAP type and retirns |
||
| 298 | * an initiated object |
||
| 299 | * |
||
| 300 | * @return a profile object |
||
|
|
|||
| 301 | */ |
||
| 302 | |||
| 303 | private function setEapObject() |
||
| 319 | } |
||
| 320 | } |
||
| 321 | |||
| 322 | private function setupEapConfig() { |
||
| 323 | $servers = empty($this->attributes['eap:server_name']) ? '' : implode(';', $this->attributes['eap:server_name']); |
||
| 324 | $outerId = $this->determineOuterIdString(); |
||
| 325 | $nea = (\core\common\Entity::getAttributeValue($this->attributes, 'media:wired', 0) === 'on') ? 'true' : 'false'; |
||
| 326 | $otherTlsName = \core\common\Entity::getAttributeValue($this->attributes, 'eap-specific:tls_use_other_id', 0) === 'on' ? 'true' : 'false'; |
||
| 327 | if (isset(\core\common\Entity::getAttributeValue($this->attributes, 'device-specific:geantlink', $this->device_id)[0]) && |
||
| 328 | \core\common\Entity::getAttributeValue($this->attributes, 'device-specific:geantlink', $this->device_id)[0] === 'on') { |
||
| 329 | $this->useGeantLink = true; |
||
| 330 | } else { |
||
| 331 | $this->useGeantLink = false; |
||
| 332 | } |
||
| 333 | $eapConfig = $this->setEapObject(); |
||
| 334 | $eapConfig->setInnerType($this->selectedEap['INNER']); |
||
| 335 | $eapConfig->setInnerTypeDisplay(\core\common\EAP::eapDisplayName($this->selectedEap)['INNER']); |
||
| 336 | $eapConfig->setCAList($this->getAttribute('internal:CAs')[0]); |
||
| 337 | $eapConfig->setServerNames($servers); |
||
| 338 | $eapConfig->setOuterId($outerId); |
||
| 339 | $eapConfig->setNea($nea); |
||
| 340 | $eapConfig->setDisplayName($this->translateString($this->attributes['general:instname'][0])); |
||
| 341 | $eapConfig->setIdPId($this->deviceUUID); |
||
| 342 | $eapConfig->setOtherTlsName($otherTlsName); |
||
| 343 | $eapConfig->setConfig(); |
||
| 344 | $this->eapConfigObject = $eapConfig; |
||
| 345 | } |
||
| 346 | |||
| 347 | private function generateWlanProfile($networkName, $ssids, $authentication, $encryption, $ois, $hs20 = false) |
||
| 363 | } |
||
| 364 | |||
| 365 | private function generateLanProfile() |
||
| 370 | } |
||
| 371 | |||
| 372 | private $eapTypeId; |
||
| 373 | private $eapAuthorId; |
||
| 374 | private $eapConfigObject; |
||
| 375 | private $profileNames; |
||
| 376 | private $iterator; |
||
| 377 | } |
||
| 381 |