cwp7.php 11 KB

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