Issues (3887)

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.

Bundle/CronBundle/Command/DaemonMonitorCommand.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
namespace Oro\Bundle\CronBundle\Command;
4
5
use Doctrine\ORM\EntityManager;
6
7
use JMS\JobQueueBundle\Entity\Job;
8
9
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
use Oro\Bundle\CronBundle\Job\Daemon;
15
use Oro\Component\Log\OutputLogger;
16
17
class DaemonMonitorCommand extends ContainerAwareCommand
18
{
19
    const COMMAND_NAME  = 'oro:daemon';
20
21
    /** @var array */
22
    protected $repeatTime = [5, 10, 15, 25, 25];
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function configure()
28
    {
29
        $this
30
            ->setName(static::COMMAND_NAME)
31
            ->addOption(
32
                'start',
33
                'start',
34
                InputOption::VALUE_NONE,
35
                'If option exists Daemon will start'
36
            )
37
            ->addOption(
38
                'stop',
39
                'stop',
40
                InputOption::VALUE_NONE,
41
                'If option exists Daemon will stop'
42
            )
43
            ->addOption(
44
                'restart',
45
                'restart',
46
                InputOption::VALUE_NONE,
47
                'If option exists Daemon will restart'
48
            )
49
            ->setDescription('Monitor Daemon and restart it once a day if it has pid');
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        $logger       = new OutputLogger($output);
58
        $daemon       = $this->getContainer()->get('oro_cron.job_daemon');
59
        $em           = $this->getContainer()->get('doctrine.orm.entity_manager');
60
        $stop         = (int)$input->getOption('stop');
61
        $start        = (int)$input->getOption('start');
62
        $restart      = (int)$input->getOption('restart');
63
        $isClearQueue = false;
64
65
        if (($stop + $start + $restart) > 1) {
66
            throw new \RuntimeException('Please use only one option at a time');
67
        }
68
69
        if ($restart || $this->needToRestart($daemon)) {
70
            $stop  = true;
71
            $start = true;
72
        }
73
74
        foreach ($this->repeatTime as $time) {
75
            $jobQueue  = (int)$this->getJobInQueue($em);
76
77
            if ($jobQueue > 0) {
78
                $logger->info(sprintf('There is a %d job(s), script will wait %d seconds', $jobQueue, $time));
79
                sleep($time);
80
            } else {
81
                $isClearQueue = true;
82
                break;
83
            }
84
        }
85
86
        if ($stop && $isClearQueue) {
87
            $this->doStop($daemon, $logger);
88
        }
89
90
        if ($start && $isClearQueue) {
91
            $this->doStart($daemon, $logger);
92
        }
93
    }
94
95
    /**
96
     * @param Daemon $daemon
97
     * @param OutputLogger $logger
98
     */
99
    protected function doStop(Daemon $daemon, OutputLogger $logger)
100
    {
101
        try {
102
            if ($daemon->stop()) {
103
                $logger->info('Daemon was stopped');
104
            }
105
        } catch (\Exception $e) {
106
            $logger->info('Daemon already stopped');
107
        }
108
    }
109
110
    /**
111
     * @param Daemon $daemon
112
     * @param OutputLogger $logger
113
     */
114
    protected function doStart(Daemon $daemon, OutputLogger $logger)
115
    {
116
        try {
117
            if ($daemon->run()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $daemon->run() of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
118
                $logger->info('Daemon was started');
119
            }
120
        } catch (\Exception $e) {
121
            $logger->info('Daemon can`t be started');
122
        }
123
    }
124
125
    /**
126
     * @param Daemon $daemon
127
     *
128
     * @return bool
129
     */
130
    protected function needToRestart(Daemon $daemon)
131
    {
132
        if ($daemon->getPid()) {
133
            $interval = date_diff($daemon->getDateStart(), new \DateTime('now'));
134
            return ((int)$interval->format('%d')) >= 1;
135
        }
136
137
        return false;
138
    }
139
140
    /**
141
     * @param EntityManager $em
142
     *
143
     * @return string
144
     */
145
    protected function getJobInQueue(EntityManager $em)
146
    {
147
        $qb = $em->getRepository('JMSJobQueueBundle:Job')->createQueryBuilder('j');
148
        $qb->select($qb->expr()->count('j'));
149
        $qb->andWhere($qb->expr()->in('j.state', [Job::STATE_RUNNING, Job::STATE_NEW, Job::STATE_PENDING]));
150
        return $qb->getQuery()->getSingleScalarResult();
151
    }
152
}
153