Issues (50)

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/Agent/AgentTask.php (1 issue)

Labels
Severity

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
 * For the full copyright and license information, please view the LICENSE.md
4
 * file that was distributed with this source code.
5
 */
6
7
namespace Notamedia\ConsoleJedi\Agent;
8
9
use Bitrix\Main\Type\DateTime;
10
11
/**
12
 * Builder for create new agents in the Bitrix queue.
13
 *
14
 * Usage:
15
 * ```php
16
 * use Notamedia\ConsoleJedi\Agent\AgentTask;
17
 * use Vendor\Module\TestAgent;
18
 *
19
 * AgentTask::builder()
20
 *      ->setClass(TestAgent::class)
21
 *      ->setConstructorArgs(['arg1', true])
22
 *      ->setCallChain([
23
 *          ['execute' => [100500]]
24
 *      ]),
25
 *      ->setModule('vendor.module')
26
 *      ->create();
27
 * ```
28
 * The result: will be the registered agent `\Vendor\Module\TestAgent::agent('arg1', true)->execute(100500);`.
29
 *
30
 * @author Nik Samokhvalov <[email protected]>
31
 */
32
class AgentTask
33
{
34
    protected $class;
35
    protected $constructorArgs = [];
36
    protected $callChain;
37
    protected $module;
38
    protected $interval;
39
    protected $periodically = false;
40
    protected $active = true;
41
    protected $executionTime;
42
    protected $sort;
43
    protected $userId;
44
45
    /**
46
     * Builder for create new task to the queue of agents.
47
     *
48
     * @return static
49
     */
50
    public static function build()
51
    {
52
        return new static;
53
    }
54
55
    /**
56
     * Sets agent class name.
57
     *
58
     * @param string $className
59
     *
60
     * @return $this
61
     */
62
    public function setClass($className)
63
    {
64
        $this->class = $className;
65
66
        return $this;
67
    }
68
69
    /**
70
     * Sets the arguments for `__constructor` of agent class.
71
     *
72
     * @param array $args
73
     *
74
     * @return $this
75
     */
76
    public function setConstructorArgs(array $args)
77
    {
78
        $this->constructorArgs = $args;
79
80
        return $this;
81
    }
82
83
    /**
84
     * Sets the chain methods with arguments for add them to agent name for execution.
85
     *
86
     * @param array $callChain
87
     *
88
     * @return $this
89
     */
90
    public function setCallChain(array $callChain)
91
    {
92
        $this->callChain = $callChain;
93
94
        return $this;
95
    }
96
97
    /**
98
     * Sets the name of the module to which the agent belongs.
99
     *
100
     * @param string $moduleName
101
     *
102
     * @return $this
103
     */
104
    public function setModule($moduleName)
105
    {
106
        $this->module = $moduleName;
107
108
        return $this;
109
    }
110
111
    /**
112
     * Sets the time interval between execution.
113
     *
114
     * @param int $seconds
115
     *
116
     * @return $this
117
     */
118
    public function setInterval($seconds)
119
    {
120
        $this->interval = (int)$seconds;
121
122
        return $this;
123
    }
124
125
    /**
126
     * Sets the periodically mode of agent.
127
     *
128
     * @param bool $periodically
129
     *
130
     * @return $this
131
     */
132
    public function setPeriodically($periodically)
133
    {
134
        $this->periodically = (bool)$periodically;
135
136
        return $this;
137
    }
138
139
    /**
140
     * Sets the activity of agent.
141
     *
142
     * @param bool $active
143
     *
144
     * @return $this
145
     */
146
    public function setActive($active)
147
    {
148
        $this->active = (bool)$active;
149
150
        return $this;
151
    }
152
153
    /**
154
     * Sets first execution time.
155
     *
156
     * @param DateTime $time
157
     *
158
     * @return $this
159
     */
160
    public function setExecutionTime(DateTime $time)
161
    {
162
        $this->executionTime = $time;
163
164
        return $this;
165
    }
166
167
    /**
168
     * Sets sorting.
169
     *
170
     * @param int $sort
171
     *
172
     * @return $this
173
     */
174
    public function setSort($sort)
175
    {
176
        $this->sort = (int)$sort;
177
178
        return $this;
179
    }
180
181
    /**
182
     * Sets user ID on whose behalf the agent is executed.
183
     *
184
     * @param int $userId User ID.
185
     *
186
     * @return $this
187
     */
188
    public function setUserId($userId)
189
    {
190
        $this->userId = (int)$userId;
191
192
        return $this;
193
    }
194
195
    /**
196
     * Convertation property for creation agent in queue through the old and dirty Bitrix API.
197
     */
198
    protected function convertation()
199
    {
200
        if ($this->executionTime instanceof DateTime) {
0 ignored issues
show
The class Bitrix\Main\Type\DateTime does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
201
            $this->executionTime = $this->executionTime->toString();
202
        } elseif ($this->executionTime === null) {
203
            $time = new DateTime();
204
            $this->executionTime = $time->toString();
205
        }
206
207
        foreach (['periodically', 'active'] as $property) {
208
            if ($this->$property === true) {
209
                $this->$property = 'Y';
210
            } else {
211
                $this->$property = 'N';
212
            }
213
        }
214
    }
215
216
    /**
217
     * Create agent in Bitrix queue.
218
     *
219
     * @param bool $checkExist Return false and set `CAdminException`, if agent already exist.
220
     *
221
     * @return bool|int ID of agent or false if `$checkExist` is true and agent already exist.
222
     */
223
    public function create($checkExist = false)
224
    {
225
        $this->convertation();
226
227
        $model = new \CAgent;
228
229
        return $model->AddAgent(
230
            AgentHelper::createName($this->class, $this->constructorArgs, $this->callChain),
231
            $this->module,
232
            $this->periodically,
233
            $this->interval,
234
            null,
235
            $this->active,
236
            $this->executionTime,
237
            $this->sort,
238
            $this->userId,
239
            $checkExist
240
        );
241
    }
242
}
243