json_api.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  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 "resource":
  151. switch ($object) {
  152. case "all":
  153. $domains = mailbox_get_domains();
  154. if (!empty($domains)) {
  155. foreach ($domains as $domain) {
  156. $resources = mailbox_get_resources($domain);
  157. if (!empty($resources)) {
  158. foreach ($resources as $resource) {
  159. if ($details = mailbox_get_resource_details($resource)) {
  160. $data[] = $details;
  161. }
  162. else {
  163. continue;
  164. }
  165. }
  166. }
  167. }
  168. if (!isset($data) || empty($data)) {
  169. echo '{}';
  170. }
  171. else {
  172. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  173. }
  174. }
  175. else {
  176. echo '{}';
  177. }
  178. break;
  179. default:
  180. $data = mailbox_get_resource_details($object);
  181. if (!isset($data) || empty($data)) {
  182. echo '{}';
  183. }
  184. else {
  185. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  186. }
  187. break;
  188. }
  189. break;
  190. case "fwdhost":
  191. switch ($object) {
  192. case "all":
  193. $fwdhosts = get_forwarding_hosts();
  194. if (!empty($fwdhosts)) {
  195. foreach ($fwdhosts as $fwdhost) {
  196. if ($details = get_forwarding_host_details($fwdhost)) {
  197. $data[] = $details;
  198. }
  199. else {
  200. continue;
  201. }
  202. }
  203. }
  204. if (!isset($data) || empty($data)) {
  205. echo '{}';
  206. }
  207. else {
  208. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  209. }
  210. break;
  211. default:
  212. $data = get_forwarding_host_details($object);
  213. if (!isset($data) || empty($data)) {
  214. echo '{}';
  215. }
  216. else {
  217. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  218. }
  219. break;
  220. }
  221. break;
  222. case "alias-domain":
  223. switch ($object) {
  224. case "all":
  225. $domains = mailbox_get_domains();
  226. if (!empty($domains)) {
  227. foreach ($domains as $domain) {
  228. $alias_domains = mailbox_get_alias_domains($domain);
  229. if (!empty($alias_domains)) {
  230. foreach ($alias_domains as $alias_domain) {
  231. if ($details = mailbox_get_alias_domain_details($alias_domain)) {
  232. $data[] = $details;
  233. }
  234. else {
  235. continue;
  236. }
  237. }
  238. }
  239. }
  240. if (!isset($data) || empty($data)) {
  241. echo '{}';
  242. }
  243. else {
  244. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  245. }
  246. }
  247. else {
  248. echo '{}';
  249. }
  250. break;
  251. default:
  252. $data = mailbox_get_alias_domains($object);
  253. if (!isset($data) || empty($data)) {
  254. echo '{}';
  255. }
  256. else {
  257. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  258. }
  259. break;
  260. }
  261. break;
  262. case "alias":
  263. switch ($object) {
  264. case "all":
  265. $domains = array_merge(mailbox_get_domains(), mailbox_get_alias_domains());
  266. if (!empty($domains)) {
  267. foreach ($domains as $domain) {
  268. $aliases = mailbox_get_aliases($domain);
  269. if (!empty($aliases)) {
  270. foreach ($aliases as $alias) {
  271. if ($details = mailbox_get_alias_details($alias)) {
  272. $data[] = $details;
  273. }
  274. else {
  275. continue;
  276. }
  277. }
  278. }
  279. }
  280. if (!isset($data) || empty($data)) {
  281. echo '{}';
  282. }
  283. else {
  284. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  285. }
  286. }
  287. else {
  288. echo '{}';
  289. }
  290. break;
  291. default:
  292. $data = mailbox_get_alias_details($object);
  293. if (!isset($data) || empty($data)) {
  294. echo '{}';
  295. }
  296. else {
  297. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  298. }
  299. break;
  300. }
  301. break;
  302. case "domain-admin":
  303. switch ($object) {
  304. case "all":
  305. $domain_admins = get_domain_admins();
  306. if (!empty($domain_admins)) {
  307. foreach ($domain_admins as $domain_admin) {
  308. if ($details = get_domain_admin_details($domain_admin)) {
  309. $data[] = $details;
  310. }
  311. else {
  312. continue;
  313. }
  314. }
  315. if (!isset($data) || empty($data)) {
  316. echo '{}';
  317. }
  318. else {
  319. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  320. }
  321. }
  322. else {
  323. echo '{}';
  324. }
  325. break;
  326. default:
  327. $data = get_domain_admin_details($object);
  328. if (!isset($data) || empty($data)) {
  329. echo '{}';
  330. }
  331. else {
  332. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  333. }
  334. break;
  335. }
  336. break;
  337. case "u2f-registration":
  338. header('Content-Type: application/javascript');
  339. if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
  340. $data = $u2f->getRegisterData(get_u2f_registrations($object));
  341. list($req, $sigs) = $data;
  342. $_SESSION['regReq'] = json_encode($req);
  343. echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';';
  344. }
  345. else {
  346. return;
  347. }
  348. break;
  349. case "u2f-authentication":
  350. header('Content-Type: application/javascript');
  351. if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
  352. $reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
  353. $_SESSION['authReq'] = $reqs;
  354. echo 'var req = ' . $reqs . ';';
  355. }
  356. else {
  357. return;
  358. }
  359. break;
  360. default:
  361. echo '{}';
  362. break;
  363. }
  364. break;
  365. case "delete":
  366. switch ($category) {
  367. case "alias":
  368. if (isset($_POST['items'])) {
  369. $items = (array)json_decode($_POST['items'], true);
  370. if (is_array($items)) {
  371. if (mailbox_delete_alias(array('address' => $items)) === false) {
  372. if (isset($_SESSION['return'])) {
  373. echo json_encode($_SESSION['return']);
  374. }
  375. else {
  376. echo json_encode(array(
  377. 'type' => 'error',
  378. 'msg' => 'Deletion of items/s failed'
  379. ));
  380. }
  381. }
  382. else {
  383. if (isset($_SESSION['return'])) {
  384. echo json_encode($_SESSION['return']);
  385. }
  386. else {
  387. echo json_encode(array(
  388. 'type' => 'success',
  389. 'msg' => 'Task completed'
  390. ));
  391. }
  392. }
  393. }
  394. else {
  395. echo json_encode(array(
  396. 'type' => 'error',
  397. 'msg' => 'Cannot find address array in post data'
  398. ));
  399. }
  400. }
  401. else {
  402. echo json_encode(array(
  403. 'type' => 'error',
  404. 'msg' => 'Cannot find items in post data'
  405. ));
  406. }
  407. break;
  408. case "fwdhost":
  409. if (isset($_POST['items'])) {
  410. $items = (array)json_decode($_POST['items'], true);
  411. if (is_array($items)) {
  412. if (delete_forwarding_host(array('forwardinghost' => $items)) === false) {
  413. if (isset($_SESSION['return'])) {
  414. echo json_encode($_SESSION['return']);
  415. }
  416. else {
  417. echo json_encode(array(
  418. 'type' => 'error',
  419. 'msg' => 'Deletion of items/s failed'
  420. ));
  421. }
  422. }
  423. else {
  424. if (isset($_SESSION['return'])) {
  425. echo json_encode($_SESSION['return']);
  426. }
  427. else {
  428. echo json_encode(array(
  429. 'type' => 'success',
  430. 'msg' => 'Task completed'
  431. ));
  432. }
  433. }
  434. }
  435. else {
  436. echo json_encode(array(
  437. 'type' => 'error',
  438. 'msg' => 'Cannot find forwardinghost array in post data'
  439. ));
  440. }
  441. }
  442. else {
  443. echo json_encode(array(
  444. 'type' => 'error',
  445. 'msg' => 'Cannot find items in post data'
  446. ));
  447. }
  448. break;
  449. case "dkim":
  450. if (isset($_POST['items'])) {
  451. $items = (array)json_decode($_POST['items'], true);
  452. if (is_array($items)) {
  453. if (dkim_delete_key(array('domains' => $items)) === false) {
  454. if (isset($_SESSION['return'])) {
  455. echo json_encode($_SESSION['return']);
  456. }
  457. else {
  458. echo json_encode(array(
  459. 'type' => 'error',
  460. 'msg' => 'Deletion of items/s failed'
  461. ));
  462. }
  463. }
  464. else {
  465. if (isset($_SESSION['return'])) {
  466. echo json_encode($_SESSION['return']);
  467. }
  468. else {
  469. echo json_encode(array(
  470. 'type' => 'success',
  471. 'msg' => 'Task completed'
  472. ));
  473. }
  474. }
  475. }
  476. else {
  477. echo json_encode(array(
  478. 'type' => 'error',
  479. 'msg' => 'Cannot find domains array in post data'
  480. ));
  481. }
  482. }
  483. else {
  484. echo json_encode(array(
  485. 'type' => 'error',
  486. 'msg' => 'Cannot find items in post data'
  487. ));
  488. }
  489. break;
  490. case "domain":
  491. if (isset($_POST['items'])) {
  492. $items = (array)json_decode($_POST['items'], true);
  493. if (is_array($items)) {
  494. if (mailbox_delete_domain(array('domain' => $items)) === false) {
  495. if (isset($_SESSION['return'])) {
  496. echo json_encode($_SESSION['return']);
  497. }
  498. else {
  499. echo json_encode(array(
  500. 'type' => 'error',
  501. 'msg' => 'Task failed'
  502. ));
  503. }
  504. }
  505. else {
  506. if (isset($_SESSION['return'])) {
  507. echo json_encode($_SESSION['return']);
  508. }
  509. else {
  510. echo json_encode(array(
  511. 'type' => 'success',
  512. 'msg' => 'Task completed'
  513. ));
  514. }
  515. }
  516. }
  517. else {
  518. echo json_encode(array(
  519. 'type' => 'error',
  520. 'msg' => 'Cannot find domain array in post data'
  521. ));
  522. }
  523. }
  524. else {
  525. echo json_encode(array(
  526. 'type' => 'error',
  527. 'msg' => 'Cannot find items in post data'
  528. ));
  529. }
  530. break;
  531. case "alias-domain":
  532. if (isset($_POST['items'])) {
  533. $items = (array)json_decode($_POST['items'], true);
  534. if (is_array($items)) {
  535. if (mailbox_delete_alias_domain(array('alias_domain' => $items)) === false) {
  536. if (isset($_SESSION['return'])) {
  537. echo json_encode($_SESSION['return']);
  538. }
  539. else {
  540. echo json_encode(array(
  541. 'type' => 'error',
  542. 'msg' => 'Task failed'
  543. ));
  544. }
  545. }
  546. else {
  547. if (isset($_SESSION['return'])) {
  548. echo json_encode($_SESSION['return']);
  549. }
  550. else {
  551. echo json_encode(array(
  552. 'type' => 'success',
  553. 'msg' => 'Task completed'
  554. ));
  555. }
  556. }
  557. }
  558. else {
  559. echo json_encode(array(
  560. 'type' => 'error',
  561. 'msg' => 'Cannot find alias_domain array in post data'
  562. ));
  563. }
  564. }
  565. else {
  566. echo json_encode(array(
  567. 'type' => 'error',
  568. 'msg' => 'Cannot find items in post data'
  569. ));
  570. }
  571. break;
  572. case "mailbox":
  573. if (isset($_POST['items'])) {
  574. $items = (array)json_decode($_POST['items'], true);
  575. if (is_array($items)) {
  576. if (mailbox_delete_mailbox(array('username' => $items)) === false) {
  577. if (isset($_SESSION['return'])) {
  578. echo json_encode($_SESSION['return']);
  579. }
  580. else {
  581. echo json_encode(array(
  582. 'type' => 'error',
  583. 'msg' => 'Task failed'
  584. ));
  585. }
  586. }
  587. else {
  588. if (isset($_SESSION['return'])) {
  589. echo json_encode($_SESSION['return']);
  590. }
  591. else {
  592. echo json_encode(array(
  593. 'type' => 'success',
  594. 'msg' => 'Task completed'
  595. ));
  596. }
  597. }
  598. }
  599. else {
  600. echo json_encode(array(
  601. 'type' => 'error',
  602. 'msg' => 'Cannot find username array in post data'
  603. ));
  604. }
  605. }
  606. else {
  607. echo json_encode(array(
  608. 'type' => 'error',
  609. 'msg' => 'Cannot find items in post data'
  610. ));
  611. }
  612. break;
  613. case "resource":
  614. if (isset($_POST['items'])) {
  615. $items = (array)json_decode($_POST['items'], true);
  616. if (is_array($items)) {
  617. if (mailbox_delete_resource(array('name' => $items)) === false) {
  618. if (isset($_SESSION['return'])) {
  619. echo json_encode($_SESSION['return']);
  620. }
  621. else {
  622. echo json_encode(array(
  623. 'type' => 'error',
  624. 'msg' => 'Task failed'
  625. ));
  626. }
  627. }
  628. else {
  629. if (isset($_SESSION['return'])) {
  630. echo json_encode($_SESSION['return']);
  631. }
  632. else {
  633. echo json_encode(array(
  634. 'type' => 'success',
  635. 'msg' => 'Task completed'
  636. ));
  637. }
  638. }
  639. }
  640. else {
  641. echo json_encode(array(
  642. 'type' => 'error',
  643. 'msg' => 'Cannot find name array in post data'
  644. ));
  645. }
  646. }
  647. else {
  648. echo json_encode(array(
  649. 'type' => 'error',
  650. 'msg' => 'Cannot find items in post data'
  651. ));
  652. }
  653. break;
  654. }
  655. break;
  656. case "edit":
  657. switch ($category) {
  658. case "alias":
  659. if (isset($_POST['items']) && isset($_POST['attr'])) {
  660. $items = (array)json_decode($_POST['items'], true);
  661. $attr = (array)json_decode($_POST['attr'], true);
  662. $postarray = array_merge(array('address' => $items), $attr);
  663. if (is_array($postarray['address'])) {
  664. if (mailbox_edit_alias($postarray) === false) {
  665. if (isset($_SESSION['return'])) {
  666. echo json_encode($_SESSION['return']);
  667. }
  668. else {
  669. echo json_encode(array(
  670. 'type' => 'error',
  671. 'msg' => 'Edit failed'
  672. ));
  673. }
  674. exit();
  675. }
  676. else {
  677. if (isset($_SESSION['return'])) {
  678. echo json_encode($_SESSION['return']);
  679. }
  680. else {
  681. echo json_encode(array(
  682. 'type' => 'success',
  683. 'msg' => 'Task completed'
  684. ));
  685. }
  686. }
  687. }
  688. else {
  689. echo json_encode(array(
  690. 'type' => 'error',
  691. 'msg' => 'Incomplete post data'
  692. ));
  693. }
  694. }
  695. else {
  696. echo json_encode(array(
  697. 'type' => 'error',
  698. 'msg' => 'Incomplete post data'
  699. ));
  700. }
  701. break;
  702. case "mailbox":
  703. if (isset($_POST['items']) && isset($_POST['attr'])) {
  704. $items = (array)json_decode($_POST['items'], true);
  705. $attr = (array)json_decode($_POST['attr'], true);
  706. $postarray = array_merge(array('username' => $items), $attr);
  707. if (is_array($postarray['username'])) {
  708. if (mailbox_edit_mailbox($postarray) === false) {
  709. if (isset($_SESSION['return'])) {
  710. echo json_encode($_SESSION['return']);
  711. }
  712. else {
  713. echo json_encode(array(
  714. 'type' => 'error',
  715. 'msg' => 'Edit failed'
  716. ));
  717. }
  718. exit();
  719. }
  720. else {
  721. if (isset($_SESSION['return'])) {
  722. echo json_encode($_SESSION['return']);
  723. }
  724. else {
  725. echo json_encode(array(
  726. 'type' => 'success',
  727. 'msg' => 'Task completed'
  728. ));
  729. }
  730. }
  731. }
  732. else {
  733. echo json_encode(array(
  734. 'type' => 'error',
  735. 'msg' => 'Incomplete post data'
  736. ));
  737. }
  738. }
  739. else {
  740. echo json_encode(array(
  741. 'type' => 'error',
  742. 'msg' => 'Incomplete post data'
  743. ));
  744. }
  745. break;
  746. case "resource":
  747. if (isset($_POST['items']) && isset($_POST['attr'])) {
  748. $items = (array)json_decode($_POST['items'], true);
  749. $attr = (array)json_decode($_POST['attr'], true);
  750. $postarray = array_merge(array('name' => $items), $attr);
  751. if (is_array($postarray['name'])) {
  752. if (mailbox_edit_resource($postarray) === false) {
  753. if (isset($_SESSION['return'])) {
  754. echo json_encode($_SESSION['return']);
  755. }
  756. else {
  757. echo json_encode(array(
  758. 'type' => 'error',
  759. 'msg' => 'Edit failed'
  760. ));
  761. }
  762. exit();
  763. }
  764. else {
  765. if (isset($_SESSION['return'])) {
  766. echo json_encode($_SESSION['return']);
  767. }
  768. else {
  769. echo json_encode(array(
  770. 'type' => 'success',
  771. 'msg' => 'Task completed'
  772. ));
  773. }
  774. }
  775. }
  776. else {
  777. echo json_encode(array(
  778. 'type' => 'error',
  779. 'msg' => 'Incomplete post data'
  780. ));
  781. }
  782. }
  783. else {
  784. echo json_encode(array(
  785. 'type' => 'error',
  786. 'msg' => 'Incomplete post data'
  787. ));
  788. }
  789. break;
  790. case "domain":
  791. if (isset($_POST['items']) && isset($_POST['attr'])) {
  792. $items = (array)json_decode($_POST['items'], true);
  793. $attr = (array)json_decode($_POST['attr'], true);
  794. $postarray = array_merge(array('domain' => $items), $attr);
  795. if (is_array($postarray['domain'])) {
  796. if (mailbox_edit_domain($postarray) === false) {
  797. if (isset($_SESSION['return'])) {
  798. echo json_encode($_SESSION['return']);
  799. }
  800. else {
  801. echo json_encode(array(
  802. 'type' => 'error',
  803. 'msg' => 'Edit failed'
  804. ));
  805. }
  806. exit();
  807. }
  808. else {
  809. if (isset($_SESSION['return'])) {
  810. echo json_encode($_SESSION['return']);
  811. }
  812. else {
  813. echo json_encode(array(
  814. 'type' => 'success',
  815. 'msg' => 'Task completed'
  816. ));
  817. }
  818. }
  819. }
  820. else {
  821. echo json_encode(array(
  822. 'type' => 'error',
  823. 'msg' => 'Incomplete post data'
  824. ));
  825. }
  826. }
  827. else {
  828. echo json_encode(array(
  829. 'type' => 'error',
  830. 'msg' => 'Incomplete post data'
  831. ));
  832. }
  833. break;
  834. case "alias-domain":
  835. if (isset($_POST['items']) && isset($_POST['attr'])) {
  836. $items = (array)json_decode($_POST['items'], true);
  837. $attr = (array)json_decode($_POST['attr'], true);
  838. $postarray = array_merge(array('alias_domain' => $items), $attr);
  839. if (is_array($postarray['alias_domain'])) {
  840. if (mailbox_edit_alias_domain($postarray) === false) {
  841. if (isset($_SESSION['return'])) {
  842. echo json_encode($_SESSION['return']);
  843. }
  844. else {
  845. echo json_encode(array(
  846. 'type' => 'error',
  847. 'msg' => 'Edit failed'
  848. ));
  849. }
  850. exit();
  851. }
  852. else {
  853. if (isset($_SESSION['return'])) {
  854. echo json_encode($_SESSION['return']);
  855. }
  856. else {
  857. echo json_encode(array(
  858. 'type' => 'success',
  859. 'msg' => 'Task completed'
  860. ));
  861. }
  862. }
  863. }
  864. else {
  865. echo json_encode(array(
  866. 'type' => 'error',
  867. 'msg' => 'Incomplete post data'
  868. ));
  869. }
  870. }
  871. else {
  872. echo json_encode(array(
  873. 'type' => 'error',
  874. 'msg' => 'Incomplete post data'
  875. ));
  876. }
  877. break;
  878. }
  879. break;
  880. }
  881. }
  882. }