zimbraSingle.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. * WHMCS Zimbra Provisioning Module
  4. *
  5. * Provisioning for private user accounts on the Zimbra Server
  6. *
  7. * @see https://www.zimbra.com
  8. * @copyright Copyright (c) Thurdata GmbH 2020
  9. * @license GPL
  10. */
  11. if (!defined("WHMCS")) {
  12. die("This file cannot be accessed directly");
  13. }
  14. use WHMCS\Database\Capsule;
  15. require_once dirname(__FILE__) . '/zimbraSingle.inc';
  16. function zimbraSingle_TestConnection($params)
  17. {
  18. $auth = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
  19. $login = $auth->login();
  20. if(is_a($login, "Exception")) {
  21. logModuleCall(
  22. 'zimbrasingle',
  23. __FUNCTION__,
  24. $params,
  25. "Connection test to " . $params['serverip'] . " failed: Cannot login",
  26. $login->getMessage()
  27. );
  28. return array(
  29. 'success' => false,
  30. 'error' => "Connection test to " . $params['serverip'] . " failed, the error was: " . $login->getMessage(),
  31. );
  32. } else {
  33. return array(
  34. 'success' => true,
  35. 'error' => '',
  36. );
  37. }
  38. }
  39. function zimbraSingle_ClientArea($params)
  40. {
  41. $response = zimbraSingleClientArea($params['customfields']);
  42. return array(
  43. 'templatefile' => 'clientarea',
  44. 'vars' => $response,
  45. );
  46. }
  47. function zimbraSingle_ChangePassword($params)
  48. {
  49. if (defined('CLIENTAREA')) {
  50. $params['customfields']['password'] = $params['password'];
  51. $params['customfields']['pwrepeat'] = $params['password'];
  52. $customFieldIDsObj = Capsule::table('tblcustomfields')
  53. ->select('id')
  54. ->where('relid', '=', $params['pid'])
  55. ->where('fieldtype', '=', 'password')
  56. ->get();
  57. $customFieldIDs = $customFieldIDsObj->toArray();
  58. logModuleCall(
  59. 'zimbrasingle',
  60. __FUNCTION__,
  61. $customFieldIDs[0]['id'],
  62. "Debug",
  63. $customFieldIDs[1]['id']
  64. );
  65. $customfields = array(
  66. '399' => $params['password'],
  67. '400' => $params['password']
  68. );
  69. $postData = array(
  70. 'serviceid' => $params['serviceid'],
  71. 'customfields' => base64_encode(serialize($customfields)),
  72. );
  73. $results = localAPI('UpdateClientProduct', $postData);
  74. $response = zimbraSingleChangePassword($params['customfields'], 'no');
  75. } else {
  76. $response = zimbraSingleChangePassword($params['customfields'], 'yes');
  77. }
  78. if($response == 'success') {
  79. return 'success';
  80. }
  81. return $response;
  82. }
  83. function zimbraSingle_CreateAccount($params)
  84. {
  85. $response = zimbraSingleCreateAccount($params['customfields']);
  86. if($response) {
  87. return 'success';
  88. }
  89. return 'Error creating account';
  90. }
  91. function zimbraSingle_SuspendAccount($params)
  92. {
  93. $response = zimbraSingleSuspendAccount($params['customfields']);
  94. if($response) {
  95. return 'success';
  96. }
  97. return 'Error suspending account';
  98. }
  99. function zimbraSingle_UnsuspendAccount($params)
  100. {
  101. $response = zimbraSingleUnsuspendAccount($params['customfields']);
  102. if($response) {
  103. return 'success';
  104. }
  105. return 'Error unsuspending account';
  106. }
  107. function zimbraSingle_TerminateAccount($params)
  108. {
  109. $response = zimbraSingleDeleteAccount($params['customfields']);
  110. if($response == 'success') {
  111. return 'success';
  112. }
  113. return $response;
  114. }
  115. function zimbraSingle_ChangePackage($params)
  116. {
  117. $response = zimbraSingleChangePackage($params['customfields']);
  118. if($response) {
  119. return 'success';
  120. }
  121. return 'Error changing package';
  122. }
  123. function zimbraSingle_ConfigOptions($params)
  124. {
  125. if(isset($_POST['packageconfigoption'])) {
  126. zimbraSingleCreateCustomFields($_POST['packageconfigoption']);
  127. }
  128. $response = zimbraSingleConfigOptions($params);
  129. if($response) {
  130. return $response;
  131. }
  132. return 'Error setting config options';
  133. }
  134. function zimbraSingle_genUsername($name)
  135. {
  136. /* $namelen = strlen($name);
  137. $result = select_query("tblhosting","COUNT(*)",array("username" => $name));
  138. $data = mysql_fetch_array($result);
  139. $username_exists = $data[0];
  140. $suffix=0;
  141. while ($username_exists > 0) {
  142. $suffix++;
  143. $name = substr($name,0,$namelen).$suffix;
  144. $result = select_query( "tblhosting", "COUNT(*)", array( "username" => $name ) );
  145. $data = mysql_fetch_array($result);
  146. $username_exists = $data[0];
  147. }
  148. return $name; */
  149. }