1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ExpressApi\Apis; |
4
|
|
|
|
5
|
|
|
class CPanel extends xmlapi { |
6
|
|
|
|
7
|
|
|
const DEBUG = 0; |
8
|
|
|
|
9
|
|
|
private $ip; |
10
|
|
|
private $user; |
|
|
|
|
11
|
|
|
private $pass; |
12
|
|
|
|
13
|
|
|
public function __construct($param) { |
14
|
|
|
|
15
|
|
|
$this->ip = $param["ip"]; |
16
|
|
|
$this->user = $param["user"]; |
17
|
|
|
$this->pass = $param["pass"]; |
18
|
|
|
|
19
|
|
|
if(empty($this->ip)) { |
20
|
|
|
$this->ip = $_SERVER['SERVER_ADDR']; |
21
|
|
|
} |
22
|
|
|
parent::__construct($this->ip); |
23
|
|
|
if(!empty($this->user) && !empty($this->pass)) { |
24
|
|
|
$this->password_auth($this->user, $this->pass); |
25
|
|
|
} |
26
|
|
|
$this->set_output($param["output"]); |
27
|
|
|
$this->set_port($param["port"]); |
28
|
|
|
$this->set_debug($param["debug"]); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getEmailAccounts($filter = NULL) { |
32
|
|
|
$this->user = $this->get_user(); |
33
|
|
|
if(!empty($this->user)) { |
34
|
|
|
if(!is_null($filter)) { |
35
|
|
|
$params = array("regex" => $filter); |
36
|
|
|
$retorno = $this->api2_query($this->get_user(), "Email", "listpopswithdisk", $params); |
37
|
|
|
} |
38
|
|
|
else { |
39
|
|
|
$retorno = $this->api2_query($this->get_user(), "Email", "listpopswithdisk"); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
return $retorno; |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getEmailAccountsDiskUsage($filter = NULL) { |
46
|
|
|
$this->user = $this->get_user(); |
47
|
|
|
if(!empty($this->user)) { |
48
|
|
|
if(!is_null($filter)) { |
49
|
|
|
$params = array("regex" => $filter); |
50
|
|
|
$retorno = $this->api2_query($this->get_user(), "Email", "getdiskusage", $params); |
51
|
|
|
} |
52
|
|
|
else { |
53
|
|
|
$retorno = $this->api2_query($this->get_user(), "Email", "getdiskusage"); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
return $retorno; |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function delEmailAccount($email) { |
60
|
|
|
$this->user = $this->get_user(); |
61
|
|
|
if(!empty($this->user)) { |
62
|
|
|
$a = explode("@", $email); |
63
|
|
|
$email_user = $a[0]; |
64
|
|
|
$domain = $a[1]; |
65
|
|
|
$params = array("domain" => $domain, |
66
|
|
|
"email" => $email_user |
67
|
|
|
); |
68
|
|
|
$retorno = $this->api2_query($this->get_user(), "Email", "delpop", $params); |
69
|
|
|
} |
70
|
|
|
return $retorno; |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function addEmailAccount($domain, $email_user, $password, $quota) { |
74
|
|
|
$this->user = $this->get_user(); |
75
|
|
|
if(!empty($this->user)) { |
76
|
|
|
$params = array("domain" => $domain, |
77
|
|
|
"email" => $email_user, |
78
|
|
|
"password" => $password, |
79
|
|
|
"quota" => $quota |
80
|
|
|
); |
81
|
|
|
$retorno = $this->api2_query($this->get_user(), "Email", "addpop", $params); |
82
|
|
|
} |
83
|
|
|
return $retorno; |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function modEmailAccount($domain, $email_user, $password, $quota) { |
87
|
|
|
$this->user = $this->get_user(); |
88
|
|
|
if(!empty($this->user)) { |
89
|
|
|
$params1 = array("domain" => $domain, |
90
|
|
|
"email" => $email_user, |
91
|
|
|
"quota" => $quota |
92
|
|
|
); |
93
|
|
|
$retorno[] = $this->api2_query($this->get_user(), "Email", "editquota", $params1); |
|
|
|
|
94
|
|
|
if(!empty($password)) { |
95
|
|
|
$params2 = array("domain" => $domain, |
96
|
|
|
"email" => $email_user, |
97
|
|
|
"password" => $password |
98
|
|
|
); |
99
|
|
|
$retorno[] = $this->api2_query($this->get_user(), "Email", "passwdpop", $params2); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
return $retorno; |
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function setCatchAll($domain, $email) { |
106
|
|
|
$this->user = $this->get_user(); |
107
|
|
|
if(!empty($this->user)) { |
108
|
|
|
$params = array("fwdopt " => 'fwd', |
109
|
|
|
"fwdemail" => $email, |
110
|
|
|
"domain" => $domain |
111
|
|
|
); |
112
|
|
|
$retorno[] = $this->api2_query($this->get_user(), "Email", "setdefaultaddress", $params); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
return $retorno; |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getAddonDomains($filter = NULL) { |
118
|
|
|
$this->user = $this->get_user(); |
119
|
|
|
if(!empty($this->user)) { |
120
|
|
|
if(!is_null($filter)) { |
121
|
|
|
$params = array("regex" => $filter); |
122
|
|
|
$retorno = $this->api2_query($this->get_user(), "AddonDomain", "listaddondomains", $params); |
123
|
|
|
} |
124
|
|
|
else { |
125
|
|
|
$retorno = $this->api2_query($this->get_user(), "AddonDomain", "listaddondomains"); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
return $retorno; |
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function getHddDiskUsage($filter = NULL) { |
132
|
|
|
$this->user = $this->get_user(); |
133
|
|
|
if(!empty($this->user)) { |
134
|
|
|
if(!is_null($filter)) { |
135
|
|
|
$params = array("regex" => $filter); |
136
|
|
|
$retorno = $this->api2_query($this->get_user(), "DiskUsage", "fetchdiskusage", $params); |
137
|
|
|
} |
138
|
|
|
else { |
139
|
|
|
$retorno = $this->api2_query($this->get_user(), "DiskUsage", "fetchdiskusage"); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
return $retorno; |
|
|
|
|
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function getBandwidthUsage($filter = NULL) { |
146
|
|
|
$this->user = $this->get_user(); |
147
|
|
|
if(!empty($this->user)) { |
148
|
|
|
if(!is_null($filter)) { |
149
|
|
|
$params = array("regex" => $filter); |
150
|
|
|
$retorno = $this->api2_query($this->get_user(), 'Stats', 'getthismonthsbwusage', $params); |
151
|
|
|
} |
152
|
|
|
else { |
153
|
|
|
$retorno = $this->api2_query($this->get_user(), 'Stats', 'getthismonthsbwusage'); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
return $retorno; |
|
|
|
|
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function getParkedDomains($filter = NULL) { |
160
|
|
|
$this->user = $this->get_user(); |
161
|
|
|
if(!empty($this->user)) { |
162
|
|
|
if(!is_null($filter)) { |
163
|
|
|
$params = array("regex" => $filter); |
164
|
|
|
$retorno = $this->api2_query($this->get_user(), "Park", "listparkeddomains", $params); |
165
|
|
|
} |
166
|
|
|
else { |
167
|
|
|
$retorno = $this->api2_query($this->get_user(), "Park", "listparkeddomains"); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
return $retorno; |
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function getSubDomains($filter = NULL) { |
174
|
|
|
$this->user = $this->get_user(); |
175
|
|
|
if(!empty($this->user)) { |
176
|
|
|
if(!is_null($filter)) { |
177
|
|
|
$params = array("regex" => $filter); |
178
|
|
|
$retorno = $this->api2_query($this->get_user(), "SubDomain", "listsubdomains", $params); |
179
|
|
|
} |
180
|
|
|
else { |
181
|
|
|
$retorno = $this->api2_query($this->get_user(), "SubDomain", "listsubdomains"); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
return $retorno; |
|
|
|
|
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function createMysqlDb($dbname) { |
188
|
|
|
$retorno = false; |
189
|
|
|
$this->user = $this->get_user(); |
190
|
|
|
if(!empty($this->user)) { |
191
|
|
|
$params = array($dbname); |
192
|
|
|
$retorno = $this->api1_query($this->user, "Mysql", "adddb", $params); |
193
|
|
|
} |
194
|
|
|
return json_decode($retorno); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
public function createDbUser($databaseuser, $databasepass) { |
198
|
|
|
$this->user = $this->get_user(); |
199
|
|
|
if(!empty($this->user)) { |
200
|
|
|
$params = array($databaseuser, $databasepass); |
201
|
|
|
$retorno = $this->api1_query($this->user, "Mysql", "adduser", $params); |
202
|
|
|
} |
203
|
|
|
return json_decode($retorno); |
|
|
|
|
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function addUserToDb($databasename, $databaseuser) { |
207
|
|
|
$this->user = $this->get_user(); |
208
|
|
|
if(!empty($this->user)) { |
209
|
|
|
$params = array($databasename, $databaseuser, 'all'); |
210
|
|
|
$retorno = $this->api1_query($this->user, "Mysql", "adduserdb", $params); |
211
|
|
|
} |
212
|
|
|
return json_decode($retorno); |
|
|
|
|
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function getFtpAccounts() { |
216
|
|
|
$this->user = $this->get_user(); |
217
|
|
|
if(!empty($this->user)) { |
218
|
|
|
$retorno = $this->api2_query($this->user, "Ftp", "listftpwithdisk"); |
219
|
|
|
} |
220
|
|
|
return $retorno; |
|
|
|
|
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function addFtpAccount($userFtp, $pass, $quota, $homedir) { |
224
|
|
|
$this->user = $this->get_user(); |
225
|
|
|
if(!empty($this->user)) { |
226
|
|
|
$params = array("user" => $userFtp, |
227
|
|
|
"pass" => $pass, |
228
|
|
|
"quota" => $quota, |
229
|
|
|
"homedir" => $homedir |
230
|
|
|
); |
231
|
|
|
debug($params); |
232
|
|
|
$retorno = $this->api2_query($this->user, "Ftp", "addftp", $params); |
233
|
|
|
} |
234
|
|
|
return $retorno; |
|
|
|
|
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|