Issues (133)

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.

app/Drivers/RabbitMQ/RabbitMQDataManager.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 UniMan\Drivers\RabbitMQ;
4
5
use Nette\Localization\ITranslator;
6
use PhpAmqpLib\Connection\AMQPStreamConnection;
7
use UniMan\Core\DataManager\AbstractDataManager;
8
use UniMan\Core\Utils\Filter;
9
use UniMan\Core\Utils\Multisort;
10
11
class RabbitMQDataManager extends AbstractDataManager
12
{
13
    private $translator;
14
15
    /** @var AMQPStreamConnection */
16
    private $connection;
17
18
    private $credentials = [];
19
20
    private $client;
21
22
    private $vhost;
23
24 2
    public function __construct(array $credentials, RabbitMQManagementApiClient $client, ITranslator $translator)
25
    {
26 2
        $this->credentials = $credentials;
27 2
        $this->client = $client;
28 2
        $this->translator = $translator;
29 2
    }
30
31
    public function getConnection()
32
    {
33
        return $this->connection;
34
    }
35
36
    public function databases(array $sorting = [])
37
    {
38
        $vhosts = [];
39
        foreach ($this->client->getVhosts($this->credentials['user']) as $vhost) {
40
            $vhosts[$vhost['name']] = [
41
                'vhost' => $vhost['name'],
42
                'queues' => count($this->client->getQueues($vhost['name'])),
43
                'messages' => isset($vhost['messages']) ? $vhost['messages'] : 0,
44
            ];
45
        }
46
        return Multisort::sort($vhosts, $sorting);
47
    }
48
49
    protected function getDatabaseNameColumn()
50
    {
51
        return 'vhost';
52
    }
53
54
    public function selectDatabase($vhost)
55
    {
56
        $this->vhost = $vhost;
57
        $this->connection = new AMQPStreamConnection(
58
            $this->credentials['host'],
59
            $this->credentials['port'],
60
            $this->credentials['user'],
61
            $this->credentials['password'],
62
            $vhost
63
        );
64
        return $this->connection;
65
    }
66
67
    public function tables(array $sorting = [])
68
    {
69
        $tables = [
70
            RabbitMQDriver::TYPE_QUEUE => [],
71
        ];
72
        foreach ($this->client->getQueues($this->vhost) as $queue) {
73
            $tables[RabbitMQDriver::TYPE_QUEUE][$queue['name']] = [
74
                'queue' => $queue['name'],
75
                'number_of_items' => $queue['messages'],
76
                'size' => $queue['message_bytes'],
77
            ];
78
        }
79
        return [
80
            RabbitMQDriver::TYPE_QUEUE => Multisort::sort($tables[RabbitMQDriver::TYPE_QUEUE], $sorting),
81
        ];
82
    }
83
84
    public function itemsCount($type, $table, array $filter = [])
85
    {
86
        if ($type != RabbitMQDriver::TYPE_QUEUE) {
87
            return 0;
88
        }
89
        if (!$filter) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $filter of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
90
            foreach ($this->client->getQueues($this->vhost) as $queue) {
91
                if ($queue['name'] == $table) {
92
                    return $queue['messages'];
93
                }
94
            }
95
        }
96
        $totalCount = 0;
97
        foreach ($this->client->getMessages($this->vhost, $table) as $message) {
98
            $item = [
99
                'message_body' => $message['payload'],
100
                'length' => $message['payload_bytes'],
101
                'is_truncated' => false ? $this->translator->translate('core.yes') : $this->translator->translate('core.no'),
102
                'content_encoding' => $message['payload_encoding'],
103
                'redelivered' => $message['redelivered'] ? $this->translator->translate('core.yes') : $this->translator->translate('core.no'),
104
            ];
105
            if (Filter::apply($item, $filter)) {
106
                $totalCount++;
107
            }
108
        }
109
110
        return $totalCount;
111
    }
112
113
    public function items($type, $table, $page, $onPage, array $filter = [], array $sorting = [])
114
    {
115
        if ($type != RabbitMQDriver::TYPE_QUEUE) {
116
            return [];
117
        }
118
        $items = [];
119
        foreach ($this->client->getMessages($this->vhost, $table) as $message) {
120
            $item = [
121
                'message_body' => $message['payload'],
122
                'length' => $message['payload_bytes'],
123
                'is_truncated' => false ? $this->translator->translate('core.yes') : $this->translator->translate('core.no'),
124
                'content_encoding' => $message['payload_encoding'],
125
                'redelivered' => $message['redelivered'] ? $this->translator->translate('core.yes') : $this->translator->translate('core.no'),
126
            ];
127
            if (!Filter::apply($item, $filter)) {
128
                continue;
129
            }
130
            $items[$message['payload']] = $item;
131
        }
132
        $items = Multisort::sort($items, $sorting);
133
        return array_slice($items, ($page - 1) * $onPage, $onPage, true);
134
    }
135
136
    public function deleteTable($type, $queue)
137
    {
138
        $channel = $this->connection->channel();
139
        $channel->queue_delete($queue);
140
        $channel->close();
141
        $this->connection->close();
142
        return true;
143
    }
144
}
145