zimbraSingle.php 22 KB

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