From 9dd6022057c9b05521ab890fb60adc2301dea94b Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Wed, 20 Jun 2012 16:58:16 +0300 Subject: [PATCH] database add page --- bin/v_list_database_types | 66 +++++++++++++++++ bin/v_list_web_stats | 2 +- func/db.sh | 2 +- web/add/db/index.php | 77 ++++++++++++++++++++ web/add/dns/index.php | 7 -- web/add/mail/index.php | 6 -- web/add/user/index.php | 7 -- web/add/web/index.php | 7 -- web/templates/admin/add_db.html | 101 +++++++++++++++++++++++++++ web/templates/admin/menu_add_db.html | 15 ++++ web/templates/header.html | 1 + 11 files changed, 262 insertions(+), 29 deletions(-) create mode 100755 bin/v_list_database_types create mode 100644 web/add/db/index.php create mode 100644 web/templates/admin/add_db.html create mode 100644 web/templates/admin/menu_add_db.html diff --git a/bin/v_list_database_types b/bin/v_list_database_types new file mode 100755 index 00000000..a3bf247b --- /dev/null +++ b/bin/v_list_database_types @@ -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 diff --git a/bin/v_list_web_stats b/bin/v_list_web_stats index 1e716366..086dcc8f 100755 --- a/bin/v_list_web_stats +++ b/bin/v_list_web_stats @@ -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. #----------------------------------------------------------# diff --git a/func/db.sh b/func/db.sh index 1c7e4daf..75d29c1b 100644 --- a/func/db.sh +++ b/func/db.sh @@ -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" diff --git a/web/add/db/index.php b/web/add/db/index.php new file mode 100644 index 00000000..6d3d6dbc --- /dev/null +++ b/web/add/db/index.php @@ -0,0 +1,77 @@ + $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('
', $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 ".$_POST['v_database']." 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'); diff --git a/web/add/dns/index.php b/web/add/dns/index.php index eed374c6..48a4df2b 100644 --- a/web/add/dns/index.php +++ b/web/add/dns/index.php @@ -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'; diff --git a/web/add/mail/index.php b/web/add/mail/index.php index 8733979f..31dde6cc 100644 --- a/web/add/mail/index.php +++ b/web/add/mail/index.php @@ -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'; diff --git a/web/add/user/index.php b/web/add/user/index.php index 615b199f..20746d6c 100644 --- a/web/add/user/index.php +++ b/web/add/user/index.php @@ -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'; diff --git a/web/add/web/index.php b/web/add/web/index.php index ace74674..bc1a6176 100644 --- a/web/add/web/index.php +++ b/web/add/web/index.php @@ -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'; diff --git a/web/templates/admin/add_db.html b/web/templates/admin/add_db.html new file mode 100644 index 00000000..909ecc89 --- /dev/null +++ b/web/templates/admin/add_db.html @@ -0,0 +1,101 @@ + + + + + + + + +
+ + +
+
+ + +
+ + + + + + + + + + + + + +
Prefix "" will be automaticaly added to database name and database user
Database
Username
Password generate
Type
Charset
+ + +
+
diff --git a/web/templates/admin/menu_add_db.html b/web/templates/admin/menu_add_db.html new file mode 100644 index 00000000..2d161c07 --- /dev/null +++ b/web/templates/admin/menu_add_db.html @@ -0,0 +1,15 @@ + + + + + diff --git a/web/templates/header.html b/web/templates/header.html index 004afbf3..9c71316f 100644 --- a/web/templates/header.html +++ b/web/templates/header.html @@ -427,6 +427,7 @@ if (!empty($_SESSION['look'])) { font-size: 8pt; padding: 4 0 0 0; color: #484243; + color: #5c5455; } .counter-value {