json_api.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. <?php
  2. /*
  3. edit/alias => POST data:
  4. {
  5. address: {a, b, c}, (where a, b, c represent alias addresses)
  6. active: 1 (0 or 1)
  7. }
  8. delete/alias => POST data:
  9. {
  10. address: {a, b, c}, (where a, b, c represent alias addresses)
  11. }
  12. */
  13. header('Content-Type: application/json');
  14. require_once 'inc/prerequisites.inc.php';
  15. error_reporting(0);
  16. if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_username'])) {
  17. if (isset($_GET['query'])) {
  18. $query = explode('/', $_GET['query']);
  19. $action = (isset($query[0])) ? $query[0] : null;
  20. $category = (isset($query[1])) ? $query[1] : null;
  21. $object = (isset($query[2])) ? $query[2] : null;
  22. $extra = (isset($query[3])) ? $query[3] : null;
  23. switch ($action) {
  24. case "get":
  25. switch ($category) {
  26. case "domain":
  27. switch ($object) {
  28. case "all":
  29. $domains = mailbox_get_domains();
  30. if (!empty($domains)) {
  31. foreach ($domains as $domain) {
  32. if ($details = mailbox_get_domain_details($domain)) {
  33. $data[] = $details;
  34. }
  35. else {
  36. continue;
  37. }
  38. }
  39. if (!isset($data) || empty($data)) {
  40. echo '{}';
  41. }
  42. else {
  43. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  44. }
  45. }
  46. else {
  47. echo '{}';
  48. }
  49. break;
  50. default:
  51. $data = mailbox_get_domain_details($object);
  52. if (!isset($data) || empty($data)) {
  53. echo '{}';
  54. }
  55. else {
  56. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  57. }
  58. break;
  59. }
  60. break;
  61. case "logs":
  62. switch ($object) {
  63. case "dovecot":
  64. if (isset($extra) && !empty($extra)) {
  65. $extra = intval($extra);
  66. $logs = get_logs('dovecot-mailcow', $extra);
  67. }
  68. else {
  69. $logs = get_logs('dovecot-mailcow', -1);
  70. }
  71. if (isset($logs) && !empty($logs)) {
  72. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  73. }
  74. else {
  75. echo '{}';
  76. }
  77. break;
  78. case "postfix":
  79. if (isset($extra) && !empty($extra)) {
  80. $extra = intval($extra);
  81. $logs = get_logs('postfix-mailcow', $extra);
  82. }
  83. else {
  84. $logs = get_logs('postfix-mailcow', -1);
  85. }
  86. if (isset($logs) && !empty($logs)) {
  87. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  88. }
  89. else {
  90. echo '{}';
  91. }
  92. break;
  93. case "sogo":
  94. if (isset($extra) && !empty($extra)) {
  95. $extra = intval($extra);
  96. $logs = get_logs('sogo-mailcow', $extra);
  97. }
  98. else {
  99. $logs = get_logs('sogo-mailcow', -1);
  100. }
  101. if (isset($logs) && !empty($logs)) {
  102. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  103. }
  104. else {
  105. echo '{}';
  106. }
  107. break;
  108. }
  109. break;
  110. case "mailbox":
  111. switch ($object) {
  112. case "all":
  113. $domains = mailbox_get_domains();
  114. if (!empty($domains)) {
  115. foreach ($domains as $domain) {
  116. $mailboxes = mailbox_get_mailboxes($domain);
  117. if (!empty($mailboxes)) {
  118. foreach ($mailboxes as $mailbox) {
  119. if ($details = mailbox_get_mailbox_details($mailbox)) {
  120. $data[] = $details;
  121. }
  122. else {
  123. continue;
  124. }
  125. }
  126. }
  127. }
  128. if (!isset($data) || empty($data)) {
  129. echo '{}';
  130. }
  131. else {
  132. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  133. }
  134. }
  135. else {
  136. echo '{}';
  137. }
  138. break;
  139. default:
  140. $data = mailbox_get_mailbox_details($object);
  141. if (!isset($data) || empty($data)) {
  142. echo '{}';
  143. }
  144. else {
  145. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  146. }
  147. break;
  148. }
  149. break;
  150. case "syncjob":
  151. switch ($object) {
  152. default:
  153. $data = get_syncjobs($object);
  154. if (!isset($data) || empty($data)) {
  155. echo '{}';
  156. }
  157. else {
  158. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  159. }
  160. break;
  161. }
  162. break;
  163. case "resource":
  164. switch ($object) {
  165. case "all":
  166. $domains = mailbox_get_domains();
  167. if (!empty($domains)) {
  168. foreach ($domains as $domain) {
  169. $resources = mailbox_get_resources($domain);
  170. if (!empty($resources)) {
  171. foreach ($resources as $resource) {
  172. if ($details = mailbox_get_resource_details($resource)) {
  173. $data[] = $details;
  174. }
  175. else {
  176. continue;
  177. }
  178. }
  179. }
  180. }
  181. if (!isset($data) || empty($data)) {
  182. echo '{}';
  183. }
  184. else {
  185. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  186. }
  187. }
  188. else {
  189. echo '{}';
  190. }
  191. break;
  192. default:
  193. $data = mailbox_get_resource_details($object);
  194. if (!isset($data) || empty($data)) {
  195. echo '{}';
  196. }
  197. else {
  198. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  199. }
  200. break;
  201. }
  202. break;
  203. case "fwdhost":
  204. switch ($object) {
  205. case "all":
  206. $fwdhosts = get_forwarding_hosts();
  207. if (!empty($fwdhosts)) {
  208. foreach ($fwdhosts as $fwdhost) {
  209. if ($details = get_forwarding_host_details($fwdhost)) {
  210. $data[] = $details;
  211. }
  212. else {
  213. continue;
  214. }
  215. }
  216. }
  217. if (!isset($data) || empty($data)) {
  218. echo '{}';
  219. }
  220. else {
  221. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  222. }
  223. break;
  224. default:
  225. $data = get_forwarding_host_details($object);
  226. if (!isset($data) || empty($data)) {
  227. echo '{}';
  228. }
  229. else {
  230. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  231. }
  232. break;
  233. }
  234. break;
  235. case "alias-domain":
  236. switch ($object) {
  237. case "all":
  238. $domains = mailbox_get_domains();
  239. if (!empty($domains)) {
  240. foreach ($domains as $domain) {
  241. $alias_domains = mailbox_get_alias_domains($domain);
  242. if (!empty($alias_domains)) {
  243. foreach ($alias_domains as $alias_domain) {
  244. if ($details = mailbox_get_alias_domain_details($alias_domain)) {
  245. $data[] = $details;
  246. }
  247. else {
  248. continue;
  249. }
  250. }
  251. }
  252. }
  253. if (!isset($data) || empty($data)) {
  254. echo '{}';
  255. }
  256. else {
  257. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  258. }
  259. }
  260. else {
  261. echo '{}';
  262. }
  263. break;
  264. default:
  265. $data = mailbox_get_alias_domains($object);
  266. if (!isset($data) || empty($data)) {
  267. echo '{}';
  268. }
  269. else {
  270. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  271. }
  272. break;
  273. }
  274. break;
  275. case "alias":
  276. switch ($object) {
  277. case "all":
  278. $domains = array_merge(mailbox_get_domains(), mailbox_get_alias_domains());
  279. if (!empty($domains)) {
  280. foreach ($domains as $domain) {
  281. $aliases = mailbox_get_aliases($domain);
  282. if (!empty($aliases)) {
  283. foreach ($aliases as $alias) {
  284. if ($details = mailbox_get_alias_details($alias)) {
  285. $data[] = $details;
  286. }
  287. else {
  288. continue;
  289. }
  290. }
  291. }
  292. }
  293. if (!isset($data) || empty($data)) {
  294. echo '{}';
  295. }
  296. else {
  297. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  298. }
  299. }
  300. else {
  301. echo '{}';
  302. }
  303. break;
  304. default:
  305. $data = mailbox_get_alias_details($object);
  306. if (!isset($data) || empty($data)) {
  307. echo '{}';
  308. }
  309. else {
  310. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  311. }
  312. break;
  313. }
  314. break;
  315. case "domain-admin":
  316. switch ($object) {
  317. case "all":
  318. $domain_admins = get_domain_admins();
  319. if (!empty($domain_admins)) {
  320. foreach ($domain_admins as $domain_admin) {
  321. if ($details = get_domain_admin_details($domain_admin)) {
  322. $data[] = $details;
  323. }
  324. else {
  325. continue;
  326. }
  327. }
  328. if (!isset($data) || empty($data)) {
  329. echo '{}';
  330. }
  331. else {
  332. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  333. }
  334. }
  335. else {
  336. echo '{}';
  337. }
  338. break;
  339. default:
  340. $data = get_domain_admin_details($object);
  341. if (!isset($data) || empty($data)) {
  342. echo '{}';
  343. }
  344. else {
  345. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  346. }
  347. break;
  348. }
  349. break;
  350. case "u2f-registration":
  351. header('Content-Type: application/javascript');
  352. if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
  353. $data = $u2f->getRegisterData(get_u2f_registrations($object));
  354. list($req, $sigs) = $data;
  355. $_SESSION['regReq'] = json_encode($req);
  356. echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';';
  357. }
  358. else {
  359. return;
  360. }
  361. break;
  362. case "u2f-authentication":
  363. header('Content-Type: application/javascript');
  364. if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
  365. $reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
  366. $_SESSION['authReq'] = $reqs;
  367. echo 'var req = ' . $reqs . ';';
  368. }
  369. else {
  370. return;
  371. }
  372. break;
  373. default:
  374. echo '{}';
  375. break;
  376. }
  377. break;
  378. case "delete":
  379. switch ($category) {
  380. case "alias":
  381. if (isset($_POST['items'])) {
  382. $items = (array)json_decode($_POST['items'], true);
  383. if (is_array($items)) {
  384. if (mailbox_delete_alias(array('address' => $items)) === false) {
  385. if (isset($_SESSION['return'])) {
  386. echo json_encode($_SESSION['return']);
  387. }
  388. else {
  389. echo json_encode(array(
  390. 'type' => 'error',
  391. 'msg' => 'Deletion of items/s failed'
  392. ));
  393. }
  394. }
  395. else {
  396. if (isset($_SESSION['return'])) {
  397. echo json_encode($_SESSION['return']);
  398. }
  399. else {
  400. echo json_encode(array(
  401. 'type' => 'success',
  402. 'msg' => 'Task completed'
  403. ));
  404. }
  405. }
  406. }
  407. else {
  408. echo json_encode(array(
  409. 'type' => 'error',
  410. 'msg' => 'Cannot find address array in post data'
  411. ));
  412. }
  413. }
  414. else {
  415. echo json_encode(array(
  416. 'type' => 'error',
  417. 'msg' => 'Cannot find items in post data'
  418. ));
  419. }
  420. break;
  421. case "fwdhost":
  422. if (isset($_POST['items'])) {
  423. $items = (array)json_decode($_POST['items'], true);
  424. if (is_array($items)) {
  425. if (delete_forwarding_host(array('forwardinghost' => $items)) === false) {
  426. if (isset($_SESSION['return'])) {
  427. echo json_encode($_SESSION['return']);
  428. }
  429. else {
  430. echo json_encode(array(
  431. 'type' => 'error',
  432. 'msg' => 'Deletion of items/s failed'
  433. ));
  434. }
  435. }
  436. else {
  437. if (isset($_SESSION['return'])) {
  438. echo json_encode($_SESSION['return']);
  439. }
  440. else {
  441. echo json_encode(array(
  442. 'type' => 'success',
  443. 'msg' => 'Task completed'
  444. ));
  445. }
  446. }
  447. }
  448. else {
  449. echo json_encode(array(
  450. 'type' => 'error',
  451. 'msg' => 'Cannot find forwardinghost array in post data'
  452. ));
  453. }
  454. }
  455. else {
  456. echo json_encode(array(
  457. 'type' => 'error',
  458. 'msg' => 'Cannot find items in post data'
  459. ));
  460. }
  461. break;
  462. case "dkim":
  463. if (isset($_POST['items'])) {
  464. $items = (array)json_decode($_POST['items'], true);
  465. if (is_array($items)) {
  466. if (dkim_delete_key(array('domains' => $items)) === false) {
  467. if (isset($_SESSION['return'])) {
  468. echo json_encode($_SESSION['return']);
  469. }
  470. else {
  471. echo json_encode(array(
  472. 'type' => 'error',
  473. 'msg' => 'Deletion of items/s failed'
  474. ));
  475. }
  476. }
  477. else {
  478. if (isset($_SESSION['return'])) {
  479. echo json_encode($_SESSION['return']);
  480. }
  481. else {
  482. echo json_encode(array(
  483. 'type' => 'success',
  484. 'msg' => 'Task completed'
  485. ));
  486. }
  487. }
  488. }
  489. else {
  490. echo json_encode(array(
  491. 'type' => 'error',
  492. 'msg' => 'Cannot find domains array in post data'
  493. ));
  494. }
  495. }
  496. else {
  497. echo json_encode(array(
  498. 'type' => 'error',
  499. 'msg' => 'Cannot find items in post data'
  500. ));
  501. }
  502. break;
  503. case "domain":
  504. if (isset($_POST['items'])) {
  505. $items = (array)json_decode($_POST['items'], true);
  506. if (is_array($items)) {
  507. if (mailbox_delete_domain(array('domain' => $items)) === false) {
  508. if (isset($_SESSION['return'])) {
  509. echo json_encode($_SESSION['return']);
  510. }
  511. else {
  512. echo json_encode(array(
  513. 'type' => 'error',
  514. 'msg' => 'Task failed'
  515. ));
  516. }
  517. }
  518. else {
  519. if (isset($_SESSION['return'])) {
  520. echo json_encode($_SESSION['return']);
  521. }
  522. else {
  523. echo json_encode(array(
  524. 'type' => 'success',
  525. 'msg' => 'Task completed'
  526. ));
  527. }
  528. }
  529. }
  530. else {
  531. echo json_encode(array(
  532. 'type' => 'error',
  533. 'msg' => 'Cannot find domain array in post data'
  534. ));
  535. }
  536. }
  537. else {
  538. echo json_encode(array(
  539. 'type' => 'error',
  540. 'msg' => 'Cannot find items in post data'
  541. ));
  542. }
  543. break;
  544. case "alias-domain":
  545. if (isset($_POST['items'])) {
  546. $items = (array)json_decode($_POST['items'], true);
  547. if (is_array($items)) {
  548. if (mailbox_delete_alias_domain(array('alias_domain' => $items)) === false) {
  549. if (isset($_SESSION['return'])) {
  550. echo json_encode($_SESSION['return']);
  551. }
  552. else {
  553. echo json_encode(array(
  554. 'type' => 'error',
  555. 'msg' => 'Task failed'
  556. ));
  557. }
  558. }
  559. else {
  560. if (isset($_SESSION['return'])) {
  561. echo json_encode($_SESSION['return']);
  562. }
  563. else {
  564. echo json_encode(array(
  565. 'type' => 'success',
  566. 'msg' => 'Task completed'
  567. ));
  568. }
  569. }
  570. }
  571. else {
  572. echo json_encode(array(
  573. 'type' => 'error',
  574. 'msg' => 'Cannot find alias_domain array in post data'
  575. ));
  576. }
  577. }
  578. else {
  579. echo json_encode(array(
  580. 'type' => 'error',
  581. 'msg' => 'Cannot find items in post data'
  582. ));
  583. }
  584. break;
  585. case "mailbox":
  586. if (isset($_POST['items'])) {
  587. $items = (array)json_decode($_POST['items'], true);
  588. if (is_array($items)) {
  589. if (mailbox_delete_mailbox(array('username' => $items)) === false) {
  590. if (isset($_SESSION['return'])) {
  591. echo json_encode($_SESSION['return']);
  592. }
  593. else {
  594. echo json_encode(array(
  595. 'type' => 'error',
  596. 'msg' => 'Task failed'
  597. ));
  598. }
  599. }
  600. else {
  601. if (isset($_SESSION['return'])) {
  602. echo json_encode($_SESSION['return']);
  603. }
  604. else {
  605. echo json_encode(array(
  606. 'type' => 'success',
  607. 'msg' => 'Task completed'
  608. ));
  609. }
  610. }
  611. }
  612. else {
  613. echo json_encode(array(
  614. 'type' => 'error',
  615. 'msg' => 'Cannot find username array in post data'
  616. ));
  617. }
  618. }
  619. else {
  620. echo json_encode(array(
  621. 'type' => 'error',
  622. 'msg' => 'Cannot find items in post data'
  623. ));
  624. }
  625. break;
  626. case "resource":
  627. if (isset($_POST['items'])) {
  628. $items = (array)json_decode($_POST['items'], true);
  629. if (is_array($items)) {
  630. if (mailbox_delete_resource(array('name' => $items)) === false) {
  631. if (isset($_SESSION['return'])) {
  632. echo json_encode($_SESSION['return']);
  633. }
  634. else {
  635. echo json_encode(array(
  636. 'type' => 'error',
  637. 'msg' => 'Task failed'
  638. ));
  639. }
  640. }
  641. else {
  642. if (isset($_SESSION['return'])) {
  643. echo json_encode($_SESSION['return']);
  644. }
  645. else {
  646. echo json_encode(array(
  647. 'type' => 'success',
  648. 'msg' => 'Task completed'
  649. ));
  650. }
  651. }
  652. }
  653. else {
  654. echo json_encode(array(
  655. 'type' => 'error',
  656. 'msg' => 'Cannot find name array in post data'
  657. ));
  658. }
  659. }
  660. else {
  661. echo json_encode(array(
  662. 'type' => 'error',
  663. 'msg' => 'Cannot find items in post data'
  664. ));
  665. }
  666. break;
  667. }
  668. break;
  669. case "edit":
  670. switch ($category) {
  671. case "alias":
  672. if (isset($_POST['items']) && isset($_POST['attr'])) {
  673. $items = (array)json_decode($_POST['items'], true);
  674. $attr = (array)json_decode($_POST['attr'], true);
  675. $postarray = array_merge(array('address' => $items), $attr);
  676. if (is_array($postarray['address'])) {
  677. if (mailbox_edit_alias($postarray) === false) {
  678. if (isset($_SESSION['return'])) {
  679. echo json_encode($_SESSION['return']);
  680. }
  681. else {
  682. echo json_encode(array(
  683. 'type' => 'error',
  684. 'msg' => 'Edit failed'
  685. ));
  686. }
  687. exit();
  688. }
  689. else {
  690. if (isset($_SESSION['return'])) {
  691. echo json_encode($_SESSION['return']);
  692. }
  693. else {
  694. echo json_encode(array(
  695. 'type' => 'success',
  696. 'msg' => 'Task completed'
  697. ));
  698. }
  699. }
  700. }
  701. else {
  702. echo json_encode(array(
  703. 'type' => 'error',
  704. 'msg' => 'Incomplete post data'
  705. ));
  706. }
  707. }
  708. else {
  709. echo json_encode(array(
  710. 'type' => 'error',
  711. 'msg' => 'Incomplete post data'
  712. ));
  713. }
  714. break;
  715. case "mailbox":
  716. if (isset($_POST['items']) && isset($_POST['attr'])) {
  717. $items = (array)json_decode($_POST['items'], true);
  718. $attr = (array)json_decode($_POST['attr'], true);
  719. $postarray = array_merge(array('username' => $items), $attr);
  720. if (is_array($postarray['username'])) {
  721. if (mailbox_edit_mailbox($postarray) === false) {
  722. if (isset($_SESSION['return'])) {
  723. echo json_encode($_SESSION['return']);
  724. }
  725. else {
  726. echo json_encode(array(
  727. 'type' => 'error',
  728. 'msg' => 'Edit failed'
  729. ));
  730. }
  731. exit();
  732. }
  733. else {
  734. if (isset($_SESSION['return'])) {
  735. echo json_encode($_SESSION['return']);
  736. }
  737. else {
  738. echo json_encode(array(
  739. 'type' => 'success',
  740. 'msg' => 'Task completed'
  741. ));
  742. }
  743. }
  744. }
  745. else {
  746. echo json_encode(array(
  747. 'type' => 'error',
  748. 'msg' => 'Incomplete post data'
  749. ));
  750. }
  751. }
  752. else {
  753. echo json_encode(array(
  754. 'type' => 'error',
  755. 'msg' => 'Incomplete post data'
  756. ));
  757. }
  758. break;
  759. case "syncjob":
  760. if (isset($_POST['items']) && isset($_POST['attr'])) {
  761. $items = (array)json_decode($_POST['items'], true);
  762. $attr = (array)json_decode($_POST['attr'], true);
  763. $postarray = array_merge(array('id' => $items), $attr);
  764. if (is_array($postarray['id'])) {
  765. if (edit_syncjob($postarray) === false) {
  766. if (isset($_SESSION['return'])) {
  767. echo json_encode($_SESSION['return']);
  768. }
  769. else {
  770. echo json_encode(array(
  771. 'type' => 'error',
  772. 'msg' => 'Edit failed'
  773. ));
  774. }
  775. exit();
  776. }
  777. else {
  778. if (isset($_SESSION['return'])) {
  779. echo json_encode($_SESSION['return']);
  780. }
  781. else {
  782. echo json_encode(array(
  783. 'type' => 'success',
  784. 'msg' => 'Task completed'
  785. ));
  786. }
  787. }
  788. }
  789. else {
  790. echo json_encode(array(
  791. 'type' => 'error',
  792. 'msg' => 'Incomplete post data'
  793. ));
  794. }
  795. }
  796. else {
  797. echo json_encode(array(
  798. 'type' => 'error',
  799. 'msg' => 'Incomplete post data'
  800. ));
  801. }
  802. break;
  803. case "resource":
  804. if (isset($_POST['items']) && isset($_POST['attr'])) {
  805. $items = (array)json_decode($_POST['items'], true);
  806. $attr = (array)json_decode($_POST['attr'], true);
  807. $postarray = array_merge(array('name' => $items), $attr);
  808. if (is_array($postarray['name'])) {
  809. if (mailbox_edit_resource($postarray) === false) {
  810. if (isset($_SESSION['return'])) {
  811. echo json_encode($_SESSION['return']);
  812. }
  813. else {
  814. echo json_encode(array(
  815. 'type' => 'error',
  816. 'msg' => 'Edit failed'
  817. ));
  818. }
  819. exit();
  820. }
  821. else {
  822. if (isset($_SESSION['return'])) {
  823. echo json_encode($_SESSION['return']);
  824. }
  825. else {
  826. echo json_encode(array(
  827. 'type' => 'success',
  828. 'msg' => 'Task completed'
  829. ));
  830. }
  831. }
  832. }
  833. else {
  834. echo json_encode(array(
  835. 'type' => 'error',
  836. 'msg' => 'Incomplete post data'
  837. ));
  838. }
  839. }
  840. else {
  841. echo json_encode(array(
  842. 'type' => 'error',
  843. 'msg' => 'Incomplete post data'
  844. ));
  845. }
  846. break;
  847. case "domain":
  848. if (isset($_POST['items']) && isset($_POST['attr'])) {
  849. $items = (array)json_decode($_POST['items'], true);
  850. $attr = (array)json_decode($_POST['attr'], true);
  851. $postarray = array_merge(array('domain' => $items), $attr);
  852. if (is_array($postarray['domain'])) {
  853. if (mailbox_edit_domain($postarray) === false) {
  854. if (isset($_SESSION['return'])) {
  855. echo json_encode($_SESSION['return']);
  856. }
  857. else {
  858. echo json_encode(array(
  859. 'type' => 'error',
  860. 'msg' => 'Edit failed'
  861. ));
  862. }
  863. exit();
  864. }
  865. else {
  866. if (isset($_SESSION['return'])) {
  867. echo json_encode($_SESSION['return']);
  868. }
  869. else {
  870. echo json_encode(array(
  871. 'type' => 'success',
  872. 'msg' => 'Task completed'
  873. ));
  874. }
  875. }
  876. }
  877. else {
  878. echo json_encode(array(
  879. 'type' => 'error',
  880. 'msg' => 'Incomplete post data'
  881. ));
  882. }
  883. }
  884. else {
  885. echo json_encode(array(
  886. 'type' => 'error',
  887. 'msg' => 'Incomplete post data'
  888. ));
  889. }
  890. break;
  891. case "alias-domain":
  892. if (isset($_POST['items']) && isset($_POST['attr'])) {
  893. $items = (array)json_decode($_POST['items'], true);
  894. $attr = (array)json_decode($_POST['attr'], true);
  895. $postarray = array_merge(array('alias_domain' => $items), $attr);
  896. if (is_array($postarray['alias_domain'])) {
  897. if (mailbox_edit_alias_domain($postarray) === false) {
  898. if (isset($_SESSION['return'])) {
  899. echo json_encode($_SESSION['return']);
  900. }
  901. else {
  902. echo json_encode(array(
  903. 'type' => 'error',
  904. 'msg' => 'Edit failed'
  905. ));
  906. }
  907. exit();
  908. }
  909. else {
  910. if (isset($_SESSION['return'])) {
  911. echo json_encode($_SESSION['return']);
  912. }
  913. else {
  914. echo json_encode(array(
  915. 'type' => 'success',
  916. 'msg' => 'Task completed'
  917. ));
  918. }
  919. }
  920. }
  921. else {
  922. echo json_encode(array(
  923. 'type' => 'error',
  924. 'msg' => 'Incomplete post data'
  925. ));
  926. }
  927. }
  928. else {
  929. echo json_encode(array(
  930. 'type' => 'error',
  931. 'msg' => 'Incomplete post data'
  932. ));
  933. }
  934. break;
  935. }
  936. break;
  937. }
  938. }
  939. }