zimbraSingle.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. $customfields = array(
  52. '399' => $params['password'],
  53. '400' => $params['password']
  54. );
  55. $postData = array(
  56. 'serviceid' => $params['serviceid'],
  57. 'customfields' => base64_encode(serialize($customfields)),
  58. );
  59. $results = localAPI('UpdateClientProduct', $postData);
  60. logModuleCall(
  61. 'zimbrasingle',
  62. __FUNCTION__,
  63. $postData,
  64. "Debug",
  65. $results
  66. );
  67. $response = zimbraSingleChangePassword($params['customfields'], 'no');
  68. } else {
  69. $response = zimbraSingleChangePassword($params['customfields'], 'yes');
  70. }
  71. if($response == 'success') {
  72. return 'success';
  73. }
  74. return $response;
  75. }
  76. function zimbraSingle_CreateAccount($params)
  77. {
  78. $response = zimbraSingleCreateAccount($params['customfields']);
  79. if($response) {
  80. return 'success';
  81. }
  82. return 'Error creating account';
  83. }
  84. function zimbraSingle_SuspendAccount($params)
  85. {
  86. $response = zimbraSingleSuspendAccount($params['customfields']);
  87. if($response) {
  88. return 'success';
  89. }
  90. return 'Error suspending account';
  91. }
  92. function zimbraSingle_UnsuspendAccount($params)
  93. {
  94. $response = zimbraSingleUnsuspendAccount($params['customfields']);
  95. if($response) {
  96. return 'success';
  97. }
  98. return 'Error unsuspending account';
  99. }
  100. function zimbraSingle_TerminateAccount($params)
  101. {
  102. $response = zimbraSingleDeleteAccount($params['customfields']);
  103. if($response == 'success') {
  104. return 'success';
  105. }
  106. return $response;
  107. }
  108. function zimbraSingle_ChangePackage($params)
  109. {
  110. $response = zimbraSingleChangePackage($params['customfields']);
  111. if($response) {
  112. return 'success';
  113. }
  114. return 'Error changing package';
  115. }
  116. function zimbraSingle_ConfigOptions($params)
  117. {
  118. if(isset($_POST['packageconfigoption'])) {
  119. zimbraSingleCreateCustomFields($_POST['packageconfigoption']);
  120. }
  121. $response = zimbraSingleConfigOptions($params);
  122. if($response) {
  123. return $response;
  124. }
  125. return 'Error setting config options';
  126. }
  127. function zimbraSingle_genUsername($name)
  128. {
  129. /* $namelen = strlen($name);
  130. $result = select_query("tblhosting","COUNT(*)",array("username" => $name));
  131. $data = mysql_fetch_array($result);
  132. $username_exists = $data[0];
  133. $suffix=0;
  134. while ($username_exists > 0) {
  135. $suffix++;
  136. $name = substr($name,0,$namelen).$suffix;
  137. $result = select_query( "tblhosting", "COUNT(*)", array( "username" => $name ) );
  138. $data = mysql_fetch_array($result);
  139. $username_exists = $data[0];
  140. }
  141. return $name; */
  142. }