1
0
mirror of https://github.com/myvesta/vesta.git synced 2025-03-12 04:35:23 -07:00

database add page

This commit is contained in:
Serghey Rodin 2012-06-20 16:58:16 +03:00
parent 118ceaa34a
commit 9dd6022057
11 changed files with 262 additions and 29 deletions

66
bin/v_list_database_types Executable file

@ -0,0 +1,66 @@
#!/bin/bash
# info: list supported database types
# options: [format]
#
# The function for obtaining the list of database types.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
format=${1-shell}
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
# Json function
json_list_dbtypes() {
types=$(echo "${DB_SYSTEM//,/ }")
t_counter=$(echo "$types" | wc -w)
i=1
echo '['
for type in $types; do
if [ "$i" -lt "$t_counter" ]; then
echo -e "\t\"$type\","
else
echo -e "\t\"$type\""
fi
(( ++i))
done
echo "]"
}
# Shell function
shell_list_dbtypes() {
types=$(echo "${DB_SYSTEM//,/ }")
if [ -z "$nohead" ]; then
echo "TYPES"
echo "----------"
fi
for type in $types; do
echo "$type"
done
}
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Listing domains
case $format in
json) json_list_dbtypes ;;
plain) nohead=1; shell_list_dbtypes ;;
shell) shell_list_dbtypes ;;
*) check_args '1' '0' '[format]' ;;
esac
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit

@ -2,7 +2,7 @@
# info: list web statistics
# options: [format]
#
# The function for obtaining the list of system shells.
# The function for obtaining the list of web statistics analyzer.
#----------------------------------------------------------#

@ -1,6 +1,6 @@
# Get database host
get_next_dbhost() {
if [ -z "$host" ]; then
if [ -z "$host" ] || [ "$host" == 'default' ]; then
IFS=$'\n'
host='EMPTY_DB_HOST'
config="$VESTA/conf/$type.conf"

77
web/add/db/index.php Normal file

@ -0,0 +1,77 @@
<?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);
// Are you admin?
if ($_SESSION['user'] == 'admin') {
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';
// 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'];
// Check for errors
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
} else {
// 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: vesta did not return any output.';
$_SESSION['error_msg'] = $error;
unset($v_password);
unset($output);
} else {
$_SESSION['ok_msg'] = "OK: database <b>".$_POST['v_database']."</b> has been created successfully.";
unset($v_database);
unset($v_dbuser);
unset($v_password);
unset($v_type);
unset($v_charset);
unset($output);
}
}
}
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/menu_add_db.html');
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');

