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- if (empty ($ _POST ['v_notify ' ])) $ v_notify = 'off ' ;
32-
33- // Check for errors
34- if (!empty ($ errors [0 ])) {
35- foreach ($ errors as $ i => $ error ) {
36- if ( $ i == 0 ) {
37- $ error_msg = $ error ;
38- } else {
39- $ error_msg = $ error_msg .", " .$ error ;
40- }
41- }
42- $ _SESSION ['error_msg ' ] = _ ('Error: field "%s" can not be blank. ' ,$ error_msg );
43- } else {
44- // Add Database
45- $ v_type = escapeshellarg ($ _POST ['v_type ' ]);
46- $ v_charset = escapeshellarg ($ _POST ['v_charset ' ]);
47- exec (VESTA_CMD ."v-add-database " .$ user ." " .$ v_database ." " .$ v_dbuser ." " .$ v_password ." " .$ v_type ." 'default' " .$ v_charset , $ output , $ return_var );
48- $ v_type = $ _POST ['v_type ' ];
49- $ v_charset = $ _POST ['v_charset ' ];
50- if ($ return_var != 0 ) {
51- $ error = implode ('<br> ' , $ output );
52- if (empty ($ error )) $ error = _ ('Error: vesta did not return any output. ' );
53- $ _SESSION ['error_msg ' ] = $ error ;
54- unset($ v_password );
55- unset($ output );
56- } else {
57- // Add Database
58- $ v_type = escapeshellarg ($ _POST ['v_type ' ]);
59- $ v_charset = escapeshellarg ($ _POST ['v_charset ' ]);
60- exec (VESTA_CMD ."v-add-database " .$ user ." " .$ v_database ." " .$ v_dbuser ." " .$ v_password ." " .$ v_type ." 'default' " .$ v_charset , $ output , $ return_var );
61- $ v_type = $ _POST ['v_type ' ];
62- $ v_charset = $ _POST ['v_charset ' ];
63- if ($ return_var != 0 ) {
64- $ error = implode ('<br> ' , $ output );
65- if (empty ($ error )) $ error = _ ('Error: vesta did not return any output. ' );
66- $ _SESSION ['error_msg ' ] = $ error ;
67- unset($ v_password );
68- unset($ output );
69- }
70- else {
71- if (empty ($ v_notify )) {
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-
76- $ to = $ panel [$ user ]['CONTACT ' ];
77- $ subject = _ ("Database Credentials " );
78- $ hostname = exec ('hostname ' );
79- $ from = _ ('MAIL_FROM ' ,$ hostname );
80- $ mailtext = _ ('DATABASE_READY ' ,$ panel [$ user ]['FNAME ' ],$ panel [$ user ]['LNAME ' ],$ _POST ['v_type ' ],$ user ,$ _POST ['v_database ' ],$ user ,$ _POST ['v_dbuser ' ],$ _POST ['v_password ' ]);
81- $ mailtext .= $ db_admin_link ."\n\n" ;
82-
83- $ mailtext .= "-- \n" ._ ('Vesta Control Panel ' )."\n" ;
84- send_email ($ to , $ subject , $ mailtext , $ from );
85-
86- }
87- $ _SESSION ['ok_msg ' ] = _ ('DATABASE_CREATED_OK ' ,$ user ."_ " .$ _POST ['v_database ' ],$ user ."_ " .$ _POST ['v_database ' ]);
88- unset($ v_database );
89- unset($ v_dbuser );
90- unset($ v_password );
91- unset($ v_type );
92- unset($ v_charset );
93- unset($ output );
94- }
95- }
96- }
97- }
98- exec (VESTA_CMD ."v-list-database-types 'json' " , $ output , $ return_var );
99- $ db_types = json_decode (implode ('' , $ output ), true );
100- unset($ output );
101-
102- include ($ _SERVER ['DOCUMENT_ROOT ' ].'/templates/admin/add_db.html ' );
103- unset($ _SESSION ['error_msg ' ]);
104- unset($ _SESSION ['ok_msg ' ]);
105- //}
106-
107- // Footer
108- include ($ _SERVER ['DOCUMENT_ROOT ' ].'/templates/footer.html ' );
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+ if (empty ($ _POST ['v_notify ' ])) $ v_notify = 'off ' ;
32+
33+ // Check for errors
34+ if (!empty ($ errors [0 ])) {
35+ foreach ($ errors as $ i => $ error ) {
36+ if ( $ i == 0 ) {
37+ $ error_msg = $ error ;
38+ } else {
39+ $ error_msg = $ error_msg .", " .$ error ;
40+ }
41+ }
42+ $ _SESSION ['error_msg ' ] = _ ('Error: field "%s" can not be blank. ' ,$ error_msg );
43+ } else {
44+ // Add Database
45+ $ v_type = escapeshellarg ($ _POST ['v_type ' ]);
46+ $ v_charset = escapeshellarg ($ _POST ['v_charset ' ]);
47+ exec (VESTA_CMD ."v-add-database " .$ user ." " .$ v_database ." " .$ v_dbuser ." " .$ v_password ." " .$ v_type ." 'default' " .$ v_charset , $ output , $ return_var );
48+ $ v_type = $ _POST ['v_type ' ];
49+ $ v_charset = $ _POST ['v_charset ' ];
50+ if ($ return_var != 0 ) {
51+ $ error = implode ('<br> ' , $ output );
52+ if (empty ($ error )) $ error = _ ('Error: vesta did not return any output. ' );
53+ $ _SESSION ['error_msg ' ] = $ error ;
54+ unset($ v_password );
55+ unset($ output );
56+ } else {
57+ // Add Database
58+ $ v_type = escapeshellarg ($ _POST ['v_type ' ]);
59+ $ v_charset = escapeshellarg ($ _POST ['v_charset ' ]);
60+ exec (VESTA_CMD ."v-add-database " .$ user ." " .$ v_database ." " .$ v_dbuser ." " .$ v_password ." " .$ v_type ." 'default' " .$ v_charset , $ output , $ return_var );
61+ $ v_type = $ _POST ['v_type ' ];
62+ $ v_charset = $ _POST ['v_charset ' ];
63+ if ($ return_var != 0 ) {
64+ $ error = implode ('<br> ' , $ output );
65+ if (empty ($ error )) $ error = _ ('Error: vesta did not return any output. ' );
66+ $ _SESSION ['error_msg ' ] = $ error ;
67+ unset($ v_password );
68+ unset($ output );
69+ }
70+ else {
71+ if (empty ($ v_notify )) {
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+
76+ $ to = $ panel [$ user ]['CONTACT ' ];
77+ $ subject = _ ("Database Credentials " );
78+ $ hostname = exec ('hostname ' );
79+ $ from = _ ('MAIL_FROM ' ,$ hostname );
80+ $ mailtext = _ ('DATABASE_READY ' ,$ panel [$ user ]['FNAME ' ],$ panel [$ user ]['LNAME ' ],$ _POST ['v_type ' ],$ user ,$ _POST ['v_database ' ],$ user ,$ _POST ['v_dbuser ' ],$ _POST ['v_password ' ]);
81+ $ mailtext .= $ db_admin_link ."\n\n" ;
82+
83+ $ mailtext .= "-- \n" ._ ('Vesta Control Panel ' )."\n" ;
84+ send_email ($ to , $ subject , $ mailtext , $ from );
85+
86+ }
87+ $ _SESSION ['ok_msg ' ] = _ ('DATABASE_CREATED_OK ' ,$ user ."_ " .$ _POST ['v_database ' ],$ user ."_ " .$ _POST ['v_database ' ]);
88+ unset($ v_database );
89+ unset($ v_dbuser );
90+ unset($ v_password );
91+ unset($ v_type );
92+ unset($ v_charset );
93+ unset($ output );
94+ }
95+ }
96+ }
97+ }
98+ exec (VESTA_CMD ."v-list-database-types 'json' " , $ output , $ return_var );
99+ $ db_types = json_decode (implode ('' , $ output ), true );
100+ unset($ output );
101+
102+ include ($ _SERVER ['DOCUMENT_ROOT ' ].'/templates/admin/add_db.html ' );
103+ unset($ _SESSION ['error_msg ' ]);
104+ unset($ _SESSION ['ok_msg ' ]);
105+ //}
106+
107+ // Footer
108+ include ($ _SERVER ['DOCUMENT_ROOT ' ].'/templates/footer.html ' );
109109?>
0 commit comments