Issues (205)

Security Analysis    no request data  

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.

src/plugins/onTick/getKillmailsOld.php (22 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
 * The MIT License (MIT)
4
 *
5
 * Copyright (c) 2016 Robert Sardinia
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 */
25
26
use discord\discord;
27
28
/**
29
 * Class getKillmails
30
 */
31
class getKillmailsOld
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
32
{
33
    public $config;
34
    public $db;
35
    public $discord;
36
    public $channelConfig;
37
    public $lastCheck = 0;
38
    public $logger;
39
    public $groupConfig;
40
41
    /**
42
     * @param $config
43
     * @param $discord
44
     * @param $logger
45
     */
46 View Code Duplication
    public function init($config, $discord, $logger)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        $this->config = $config;
49
        $this->discord = $discord;
50
        $this->logger = $logger;
51
        $this->groupConfig = $config['plugins']['getKillmails']['groupConfig'];
52
        $this->guild = $config['bot']['guild'];
0 ignored issues
show
The property guild does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
53
        //Refresh check at bot start
54
        setPermCache('killmailCheck', time() - 5);
55
    }
56
57
    /**
58
     *
59
     */
60
    public function tick()
61
    {
62
        // What was the servers last reported state
63
        $lastStatus = getPermCache('serverState');
64
        if ($lastStatus === 'online') {
65
            $lastChecked = getPermCache('killmailCheck');
66
            if ($lastChecked <= time()) {
67
                //check if user is still using the old config
68 View Code Duplication
                if (null === $this->groupConfig) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
                    $this->logger->addError('Killmails: UPDATE YOUR CONFIG TO RECEIVE KILLMAILS');
70
                    setPermCache('killmailCheck', time() + 600);
71
                    return null;
72
                }
73
                $this->logger->addInfo('Killmails: Checking for new killmails.');
74
                $this->getKM();
75
                setPermCache('killmailCheck', time() + 600);
76
                if (@$this->config['plugins']['getKillmails']['bigKills']['shareBigKills'] === 'true') {
77
                    $this->logger->addInfo('Killmails: Checking for 10b+ kills.');
78
                    $this->getBigKM();
79
                }
80
            }
81
        }
82
    }
83
84
    private function getKM()
