Issues (64)

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/Commands/Command.php (1 issue)

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
 * This file is part of the TelegramBot package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\TelegramBot\Commands;
12
13
use Longman\TelegramBot\DB;
14
use Longman\TelegramBot\Request;
15
use Longman\TelegramBot\Telegram;
16
use Longman\TelegramBot\Entities\Update;
17
18
abstract class Command
19
{
20
    /**
21
     * Telegram object
22
     *
23
     * @var \Longman\TelegramBot\Telegram
24
     */
25
    protected $telegram;
26
27
    /**
28
     * Update object
29
     *
30
     * @var \Longman\TelegramBot\Entities\Update
31
     */
32
    protected $update;
33
34
    /**
35
     * Message object
36
     *
37
     * @var \Longman\TelegramBot\Entities\Message
38
     */
39
    protected $message;
40
41
    /**
42
     * Name
43
     *
44
     * @var string
45
     */
46
    protected $name = '';
47
48
    /**
49
     * Description
50
     *
51
     * @var string
52
     */
53
    protected $description = 'Command description';
54
55
    /**
56
     * Usage
57
     *
58
     * @var string
59
     */
60
    protected $usage = 'Command usage';
61
62
    /**
63
     * Show in Help
64
     *
65
     * @var bool
66
     */
67
    protected $show_in_help = true;
68
69
    /**
70
     * Version
71
     *
72
     * @var string
73
     */
74
    protected $version = '1.0.0';
75
76
    /**
77
     * If this command is enabled
78
     *
79
     * @var boolean
80
     */
81
    protected $enabled = true;
82
83
    /**
84
     * If this command needs mysql
85
     *
86
     * @var boolean
87
     */
88
    protected $need_mysql = false;
89
90
    /**
91
     * Command config
92
     *
93
     * @var array
94
     */
95
    protected $config = [];
96
97
    /**
98
     * Constructor
99
     *
100
     * @param \Longman\TelegramBot\Telegram        $telegram
101
     * @param \Longman\TelegramBot\Entities\Update $update
102
     */
103 26
    public function __construct(Telegram $telegram, Update $update = null)
104
    {
105 26
        $this->telegram = $telegram;
106 26
        $this->setUpdate($update);
107 26
        $this->config = $telegram->getCommandConfig($this->name);
108 26
    }
109
110
    /**
111
     * Set update object
112
     *
113
     * @param \Longman\TelegramBot\Entities\Update $update
114
     *
115
     * @return \Longman\TelegramBot\Commands\Command
116
     */
117 26
    public function setUpdate(Update $update = null)
118
    {
119 26
        if ($update !== null) {
120 7
            $this->update  = $update;
121 7
            $this->message = $this->update->getMessage();
122
        }
123
124 26
        return $this;
125
    }
126
127
    /**
128
     * Pre-execute command
129
     *
130
     * @return \Longman\TelegramBot\Entities\ServerResponse
131
     * @throws \Longman\TelegramBot\Exception\TelegramException
132
     */
133
    public function preExecute()
134
    {
135
        if ($this->need_mysql && !($this->telegram->isDbEnabled() && DB::isDbConnected())) {
136
            return $this->executeNoDb();
137
        }
138
139
        return $this->execute();
140
    }
141
142
    /**
143
     * Execute command
144
     *
145
     * @return \Longman\TelegramBot\Entities\ServerResponse
146
     * @throws \Longman\TelegramBot\Exception\TelegramException
147
     */
148
    abstract public function execute();
149
150
    /**
151
     * Execution if MySQL is required but not available
152
     *
153
     * @return \Longman\TelegramBot\Entities\ServerResponse
154
     * @throws \Longman\TelegramBot\Exception\TelegramException
155
     */
156 View Code Duplication
    public function executeNoDb()
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...
157
    {
158
        //Preparing message
159
        $message = $this->getMessage();
160
        $chat_id = $message->getChat()->getId();
161
162
        $data = [
163
            'chat_id' => $chat_id,
164
            'text'    => 'Sorry no database connection, unable to execute "' . $this->name . '" command.',
165
        ];
166
167
        return Request::sendMessage($data);
168
    }
169
170
    /**
171
     * Get update object
172
     *
173
     * @return \Longman\TelegramBot\Entities\Update
174
     */
175 1
    public function getUpdate()
176
    {
177 1
        return $this->update;
178
    }
179
180
    /**
181
     * Get message object
182
     *
183
     * @return \Longman\TelegramBot\Entities\Message
184
     */
185 7
    public function getMessage()
186
    {
187 7
        return $this->message;
188
    }
189
190
    /**
191
     * Get command config
192
     *
193
     * Look for config $name if found return it, if not return null.
194
     * If $name is not set return all set config.
195
     *
196
     * @param string|null $name
197
     *
198
     * @return array|mixed|null
199
     */
200 1
    public function getConfig($name = null)
201
    {
202 1
        if ($name === null) {
203 1
            return $this->config;
204
        }
205 1
        if (isset($this->config[$name])) {
206 1
            return $this->config[$name];
207
        }
208
209 1
        return null;
210
    }
211
212
    /**
213
     * Get telegram object
214
     *
215
     * @return \Longman\TelegramBot\Telegram
216
     */
217 1
    public function getTelegram()
218
    {
219 1
        return $this->telegram;
220
    }
221
222
    /**
223
     * Get usage
224
     *
225
     * @return string
226
     */
227 3
    public function getUsage()
228
    {
229 3
        return $this->usage;
230
    }
231
232
    /**
233
     * Get version
234
     *
235
     * @return string
236
     */
237 4
    public function getVersion()
238
    {
239 4
        return $this->version;
240
    }
241
242
    /**
243
     * Get description
244
     *
245
     * @return string
246
     */
247 4
    public function getDescription()
248
    {
249 4
        return $this->description;
250
    }
251
252
    /**
253
     * Get name
254
     *
255
     * @return string
256
     */
257 4
    public function getName()
258
    {
259 4
        return $this->name;
260
    }
261
262
    /**
263
     * Get Show in Help
264
     *
265
     * @return bool
266
     */
267 3
    public function showInHelp()
268
    {
269 3
        return $this->show_in_help;
270
    }
271
272
    /**
273
     * Check if command is enabled
274
     *
275
     * @return bool
276
     */
277 5
    public function isEnabled()
278
    {
279 5
        return $this->enabled;
280
    }
281
282
    /**
283
     * If this is a SystemCommand
284
     *
285
     * @return bool
286
     */
287 4
    public function isSystemCommand()
288
    {
289 4
        return ($this instanceof SystemCommand);
290
    }
291
292
    /**
293
     * If this is an AdminCommand
294
     *
295
     * @return bool
296
     */
297
    public function isAdminCommand()
298
    {
299
        return ($this instanceof AdminCommand);
300
    }
301
302
    /**
303
     * If this is a UserCommand
304
     *
305
     * @return bool
306
     */
307
    public function isUserCommand()
308
    {
309
        return ($this instanceof UserCommand);
310
    }
311
}
312