1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Puerari\Cwp; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @trait Mysql |
7
|
|
|
* @package Puerari\Cwp |
8
|
|
|
* @author Leandro Puerari <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
trait Mysql |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @param string $user : Account username |
14
|
|
|
* @param string $database : Data Base Name (Max 8 Characters) |
15
|
|
|
* @return string|bool: false on failure, result on success (JSON / XML) |
16
|
|
|
* status -> OK |
17
|
|
|
* status -> Error, msj -> Duplicate data base name |
18
|
|
|
* status -> Error, msj -> Mysql Package Exhausted |
19
|
|
|
*/ |
20
|
|
|
public function createMysqlDatabase(string $user, string $database) |
21
|
|
|
{ |
22
|
|
|
$this->data = compact('user', 'database'); |
|
|
|
|
23
|
|
|
$this->data['debug'] = $this->debug; |
24
|
|
|
$this->data['action'] = 'add'; |
25
|
|
|
$this->cwpuri = 'databasemysql'; |
|
|
|
|
26
|
|
|
return $this->execCurl(); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $user : Account username |
31
|
|
|
* @param string $database : Data Base Name (Max 8 Characters) |
32
|
|
|
* @return string|bool: false on failure, result on success (JSON / XML) |
33
|
|
|
* status -> OK, msj -> Deleted database |
34
|
|
|
* status -> Error, can not delete database as root |
35
|
|
|
*/ |
36
|
|
|
public function deleteMysqlDatabase(string $user, string $database) |
37
|
|
|
{ |
38
|
|
|
$this->data = compact('user', 'database'); |
|
|
|
|
39
|
|
|
$this->data['debug'] = $this->debug; |
40
|
|
|
$this->data['action'] = 'del'; |
41
|
|
|
$this->cwpuri = 'databasemysql'; |
|
|
|
|
42
|
|
|
return $this->execCurl(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $user : Account username |
47
|
|
|
* @return string|bool: false on failure, result on success (JSON / XML) |
48
|
|
|
* status -> OK, msj -> array |
49
|
|
|
* status -> OK, msj -> No packages found |
50
|
|
|
*/ |
51
|
|
|
public function listMysqlDatabases(string $user) |
52
|
|
|
{ |
53
|
|
|
$this->data = compact('user'); |
|
|
|
|
54
|
|
|
$this->data['debug'] = $this->debug; |
55
|
|
|
$this->data['action'] = 'list'; |
56
|
|
|
$this->cwpuri = 'databasemysql'; |
|
|
|
|
57
|
|
|
return $this->execCurl(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $user : Account username |
62
|
|
|
* @param string $userdb : Database User |
63
|
|
|
* @param string $pass : Password for the database user |
64
|
|
|
* @param string $dbase : Data Base Name (Max 8 Characters) |
65
|
|
|
* @param string $host : Name Host (%, Localhost, IP) |
66
|
|
|
* @return string|bool: false on failure, result on success (JSON / XML) |
67
|
|
|
* status -> OK |
68
|
|
|
* status -> Error, msj -> User already exists |
69
|
|
|
*/ |
70
|
|
|
public function createMysqlUser(string $user, string $userdb, string $pass, string $dbase, string $host) |
71
|
|
|
{ |
72
|
|
|
$this->data = compact('user', 'userdb', 'pass', 'dbase', 'host'); |
|
|
|
|
73
|
|
|
$this->data['debug'] = $this->debug; |
74
|
|
|
$this->data['action'] = 'add'; |
75
|
|
|
$this->cwpuri = 'usermysql'; |
|
|
|
|
76
|
|
|
return $this->execCurl(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $user : Account username |
81
|
|
|
* @param string $userdb : Database User |
82
|
|
|
* @param string $host : Name Host (%, Localhost, IP) |
83
|
|
|
* @return string|bool: false on failure, result on success (JSON / XML) |
84
|
|
|
* status -> OK |
85
|
|
|
*/ |
86
|
|
|
public function deleteMysqlUser(string $user, string $userdb, string $host) |
87
|
|
|
{ |
88
|
|
|
$this->data = compact('user', 'userdb', 'host'); |
|
|
|
|
89
|
|
|
$this->data['debug'] = $this->debug; |
90
|
|
|
$this->data['action'] = 'del'; |
91
|
|
|
$this->cwpuri = 'usermysql'; |
|
|
|
|
92
|
|
|
return $this->execCurl(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $user : Account username |
97
|
|
|
* @return string|bool: false on failure, result on success (JSON / XML) |
98
|
|
|
* status -> OK, msj -> Array of database users |
99
|
|
|
* status -> Error, msj -> User does not exist |
100
|
|
|
*/ |
101
|
|
|
public function listMysqlUsers(string $user) |
102
|
|
|
{ |
103
|
|
|
$this->data = compact('user'); |
|
|
|
|
104
|
|
|
$this->data['debug'] = $this->debug; |
105
|
|
|
$this->data['action'] = 'list'; |
106
|
|
|
$this->cwpuri = 'usermysql'; |
|
|
|
|
107
|
|
|
return $this->execCurl(); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|