zimbraSingle.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. require_once dirname(__FILE__) . '/zimbraSingle.inc';
  15. function zimbraSingle_TestConnection($params)
  16. {
  17. $auth = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
  18. $login = $auth->login();
  19. if(is_a($login, "Exception")) {
  20. logModuleCall(
  21. 'zimbrasingle',
  22. __FUNCTION__,
  23. $params,
  24. "Connection test to " . $params['serverip'] . " failed: Cannot login",
  25. $login->getMessage()
  26. );
  27. return array(
  28. 'success' => false,
  29. 'error' => "Connection test to " . $params['serverip'] . " failed, the error was: " . $login->getMessage(),
  30. );
  31. } else {
  32. return array(
  33. 'success' => true,
  34. 'error' => '',
  35. );
  36. }
  37. }
  38. function zimbraSingle_ClientArea($params)
  39. {
  40. $response = zimbraSingleClientArea($params['customfields']);
  41. return array(
  42. 'templatefile' => 'clientarea',
  43. 'vars' => $response,
  44. );
  45. }
  46. function zimbraSingle_ChangePassword($params)
  47. {
  48. if (defined('CLIENTAREA')) {
  49. $params['customfields']['password'] = $params['password'];
  50. $params['customfields']['pwrepeat'] = $params['password'];
  51. $clientFields = Client::find($userID)->customFieldValues;
  52. logModuleCall(
  53. 'zimbrasingle',
  54. __FUNCTION__,
  55. $userID,
  56. "Debug",
  57. $clientFields
  58. );
  59. $customfields = array(
  60. 'password' => $params['password'],
  61. '400' => $params['password']
  62. );
  63. $postData = array(
  64. 'serviceid' => $params['serviceid'],
  65. 'customfields' => base64_encode(serialize($customfields)),
  66. );
  67. $results = localAPI('UpdateClientProduct', $postData);
  68. logModuleCall(
  69. 'zimbrasingle',
  70. __FUNCTION__,
  71. $postData,
  72. "Debug",
  73. $results
  74. );
  75. $response = zimbraSingleChangePassword($params['customfields'], 'no');
  76. } else {
  77. $response = zimbraSingleChangePassword($params['customfields'], 'yes');
  78. }
  79. if($response == 'success') {
  80. return 'success';
  81. }
  82. return $response;
  83. }
  84. function zimbraSingle_CreateAccount($params)
  85. {
  86. $response = zimbraSingleCreateAccount($params['customfields']);
  87. if($response) {
  88. return 'success';
  89. }
  90. return 'Error creating account';
  91. }
  92. function zimbraSingle_SuspendAccount($params)
  93. {
  94. $response = zimbraSingleSuspendAccount($params['customfields']);
  95. if($response) {
  96. return 'success';
  97. }
  98. return 'Error suspending account';
  99. }
  100. function zimbraSingle_UnsuspendAccount($params)
  101. {
  102. $response = zimbraSingleUnsuspendAccount($params['customfields']);
  103. if($response) {
  104. return 'success';
  105. }
  106. return 'Error unsuspending account';
  107. }
  108. function zimbraSingle_TerminateAccount($params)
  109. {
  110. $response = zimbraSingleDeleteAccount($params['customfields']);
  111. if($response == 'success') {
  112. return 'success';
  113. }
  114. return $response;
  115. }
  116. function zimbraSingle_ChangePackage($params)
  117. {
  118. $response = zimbraSingleChangePackage($params['customfields']);
  119. if($response) {
  120. return 'success';
  121. }
  122. return 'Error changing package';
  123. }
  124. function zimbraSingle_ConfigOptions($params)
  125. {
  126. if(isset($_POST['packageconfigoption'])) {
  127. zimbraSingleCreateCustomFields($_POST['packageconfigoption']);
  128. }
  129. $response = zimbraSingleConfigOptions($params);
  130. if($response) {
  131. return $response;
  132. }
  133. return 'Error setting config options';
  134. }
  135. function zimbraSingle_genUsername($name)
  136. {
  137. /* $namelen = strlen($name);
  138. $result = select_query("tblhosting","COUNT(*)",array("username" => $name));
  139. $data = mysql_fetch_array($result);
  140. $username_exists = $data[0];
  141. $suffix=0;
  142. while ($username_exists > 0) {
  143. $suffix++;
  144. $name = substr($name,0,$namelen).$suffix;
  145. $result = select_query( "tblhosting", "COUNT(*)", array( "username" => $name ) );
  146. $data = mysql_fetch_array($result);
  147. $username_exists = $data[0];
  148. }
  149. return $name; */
  150. }