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/Detail.php (8 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
class Detail {
20
21
	public static function involvedships($array)
22
	{
23
		$involved = array();
24
		foreach($array as $inv)
25
		{
26
			if(isset($involved[$inv["shipTypeID"]]) && isset($inv["shipName"]))
27
				$involved[$inv["shipTypeID"]] = array("shipName" => $inv["shipName"], "shipTypeID" => $inv["shipTypeID"], "count" => $involved[$inv["shipTypeID"]]["count"] + 1);
28
			elseif(isset($inv["shipTypeID"]) && isset($inv["shipName"]))
29
			{
30
				$involved[$inv["shipTypeID"]] = array("shipName" => $inv["shipName"], "shipTypeID" => $inv["shipTypeID"], "count" => 1);
31
			}
32
			else
33
				continue;
34
		}
35
36
		usort($involved, "sortByOrder");
37
		return $involved;
38
	}
39
40
	public static function sortByOrder($a, $b)
41
	{
42
		return $a["count"] < $b["count"];
43
	}
44
45
	public static function usdeurgbp($totalprice)
46
	{
47
		$usd = 17;
48
		$eur = 13;
49
		$gbp = 10;
50
		$plex = Price::getItemPrice("29668", date("Ymd"));
51
		$usdval = $plex / $usd;
52
		$eurval = $plex / $eur;
53
		$gbpval = $plex / $gbp;
54
55
		return array("usd" => $totalprice / $usdval, "eur" => $totalprice / $eurval, "gbp" => $totalprice / $gbpval);
56
	}
57
58
	public static function eftarray($md5, $items, $victimID = 0)
59
	{
60
		$Cache = Cache::get($md5."eftarray");
61
		if ($Cache) return $Cache;
0 ignored issues
show
Bug Best Practice introduced by
The expression $Cache of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
62
63
		// EFT / Fitting Wheel
64
		$eftarray["high"] = array(); // high
0 ignored issues
show
Coding Style Comprehensibility introduced by
$eftarray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $eftarray = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
65
		$eftarray["mid"] = array(); // mid
66
		$eftarray["low"] = array(); // low
67
		$eftarray["rig"] = array(); // rig
68
		$eftarray["drone"] = array(); // drone
69
		$eftarray["sub"] = array(); // sub
70
		$eftammo["high"] = array(); // high ammo
0 ignored issues
show
Coding Style Comprehensibility introduced by
$eftammo was never initialized. Although not strictly required by PHP, it is generally a good practice to add $eftammo = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
71
		$eftammo["mid"] = array(); // mid ammo
72
73
		foreach($items as $itm)
74
		{
75
			if (!isset($itm["inContainer"])) $itm["inContainer"] = 0;
76
			if ($victimID >= 2100000000 && $victimID <= 2999999999) $itm["flagName"] = Info::getGroupName(Info::getGroupID($itm["typeID"]));
77
			else if (!isset($itm["flagName"])) $itm["flagName"] = Info::getFlagName($itm["flag"]);
78
79
			if ($itm["flagName"] == "Infantry Modules") $itm["flagName"] = "Mid Slots";
80
			if ($itm["flagName"] == "Infantry Weapons") $itm["flagName"] = "High Slots";
81
			if ($itm["flagName"] == "Infantry Equipment") $itm["flagName"] = "Low Slots";
82
			if ($itm["flag"] == 89) {
83
				$slot = Db::queryField("select coalesce(valueInt, valueFloat) slot from ccp_dgmTypeAttributes where typeID = :typeID and attributeID = 331", "slot", array(":typeID" => $itm["typeID"]));
84
				if ($slot <= 5 && $slot >= 1) {
85
					$itm["flagName"] = "High Slots";
86
					$itm["flag"] = 27 + ($slot - 1);
87
				}
88
				else if ($slot > 5 && $slot <= 10) {
89
					$itm["flagName"] = "Low Slots";
90
					$itm["flag"] = 11 + ($slot - 6);
91
				}
92
				$itm["fittable"] = 1;
93
			}
94
95
			if (!isset($itm["flag"]) || $itm["flag"] == 0) {
96
				if ($itm["flagName"] == "High Slots") $itm["flag"] = 27;
97
				if ($itm["flagName"] == "Mid Slots") $itm["flag"] = 19;
98
				if ($itm["flagName"] == "Low Slots") $itm["flag"] = 11;
99
			}
100
101
			$key = $itm["typeName"] . "|" . $itm["flagName"];
102
			if(isset($itm["flagName"]))
103
			{
104
				if($itm["fittable"] && $itm["inContainer"] == 0) // not ammo or whatever
105
				{
106
					$repeats = $itm["qtyDropped"] + $itm["qtyDestroyed"];
107
					$i = 0;
108
					while($i < $repeats)
109
					{
110
						if($itm["flagName"] == "High Slots")
111
						{
112
high:
113
							if(isset($eftarray["high"][$itm["flag"]]))
114
							{
115
								$itm["flag"] = $itm["flag"]+1;
116
								goto high;
117
							}
118
							$eftarray["high"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"]);
119
						}
120
						if($itm["flagName"] == "Mid Slots")
121
						{
122
mid:
123
							if(isset($eftarray["mid"][$itm["flag"]]))
124
							{
125
								$itm["flag"] = $itm["flag"]+1;
126
								goto mid;
127
							}
128
							$eftarray["mid"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"]);
129
						}
130
						if($itm["flagName"] == "Low Slots")
131
						{
132
low:
133
							if(isset($eftarray["low"][$itm["flag"]]))
134
							{
135
								$itm["flag"] = $itm["flag"]+1;
136
								goto low;
137
							}
138
							$eftarray["low"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"]);
139
						}
140
						if($itm["flagName"] == "Rigs")
141
						{
142
rigs:
143
							if(isset($eftarray["rig"][$itm["flag"]]))
144
							{
145
								$itm["flag"] = $itm["flag"]+1;
146
								goto rigs;
147
							}
148
							$eftarray["rig"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"]);
149
						}
150
						if($itm["flagName"] == "SubSystems")
151
						{
152
subs:
153
							if(isset($eftarray["sub"][$itm["flag"]]))
154
							{
155
								$itm["flag"] = $itm["flag"]+1;
156
								goto subs;
157
							}
158
							$eftarray["sub"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"]);
159
						}
160
						$i++;
161
					}
162
				}
163
				else
164
				{
165
					if($itm["flagName"] == "Drone Bay")
166
						$eftarray["drone"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"], "qty" => $itm["qtyDropped"] + $itm["qtyDestroyed"]);
167
				}
168
			}
169
		}
170
171
		// Ammo shit
172
		foreach($items as $itm) {
173
			if (!isset($itm["inContainer"])) $itm["inContainer"] = 0;
174
			if($itm["inContainer"] == 0 && !$itm["fittable"] && isset($itm["flagName"])) // possibly ammo
175
			{
176
				if($itm["flagName"] == "High Slots") // high slot ammo
177
					$eftarray["high"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"], "charge" => true);
178
				if($itm["flagName"] == "Mid Slots") // mid slot ammo
179
					$eftarray["mid"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"], "charge" => true);
180
				if($itm["flagName"] == "Low Slots") // mid slot ammo
181
					$eftarray["low"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"], "charge" => true);
182
			}
183
		}
184
		foreach($eftarray as $key=>$value) {
185
			if (sizeof($value)) {
186
				asort($value);
187
				$eftarray[$key] = $value;
188
			} else unset($eftarray[$key]);
189
		}
190
		Cache::set($md5."eftarray", $eftarray);
191
		return $eftarray;
192
	}
193
194
	public static function combineditems($md5, $items)
195
	{
196
		$Cache = Cache::get($md5."combineditems");
197
		if($Cache) return $Cache;
0 ignored issues
show
Bug Best Practice introduced by
The expression $Cache of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
198
199
		// Create the new item array with combined items and whatnot
200
		$itemList = array();
201
		foreach($items as $itm)
202
		{
203
			if (!isset($itm["inContainer"])) $itm["inContainer"] = 0;
204
			if ($itm["inContainer"] == 1) $itm["flag"] = 0;
205
			if (!isset($itm["flagName"])) $itm["flagName"] = Info::getFlagName($itm["flag"]);
206
			for ($i = 0; $i <= 1; $i++) {
207
				$mItem = $itm;
208
				if ($i == 0) $mItem["qtyDropped"] = 0;
209
				if ($i == 1) $mItem["qtyDestroyed"] = 0;
210
				if ($mItem["qtyDropped"] == 0 && $mItem["qtyDestroyed"] == 0) continue;
211
				$key = static::buildItemKey($mItem);
212
213
				if(!isset($itemList[$key])) {
214
					$itemList[$key] = $mItem;
215
					$itemList[$key]["price"] = $mItem["price"] * ($mItem["qtyDropped"] + $mItem["qtyDestroyed"]);
216
				}
217
				else {
218
					$itemList[$key]["qtyDropped"] += $mItem["qtyDropped"];
219
					$itemList[$key]["qtyDestroyed"] += $mItem["qtyDestroyed"];
220
					$itemList[$key]["price"] += $mItem["price"] * ($mItem["qtyDropped"] + $mItem["qtyDestroyed"]);
221
				}
222
			}
223
		}
224
		Cache::set($md5."combineditems", $itemList);
225
		return $itemList;
226
	}
227
228
        public static function fullCombinedItems($md5, $items)
0 ignored issues
show
The parameter $md5 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...
229
        {
230
                // Create the new item array with combined items and whatnot
231
                $itemList = array();
232
                foreach($items as $itm)
233
                {
234
                        if ($itm["fittable"] != 1) continue;
235
                        if (!isset($itm["inContainer"])) $itm["inContainer"] = 0;
236
                        if ($itm["inContainer"] == 1) $itm["flag"] = 0;
237
                        if (!isset($itm["flagName"])) $itm["flagName"] = Info::getFlagName($itm["flag"]);
238
239
			$mItem = $itm;
240
			if ($mItem["qtyDropped"] == 0 && $mItem["qtyDestroyed"] == 0) continue;
241
			$key = $itm["typeID"];
242
243
			if(!isset($itemList[$key])) {
244
				$itemList[$key] = $mItem;
245
				$itemList[$key]["price"] = $mItem["price"] * ($mItem["qtyDropped"] + $mItem["qtyDestroyed"]);
246
			}
247
			else $itemList[$key]["qtyDropped"] += $mItem["qtyDropped"];
248
			$itemList[$key]["qtyDropped"] += $mItem["qtyDestroyed"];
249
			$mItem["qtyDestroyed"] = 0;
250
			$itemList[$key]["price"] += $mItem["price"] * ($mItem["qtyDropped"] + $mItem["qtyDestroyed"]);
251
		}
252
		return $itemList;
253
	}
254
255
	public static function buildItemKey($itm)
256
	{
257
		$key = $itm["typeName"] . ($itm["singleton"] == 2 ? " (Copy)" : "");
258
		$key .= "|" . ($itm["qtyDropped"] > 0 ? "dropped" : "destroyed");
259
		if (!isset($itm["flagName"])) $itm["flagName"] = Info::getFlagName($itm["flag"]);
260
		$key .= "|" . $itm["flagName"];
261
		if (in_array($itm["groupID"], array(340, 649)) && isset($itm["items"])) $key .= microtime() . rand(0, 10000);
262
		return $key;
263
	}
264
265
	public static function involvedCorpsAndAllis($md5, $involved)
266
	{
267
		$Cache = Cache::get($md5."involvedCorpsAndAllis");
268
		if($Cache) return $Cache;
0 ignored issues
show
Bug Best Practice introduced by
The expression $Cache of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
269
270
		$involvedAlliCount = 0;
271
		$involvedCorpCount = 0;
272
		// Create the involved corps / alliances list
273
		$invAll = array();
274
		foreach($involved as $inv) {
275
			$allianceID = $inv["allianceID"];
276
			$corporationID = $inv["corporationID"];
277
			if (!isset($invAll["$allianceID"])) {
278
				$involvedAlliCount++;
279
				$invAll["$allianceID"] = array();
280
				if ($allianceID != 0) $invAll["$allianceID"]["allianceName"] = $inv["allianceName"];
281
				if ($allianceID != 0) $invAll["$allianceID"]["name"] = $inv["allianceName"];
282
				if ($allianceID != 0) $invAll["$allianceID"]["allianceID"] = $allianceID;
283
				$invAll["$allianceID"]["corporations"] = array();
284
				$invAll["$allianceID"]["involved"] = 0;
285
			}
286
			$involvedCount = $invAll["$allianceID"]["involved"];
287
			$invAll["$allianceID"]["involved"] = $involvedCount + 1;
288
289
			if (!isset($invAll["$allianceID"]["corporations"]["$corporationID"])) {
290
				$involvedCorpCount++;
291
				$invAll["$allianceID"]["corporations"]["$corporationID"] = array();
292
				$invAll["$allianceID"]["corporations"]["$corporationID"]["corporationName"] = isset($inv["corporationName"]) ? $inv["corporationName"] : "";
293
				$invAll["$allianceID"]["corporations"]["$corporationID"]["name"] = isset($inv["corporationName"]) ? $inv["corporationName"] : "";
294
				$invAll["$allianceID"]["corporations"]["$corporationID"]["corporationID"] = $corporationID;
295
				$invAll["$allianceID"]["corporations"]["$corporationID"]["involved"] = 0;
296
			}
297
			$involvedCount =  $invAll["$allianceID"]["corporations"]["$corporationID"]["involved"];
298
			$invAll["$allianceID"]["corporations"]["$corporationID"]["involved"] =  $involvedCount + 1;
299
		}
300
		uasort($invAll, "involvedSort");
301
		foreach($invAll as $id=>$alliance) {
302
			$corps = $alliance["corporations"];
303
			uasort($corps, "involvedSort");
304
			$invAll["$id"]["corporations"] = $corps;
305
		}
306
		if ($involvedCorpCount <= 1 && $involvedAlliCount <= 1) $invAll = array();
307
		Cache::set($md5."involvedCorpsAndAllis", $invAll);
308
		return $invAll;
309
	}
310
311
	public static function involvedSort($field1, $field2)
312
	{
313
		if ($field1["involved"] == $field2["involved"] && isset($field1["name"]) && isset($field2["name"])) return strcasecmp($field1["name"], $field2["name"]);
314
		return $field2["involved"] - $field1["involved"];
315
	}
316
317
	public static function droppedIsk($md5, $items)
318
	{
319
		$Cache = Cache::get($md5."droppedisk");
320
		if($Cache) return $Cache;
0 ignored issues
show
Bug Best Practice introduced by
The expression $Cache of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
321
322
		$droppedisk = 0;
323
		foreach($items as $dropped) {
324
			$droppedisk += $dropped["price"] * ($dropped["singleton"] ? $dropped["qtyDropped"] / 100 : $dropped["qtyDropped"]);
325
		}
326
327
		Cache::set($md5."droppedisk", $droppedisk);
328
		return $droppedisk;
329
	}
330
331
	public static function fittedIsk($md5, $items)
332
	{
333
		$key = $md5 . "fittedIsk";
334
		$cache = Cache::get($key);
335
		if($cache)
0 ignored issues
show
Bug Best Practice introduced by
The expression $cache of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
336
			return $cache;
337
338
		$fittedIsk = 0;
339
		$flags = array("High Slots", "Mid Slots", "Low Slots", "SubSystems", "Rigs", "Drone Bay", "Fuel Bay");
340
		foreach($items as $item)
341
		{
342
			if(isset($item["flagName"]) && in_array($item["flagName"], $flags)) {
343
				$qty = isset($item["qtyDropped"]) ? $item["qtyDropped"] : 0;
344
				$qty += isset($item["qtyDestroyed"]) ? $item["qtyDestroyed"] : 0;
345
				$fittedIsk = $fittedIsk + ($item["price"] * $qty);
346
			}
347
		}
348
		Cache::set($key, $fittedIsk);
349
		return $fittedIsk;
350
	}
351
}
352