zimbraSingle.php 22 KB

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