85
    {
86
        foreach ($this->groupConfig as $kmGroup) {
87
            $SavedKillID = getPermCache("{$kmGroup['name']}newestKillmailID");
88
            //check if start id is greater than current id and if it is set
89
            if (null !== $SavedKillID && preg_match('/[a-z]/i', $SavedKillID)) {
90
                getStartMail($kmGroup);
91
                $SavedKillID = getPermCache("{$kmGroup['name']}newestKillmailID");
92
            }
93
            if ($kmGroup['startMail'] > $SavedKillID || null === $SavedKillID) {
94
                $SavedKillID = $kmGroup['startMail'];
95
            }
96 View Code Duplication
            if ((string)$kmGroup['allianceID'] === '0' & $kmGroup['lossMails'] === 'true') {
0 ignored issues
show
Comprehensibility introduced by
Consider adding parentheses for clarity. Current Interpretation: ((string) $kmGroup['alli...'lossMails'] === 'true', Probably Intended Meaning: (string) $kmGroup['allia...lossMails'] === 'true')

When comparing the result of a bit operation, we suggest to add explicit parenthesis and not to rely on PHP’s built-in operator precedence to ensure the code behaves as intended and to make it more readable.

Let’s take a look at these examples:

// Returns always int(0).
return 0 === $foo & 4;
return (0 === $foo) & 4;

// More likely intended return: true/false
return 0 === ($foo & 4);
Loading history...
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
                $url = "https://zkillboard.com/api/corporationID/{$kmGroup['corpID']}/no-attackers/no-items/orderDirection/asc/pastSeconds/10800/";
98
            }
99 View Code Duplication
            if ((string)$kmGroup['allianceID'] === '0' & $kmGroup['lossMails'] === 'false') {
0 ignored issues
show
Comprehensibility introduced by
Consider adding parentheses for clarity. Current Interpretation: ((string) $kmGroup['alli...lossMails'] === 'false', Probably Intended Meaning: (string) $kmGroup['allia...ossMails'] === 'false')

When comparing the result of a bit operation, we suggest to add explicit parenthesis and not to rely on PHP’s built-in operator precedence to ensure the code behaves as intended and to make it more readable.

Let’s take a look at these examples:

// Returns always int(0).
return 0 === $foo & 4;
return (0 === $foo) & 4;

// More likely intended return: true/false
return 0 === ($foo & 4);
Loading history...
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
                $url = "https://zkillboard.com/api/corporationID/{$kmGroup['corpID']}/no-attackers/no-items/kills/orderDirection/asc/pastSeconds/10800/";
101
            }
102 View Code Duplication
            if ((string)$kmGroup['allianceID'] !== '0' & $kmGroup['lossMails'] === 'true') {
0 ignored issues
show
Comprehensibility introduced by
Consider adding parentheses for clarity. Current Interpretation: ((string) $kmGroup['alli...'lossMails'] === 'true', Probably Intended Meaning: (string) $kmGroup['allia...lossMails'] === 'true')

When comparing the result of a bit operation, we suggest to add explicit parenthesis and not to rely on PHP’s built-in operator precedence to ensure the code behaves as intended and to make it more readable.

Let’s take a look at these examples:

// Returns always int(0).
return 0 === $foo & 4;
return (0 === $foo) & 4;

// More likely intended return: true/false
return 0 === ($foo & 4);
Loading history...
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
                $url = "https://zkillboard.com/api/allianceID/{$kmGroup['allianceID']}/no-attackers/no-items/orderDirection/asc/pastSeconds/10800/";
104
            }
105 View Code Duplication
            if ((string)$kmGroup['allianceID'] !== '0' & $kmGroup['lossMails'] === 'false') {
0 ignored issues
show
Comprehensibility introduced by
Consider adding parentheses for clarity. Current Interpretation: ((string) $kmGroup['alli...lossMails'] === 'false', Probably Intended Meaning: (string) $kmGroup['allia...ossMails'] === 'false')

When comparing the result of a bit operation, we suggest to add explicit parenthesis and not to rely on PHP’s built-in operator precedence to ensure the code behaves as intended and to make it more readable.

Let’s take a look at these examples:

// Returns always int(0).
return 0 === $foo & 4;
return (0 === $foo) & 4;

// More likely intended return: true/false
return 0 === ($foo & 4);
Loading history...
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
                $url = "https://zkillboard.com/api/allianceID/{$kmGroup['allianceID']}/no-attackers/no-items/kills/orderDirection/asc/pastSeconds/10800/";
107
            }
108
109
            if (!isset($url)) { // Make sure it's always set.
110
                $this->logger->addInfo('Killmails: ERROR - Ensure your config file is setup correctly for killmails.');
111
                return null;
112
            }
113
114
            $kills = json_decode(downloadData($url), true);
115
//            $i = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
116
            if (isset($kills)) {
117
                foreach ($kills as $kill) {
118
 //                   if ($i < 10) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
119
                        //if big kill isn't set, disable it
120
                        if (!array_key_exists('bigKill', $kmGroup)) {
121
                            $kmGroup['bigKill'] = 99999999999999999999999999;
122
                        }
123
                        $killID = $kill['killID'];
124
                        if ($killID <= $SavedKillID) {
125
//                            $i++;
126
                            continue;
127
                        }
128
                        $channelID = $kmGroup['channel'];
129
                        $solarSystemID = $kill['solarSystemID'];
130
                        $systemName = systemName($solarSystemID);
131
                        $killTime = $kill['killTime'];
132
                        $victimAllianceName = '';
133 View Code Duplication
                    if ($kill['victim']['allianceName'] !== null && $kill['victim']['allianceName'] !== '') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134
                            $victimAllianceName = "|{$kill['victim']['allianceName']}";
135
                        }
136
                        $victimName = $kill['victim']['characterName'];
137
                        $victimCorpName = $kill['victim']['corporationName'];
138
                        $victimShipID = $kill['victim']['shipTypeID'];
139
                        $shipName = apiTypeName($victimShipID);
140
                        $rawValue = $kill['zkb']['totalValue'];
141
                        //Check if killmail meets minimum value and if it meets lost minimum value
142
                        if (isset($kmGroup['minimumValue']) && isset($kmGroup['minimumlossValue'])) {
143
                            if ($rawValue < $kmGroup['minimumValue']) {
144
                                if ($kill['victim']['corporationID'] == $kmGroup['corpID'] && $rawValue > $kmGroup['minimumlossValue'] ||
145
                                $kill['victim']['allianceID'] == $kmGroup['allianceID'] && $rawValue > $kmGroup['minimumlossValue'])
146
                                {
147
                                    $this->logger->addInfo("Killmails: Mail {$killID} posted because it meet minimum loss value required.");
148
                                } else {
149
                                    $this->logger->addInfo("Killmails: Mail {$killID} ignored for not meeting the minimum value required.");
150
                                    setPermCache("{$kmGroup['name']}newestKillmailID", $killID);
151
                                    continue;
152
                                }
153
                            }
154
                        }
155
                        $totalValue = number_format($kill['zkb']['totalValue']);
156
                        // Check if it's a structure
157 View Code Duplication
                        if ($victimName !== '') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
                            if ($kmGroup['bigKill'] != null && $rawValue >= $kmGroup['bigKill']) {
159
                                $channelID = $kmGroup['bigKillChannel'];
160
                                $msg = "@here \n :warning:***Expensive Killmail***:warning: \n **{$killTime}**\n\n**{$shipName}** worth **{$totalValue} ISK** flown by **{$victimName}** of (***{$victimCorpName}|{$victimAllianceName}***) killed in {$systemName}\nhttps://zkillboard.com/kill/{$killID}/";
161
                            } elseif ($kmGroup['bigKill'] == null || $rawValue <= $kmGroup['bigKill']) {
162
                                $msg = "**{$killTime}**\n\n**{$shipName}** worth **{$totalValue} ISK** flown by **{$victimName}** of (***{$victimCorpName}|{$victimAllianceName}***) killed in {$systemName}\nhttps://zkillboard.com/kill/{$killID}/";
163
                            }
164
                        } elseif ($victimName === '') {
165
                            $msg = "**{$killTime}**\n\n**{$shipName}** worth **{$totalValue} ISK** owned by (***{$victimCorpName}|{$victimAllianceName}***) killed in {$systemName}\nhttps://zkillboard.com/kill/{$killID}/";
166
                        }
167
168
                        if (!isset($msg)) { // Make sure it's always set.
169
                            return null;
170
                        }
171
                        queueMessage($msg, $channelID, $this->guild);
172
                        $this->logger->addInfo("Killmails: Mail {$killID} queued.");
173
174
//                        $i++;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
175
/*                    } else {
176
                        $updatedID = getPermCache("{$kmGroup['name']}newestKillmailID");
177
                        $this->logger->addInfo("Killmails: Kill posting cap reached, newest kill id for {$kmGroup['name']} is {$updatedID}");
178
                        break;
179
                    }*/
180
                }
181
                if (!isset($killID)) {
182
                    $killID = $SavedKillID;
183
                }
184
                setPermCache("{$kmGroup['name']}newestKillmailID", $killID);
185
            }
186
            $updatedID = getPermCache("{$kmGroup['name']}newestKillmailID");
187
            $this->logger->addInfo("Killmails: All kills posted, newest kill id for {$kmGroup['name']} is {$updatedID}");
188
            continue;
189
        }
190
    }
191
192
    private function getBigKM()
193
    {
194
        $oldID = getPermCache('bigKillNewestKillmailID');
195
        if (null === $oldID || preg_match('/[a-z]/i', $oldID)) {
196
            getStartBigMail();
197
            $oldID = getPermCache('bigKillNewestKillmailID');
198
        }
199
200
        $url = 'https://zkillboard.com/api/kills/orderDirection/desc/iskValue/10000000000/limit/10/';
201
202
        $kills = json_decode(downloadData($url), true);
203
        $i = 0;
0 ignored issues
show
$i 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...
204
        if (isset($kills)) {
205
            foreach ($kills as $kill) {
206
                $cacheID = getPermCache('bigKillNewestKillmailID');
207
 //               if ($i < 10) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
208
                    $killID = $kill['killID'];
209
                    //check if mail is old
210
                    if ((int)$killID <= (int)$oldID) {
211
                        continue;
212
                    }
213
                    //save highest killID for cache
214
                    if ($killID > $cacheID) {
215
                        setPermCache('bigKillNewestKillmailID', $killID);
216
                    }
217
                    $channelID = $this->config['plugins']['getKillmails']['bigKills']['bigKillChannel'];
218
                    $solarSystemID = $kill['solarSystemID'];
219
                    $systemName = systemName($solarSystemID);
220
                    $killTime = $kill['killTime'];
221
                $victimAllianceName = '';
222 View Code Duplication
                if ($kill['victim']['allianceName'] !== null && $kill['victim']['allianceName'] !== '') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
223
                    $victimAllianceName = "|{$kill['victim']['allianceName']}";
224
                }
225
                    $victimName = $kill['victim']['characterName'];
226
                    $victimCorpName = $kill['victim']['corporationName'];
227
                    $victimShipID = $kill['victim']['shipTypeID'];
228
                    $shipName = apiTypeName($victimShipID);
229
                    $totalValue = number_format($kill['zkb']['totalValue']);
230
                    // Check if it's a structure
231 View Code Duplication
                    if ($victimName !== '') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
232
                        $msg = "**10b+ Kill Reported**\n\n**{$killTime}**\n\n**{$shipName}** worth **{$totalValue} ISK** flown by **{$victimName}** of (***{$victimCorpName}|{$victimAllianceName}***) killed in {$systemName}\nhttps://zkillboard.com/kill/{$killID}/";
233
                    } else {
234
                        $msg = "**10b+ Kill Reported**\n\n**{$killTime}**\n\n**{$shipName}** worth **{$totalValue} ISK** owned by (***{$victimCorpName}|{$victimAllianceName}***) killed in {$systemName}\nhttps://zkillboard.com/kill/{$killID}/";
235
                    }
236
                    if (!isset($msg)) { // Make sure it's always set.
237
                        return null;
238
                    }
239
                    queueMessage($msg, $channelID, $this->guild);
240
                    $this->logger->addInfo("Killmails: Mail {$killID} queued.");
241
242
/*                    $i++;
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
243
                } else {
244
                    $cacheID = getPermCache('bigKillNewestKillmailID');
245
                    $this->logger->addInfo("Killmails: bigKill posting cap reached, newest kill id is {$cacheID}");
246
                    break;
247
                }*/
248
            }
249
        }
250
        $updatedID = getPermCache('bigKillNewestKillmailID');
251
        $this->logger->addInfo("Killmails: All bigKills posted, newest kill id is {$updatedID}");
252
    }
253
}
254