Skip to content

Commit 2558fa5

Browse files
committed
Improved code formating
1 parent 2f300aa commit 2558fa5

File tree

15 files changed

+1637
-1569
lines changed

15 files changed

+1637
-1569
lines changed

web/add/cron/index.php

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,19 @@
44
ob_start();
55
session_start();
66
$TAB = 'CRON';
7-
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
87

9-
// Header
10-
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
11-
12-
// Panel
13-
top_panel($user,$TAB);
8+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
149

10+
// Check POST request
1511
if (!empty($_POST['ok'])) {
16-
// Check input
12+
13+
// Check empty fields
1714
if ((!isset($_POST['v_min'])) || ($_POST['v_min'] == '')) $errors[] = __('minute');
1815
if ((!isset($_POST['v_hour'])) || ($_POST['v_hour'] == '')) $errors[] = __('hour');
1916
if ((!isset($_POST['v_day'])) || ($_POST['v_day'] == '')) $errors[] = __('day');
2017
if ((!isset($_POST['v_month'])) || ($_POST['v_month'] == '')) $errors[] = __('month');
2118
if ((!isset($_POST['v_wday'])) || ($_POST['v_wday'] == '')) $errors[] = __('day of week');
2219
if ((!isset($_POST['v_cmd'])) || ($_POST['v_cmd'] == '')) $errors[] = __('cmd');
23-
24-
// Protect input
25-
$v_min = escapeshellarg($_POST['v_min']);
26-
$v_hour = escapeshellarg($_POST['v_hour']);
27-
$v_day = escapeshellarg($_POST['v_day']);
28-
$v_month = escapeshellarg($_POST['v_month']);
29-
$v_wday = escapeshellarg($_POST['v_wday']);
30-
$v_cmd = escapeshellarg($_POST['v_cmd']);
31-
32-
// Check for errors
3320
if (!empty($errors[0])) {
3421
foreach ($errors as $i => $error) {
3522
if ( $i == 0 ) {
@@ -39,32 +26,46 @@
3926
}
4027
}
4128
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
42-
} else {
43-
// Add Cron Job
29+
}
30+
31+
// Protect input
32+
$v_min = escapeshellarg($_POST['v_min']);
33+
$v_hour = escapeshellarg($_POST['v_hour']);
34+
$v_day = escapeshellarg($_POST['v_day']);
35+
$v_month = escapeshellarg($_POST['v_month']);
36+
$v_wday = escapeshellarg($_POST['v_wday']);
37+
$v_cmd = escapeshellarg($_POST['v_cmd']);
38+
39+
// Add cron job
40+
if (empty($_SESSION['error_msg'])) {
4441
exec (VESTA_CMD."v-add-cron-job ".$user." ".$v_min." ".$v_hour." ".$v_day." ".$v_month." ".$v_wday." ".$v_cmd, $output, $return_var);
45-
$v_type = $_POST['v_type'];
46-
$v_charset = $_POST['v_charset'];
4742
check_return_code($return_var,$output);
48-
unset($v_password);
4943
unset($output);
50-
if (empty($_SESSION['error_msg'])) {
51-
$_SESSION['ok_msg'] = __('CRON_CREATED_OK');
52-
unset($v_min);
53-
unset($v_hour);
54-
unset($v_day);
55-
unset($v_month);
56-
unset($v_wday);
57-
unset($v_cmd);
58-
unset($output);
59-
}
44+
}
45+
46+
// Flush field values on success
47+
if (empty($_SESSION['error_msg'])) {
48+
$_SESSION['ok_msg'] = __('CRON_CREATED_OK');
49+
unset($v_min);
50+
unset($v_hour);
51+
unset($v_day);
52+
unset($v_month);
53+
unset($v_wday);
54+
unset($v_cmd);
55+
unset($output);
6056
}
6157
}
6258

63-
exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
64-
$db_types = json_decode(implode('', $output), true);
65-
unset($output);
59+
// Header
60+
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
6661

