Skip to content

Commit 9dd6022

Browse files
committed
database add page
1 parent 118ceaa commit 9dd6022

File tree

11 files changed

+262
-29
lines changed

11 files changed

+262
-29
lines changed

bin/v_list_database_types

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# info: list supported database types
3+
# options: [format]
4+
#
5+
# The function for obtaining the list of database types.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
format=${1-shell}
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
source $VESTA/conf/vesta.conf
18+
19+
# Json function
20+
json_list_dbtypes() {
21+
types=$(echo "${DB_SYSTEM//,/ }")
22+
t_counter=$(echo "$types" | wc -w)
23+
i=1
24+
echo '['
25+
for type in $types; do
26+
if [ "$i" -lt "$t_counter" ]; then
27+
echo -e "\t\"$type\","
28+
else
29+
echo -e "\t\"$type\""
30+
fi
31+
(( ++i))
32+
done
33+
echo "]"
34+
}
35+
36+
# Shell function
37+
shell_list_dbtypes() {
38+
types=$(echo "${DB_SYSTEM//,/ }")
39+
if [ -z "$nohead" ]; then
40+
echo "TYPES"
41+
echo "----------"
42+
fi
43+
for type in $types; do
44+
echo "$type"
45+
done
46+
}
47+
48+
49+
#----------------------------------------------------------#
50+
# Action #
51+
#----------------------------------------------------------#
52+
53+
# Listing domains
54+
case $format in
55+
json) json_list_dbtypes ;;
56+
plain) nohead=1; shell_list_dbtypes ;;
57+
shell) shell_list_dbtypes ;;
58+
*) check_args '1' '0' '[format]' ;;
59+
esac
60+
61+
62+
#----------------------------------------------------------#
63+
# Vesta #
64+
#----------------------------------------------------------#
65+
66+
exit

bin/v_list_web_stats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# info: list web statistics
33
# options: [format]
44
#
5-
# The function for obtaining the list of system shells.
5+
# The function for obtaining the list of web statistics analyzer.
66

77

88
#----------------------------------------------------------#

