| Total Complexity | 57 |
| Total Lines | 647 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like MobileconfigSuperclass 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 MobileconfigSuperclass, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 43 | abstract class MobileconfigSuperclass extends \core\DeviceConfig { |
||
| 44 | |||
| 45 | private $instName; |
||
| 46 | private $profileName; |
||
| 47 | private $massagedInst; |
||
| 48 | private $massagedProfile; |
||
| 49 | private $massagedCountry; |
||
| 50 | private $massagedConsortium; |
||
| 51 | private $lang; |
||
| 52 | static private $iPhonePayloadPrefix = "org.1x-config"; |
||
| 53 | private $clientCertUUID; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * construct with the standard set of EAP methods we support, and preload |
||
| 57 | * specialities |
||
| 58 | */ |
||
| 59 | public function __construct() { |
||
| 60 | parent::__construct(); |
||
| 61 | \core\common\Entity::intoThePotatoes(); |
||
| 62 | // that's what all variants support. Sub-classes can change it. |
||
| 63 | $this->setSupportedEapMethods([\core\common\EAP::EAPTYPE_PEAP_MSCHAP2, \core\common\EAP::EAPTYPE_TTLS_PAP, \core\common\EAP::EAPTYPE_TTLS_MSCHAP2, \core\common\EAP::EAPTYPE_SILVERBULLET]); |
||
| 64 | $this->specialities['internal:verify_userinput_suffix'] = _("It is not possible to actively verify the user input for suffix match; but if there is no 'Terms of Use' configured, the installer will display a corresponding hint to the user instead."); |
||
| 65 | \core\common\Entity::outOfThePotatoes(); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * massage a name so that it becomes acceptable inside the plist XML |
||
| 70 | * |
||
| 71 | * @param string $input the literal name |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | private function massageName($input) { |
||
| 75 | return htmlspecialchars(strtolower(iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace(['/ /', '/\//'], '_', $input))), ENT_XML1, 'UTF-8'); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * the general part of a mobileconfig file in plist format |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | private function generalPayload() { |
||
| 109 | } |
||
| 110 | |||
| 111 | const FILE_START = "<?xml version=\"1.0\" encoding=\"utf-8\"?> |
||
| 112 | <!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" |
||
| 113 | \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> |
||
| 114 | <plist version=\"1.0\"> |
||
| 115 | <dict>"; |
||
| 116 | const FILE_END = "</dict></plist>"; |
||
| 117 | const BUFFER_CONSENT_PRE = " |
||
| 118 | <key>ConsentText</key> |
||
| 119 | <dict> |
||
| 120 | <key>default</key> |
||
| 121 | <string>"; |
||
| 122 | const BUFFER_CONSENT_POST = "</string> |
||
| 123 | </dict> |
||
| 124 | "; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * creates a ConsentText block if either Terms of Use are specified or the |
||
| 128 | * user input hints should be displayed. Otherwise, produces nothing. |
||
| 129 | * |
||
| 130 | * @return string |
||
| 131 | */ |
||
| 132 | protected function consentBlock() { |
||
| 133 | \core\common\Entity::intoThePotatoes(); |
||
| 134 | if (isset($this->attributes['support:info_file'])) { |
||
| 135 | return MobileconfigSuperclass::BUFFER_CONSENT_PRE . htmlspecialchars(iconv("UTF-8", "UTF-8//TRANSLIT", $this->attributes['support:info_file'][0]), ENT_XML1, 'UTF-8') . MobileconfigSuperclass::BUFFER_CONSENT_POST; |
||
| 136 | } |
||
| 137 | if ($this->attributes['internal:verify_userinput_suffix'][0] != 0) { |
||
| 138 | if (strlen($this->attributes['internal:realm'][0]) > 0) { |
||
| 139 | $retval =MobileconfigSuperclass::BUFFER_CONSENT_PRE . sprintf(_("Important Notice: your username must end with @%s!"), $this->attributes['internal:realm'][0]) . MobileconfigSuperclass::BUFFER_CONSENT_POST; |
||
| 140 | \core\common\Entity::outOfThePotatoes(); |
||
| 141 | return $retval; |
||
| 142 | } |
||
| 143 | $retval = MobileconfigSuperclass::BUFFER_CONSENT_PRE . _("Important Notice: your username MUST be in the form of xxx@yyy where the yyy is a common suffix identifying your Identity Provider. Please find out what to use there and enter the username in the correct format.") . MobileconfigSuperclass::BUFFER_CONSENT_POST; |
||
| 144 | \core\common\Entity::outOfThePotatoes(); |
||
| 145 | return $retval; |
||
| 146 | } |
||
| 147 | \core\common\Entity::outOfThePotatoes(); |
||
| 148 | return ""; |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * create the actual installer XML file |
||
| 153 | * |
||
| 154 | * @return string filename of the generated installer |
||
| 155 | * |
||
| 156 | */ |
||
| 157 | public function writeInstaller() { |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
| 229 | * produces the HTML text to be displayed when clicking on the "help" button |
||
| 230 | * besides the download button. |
||
| 231 | * |
||
| 232 | * @return string |
||
| 233 | */ |
||
| 234 | public function writeDeviceInfo() { |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * collates a list of the UUIDs of all the CAs which are to be included in |
||
| 261 | * the mobileconfig file |
||
| 262 | * |
||
| 263 | * @return array |
||
| 264 | */ |
||
| 265 | private function listCAUuids() { |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * This is the XML structure subtree of a Network block which contains the |
||
| 275 | * settings specific to Passpoint |
||
| 276 | * |
||
| 277 | * @param array $consortiumOi list of consortiumOi to put into structure |
||
| 278 | * @return string |
||
| 279 | */ |
||
| 280 | private function passPointBlock($consortiumOi) { |
||
| 281 | $retval = " |
||
| 282 | <key>IsHotspot</key> |
||
| 283 | <true/> |
||
| 284 | <key>ServiceProviderRoamingEnabled</key> |
||
| 285 | <true/> |
||
| 286 | <key>DisplayedOperatorName</key> |
||
| 287 | <string>" . CONFIG_CONFASSISTANT['CONSORTIUM']['display_name'] . " via Passpoint</string>"; |
||
| 288 | // if we don't know the realm, omit the entire DomainName key |
||
| 289 | if (isset($this->attributes['internal:realm'])) { |
||
| 290 | $retval .= "<key>DomainName</key> |
||
| 291 | <string>"; |
||
| 292 | $retval .= $this->attributes['internal:realm'][0]; |
||
| 293 | $retval .= "</string> |
||
| 294 | "; |
||
| 295 | } |
||
| 296 | $retval .= " <key>RoamingConsortiumOIs</key> |
||
| 297 | <array>"; |
||
| 298 | foreach ($consortiumOi as $oiValue) { |
||
| 299 | $retval .= "<string>$oiValue</string>"; |
||
| 300 | } |
||
| 301 | $retval .= "</array>"; |
||
| 302 | // this is an undocmented value found on the net. Does it do something useful? |
||
| 303 | $retval .= "<key>_UsingHotspot20</key> |
||
| 304 | <true/> |
||
| 305 | "; |
||
| 306 | // do we need to set NAIRealmName ? In Rel 1, probably yes, in Rel 2, |
||
| 307 | // no because ConsortiumOI is enough. |
||
| 308 | // but which release is OS X doing? And what should we fill in, given |
||
| 309 | // that we have thousands of realms? Try just eduroam.org |
||
| 310 | // |
||
| 311 | // tests from Hideaki suggest it's better not to set it; if Roaming |
||
| 312 | // consortium OI and NAIRealmNames are both set, connecting to a hotspot |
||
| 313 | // with just RCOI does not work |
||
| 314 | /* if (CONFIG_CONFASSISTANT['CONSORTIUM']['name'] == "eduroam") { |
||
| 315 | $retval .= "<key>NAIRealmNames</key> |
||
| 316 | <array> |
||
| 317 | <string>eduroam.org</string> |
||
| 318 | </array>"; |
||
| 319 | }*/ |
||
| 320 | return $retval; |
||
| 321 | } |
||
| 322 | |||
| 323 | private $serial; |
||
| 324 | private $removeSerial; |
||
| 325 | private $caSerial; |
||
| 326 | |||
| 327 | /** |
||
| 328 | * produces the EAP sub-block of a Network block |
||
| 329 | * |
||
| 330 | * @param array $eapType EAP type in array notation |
||
| 331 | * @return string |
||
| 332 | */ |
||
| 333 | private function eapBlock($eapType) { |
||
| 334 | $realm = $this->determineOuterIdString(); |
||
| 335 | $retval = "<key>EAPClientConfiguration</key> |
||
| 336 | <dict> |
||
| 337 | <key>AcceptEAPTypes</key> |
||
| 338 | <array> |
||
| 339 | <integer>" . $eapType['OUTER'] . "</integer> |
||
| 340 | </array> |
||
| 341 | <key>EAPFASTProvisionPAC</key> |
||
| 342 | <true /> |
||
| 343 | <key>EAPFASTUsePAC</key> |
||
| 344 | <true /> |
||
| 345 | <key>EAPFastProvisionPACAnonymously</key> |
||
| 346 | <false /> |
||
| 347 | <key>OneTimeUserPassword</key> |
||
| 348 | <false /> |
||
| 349 | "; |
||
| 350 | if ($realm !== NULL) { |
||
| 351 | $retval .= "<key>OuterIdentity</key> |
||
| 352 | <string>" . htmlspecialchars($realm, ENT_XML1, 'UTF-8') . "</string> |
||
| 353 | "; |
||
| 354 | } |
||
| 355 | $retval .= "<key>PayloadCertificateAnchorUUID</key> |
||
| 356 | <array>"; |
||
| 357 | foreach ($this->listCAUuids() as $uuid) { |
||
| 358 | if (in_array($uuid, $this->CAsAccountedFor)) { |
||
| 359 | $retval .= " |
||
| 360 | <string>$uuid</string>"; |
||
| 361 | } |
||
| 362 | } |
||
| 363 | $retval .= " |
||
| 364 | </array> |
||
| 365 | <key>TLSAllowTrustExceptions</key> |
||
| 366 | <false /> |
||
| 367 | <key>TLSTrustedServerNames</key> |
||
| 368 | <array>"; |
||
| 369 | foreach ($this->attributes['eap:server_name'] as $commonName) { |
||
| 370 | $retval .= " |
||
| 371 | <string>$commonName</string>"; |
||
| 372 | } |
||
| 373 | $retval .= " |
||
| 374 | </array>"; |
||
| 375 | if ($eapType['INNER'] == \core\common\EAP::NE_SILVERBULLET) { |
||
| 376 | $retval .= "<key>UserName</key><string>" . $this->clientCert["certObject"]->username . "</string>"; |
||
| 377 | } |
||
| 378 | $retval .= " |
||
| 379 | <key>TTLSInnerAuthentication</key> |
||
| 380 | <string>" . ($eapType['INNER'] == \core\common\EAP::NONE ? "PAP" : "MSCHAPv2") . "</string> |
||
| 381 | </dict>"; |
||
| 382 | return $retval; |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * produces the Proxy sub-block of a Network block |
||
| 387 | * |
||
| 388 | * @return string |
||
| 389 | */ |
||
| 390 | protected function proxySettings() { |
||
| 410 | } |
||
| 411 | |||
| 412 | /** |
||
| 413 | * produces an entire Network block |
||
| 414 | * |
||
| 415 | * @param int $blocktype which type of network block is this? |
||
| 416 | * @param string|array|boolean $toBeConfigured variable part of the config. Single SSID or list of ConsortiumOi |
||
| 417 | * @return string |
||
| 418 | * @throws Exception |
||
| 419 | */ |
||
| 420 | private function networkBlock($blocktype, $toBeConfigured) { |
||
| 421 | \core\common\Entity::intoThePotatoes(); |
||
| 422 | $eapType = $this->selectedEap; |
||
| 423 | switch ($blocktype) { |
||
| 424 | case MobileconfigSuperclass::NETWORK_BLOCK_TYPE_SSID: |
||
| 425 | if (!is_string($toBeConfigured)) { |
||
| 426 | throw new Exception("SSID must be a string!"); |
||
| 427 | } |
||
| 428 | $escapedSSID = htmlspecialchars($toBeConfigured, ENT_XML1, 'UTF-8'); |
||
| 429 | $payloadIdentifier = "wifi." . $this->serial; |
||
| 430 | $payloadShortName = sprintf(_("SSID %s"), $escapedSSID); |
||
| 431 | $payloadName = sprintf(_("%s configuration for network name %s"), CONFIG_CONFASSISTANT['CONSORTIUM']['display_name'], $escapedSSID); |
||
| 432 | $encryptionTypeString = "WPA"; |
||
| 433 | $setupModesString = ""; |
||
| 434 | $wifiNetworkIdentification = "<key>SSID_STR</key> |
||
| 435 | <string>$escapedSSID</string>"; |
||
| 436 | break; |
||
| 437 | case MobileconfigSuperclass::NETWORK_BLOCK_TYPE_WIRED: |
||
| 438 | if (!is_bool($toBeConfigured)) { |
||
| 439 | throw new Exception("We expected a TRUE here!"); |
||
| 440 | } |
||
| 441 | $payloadIdentifier = "firstactiveethernet"; |
||
| 442 | $payloadShortName = _("Wired Network"); |
||
| 443 | $payloadName = sprintf(_("%s configuration for wired network"), CONFIG_CONFASSISTANT['CONSORTIUM']['display_name']); |
||
| 444 | $encryptionTypeString = "any"; |
||
| 445 | $setupModesString = " |
||
| 446 | <key>SetupModes</key> |
||
| 447 | <array> |
||
| 448 | <string>System</string> |
||
| 449 | </array>"; |
||
| 450 | $wifiNetworkIdentification = ""; |
||
| 451 | break; |
||
| 452 | case MobileconfigSuperclass::NETWORK_BLOCK_TYPE_CONSORTIUMOIS: |
||
| 453 | if (!is_array($toBeConfigured)) { |
||
| 454 | throw new Exception("ConsortiumOI list must be an array!"); |
||
| 455 | } |
||
| 456 | $payloadIdentifier = "hs20"; |
||
| 457 | $payloadShortName = _("Hotspot 2.0 Settings"); |
||
| 458 | $payloadName = sprintf(_("%s Hotspot 2.0 configuration"), CONFIG_CONFASSISTANT['CONSORTIUM']['display_name']); |
||
| 459 | $encryptionTypeString = "WPA"; |
||
| 460 | $setupModesString = ""; |
||
| 461 | $wifiNetworkIdentification = $this->passPointBlock($toBeConfigured); |
||
| 462 | break; |
||
| 463 | default: |
||
| 464 | throw new Exception("This type of network block is unknown!"); |
||
| 465 | } |
||
| 466 | $retval = "<dict>"; |
||
| 467 | $retval .= $this->eapBlock($eapType); |
||
| 468 | $retval .= "<key>EncryptionType</key> |
||
| 469 | <string>$encryptionTypeString</string> |
||
| 470 | <key>HIDDEN_NETWORK</key> |
||
| 471 | <true /> |
||
| 472 | <key>PayloadDescription</key> |
||
| 473 | <string>$payloadName</string> |
||
| 474 | <key>PayloadDisplayName</key> |
||
| 475 | <string>$payloadShortName</string> |
||
| 476 | <key>PayloadIdentifier</key> |
||
| 477 | <string>" . self::$iPhonePayloadPrefix . ".$this->massagedConsortium.$this->massagedCountry.$this->massagedInst.$this->massagedProfile.$this->lang.$payloadIdentifier</string> |
||
| 478 | <key>PayloadOrganization</key> |
||
| 479 | <string>" . $this->massagedConsortium . ".1x-config.org</string> |
||
| 480 | <key>PayloadType</key> |
||
| 481 | <string>com.apple." . ($blocktype == MobileconfigSuperclass::NETWORK_BLOCK_TYPE_WIRED ? "firstactiveethernet" : "wifi") . ".managed</string>"; |
||
| 482 | $retval .= $this->proxySettings(); |
||
| 483 | $retval .= $setupModesString; |
||
| 484 | if ($eapType['INNER'] == \core\common\EAP::NE_SILVERBULLET) { |
||
| 485 | if ($this->clientCertUUID === NULL) { |
||
| 486 | throw new Exception("Silverbullet REQUIRES a client certificate and we need to know the UUID!"); |
||
| 487 | } |
||
| 488 | $retval .= "<key>PayloadCertificateUUID</key> |
||
| 489 | <string>$this->clientCertUUID</string>"; |
||
| 490 | } |
||
| 491 | $retval .= " |
||
| 492 | <key>PayloadUUID</key> |
||
| 493 | <string>" . \core\common\Entity::uuid() . "</string> |
||
| 494 | <key>PayloadVersion</key> |
||
| 495 | <integer>1</integer> |
||
| 496 | $wifiNetworkIdentification</dict>"; |
||
| 497 | $this->serial = $this->serial + 1; |
||
| 498 | \core\common\Entity::outOfThePotatoes(); |
||
| 499 | return $retval; |
||
| 500 | } |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Produces a Network block which sets a network to manual join (we don't |
||
| 504 | * get any closer to removing a network in mobileconfig) |
||
| 505 | * |
||
| 506 | * @param string $ssid the SSID to set to manual join only |
||
| 507 | * @return string |
||
| 508 | */ |
||
| 509 | private function removenetworkBlock($ssid) { |
||
| 510 | \core\common\Entity::intoThePotatoes(); |
||
| 511 | $retval = " |
||
| 512 | <dict> |
||
| 513 | <key>AutoJoin</key> |
||
| 514 | <false/> |
||
| 515 | <key>EncryptionType</key> |
||
| 516 | <string>None</string> |
||
| 517 | <key>HIDDEN_NETWORK</key> |
||
| 518 | <false/> |
||
| 519 | <key>IsHotspot</key> |
||
| 520 | <false/> |
||
| 521 | <key>PayloadDescription</key> |
||
| 522 | <string>" . sprintf(_("This SSID should not be used after bootstrapping %s"), CONFIG_CONFASSISTANT['CONSORTIUM']['display_name']) . "</string> |
||
| 523 | <key>PayloadDisplayName</key> |
||
| 524 | <string>" . _("Disabled WiFi network") . "</string> |
||
| 525 | <key>PayloadIdentifier</key> |
||
| 526 | <string>" . self::$iPhonePayloadPrefix . ".$this->massagedConsortium.$this->massagedCountry.$this->massagedInst.$this->massagedProfile.$this->lang.wifi.disabled.$this->removeSerial</string> |
||
| 527 | <key>PayloadType</key> |
||
| 528 | <string>com.apple.wifi.managed</string> |
||
| 529 | <key>PayloadUUID</key> |
||
| 530 | <string>" . \core\common\Entity::uuid() . "</string> |
||
| 531 | <key>PayloadVersion</key> |
||
| 532 | <real>1</real>"; |
||
| 533 | $retval .= $this->proxySettings(); |
||
| 534 | $retval .= "<key>SSID_STR</key> |
||
| 535 | <string>$ssid</string> |
||
| 536 | </dict> |
||
| 537 | "; |
||
| 538 | \core\common\Entity::outOfThePotatoes(); |
||
| 539 | return $retval; |
||
| 540 | } |
||
| 541 | |||
| 542 | const NETWORK_BLOCK_TYPE_SSID = 100; |
||
| 543 | const NETWORK_BLOCK_TYPE_CONSORTIUMOIS = 101; |
||
| 544 | const NETWORK_BLOCK_TYPE_WIRED = 102; |
||
| 545 | |||
| 546 | /** |
||
| 547 | * produces the entire series of Network blocks; all for SSID-based, |
||
| 548 | * Passpoint-based, wired, and manual-select only SSIDs |
||
| 549 | * |
||
| 550 | * @return string |
||
| 551 | */ |
||
| 552 | private function allNetworkBlocks() { |
||
| 553 | $retval = ""; |
||
| 554 | $this->serial = 0; |
||
| 555 | |||
| 556 | foreach (array_keys($this->attributes['internal:SSID']) as $ssid) { |
||
| 557 | $retval .= $this->networkBlock(MobileconfigSuperclass::NETWORK_BLOCK_TYPE_SSID, $ssid); |
||
| 558 | } |
||
| 559 | if (isset($this->attributes['media:wired']) && get_class($this) == "devices\apple_mobileconfig\Device_mobileconfig_os_x") { |
||
| 560 | $retval .= $this->networkBlock(MobileconfigSuperclass::NETWORK_BLOCK_TYPE_WIRED, TRUE); |
||
| 561 | } |
||
| 562 | if (count($this->attributes['internal:consortia']) > 0) { |
||
| 563 | $retval .= $this->networkBlock(MobileconfigSuperclass::NETWORK_BLOCK_TYPE_CONSORTIUMOIS, $this->attributes['internal:consortia']); |
||
| 564 | } |
||
| 565 | if (isset($this->attributes['media:remove_SSID'])) { |
||
| 566 | $this->removeSerial = 0; |
||
| 567 | foreach ($this->attributes['media:remove_SSID'] as $removeSSID) { |
||
| 568 | $retval .= $this->removenetworkBlock($removeSSID); |
||
| 569 | $this->removeSerial = $this->removeSerial + 1; |
||
| 570 | } |
||
| 571 | } |
||
| 572 | return $retval; |
||
| 573 | } |
||
| 574 | |||
| 575 | /** |
||
| 576 | * collates a block with all CAs that are to be included in the mobileconfig |
||
| 577 | * |
||
| 578 | * @return string |
||
| 579 | */ |
||
| 580 | private function allCA() { |
||
| 581 | $retval = ""; |
||
| 582 | $this->caSerial = 0; |
||
| 583 | foreach ($this->attributes['internal:CAs'][0] as $ca) { |
||
| 584 | $retval .= $this->caBlob($ca); |
||
| 585 | $this->caSerial = $this->caSerial + 1; |
||
| 586 | } |
||
| 587 | return $retval; |
||
| 588 | } |
||
| 589 | |||
| 590 | /** |
||
| 591 | * creates a Cert block containing a client certificate (used in SB only) |
||
| 592 | * @return array the block itself, and the UUID of the certificate |
||
| 593 | * @throws Exception |
||
| 594 | */ |
||
| 595 | private function clientP12Block() { |
||
| 630 | } |
||
| 631 | |||
| 632 | /** |
||
| 633 | * creates an Expiry block. This is only done in SB; the profile expires |
||
| 634 | * when the client cert expires. |
||
| 635 | * |
||
| 636 | * @return string |
||
| 637 | * @throws Exception |
||
| 638 | */ |
||
| 639 | private function expiryBlock() { |
||
| 646 | } |
||
| 647 | |||
| 648 | private $CAsAccountedFor = []; |
||
| 649 | |||
| 650 | /** |
||
| 651 | * creates a block for one single CA |
||
| 652 | * |
||
| 653 | * @param array $ca the CA for which to generate the XML block |
||
| 654 | * @return string |
||
| 655 | */ |
||
| 656 | private function caBlob($ca) { |
||
| 690 | } |
||
| 691 | |||
| 693 |