whmcs-module.php 11 KB

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