Skip to content

Commit 1a49d80

Browse files
committed
WHMCS support module
1 parent 410b7e3 commit 1a49d80

File tree

1 file changed

+340
-0
lines changed

1 file changed

+340
-0
lines changed
Lines changed: 340 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,340 @@
1+
<?php
2+
3+
function vesta_ConfigOptions() {
4+
5+
$configarray = array(
6+
"Package Name" => array( "Type" => "text", "Default" => "default"),
7+
"SSH Access" => array( "Type" => "yesno", "Description" => "Tick to grant access", ),
8+
"IP Address (optional)" => array( "Type" => "text" ),
9+
);
10+
return $configarray;
11+
12+
}
13+
14+
function vesta_CreateAccount($params) {
15+
16+
// Execute only if there is assigned server
17+
if ($params["server"] == 1) {
18+
19+
// Prepare variables
20+
$postvars = array(
21+
'user' => $params["serverusername"],
22+
'password' => $params["serverpassword"],
23+
'hash' => $params["serveraccesshash"],
24+
'cmd' => 'v-add-user',
25+
'arg1' => $params["username"],
26+
'arg2' => $params["password"],
27+
'arg3' => $params["clientsdetails"]["email"],
28+
'arg4' => $params["configoption1"],
29+
'arg5' => $params["clientsdetails"]["firstname"],
30+
'arg6' => $params["clientsdetails"]["lastname"],
31+
);
32+
$postdata = http_build_query($postvars);
33+
34+
// Create user account
35+
$curl = curl_init();
36+
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
37+
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
38+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
39+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
40+
curl_setopt($curl, CURLOPT_POST, true);
41+
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
42+
$answer = curl_exec($curl);
43+
44+
// Enable ssh access
45+
if(($answer == 'OK') && ($params["configoption2"] == 'on')) {
46+
$postvars = array(
47+
'user' => $params["serverusername"],
48+
'password' => $params["serverpassword"],
49+
'hash' => $params["serveraccesshash"],
50+
'cmd' => 'v-change-user-shell',
51+
'arg1' => $params["username"],
52+
'arg2' => 'bash'
53+
);
54+
$postdata = http_build_query($postvars);
55+
$curl = curl_init();
56+
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
57+
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
58+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
59+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
60+
curl_setopt($curl, CURLOPT_POST, true);
61+
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
62+
$answer = curl_exec($curl);
63+
}
64+
65+
// Add domain
66+
if(($answer == 'OK') && (!empty($params["domain"]))) {
67+
$postvars = array(
68+
'user' => $params["serverusername"],
69+
'password' => $params["serverpassword"],
70+
'hash' => $params["serveraccesshash"],
71+
'cmd' => 'v-add-domain',
72+
'arg1' => $params["username"],
73+
'arg2' => $params["domain"],
74+
'arg3' => $params["configoption3"],
75+
);
76+
$postdata = http_build_query($postvars);
77+
$curl = curl_init();
78+
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
79+
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
80+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
81+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
82+
curl_setopt($curl, CURLOPT_POST, true);
83+
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
84+
$answer = curl_exec($curl);
85+
}
86+
}
87+
88+
if($answer == 'OK') {
89+
$result = "success";
90+
} else {
91+
$result = $answer;
92+
}
93+
return $result;
94+
95+
}
96+
97+
function vesta_TerminateAccount($params) {
98+
99+
// Execute only if there is assigned server
100+
if ($params["server"] == 1) {
101+
102+
// Prepare variables
103+
$postvars = array(
104+
'user' => $params["serverusername"],
105+
'password' => $params["serverpassword"],
106+
'hash' => $params["serveraccesshash"],
107+
'cmd' => 'v-delete-user',
108+
'arg1' => $params["username"]
109+
);
110+
$postdata = http_build_query($postvars);
111+
112+
// Delete user account
113+
$curl = curl_init();
114+
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
115+
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
116+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
117+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
118+
curl_setopt($curl, CURLOPT_POST, true);
119+
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
120+
$answer = curl_exec($curl);
121+
}
122+
123+
if($answer == 'OK') {
124+
$result = "success";
125+
} else {
126+
$result = $answer;
127+
}
128+
129+
return $result;
130+
131+
}
132+
133+
function vesta_SuspendAccount($params) {
134+
135+
// Execute only if there is assigned server
136+
if ($params["server"] == 1) {
137+
138+
// Prepare variables
139+
$postvars = array(
140+
'user' => $params["serverusername"],
141+
'password' => $params["serverpassword"],
142+
'hash' => $params["serveraccesshash"],
143+
'cmd' => 'v-suspend-user',
144+
'arg1' => $params["username"]
145+
);
146+
$postdata = http_build_query($postvars);
147+
148+
// Susupend user account
149+
$curl = curl_init();
150+
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
151+
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
152+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
153+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
154+
curl_setopt($curl, CURLOPT_POST, true);
155+
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
156+
$answer = curl_exec($curl);
157+
}
158+
159+
if($answer == 'OK') {
160+
$result = "success";
161+
} else {
162+
$result = $answer;
163+
}
164+
165+
}
166+
167+
function vesta_UnsuspendAccount($params) {
168+
169+
// Execute only if there is assigned server
170+
if ($params["server"] == 1) {
171+
172+
// Prepare variables
173+
$postvars = array(
174+
'user' => $params["serverusername"],
175+
'password' => $params["serverpassword"],
176+
'hash' => $params["serveraccesshash"],
177+
'cmd' => 'v-unsuspend-user',
178+
'arg1' => $params["username"]
179+
);
180+
$postdata = http_build_query($postvars);
181+
182+
// Unsusupend user account
183+
$curl = curl_init();
184+
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
185+
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
186+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
187+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
188+
curl_setopt($curl, CURLOPT_POST, true);
189+
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
190+
$answer = curl_exec($curl);
191+
}
192+
193+
if($answer == 'OK') {
194+
$result = "success";
195+
} else {
196+
$result = $answer;
197+
}
198+
199+
}
200+
201+
function vesta_ChangePassword($params) {
202+
203+
// Execute only if there is assigned server
204+
if ($params["server"] == 1) {
205+
206+
// Prepare variables
207+
$postvars = array(
208+
'user' => $params["serverusername"],
209+
'password' => $params["serverpassword"],
210+
'hash' => $params["serveraccesshash"],
211+
'cmd' => 'v-change-user-password',
212+
'arg1' => $params["username"],
213+
'arg2' => $params["password"]
214+
);
215+
$postdata = http_build_query($postvars);
216+
217+
// Change user package
218+
$curl = curl_init();
219+
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
220+
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
221+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
222+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
223+
curl_setopt($curl, CURLOPT_POST, true);
224+
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
225+
$answer = curl_exec($curl);
226+
}
227+
228+
if($answer == 'OK') {
229+
$result = "success";
230+
} else {
231+
$result = $answer;
232+
}
233+
return $result;
234+
235+
}
236+
237+
function vesta_ChangePackage($params) {
238+
239+
// Execute only if there is assigned server
240+
if ($params["server"] == 1) {
241+
242+
// Prepare variables
243+
$postvars = array(
244+
'user' => $params["serverusername"],
245+
'password' => $params["serverpassword"],
246+
'hash' => $params["serveraccesshash"],
247+
'cmd' => 'v-change-user-package',
248+
'arg1' => $params["username"],
249+
'arg2' => $params["configoption1"]
250+
);
251+
$postdata = http_build_query($postvars);
252+
253+
// Change user package
254+
$curl = curl_init();
255+
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
256+
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
257+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
258+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
259+
curl_setopt($curl, CURLOPT_POST, true);
260+
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
261+
$answer = curl_exec($curl);
262+
}
263+
264+
if($answer == 'OK') {
265+
$result = "success";
266+
} else {
267+
$result = $answer;
268+
}
269+
return $result;
270+
271+
}
272+
273+
function vesta_ClientArea($params) {
274+
275+
$code = '<form action="https://'.$params["serverhostname"].'/login/" method="post" target="_blank">
276+
<input type="hidden" name="user" value="'.$params["username"].'" />
277+
<input type="hidden" name="password" value="'.$params["password"].'" />
278+
<input type="submit" value="Login to Control Panel" />
279+
<input type="button" value="Login to Webmail" onClick="window.open(\'http://'.$serverhostname.'/webmail\')" />
280+
</form>';
281+
return $code;
282+
283+
}
284+
285+
function vesta_AdminLink($params) {
286+
287+
$code = '<form action="https://'.$params["serverhostname"].'/login/" method="post" target="_blank">
288+
<input type="hidden" name="user" value="'.$params["serverusername"].'" />
289+
<input type="hidden" name="password" value="'.$params["serverpassword"].'" />
290+
<input type="submit" value="Login to Control Panel" />
291+
</form>';
292+
return $code;
293+
294+
}
295+
296+
function vesta_LoginLink($params) {
297+
298+
echo "<a href=\"https://".$params["serverhostname"]."/login/\" target=\"_blank\" style=\"color:#cc0000\">control panel</a>";
299+
300+
}
301+
302+
function vesta_UsageUpdate($params) {
303+
304+
// Prepare variables
305+
$postvars = array(
306+
'user' => $params["serverusername"],
307+
'password' => $params["serverpassword"],
308+
'hash' => $params["serveraccesshash"],
309+
'cmd' => 'v-list-users',
310+
'arg1' => 'json'
311+
);
312+
$postdata = http_build_query($postvars);
313+
314+
// Get user stats
315+
$curl = curl_init();
316+
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
317+
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
318+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
319+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
320+
curl_setopt($curl, CURLOPT_POST, true);
321+
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
322+
$answer = curl_exec($curl);
323+
324+
// Decode json data
325+
$results = json_decode($answer, true);
326+
327+
// Loop through results and update DB
328+
foreach ($results AS $user=>$values) {
329+
update_query("tblhosting",array(
330+
"diskusage"=>$values['U_DISK'],
331+
"disklimit"=>$values['DISK_QUOTA'],
332+
"bwusage"=>$values['U_BANDWIDTH'],
333+
"bwlimit"=>$values['BANDWIDTH'],
334+
"lastupdate"=>"now()",
335+
),array("server"=>$params['serverid'], "username"=>$user));
336+
}
337+
338+
}
339+
340+
?>

0 commit comments

Comments
 (0)