Issues (438)

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.

classes/Related.php (3 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
/* zKillboard
3
 * Copyright (C) 2012-2015 EVE-KILL Team and EVSCO.
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
/**
20
 * Parser for raw killmails from ingame EVE.
21
 */
22
23
class Related
24
{
25
	private static $killstorage = array();
26
27
	public static function buildSummary(&$kills, $parameters, $options)
0 ignored issues
show
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
	{
29
		$involvedEntities = array();
30
		foreach($kills as $killID => $kill)
31
			self::addAllInvolved($involvedEntities, $killID);
32
33
		$blueTeam = array();
34
		$redTeam = self::findWinners($kills, "allianceID");
35
		foreach($involvedEntities as $entity=>$chars)
36
			if (!in_array($entity, $redTeam))
37
				$blueTeam[] = $entity;
38
39
		if (isset($options["A"]))
40
			self::assignSides($options["A"], $redTeam, $blueTeam);
41
		if (isset($options["B"]))
42
			self::assignSides($options["B"], $blueTeam, $redTeam);
43
44
		$redInvolved = self::getInvolved($kills, $redTeam);
45
		$blueInvolved = self::getInvolved($kills, $blueTeam);
46
47
		$redKills = self::getKills($kills, $redTeam);
48
		$blueKills = self::getKills($kills, $blueTeam);
49
50
		$redKillIDs = self::getKillIDs($kills, $redTeam);
51
		$blueKillIDs = self::getKillIDs($kills, $blueTeam);
52
53
		self::addMoreInvolved($redInvolved, $redKills);
54
		self::addMoreInvolved($blueInvolved, $blueKills);
55
56
		$redTotals = self::getStatsKillList(array_keys($redKills));
57
		$redTotals["pilotCount"] = count($redInvolved);
58
		$blueTotals = self::getStatsKillList(array_keys($blueKills));
59
		$blueTotals["pilotCount"] = count($blueInvolved);
60
61
		$red = self::addInfo($redTeam);
62
		asort($red);
63
		$blue = self::addInfo($blueTeam);
64
		asort($blue);
65
66
		usort($redInvolved, "Related::compareShips");
67
		usort($blueInvolved, "Related::compareShips");
68
69
		$retValue = array(
70
			"teamA" => array(
71
				"list" => $redInvolved,
72
				"kills" => $redKills,
73
				"totals" => $redTotals,
74
				"entities" => $red,
75
				"killIDs" => $redKillIDs
76
			),
77
			"teamB" => array(
78
				"list" => $blueInvolved,
79
				"kills" => $blueKills,
80
				"totals" => $blueTotals,
81
				"entities" => $blue,
82
				"killIDs" => $blueKillIDs
83
			),
84
		);
85
		return $retValue;
86
	}
87
88
	private static function addAllInvolved(&$entities, $killID)
89
	{
90
		$killjson = Killmail::get($killID);
91
		$kill = json_decode($killjson, true);
92
93
		self::$killstorage[$killID] = $kill;
94
95
		$victim = $kill["victim"];
96
		self::addInvolved($entities, $victim);
97
		$involved = $kill["attackers"];
98
		foreach($involved as $entry)
99
			self::addInvolved($entities, $entry);
100
	}
101
102
	private static function addInvolved(&$entities, &$entry)
103
	{
104
		$entity = isset($entry["allianceID"]) && $entry["allianceID"] != 0 ? $entry["allianceID"] : $entry["corporationID"];
105
		if (!isset($entities["$entity"]))
106
			$entities["$entity"] = array();
107
		if (!in_array($entry["characterID"], $entities["$entity"]))
108
			$entities["$entity"][] = $entry["characterID"];
109
	}
110
111
	private static function getInvolved(&$kills, $team)
112
	{
113
		$involved = array();
114
		foreach($kills as $kill)
115
		{
116
			$kill = self::$killstorage[$kill["victim"]["killID"]];
117
118
			$attackers = $kill["attackers"];
119
			foreach($attackers as $entry)
120
			{
121
				$add = false;
122
				if (in_array($entry["allianceID"], $team))
123
					$add = true;
124
				if (in_array($entry["corporationID"], $team))
125
					$add = true;
126
127
				if ($add)
128
				{
129
					$key = $entry["characterID"] . ":" . $entry["corporationID"] . ":" . $entry["allianceID"] . ":" . $entry["shipTypeID"];
130
					$entry["shipName"] = Info::getItemName($entry["shipTypeID"]);
131
					if (!in_array($key, $involved))
132
						$involved[$key] = $entry;
133
				}
134
			}
135
		}
136
		return $involved;
137
	}
138
139
	private static function addMoreInvolved(&$team, $kills)
140
	{
141
		foreach($kills as $kill)
142
		{
143
			$victim = $kill["victim"];
144
			Info::addInfo($victim);
145
			if ($victim["characterID"] > 0 && $victim["groupID"] != 29)
146
			{
147
				$key = $victim["characterID"] . ":" . $victim["corporationID"] . ":" . $victim["allianceID"] . ":" . $victim["shipTypeID"];
148
				$victim["destroyed"] = $victim["killID"];
149
				$team[$key] = $victim;
150
			}
151
		}
152
	}
153
154
	private static function getKills(&$kills, $team)
155
	{
156
		$teamsKills = array();
157
		foreach($kills as $killID=>$kill)
158
		{
159
			$victim = $kill["victim"];
160
			$add = in_array($victim["allianceID"], $team) || in_array($victim["corporationID"], $team);
161
162
			if ($add)
163
				$teamsKills[$killID] = $kill;
164
		}
165
		return $teamsKills;
166
	}
167
168
	private static function getKillIDs(&$kills, $team)
169
	{
170
		$killIDs = array();
171
		foreach($kills as $killID => $kill)
172
		{
173
			$victim = $kill["victim"];
174
			$add = in_array($victim["allianceID"], $team) || in_array($victim["corporationID"], $team);
175
176
			if($add)
177
				$killIDs[] = $killID;
178
		}
179
	return $killIDs;
180
	}
181
182
	private static function getStatsKillList($killIDs)
183
	{
184
		$totalPrice = 0;
185
		$totalPoints = 0;
186
		$groupIDs = array();
187
		$totalShips = 0;
188
		foreach ($killIDs as $killID) {
189
			$kill = Kills::getKillDetails($killID);
190
			$info = $kill["info"];
191
			$victim = $kill["victim"];
192
			$totalPrice += $info["total_price"];
193
			$totalPoints += $info["points"];
194
			$groupID = $victim["groupID"];
195
			if (!isset($groupIDs[$groupID]))
196
			{
197
				$groupIDs[$groupID] = array();
198
				$groupIDs[$groupID]["count"] = 0;
199
				$groupIDs[$groupID]["isk"] = 0;
200
				$groupIDs[$groupID]["points"] = 0;
201
			}
202
			$groupIDs[$groupID]["groupID"] = $groupID;
203
			$groupIDs[$groupID]["count"]++;
204
			$groupIDs[$groupID]["isk"] += $info["total_price"];
205
			$groupIDs[$groupID]["points"] += $info["points"];
206
			$totalShips++;
207
		}
208
		Info::addInfo($groupIDs);
209
		return array(
210
			"total_price" => $totalPrice, "groupIDs" => $groupIDs, "totalShips" => $totalShips,
211
			"total_points" => $totalPoints
212
		);
213
	}
214
215
	private static function addInfo(&$team)
216
	{
217
		$retValue = array();
218
		foreach($team as $entity)
219
		{
220
			$alliName = Info::getAlliName($entity);
221
			if ($alliName)
222
				$retValue[$entity] = $alliName;
223
			else
224
				$retValue[$entity] = Info::getCorpName($entity);
225
		}
226
		return $retValue;
227
	}
228
229
	/**
230
	 * @param string $typeColumn
231
	 */
232
	private static function findWinners(&$kills, $typeColumn)
0 ignored issues
show
The parameter $typeColumn is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
233
	{
234
		$involvedArray = array();
235
		foreach ($kills as $killID=>$kill) {
236
			$finalBlow = $kill["finalBlow"];
237
			$added = self::addInvolvedEntity($involvedArray, $killID, $finalBlow["allianceID"]);
238
			if (!$added)
239
				$added = self::addInvolvedEntity($involvedArray, $killID, $finalBlow["corporationID"]);
240
			if (!$added)
241
				$added = self::addInvolvedEntity($involvedArray, $killID, $finalBlow["characterID"]);
0 ignored issues
show
$added is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
242
		}
243
		return array_keys($involvedArray);
244
	}
245
246
	public static function compareShips($a, $b)
247
	{
248
		$aSize = Db::queryField("select mass from ccp_invTypes where typeID = :typeID", "mass", array(":typeID" => $a["shipTypeID"]));
249
		$bSize = Db::queryField("select mass from ccp_invTypes where typeID = :typeID", "mass", array(":typeID" => $b["shipTypeID"]));
250
		return $aSize < $bSize;
251
	}
252
253
	private static function addInvolvedEntity(&$involvedArray, &$killID, &$entity)
254
	{
255
		if ($entity == 0)
256
			return false;
257
		if (!isset($involvedArray["$entity"]))
258
			$involvedArray["$entity"] = array();
259
		if (!in_array($killID, $involvedArray["$entity"]))
260
		{
261
			$involvedArray["$entity"][] = $killID;
262
			return true;
263
		}
264
		return false;
265
	}
266
267
	private static function assignSides($assignees, &$teamA, &$teamB)
268
	{
269
		foreach($assignees as $id)
270
		{
271
			if (!isset($teamA[$id]))
272
				$teamA[] = $id;
273
			if (($key = array_search($id, $teamB)) !== false)
274
				unset($teamB[$key]);
275
		}
276
	}
277
}
278