| Total Complexity | 53 |
| Total Lines | 355 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like DeviceLinuxSh 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 DeviceLinuxSh, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class DeviceLinuxSh extends \core\DeviceConfig { |
||
| 32 | /** |
||
| 33 | * constructor. Sets supported EAP methods. |
||
| 34 | */ |
||
| 35 | final public function __construct() { |
||
| 36 | parent::__construct(); |
||
| 37 | $this->setSupportedEapMethods([\core\common\EAP::EAPTYPE_PEAP_MSCHAP2, \core\common\EAP::EAPTYPE_TTLS_PAP, \core\common\EAP::EAPTYPE_TTLS_MSCHAP2, \core\common\EAP::EAPTYPE_TLS, \core\common\EAP::EAPTYPE_SILVERBULLET]); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * create the actual installer script |
||
| 42 | * |
||
| 43 | * @return string filename of the generated installer |
||
| 44 | * @throws Exception |
||
| 45 | * |
||
| 46 | */ |
||
| 47 | public function writeInstaller() { |
||
| 48 | $installerPath = $this->installerBasename . ".py"; |
||
| 49 | $this->copyFile("eduroam_linux_main.sh", $installerPath); |
||
| 50 | $installer = fopen($installerPath, "a"); |
||
| 51 | if ($installer === FALSE) { |
||
| 52 | throw new Exception("Unable to open installer file for writing!"); |
||
| 53 | } |
||
| 54 | fwrite($installer, "\n\n"); |
||
| 55 | $this->fseek($installer, 0, SEEK_END); |
||
|
|
|||
| 56 | $this->writeMessages($installer); |
||
| 57 | $this->writeConfigVars($installer); |
||
| 58 | fwrite($installer, "printf -v INIT_INFO \"$INIT_INFO_TMP\" \"$ORGANISATION\" \"$E_MAIL\" \"$URL\"\n"); |
||
| 59 | fwrite($installer, "printf -v INIT_CONFIRMATION \"$INIT_CONFIRMATION_TMP\" \"$ORGANISATION\""); |
||
| 60 | fwrite($installer, "main \"$@\"; exit\n"); |
||
| 61 | fclose($installer); |
||
| 62 | return($installerPath); |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * produces the HTML text to be displayed when clicking on the "help" button |
||
| 67 | * besides the download button. |
||
| 68 | * |
||
| 69 | * @return string |
||
| 70 | */ |
||
| 71 | public function writeDeviceInfo() { |
||
| 72 | \core\common\Entity::intoThePotatoes(); |
||
| 73 | $ssidCount = count($this->attributes['internal:SSID']); |
||
| 74 | $out = ''; |
||
| 75 | |||
| 76 | $out .= sprintf(_("The installer is in the form of a Python script. It will try to configure %s under NetworkManager and if this is either not appropriate for your system or your version of NetworkManager is too old, a wpa_supplicant config file will be created instead."), \config\ConfAssistant::CONSORTIUM['display_name']); |
||
| 77 | $out .= "<p>"; |
||
| 78 | if ($ssidCount > 1) { |
||
| 79 | if ($ssidCount > 2) { |
||
| 80 | $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to the following networks:"), implode(', ', \config\ConfAssistant::CONSORTIUM['ssid'])) . " "; |
||
| 81 | } else { |
||
| 82 | $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to:"), implode(', ', \config\ConfAssistant::CONSORTIUM['ssid'])) . " "; |
||
| 83 | } |
||
| 84 | $iterator = 0; |
||
| 85 | foreach ($this->attributes['internal:SSID'] as $ssid => $v) { |
||
| 86 | if (!in_array($ssid, \config\ConfAssistant::CONSORTIUM['ssid'])) { |
||
| 87 | if ($iterator > 0) { |
||
| 88 | $out .= ", "; |
||
| 89 | } |
||
| 90 | $iterator++; |
||
| 91 | $out .= "<strong>$ssid</strong>"; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | $out .= "<p>"; |
||
| 95 | } |
||
| 96 | $out .= _("The installer will create .cat_installer sub-directory in your home directory and will copy your server certificates there."); |
||
| 97 | if ($this->selectedEap == \core\common\EAP::EAPTYPE_TLS) { |
||
| 98 | $out .= _("In order to connect to the network you will need a personal certificate in the form of a p12 file. You should obtain this certificate from your organisation. Consult the support page to find out how this certificate can be obtained. Such certificate files are password protected. You should have both the file and the password available during the installation process. Your p12 file will also be copied to the .cat_installer directory."); |
||
| 99 | } elseif ($this->selectedEap != \core\common\EAP::EAPTYPE_SILVERBULLET) { |
||
| 100 | $out .= _("In order to connect to the network you will need an account from your organisation. You should consult the support page to find out how this account can be obtained. It is very likely that your account is already activated."); |
||
| 101 | $out .= "<p>"; |
||
| 102 | $out .= _("You will be requested to enter your account credentials during the installation. This information will be saved so that you will reconnect to the network automatically each time you are in the range."); |
||
| 103 | } |
||
| 104 | // nothing to say if we are doing silverbullet. |
||
| 105 | $out .= "<p>"; |
||
| 106 | \core\common\Entity::outOfThePotatoes(); |
||
| 107 | return $out; |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * writes a line of Python code into the installer script |
||
| 112 | * |
||
| 113 | * @param resource $file the file handle |
||
| 114 | * @param string $name config item to write |
||
| 115 | * @param string $text text to write |
||
| 116 | * @return void |
||
| 117 | */ |
||
| 118 | private function writeConfigLine($file, $name, $text) { |
||
| 119 | $out = $name . '="' . $text . '"\n'; |
||
| 120 | fwrite($file, wordwrap($out, 70, "\n")); |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * localises the user messages and writes them into the file |
||
| 125 | * |
||
| 126 | * @param resource $file the file resource of the installer script |
||
| 127 | * @return void |
||
| 128 | */ |
||
| 129 | private function writeMessages($file) { |
||
| 130 | \core\common\Entity::intoThePotatoes(); |
||
| 131 | $messages = [ |
||
| 132 | 'QUIT'=> _("Really quit?"), |
||
| 133 | 'USERNAME_PROMPT'=> _("enter your userid"), |
||
| 134 | 'ENTER_PASSWORD' => _("enter password"), |
||
| 135 | 'ENTER_IMPORT_PASSWORD' => _("enter your import password"), |
||
| 136 | 'INCORRECT_PASSWORD' => _("incorrect password"), |
||
| 137 | 'REPEAT_PASSWORD' => _("repeat your password"), |
||
| 138 | 'PASSWORD_DIFFER'=> _("passwords do not match"), |
||
| 139 | 'INSTALLATION_FINISHED' => _("Installation successful"), |
||
| 140 | 'CAT_DIR_EXISTS' => _("Directory {} exists; some of its files may be overwritten."), |
||
| 141 | 'CONTINUE' => _("Continue?"), |
||
| 142 | 'NM_NOT_SUPPORTED' => _("This NetworkManager version is not supported"), |
||
| 143 | 'CERT_ERROR' => _("Certificate file not found, looks like a CAT error"), |
||
| 144 | 'UNKNOWN_VERSION' => _("Unknown version"), |
||
| 145 | 'DBUS_ERROR' => _("DBus connection problem, a sudo might help"), |
||
| 146 | 'YES' => _("Y"), |
||
| 147 | 'NO' => _("N"), |
||
| 148 | 'SAVE_WPA_CONF' => _("NetworkManager configuration failed, but we may generate a wpa_supplicant configuration file if you wish. Be warned that your connection password will be saved in this file as clear text."), |
||
| 149 | 'SAVE_WPA_CONFIRM' => _("Write the file"), |
||
| 150 | 'WRONG_USERNAME_FORMAT' =>_("Error: Your username must be of the form 'xxx@institutionID' e.g. '[email protected]'!"), |
||
| 151 | 'WRONG_REALM' => _("Error: your username must be in the form of 'xxx@{}'. Please enter the username in the correct format."), |
||
| 152 | 'WRONG_REALM_SUFFIX' => _("Error: your username must be in the form of 'xxx@institutionID' and end with '{}'. Please enter the username in the correct format."), |
||
| 153 | 'USER_CERT_MISSING' => _("personal certificate file not found"), |
||
| 154 | ]; |
||
| 155 | foreach ($messages as $name => $value) { |
||
| 156 | $this->writeConfigLine($file, $name, $value); |
||
| 157 | } |
||
| 158 | \core\common\Entity::outOfThePotatoes(); |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * writes configuration variables into the installer script |
||
| 163 | * |
||
| 164 | * @param resource $file the file handle |
||
| 165 | * @return void |
||
| 166 | */ |
||
| 167 | private function writeConfigVars($file) { |
||
| 233 | } |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * coerces the list of EAP server names into a single string |
||
| 238 | * |
||
| 239 | * @return string |
||
| 240 | */ |
||
| 241 | private function glueServerNames() { |
||
| 242 | $serverList = $this->attributes['eap:server_name']; |
||
| 243 | if (!$serverList) { |
||
| 244 | return ''; |
||
| 245 | } |
||
| 246 | $A0 = array_reverse(explode('.', array_shift($serverList))); |
||
| 247 | $B = $A0; |
||
| 248 | foreach ($serverList as $oneServer) { |
||
| 249 | $A = array_reverse(explode('.', $oneServer)); |
||
| 250 | $B = array_intersect_assoc($A0, $A); |
||
| 251 | $A0 = $B; |
||
| 252 | } |
||
| 253 | return implode('.', array_reverse($B)); |
||
| 254 | } |
||
| 255 | |||
| 256 | /** |
||
| 257 | * generates the list of support contacts |
||
| 258 | * |
||
| 259 | * @return array |
||
| 260 | */ |
||
| 261 | private function mkSupportContacts() { |
||
| 262 | $url = (!empty($this->attributes['support:url'][0])) ? $this->attributes['support:url'][0] : $this->support_url_substitute; |
||
| 263 | $email = (!empty($this->attributes['support:email'][0])) ? $this->attributes['support:email'][0] : $this->support_email_substitute; |
||
| 264 | return ['url'=>$url, 'email'=>$email]; |
||
| 265 | } |
||
| 266 | |||
| 267 | /** |
||
| 268 | * generates the list of subjectAltNames to configure |
||
| 269 | * |
||
| 270 | * @return string |
||
| 271 | */ |
||
| 272 | private function mkSubjectAltNameList() { |
||
| 273 | $serverList = $this->attributes['eap:server_name']; |
||
| 274 | if (!$serverList) { |
||
| 275 | return ''; |
||
| 276 | } |
||
| 277 | $out = ''; |
||
| 278 | foreach ($serverList as $oneServer) { |
||
| 279 | if ($out) { |
||
| 280 | $out .= ', '; |
||
| 281 | } |
||
| 282 | $out .= "'DNS:$oneServer'"; |
||
| 283 | } |
||
| 284 | return "[" . $out. "]"; |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * generates the list of SSIDs to configure |
||
| 289 | * |
||
| 290 | * @return string |
||
| 291 | */ |
||
| 292 | private function mkSsidList() { |
||
| 293 | $ssids = $this->attributes['internal:SSID']; |
||
| 294 | $outArray = []; |
||
| 295 | foreach ($ssids as $ssid => $cipher) { |
||
| 296 | $outArray[] = "'$ssid'"; |
||
| 297 | } |
||
| 298 | return '[' . implode(', ', $outArray) . ']'; |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * generates the list of SSIDs to delete from the system |
||
| 303 | * |
||
| 304 | * @return string |
||
| 305 | */ |
||
| 306 | private function mkDelSsidList() { |
||
| 307 | $outArray = []; |
||
| 308 | $delSSIDs = $this->attributes['internal:remove_SSID']; |
||
| 309 | foreach ($delSSIDs as $ssid => $cipher) { |
||
| 310 | if ($cipher == 'DEL') { |
||
| 311 | $outArray[] = "'$ssid'"; |
||
| 312 | } |
||
| 313 | } |
||
| 314 | return '[' . implode(', ', $outArray) . ']'; |
||
| 315 | } |
||
| 316 | |||
| 317 | /** |
||
| 318 | * creates a blob containing all CA certificates |
||
| 319 | * |
||
| 320 | * @return string |
||
| 321 | */ |
||
| 322 | private function mkCAfile(){ |
||
| 323 | $out = ''; |
||
| 324 | $cAlist = $this->attributes['internal:CAs'][0]; |
||
| 325 | foreach ($cAlist as $oneCa) { |
||
| 326 | $out .= $oneCa['pem']; |
||
| 327 | } |
||
| 328 | return $out; |
||
| 329 | } |
||
| 330 | |||
| 331 | /** |
||
| 332 | * generates the welcome text |
||
| 333 | * |
||
| 334 | * @return string |
||
| 335 | */ |
||
| 336 | private function mkIntro() { |
||
| 337 | \core\common\Entity::intoThePotatoes(); |
||
| 338 | $out = _("This installer has been prepared for {0}") . '\n\n' . _("More information and comments:") . '\n\nE-Mail: {1}\nWWW: {2}\n\n' . |
||
| 339 | _("Installer created with software from the GEANT project."); |
||
| 340 | \core\common\Entity::outOfThePotatoes(); |
||
| 341 | return $out; |
||
| 342 | } |
||
| 343 | |||
| 344 | /** |
||
| 345 | * generates text for the user consent dialog box, if any |
||
| 346 | * |
||
| 347 | * @return string |
||
| 348 | */ |
||
| 349 | private function mkUserConsent() { |
||
| 350 | $out = ''; |
||
| 351 | if (isset($this->attributes['support:info_file'])) { |
||
| 352 | if ($this->attributes['internal:info_file'][0]['mime'] == 'txt') { |
||
| 353 | $out = $this->attributes['support:info_file'][0]; |
||
| 354 | } |
||
| 355 | } |
||
| 356 | return $out; |
||
| 357 | } |
||
| 358 | |||
| 359 | /** |
||
| 360 | * generates the warning that the account will only work for inst members |
||
| 361 | * |
||
| 362 | * @return string |
||
| 363 | */ |
||
| 364 | private function mkProfileConfirmation() { |
||
| 373 | } |
||
| 374 | |||
| 375 | |||
| 376 | /** |
||
| 377 | * generates the client certificate data for Silberbullet installers |
||
| 378 | * |
||
| 379 | * @return string |
||
| 380 | */ |
||
| 381 | private function mkSbUserFile() { |
||
| 386 | } |
||
| 387 | |||
| 388 | } |
||
| 389 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.