| Conditions | 5 |
| Paths | 16 |
| Total Lines | 206 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 183 | // 'sb_user_file' => $this->mkSbUserFile(), |
||
| 184 | ]; |
||
| 185 | |||
| 186 | $configRaw = [ |
||
| 187 | 'SSIDS' => $this->mkSsidList(), |
||
| 188 | 'DEL_SSIDS' => $this->mkDelSsidList(), |
||
| 189 | 'SERVERS' => $this->mkSubjectAltNameList(), |
||
| 190 | ]; |
||
| 191 | |||
| 192 | if ($this->selectedEap == \core\common\EAP::EAPTYPE_TLS && isset($this->attributes['eap-specific:tls_use_other_id']) && $this->attributes['eap-specific:tls_use_other_id'][0] == 'on') { |
||
| 193 | $configRaw['USE_OTHER_TLS_ID'] = "True"; |
||
| 194 | } |
||
| 195 | else { |
||
| 196 | $configRaw['USE_OTHER_TLS_ID'] = "False"; |
||
| 197 | } |
||
| 198 | |||
| 199 | if ($outerId !== NULL) { |
||
| 200 | $configRaw['ANONYMOUS_IDENTITY'] = '"' . $outerId . '"'; |
||
| 201 | } |
||
| 202 | |||
| 203 | if (!empty($this->attributes['internal:realm'][0])) { |
||
| 204 | $config['USER_REALM'] = $this->attributes['internal:realm'][0]; |
||
| 205 | } |
||
| 206 | |||
| 207 | if(!empty($this->attributes['internal:hint_userinput_suffix'][0]) && $this->attributes['internal:hint_userinput_suffix'][0] == 1) { |
||
| 208 | $configRaw['HINT_USER_INPUT'] = "True"; |
||
| 209 | } |
||
| 210 | |||
| 211 | if(!empty($this->attributes['internal:verify_userinput_suffix'][0]) && $this->attributes['internal:verify_userinput_suffix'][0] == 1) { |
||
| 212 | $configRaw['VERIFY_USER_REALM_INPUT'] = "True"; |
||
| 213 | } |
||
| 214 | |||
| 215 | foreach ($config as $name => $value) { |
||
| 216 | $this->writeConfigLine($file, $name, $value); |
||
| 217 | } |
||
| 218 | |||
| 219 | foreach ($configRaw as $name => $value) { |
||
| 220 | fwrite($file, $name, $value); |
||
| 221 | } |
||
| 222 | |||
| 223 | if ($tou === '') { |
||
| 224 | fwrite($file, "TOU=\"\"\n"); |
||
| 225 | } else { |
||
| 226 | fwrite($file, "TOU=\"" . $tou . "\"\n"); |
||
| 227 | } |
||
| 228 | |||
| 229 | fwrite($file, "CA=\"" . $this->mkCAfile() . "\"\n"); |
||
| 230 | $sbUserFile = $this->mkSbUserFile(); |
||
| 231 | if ($sbUserFile !== '') { |
||
| 232 | fwrite($file, "SB_USER_FILE=\"" . $sbUserFile . "\"\n"); |
||
| 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() { |
||
| 365 | \core\common\Entity::intoThePotatoes(); |
||
| 366 | if ($this->attributes['internal:profile_count'][0] > 1) { |
||
| 367 | $out = _("This installer will only work properly if you are a member of {0} and the user group: {1}."); |
||
| 368 | } else { |
||
| 369 | $out = _("This installer will only work properly if you are a member of {0}."); |
||
| 370 | } |
||
| 371 | \core\common\Entity::outOfThePotatoes(); |
||
| 372 | return $out; |
||
| 373 | } |
||
| 374 | |||
| 375 | |||
| 376 | /** |
||
| 377 | * generates the client certificate data for Silberbullet installers |
||
| 378 | * |
||
| 379 | * @return string |
||
| 380 | */ |
||
| 381 | private function mkSbUserFile() { |
||
| 382 | if ($this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) { |
||
| 383 | return chunk_split(base64_encode($this->clientCert["certdata"]), 64, "\n"); |
||
| 384 | } |
||
| 385 | return ""; |
||
| 386 | } |
||
| 387 | |||
| 388 | } |
||
| 389 |