@ -14,13 +14,6 @@ top_panel($user,$TAB);
// Are you admin?
if ($_SESSION['user'] == 'admin') {
// Cancel
if (!empty($_POST['cancel'])) {
header("Location: /list/dns/");
}
// DNS Domain
if (!empty($_POST['ok'])) {
// Check input
if (empty($_POST['v_domain'])) $errors[] = 'domain';

@ -14,12 +14,6 @@ top_panel($user,$TAB);
// Are you admin?
if ($_SESSION['user'] == 'admin') {
// Cancel
if (!empty($_POST['cancel'])) {
header("Location: /list/mail/");
}
// Mail Domain
if (!empty($_POST['ok'])) {
if (empty($_POST['v_domain'])) $errors[] = 'domain';

@ -18,13 +18,6 @@ top_panel($user,$TAB);
// Are you admin?
if ($_SESSION['user'] == 'admin') {
// Cancel
if (!empty($_POST['cancel'])) {
header("Location: /list/user/");
}
// Ok
if (!empty($_POST['ok'])) {
// Check input
if (empty($_POST['v_username'])) $errors[] = 'user';

@ -14,13 +14,6 @@ top_panel($user,$TAB);
// Are you admin?
if ($_SESSION['user'] == 'admin') {
// Cancel
if (!empty($_POST['cancel'])) {
header("Location: /list/web/");
}
// Action
if (!empty($_POST['ok'])) {
// Check input
if (empty($_POST['v_domain'])) $errors[] = 'domain';

@ -0,0 +1,101 @@
<script type="text/javascript">
function elementHideShow(elementToHideOrShow) {
var el = document.getElementById(elementToHideOrShow);
if (el.style.display == "block") {
el.style.display = "none";
} else {
el.style.display = "block";
}
}
function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 10;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
document.v_add_user.v_password.value = randomstring;
}
</script>
<table class='data'>
<tr class="data-add">
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
<table class="data-col1">
<tr><td style="padding: 18 0 4 18;"></td></tr>
</table>
</td>
<td class="data-dotted" width="830px" style="vertical-align:top;">
<table width="830px"><tr>
<td></td>
</tr></table>
<table class="data-col2" width="600px">
<form method="post" name="v_add_user">
<tr><td style="padding: 10 0 0 2px; color:99a7af;" >Prefix "<?php echo $user."_"; ?>" will be automaticaly added to database name and database user</td></tr>
<tr><td class="add-text" style="padding: 10 0 0 2px;">Database</td></tr>
<tr><td><input type="text" size="20" class="add-input" name="v_database" <?php if (!empty($v_database)) echo "value=".$v_database; ?>></td></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Username</td></tr>
<tr><td></span><input type="text" size="20" class="add-input" name="v_dbuser" <?php if (!empty($v_dbuser)) echo "value=".$v_dbuser; ?>></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Password <a href="javascript:randomString();" class="genpass">generate</a></td></tr>
<tr><td><input type="text" size="20" class="add-input" name="v_password"></td></tr>
<tr><td class="add-text" style="padding: 10 0 0 2px;">Type</td></tr>
<tr><td><select class="add-list" name="v_type">
<?php
foreach ($db_types as $key => $value) {
echo "\t\t\t\t<option value=\"".$value."\"";
if ((!empty($v_type)) && ( $value == $v_type )) echo ' selected';
echo ">".$value."</option>\n";
}
?>
</select></td></tr>
<tr><td class="add-text" style="padding: 10 0 0 2px;">Charset</td></tr>
<tr><td><select class="add-list" name="v_charset">
<option value=big5 <?php if ((!empty($v_charset)) && ( $v_charset == 'big5')) echo 'selected';?> >big5</option>
<option value=dec8 <?php if ((!empty($v_charset)) && ( $v_charset == 'dec8')) echo 'selected';?> >dec8</option>
<option value=cp850 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp850')) echo 'selected';?> >cp850</option>
<option value=hp8 <?php if ((!empty($v_charset)) && ( $v_charset == 'hp8')) echo 'selected';?> >hp8</option>
<option value=koi8r <?php if ((!empty($v_charset)) && ( $v_charset == 'koi8r')) echo 'selected';?> >koi8r</option>
<option value=latin1 <?php if ((!empty($v_charset)) && ( $v_charset == 'latin1')) echo 'selected';?> >latin1</option>
<option value=latin2 <?php if ((!empty($v_charset)) && ( $v_charset == 'latin2')) echo 'selected';?> >latin2</option>
<option value=swe7 <?php if ((!empty($v_charset)) && ( $v_charset == 'swe7')) echo 'selected';?> >swe7</option>
<option value=ascii <?php if ((!empty($v_charset)) && ( $v_charset == 'ascii')) echo 'selected';?> >ascii</option>
<option value=ujis <?php if ((!empty($v_charset)) && ( $v_charset == 'ujis')) echo 'selected';?> >ujis</option>
<option value=sjis <?php if ((!empty($v_charset)) && ( $v_charset == 'sjis')) echo 'selected';?> >sjis</option>
<option value=hebrew <?php if ((!empty($v_charset)) && ( $v_charset == 'hebrew')) echo 'selected';?> >hebrew</option>
<option value=tis620 <?php if ((!empty($v_charset)) && ( $v_charset == 'tis620')) echo 'selected';?> >tis620</option>
<option value=euckr <?php if ((!empty($v_charset)) && ( $v_charset == 'euckr')) echo 'selected';?> >euckr</option>
<option value=koi8u <?php if ((!empty($v_charset)) && ( $v_charset == 'koi8u')) echo 'selected';?> >koi8u</option>
<option value=gb2312 <?php if ((!empty($v_charset)) && ( $v_charset == 'gb2312')) echo 'selected';?> >gb2312</option>
<option value=greek <?php if ((!empty($v_charset)) && ( $v_charset == 'greek')) echo 'selected';?> >greek</option>
<option value=cp1250 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp1250')) echo 'selected';?> >cp1250</option>
<option value=gbk <?php if ((!empty($v_charset)) && ( $v_charset == 'gbk')) echo 'selected';?> >gbk</option>
<option value=latin5 <?php if ((!empty($v_charset)) && ( $v_charset == 'latin5')) echo 'selected';?> >latin5</option>
<option value=armscii8 <?php if ((!empty($v_charset)) && ( $v_charset == 'armscii8')) echo 'selected';?> >armscii8</option>
<option value=utf8 <?php if ((!empty($v_charset)) && ( $v_charset == 'utf8')) echo 'selected';?> <?php if (empty($v_charset)) echo 'selected';?> >utf8</option>
<option value=ucs2 <?php if ((!empty($v_charset)) && ( $v_charset == 'ucs2')) echo 'selected';?> >ucs2</option>
<option value=cp866 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp866')) echo 'selected';?> >cp866</option>
<option value=keybcs2 <?php if ((!empty($v_charset)) && ( $v_charset == 'keybcs2')) echo 'selected';?> >keybcs2</option>
<option value=macce <?php if ((!empty($v_charset)) && ( $v_charset == 'macce')) echo 'selected';?> >macce</option>
<option value=macroman <?php if ((!empty($v_charset)) && ( $v_charset == 'macroman')) echo 'selected';?> >macroman</option>
<option value=cp852 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp852')) echo 'selected';?> >cp852</option>
<option value=latin7 <?php if ((!empty($v_charset)) && ( $v_charset == 'latin7')) echo 'selected';?> >latin7</option>
<option value=cp1251 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp1251')) echo 'selected';?> >cp1251</option>
<option value=cp1256 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp1256')) echo 'selected';?> >cp1256</option>
<option value=cp1257 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp1257')) echo 'selected';?> >cp1257</option>
<option value=binary <?php if ((!empty($v_charset)) && ( $v_charset == 'binary')) echo 'selected';?> >binary</option>
<option value=geostd8 <?php if ((!empty($v_charset)) && ( $v_charset == 'geostd8')) echo 'selected';?> >geostd8</option>
<option value=cp932 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp932')) echo 'selected';?> >cp932</option>
<option value=eucjpms <?php if ((!empty($v_charset)) && ( $v_charset == 'eucjpms')) echo 'selected';?> >eucjpms</option>
</td></tr>
<tr><td style="padding: 24px 0 0 0;">
<input type="submit" name="ok" value="OK" class="add-button"></form>
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/db/'">
</td></tr>
</table>
</td>
</tr>
</table>

@ -0,0 +1,15 @@
<table class="sub-menu">
<tr>
<td style="padding: 10px 2px 28px 0;" ><a class="add-name"><b>Adding Database</b></a>
<?php
if (!empty($_SESSION['error_msg'])) {
echo "<a class=\"add-error\"> → ".$_SESSION['error_msg']."</a>";
} else {
if (!empty($_SESSION['ok_msg'])) {
echo "<a class=\"add-ok\"> → ".$_SESSION['ok_msg']."</a>";
}
}
?>
</td>
</tr>
</table>

@ -427,6 +427,7 @@ if (!empty($_SESSION['look'])) {
font-size: 8pt;
padding: 4 0 0 0;
color: #484243;
color: #5c5455;
}
.counter-value {