zimbraSingle.php 4.5 KB

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