Passed
Push — master ( c6cd3b...3b84dd )
by Maja
07:08
created
core/DeploymentManaged.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -468,11 +468,11 @@
 block discarded – undo
468 468
         return 0;
469 469
     }
470 470
         /**
471
-     * check whether the configured RADIUS hosts actually exist
472
-     * 
473
-     * @param  integer $idx server index 1 (primary) or 2 (backup)
474
-     * @return boolean or NULL
475
-     */
471
+         * check whether the configured RADIUS hosts actually exist
472
+         * 
473
+         * @param  integer $idx server index 1 (primary) or 2 (backup)
474
+         * @return boolean or NULL
475
+         */
476 476
     public function checkRADIUSHost($idx) {
477 477
         if ($idx == 1) {
478 478
             $host = $this->radius_hostname_1;
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
                 $serverCandidates[IdPlist::geoDistance($adminLocation, ['lat' => $iterator->location_lat, 'lon' => $iterator->location_lon])] = $iterator->server_id;
251 251
             }
252 252
             if ($clients > $maxSupportedClients * 0.9) {
253
-                $this->loggerInstance->debug(1, "A RADIUS server for Managed SP (" . $iterator->server_id . ") is serving at more than 90% capacity!");
253
+                $this->loggerInstance->debug(1, "A RADIUS server for Managed SP (".$iterator->server_id.") is serving at more than 90% capacity!");
254 254
             }
255 255
         }
256 256
         if (count($serverCandidates) == 0 && $federation != "DEFAULT") {
@@ -281,28 +281,28 @@  discard block
 block discarded – undo
281 281
             $ourLocation = ['lon' => $geoip['geo']['lon'], 'lat' => $geoip['geo']['lat']];
282 282
         }
283 283
         $inst = new IdP($this->institution);
284
-        $ourserver = $this->findGoodServerLocation($ourLocation, $inst->federation , []);
284
+        $ourserver = $this->findGoodServerLocation($ourLocation, $inst->federation, []);
285 285
         // now, find an unused port in the preferred server
286 286
         $foundFreePort1 = 0;
287 287
         while ($foundFreePort1 == 0) {
288 288
             $portCandidate = random_int(1200, 65535);
289
-            $check = $this->databaseHandle->exec("SELECT port_instance_1 FROM deployment WHERE radius_instance_1 = '" . $ourserver . "' AND port_instance_1 = $portCandidate");
289
+            $check = $this->databaseHandle->exec("SELECT port_instance_1 FROM deployment WHERE radius_instance_1 = '".$ourserver."' AND port_instance_1 = $portCandidate");
290 290
             if (mysqli_num_rows(/** @scrutinizer ignore-type */ $check) == 0) {
291 291
                 $foundFreePort1 = $portCandidate;
292 292
             }
293 293
         }
294
-        $ourSecondServer = $this->findGoodServerLocation($ourLocation, $inst->federation , [$ourserver]);
294
+        $ourSecondServer = $this->findGoodServerLocation($ourLocation, $inst->federation, [$ourserver]);
295 295
         $foundFreePort2 = 0;
296 296
         while ($foundFreePort2 == 0) {
297 297
             $portCandidate = random_int(1200, 65535);
298
-            $check = $this->databaseHandle->exec("SELECT port_instance_2 FROM deployment WHERE radius_instance_2 = '" . $ourSecondServer . "' AND port_instance_2 = $portCandidate");
298
+            $check = $this->databaseHandle->exec("SELECT port_instance_2 FROM deployment WHERE radius_instance_2 = '".$ourSecondServer."' AND port_instance_2 = $portCandidate");
299 299
             if (mysqli_num_rows(/** @scrutinizer ignore-type */ $check) == 0) {
300 300
                 $foundFreePort2 = $portCandidate;
301 301
             }
302 302
         }
303 303
         // and make up a shared secret that is halfways readable
304 304
         $futureSecret = $this->randomString(16, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
305
-        $this->databaseHandle->exec("UPDATE deployment SET radius_instance_1 = '" . $ourserver . "', radius_instance_2 = '" . $ourSecondServer . "', port_instance_1 = $foundFreePort1, port_instance_2 = $foundFreePort2, secret = '$futureSecret' WHERE deployment_id = $this->identifier");
305
+        $this->databaseHandle->exec("UPDATE deployment SET radius_instance_1 = '".$ourserver."', radius_instance_2 = '".$ourSecondServer."', port_instance_1 = $foundFreePort1, port_instance_2 = $foundFreePort2, secret = '$futureSecret' WHERE deployment_id = $this->identifier");
306 306
         return ["port_instance_1" => $foundFreePort1, "port_instance_2" => $foundFreePort2, "secret" => $futureSecret, "radius_instance_1" => $ourserver, "radius_instance_2" => $ourserver];
307 307
     }
308 308
 
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
      * @return void
346 346
      */