func/db.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Get database host
22
get_next_dbhost() {
3-
if [ -z "$host" ]; then
3+
if [ -z "$host" ] || [ "$host" == 'default' ]; then
44
IFS=$'\n'
55
host='EMPTY_DB_HOST'
66
config="$VESTA/conf/$type.conf"

web/add/db/index.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
// Init
3+
//error_reporting(NULL);
4+
ob_start();
5+
session_start();
6+
$TAB = 'DB';
7+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
8+
9+
// Header
10+
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
11+
12+
// Panel
13+
top_panel($user,$TAB);
14+
15+
// Are you admin?
16+
if ($_SESSION['user'] == 'admin') {
17+
if (!empty($_POST['ok'])) {
18+
// Check input
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_charset'])) $errors[] = 'charset';
24+
25+
// Protect input
26+
$v_database = escapeshellarg($_POST['v_database']);
27+
$v_dbuser = escapeshellarg($_POST['v_dbuser']);
28+
$v_password = escapeshellarg($_POST['v_password']);
29+
$v_type = $_POST['v_type'];
30+
$v_charset = $_POST['v_charset'];
31+
32+
// Check for errors
33+
if (!empty($errors[0])) {
34+
foreach ($errors as $i => $error) {
35+
if ( $i == 0 ) {
36+
$error_msg = $error;
37+
} else {
38+
$error_msg = $error_msg.", ".$error;
39+
}
40+
}
41+
$_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
42+
} else {
43+
// Add Database
44+
$v_type = escapeshellarg($_POST['v_type']);
45+
$v_charset = escapeshellarg($_POST['v_charset']);
46+
exec (VESTA_CMD."v_add_database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." 'default' ".$v_charset, $output, $return_var);
47+
$v_type = $_POST['v_type'];
48+
$v_charset = $_POST['v_charset'];
49+
if ($return_var != 0) {
50+
$error = implode('<br>', $output);
51+
if (empty($error)) $error = 'Error: vesta did not return any output.';
52+
$_SESSION['error_msg'] = $error;
53+
unset($v_password);
54+
unset($output);
55+
} else {
56+
$_SESSION['ok_msg'] = "OK: database <b>".$_POST['v_database']."</b> has been created successfully.";
57+
unset($v_database);
58+
unset($v_dbuser);
59+
unset($v_password);
60+
unset($v_type);
61+
unset($v_charset);
62+
unset($output);
63+
}
64+
}
65+
}
66+
exec (VESTA_CMD."v_list_database_types 'json'", $output, $return_var);
67+
$db_types = json_decode(implode('', $output), true);
68+
unset($output);
69+
70+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_db.html');
71+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
72+
unset($_SESSION['error_msg']);
73+
unset($_SESSION['ok_msg']);
74+
}
75+
76+
// Footer
77+
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

web/add/dns/index.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414

1515
// Are you admin?
1616
if ($_SESSION['user'] == 'admin') {
17-
18-
// Cancel
19-
if (!empty($_POST['cancel'])) {
20-
header("Location: /list/dns/");
21-
}
22-
23-
// DNS Domain
2417
if (!empty($_POST['ok'])) {
2518
// Check input
2619
if (empty($_POST['v_domain'])) $errors[] = 'domain';

web/add/mail/index.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414

1515
// Are you admin?
1616
if ($_SESSION['user'] == 'admin') {
17-
18-
// Cancel
19-
if (!empty($_POST['cancel'])) {
20-
header("Location: /list/mail/");
21-
}
22-
2317
// Mail Domain
2418
if (!empty($_POST['ok'])) {
2519
if (empty($_POST['v_domain'])) $errors[] = 'domain';

web/add/user/index.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818

1919
// Are you admin?
2020
if ($_SESSION['user'] == 'admin') {
21-
22-
// Cancel
23-
if (!empty($_POST['cancel'])) {
24-
header("Location: /list/user/");
25-
}
26-
27-
// Ok
2821
if (!empty($_POST['ok'])) {
2922
// Check input
3023
if (empty($_POST['v_username'])) $errors[] = 'user';

web/add/web/index.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414

1515
// Are you admin?
1616
if ($_SESSION['user'] == 'admin') {
17-
18-
// Cancel
19-
if (!empty($_POST['cancel'])) {
20-
header("Location: /list/web/");
21-
}
22-
23-
// Action
2417
if (!empty($_POST['ok'])) {
2518
// Check input
2619
if (empty($_POST['v_domain'])) $errors[] = 'domain';

web/templates/admin/add_db.html

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<script type="text/javascript">
2+
function elementHideShow(elementToHideOrShow) {
3+
var el = document.getElementById(elementToHideOrShow);
4+
if (el.style.display == "block") {
5+
el.style.display = "none";
6+
} else {
7+
el.style.display = "block";
8+
}
9+
}
10+
11+
function randomString() {
12+
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
13+
var string_length = 10;
14+
var randomstring = '';
15+
for (var i=0; i<string_length; i++) {
16+
var rnum = Math.floor(Math.random() * chars.length);
17+
randomstring += chars.substring(rnum,rnum+1);
18+
}
19+
document.v_add_user.v_password.value = randomstring;
20+
}
21+
</script>
22+
23+
24+
<table class='data'>
25+
<tr class="data-add">
26+
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
27+
<table class="data-col1">
28+
<tr><td style="padding: 18 0 4 18;"></td></tr>
29+
</table>
30+
</td>
31+
<td class="data-dotted" width="830px" style="vertical-align:top;">
32+
<table width="830px"><tr>
33+
<td></td>
34+
</tr></table>
35+
<table class="data-col2" width="600px">
36+
<form method="post" name="v_add_user">
37+
<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>
38+
<tr><td class="add-text" style="padding: 10 0 0 2px;">Database</td></tr>
39+
<tr><td><input type="text" size="20" class="add-input" name="v_database" <?php if (!empty($v_database)) echo "value=".$v_database; ?>></td></tr>
40+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Username</td></tr>
41+
<tr><td></span><input type="text" size="20" class="add-input" name="v_dbuser" <?php if (!empty($v_dbuser)) echo "value=".$v_dbuser; ?>></tr>
42+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Password <a href="javascript:randomString();" class="genpass">generate</a></td></tr>
43+
<tr><td><input type="text" size="20" class="add-input" name="v_password"></td></tr>
44+
<tr><td class="add-text" style="padding: 10 0 0 2px;">Type</td></tr>
45+
<tr><td><select class="add-list" name="v_type">
46+
<?php
47+
foreach ($db_types as $key => $value) {
48+
echo "\t\t\t\t<option value=\"".$value."\"";
49+
if ((!empty($v_type)) && ( $value == $v_type )) echo ' selected';
50+
echo ">".$value."</option>\n";
51+
}
52+
?>
53+
</select></td></tr>
54+
<tr><td class="add-text" style="padding: 10 0 0 2px;">Charset</td></tr>
55+
<tr><td><select class="add-list" name="v_charset">
56+
<option value=big5 <?php if ((!empty($v_charset)) && ( $v_charset == 'big5')) echo 'selected';?> >big5</option>
57+
<option value=dec8 <?php if ((!empty($v_charset)) && ( $v_charset == 'dec8')) echo 'selected';?> >dec8</option>
58+
<option value=cp850 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp850')) echo 'selected';?> >cp850</option>
59+
<option value=hp8 <?php if ((!empty($v_charset)) && ( $v_charset == 'hp8')) echo 'selected';?> >hp8</option>
60+
<option value=koi8r <?php if ((!empty($v_charset)) && ( $v_charset == 'koi8r')) echo 'selected';?> >koi8r</option>
61+
<option value=latin1 <?php if ((!empty($v_charset)) && ( $v_charset == 'latin1')) echo 'selected';?> >latin1</option>
62+
<option value=latin2 <?php if ((!empty($v_charset)) && ( $v_charset == 'latin2')) echo 'selected';?> >latin2</option>
63+
<option value=swe7 <?php if ((!empty($v_charset)) && ( $v_charset == 'swe7')) echo 'selected';?> >swe7</option>
64+
<option value=ascii <?php if ((!empty($v_charset)) && ( $v_charset == 'ascii')) echo 'selected';?> >ascii</option>
65+
<option value=ujis <?php if ((!empty($v_charset)) && ( $v_charset == 'ujis')) echo 'selected';?> >ujis</option>
66+
<option value=sjis <?php if ((!empty($v_charset)) && ( $v_charset == 'sjis')) echo 'selected';?> >sjis</option>
67+
<option value=hebrew <?php if ((!empty($v_charset)) && ( $v_charset == 'hebrew')) echo 'selected';?> >hebrew</option>
68+
<option value=tis620 <?php if ((!empty($v_charset)) && ( $v_charset == 'tis620')) echo 'selected';?> >tis620</option>
69+
<option value=euckr <?php if ((!empty($v_charset)) && ( $v_charset == 'euckr')) echo 'selected';?> >euckr</option>
70+
<option value=koi8u <?php if ((!empty($v_charset)) && ( $v_charset == 'koi8u')) echo 'selected';?> >koi8u</option>
71+
<option value=gb2312 <?php if ((!empty($v_charset)) && ( $v_charset == 'gb2312')) echo 'selected';?> >gb2312</option>
72+
<option value=greek <?php if ((!empty($v_charset)) && ( $v_charset == 'greek')) echo 'selected';?> >greek</option>
73+
<option value=cp1250 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp1250')) echo 'selected';?> >cp1250</option>
74+
<option value=gbk <?php if ((!empty($v_charset)) && ( $v_charset == 'gbk')) echo 'selected';?> >gbk</option>
75+
<option value=latin5 <?php if ((!empty($v_charset)) && ( $v_charset == 'latin5')) echo 'selected';?> >latin5</option>
76+
<option value=armscii8 <?php if ((!empty($v_charset)) && ( $v_charset == 'armscii8')) echo 'selected';?> >armscii8</option>
77+
<option value=utf8 <?php if ((!empty($v_charset)) && ( $v_charset == 'utf8')) echo 'selected';?> <?php if (empty($v_charset)) echo 'selected';?> >utf8</option>
78+
<option value=ucs2 <?php if ((!empty($v_charset)) && ( $v_charset == 'ucs2')) echo 'selected';?> >ucs2</option>
79+
<option value=cp866 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp866')) echo 'selected';?> >cp866</option>
80+
<option value=keybcs2 <?php if ((!empty($v_charset)) && ( $v_charset == 'keybcs2')) echo 'selected';?> >keybcs2</option>
81+
<option value=macce <?php if ((!empty($v_charset)) && ( $v_charset == 'macce')) echo 'selected';?> >macce</option>
82+
<option value=macroman <?php if ((!empty($v_charset)) && ( $v_charset == 'macroman')) echo 'selected';?> >macroman</option>
83+
<option value=cp852 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp852')) echo 'selected';?> >cp852</option>
84+
<option value=latin7 <?php if ((!empty($v_charset)) && ( $v_charset == 'latin7')) echo 'selected';?> >latin7</option>
85+
<option value=cp1251 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp1251')) echo 'selected';?> >cp1251</option>
86+
<option value=cp1256 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp1256')) echo 'selected';?> >cp1256</option>
87+
<option value=cp1257 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp1257')) echo 'selected';?> >cp1257</option>
88+
<option value=binary <?php if ((!empty($v_charset)) && ( $v_charset == 'binary')) echo 'selected';?> >binary</option>
89+
<option value=geostd8 <?php if ((!empty($v_charset)) && ( $v_charset == 'geostd8')) echo 'selected';?> >geostd8</option>
90+
<option value=cp932 <?php if ((!empty($v_charset)) && ( $v_charset == 'cp932')) echo 'selected';?> >cp932</option>
91+
<option value=eucjpms <?php if ((!empty($v_charset)) && ( $v_charset == 'eucjpms')) echo 'selected';?> >eucjpms</option>
92+
</td></tr>
93+
94+
<tr><td style="padding: 24px 0 0 0;">
95+
<input type="submit" name="ok" value="OK" class="add-button"></form>
96+
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/db/'">
97+
</td></tr>
98+
</table>
99+
</td>
100+
</tr>
101+
</table>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<table class="sub-menu">
2+
<tr>
3+
<td style="padding: 10px 2px 28px 0;" ><a class="add-name"><b>Adding Database</b></a>
4+
<?php
5+
if (!empty($_SESSION['error_msg'])) {
6+
echo "<a class=\"add-error\"> → ".$_SESSION['error_msg']."</a>";
7+
} else {
8+
if (!empty($_SESSION['ok_msg'])) {
9+
echo "<a class=\"add-ok\"> → ".$_SESSION['ok_msg']."</a>";
10+
}
11+
}
12+
?>
13+
</td>
14+
</tr>
15+
</table>

0 commit comments

Comments
 (0)