cwp7.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /**
  3. * WHMCS cwp7 Provisioning Module
  4. *
  5. * Provisioning for User Account on the cwp7 Server
  6. *
  7. * @see https://centos-webpanel.com/
  8. * @copyright Copyright (c) Thurdata GmbH 2020
  9. * @license GPL
  10. */
  11. use WHMCS\Database\Capsule;
  12. require_once(__DIR__ . '/api/cwp7/Admin.php');
  13. if (!defined('WHMCS')) {
  14. die('This file cannot be accessed directly');
  15. }
  16. function cwp7_ConfigOptions() {
  17. $whmcs = App::self();
  18. $serverGroupID = $whmcs->get_req_var('servergroup');
  19. $serverIDs = array(Capsule::table('tblservergroupsrel')
  20. ->select('serverid')
  21. ->where('groupid', '=', $serverGroupID)
  22. ->get());
  23. $server = Capsule::table('tblservers')
  24. ->select('ipaddress', 'accesshash')
  25. ->where('id', $serverIDs)
  26. ->where('active', '=', 1)
  27. ->get();
  28. logModuleCall(
  29. 'cwp7',
  30. __FUNCTION__,
  31. $server,
  32. 'Debug',
  33. $serverIDs
  34. );
  35. $configarray = array(
  36. "Package" => array( "Type" => "text", "Description" => "Package ID", "Default" => "1"),
  37. "inode" => array( "Type" => "text" , "Description" => "Max of inode", "Default" => "0",),
  38. "nofile" => array( "Type" => "text", "Description" => "Max of nofile", "Default" => "100", ),
  39. "nproc" => array( "Type" => "text" , "Description" => "Nproc limit - 40 suggested", "Default" => "40",),
  40. );
  41. return $configarray;
  42. }
  43. function cwp7_CreateAccount($params) {
  44. if ($params["server"] == 1) {
  45. $postvars = array(
  46. 'package' => $params["configoption1"],
  47. 'domain' => $params["domain"],
  48. 'key' => $params["serveraccesshash"],
  49. 'action' => 'add',
  50. 'username' => $params["username"],
  51. 'user' => $params["username"],
  52. 'pass' => $params["password"],
  53. 'email' => $params["clientsdetails"]["email"],
  54. 'inode' => $params["configoption2"],
  55. 'nofile' => $params["configoption3"],
  56. 'nproc' => $params["configoption4"],
  57. 'server_ips'=>$params["serverip"]
  58. );
  59. $postdata = http_build_query($postvars);
  60. $curl = curl_init();
  61. curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/account');
  62. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  63. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  64. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  65. curl_setopt($curl, CURLOPT_POST, true);
  66. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  67. $answer = curl_exec($curl);
  68. logModuleCall('cwpwhmcs','CreateAccount_UserAccount','https://' . $params["serverhostname"] . ':2304/v1/account/'.$postdata,$answer);
  69. }
  70. if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];}
  71. return $result;
  72. }
  73. function cwp7_TerminateAccount($params) {
  74. if ($params["server"] == 1) {
  75. $postvars = array('key' => $params["serveraccesshash"],'action' => 'del','user' => $params["username"]);
  76. $postdata = http_build_query($postvars);
  77. $curl = curl_init();
  78. curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/account');
  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. logModuleCall('cwpwhmcs','TerminateAccount','https://' . $params["serverhostname"] . ':2304/v1/account/'.$postdata,$answer);
  86. }
  87. if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];}
  88. return $result;
  89. }
  90. function cwp7_SuspendAccount($params) {
  91. if ($params["server"] == 1) {
  92. $postvars = array('key' => $params["serveraccesshash"],'action' => 'susp','user' => $params["username"]);
  93. $postdata = http_build_query($postvars);
  94. $curl = curl_init();
  95. curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/account');
  96. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  97. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  98. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  99. curl_setopt($curl, CURLOPT_POST, true);
  100. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  101. $answer = curl_exec($curl);
  102. }
  103. if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];}
  104. logModuleCall('cwpwhmcs','SuspendAccount','https://' . $params["serverhostname"] . ':2304/v1/account/'.$postdata,$result);
  105. return $result;
  106. }
  107. function cwp7_UnsuspendAccount($params) {
  108. if ($params["server"] == 1) {
  109. $postvars = array('key' => $params["serveraccesshash"],'action' => 'unsp','user' => $params["username"]);
  110. $postdata = http_build_query($postvars);
  111. $curl = curl_init();
  112. curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/account');
  113. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  114. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  115. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  116. curl_setopt($curl, CURLOPT_POST, true);
  117. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  118. $answer = curl_exec($curl);
  119. }
  120. if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];}
  121. logModuleCall('cwpwhmcs','UnsuspendAccount','https://' . $params["serverhostname"] . ':2304/v1/account'.$postdata,$result);
  122. return $result;
  123. }
  124. function cwp7_ClientArea($params){
  125. $postvars = array('key' => $params["serveraccesshash"], 'action' => 'list', 'user' => $params["username"], 'timer' => 5);
  126. $postdata = http_build_query($postvars);
  127. $curl = curl_init();
  128. curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/user_session');
  129. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  130. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  131. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  132. curl_setopt($curl, CURLOPT_POST, true);
  133. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  134. $answer = curl_exec($curl);
  135. $arry = (json_decode($answer, true)); //die;F
  136. $link = $arry['msj']['details'];
  137. $linkautologin = $link[0]['url'];
  138. logModuleCall('cwpwhmcs', 'cwp7_LoginLink', 'https://' . $params["serverhostname"] . ':2304/v1/user_session' . $postdata, $answer);
  139. return "<a href=\"{$linkautologin}\" target=\"_blank\" style=\"color:#cc0000\">Login to Control Panel</a>";
  140. }
  141. function cwp7_AdminLink($params) {
  142. $code = '<form action="https://'.$params["serverhostname"].':2031" method="post" target="_blank">
  143. <input type="submit" value="Login to Control Panel" />
  144. </form>';
  145. return $code;
  146. }
  147. function cwp7_LoginLink($params) {
  148. $postvars = array('key' => $params["serveraccesshash"],'action' => 'list','user' => $params["username"],'timer'=>5);
  149. $postdata = http_build_query($postvars);
  150. $curl = curl_init();
  151. curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/user_session');
  152. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  153. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  154. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  155. curl_setopt($curl, CURLOPT_POST, true);
  156. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  157. $answer = curl_exec($curl);
  158. $arry=(json_decode($answer,true)); //die;F
  159. $link=$arry['msj']['details'];
  160. $linkautologin=$link[0]['url'];
  161. logModuleCall('cwpwhmcs','cwp7_LoginLink','https://' . $params["serverhostname"] . ':2304/v1/user_session'.$postdata,$answer);
  162. echo "<a href=\"{$linkautologin}\" target=\"_blank\" style=\"color:#cc0000\">Control Panel</a>";
  163. }
  164. function cwp7_ChangePassword($params){
  165. $postvars = array('key' => $params["serveraccesshash"],'acction' => 'udp','user' => $params["username"], 'pass' =>$params["password"]);
  166. $postdata = http_build_query($postvars);
  167. $curl = curl_init();
  168. curl_setopt($curl, CURLOPT_URL, 'https://'. $params["serverhostname"] . ':2304/v1/changepass');
  169. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  170. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  171. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  172. curl_setopt($curl, CURLOPT_POST, true);
  173. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  174. $answer = curl_exec($curl);
  175. if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];}
  176. logModuleCall('cwpwhmcs','ChangePassword','https://' . $params["serverhostname"] . ':2304/v1/changepass'.$postdata,$result);
  177. return $result;
  178. }
  179. function cwp7_ChangePackage($params){
  180. $postvars = array("key" => $params["serveraccesshash"],"action"=>'udp','user' => $params["username"],'package'=>$params["configoption1"].'@');
  181. $postdata = http_build_query($postvars);
  182. $curl = curl_init();
  183. curl_setopt($curl, CURLOPT_URL, 'https://'. $params["serverhostname"] . ':2304/v1/account');
  184. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  185. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  186. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  187. curl_setopt($curl, CURLOPT_POST, true);
  188. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  189. $answer = curl_exec($curl);
  190. curl_close($curl);
  191. if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];}
  192. logModuleCall('cwpwhmcs','ChangePackage','https://' . $params["serverhostname"] . ':2304/v1/packages'.$postdata,$answer);
  193. return $result;
  194. }
  195. function cwp7_UsageUpdate($params) {
  196. $postvars = array('key' => $params["serveraccesshash"],'action' => 'list');
  197. $postdata = http_build_query($postvars);
  198. $curl = curl_init();
  199. curl_setopt($curl, CURLOPT_URL, 'https://'. $params["serverhostname"] . ':2304/v1/account');
  200. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  201. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  202. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  203. curl_setopt($curl, CURLOPT_POST, true);
  204. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  205. if (curl_errno($curl)) {
  206. $error_msg = curl_error($curl);
  207. }
  208. $answer = curl_exec($curl);
  209. $resp=json_decode($answer,true);
  210. if($resp['status']=='OK'){
  211. $results=$resp['msj'];
  212. for($i=0;$i<count($results);$i++){
  213. $date=date('Y-m-d H:i:s');
  214. if($results[$i]['diskusage']==''){$diskusage=0;}else{$diskusage=trim($results[$i]['diskusage']);}
  215. if($results[$i]['disklimit']==''){$disklimit=0;}else{$disklimit=trim($results[$i]['disklimit']);}
  216. if($results[$i]['bandwidth']==''){$bandwidth=0;}else{$bandwidth=trim($results[$i]['bandwidth']);}
  217. if($results[$i]['bwlimit']==''){$bwlimit=0;}else{$bwlimit=trim($results[$i]['bwlimit']);}
  218. $domian=trim($results[$i]['domain']);
  219. try {
  220. \WHMCS\Database\Capsule::table('tblhosting')
  221. ->where('dedicatedip', $results[$i]['ip_address'])
  222. ->where('domain', $domian)
  223. ->update([
  224. 'diskusage' => $diskusage,
  225. 'disklimit' => $disklimit,
  226. 'bwusage' => $bandwidth,
  227. 'bwlimit' => $bwlimit,
  228. 'lastupdate' => date('Y-m-d H:i:S'),
  229. ]);
  230. } catch (\Exception $e) {
  231. logActivity('ERROR: Unable to update server usage: ' . $e->getMessage());
  232. }
  233. }
  234. }
  235. }