347 347
     public function deactivate() {
348
-        $this->databaseHandle->exec("UPDATE deployment SET status = " . DeploymentManaged::INACTIVE . " WHERE deployment_id = $this->identifier");
348
+        $this->databaseHandle->exec("UPDATE deployment SET status = ".DeploymentManaged::INACTIVE." WHERE deployment_id = $this->identifier");
349 349
     }
350 350
 
351 351
     /**
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
      * @return void
356 356
      */
357 357
     public function activate() {
358
-        $this->databaseHandle->exec("UPDATE deployment SET status = " . DeploymentManaged::ACTIVE . " WHERE deployment_id = $this->identifier");
358
+        $this->databaseHandle->exec("UPDATE deployment SET status = ".DeploymentManaged::ACTIVE." WHERE deployment_id = $this->identifier");
359 359
     }
360 360
 
361 361
     /**
@@ -381,17 +381,17 @@  discard block
 block discarded – undo
381 381
     private function sendToRADIUS($idx, $post) {
382 382
             
383 383
         $hostname = "radius_hostname_$idx";
384
-        $ch = curl_init( "http://" . $this->$hostname );
384
+        $ch = curl_init("http://".$this->$hostname);
385 385
         if ($ch === FALSE) {
386 386
             $res = 'FAILURE';
387 387
         } else {
388
-            curl_setopt( $ch, CURLOPT_POST, 1);
389
-            curl_setopt( $ch, CURLOPT_POSTFIELDS, $post);
390
-            $this->loggerInstance->debug(1, "Posting to http://" . $this->$hostname . ": $post\n");
391
-            curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
392
-            curl_setopt( $ch, CURLOPT_HEADER, 0);
393
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
394
-            $exec = curl_exec( $ch );
388
+            curl_setopt($ch, CURLOPT_POST, 1);
389
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
390
+            $this->loggerInstance->debug(1, "Posting to http://".$this->$hostname.": $post\n");
391
+            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
392
+            curl_setopt($ch, CURLOPT_HEADER, 0);
393
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
394
+            $exec = curl_exec($ch);
395 395
             if ($exec === FALSE) {
396 396
                 $res = 'FAILURE';
397 397
             } else {
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
             $this->loggerInstance->debug(1, "Response from FR configurator: $res\n");
401 401
             $this->loggerInstance->debug(1, $this);           
402 402
         }
403
-        $this->databaseHandle->exec("UPDATE deployment SET radius_status_$idx = " . ($res == 'OK'? \core\AbstractDeployment::RADIUS_OK : \core\AbstractDeployment::RADIUS_FAILURE) . " WHERE deployment_id = $this->identifier");
403
+        $this->databaseHandle->exec("UPDATE deployment SET radius_status_$idx = ".($res == 'OK' ? \core\AbstractDeployment::RADIUS_OK : \core\AbstractDeployment::RADIUS_FAILURE)." WHERE deployment_id = $this->identifier");
404 404
         return $res;
405 405
     }
406 406
     /**
@@ -414,28 +414,28 @@  discard block
 block discarded – undo
414 414
     private function sendMailtoAdmin($remove, $response) {
415 415
         $txt = '';
416 416
         if ($remove) {
417
-            $txt = _('Profile dectivation failed' . ' ');
417
+            $txt = _('Profile dectivation failed'.' ');
418 418
         } else {
419
-            $txt = _('Profile activation/modification failed' . ' ');
419
+            $txt = _('Profile activation/modification failed'.' ');
420 420
         }
421 421
         if (array_count_values($response)['FAILURE'] == 2) {
422
-            $txt = $txt . _('on both RADIUS servers: primary and backup') . '.';
422
+            $txt = $txt._('on both RADIUS servers: primary and backup').'.';
423 423
         } else {
424 424
             if ($response['res[1]'] == 'FAILURE') {
425
-                $txt = $txt . _('on primary RADIUS server') . '.';
425
+                $txt = $txt._('on primary RADIUS server').'.';
426 426
             } else {
427
-                $txt = $txt . _('on backup RADIUS server') . '.';
427
+                $txt = $txt._('on backup RADIUS server').'.';
428 428
             }
429 429
         }
430 430
         $mail = \core\common\OutsideComm::mailHandle();
431 431
         $email = $this->getAttributes("support:email")[0]['value'];
432
-        $mail->FromName = \config\Master::APPEARANCE['productname'] . " Notification System";
432
+        $mail->FromName = \config\Master::APPEARANCE['productname']." Notification System";
433 433
         $mail->addAddress($email);
434 434
         $mail->Subject = _('RADIUS profile update problem');
435 435
         $mail->Body = $txt;
436 436
 
437 437
         $sent = $mail->send();
438
-        if ( $sent === FALSE)
438
+        if ($sent === FALSE)
439 439
         $this->loggerInstance->debug(1, 'Mailing on RADIUS problem failed');
440 440
     }
441 441
     /**
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
      * @param integer $idx server index 1 (primary) or 2 (backup)
445 445
      * @return integer or NULL
446 446
      */
