|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The MIT License |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2015 Daniel Popiniuc <[email protected]>. |
|
7
|
|
|
* |
|
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
10
|
|
|
* in the Software without restriction, including without limitation the rights |
|
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
13
|
|
|
* furnished to do so, subject to the following conditions: |
|
14
|
|
|
* |
|
15
|
|
|
* The above copyright notice and this permission notice shall be included in |
|
16
|
|
|
* all copies or substantial portions of the Software. |
|
17
|
|
|
* |
|
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
19
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
21
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
22
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
23
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
24
|
|
|
* THE SOFTWARE. |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace danielgp\rights_mysql; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* This script has been made to extract all users and their grants from Productrion network |
|
31
|
|
|
* for an MySQL major version upgrade (5.5.30 to 5.6.10) |
|
32
|
|
|
*/ |
|
33
|
|
|
class ReadingSecurity |
|
34
|
|
|
{ |
|
35
|
|
|
|
|
36
|
|
|
use configurationRightsMySQL, |
|
37
|
|
|
\danielgp\common_lib\CommonLibLocale, |
|
38
|
|
|
\danielgp\common_lib\DomComponentsByDanielGP, |
|
39
|
|
|
\danielgp\common_lib\MySQLiByDanielGP; |
|
40
|
|
|
|
|
41
|
|
|
public function __construct() { |
|
42
|
|
|
$this->setHeaderNoCache('text/html'); |
|
43
|
|
|
echo $this->setHeaderCommon(); |
|
44
|
|
|
$this->connectToMySql($this->configuredMySqlServer()); |
|
45
|
|
|
echo $this->getMySqlUserGrants($this->getMySqlUsers()); |
|
46
|
|
|
echo $this->setFooterCommon(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
private function getMySqlUsers() { |
|
50
|
|
|
return $this->setMySQLquery2Server($this->queryMySqlUsersList(), 'array_numbered')['result']; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
private function getMySqlUserGrants($listOfMySqlUsers) { |
|
54
|
|
|
$sReturn = []; |
|
55
|
|
|
foreach ($listOfMySqlUsers as $value) { |
|
56
|
|
|
if ($this->mySQLconnection->server_version >= 50708) { |
|
57
|
|
|
$sReturn[] = $this->setQuery2Server($this->queryShowMySqlUsersCreate([$value]), 'value'); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
$q = $this->queryShowMySqlUsersGrants([$value]); |
|
60
|
|
|
$result = $this->setMySQLquery2Server($q, 'full_array_key_numbered')['result']; |
|
61
|
|
|
foreach ($result as $value2) { |
|
62
|
|
|
foreach ($value2 as $value3) { |
|
63
|
|
|
$sReturn[] = $value3; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
return implode(';<br/>', $sReturn) . ';'; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
private function queryMySqlUsersList() { |
|
71
|
|
|
return 'SELECT CONCAT("\"", `User`, "\"@\"", `Host`, "\"") AS `UserHost` ' |
|
72
|
|
|
. 'FROM `mysql`.`user` ' |
|
73
|
|
|
. 'ORDER BY `host`, `user`;'; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
private function queryShowMySqlUsersCreate($parameters) { |
|
77
|
|
|
return 'SHOW CREATE USER ' . filter_var($parameters[0], FILTER_SANITIZE_STRING) . ';'; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
private function queryShowMySqlUsersGrants($parameters) { |
|
81
|
|
|
return 'SHOW GRANTS FOR ' . filter_var($parameters[0], FILTER_SANITIZE_STRING) . ';'; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.