forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDB.class.php
More file actions
190 lines (159 loc) · 5.88 KB
/
Copy pathDB.class.php
File metadata and controls
190 lines (159 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/**
* DB
*
* @author vesta, http://vestacp.com/
* @author Dmitry Malishev <dima.malishev@gmail.com>
* @author Dmitry Naumov-Socolov <naumov.socolov@gmail.com>
* @copyright vesta 2010-2011
*/
class DB extends AjaxHandler
{
/**
* Get DB entries
*
* @param Request $request
* @return string - Ajax Reply
*/
public function getListExecute(Request $request)
{
$user = $this->getLoggedUser();
$reply = array();
$result = Vesta::execute(Vesta::V_LIST_DB_BASES, array($user['uid'], Config::get('response_type')));
foreach ($result['data'] as $db => $record) {
$type = $record['TYPE'];
if (!isset($reply[$type])) {
$reply[$type] = array();
}
$reply[$type][] = array(
'DB' => $db,
'OWNER' => $record['USER'],
'USER' => $record['USER'],
'USERS' => (array)$record['USER'],
'HOST' => $record['HOST'],
'TYPE' => $record['TYPE'],
'U_DISK' => $record['U_DISK'],
'DISK' => 2024,
'SUSPEND' => $record['SUSPEND'],
'DATE' => date(Config::get('ui_date_format', strtotime($record['DATE'])))
);
}
if (!$result['status']) {
$this->errors[] = array($result['error_code'] => $result['error_message']);
}
return $this->reply($result['status'], $reply);
}
/**
* Add DB entry
*
* @param Request $request
* @return string - Ajax Reply
*/
public function addExecute(Request $request)
{
$user = $this->getLoggedUser();
$_s = $request->getParameter('spell');
$params = array(
'USER' => $user['uid'],
'DB' => $_s['DB'],
'DB_USER' => $_s['USER'],
'DB_PASSWORD' => $_s['PASSWORD'],
'TYPE' => $_s['TYPE']
);
$result = Vesta::execute(Vesta::V_ADD_DB_BASE, $params);
if (!$result['status']) {
$this->errors[] = array($result['error_code'] => $result['error_message']);
}
if ($_s['SUSPEND'] == 'on') {
if($result['status']){
$result = array();
$result = Vesta::execute(Vesta::V_SUSPEND_DB_BASE, array('USER' => $user['uid'], 'JOB' => $_s['DB']));
if (!$result['status']) {
$this->status = FALSE;
$this->errors['SUSPEND'] = array($result['error_code'] => $result['error_message']);
}
}
}
return $this->reply($result['status'], $result['data']);
}
/**
* Delete DB entry
*
* @param Request $request
* @return string - Ajax Reply
*/
public function deleteExecute(Request $request)
{
$_s = $request->getParameter('spell');
$user = $this->getLoggedUser();
$params = array(
'USER' => $user['uid'],
'DB' => $_s['DB']
);
$result = Vesta::execute(Vesta::V_DEL_DB_BASE, $params);
if (!$result['status']) {
$this->errors[] = array($result['error_code'] => $result['error_message']);
}
return $this->reply($result['status'], $result['data']);
}
/**
* Change Password
*
* @param Request $request
* @return string - Ajax Reply
*/
public function changeExecute(Request $request)
{
$_s = $request->getParameter('spell');
$_old = $request->getParameter('old');
$_new = $request->getParameter('new');
$user = $this->getLoggedUser();
$result = array();
if($_new['SUSPEND'] == 'on'){
$result = Vesta::execute(Vesta::V_SUSPEND_DB_BASE, array('USER' => $user['uid'], 'DB' => $_new['DB']));
}
else{
$result = Vesta::execute(Vesta::V_UNSUSPEND_DB_BASE, array('USER' => $user['uid'], 'DB' => $_new['DB']));
}
if (!$result['status']) {
$this->status = FALSE;
$this->errors['SUSPEND'] = array($result['error_code'] => $result['error_message']);
}
if ($_new['PASSWORD'] != Vesta::SAME_PASSWORD && $_new['PASSWORD'] != $_old['PASSWORD']) {
$params = array(
'USER' => $user['uid'],
'DB' => $_new['DB'],
'PASSWORD' => $_new['PASSWORD']
);
$result = Vesta::execute(Vesta::V_CHANGE_DB_PASSWORD, $params);
if (!$result['status']) {
$this->errors[] = array($result['error_code'] => $result['error_message']);
}
}
return $this->reply($result['status'], $result['data']);
}
public function massiveSuspendExecute(Request $request)
{
$user = $this->getLoggedUser();
$_entities = $request->getParameter('entities');
foreach($_entities as $entity){
$result = Vesta::execute(Vesta::V_SUSPEND_DB_BASE, array('USER' => $user, $entity['DB']));
}
}
public function massiveUnsuspendExecute(Request $request)
{
$user = $this->getLoggedUser();
$_entities = $request->getParameter('entities');
foreach($_entities as $entity){
$result = Vesta::execute(Vesta::V_UNSUSPEND_DB_BASE, array('USER' => $user, $entity['DB']));
}
}
public function massiveDeleteExecute(Request $request)
{
$user = $this->getLoggedUser();
$_entities = $request->getParameter('entities');
foreach($_entities as $entity){
$result = Vesta::execute(Vesta::V_DEL_DB_BASE, array('USER' => $user, $entity['DB']));
}
}
}