zimbraSingle.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. <?php
  2. /**
  3. * WHMCS Zimbra Provisioning Module
  4. *
  5. * Provisioning for private mailboxes on a 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. /**
  16. * Requires this PHP api to make soap calls and parse responses
  17. * This is an extend version of:
  18. * @see https://github.com/alloylab/zimbra-admin-api-soap-php
  19. */
  20. require_once("api/Zm/Auth.php");
  21. require_once("api/Zm/Account.php");
  22. require_once("api/Zm/Domain.php");
  23. require_once("api/Zm/Server.php");
  24. /**
  25. * Helper function to get the zimbra server access data from whmcs database
  26. *
  27. * @return array $accessData {
  28. * @type string 'zimbraServer' zimbra server IP address
  29. * @type string 'adminUser' zimbra admin username
  30. * @type string 'password' zimbra admin password
  31. * } or false in case of error
  32. */
  33. function zimbraSingleGetAccess()
  34. {
  35. $accessData = array('zimbraServer' => '', 'adminUser' => '', 'adminPass' => '');
  36. $whmcs = App::self();
  37. $serverGroupID = $whmcs->get_req_var('servergroup');
  38. $action = $whmcs->get_req_var('action');
  39. if(($action == 'module-settings') || ($action == 'ConfigOptions') || ($action == 'save')) {
  40. $productID = $whmcs->get_req_var('id');
  41. $serverGroupIDObj = Capsule::table('tblproducts')
  42. ->select('servergroup')
  43. ->where('id', '=', $productID)
  44. ->get();
  45. $serverGroupID = $serverGroupIDObj[0]->servergroup;
  46. $serverIDObj = Capsule::table('tblservergroupsrel')
  47. ->select('serverid')
  48. ->where('groupid', '=', $serverGroupID)
  49. ->get();
  50. $serverID = $serverIDObj[0]->serverid;
  51. } else {
  52. $id = $whmcs->get_req_var('id');
  53. $serverIDObj = Capsule::table('tblhosting')
  54. ->select('server')
  55. ->where('id', '=', $id)
  56. ->get();
  57. $serverID = $serverIDObj[0]->server;
  58. }
  59. $server = Capsule::table('tblservers')
  60. ->select('ipaddress', 'username', 'password')
  61. ->where('id', '=', $serverID)
  62. ->where('active', '=', 1)
  63. ->get();
  64. $accessData['zimbraServer'] = $server[0]->ipaddress;
  65. $accessData['adminUser'] = $server[0]->username;
  66. $adminPassCrypt = $server[0]->password;
  67. $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $adminPassCrypt));
  68. if ($adminPassDecrypt['result'] == 'success') {
  69. $accessData['adminPass'] = $adminPassDecrypt['password'];
  70. } else {
  71. logModuleCall(
  72. 'zimbrasingle',
  73. __FUNCTION__,
  74. $adminPassCrypt,
  75. "Error: cloud not decrypt admin password" ,
  76. $adminPassDecrypt
  77. );
  78. return false;
  79. }
  80. return $accessData;
  81. }
  82. /**
  83. * Helper function to find values of a named key in a multidimensional arrays
  84. *
  85. * @param array $haystack mixed data
  86. * @param string $needle key to search for values
  87. * @return array of values
  88. */
  89. function recursiveFindAll($haystack, $needle)
  90. {
  91. $values = array();
  92. $iterator = new RecursiveArrayIterator($haystack);
  93. $recursive = new RecursiveIteratorIterator(
  94. $iterator,
  95. RecursiveIteratorIterator::SELF_FIRST
  96. );
  97. foreach ($recursive as $key => $value) {
  98. if ($key === $needle) {
  99. array_push($values, $value);
  100. }
  101. }
  102. return $values;
  103. }
  104. /**
  105. * Helper function to check a password strength
  106. *
  107. * @param string $pwd password to check
  108. * @return string $message what is missing in the password (empty if it is okay)
  109. */
  110. function zimbraSingleCheckPassword($pwd)
  111. {
  112. $message = '';
  113. if (strlen($pwd) < 8) {
  114. $message .= "Das das Passwort ist zu kurz. Es werden mind. 8 Zeichen benötigt" . PHP_EOL;
  115. }
  116. if (!preg_match("#[0-9]+#", $pwd)) {
  117. $message .= "Das Passwort muss mindestens eine Zahl enthalten" . PHP_EOL;
  118. }
  119. if (!preg_match("#[A-Z]+#", $pwd)) {
  120. $message .= "Das Passwort muss mindestens einen Grossbuchstaben (A-Z) enthalten" . PHP_EOL;
  121. }
  122. if (!preg_match("#[a-z]+#", $pwd)) {
  123. $message .= "Das Passwort muss mindestens einen Kleinbuchstaben (a-z) enthalten" . PHP_EOL;
  124. }
  125. if (!preg_match("#[^\w]+#", $pwd)) {
  126. $message .= "Das Passwort muss mindestens ein Sonderzeichen (.,-:=) enthalten" . PHP_EOL;
  127. }
  128. return $message;
  129. }
  130. /**
  131. * Convert raw byte value to human readable
  132. *
  133. * Helper function to convert byte in huam readable format
  134. *
  135. * @param int $bytes value in bytes
  136. * @return string value rounded and in human readable units
  137. */
  138. function bytesToHuman($bytes)
  139. {
  140. $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
  141. for ($i = 0; $bytes > 1024; $i++) $bytes /= 1024;
  142. return round($bytes, 2) . ' ' . $units[$i];
  143. }
  144. /**
  145. * Define module related meta data.
  146. *
  147. * Values returned here are used to determine module related abilities and
  148. * settings.
  149. *
  150. * @see https://developers.whmcs.com/provisioning-modules/meta-data-params/
  151. *
  152. * @return array
  153. */
  154. function zimbraSingle_MetaData()
  155. {
  156. return array(
  157. 'DisplayName' => 'Zimbra Single Mailbox Provisioning',
  158. 'APIVersion' => '1.2',
  159. 'DefaultNonSSLPort' => '7071',
  160. 'DefaultSSLPort' => '7071',
  161. 'RequiresServer' => true,
  162. 'ServiceSingleSignOnLabel' => 'Login to Zimbra',
  163. 'AdminSingleSignOnLabel' => 'Login to Zimbra Admin'
  164. );
  165. }
  166. /**
  167. * Test connection to a Zimbra server with the given server parameters.
  168. *
  169. * Allows an admin user to verify that an API connection can be
  170. * successfully made with the given configuration parameters for a
  171. * server.
  172. *
  173. * When defined in a module, a Test Connection button will appear
  174. * alongside the Server Type dropdown when adding or editing an
  175. * existing server.
  176. *
  177. * @param array $params common module parameters
  178. *
  179. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  180. *
  181. * @return array
  182. */
  183. function zimbraSingle_TestConnection($params)
  184. {
  185. $auth = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
  186. $login = $auth->login();
  187. if(is_a($login, "Exception")) {
  188. logModuleCall(
  189. 'zimbrasingle',
  190. __FUNCTION__,
  191. $params,
  192. "Connection test to " . $params['serverip'] . " failed: Cannot login",
  193. $login->getMessage()
  194. );
  195. return array(
  196. 'success' => false,
  197. 'error' => "Connection test to " . $params['serverip'] . " failed, the error was: " . $login->getMessage(),
  198. );
  199. } else {
  200. return array(
  201. 'success' => true,
  202. 'error' => '',
  203. );
  204. }
  205. }
  206. /**
  207. * Client area output logic handling.
  208. *
  209. * This function is used to define module specific client area output. It should
  210. * return an array consisting of a template file and optional additional
  211. * template variables to make available to that template.
  212. *
  213. * The template file you return can be one of two types:
  214. *
  215. * * tabOverviewModuleOutputTemplate - The output of the template provided here
  216. * will be displayed as part of the default product/service client area
  217. * product overview page.
  218. *
  219. * * tabOverviewReplacementTemplate - Alternatively using this option allows you
  220. * to entirely take control of the product/service overview page within the
  221. * client area.
  222. *
  223. * Whichever option you choose, extra template variables are defined in the same
  224. * way. This demonstrates the use of the full replacement.
  225. *
  226. * Please Note: Using tabOverviewReplacementTemplate means you should display
  227. * the standard information such as pricing and billing details in your custom
  228. * template or they will not be visible to the end user.
  229. *
  230. * @param array $params common module parameters
  231. *
  232. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  233. *
  234. * @return array
  235. */
  236. function zimbraSingle_ClientArea($params)
  237. {
  238. $clientInfo = array();
  239. $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
  240. $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
  241. $login = $api->login();
  242. if(is_a($login, "Exception")) {
  243. logModuleCall(
  244. 'zimbrasingle',
  245. __FUNCTION__,
  246. $params,
  247. "Error: cannot login to " . $accessData['zimbraServer'],
  248. $login
  249. );
  250. return false;
  251. }
  252. $apiAccountManager = new Zm_Account($api);
  253. $response = $apiAccountManager->getAccountInfo($accountName);
  254. if(is_a($response, "Exception")) {
  255. logModuleCall(
  256. 'zimbrasingle',
  257. __FUNCTION__,
  258. $params,
  259. "Error: could not gather informations for $accountName",
  260. $response
  261. );
  262. return false;
  263. }
  264. $webmailUrl = recursiveFindAll( $response, 'PUBLICMAILURL');
  265. $clientInfo['webmailurl'] = $webmailUrl[0]['DATA'];
  266. return array(
  267. 'templatefile' => 'clientarea',
  268. 'vars' => $clientInfo,
  269. );
  270. }
  271. function zimbraSingle_UsageUpdate($params) {
  272. $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
  273. $login = $api->login();
  274. if(is_a($login, "Exception")) {
  275. logModuleCall(
  276. 'zimbrasingle',
  277. __FUNCTION__,
  278. $params,
  279. "Error: cannot login to " . $params['serverip'],
  280. $login->getMessage()
  281. );
  282. return false;
  283. }
  284. $apiAccountManager = new Zm_Account($api);
  285. $productsObj = Capsule::table('tblhosting')
  286. ->select('*')
  287. ->where('server', '=', $params['serverid'])
  288. ->where('domainstatus', '=', 'Active')
  289. ->get();
  290. foreach((array)$productsObj as $productObj) {
  291. $product = get_object_vars($productObj[0]);
  292. $quota = $apiAccountManager->getQuota($product['username']);
  293. if(is_a($quota, "Exception")) {
  294. logModuleCall(
  295. 'zimbrasingle',
  296. __FUNCTION__,
  297. $product,
  298. "Error : could not find " . $product['username'],
  299. $quota->getMessage()
  300. );
  301. }
  302. $response = $apiAccountManager->getMailbox($product['username']);
  303. if(is_a($response, "Exception")) {
  304. logModuleCall(
  305. 'zimbrasingle',
  306. __FUNCTION__,
  307. $params,
  308. "Error: could not fetch mailbox info for " . $product['username'],
  309. $response->getMessage()
  310. );
  311. }
  312. $mbox = get_object_vars($response);
  313. $mboxSize = $mbox['S'];
  314. Capsule::table('tblhosting')
  315. ->where('id', '=', $product['id'])
  316. ->update(
  317. array(
  318. 'diskusage' => round($mboxSize / 1048576,2),
  319. 'disklimit' => round($quota / 1048576,2),
  320. 'lastupdate' => Capsule::raw('now()')
  321. )
  322. );
  323. }
  324. }
  325. /**
  326. * Change the password for a Zimbra account.
  327. *
  328. * Called when a password change is requested. This can occur either due to a
  329. * client requesting it via the client area or an admin requesting it from the
  330. * admin side.
  331. *
  332. * This option is only available to client end users when the product is in an
  333. * active status.
  334. *
  335. * @param array $params common module parameters
  336. *
  337. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  338. *
  339. * @return string "success" or an error message
  340. */
  341. function zimbraSingle_ChangePassword($params)
  342. {
  343. $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
  344. $login = $api->login();
  345. if(is_a($login, "Exception")) {
  346. logModuleCall(
  347. 'zimbrasingle',
  348. __FUNCTION__,
  349. $params,
  350. "Error: cannot login to " . $accessData['zimbraServer'],
  351. $login
  352. );
  353. return false;
  354. }
  355. $apiAccountManager = new Zm_Account($api);
  356. $response = $apiAccountManager->setAccountPassword($accountName, $params['password']);
  357. if(is_a($response, "Exception")) {
  358. logModuleCall(
  359. 'zimbrasingle',
  360. __FUNCTION__,
  361. $params,
  362. "Error: password for $accountName could not be set",
  363. $response
  364. );
  365. return false;
  366. }
  367. return 'success';
  368. }
  369. /**
  370. * Provision a new instance of a Zimbra account.
  371. *
  372. * Attempt to provision a new Zimbra mail account. This is
  373. * called any time provisioning is requested inside of WHMCS. Depending upon the
  374. * configuration, this can be any of:
  375. * * When a new order is placed
  376. * * When an invoice for a new order is paid
  377. * * Upon manual request by an admin user
  378. *
  379. * @param array $params common module parameters
  380. *
  381. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  382. *
  383. * @return string "success" or an error message
  384. */
  385. function zimbraSingle_CreateAccount($params)
  386. {
  387. $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
  388. $login = $api->login();
  389. $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
  390. $apiAccountManager = new Zm_Account($api);
  391. $accountExists = $apiAccountManager->accountExists($accountName);
  392. if(is_a($accountExists, "Exception")) {
  393. logModuleCall(
  394. 'zimbrasingle',
  395. __FUNCTION__,
  396. $accessData,
  397. "Error: could not verify $accountName",
  398. $accountExists
  399. );
  400. return "Error: could not verify $accountName";
  401. }
  402. if($accountExists === true) {
  403. return "Error: account $accountName already exists";
  404. }
  405. $attrs = array();
  406. $attrs["gn"] = $params['customfields']["givenname"];
  407. $attrs["sn"] = $params['customfields']["sn"];
  408. $attrs["displayName"] = $attrs["gn"] . " " . $attrs["sn"];
  409. $passDecrypt = localAPI('DecryptPassword', array('password2' => $params['customfields']['password']));
  410. if ($passDecrypt['result'] == 'success') {
  411. $params['customfields']['password'] = $passDecrypt['password'];
  412. } else {
  413. logModuleCall(
  414. 'zimbrasingle',
  415. __FUNCTION__,
  416. $params['customfields']['password'],
  417. "Error: could not decrypt password",
  418. $passDecrypt
  419. );
  420. return "Error: could not decrypt password";
  421. }
  422. $cosID = $apiAccountManager->getCosId($params['configoption1']);
  423. if(is_a($cosID, "Exception")) {
  424. logModuleCall(
  425. 'zimbrasingle',
  426. __FUNCTION__,
  427. $params['configoption1'],
  428. "Error: serviceclass not available",
  429. $cosID
  430. );
  431. return "Error: serviceclass not available";
  432. }
  433. $attrs['zimbraCOSId'] = $cosID;
  434. $id = $apiAccountManager->createAccount($accountName, $params['customfields']['password'], $attrs);
  435. if(is_a($id, "Exception")) {
  436. logModuleCall(
  437. 'zimbrasingle',
  438. __FUNCTION__,
  439. $params,
  440. "Error: account $accountName not created",
  441. $id
  442. );
  443. return "Error: account $accountName not created";
  444. }
  445. return 'success';
  446. }
  447. /**
  448. * Set a Zimbra account to status locked.
  449. *
  450. * Called when a suspension is requested. This is invoked automatically by WHMCS
  451. * when a product becomes overdue on payment or can be called manually by admin
  452. * user.
  453. *
  454. * @param array $params common module parameters
  455. *
  456. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  457. *
  458. * @return string "success" or an error message
  459. */
  460. function zimbraSingle_SuspendAccount($params)
  461. {
  462. $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
  463. $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
  464. $login = $api->login();
  465. if(is_a($login, "Exception")) {
  466. logModuleCall(
  467. 'zimbrasingle',
  468. __FUNCTION__,
  469. $params,
  470. "Error: cannot login to " . $accessData['zimbraServer'],
  471. $login
  472. );
  473. return $login->getMessage();
  474. }
  475. $apiAccountManager = new Zm_Account($api);
  476. $response = $apiAccountManager->setAccountStatus($accountName, "locked");
  477. if(is_a($response, "Exception")) {
  478. logModuleCall(
  479. 'zimbrasingle',
  480. __FUNCTION__,
  481. $params,
  482. "Error: account $accountName could not locked",
  483. $response
  484. );
  485. return false;
  486. }
  487. return 'success';
  488. }
  489. /**
  490. * Set a Zimbra account to status active.
  491. *
  492. * Called when an un-suspension is requested. This is invoked
  493. * automatically upon payment of an overdue invoice for a product, or
  494. * can be called manually by admin user.
  495. *
  496. * @param array $params common module parameters
  497. *
  498. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  499. *
  500. * @return string "success" or an error message
  501. */
  502. function zimbraSingle_UnsuspendAccount($params)
  503. {
  504. $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
  505. $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
  506. $login = $api->login();
  507. if(is_a($login, "Exception")) {
  508. logModuleCall(
  509. 'zimbrasingle',
  510. __FUNCTION__,
  511. $params,
  512. "Error: cannot login to " . $accessData['zimbraServer'],
  513. $login
  514. );
  515. return $login->getMessage();
  516. }
  517. $apiAccountManager = new Zm_Account($api);
  518. $response = $apiAccountManager->setAccountStatus($accountName, "active");
  519. if(is_a($response, "Exception")) {
  520. logModuleCall(
  521. 'zimbrasingle',
  522. __FUNCTION__,
  523. $params,
  524. "Error: account $accountName could not unlocked",
  525. $response
  526. );
  527. return "Error: account $accountName could not unlocked";
  528. }
  529. return 'success';
  530. }
  531. /**
  532. * Removes a Zimbra account.
  533. *
  534. * Called when a termination is requested. This can be invoked automatically for
  535. * overdue products if enabled, or requested manually by an admin user.
  536. *
  537. * @param array $params common module parameters
  538. *
  539. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  540. *
  541. * @return string "success" or an error message
  542. */
  543. function zimbraSingle_TerminateAccount($params)
  544. {
  545. $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
  546. $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
  547. $login = $api->login();
  548. if(is_a($login, "Exception")) {
  549. logModuleCall(
  550. 'zimbrasingle',
  551. __FUNCTION__,
  552. $params,
  553. "Error: cannot login to " . $accessData['zimbraServer'],
  554. $login
  555. );
  556. return $login->getMessage();
  557. }
  558. $apiAccountManager = new Zm_Account($api);
  559. $response = $apiAccountManager->getAccountStatus($accountName);
  560. if(is_a($response, "Exception")) {
  561. logModuleCall(
  562. 'zimbrasingle',
  563. __FUNCTION__,
  564. $params,
  565. "Error: account $accountName could not verified",
  566. $response
  567. );
  568. return "Error : account $accountName could not verified";
  569. }
  570. if ($response != 'locked') {
  571. return "Account $accountName active, suspend account first!";
  572. }
  573. $response = $apiAccountManager->deleteAccount($accountName);
  574. if(is_a($response, "Exception")) {
  575. logModuleCall(
  576. 'zimbrasingle',
  577. __FUNCTION__,
  578. $params,
  579. "Error: account $accountName could not removed",
  580. $response
  581. );
  582. return "Error: account $accountName could not removed";
  583. }
  584. return 'success';
  585. }
  586. /**
  587. * Set a new class of service for a Zimbra account.
  588. *
  589. * Called to apply a change of the class of service. It
  590. * is called to provision upgrade or downgrade orders, as well as being
  591. * able to be invoked manually by an admin user.
  592. *
  593. * This same function is called for upgrades and downgrades of both
  594. * products and configurable options.
  595. *
  596. * @param array $params common module parameters
  597. *
  598. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  599. *
  600. * @return string "success" or an error message
  601. */
  602. function zimbraSingle_ChangePackage($params)
  603. {
  604. $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
  605. $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
  606. $login = $api->login();
  607. if(is_a($login, "Exception")) {
  608. logModuleCall(
  609. 'zimbrasingle',
  610. __FUNCTION__,
  611. $params,
  612. "Error: cannot login to " . $accessData['zimbraServer'],
  613. $login
  614. );
  615. return $login->getMessage();
  616. }
  617. $apiAccountManager = new Zm_Account($api);
  618. $response = $apiAccountManager->setAccountCos($accountName, $params['configoption1']);
  619. if(is_a($response, "Exception")) {
  620. logModuleCall(
  621. 'zimbrasingle',
  622. __FUNCTION__,
  623. $params,
  624. "Error: class of service for $accountName could not be set",
  625. $response
  626. );
  627. return "Error: class of service for $accountName could not be set";
  628. }
  629. return 'success';
  630. }
  631. /**
  632. * Define Zimbra product configuration options.
  633. *
  634. * Gather classes of service and available mail domains from the Zinbra server.
  635. * Calls a function to create all necessary customfields for the order form using the selected values.
  636. *
  637. * @see https://developers.whmcs.com/provisioning-modules/config-options/
  638. *
  639. * @return array
  640. */
  641. function zimbraSingle_ConfigOptions($params)
  642. {
  643. logModuleCall(
  644. 'zimbrasingle',
  645. __FUNCTION__,
  646. $params,
  647. "Debug",
  648. $whmcs
  649. );
  650. $accessData = zimbraSingleGetAccess();
  651. $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
  652. $login = $api->login();
  653. if(is_a($login, "Exception")) {
  654. logModuleCall(
  655. 'zimbrasingle',
  656. __FUNCTION__,
  657. $params,
  658. "Error: cannot login to " . $accessData['zimbraServer'],
  659. $login
  660. );
  661. return false;
  662. }
  663. $apiAccountManager = new Zm_Account($api);
  664. $response = $apiAccountManager->getAllCos();
  665. if(is_a($response, "Exception")) {
  666. logModuleCall(
  667. 'zimbrasingle',
  668. __FUNCTION__,
  669. $params,
  670. "Error: could not fetch classes of service",
  671. $response
  672. );
  673. return false;
  674. }
  675. $cosNames = recursiveFindAll($response, 'NAME');
  676. $configOptions = array();
  677. $configOptions['cos'] = array(
  678. "FriendlyName" => "Class of Service",
  679. "Type" => "dropdown",
  680. "Options" => implode(',', $cosNames),
  681. "Description" => "Select COS",
  682. );
  683. $apiDomainManager = new Zm_Domain($api);
  684. $response = $apiDomainManager->getAllDomains();
  685. if(is_a($response, "Exception")) {
  686. logModuleCall(
  687. 'zimbrasingle',
  688. __FUNCTION__,
  689. $params,
  690. "Error: could fetch available maildomains",
  691. $response
  692. );
  693. return false;
  694. }
  695. $domainNames = recursiveFindAll($response, 'NAME');
  696. $configOptions['maildomains'] = array(
  697. "FriendlyName" => "Mail Domain",
  698. "Type" => "dropdown",
  699. "Multiple" => true,
  700. "Options" => implode(',', $domainNames),
  701. "Description" => "Info: Available Maildomains",
  702. );
  703. return $configOptions;
  704. }