zimbraSingle.php 23 KB

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