zimbraSingle.php 4.3 KB

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