zimbraSingle.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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'] = localAPI('EncryptPassword', array('password2' => $params['password']));
  50. $params['customfields']['pwrepeat'] = localAPI('EncryptPassword', array('password2' => $params['password']));
  51. }
  52. $response = zimbraSingleChangePassword($params['customfields']);
  53. if($response == 'success') {
  54. return 'success';
  55. }
  56. return $response;
  57. }
  58. function zimbraSingle_CreateAccount($params)
  59. {
  60. $response = zimbraSingleCreateAccount($params['customfields']);
  61. if($response) {
  62. return 'success';
  63. }
  64. return 'Error creating account';
  65. }
  66. function zimbraSingle_SuspendAccount($params)
  67. {
  68. $response = zimbraSingleSuspendAccount($params['customfields']);
  69. if($response) {
  70. return 'success';
  71. }
  72. return 'Error suspending account';
  73. }
  74. function zimbraSingle_UnsuspendAccount($params)
  75. {
  76. $response = zimbraSingleUnsuspendAccount($params['customfields']);
  77. if($response) {
  78. return 'success';
  79. }
  80. return 'Error unsuspending account';
  81. }
  82. function zimbraSingle_TerminateAccount($params)
  83. {
  84. $response = zimbraSingleDeleteAccount($params['customfields']);
  85. if($response == 'success') {
  86. return 'success';
  87. }
  88. return $response;
  89. }
  90. function zimbraSingle_ChangePackage($params)
  91. {
  92. $response = zimbraSingleChangePackage($params['customfields']);
  93. if($response) {
  94. return 'success';
  95. }
  96. return 'Error changing package';
  97. }
  98. function zimbraSingle_ConfigOptions($params)
  99. {
  100. if(isset($_POST['packageconfigoption'])) {
  101. zimbraSingleCreateCustomFields($_POST['packageconfigoption']);
  102. }
  103. $response = zimbraSingleConfigOptions($params);
  104. if($response) {
  105. return $response;
  106. }
  107. return 'Error setting config options';
  108. }
  109. function zimbraSingle_genUsername($name)
  110. {
  111. /* $namelen = strlen($name);
  112. $result = select_query("tblhosting","COUNT(*)",array("username" => $name));
  113. $data = mysql_fetch_array($result);
  114. $username_exists = $data[0];
  115. $suffix=0;
  116. while ($username_exists > 0) {
  117. $suffix++;
  118. $name = substr($name,0,$namelen).$suffix;
  119. $result = select_query( "tblhosting", "COUNT(*)", array( "username" => $name ) );
  120. $data = mysql_fetch_array($result);
  121. $username_exists = $data[0];
  122. }
  123. return $name; */
  124. }