Issues (7)

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.

Command/ProcessDynamicChannelCommand.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
3
namespace Itkg\DelayEventBundle\Command;
4
5
use Itkg\DelayEventBundle\Handler\LockHandlerInterface;
6
use Itkg\DelayEventBundle\Model\Lock;
7
use Itkg\DelayEventBundle\Processor\EventProcessor;
8
use Itkg\DelayEventBundle\Repository\EventRepository;
9
use Itkg\DelayEventBundle\Repository\LockRepository;
10
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
11
use Symfony\Component\Console\Input\InputArgument;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Input\InputOption;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
/**
17
 * Class ProcessDynamicChannelCommand
18
 */
19
class ProcessDynamicChannelCommand extends ContainerAwareCommand
20
{
21
    /**
22
     * @var EventRepository
23
     */
24
    private $eventRepository;
25
26
    /**
27
     * @var EventProcessor
28
     */
29
    private $eventProcessor;
0 ignored issues
show
The property $eventProcessor is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
31
    /**
32
     * @var LockHandlerInterface
33
     */
34
    private $lockHandler;
0 ignored issues
show
The property $lockHandler is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
35
36
    /**
37
     * @var array
38
     */
39
    private $channels;
40
41
    /**
42
     * @var LockRepository
43
     */
44
    private $lockRepository;
45
46
    /**
47
     * ProcessEventCommand constructor.
48
     *
49
     * @param EventRepository      $eventRepository
50
     * @param LockRepository       $lockRepository
51
     * @param array                $channels
52
     * @param null|string          $name
53
     */
54
    public function __construct(
55
        EventRepository $eventRepository,
56
        LockRepository $lockRepository,
57
        array $channels = [],
58
        $name = null
59
    ) {
60
        $this->eventRepository = $eventRepository;
61
        $this->lockRepository = $lockRepository;
62
        $this->channels = $channels;
63
64
        parent::__construct($name);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    protected function configure()
71
    {
72
        $this
73
            ->setName('itkg_delay_event:process_dynamic_channel')
74
            ->setDescription('Process dynamic channel')
75
            ->addArgument(
76
                'channel',
77
                InputArgument::REQUIRED,
78
                'Dynamic channel to process'
79
            )
80
            ->addOption(
81
                'concurrent-jobs-count',
82
                'c',
83
                InputOption::VALUE_OPTIONAL,
84
                'Maximum concurrent jobs count for this channel. Default 5',
85
                5
86
            );
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    protected function execute(InputInterface $input, OutputInterface $output)
93
    {
94
        $channel = $input->getArgument('channel');
95
96
        $commandline = $this->getContainer()->getParameter('itkg_delay_event.command_line');
97
98
        if (!isset($this->channels[$channel])) {
99
            $output->writeln(
100
                sprintf(
101
                    '<error>Channel <info>%s</info> is not configured.</error>',
102
                    $channel
103
                )
104
            );
105
            return;
106
        }
107
108
        if (!$this->channels[$channel]['dynamic']) {
109
            $output->writeln(
110
                sprintf(
111
                    '<error>Channel <info>%s</info> is not dynamic.</error>',
112
                    $channel
113
                )
114
            );
115
            return;
116
        }
117
118
        $fieldGroupIdentifierList = $this->eventRepository->findDistinctFieldGroupIdentifierByChannel(
0 ignored issues
show
The method toArray cannot be called on $this->eventRepository->...s[$channel]['exclude']) (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
119
            $this->channels[$channel]['include'],
120
            $this->channels[$channel]['exclude']
121
        )->toArray();
122
123
        $locks = $this->lockRepository->findAll();
124
        $lockNames = array();
125
        $currentMachineLockNames = array();
126
        /** @var Lock $lock */
127
        foreach ($locks as $lock) {
128
            $lockName = str_replace(sprintf('%s_', $channel), '', $lock->getChannel());
129
            if ($lock->isCommandLocked() && in_array($lockName, $fieldGroupIdentifierList)) {
130
                $lockNames[] = $lockName;
131
                if ($lock->getLockedBy() === $this->getHostName()) {
132
                    $currentMachineLockNames[] = $lockName;
133
                }
134
            }
135
        }
136
137
        $concurrentAvailableSlotsCount = $this->calculateAvailableSlotsCount(
138
            $fieldGroupIdentifierList,
139
            $currentMachineLockNames,
140
            $input->getOption('concurrent-jobs-count')
141
        );
142
143
        if ($concurrentAvailableSlotsCount <= 0) {
144
            $output->writeln(
145
                sprintf(
146
                    '<info>Maximum concurrent jobs limit for %s is reached.</info>',
147
                    $channel
148
                )
149
            );
150
            return;
151
        }
152
153
        $groupFieldIdentifierListToProcess = array_slice(
154
            array_diff(
155
                $fieldGroupIdentifierList,
156
                $lockNames
157
            ),
158
            0,
159
            $concurrentAvailableSlotsCount
160
        );
161
162
        foreach ($groupFieldIdentifierListToProcess as $identifier) {
163
            // Create a new dynamic channel
164
165
            $process = new \Symfony\Component\Process\Process(
166
                sprintf(
167
                    $commandline,
168
                    $this->getContainer()->getParameter('kernel.environment'),
169
                    $channel,
170
                    $identifier
171
                )
172
            );
173
174
            $process->setWorkingDirectory($this->getWorkingDir());
175
            $process->start();
176
        }
177
    }
178
179
    /**
180
     * @param array $lockNames
181
     * @param array $fieldGroupIdentifierList
182
     * @param int $maxConcurrentJobsCount
183
     *
184
     * @return bool
185
     */
186
    private function calculateAvailableSlotsCount($lockNames, $fieldGroupIdentifierList, $maxConcurrentJobsCount)
187
    {
188
        $concurrentJobsCount = count(array_intersect($fieldGroupIdentifierList  , $lockNames));
189
190
        return $maxConcurrentJobsCount - $concurrentJobsCount;
191
    }
192
193
    /**
194
     * @return string
195
     */
196
    private function getWorkingDir()
197
    {
198
        return $this->getContainer()->get('kernel')->getRootDir();
199
    }
200
201
    /**
202
     * @return string
203
     */
204
    private function getHostName()
205
    {
206
        return php_uname('n');
207
    }
208
}
209