Passed
Push — master ( 67c50c...13c09d )
by Maja
16:27
created
utils/SP_consistency_check.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 require_once dirname(dirname(__FILE__)) . "/config/_config.php";
3 3
 /**
4
-    * check if URL responds with 200
5
-    *
6
-    * @param string server name
7
-    * @return integer or NULL
4
+ * check if URL responds with 200
5
+ *
6
+ * @param string server name
7
+ * @return integer or NULL
8 8
 */
9 9
 function checkURL ($srv) {
10 10
     $ch = curl_init();
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 <?php
2
-require_once dirname(dirname(__FILE__)) . "/config/_config.php";
2
+require_once dirname(dirname(__FILE__))."/config/_config.php";
3 3
 /**
4 4
     * check if URL responds with 200
5 5
     *
6 6
     * @param string server name
7 7
     * @return integer or NULL
8 8
 */
9
-function checkURL ($srv) {
9
+function checkURL($srv) {
10 10
     $ch = curl_init();
11 11
     if ($ch === FALSE) {
12 12
         return NULL;
13 13
     }
14 14
     $timeout = 10;
15
-    curl_setopt ( $ch, CURLOPT_URL, $srv );
16
-    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
17
-    curl_setopt ( $ch, CURLOPT_TIMEOUT, $timeout );
15
+    curl_setopt($ch, CURLOPT_URL, $srv);
16
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
17
+    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
18 18
     curl_exec($ch);
19
-    $http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
19
+    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
20 20
     if ($http_code == 200) {
21 21
         return 1;
22 22
     }
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 }
50 50
 $siteStatus = array();
51 51
 foreach (array_keys($brokenDeployments) as $server_id) {
52
-    print "check $server_id " . $radiusSite[$server_id] . "\n";
53
-    $siteStatus[$server_id]  = checkUrl('http://' . $radiusSite[$server_id]);
52
+    print "check $server_id ".$radiusSite[$server_id]."\n";
53
+    $siteStatus[$server_id] = checkUrl('http://'.$radiusSite[$server_id]);
54 54
     if ($siteStatus[$server_id]) {
55 55
         echo "\ncheck radius\n";
56 56
         echo \config\Diagnostics::RADIUSSPTEST['port']."\n";
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
                 $idx = 2;
77 77
             }
78 78
             echo "\nfix $deployment_id of $inst_id on server $server_id index $idx\n";
79
-            $response = $deployment->setRADIUSconfig(($deployment->status == \core\AbstractDeployment::INACTIVE)? 1 : 0, $idx, 1);
79
+            $response = $deployment->setRADIUSconfig(($deployment->status == \core\AbstractDeployment::INACTIVE) ? 1 : 0, $idx, 1);
80 80
             if (isset($response["res[$idx]"]) && $response["res[$idx]"] = 'OK') {
81 81
                 echo "FIXED\n";
82 82
                 print_r($response);
Please login to merge, or discard this patch.
core/DeploymentManaged.php 2 patches
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
                 $this->loggerInstance->debug(1, "curl_exec failure");
397 397
                 $res = 'FAILURE';
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
             $this->loggerInstance->debug(1, $this);           
403 403
         }
404 404
         $this->loggerInstance->debug(1, "Database update");
405
-        $this->databaseHandle->exec("UPDATE deployment SET radius_status_$idx = " . ($res == 'OK'? \core\AbstractDeployment::RADIUS_OK : \core\AbstractDeployment::RADIUS_FAILURE) . " WHERE deployment_id = $this->identifier");
405
+        $this->databaseHandle->exec("UPDATE deployment SET radius_status_$idx = ".($res == 'OK' ? \core\AbstractDeployment::RADIUS_OK : \core\AbstractDeployment::RADIUS_FAILURE)." WHERE deployment_id = $this->identifier");
406 406
         return $res;
407 407
     }
408 408
     /**
@@ -417,23 +417,23 @@  discard block
 block discarded – undo
417 417
     private function sendMailtoAdmin($remove, $response, $status) {
418 418
         $txt = '';
419 419
         if ($status == 'OK') {
420
-            $txt = $remove? _('Profile dectivation succeeded') : _('Profile activation/modification succeeded');
420
+            $txt = $remove ? _('Profile dectivation succeeded') : _('Profile activation/modification succeeded');
421 421
         } else {
422
-            $txt = $remove? _('Profile dectivation failed') : _('Profile activation/modification failed');
422
+            $txt = $remove ? _('Profile dectivation failed') : _('Profile activation/modification failed');
423 423
         }
424
-        $txt = $txt . ' ';
424
+        $txt = $txt.' ';
425 425
         if (array_count_values($response)[$status] == 2) {
426
-            $txt = $txt . _('on both RADIUS servers: primary and backup') . '.';
426
+            $txt = $txt._('on both RADIUS servers: primary and backup').'.';
427 427
         } else {
428 428
             if ($response['res[1]'] == $status) {
429
-                $txt = $txt . _('on primary RADIUS server') . '.';
429
+                $txt = $txt._('on primary RADIUS server').'.';
430 430
             } else {
431
-                $txt = $txt . _('on backup RADIUS server') . '.';
431
+                $txt = $txt._('on backup RADIUS server').'.';
432 432
             }
433 433
         }
434 434
         $mail = \core\common\OutsideComm::mailHandle();
435 435
         $email = $this->getAttributes("support:email")[0]['value'];
436
-        $mail->FromName = \config\Master::APPEARANCE['productname'] . " Notification System";
436
+        $mail->FromName = \config\Master::APPEARANCE['productname']." Notification System";
437 437
         $mail->addAddress($email);     
438 438
         if ($status == 'OK') {
439 439
             $mail->Subject = _('RADIUS profile update problem fixed');
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
         }
443 443
         $mail->Body = $txt;
444 444
         $sent = $mail->send();
445
-        if ( $sent === FALSE)
445
+        if ($sent === FALSE)
446 446
         $this->loggerInstance->debug(1, 'Mailing on RADIUS problem failed');
447 447
     }
448 448
     /**
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
      * @param integer $idx server index 1 (primary) or 2 (backup)
452 452
      * @return integer or NULL
453 453
      */
454
-    private function checkURL ($idx) {
454
+    private function checkURL($idx) {
455 455
         $ch = curl_init();
456 456
         if ($ch === FALSE) {
457 457
             return NULL;
@@ -464,11 +464,11 @@  discard block
 block discarded – undo
464 464
             return NULL;
465 465
         }
466 466
         $timeout = 10;
467
-        curl_setopt ( $ch, CURLOPT_URL, 'http://'.$host );
468
-        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
469
-        curl_setopt ( $ch, CURLOPT_TIMEOUT, $timeout );
467
+        curl_setopt($ch, CURLOPT_URL, 'http://'.$host);
468
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
469
+        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
470 470
         curl_exec($ch);
471
-        $http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
471
+        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
472 472
         if ($http_code == 200) {
473 473
             return 1;
474 474
         }
@@ -547,32 +547,32 @@  discard block
 block discarded – undo
547 547
      */
548 548
     public function setRADIUSconfig($remove = 0, $onlyone = 0, $notify = 0) {
549 549
         $toPost = ($onlyone ? array($onlyone => '') : array(1 => '', 2 => ''));
550
-        $toPostTemplate = 'instid=' . $this->institution . '&deploymentid=' . $this->identifier . '&secret=' . $this->secret . '&country=' . $this->getAttributes("internal:country")[0]['value'] . '&';
550
+        $toPostTemplate = 'instid='.$this->institution.'&deploymentid='.$this->identifier.'&secret='.$this->secret.'&country='.$this->getAttributes("internal:country")[0]['value'].'&';
551 551
         if ($remove) {
552
-            $toPostTemplate = $toPostTemplate . 'remove=1&';
552
+            $toPostTemplate = $toPostTemplate.'remove=1&';
553 553
         } else {
554 554
             if ($this->getAttributes("managedsp:operatorname")[0]['value'] ?? NULL) {
555
-                $toPostTemplate = $toPostTemplate . 'operatorname=' . $this->getAttributes("managedsp:operatorname")[0]['value'] . '&';
555
+                $toPostTemplate = $toPostTemplate.'operatorname='.$this->getAttributes("managedsp:operatorname")[0]['value'].'&';
556 556
             }
557 557
             if ($this->getAttributes("managedsp:vlan")[0]['value'] ?? NULL) {
558 558
                 $allRealms = $this->getAllRealms();
559 559
                 if (!empty($allRealms)) {
560
-                    $toPostTemplate = $toPostTemplate . 'vlan=' . $this->getAttributes("managedsp:vlan")[0]['value'] . '&';
561
-                    $toPostTemplate = $toPostTemplate . 'realmforvlan[]=' . implode('&realmforvlan[]=', $allRealms) . '&';
560
+                    $toPostTemplate = $toPostTemplate.'vlan='.$this->getAttributes("managedsp:vlan")[0]['value'].'&';
561
+                    $toPostTemplate = $toPostTemplate.'realmforvlan[]='.implode('&realmforvlan[]=', $allRealms).'&';
562 562
                 }
563 563
             }
564 564
         }
565 565
         foreach (array_keys($toPost) as $key) {
566
-            $elem = 'port' . $key;
567
-            $toPost[$key] = $toPostTemplate . 'port=' . $this->$elem;     
566
+            $elem = 'port'.$key;
567
+            $toPost[$key] = $toPostTemplate.'port='.$this->$elem;     
568 568
         }
569 569
         $response = array();
570 570
         foreach ($toPost as $key => $value) {
571
-            $this->loggerInstance->debug(1, 'toPost ' . $toPost[$key] ."\n");
571
+            $this->loggerInstance->debug(1, 'toPost '.$toPost[$key]."\n");
572 572
             $response['res['.$key.']'] = $this->sendToRADIUS($key, $toPost[$key]);
573 573
         }
574 574
         if ($onlyone) {
575
-            $response['res['.($onlyone==1)? 2 : 1 . ']'] = \core\AbstractDeployment::RADIUS_OK;
575
+            $response['res['.($onlyone == 1) ? 2 : 1.']'] = \core\AbstractDeployment::RADIUS_OK;
576 576
         }
577 577
         if (in_array('FAILURE', $response)) {
578 578
             $this->sendMailtoAdmin($remove, $response, 'FAILURE');
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -442,8 +442,9 @@
 block discarded – undo
442 442
         }
443 443
         $mail->Body = $txt;
444 444
         $sent = $mail->send();
445
-        if ( $sent === FALSE)
446
-        $this->loggerInstance->debug(1, 'Mailing on RADIUS problem failed');
445
+        if ( $sent === FALSE) {
446
+                $this->loggerInstance->debug(1, 'Mailing on RADIUS problem failed');
447
+        }
447 448
     }
448 449
     /**
449 450
      * check if URL responds with 200
Please login to merge, or discard this patch.