Files
VestaCP/web/add/db/index.php

104 lines
3.7 KiB
PHP
Raw Normal View History

2013-01-18 18:23:04 +04:00
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
$TAB = 'DB';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
2013-01-22 03:00:33 +02:00
$v_db_email = $panel[$user]['CONTACT'];
2013-01-18 18:23:04 +04:00
if (!empty($_POST['ok'])) {
// Check input
if (empty($_POST['v_database'])) $errors[] = __('database');
if (empty($_POST['v_dbuser'])) $errors[] = __('username');
if (empty($_POST['v_password'])) $errors[] = __('password');
if (empty($_POST['v_type'])) $errors[] = __('type');
if (empty($_POST['v_charset'])) $errors[] = __('charset');
2013-01-18 18:23:04 +04:00
2013-01-22 03:13:09 +02:00
// Check for errors
2013-01-29 00:18:09 +02:00
if (!empty($errors[0])) {
2013-01-22 03:13:09 +02:00
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
2013-01-22 03:13:09 +02:00
}
2013-01-22 03:00:33 +02:00
// Validate email
2013-01-22 03:13:09 +02:00
if (!empty($_POST['v_db_email'])) {
if (!filter_var($_POST['v_db_email'], FILTER_VALIDATE_EMAIL)) {
$_SESSION['error_msg'] = __('Please enter valid email address.');
2013-01-22 03:13:09 +02:00
}
2013-01-22 03:00:33 +02:00
}
// Protect input
$v_database = escapeshellarg($_POST['v_database']);
$v_dbuser = escapeshellarg($_POST['v_dbuser']);
$v_password = escapeshellarg($_POST['v_password']);
$v_type = $_POST['v_type'];
$v_charset = $_POST['v_charset'];
$v_db_email = $_POST['v_db_email'];
2013-01-18 18:23:04 +04:00
2013-03-31 19:19:59 +03:00
// Check password length
if (empty($_SESSION['error_msg'])) {
$pw_len = strlen($_POST['v_password']);
if ($pw_len < 6 ) $_SESSION['error_msg'] = __('Password is too short.',$error_msg);
2013-03-31 19:19:59 +03:00
}
2013-01-22 03:13:09 +02:00
if (empty($_SESSION['error_msg'])) {
2013-01-18 18:23:04 +04:00
// Add Database
$v_type = escapeshellarg($_POST['v_type']);
$v_charset = escapeshellarg($_POST['v_charset']);
exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." 'default' ".$v_charset, $output, $return_var);
$v_type = $_POST['v_type'];
$v_charset = $_POST['v_charset'];
if ($return_var != 0) {
$error = implode('<br>', $output);
if (empty($error)) $error = __('Error code:',$return_var);
2013-01-18 18:23:04 +04:00
$_SESSION['error_msg'] = $error;
unset($v_password);
unset($output);
}
2013-03-11 11:42:59 +02:00
if ((!empty($v_db_email)) && ($return_var == 0)) {
2013-01-22 03:00:33 +02:00
list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"]);
if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpMyAdmin/";
if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phpPgAdmin/";
$to = $v_db_email;
$subject = __("Database Credentials");
2013-01-22 03:00:33 +02:00
$hostname = exec('hostname');
$from = __('MAIL_FROM',$hostname);
$mailtext = __('DATABASE_READY',$user."_".$_POST['v_database'],$user."_".$_POST['v_dbuser'],$_POST['v_password'],$db_admin_link);
2013-01-22 03:00:33 +02:00
send_email($to, $subject, $mailtext, $from);
}
$_SESSION['ok_msg'] = __('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
2013-01-22 03:00:33 +02:00
unset($v_database);
unset($v_dbuser);
unset($v_password);
unset($v_type);
unset($v_charset);
unset($output);
2013-01-18 18:23:04 +04:00
}
}
2013-01-22 03:00:33 +02:00
2013-01-18 18:23:04 +04:00
exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
$db_types = json_decode(implode('', $output), true);
unset($output);
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
// Footer
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');
2013-01-22 03:00:33 +02:00
?>