|
1 | 1 | <?php |
2 | | -error_reporting(NULL); |
| 2 | + |
| 3 | +error_reporting(null); |
3 | 4 | ob_start(); |
4 | 5 | $TAB = 'DB'; |
5 | 6 |
|
|
10 | 11 | if (!empty($_POST['ok'])) { |
11 | 12 |
|
12 | 13 | // Check token |
13 | | - if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) { |
14 | | - header('location: /login/'); |
15 | | - exit(); |
16 | | - } |
| 14 | + verify_csrf($_POST); |
17 | 15 |
|
18 | 16 | // Check empty fields |
19 | | - if (empty($_POST['v_database'])) $errors[] = _('database'); |
20 | | - if (empty($_POST['v_dbuser'])) $errors[] = _('username'); |
21 | | - if (empty($_POST['v_password'])) $errors[] = _('password'); |
22 | | - if (empty($_POST['v_type'])) $errors[] = _('type'); |
23 | | - if (empty($_POST['v_host'])) $errors[] = _('host'); |
24 | | - if (empty($_POST['v_charset'])) $errors[] = _('charset'); |
| 17 | + if (empty($_POST['v_database'])) { |
| 18 | + $errors[] = _('database'); |
| 19 | + } |
| 20 | + if (empty($_POST['v_dbuser'])) { |
| 21 | + $errors[] = _('username'); |
| 22 | + } |
| 23 | + if (empty($_POST['v_password'])) { |
| 24 | + $errors[] = _('password'); |
| 25 | + } |
| 26 | + if (empty($_POST['v_type'])) { |
| 27 | + $errors[] = _('type'); |
| 28 | + } |
| 29 | + if (empty($_POST['v_host'])) { |
| 30 | + $errors[] = _('host'); |
| 31 | + } |
| 32 | + if (empty($_POST['v_charset'])) { |
| 33 | + $errors[] = _('charset'); |
| 34 | + } |
25 | 35 | if (!empty($errors[0])) { |
26 | 36 | foreach ($errors as $i => $error) { |
27 | | - if ( $i == 0 ) { |
| 37 | + if ($i == 0) { |
28 | 38 | $error_msg = $error; |
29 | 39 | } else { |
30 | 40 | $error_msg = $error_msg.", ".$error; |
31 | 41 | } |
32 | 42 | } |
33 | | - $_SESSION['error_msg'] = sprintf(_('Field "%s" can not be blank.'),$error_msg); |
| 43 | + $_SESSION['error_msg'] = sprintf(_('Field "%s" can not be blank.'), $error_msg); |
34 | 44 | } |
35 | 45 |
|
36 | 46 | // Validate email |
|
42 | 52 |
|
43 | 53 | // Check password length |
44 | 54 | if (empty($_SESSION['error_msg'])) { |
45 | | - if (!validate_password($_POST['v_password'])) { $_SESSION['error_msg'] = _('Password does not match the minimum requirements');} |
| 55 | + if (!validate_password($_POST['v_password'])) { |
| 56 | + $_SESSION['error_msg'] = _('Password does not match the minimum requirements'); |
| 57 | + } |
46 | 58 | } |
47 | 59 |
|
48 | 60 | // Protect input |
|
58 | 70 | $v_type = escapeshellarg($_POST['v_type']); |
59 | 71 | $v_charset = escapeshellarg($_POST['v_charset']); |
60 | 72 | $v_host = escapeshellarg($_POST['v_host']); |
61 | | - $v_password = tempnam("/tmp","vst"); |
| 73 | + $v_password = tempnam("/tmp", "vst"); |
62 | 74 | $fp = fopen($v_password, "w"); |
63 | 75 | fwrite($fp, $_POST['v_password']."\n"); |
64 | 76 | fclose($fp); |
65 | | - exec (HESTIA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." ".$v_host." ".$v_charset, $output, $return_var); |
66 | | - check_return_code($return_var,$output); |
| 77 | + exec(HESTIA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." ".$v_host." ".$v_charset, $output, $return_var); |
| 78 | + check_return_code($return_var, $output); |
67 | 79 | unset($output); |
68 | 80 | unlink($v_password); |
69 | 81 | $v_password = escapeshellarg($_POST['v_password']); |
|
75 | 87 | // Get database manager url |
76 | 88 | if (empty($_SESSION['error_msg'])) { |
77 | 89 | list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"] . ":"); |
78 | | - if ($_POST['v_host'] != 'localhost' ) $http_host = $_POST['v_host']; |
79 | | - if ($_POST['v_type'] == 'mysql') $db_admin = "phpMyAdmin"; |
80 | | - if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpmyadmin/"; |
81 | | - if (($_POST['v_type'] == 'mysql') && (!empty($_SESSION['DB_PMA_ALIAS']))) $db_admin_link = "http://".$http_host."/".$_SESSION['DB_PMA_ALIAS']; |
82 | | - if ($_POST['v_type'] == 'pgsql') $db_admin = "phpPgAdmin"; |
83 | | - if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phppgadmin/"; |
84 | | - if (($_POST['v_type'] == 'pgsql') && (!empty($_SESSION['DB_PGA_ALIAS']))) $db_admin_link = "http://".$http_host."/".$_SESSION['DB_PGA_ALIAS']; |
| 90 | + if ($_POST['v_host'] != 'localhost') { |
| 91 | + $http_host = $_POST['v_host']; |
| 92 | + } |
| 93 | + if ($_POST['v_type'] == 'mysql') { |
| 94 | + $db_admin = "phpMyAdmin"; |
| 95 | + } |
| 96 | + if ($_POST['v_type'] == 'mysql') { |
| 97 | + $db_admin_link = "http://".$http_host."/phpmyadmin/"; |
| 98 | + } |
| 99 | + if (($_POST['v_type'] == 'mysql') && (!empty($_SESSION['DB_PMA_ALIAS']))) { |
| 100 | + $db_admin_link = "http://".$http_host."/".$_SESSION['DB_PMA_ALIAS']; |
| 101 | + } |
| 102 | + if ($_POST['v_type'] == 'pgsql') { |
| 103 | + $db_admin = "phpPgAdmin"; |
| 104 | + } |
| 105 | + if ($_POST['v_type'] == 'pgsql') { |
| 106 | + $db_admin_link = "http://".$http_host."/phppgadmin/"; |
| 107 | + } |
| 108 | + if (($_POST['v_type'] == 'pgsql') && (!empty($_SESSION['DB_PGA_ALIAS']))) { |
| 109 | + $db_admin_link = "http://".$http_host."/".$_SESSION['DB_PGA_ALIAS']; |
| 110 | + } |
85 | 111 | } |
86 | 112 |
|
87 | 113 | // Email login credentials |
|
91 | 117 | $hostname = exec('hostname'); |
92 | 118 | $from = "noreply@".$hostname; |
93 | 119 | $from_name = _('Hestia Control Panel'); |
94 | | - $mailtext = sprintf(_('DATABASE_READY'),$user."_".$_POST['v_database'],$user."_".$_POST['v_dbuser'],$_POST['v_password'],$db_admin_link); |
| 120 | + $mailtext = sprintf(_('DATABASE_READY'), $user."_".$_POST['v_database'], $user."_".$_POST['v_dbuser'], $_POST['v_password'], $db_admin_link); |
95 | 121 | send_email($to, $subject, $mailtext, $from, $from_name); |
96 | 122 | } |
97 | 123 |
|
98 | 124 | // Flush field values on success |
99 | 125 | if (empty($_SESSION['error_msg'])) { |
100 | | - $_SESSION['ok_msg'] = sprintf(_('DATABASE_CREATED_OK'),htmlentities($user)."_".htmlentities($_POST['v_database']),htmlentities($user)."_".htmlentities($_POST['v_database'])); |
101 | | - $_SESSION['ok_msg'] .= " / <a href=".$db_admin_link." target='_blank'>" . sprintf(_('open %s'),$db_admin) . "</a>"; |
| 126 | + $_SESSION['ok_msg'] = sprintf(_('DATABASE_CREATED_OK'), htmlentities($user)."_".htmlentities($_POST['v_database']), htmlentities($user)."_".htmlentities($_POST['v_database'])); |
| 127 | + $_SESSION['ok_msg'] .= " / <a href=".$db_admin_link." target='_blank'>" . sprintf(_('open %s'), $db_admin) . "</a>"; |
102 | 128 | unset($v_database); |
103 | 129 | unset($v_dbuser); |
104 | 130 | unset($v_password); |
|
114 | 140 | $db_types = explode(',', $_SESSION['DB_SYSTEM']); |
115 | 141 |
|
116 | 142 | // List available database servers |
117 | | -exec (HESTIA_CMD."v-list-database-hosts json", $output, $return_var); |
| 143 | +exec(HESTIA_CMD."v-list-database-hosts json", $output, $return_var); |
118 | 144 | $db_hosts_tmp1 = json_decode(implode('', $output), true); |
119 | | -$db_hosts_tmp2 = array_map(function($host){return $host['HOST'];}, $db_hosts_tmp1); |
| 145 | +$db_hosts_tmp2 = array_map(function ($host) { |
| 146 | + return $host['HOST']; |
| 147 | +}, $db_hosts_tmp1); |
120 | 148 | $db_hosts = array_values(array_unique($db_hosts_tmp2)); |
121 | 149 | unset($output); |
122 | 150 | unset($db_hosts_tmp1); |
|
0 commit comments