|
6 | 6 | $TAB = 'DB'; |
7 | 7 | include($_SERVER['DOCUMENT_ROOT']."/inc/main.php"); |
8 | 8 |
|
9 | | -// Header |
10 | | -include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html'); |
11 | | - |
12 | | -// Panel |
13 | | -top_panel($user,$TAB); |
14 | | - |
15 | | -$v_db_email = $panel[$user]['CONTACT']; |
16 | | - |
| 9 | +// Check POST request |
17 | 10 | if (!empty($_POST['ok'])) { |
18 | | - // Check input |
| 11 | + |
| 12 | + // Check empty fields |
19 | 13 | if (empty($_POST['v_database'])) $errors[] = __('database'); |
20 | 14 | if (empty($_POST['v_dbuser'])) $errors[] = __('username'); |
21 | 15 | if (empty($_POST['v_password'])) $errors[] = __('password'); |
22 | 16 | if (empty($_POST['v_type'])) $errors[] = __('type'); |
23 | 17 | if (empty($_POST['v_host'])) $errors[] = __('host'); |
24 | 18 | if (empty($_POST['v_charset'])) $errors[] = __('charset'); |
25 | | - |
26 | | - // Check for errors |
27 | 19 | if (!empty($errors[0])) { |
28 | 20 | foreach ($errors as $i => $error) { |
29 | 21 | if ( $i == 0 ) { |
|
36 | 28 | } |
37 | 29 |
|
38 | 30 | // Validate email |
39 | | - if (!empty($_POST['v_db_email'])) { |
| 31 | + if ((!empty($_POST['v_db_email'])) && (empty($_SESSION['error_msg']))) { |
40 | 32 | if (!filter_var($_POST['v_db_email'], FILTER_VALIDATE_EMAIL)) { |
41 | 33 | $_SESSION['error_msg'] = __('Please enter valid email address.'); |
42 | 34 | } |
43 | 35 | } |
44 | 36 |
|
| 37 | + // Check password length |
| 38 | + if (empty($_SESSION['error_msg'])) { |
| 39 | + $pw_len = strlen($_POST['v_password']); |
| 40 | + if ($pw_len < 6 ) $_SESSION['error_msg'] = __('Password is too short.',$error_msg); |
| 41 | + } |
| 42 | + |
45 | 43 | // Protect input |
46 | 44 | $v_database = escapeshellarg($_POST['v_database']); |
47 | 45 | $v_dbuser = escapeshellarg($_POST['v_dbuser']); |
|
51 | 49 | $v_host = $_POST['v_host']; |
52 | 50 | $v_db_email = $_POST['v_db_email']; |
53 | 51 |
|
54 | | - // Check password length |
55 | | - if (empty($_SESSION['error_msg'])) { |
56 | | - $pw_len = strlen($_POST['v_password']); |
57 | | - if ($pw_len < 6 ) $_SESSION['error_msg'] = __('Password is too short.',$error_msg); |
58 | | - } |
59 | | - |
| 52 | + // Add database |
60 | 53 | if (empty($_SESSION['error_msg'])) { |
61 | | - // Add Database |
62 | 54 | $v_type = escapeshellarg($_POST['v_type']); |
63 | 55 | $v_charset = escapeshellarg($_POST['v_charset']); |
64 | 56 | $v_host = escapeshellarg($_POST['v_host']); |
65 | 57 | exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." ".$v_host." ".$v_charset, $output, $return_var); |
| 58 | + check_return_code($return_var,$output); |
| 59 | + unset($output); |
66 | 60 | $v_type = $_POST['v_type']; |
67 | 61 | $v_host = $_POST['v_host']; |
68 | 62 | $v_charset = $_POST['v_charset']; |
69 | | - check_return_code($return_var,$output); |
| 63 | + } |
| 64 | + |
| 65 | + // Get database manager url |
| 66 | + if (empty($_SESSION['error_msg'])) { |
| 67 | + exec (VESTA_CMD."v-list-sys-config json", $output, $return_var); |
| 68 | + $sys = json_decode(implode('', $output), true); |
70 | 69 | unset($output); |
71 | | - if ((!empty($v_db_email)) && (empty($_SESSION['error_msg']))) { |
72 | | - list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"]); |
73 | | - if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpmyadmin/"; |
74 | | - if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phppgadmin/"; |
75 | | - $to = $v_db_email; |
76 | | - $subject = __("Database Credentials"); |
77 | | - $hostname = exec('hostname'); |
78 | | - $from = __('MAIL_FROM',$hostname); |
79 | | - $mailtext = __('DATABASE_READY',$user."_".$_POST['v_database'],$user."_".$_POST['v_dbuser'],$_POST['v_password'],$db_admin_link); |
80 | | - send_email($to, $subject, $mailtext, $from); |
81 | | - } |
82 | | - if (empty($_SESSION['error_msg'])) { |
83 | | - exec (VESTA_CMD."v-list-sys-config json", $output, $return_var); |
84 | | - $sys = json_decode(implode('', $output), true); |
85 | | - unset($output); |
86 | | - |
87 | | - list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"] . ":"); |
88 | | - if ($_POST['v_host'] != 'localhost' ) $http_host = $_POST['v_host']; |
89 | | - if ($_POST['v_type'] == 'mysql') $db_admin = "phpMyAdmin"; |
90 | | - if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpmyadmin/"; |
91 | | - if (($_POST['v_type'] == 'mysql') && (!empty($sys['config']['DB_PMA_URL']))) $db_admin_link = $sys['config']['DB_PMA_URL']; |
92 | | - if ($_POST['v_type'] == 'pgsql') $db_admin = "phpPgAdmin"; |
93 | | - if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phppgadmin/"; |
94 | | - if (($_POST['v_type'] == 'pgsql') && (!empty($sys['config']['DB_PGA_URL']))) $db_admin_link = $sys['config']['DB_PGA_URL']; |
95 | | - |
96 | | - $_SESSION['ok_msg'] = __('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']); |
97 | | - $_SESSION['ok_msg'] .= " / <a href=".$db_admin_link." target='_blank'>" . __('open %s',$db_admin) . "</a>"; |
98 | | - unset($v_database); |
99 | | - unset($v_dbuser); |
100 | | - unset($v_password); |
101 | | - unset($v_type); |
102 | | - unset($v_charset); |
103 | | - } |
| 70 | + list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"] . ":"); |
| 71 | + if ($_POST['v_host'] != 'localhost' ) $http_host = $_POST['v_host']; |
| 72 | + if ($_POST['v_type'] == 'mysql') $db_admin = "phpMyAdmin"; |
| 73 | + if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpmyadmin/"; |
| 74 | + if (($_POST['v_type'] == 'mysql') && (!empty($sys['config']['DB_PMA_URL']))) $db_admin_link = $sys['config']['DB_PMA_URL']; |
| 75 | + if ($_POST['v_type'] == 'pgsql') $db_admin = "phpPgAdmin"; |
| 76 | + if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phppgadmin/"; |
| 77 | + if (($_POST['v_type'] == 'pgsql') && (!empty($sys['config']['DB_PGA_URL']))) $db_admin_link = $sys['config']['DB_PGA_URL']; |
| 78 | + } |
| 79 | + |
| 80 | + // Email login credentials |
| 81 | + if ((!empty($v_db_email)) && (empty($_SESSION['error_msg']))) { |
| 82 | + $to = $v_db_email; |
| 83 | + $subject = __("Database Credentials"); |
| 84 | + $hostname = exec('hostname'); |
| 85 | + $from = __('MAIL_FROM',$hostname); |
| 86 | + $mailtext = __('DATABASE_READY',$user."_".$_POST['v_database'],$user."_".$_POST['v_dbuser'],$_POST['v_password'],$db_admin_link); |
| 87 | + send_email($to, $subject, $mailtext, $from); |
| 88 | + } |
| 89 | + |
| 90 | + // Flush field values on success |
| 91 | + if (empty($_SESSION['error_msg'])) { |
| 92 | + $_SESSION['ok_msg'] = __('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']); |
| 93 | + $_SESSION['ok_msg'] .= " / <a href=".$db_admin_link." target='_blank'>" . __('open %s',$db_admin) . "</a>"; |
| 94 | + unset($v_database); |
| 95 | + unset($v_dbuser); |
| 96 | + unset($v_password); |
| 97 | + unset($v_type); |
| 98 | + unset($v_charset); |
104 | 99 | } |
105 | 100 | } |
106 | 101 |
|
| 102 | +// Header |
| 103 | +include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html'); |
| 104 | + |
| 105 | +// Panel |
| 106 | +top_panel($user,$TAB); |
| 107 | + |
| 108 | +// Get user email |
| 109 | +$v_db_email = $panel[$user]['CONTACT']; |
| 110 | + |
| 111 | +// List avaiable database types |
107 | 112 | exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var); |
108 | 113 | $db_types = json_decode(implode('', $output), true); |
109 | 114 | unset($output); |
110 | 115 |
|
| 116 | +// List available database servers |
111 | 117 | $db_hosts = array(); |
112 | 118 | foreach ($db_types as $db_type ) { |
113 | 119 | exec (VESTA_CMD."v-list-database-hosts ".$db_type." 'json'", $output, $return_var); |
|
117 | 123 | unset($output); |
118 | 124 | } |
119 | 125 |
|
| 126 | +// Display body |
120 | 127 | include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html'); |
| 128 | + |
| 129 | +// Flush session messages |
121 | 130 | unset($_SESSION['error_msg']); |
122 | 131 | unset($_SESSION['ok_msg']); |
123 | 132 |
|
|
0 commit comments