zimbraSingle.php.1 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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_UsageUpdate($params)
  39. {
  40. }
  41. function zimbraSingle_ClientArea($params)
  42. {
  43. // error_log(print_r($params,true));
  44. # error_log("CLIENT-AREA");
  45. # $zimbraSingleURL = buildzimbraSingleURL($params);
  46. # $user = $params['username'];
  47. # $result0 = select_query("tblconfiguration","value" , array('setting' => 'Language'));
  48. # $data0 = mysql_fetch_array($result0);
  49. # $lla = ($_SESSION['Language']) ? trim($_SESSION['Language']) : strtolower($data0[0]);
  50. # $slang = array();
  51. # include_once dirname(__FILE__).'/lang/'.$lla.'.php';
  52. # return array(
  53. # 'templatefile' => 'clientside',
  54. # 'vars' => array_merge(array(
  55. # 'url' => $seafileURL,
  56. # 'user' => $user,
  57. # 'mobile1' => $app,
  58. # 'mobile2' => $google,
  59. # 'drivewin' => $driveWin,
  60. # 'winclient' => $winClient,
  61. # 'macclient' => $macClient,
  62. # 'drivemac' => $driveMac,
  63. # 'linClient' => $linClient,
  64. # ), $slang, $params),
  65. # );
  66. }
  67. function zimbraSingle_ClientAreaCustomButtonArray()
  68. {
  69. $buttonarray = array(
  70. "Reset Password" => "ClientPassword",
  71. );
  72. return $buttonarray;
  73. }
  74. function zimbraSingle_ChangePassword($params)
  75. {
  76. # if (strcmp($params['status'],"Active") !== 0) {
  77. # return "Der Dienst ist gesperrt, das Passwort kann daher nicht geändert werden";
  78. # }
  79. # $loginPassword = $params["customfields"]["Passwort"];
  80. # $checkPassword = checkPassword($loginPassword);
  81. # if ($checkPassword != null) {
  82. # return $checkPassword;
  83. # }
  84. # $fieldID = getCustomFieldIDFor($params,"Passwort");
  85. #
  86. # $seafileURL = buildSeafileURL($params);
  87. # $apiuser = getSeafileAdminUser($params);
  88. # $apipass = getSeafileAdminPassword($params);
  89. #
  90. # $seafileAPI = new SeafileAPI($seafileURL,$apiuser,$apipass);
  91. # if ($seafileAPI->login() != true) {
  92. # logModuleCall(
  93. # 'seafile',
  94. # __FUNCTION__,
  95. # $params,
  96. # "Cannot login to " . $seafileURL,
  97. # ""
  98. # );
  99. # return "Login to " . $seafileURL . " fehlgeschlagen. Bitte den Administrator informieren.\n";
  100. # }
  101. #
  102. # $userAccount = $seafileAPI->getAccountByEMail($params['username']);
  103. # if ($userAccount != null) {
  104. # $userAccount->password = $loginPassword;
  105. # try {
  106. # $result = $seafileAPI->updateAccount($userAccount);
  107. # if ($result != true) {
  108. # logModuleCall(
  109. # 'seafile',
  110. # __FUNCTION__,
  111. # $params,
  112. # "Cannot change password for " . $userAccount->email . ": Unknown error",
  113. # ""
  114. # );
  115. # return "Das Passwort konnte nicht aktualisiert werden. Unbekannter Fehler.";
  116. # } else {
  117. # update_query( "tblcustomfieldsvalues",array( "value" => $loginPassword,"updated_at"=> "now()", ),array("id" => $fieldID) );
  118. # logModuleCall(
  119. # 'seafile',
  120. # __FUNCTION__,
  121. # $params,
  122. # "Changed password for " . $userAccount->email,
  123. # ""
  124. # );
  125. # return 'success';
  126. # }
  127. # } catch (Exception $exe) {
  128. # logModuleCall(
  129. # 'seafile',
  130. # __FUNCTION__,
  131. # $params,
  132. # "Cannot change password for " . $userAccount->email . ", the error was " . $exe->getMessage(),
  133. # $exe->getTraceAsString()
  134. # );
  135. # return "Fehler beim Update des Passworts, der Fehler war: " . $exe->getMessage();
  136. # }
  137. # } else {
  138. # logModuleCall(
  139. # 'seafile',
  140. # __FUNCTION__,
  141. # $params,
  142. # "Changed password for " . $userAccount->email,
  143. # ""
  144. # );
  145. # return "Konnte den Account " . $params['username'] . " auf dem Server nicht finden";
  146. # }
  147. }
  148. function zimbraSingle_ClientPassword($params)
  149. {
  150. /* if (strcmp($params['status'],"Active") !== 0) {
  151. return "Der Dienst ist gesperrt, das Passwort kann daher nicht geändert werden";
  152. }
  153. $password1 = $_POST['password1'];
  154. $password2 = $_POST['password2'];
  155. if (empty($password1) == true || empty($password2) == true) {
  156. return "Bitte beide Passwörter zuerst ausfüllen";
  157. }
  158. if (strcmp($password1,$password2) !== 0) {
  159. return "Die Passwörter stimmen nicht überein";
  160. }
  161. $checkPassword = checkPassword($password1);
  162. if ($checkPassword != null) {
  163. return $checkPassword;
  164. }
  165. $fieldID = getCustomFieldIDFor($params,"Passwort");
  166. $seafileURL = buildSeafileURL($params);
  167. $apiuser = getSeafileAdminUser($params);
  168. $apipass = getSeafileAdminPassword($params);
  169. $seafileAPI = new SeafileAPI($seafileURL,$apiuser,$apipass);
  170. if ($seafileAPI->login() != true) {
  171. logModuleCall(
  172. 'seafile',
  173. __FUNCTION__,
  174. $params,
  175. "Cannot login to " . $seafileURL,
  176. ""
  177. );
  178. return "Login to " . $seafileURL . " fehlgeschlagen. Bitte den Administrator informieren.\n";
  179. }
  180. $userAccount = $seafileAPI->getAccountByEMail($params['username']);
  181. if ($userAccount != null) {
  182. $userAccount->password = $password1;
  183. try {
  184. $result = $seafileAPI->updateAccount($userAccount);
  185. if ($result != true) {
  186. return "Das Passwort konnte nicht aktualisiert werden. Unbekannter Fehler.";
  187. } else {
  188. update_query( "tblcustomfieldsvalues",array( "value" => $password1,"updated_at"=> "now()", ),array("id" => $fieldID) );
  189. return 'success';
  190. }
  191. } catch (Exception $exe) {
  192. logModuleCall(
  193. 'seafile',
  194. __FUNCTION__,
  195. $params,
  196. "Cannot change password for " . $userAccount->email . ", the error was " . $exe->getMessage(),
  197. $exe->getTraceAsString()
  198. );
  199. return "Fehler beim Update des Passworts, der Fehler war: " . $exe->getMessage();
  200. }
  201. } else {
  202. logModuleCall(
  203. 'seafile',
  204. __FUNCTION__,
  205. $params,
  206. "Cannot find the Account " . $params['username'],
  207. ""
  208. );
  209. return "Konnte den Account " . $params['username'] . " nicht finden";
  210. } */
  211. }
  212. function zimbraSingle_CreateAccount($params)
  213. {
  214. $response = zimbraSingleCreateAccount($params['customfields']);
  215. if($response) {
  216. return 'success';
  217. }
  218. return 'Error creating account';
  219. }
  220. function zimbraSingle_SuspendAccount($params)
  221. {
  222. $response = zimbraSingleSuspendAccount($params['customfields']);
  223. if($response) {
  224. return 'success';
  225. }
  226. return 'Error suspending account';
  227. }
  228. function zimbraSingle_UnsuspendAccount($params)
  229. {
  230. $response = zimbraSingleUnsuspendAccount($params['customfields']);
  231. if($response) {
  232. return 'success';
  233. }
  234. return 'Error unsuspending account';
  235. }
  236. function zimbraSingle_TerminateAccount($params)
  237. {
  238. return zimbraSingleDeleteAccount($params['customfields']);
  239. }
  240. function zimbraSingle_genUsername($name)
  241. {
  242. /* $namelen = strlen($name);
  243. $result = select_query("tblhosting","COUNT(*)",array("username" => $name));
  244. $data = mysql_fetch_array($result);
  245. $username_exists = $data[0];
  246. $suffix=0;
  247. while ($username_exists > 0) {
  248. $suffix++;
  249. $name = substr($name,0,$namelen).$suffix;
  250. $result = select_query( "tblhosting", "COUNT(*)", array( "username" => $name ) );
  251. $data = mysql_fetch_array($result);
  252. $username_exists = $data[0];
  253. }
  254. return $name; */
  255. }
  256. function zimbraSingle_getCustomFieldIDFor($params, $fieldName)
  257. {
  258. $Client = Client::find($params['userid']);
  259. $clientFields = $Client->customFieldValues;
  260. foreach ($Client->services as $service) {
  261. //print "ServiceID: " . $service->id . " ?= " . $params['serviceid'] . " <br />";
  262. // print nl2br(print_r($service,true));
  263. if ($service->packageid == $params['packageid']) {
  264. //print " => PackageID found <br />";
  265. $serviceFields = $service->customFieldValues;
  266. //print nl2br(print_r($serviceFields,true));
  267. foreach ($serviceFields as $field) {
  268. //print " ===> " . $field->customField->fieldName . " : " . $field->id . "</br />";
  269. //print " Field: " . $field->customField->fieldName . " ?= Search Field Name: " . $fieldName . " ? " . strcmp($field->customField->fieldName,$fieldName) . " : " . $field->id . " : " . $field->fieldid . "<br />";
  270. if (strcmp($field->customField->fieldName, $fieldName) == 0) {
  271. return $field->id;
  272. }
  273. }
  274. }
  275. }
  276. return -1;
  277. /*
  278. **** TESTING METHODS ****
  279. Please do not remove this lines
  280. // run through customfields
  281. foreach($clientFields AS $field){
  282. $HTML .= "Field ".$field->customField->fieldName.": ".$field->value."<br>";
  283. }
  284. return "";
  285. $HTML .= "Service custom fields";
  286. foreach($Client->services as $service) {
  287. $HTML .= "----------------------------------------------------------<br />";
  288. $HTML .= nl2br(print_r($service,true));
  289. $HTML .= "----------------------------------------------------------<br />";
  290. $ServiceFields = $service->customFieldValues;
  291. foreach($ServiceFields as $field) {
  292. //$HTML .= "Service field ".$field->customField->fieldName . ": ".$field->value."<br>";
  293. //$HTML .= "----------------------------------------------------------<br />";
  294. //$HTML .= nl2br(print_r($field,true));
  295. //$HTML .= "Service field ".$field->customField->fieldName . "( FieldID: " . $field->fieldid . "/ ID: " . $field->id . "/ RelID:" . $field->relid . ") : " . $field->value . "<br>";
  296. //$HTML .= "----------------------------------------------------------<br />";
  297. }
  298. }
  299. */
  300. }