GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (4873)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

plugins/hudson/include/HudsonJob.class.php (19 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4
 *
5
 * This file is a part of Codendi.
6
 *
7
 * Codendi is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * Codendi is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
19
 */
20
require_once('hudson.class.php');
21
require_once('HudsonJobURLMalformedException.class.php');
22
require_once('HudsonJobURLFileException.class.php');
23
require_once('HudsonJobURLFileNotFoundException.class.php');
24
 
25
class HudsonJob {
26
    const API_XML = '/api/xml';
27
28
    protected $hudson_job_url;
29
    protected $hudson_dobuild_url;
30
    protected $dom_job;
31
    private $icons_path;
32
    
33
    private $context;
34
35
    /**
36
     * Construct an Hudson job from a job URL
37
     */
38
    function __construct($hudson_job_url, $name = null) {
39
        $parsed_url = parse_url($hudson_job_url);
40
        
41
        if ( ! $parsed_url || ! array_key_exists('scheme', $parsed_url) ) {
42
            throw new HudsonJobURLMalformedException($GLOBALS['Language']->getText('plugin_hudson','wrong_job_url', array($hudson_job_url)));
43
        }
44
45
        $this->setJobUrl($hudson_job_url);
46
47
        $this->name       = $name;
48
        $controler        = $this->getHudsonControler();
49
        $this->icons_path = $controler->getIconsPath();
50
    }
51
52
    private function setJobUrl($url) {
53
        $matches = array();
54
        if (preg_match(Jenkins_Client::BUILD_WITH_PARAMETERS_REGEXP, $url, $matches)) {
55
            $this->hudson_job_url     = $matches['job_url'] . self::API_XML;
56
            $this->hudson_dobuild_url = $url;
57
        } else {
58
            $this->hudson_job_url     = $url . self::API_XML;
59
            $this->hudson_dobuild_url = $url . "/build";
60
        }
61
    }
62
63
    public function getJobUrl() {
64
        return $this->hudson_job_url;
65
    }
66
67
    public function getDoBuildUrl() {
68
        return $this->hudson_dobuild_url;
69
    }
70
71
    function getHudsonControler() {
72
        return new hudson();
73
    }
74
75
    protected function getDomJob() {
76
        if (!$this->dom_job) {
77
            $this->_setStreamContext();
78
            $this->buildJobObject();
79
        }
80
        return $this->dom_job;
81
    }
82
83
    public function buildJobObject() {
84
         $this->dom_job = $this->_getXMLObject($this->hudson_job_url);
85
    }
86
    
87
    protected function _getXMLObject($hudson_job_url) {
88
        $xmlstr = @file_get_contents($hudson_job_url, false, $this->context);
89
        if ($xmlstr !== false) {
90
            $xmlobj = simplexml_load_string($xmlstr);
91
            if ($xmlobj !== false) {
92
                return $xmlobj;
93
            } else {
94
                throw new HudsonJobURLFileException($GLOBALS['Language']->getText('plugin_hudson','job_url_file_error', array($hudson_job_url)));
95
            }
96
        } else {
97
            throw new HudsonJobURLFileNotFoundException($GLOBALS['Language']->getText('plugin_hudson','job_url_file_not_found', array($hudson_job_url))); 
98
        }
99
    }
100
    
101
    private function _setStreamContext() {
102
        $context_opt = array(
103
            'http' => array(
104
                'method' => 'GET',
105
                'timeout' => 5.0,
106
            ),
107
        );
108
        if (!empty($GLOBALS['sys_proxy'])) {
109
            $context_opt['http']['proxy']           = $GLOBALS['sys_proxy'];
110
            $context_opt['http']['request_fulluri'] = true;
111
        }
112
        $this->context = stream_context_create($context_opt);
113
    }
114
    
115
    function getProjectStyle() {
116
        return $this->getDomJob()->getName();
117
    }
118
    function getName() {
119
        if (!$this->name) {
120
            $this->name = $this->getDomJob()->name;
121
        }
122
        return $this->name;
123
    }
124
    function getUrl() {
125
        return $this->getDomJob()->url;
126
    }
127
    function getColor() {
128
        return $this->getDomJob()->color;
129
    }
130
    function getColorNoAnime() {
131
        $color = $this->getColor();
132
        if (strpos($color, "_anime")) {
133
            $color = substr($color, 0, strpos($color, "_anime"));
134
        }
135
        return $color;
136
    }
137
    function getStatus() {
138
        switch ($this->getColor()) {
139
            case "blue":
140
                // The last build was successful.
141
                return $GLOBALS['Language']->getText('plugin_hudson','status_blue');
142
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
143
            case "blue_anime":
144
                // The last build was successful. A new build is in progress.
145
                return $GLOBALS['Language']->getText('plugin_hudson','status_blue_anime');
146
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
147
            case "yellow":
148
                // The last build was successful but unstable. This is primarily used to represent test failures.
149
                return $GLOBALS['Language']->getText('plugin_hudson','status_yellow'); 
150
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
151
            case "yellow_anime":
152
                // The last build was successful but unstable. This is primarily used to represent test failures. A new build is in progress.
153
                return $GLOBALS['Language']->getText('plugin_hudson','status_yellow_anime'); 
154
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
155
            case "red":
156
                // The last build fatally failed.
157
                return $GLOBALS['Language']->getText('plugin_hudson','status_red');
158
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
159
            case "red_anime":
160
                // The last build fatally failed. A new build is in progress.
161
                return $GLOBALS['Language']->getText('plugin_hudson','status_red_anime');
162
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
163
            case "grey":
164
                // The project has never been built before, or the project is disabled.
165
                return $GLOBALS['Language']->getText('plugin_hudson','status_grey');
166
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
167
            case "grey_anime":
168
                // The project has never been built before, or the project is disabled. The first build of this project is in progress.
169
                return $GLOBALS['Language']->getText('plugin_hudson','status_grey_anime');
170
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
171
            default:
172
                // Can we have anime icons here?
173
                return $GLOBALS['Language']->getText('plugin_hudson','status_unknown');
174
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
175
        }
176
    }
177
    
178
    function getIconsPath() {
179
        return $this->icons_path;
180
    }
181
    function getStatusIcon() {
182
        switch ($this->getColor()) {
183
            case "blue":
184
                // The last build was successful.
185
                return $this->getIconsPath()."status_blue.png";
186
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
187
            case "blue_anime":
188
                // The last build was successful. A new build is in progress.
189
                return $this->getIconsPath()."status_blue.png";
190
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
191
            case "yellow":
192
                // The last build was successful but unstable. This is primarily used to represent test failures.
193
                return $this->getIconsPath()."status_yellow.png"; 
194
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
195
            case "yellow_anime":
196
                // The last build was successful but unstable. A new build is in progress.
197
                return $this->getIconsPath()."status_yellow.png";
198
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
199
            case "red":
200
                // The last build fatally failed.
201
                return $this->getIconsPath()."status_red.png";
202
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
203
            case "red_anime":
204
                // The last build fatally failed. A new build is in progress.
205
                return $this->getIconsPath()."status_red.png";
206
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
207
            case "grey":
208
                // The project has never been built before, or the project is disabled.
209
                return $this->getIconsPath()."status_grey.png";
210
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
211
            case "grey_anime":
212
                // The first build of the project is in progress.
213
                return $this->getIconsPath()."status_grey.png";
214
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
215
            default:
216
                // Can we have anime icons here?
217
                return $this->getIconsPath()."status_unknown.png";
218
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
219
        }
220
    }
221
    
222
    function isBuildable() {
223
        return ($this->getDomJob()->buildable == "true");
224
    }
225
    
226
    function hasBuilds() {
227
        return ((int)$this->getLastBuildNumber() !== 0); 
228
    }
229
    
230
    function getLastBuildNumber() {
231
        return $this->getDomJob()->lastBuild->number;
232
    }
233
    function getLastBuildUrl() {
234
        return $this->getDomJob()->lastBuild->url;
235
    }
236
    
237
    function getLastSuccessfulBuildNumber() {
238
        return $this->getDomJob()->lastSuccessfulBuild->number;
239
    }
240
    function getLastSuccessfulBuildUrl() {
241
        return $this->getDomJob()->lastSuccessfulBuild->url;
242
    }
243
    
244
    function getLastFailedBuildNumber() {
245
        return $this->getDomJob()->lastFailedBuild->number;
246
    }
247
    function getLastFailedBuildUrl() {
248
        return $this->getDomJob()->lastFailedBuild->url;
249
    }
250
    
251
    function getNextBuildNumber() {
252
        return $this->getDomJob()->nextBuildNumber;
253
    }
254
    
255
    function getHealthScores() {
256
        $scores = array();
257
        foreach ($this->getDomJob()->healthReport as $health_report) {
258
            $scores[] = $health_report->score;
259
        }
260
        return $scores;
261
    }
262
    function getHealthDescriptions() {
263
        $descs = array();
264
        foreach ($this->getDomJob()->healthReport as $health_report) {
265
            $scores[] = $health_report->description;
266
        }
267
        return $descs;
268
    }
269
    function getHealthAverageScore() {
270
        $arr = $this->getHealthScores();
271
        $sum = 0;
272
        foreach ($arr as $score) {
273
            $sum += (int)$score;
274
        }
275
        $num = sizeof($arr);
276
        if ($num != 0) {
277
            return floor($sum/$num);
278
        } else {
279
            return 0;
280
        }
281
    }
282
    
283
    function getWeatherReportIcon() {
284
        $score = $this->getHealthAverageScore();
285
        if ($score >= 80) {
286
            return $this->getIconsPath()."health_80_plus.gif";
287
        } elseif ($score >= 60) {
288
            return $this->getIconsPath()."health_60_to_79.gif";
289
        } elseif ($score >= 40) {
290
            return $this->getIconsPath()."health_40_to_59.gif";
291
        } elseif ($score >= 20) {
292
            return $this->getIconsPath()."health_20_to_39.gif";
293
        } else {
294
            return $this->getIconsPath()."health_00_to_19.gif";
295
        }
296
    }
297
    
298
    /**
299
     * Launch a Build for this job on the Continuous Integration server.
300
     * 
301
     * @exception if unable to open build URL or if response is an error
302
     *  
303
     * @param string $token if CI server has activated security (login/password), then a token is mandatory to build jobs. This token is defined in the job configuration.
304
     * @return response of build call.
305
     */
306
    function launchBuild($token = null) {
307
        $url = $this->hudson_dobuild_url;
308
        if ($token != null) {
0 ignored issues
show
It seems like you are loosely comparing $token of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
309
            $url .= '?token='.$token;
310
        }
311
        $params = array('http' => array(
312
                     'method' => 'POST',
313
                     'content' => ''
314
                ));
315
        $ctx = stream_context_create($params);
316
        $fp = fopen($url, 'rb', false, $ctx);
317
        if (!$fp) {
318
            throw new Exception("Problem with $url");
319
        }
320
        $response = stream_get_contents($fp);
321
        if ($response === false) {
322
            throw new Exception("Problem reading data from $url");
323
        }
324
        return $response;
325
    }
326
    
327
}
328
329
?>