62+
// Panel
63+
top_panel($user,$TAB);
64+
65+
// Display body
6766
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_cron.html');
67+
68+
// Flush session messages
6869
unset($_SESSION['error_msg']);
6970
unset($_SESSION['ok_msg']);
7071

web/add/db/index.php

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,16 @@
66
$TAB = 'DB';
77
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
88

9-
// Header
10-
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
11-
12-
// Panel
13-
top_panel($user,$TAB);
14-
15-
$v_db_email = $panel[$user]['CONTACT'];
16-
9+
// Check POST request
1710
if (!empty($_POST['ok'])) {
18-
// Check input
11+
12+
// Check empty fields
1913
if (empty($_POST['v_database'])) $errors[] = __('database');
2014
if (empty($_POST['v_dbuser'])) $errors[] = __('username');
2115
if (empty($_POST['v_password'])) $errors[] = __('password');
2216
if (empty($_POST['v_type'])) $errors[] = __('type');
2317
if (empty($_POST['v_host'])) $errors[] = __('host');
2418
if (empty($_POST['v_charset'])) $errors[] = __('charset');
25-
26-
// Check for errors
2719
if (!empty($errors[0])) {
2820
foreach ($errors as $i => $error) {
2921
if ( $i == 0 ) {
@@ -36,12 +28,18 @@
3628
}
3729

3830
// Validate email
39-
if (!empty($_POST['v_db_email'])) {
31+
if ((!empty($_POST['v_db_email'])) && (empty($_SESSION['error_msg']))) {
4032
if (!filter_var($_POST['v_db_email'], FILTER_VALIDATE_EMAIL)) {
4133
$_SESSION['error_msg'] = __('Please enter valid email address.');
4234
}
4335
}
4436

37+
// Check password length
38+
if (empty($_SESSION['error_msg'])) {
39+
$pw_len = strlen($_POST['v_password']);
40+
if ($pw_len < 6 ) $_SESSION['error_msg'] = __('Password is too short.',$error_msg);
41+
}
42+
4543
// Protect input
4644
$v_database = escapeshellarg($_POST['v_database']);
4745
$v_dbuser = escapeshellarg($_POST['v_dbuser']);
@@ -51,63 +49,71 @@
5149
$v_host = $_POST['v_host'];
5250
$v_db_email = $_POST['v_db_email'];
5351

54-
// Check password length
55-
if (empty($_SESSION['error_msg'])) {
56-
$pw_len = strlen($_POST['v_password']);
57-
if ($pw_len < 6 ) $_SESSION['error_msg'] = __('Password is too short.',$error_msg);
58-
}
59-
52+
// Add database
6053
if (empty($_SESSION['error_msg'])) {
61-
// Add Database
6254
$v_type = escapeshellarg($_POST['v_type']);
6355
$v_charset = escapeshellarg($_POST['v_charset']);
6456
$v_host = escapeshellarg($_POST['v_host']);
6557
exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." ".$v_host." ".$v_charset, $output, $return_var);
58+
check_return_code($return_var,$output);
59+
unset($output);
6660
$v_type = $_POST['v_type'];
6761
$v_host = $_POST['v_host'];
6862
$v_charset = $_POST['v_charset'];
69-
check_return_code($return_var,$output);
63+
}
64+
65+
// Get database manager url
66+
if (empty($_SESSION['error_msg'])) {
67+
exec (VESTA_CMD."v-list-sys-config json", $output, $return_var);
68+
$sys = json_decode(implode('', $output), true);
7069
unset($output);
71-
if ((!empty($v_db_email)) && (empty($_SESSION['error_msg']))) {
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-
$to = $v_db_email;
76-
$subject = __("Database Credentials");
77-
$hostname = exec('hostname');
78-
$from = __('MAIL_FROM',$hostname);
79-
$mailtext = __('DATABASE_READY',$user."_".$_POST['v_database'],$user."_".$_POST['v_dbuser'],$_POST['v_password'],$db_admin_link);
80-
send_email($to, $subject, $mailtext, $from);
81-
}
82-
if (empty($_SESSION['error_msg'])) {
83-
exec (VESTA_CMD."v-list-sys-config json", $output, $return_var);
84-
$sys = json_decode(implode('', $output), true);
85-
unset($output);
86-
87-
list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"] . ":");
88-
if ($_POST['v_host'] != 'localhost' ) $http_host = $_POST['v_host'];
89-
if ($_POST['v_type'] == 'mysql') $db_admin = "phpMyAdmin";
90-
if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpmyadmin/";
91-
if (($_POST['v_type'] == 'mysql') && (!empty($sys['config']['DB_PMA_URL']))) $db_admin_link = $sys['config']['DB_PMA_URL'];
92-
if ($_POST['v_type'] == 'pgsql') $db_admin = "phpPgAdmin";
93-
if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phppgadmin/";
94-
if (($_POST['v_type'] == 'pgsql') && (!empty($sys['config']['DB_PGA_URL']))) $db_admin_link = $sys['config']['DB_PGA_URL'];
95-
96-
$_SESSION['ok_msg'] = __('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
97-
$_SESSION['ok_msg'] .= " / <a href=".$db_admin_link." target='_blank'>" . __('open %s',$db_admin) . "</a>";
98-
unset($v_database);
99-
unset($v_dbuser);
100-
unset($v_password);
101-
unset($v_type);
102-
unset($v_charset);
103-
}
70+
list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"] . ":");
71+
if ($_POST['v_host'] != 'localhost' ) $http_host = $_POST['v_host'];
72+
if ($_POST['v_type'] == 'mysql') $db_admin = "phpMyAdmin";
73+
if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpmyadmin/";
74+
if (($_POST['v_type'] == 'mysql') && (!empty($sys['config']['DB_PMA_URL']))) $db_admin_link = $sys['config']['DB_PMA_URL'];
75+
if ($_POST['v_type'] == 'pgsql') $db_admin = "phpPgAdmin";
76+
if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phppgadmin/";
77+
if (($_POST['v_type'] == 'pgsql') && (!empty($sys['config']['DB_PGA_URL']))) $db_admin_link = $sys['config']['DB_PGA_URL'];
78+
}
79+
80+
// Email login credentials
81+
if ((!empty($v_db_email)) && (empty($_SESSION['error_msg']))) {
82+
$to = $v_db_email;
83+
$subject = __("Database Credentials");
84+
$hostname = exec('hostname');
85+
$from = __('MAIL_FROM',$hostname);
86+
$mailtext = __('DATABASE_READY',$user."_".$_POST['v_database'],$user."_".$_POST['v_dbuser'],$_POST['v_password'],$db_admin_link);
87+
send_email($to, $subject, $mailtext, $from);
88+
}
89+
90+
// Flush field values on success
91+
if (empty($_SESSION['error_msg'])) {
92+
$_SESSION['ok_msg'] = __('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
93+
$_SESSION['ok_msg'] .= " / <a href=".$db_admin_link." target='_blank'>" . __('open %s',$db_admin) . "</a>";
94+
unset($v_database);
95+
unset($v_dbuser);
96+
unset($v_password);
97+
unset($v_type);
98+
unset($v_charset);
10499
}
105100
}
106101

102+
// Header
103+
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
104+
105+
// Panel
106+
top_panel($user,$TAB);
107+
108+
// Get user email
109+
$v_db_email = $panel[$user]['CONTACT'];
110+
111+
// List avaiable database types
107112
exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
108113
$db_types = json_decode(implode('', $output), true);
109114
unset($output);
110115

116+
// List available database servers
111117
$db_hosts = array();
112118
foreach ($db_types as $db_type ) {
113119
exec (VESTA_CMD."v-list-database-hosts ".$db_type." 'json'", $output, $return_var);
@@ -117,7 +123,10 @@
117123
unset($output);
118124
}
119125

126+
// Display body
120127
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
128+
129+
// Flush session messages
121130
unset($_SESSION['error_msg']);
122131
unset($_SESSION['ok_msg']);
123132

0 commit comments

Comments
 (0)