Passed
Push — master ( 67c50c...13c09d )
by Maja
16:27
created

checkURL()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 15
rs 9.8666
c 1
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 9 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
require_once dirname(dirname(__FILE__)) . "/config/_config.php";
3
/**
0 ignored issues
show
Coding Style introduced by
Parameter $srv should have a doc-comment as per coding-style.
Loading history...
4
    * check if URL responds with 200
5
    *
6
    * @param string server name
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
Bug introduced by
The type server was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
    * @return integer or NULL
8
*/
9
function checkURL ($srv) {
10
    $ch = curl_init();
11
    if ($ch === FALSE) {
12
        return NULL;
13
    }
14
    $timeout = 10;
15
    curl_setopt ( $ch, CURLOPT_URL, $srv );
16
    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
17
    curl_setopt ( $ch, CURLOPT_TIMEOUT, $timeout );
18
    curl_exec($ch);
19
    $http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
20
    if ($http_code == 200) {
21
        return 1;
22
    }
23
    return 0;
24
}
25
26
$dbLink = \core\DBConnection::handle("INST");
27
$allProblems = $dbLink->exec("SELECT deployment_id, inst_id, status, radius_status_1, radius_status_2, radius_instance_1, radius_instance_2 from deployment where radius_status_1=2 or radius_status_2=2");
28
$brokenDeployments = array();
29
while ($problemRow = mysqli_fetch_object($allProblems)) {
0 ignored issues
show
Bug introduced by
It seems like $allProblems can also be of type true; however, parameter $result of mysqli_fetch_object() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
while ($problemRow = mysqli_fetch_object(/** @scrutinizer ignore-type */ $allProblems)) {
Loading history...
30
    foreach (array(1, 2) as $id) {
31
        $fld_s = "radius_status_$id";
32
        $fld_i = "radius_instance_$id";
33
        if ($problemRow->$fld_s == 2) {
34
            if (!isset($brokenDeployments[$problemRow->$fld_i])) {
35
                $brokenDeployments[$problemRow->$fld_i] = array();
36
            }
37
            $brokenDeployments[$problemRow->$fld_i][$problemRow->inst_id] = $problemRow->deployment_id;
38
        }
39
    }
40
}
41
if (empty($brokenDeployments)) {
42
    exit;
43
}
44
$allServers = $dbLink->exec("SELECT server_id, mgmt_hostname from managed_sp_servers");
45
$radiusSites = array();
46
$siteStatus = array();
47
while ($siteRow = mysqli_fetch_object($allServers)) {
48
    $radiusSite[$siteRow->server_id] = $siteRow->mgmt_hostname;
49
}
50
$siteStatus = array();
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]);
54
    if ($siteStatus[$server_id]) {
55
        echo "\ncheck radius\n";
56
        echo \config\Diagnostics::RADIUSSPTEST['port']."\n";
57
        $statusServer = new \core\diag\RFC5997Tests($radiusSite[$server_id], \config\Diagnostics::RADIUSSPTEST['port'], \config\Diagnostics::RADIUSSPTEST['secret']);
58
        if ($statusServer->statusServerCheck() === \core\diag\AbstractTest::RETVAL_OK) {
59
            $siteStatus[$server_id] = 1;
60
        } else {
61
            $siteStatus[$server_id] = 0;
62
        }
63
    }
64
} 
65
if (!in_array(1, array_values($siteStatus))) { 
66
    exit;
67
}
68
foreach (array_keys($brokenDeployments) as $server_id) {
69
    if (isset($siteStatus[$server_id]) && $siteStatus[$server_id]) {
70
        foreach ($brokenDeployments[$server_id] as $inst_id => $deployment_id) {            
71
            $idp = new \core\IdP($inst_id);
72
            $hotspotProfiles = $idp->listDeployments();
73
            $deployment = $hotspotProfiles[0];
74
            $idx = 1;
75
            if ($deployment->radius_instance_2 == $server_id) {
76
                $idx = 2;
77
            }
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);
0 ignored issues
show
Unused Code introduced by
The call to core\AbstractDeployment::setRADIUSconfig() has too many arguments starting with 1. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
            /** @scrutinizer ignore-call */ 
80
            $response = $deployment->setRADIUSconfig(($deployment->status == \core\AbstractDeployment::INACTIVE)? 1 : 0, $idx, 1);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
80
            if (isset($response["res[$idx]"]) && $response["res[$idx]"] = 'OK') {
81
                echo "FIXED\n";
82
                print_r($response);
83
            }
84
        }
85
    }
86
}
87
88