447
-    private function checkURL ($idx) {
447
+    private function checkURL($idx) {
448 448
         $ch = curl_init();
449 449
         if ($ch === FALSE) {
450 450
             return NULL;
@@ -457,11 +457,11 @@  discard block
 block discarded – undo
457 457
             return NULL;
458 458
         }
459 459
         $timeout = 10;
460
-        curl_setopt ( $ch, CURLOPT_URL, 'http://'.$host );
461
-        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
462
-        curl_setopt ( $ch, CURLOPT_TIMEOUT, $timeout );
460
+        curl_setopt($ch, CURLOPT_URL, 'http://'.$host);
461
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
462
+        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
463 463
         curl_exec($ch);
464
-        $http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
464
+        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
465 465
         if ($http_code == 200) {
466 466
             return 1;
467 467
         }
@@ -515,18 +515,18 @@  discard block
 block discarded – undo
515 515
     public function setRADIUSconfig($remove = 0, $onlyone = 0) {
516 516
         $toPost = array();
517 517
         if ($onlyone) {
518
-            $toPost[$onlyone]  = '';
518
+            $toPost[$onlyone] = '';
519 519
         } else {
520 520
             // run on both servers
521 521
             $toPost[1] = '';
522 522
             $toPost[2] = '';
523 523
         }
524
-        $toPostTemplate = 'instid=' . $this->institution . '&deploymentid=' . $this->identifier . '&secret=' . $this->secret . '&country=' . $this->getAttributes("internal:country")[0]['value'] . '&';
524
+        $toPostTemplate = 'instid='.$this->institution.'&deploymentid='.$this->identifier.'&secret='.$this->secret.'&country='.$this->getAttributes("internal:country")[0]['value'].'&';
525 525
         if ($remove) {
526
-            $toPostTemplate = $toPostTemplate . 'remove=1&';
526
+            $toPostTemplate = $toPostTemplate.'remove=1&';
527 527
         } else {
528 528
             if ($this->getAttributes("managedsp:operatorname")[0]['value'] ?? NULL) {
529
-                $toPostTemplate = $toPostTemplate . 'operatorname=' . $this->getAttributes("managedsp:operatorname")[0]['value'] . '&';
529
+                $toPostTemplate = $toPostTemplate.'operatorname='.$this->getAttributes("managedsp:operatorname")[0]['value'].'&';
530 530
             }
531 531
             if ($this->getAttributes("managedsp:vlan")[0]['value'] ?? NULL) {
532 532
                 $idp = new IdP($this->institution);
@@ -543,25 +543,25 @@  discard block
 block discarded – undo
543 543
                     }
544 544
                 }
545 545
                 if (!empty($allRealms)) {
546
-                    $toPostTemplate = $toPostTemplate . 'vlan=' . $this->getAttributes("managedsp:vlan")[0]['value'] . '&';
547
-                    $toPostTemplate = $toPostTemplate . 'realmforvlan[]=' . implode('&realmforvlan[]=', $allRealms) . '&';
546
+                    $toPostTemplate = $toPostTemplate.'vlan='.$this->getAttributes("managedsp:vlan")[0]['value'].'&';
547
+                    $toPostTemplate = $toPostTemplate.'realmforvlan[]='.implode('&realmforvlan[]=', $allRealms).'&';
548 548
                 }
549 549
             }
550 550
         }
551 551
         foreach (array_keys($toPost) as $key) {
552 552
             if ($key == 1) {
553
-                $toPost[$key] = $toPostTemplate . 'port=' . $this->port1;
553
+                $toPost[$key] = $toPostTemplate.'port='.$this->port1;
554 554
             } else {
555
-                $toPost[$key] = $toPostTemplate . 'port=' . $this->port2;
555
+                $toPost[$key] = $toPostTemplate.'port='.$this->port2;
556 556
             }      
557 557
         }
558 558
         $response = array();
559 559
         foreach ($toPost as $key => $value) {
560
-            $this->loggerInstance->debug(1, 'toPost ' . $toPost[$key] ."\n");
560
+            $this->loggerInstance->debug(1, 'toPost '.$toPost[$key]."\n");
561 561
             $response['res['.$key.']'] = $this->sendToRADIUS($key, $toPost[$key]);
562 562
         }
563 563
         if ($onlyone) {
564
-            $response['res['.($onlyone==1)? 2 : 1 . ']'] = \core\AbstractDeployment::RADIUS_OK;
564
+            $response['res['.($onlyone == 1) ? 2 : 1.']'] = \core\AbstractDeployment::RADIUS_OK;
565 565
         }
566 566
         if (in_array('FAILURE', $response)) {
567 567
             $this->sendMailtoAdmin($remove, $response);
Please login to merge, or discard this patch.