File: Plugins.php

package info (click to toggle)
phpmyadmin 4%3A5.2.1%2Bdfsg-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 131,332 kB
  • sloc: javascript: 212,681; php: 168,094; xml: 18,098; sql: 504; sh: 274; makefile: 205; python: 199
file content (115 lines) | stat: -rw-r--r-- 3,332 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php

declare(strict_types=1);

namespace PhpMyAdmin\Server;

use PhpMyAdmin\DatabaseInterface;

use function __;

class Plugins
{
    /** @var DatabaseInterface */
    private $dbi;

    /**
     * @param DatabaseInterface $dbi DatabaseInterface instance
     */
    public function __construct(DatabaseInterface $dbi)
    {
        $this->dbi = $dbi;
    }

    /**
     * @return Plugin[]
     */
    public function getAll(): array
    {
        global $cfg;

        $sql = 'SHOW PLUGINS';
        if (! $cfg['Server']['DisableIS']) {
            $sql = 'SELECT * FROM information_schema.PLUGINS ORDER BY PLUGIN_TYPE, PLUGIN_NAME';
        }

        $result = $this->dbi->query($sql);
        $plugins = [];
        while ($row = $result->fetchAssoc()) {
            $plugins[] = $this->mapRowToPlugin($row);
        }

        return $plugins;
    }

    /**
     * @return array<int|string, string>
     */
    public function getAuthentication(): array
    {
        $result = $this->dbi->query(
            'SELECT `PLUGIN_NAME`, `PLUGIN_DESCRIPTION` FROM `information_schema`.`PLUGINS`'
                . ' WHERE `PLUGIN_TYPE` = \'AUTHENTICATION\';'
        );

        $plugins = [];

        while ($row = $result->fetchAssoc()) {
            $plugins[$row['PLUGIN_NAME']] = $this->getTranslatedDescription($row['PLUGIN_DESCRIPTION']);
        }

        return $plugins;
    }

    private function getTranslatedDescription(string $description): string
    {
        // mysql_native_password
        if ($description === 'Native MySQL authentication') {
            return __('Native MySQL authentication');
        }

        // sha256_password
        if ($description === 'SHA256 password authentication') {
            return __('SHA256 password authentication');
        }

        // caching_sha2_password
        if ($description === 'Caching sha2 authentication') {
            return __('Caching sha2 authentication');
        }

        // auth_socket || unix_socket
        if ($description === 'Unix Socket based authentication') {
            return __('Unix Socket based authentication');
        }

        // mysql_old_password
        if ($description === 'Old MySQL-4.0 authentication') {
            return __('Old MySQL-4.0 authentication');
        }

        return $description;
    }

    /**
     * @param array $row Row fetched from database
     */
    private function mapRowToPlugin(array $row): Plugin
    {
        return Plugin::fromState([
            'name' => $row['PLUGIN_NAME'] ?? $row['Name'],
            'version' => $row['PLUGIN_VERSION'] ?? null,
            'status' => $row['PLUGIN_STATUS'] ?? $row['Status'],
            'type' => $row['PLUGIN_TYPE'] ?? $row['Type'],
            'typeVersion' => $row['PLUGIN_TYPE_VERSION'] ?? null,
            'library' => $row['PLUGIN_LIBRARY'] ?? $row['Library'] ?? null,
            'libraryVersion' => $row['PLUGIN_LIBRARY_VERSION'] ?? null,
            'author' => $row['PLUGIN_AUTHOR'] ?? null,
            'description' => $row['PLUGIN_DESCRIPTION'] ?? null,
            'license' => $row['PLUGIN_LICENSE'] ?? $row['License'],
            'loadOption' => $row['LOAD_OPTION'] ?? null,
            'maturity' => $row['PLUGIN_MATURITY'] ?? null,
            'authVersion' => $row['PLUGIN_AUTH_VERSION'] ?? null,
        ]);
    }
}