|
1 | 1 | <?php |
2 | | - |
3 | | -$host = $_POST['host']; |
4 | | -$uid = $_POST['uid']; |
5 | | -$pwd = $_POST['pwd']; |
| 2 | +$method = strip_tags($_POST['method']); |
| 3 | +$host = strip_tags($_POST['host']); |
| 4 | +$uid = strip_tags($_POST['uid']); |
| 5 | +$pwd = strip_tags($_POST['pwd']); |
| 6 | +$tableprefix = strip_tags($_POST['tableprefix']); |
| 7 | +$database_name = strip_tags($_POST['database_name']); |
6 | 8 | $installMode = $_POST['installMode']; |
7 | 9 |
|
8 | 10 | $output = $_lang['status_checking_database']; |
9 | 11 | $h = explode(':', $host, 2); |
10 | 12 | $database_collation = $_POST['database_collation']; |
11 | 13 | $database_connection_method = $_POST['database_connection_method']; |
12 | 14 | $database_charset = substr($database_collation, 0, strpos($database_collation, '_')); |
13 | | -$tableprefix = $_POST['tableprefix']; |
14 | | -if ($_POST['method'] == 'pgsql') { |
| 15 | + |
| 16 | +if ($method == 'pgsql') { |
15 | 17 | if ($database_charset == 'utf8mb4') $database_charset = 'utf8'; |
16 | 18 | $database_charset = mb_strtoupper($database_charset); |
17 | 19 | } |
18 | 20 | try { |
19 | | - $dbh = new PDO($_POST['method'] . ':host=' . $_POST['host'] . ';dbname=' . $_POST['database_name'], $_POST['uid'], $_POST['pwd']); |
20 | | - switch ($_POST['method']) { |
| 21 | + $dbh = new PDO($method . ':host=' . $host . ';dbname=' . $database_name, $uid, $pwd); |
| 22 | + switch ($method) { |
21 | 23 | case 'pgsql': |
22 | | - |
23 | 24 | $result = $dbh->query("SELECT * FROM pg_settings WHERE name='client_encoding'"); |
24 | 25 | if ($result->errorCode() == 0) { |
25 | 26 | $data = $result->fetch(); |
|
42 | 43 | $result = $dbh->query("show variables like 'collation_database'"); |
43 | 44 | if ($result->errorCode() == 0) { |
44 | 45 | $data = $result->fetch(); |
45 | | - |
46 | 46 | if ($data['Value'] != $database_collation) { |
47 | | - |
48 | 47 | echo $output . '<span id="database_fail" style="color:#FF0000;">' . sprintf($_lang['status_failed_database_collation_does_not_match'], $data['1']) . '</span>'; |
49 | 48 | exit(); |
50 | 49 | } |
|
57 | 56 | } |
58 | 57 | $result = $dbh->query("SELECT SCHEMA_NAME |
59 | 58 | FROM INFORMATION_SCHEMA.SCHEMATA |
60 | | - WHERE SCHEMA_NAME = '" . $_POST['database_name'] . "'"); |
| 59 | + WHERE SCHEMA_NAME = '" . $pwd . "'"); |
61 | 60 | if ($dbh->errorCode() == 0) { |
62 | 61 | $data = $result->fetch(); |
63 | | - if (isset($data['SCHEMA_NAME']) && $data['SCHEMA_NAME'] == $_POST['database_name']) { |
| 62 | + if (isset($data['SCHEMA_NAME']) && $data['SCHEMA_NAME'] == $pwd) { |
64 | 63 | echo $output . '<span id="database_pass" style="color:#80c000;"> ' . $_lang['status_passed'] . '</span>'; |
65 | 64 | exit(); |
66 | 65 | } |
|
73 | 72 | } |
74 | 73 |
|
75 | 74 | } catch (PDOException $e) { |
76 | | - if (!stristr($e->getMessage(), 'database "' . $_POST['database_name'] . '" does not exist') && !stristr($e->getMessage(), 'Unknown database \'' . $_POST['database_name'] . '\'') && !stristr($e->getMessage(), 'Base table or view not found')) { |
| 75 | + if (!stristr($e->getMessage(), 'database "' . $pwd . '" does not exist') && !stristr($e->getMessage(), 'Unknown database \'' . $database_name . '\'') && !stristr($e->getMessage(), 'Base table or view not found')) { |
77 | 76 | echo $output . '<span id="database_fail" style="color:#FF0000;">' . $_lang['status_failed'] . ' ' . $e->getMessage() . '</span>'; |
78 | 77 | exit(); |
79 | 78 | } |
80 | 79 | } |
81 | 80 |
|
82 | 81 | try { |
83 | | - $dbh = new PDO($_POST['method'] . ':host=' . $_POST['host'] . ';', $_POST['uid'], $_POST['pwd']); |
84 | | - |
85 | | - |
86 | | - switch ($_POST['method']) { |
| 82 | + $dbh = new PDO($method . ':host=' . $host . ';', $uid, $pwd); |
| 83 | + switch ($method) { |
87 | 84 | case 'pgsql': |
88 | | - |
89 | 85 | try { |
90 | | - $dbh->query('CREATE DATABASE "' . $_POST['database_name'] . '" ENCODING \'' . $database_charset . '\';'); |
| 86 | + $dbh->query('CREATE DATABASE "' . $database_name . '" ENCODING \'' . $database_charset . '\';'); |
91 | 87 | if ($dbh->errorCode() > 0) { |
92 | 88 | if (stristr($dbh->errorInfo()[2], 'already exists') === false) { |
93 | 89 | $output .= '<span id="database_fail" style="color:#FF0000;">' . $_lang['status_failed_could_not_create_database'] . ' ' . print_r($dbh->errorInfo(), true) . '</span>'; |
94 | 90 | } |
95 | 91 | } |
96 | | - |
97 | 92 | } catch (Exception $exception) { |
98 | 93 | echo $exception->getMessage(); |
99 | 94 | } |
100 | 95 |
|
101 | 96 | break; |
102 | 97 | case 'mysql': |
103 | | - $query = 'CREATE DATABASE IF NOT EXISTS `' . $_POST['database_name'] . '` CHARACTER SET ' . $database_charset . ' COLLATE ' . $database_collation . ";"; |
| 98 | + $query = 'CREATE DATABASE IF NOT EXISTS `' . $database_name . '` CHARACTER SET ' . $database_charset . ' COLLATE ' . $database_collation . ";"; |
104 | 99 | if (!$dbh->query($query)) { |
105 | 100 | $output .= '<span id="database_fail" style="color:#FF0000;">' . $_lang['status_failed_could_not_create_database'] . '</span>'; |
106 | 101 | echo $output; |
|
116 | 111 | echo $output . '<span id="database_pass" style="color:#80c000;"> ' . $_lang['status_passed'] . '</span>'; |
117 | 112 | exit(); |
118 | 113 | } catch (PDOException $e) { |
119 | | - |
120 | 114 | echo $output . '<span id="database_fail" style="color:#FF0000;">' . $_lang['status_failed'] . ' ' . $e->getMessage() . '</span>'; |
121 | | - |
122 | 115 | } |
123 | 116 |
|
124 | 117 | echo $output; |
0 commit comments