json_api.php 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948
  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 "add":
  25. switch ($category) {
  26. case "time_limited_alias":
  27. if (isset($_POST['attr'])) {
  28. $attr = (array)json_decode($_POST['attr'], true);
  29. if (mailbox('add', 'time_limited_alias', $attr) === false) {
  30. if (isset($_SESSION['return'])) {
  31. echo json_encode($_SESSION['return']);
  32. }
  33. else {
  34. echo json_encode(array(
  35. 'type' => 'error',
  36. 'msg' => 'Cannot add item'
  37. ));
  38. }
  39. }
  40. else {
  41. if (isset($_SESSION['return'])) {
  42. echo json_encode($_SESSION['return']);
  43. }
  44. else {
  45. echo json_encode(array(
  46. 'type' => 'success',
  47. 'msg' => 'Task completed'
  48. ));
  49. }
  50. }
  51. }
  52. else {
  53. echo json_encode(array(
  54. 'type' => 'error',
  55. 'msg' => 'Cannot find attributes in post data'
  56. ));
  57. }
  58. break;
  59. case "mailbox":
  60. if (isset($_POST['attr'])) {
  61. $attr = (array)json_decode($_POST['attr'], true);
  62. if (mailbox('add', 'mailbox', $attr) === false) {
  63. if (isset($_SESSION['return'])) {
  64. echo json_encode($_SESSION['return']);
  65. }
  66. else {
  67. echo json_encode(array(
  68. 'type' => 'error',
  69. 'msg' => 'Cannot add item'
  70. ));
  71. }
  72. }
  73. else {
  74. if (isset($_SESSION['return'])) {
  75. echo json_encode($_SESSION['return']);
  76. }
  77. else {
  78. echo json_encode(array(
  79. 'type' => 'success',
  80. 'msg' => 'Task completed'
  81. ));
  82. }
  83. }
  84. }
  85. else {
  86. echo json_encode(array(
  87. 'type' => 'error',
  88. 'msg' => 'Cannot find attributes in post data'
  89. ));
  90. }
  91. break;
  92. case "domain":
  93. if (isset($_POST['attr'])) {
  94. $attr = (array)json_decode($_POST['attr'], true);
  95. if (mailbox('add', 'domain', $attr) === false) {
  96. if (isset($_SESSION['return'])) {
  97. echo json_encode($_SESSION['return']);
  98. }
  99. else {
  100. echo json_encode(array(
  101. 'type' => 'error',
  102. 'msg' => 'Cannot add item'
  103. ));
  104. }
  105. }
  106. else {
  107. if (isset($_SESSION['return'])) {
  108. echo json_encode($_SESSION['return']);
  109. }
  110. else {
  111. echo json_encode(array(
  112. 'type' => 'success',
  113. 'msg' => 'Task completed'
  114. ));
  115. }
  116. }
  117. }
  118. else {
  119. echo json_encode(array(
  120. 'type' => 'error',
  121. 'msg' => 'Cannot find attributes in post data'
  122. ));
  123. }
  124. break;
  125. case "resource":
  126. if (isset($_POST['attr'])) {
  127. $attr = (array)json_decode($_POST['attr'], true);
  128. if (mailbox('add', 'resource', $attr) === false) {
  129. if (isset($_SESSION['return'])) {
  130. echo json_encode($_SESSION['return']);
  131. }
  132. else {
  133. echo json_encode(array(
  134. 'type' => 'error',
  135. 'msg' => 'Cannot add item'
  136. ));
  137. }
  138. }
  139. else {
  140. if (isset($_SESSION['return'])) {
  141. echo json_encode($_SESSION['return']);
  142. }
  143. else {
  144. echo json_encode(array(
  145. 'type' => 'success',
  146. 'msg' => 'Task completed'
  147. ));
  148. }
  149. }
  150. }
  151. else {
  152. echo json_encode(array(
  153. 'type' => 'error',
  154. 'msg' => 'Cannot find attributes in post data'
  155. ));
  156. }
  157. break;
  158. case "alias":
  159. if (isset($_POST['attr'])) {
  160. $attr = (array)json_decode($_POST['attr'], true);
  161. if (mailbox('add', 'alias', $attr) === false) {
  162. if (isset($_SESSION['return'])) {
  163. echo json_encode($_SESSION['return']);
  164. }
  165. else {
  166. echo json_encode(array(
  167. 'type' => 'error',
  168. 'msg' => 'Cannot add item'
  169. ));
  170. }
  171. }
  172. else {
  173. if (isset($_SESSION['return'])) {
  174. echo json_encode($_SESSION['return']);
  175. }
  176. else {
  177. echo json_encode(array(
  178. 'type' => 'success',
  179. 'msg' => 'Task completed'
  180. ));
  181. }
  182. }
  183. }
  184. else {
  185. echo json_encode(array(
  186. 'type' => 'error',
  187. 'msg' => 'Cannot find attributes in post data'
  188. ));
  189. }
  190. break;
  191. case "syncjob":
  192. if (isset($_POST['attr'])) {
  193. $attr = (array)json_decode($_POST['attr'], true);
  194. if (mailbox('add', 'syncjob', $attr) === false) {
  195. if (isset($_SESSION['return'])) {
  196. echo json_encode($_SESSION['return']);
  197. }
  198. else {
  199. echo json_encode(array(
  200. 'type' => 'error',
  201. 'msg' => 'Cannot add item'
  202. ));
  203. }
  204. }
  205. else {
  206. if (isset($_SESSION['return'])) {
  207. echo json_encode($_SESSION['return']);
  208. }
  209. else {
  210. echo json_encode(array(
  211. 'type' => 'success',
  212. 'msg' => 'Task completed'
  213. ));
  214. }
  215. }
  216. }
  217. else {
  218. echo json_encode(array(
  219. 'type' => 'error',
  220. 'msg' => 'Cannot find attributes in post data'
  221. ));
  222. }
  223. break;
  224. case "domain-policy":
  225. if (isset($_POST['attr'])) {
  226. $attr = (array)json_decode($_POST['attr'], true);
  227. if (policy('add', 'domain', $attr) === false) {
  228. if (isset($_SESSION['return'])) {
  229. echo json_encode($_SESSION['return']);
  230. }
  231. else {
  232. echo json_encode(array(
  233. 'type' => 'error',
  234. 'msg' => 'Cannot add item'
  235. ));
  236. }
  237. }
  238. else {
  239. if (isset($_SESSION['return'])) {
  240. echo json_encode($_SESSION['return']);
  241. }
  242. else {
  243. echo json_encode(array(
  244. 'type' => 'success',
  245. 'msg' => 'Task completed'
  246. ));
  247. }
  248. }
  249. }
  250. else {
  251. echo json_encode(array(
  252. 'type' => 'error',
  253. 'msg' => 'Cannot find attributes in post data'
  254. ));
  255. }
  256. break;
  257. case "mailbox-policy":
  258. if (isset($_POST['attr'])) {
  259. $attr = (array)json_decode($_POST['attr'], true);
  260. if (policy('add', 'mailbox', $attr) === false) {
  261. if (isset($_SESSION['return'])) {
  262. echo json_encode($_SESSION['return']);
  263. }
  264. else {
  265. echo json_encode(array(
  266. 'type' => 'error',
  267. 'msg' => 'Cannot add item'
  268. ));
  269. }
  270. }
  271. else {
  272. if (isset($_SESSION['return'])) {
  273. echo json_encode($_SESSION['return']);
  274. }
  275. else {
  276. echo json_encode(array(
  277. 'type' => 'success',
  278. 'msg' => 'Task completed'
  279. ));
  280. }
  281. }
  282. }
  283. else {
  284. echo json_encode(array(
  285. 'type' => 'error',
  286. 'msg' => 'Cannot find attributes in post data'
  287. ));
  288. }
  289. break;
  290. case "alias-domain":
  291. if (isset($_POST['attr'])) {
  292. $attr = (array)json_decode($_POST['attr'], true);
  293. if (mailbox('add', 'alias_domain', $attr) === false) {
  294. if (isset($_SESSION['return'])) {
  295. echo json_encode($_SESSION['return']);
  296. }
  297. else {
  298. echo json_encode(array(
  299. 'type' => 'error',
  300. 'msg' => 'Cannot add item'
  301. ));
  302. }
  303. }
  304. else {
  305. if (isset($_SESSION['return'])) {
  306. echo json_encode($_SESSION['return']);
  307. }
  308. else {
  309. echo json_encode(array(
  310. 'type' => 'success',
  311. 'msg' => 'Task completed'
  312. ));
  313. }
  314. }
  315. }
  316. else {
  317. echo json_encode(array(
  318. 'type' => 'error',
  319. 'msg' => 'Cannot find attributes in post data'
  320. ));
  321. }
  322. break;
  323. case "fwdhost":
  324. if (isset($_POST['attr'])) {
  325. $attr = (array)json_decode($_POST['attr'], true);
  326. if (fwdhost('add', $attr) === false) {
  327. if (isset($_SESSION['return'])) {
  328. echo json_encode($_SESSION['return']);
  329. }
  330. else {
  331. echo json_encode(array(
  332. 'type' => 'error',
  333. 'msg' => 'Cannot add item'
  334. ));
  335. }
  336. }
  337. else {
  338. if (isset($_SESSION['return'])) {
  339. echo json_encode($_SESSION['return']);
  340. }
  341. else {
  342. echo json_encode(array(
  343. 'type' => 'success',
  344. 'msg' => 'Task completed'
  345. ));
  346. }
  347. }
  348. }
  349. else {
  350. echo json_encode(array(
  351. 'type' => 'error',
  352. 'msg' => 'Cannot find attributes in post data'
  353. ));
  354. }
  355. break;
  356. case "dkim":
  357. if (isset($_POST['attr'])) {
  358. $attr = (array)json_decode($_POST['attr'], true);
  359. if (dkim('add', $attr) === false) {
  360. if (isset($_SESSION['return'])) {
  361. echo json_encode($_SESSION['return']);
  362. }
  363. else {
  364. echo json_encode(array(
  365. 'type' => 'error',
  366. 'msg' => 'Cannot add item'
  367. ));
  368. }
  369. }
  370. else {
  371. if (isset($_SESSION['return'])) {
  372. echo json_encode($_SESSION['return']);
  373. }
  374. else {
  375. echo json_encode(array(
  376. 'type' => 'success',
  377. 'msg' => 'Task completed'
  378. ));
  379. }
  380. }
  381. }
  382. else {
  383. echo json_encode(array(
  384. 'type' => 'error',
  385. 'msg' => 'Cannot find attributes in post data'
  386. ));
  387. }
  388. break;
  389. case "domain-admin":
  390. if (isset($_POST['attr'])) {
  391. $attr = (array)json_decode($_POST['attr'], true);
  392. if (add_domain_admin($attr) === false) {
  393. if (isset($_SESSION['return'])) {
  394. echo json_encode($_SESSION['return']);
  395. }
  396. else {
  397. echo json_encode(array(
  398. 'type' => 'error',
  399. 'msg' => 'Cannot add item'
  400. ));
  401. }
  402. }
  403. else {
  404. if (isset($_SESSION['return'])) {
  405. echo json_encode($_SESSION['return']);
  406. }
  407. else {
  408. echo json_encode(array(
  409. 'type' => 'success',
  410. 'msg' => 'Task completed'
  411. ));
  412. }
  413. }
  414. }
  415. else {
  416. echo json_encode(array(
  417. 'type' => 'error',
  418. 'msg' => 'Cannot find attributes in post data'
  419. ));
  420. }
  421. break;
  422. }
  423. break;
  424. case "get":
  425. switch ($category) {
  426. case "domain":
  427. switch ($object) {
  428. case "all":
  429. $domains = mailbox('get', 'domains');
  430. if (!empty($domains)) {
  431. foreach ($domains as $domain) {
  432. if ($details = mailbox('get', 'domain_details', $domain)) {
  433. $data[] = $details;
  434. }
  435. else {
  436. continue;
  437. }
  438. }
  439. if (!isset($data) || empty($data)) {
  440. echo '{}';
  441. }
  442. else {
  443. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  444. }
  445. }
  446. else {
  447. echo '{}';
  448. }
  449. break;
  450. default:
  451. $data = mailbox('get', 'domain_details', $object);
  452. if (!isset($data) || empty($data)) {
  453. echo '{}';
  454. }
  455. else {
  456. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  457. }
  458. break;
  459. }
  460. break;
  461. case "logs":
  462. switch ($object) {
  463. case "dovecot":
  464. if (isset($extra) && !empty($extra)) {
  465. $extra = intval($extra);
  466. $logs = get_logs('dovecot-mailcow', $extra);
  467. }
  468. else {
  469. $logs = get_logs('dovecot-mailcow', -1);
  470. }
  471. if (isset($logs) && !empty($logs)) {
  472. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  473. }
  474. else {
  475. echo '{}';
  476. }
  477. break;
  478. case "postfix":
  479. if (isset($extra) && !empty($extra)) {
  480. $extra = intval($extra);
  481. $logs = get_logs('postfix-mailcow', $extra);
  482. }
  483. else {
  484. $logs = get_logs('postfix-mailcow', -1);
  485. }
  486. if (isset($logs) && !empty($logs)) {
  487. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  488. }
  489. else {
  490. echo '{}';
  491. }
  492. break;
  493. case "sogo":
  494. if (isset($extra) && !empty($extra)) {
  495. $extra = intval($extra);
  496. $logs = get_logs('sogo-mailcow', $extra);
  497. }
  498. else {
  499. $logs = get_logs('sogo-mailcow', -1);
  500. }
  501. if (isset($logs) && !empty($logs)) {
  502. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  503. }
  504. else {
  505. echo '{}';
  506. }
  507. break;
  508. case "rspamd-history":
  509. $logs = get_logs('rspamd-history');
  510. if (isset($logs) && !empty($logs)) {
  511. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  512. }
  513. else {
  514. echo '{}';
  515. }
  516. break;
  517. }
  518. break;
  519. case "mailbox":
  520. switch ($object) {
  521. case "all":
  522. $domains = mailbox('get', 'domains');
  523. if (!empty($domains)) {
  524. foreach ($domains as $domain) {
  525. $mailboxes = mailbox('get', 'mailboxes', $domain);
  526. if (!empty($mailboxes)) {
  527. foreach ($mailboxes as $mailbox) {
  528. if ($details = mailbox('get', 'mailbox_details', $mailbox)) {
  529. $data[] = $details;
  530. }
  531. else {
  532. continue;
  533. }
  534. }
  535. }
  536. }
  537. if (!isset($data) || empty($data)) {
  538. echo '{}';
  539. }
  540. else {
  541. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  542. }
  543. }
  544. else {
  545. echo '{}';
  546. }
  547. break;
  548. default:
  549. $data = mailbox('get', 'mailbox_details', $object);
  550. if (!isset($data) || empty($data)) {
  551. echo '{}';
  552. }
  553. else {
  554. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  555. }
  556. break;
  557. }
  558. break;
  559. case "syncjobs":
  560. switch ($object) {
  561. default:
  562. $data = mailbox('get', 'syncjobs', $object);
  563. if (!isset($data) || empty($data)) {
  564. echo '{}';
  565. }
  566. else {
  567. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  568. }
  569. break;
  570. }
  571. break;
  572. case "policy_wl_mailbox":
  573. switch ($object) {
  574. default:
  575. $data = policy('get', 'mailbox', $object)['whitelist'];
  576. if (!isset($data) || empty($data)) {
  577. echo '{}';
  578. }
  579. else {
  580. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  581. }
  582. break;
  583. }
  584. break;
  585. case "policy_bl_mailbox":
  586. switch ($object) {
  587. default:
  588. $data = policy('get', 'mailbox', $object)['blacklist'];
  589. if (!isset($data) || empty($data)) {
  590. echo '{}';
  591. }
  592. else {
  593. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  594. }
  595. break;
  596. }
  597. break;
  598. case "policy_wl_domain":
  599. switch ($object) {
  600. default:
  601. $data = policy('get', 'domain', $object)['whitelist'];
  602. if (!isset($data) || empty($data)) {
  603. echo '{}';
  604. }
  605. else {
  606. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  607. }
  608. break;
  609. }
  610. break;
  611. case "policy_bl_domain":
  612. switch ($object) {
  613. default:
  614. $data = policy('get', 'domain', $object)['blacklist'];
  615. if (!isset($data) || empty($data)) {
  616. echo '{}';
  617. }
  618. else {
  619. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  620. }
  621. break;
  622. }
  623. break;
  624. case "time_limited_aliases":
  625. switch ($object) {
  626. default:
  627. $data = mailbox('get', 'time_limited_aliases', $object);
  628. if (!isset($data) || empty($data)) {
  629. echo '{}';
  630. }
  631. else {
  632. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  633. }
  634. break;
  635. }
  636. break;
  637. case "resource":
  638. switch ($object) {
  639. case "all":
  640. $domains = mailbox('get', 'domains');
  641. if (!empty($domains)) {
  642. foreach ($domains as $domain) {
  643. $resources = mailbox('get', 'resources', $domain);
  644. if (!empty($resources)) {
  645. foreach ($resources as $resource) {
  646. if ($details = mailbox('get', 'resource_details', $resource)) {
  647. $data[] = $details;
  648. }
  649. else {
  650. continue;
  651. }
  652. }
  653. }
  654. }
  655. if (!isset($data) || empty($data)) {
  656. echo '{}';
  657. }
  658. else {
  659. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  660. }
  661. }
  662. else {
  663. echo '{}';
  664. }
  665. break;
  666. default:
  667. $data = mailbox('get', 'resource_details', $object);
  668. if (!isset($data) || empty($data)) {
  669. echo '{}';
  670. }
  671. else {
  672. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  673. }
  674. break;
  675. }
  676. break;
  677. case "fwdhost":
  678. switch ($object) {
  679. case "all":
  680. $data = fwdhost('get');
  681. if (!isset($data) || empty($data)) {
  682. echo '{}';
  683. }
  684. else {
  685. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  686. }
  687. break;
  688. default:
  689. $data = fwdhost('details', $object);
  690. if (!isset($data) || empty($data)) {
  691. echo '{}';
  692. }
  693. else {
  694. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  695. }
  696. break;
  697. }
  698. break;
  699. case "alias-domain":
  700. switch ($object) {
  701. case "all":
  702. $alias_domains = mailbox('get', 'alias_domains');
  703. if (!empty($alias_domains)) {
  704. foreach ($alias_domains as $alias_domain) {
  705. if ($details = mailbox('get', 'alias_domain_details', $alias_domain)) {
  706. $data[] = $details;
  707. }
  708. else {
  709. continue;
  710. }
  711. }
  712. }
  713. if (!isset($data) || empty($data)) {
  714. echo '{}';
  715. }
  716. else {
  717. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  718. }
  719. break;
  720. default:
  721. $data = mailbox('get', 'alias_domain_details', $object);
  722. if (!isset($data) || empty($data)) {
  723. echo '{}';
  724. }
  725. else {
  726. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  727. }
  728. break;
  729. }
  730. break;
  731. case "alias":
  732. switch ($object) {
  733. case "all":
  734. $domains = array_merge(mailbox('get', 'domains'),mailbox('get', 'alias_domains'));
  735. if (!empty($domains)) {
  736. foreach ($domains as $domain) {
  737. $aliases = mailbox('get', 'aliases', $domain);
  738. if (!empty($aliases)) {
  739. foreach ($aliases as $alias) {
  740. if ($details = mailbox('get', 'alias_details', $alias)) {
  741. $data[] = $details;
  742. }
  743. else {
  744. continue;
  745. }
  746. }
  747. }
  748. }
  749. if (!isset($data) || empty($data)) {
  750. echo '{}';
  751. }
  752. else {
  753. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  754. }
  755. }
  756. else {
  757. echo '{}';
  758. }
  759. break;
  760. default:
  761. $data = mailbox('get', 'alias_details', $object);
  762. if (!isset($data) || empty($data)) {
  763. echo '{}';
  764. }
  765. else {
  766. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  767. }
  768. break;
  769. }
  770. break;
  771. case "domain-admin":
  772. switch ($object) {
  773. case "all":
  774. $domain_admins = get_domain_admins();
  775. if (!empty($domain_admins)) {
  776. foreach ($domain_admins as $domain_admin) {
  777. if ($details = get_domain_admin_details($domain_admin)) {
  778. $data[] = $details;
  779. }
  780. else {
  781. continue;
  782. }
  783. }
  784. if (!isset($data) || empty($data)) {
  785. echo '{}';
  786. }
  787. else {
  788. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  789. }
  790. }
  791. else {
  792. echo '{}';
  793. }
  794. break;
  795. default:
  796. $data = get_domain_admin_details($object);
  797. if (!isset($data) || empty($data)) {
  798. echo '{}';
  799. }
  800. else {
  801. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  802. }
  803. break;
  804. }
  805. break;
  806. case "u2f-registration":
  807. header('Content-Type: application/javascript');
  808. if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
  809. $data = $u2f->getRegisterData(get_u2f_registrations($object));
  810. list($req, $sigs) = $data;
  811. $_SESSION['regReq'] = json_encode($req);
  812. echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';';
  813. }
  814. else {
  815. return;
  816. }
  817. break;
  818. case "u2f-authentication":
  819. header('Content-Type: application/javascript');
  820. if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
  821. $reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
  822. $_SESSION['authReq'] = $reqs;
  823. echo 'var req = ' . $reqs . ';';
  824. }
  825. else {
  826. return;
  827. }
  828. break;
  829. default:
  830. echo '{}';
  831. break;
  832. }
  833. break;
  834. case "delete":
  835. switch ($category) {
  836. case "alias":
  837. if (isset($_POST['items'])) {
  838. $items = (array)json_decode($_POST['items'], true);
  839. if (is_array($items)) {
  840. if (mailbox('delete', 'alias', array('address' => $items)) === 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' => 'Deletion of items/s failed'
  848. ));
  849. }
  850. }
  851. else {
  852. if (isset($_SESSION['return'])) {
  853. echo json_encode($_SESSION['return']);
  854. }
  855. else {
  856. echo json_encode(array(
  857. 'type' => 'success',
  858. 'msg' => 'Task completed'
  859. ));
  860. }
  861. }
  862. }
  863. else {
  864. echo json_encode(array(
  865. 'type' => 'error',
  866. 'msg' => 'Cannot find address array in post data'
  867. ));
  868. }
  869. }
  870. else {
  871. echo json_encode(array(
  872. 'type' => 'error',
  873. 'msg' => 'Cannot find items in post data'
  874. ));
  875. }
  876. break;
  877. case "syncjob":
  878. if (isset($_POST['items'])) {
  879. $items = (array)json_decode($_POST['items'], true);
  880. if (is_array($items)) {
  881. if (mailbox('delete', 'syncjob', array('id' => $items)) === false) {
  882. if (isset($_SESSION['return'])) {
  883. echo json_encode($_SESSION['return']);
  884. }
  885. else {
  886. echo json_encode(array(
  887. 'type' => 'error',
  888. 'msg' => 'Deletion of items/s failed'
  889. ));
  890. }
  891. }
  892. else {
  893. if (isset($_SESSION['return'])) {
  894. echo json_encode($_SESSION['return']);
  895. }
  896. else {
  897. echo json_encode(array(
  898. 'type' => 'success',
  899. 'msg' => 'Task completed'
  900. ));
  901. }
  902. }
  903. }
  904. else {
  905. echo json_encode(array(
  906. 'type' => 'error',
  907. 'msg' => 'Cannot find id array in post data'
  908. ));
  909. }
  910. }
  911. else {
  912. echo json_encode(array(
  913. 'type' => 'error',
  914. 'msg' => 'Cannot find items in post data'
  915. ));
  916. }
  917. break;
  918. case "fwdhost":
  919. if (isset($_POST['items'])) {
  920. $items = (array)json_decode($_POST['items'], true);
  921. if (is_array($items)) {
  922. if (fwdhost('delete', array('forwardinghost' => $items)) === false) {
  923. if (isset($_SESSION['return'])) {
  924. echo json_encode($_SESSION['return']);
  925. }
  926. else {
  927. echo json_encode(array(
  928. 'type' => 'error',
  929. 'msg' => 'Deletion of items/s failed'
  930. ));
  931. }
  932. }
  933. else {
  934. if (isset($_SESSION['return'])) {
  935. echo json_encode($_SESSION['return']);
  936. }
  937. else {
  938. echo json_encode(array(
  939. 'type' => 'success',
  940. 'msg' => 'Task completed'
  941. ));
  942. }
  943. }
  944. }
  945. else {
  946. echo json_encode(array(
  947. 'type' => 'error',
  948. 'msg' => 'Cannot find forwardinghost array in post data'
  949. ));
  950. }
  951. }
  952. else {
  953. echo json_encode(array(
  954. 'type' => 'error',
  955. 'msg' => 'Cannot find items in post data'
  956. ));
  957. }
  958. break;
  959. case "dkim":
  960. if (isset($_POST['items'])) {
  961. $items = (array)json_decode($_POST['items'], true);
  962. if (is_array($items)) {
  963. if (dkim('delete', array('domains' => $items)) === false) {
  964. if (isset($_SESSION['return'])) {
  965. echo json_encode($_SESSION['return']);
  966. }
  967. else {
  968. echo json_encode(array(
  969. 'type' => 'error',
  970. 'msg' => 'Deletion of items/s failed'
  971. ));
  972. }
  973. }
  974. else {
  975. if (isset($_SESSION['return'])) {
  976. echo json_encode($_SESSION['return']);
  977. }
  978. else {
  979. echo json_encode(array(
  980. 'type' => 'success',
  981. 'msg' => 'Task completed'
  982. ));
  983. }
  984. }
  985. }
  986. else {
  987. echo json_encode(array(
  988. 'type' => 'error',
  989. 'msg' => 'Cannot find domains array in post data'
  990. ));
  991. }
  992. }
  993. else {
  994. echo json_encode(array(
  995. 'type' => 'error',
  996. 'msg' => 'Cannot find items in post data'
  997. ));
  998. }
  999. break;
  1000. case "domain":
  1001. if (isset($_POST['items'])) {
  1002. $items = (array)json_decode($_POST['items'], true);
  1003. if (is_array($items)) {
  1004. if (mailbox('delete', 'domain', array('domain' => $items)) === false) {
  1005. if (isset($_SESSION['return'])) {
  1006. echo json_encode($_SESSION['return']);
  1007. }
  1008. else {
  1009. echo json_encode(array(
  1010. 'type' => 'error',
  1011. 'msg' => 'Task failed'
  1012. ));
  1013. }
  1014. }
  1015. else {
  1016. if (isset($_SESSION['return'])) {
  1017. echo json_encode($_SESSION['return']);
  1018. }
  1019. else {
  1020. echo json_encode(array(
  1021. 'type' => 'success',
  1022. 'msg' => 'Task completed'
  1023. ));
  1024. }
  1025. }
  1026. }
  1027. else {
  1028. echo json_encode(array(
  1029. 'type' => 'error',
  1030. 'msg' => 'Cannot find domain array in post data'
  1031. ));
  1032. }
  1033. }
  1034. else {
  1035. echo json_encode(array(
  1036. 'type' => 'error',
  1037. 'msg' => 'Cannot find items in post data'
  1038. ));
  1039. }
  1040. break;
  1041. case "alias-domain":
  1042. if (isset($_POST['items'])) {
  1043. $items = (array)json_decode($_POST['items'], true);
  1044. if (is_array($items)) {
  1045. if (mailbox('delete', 'alias_domain', array('alias_domain' => $items)) === false) {
  1046. if (isset($_SESSION['return'])) {
  1047. echo json_encode($_SESSION['return']);
  1048. }
  1049. else {
  1050. echo json_encode(array(
  1051. 'type' => 'error',
  1052. 'msg' => 'Task failed'
  1053. ));
  1054. }
  1055. }
  1056. else {
  1057. if (isset($_SESSION['return'])) {
  1058. echo json_encode($_SESSION['return']);
  1059. }
  1060. else {
  1061. echo json_encode(array(
  1062. 'type' => 'success',
  1063. 'msg' => 'Task completed'
  1064. ));
  1065. }
  1066. }
  1067. }
  1068. else {
  1069. echo json_encode(array(
  1070. 'type' => 'error',
  1071. 'msg' => 'Cannot find alias_domain array in post data'
  1072. ));
  1073. }
  1074. }
  1075. else {
  1076. echo json_encode(array(
  1077. 'type' => 'error',
  1078. 'msg' => 'Cannot find items in post data'
  1079. ));
  1080. }
  1081. break;
  1082. case "mailbox":
  1083. if (isset($_POST['items'])) {
  1084. $items = (array)json_decode($_POST['items'], true);
  1085. if (is_array($items)) {
  1086. if (mailbox('delete', 'mailbox', array('username' => $items)) === false) {
  1087. if (isset($_SESSION['return'])) {
  1088. echo json_encode($_SESSION['return']);
  1089. }
  1090. else {
  1091. echo json_encode(array(
  1092. 'type' => 'error',
  1093. 'msg' => 'Task failed'
  1094. ));
  1095. }
  1096. }
  1097. else {
  1098. if (isset($_SESSION['return'])) {
  1099. echo json_encode($_SESSION['return']);
  1100. }
  1101. else {
  1102. echo json_encode(array(
  1103. 'type' => 'success',
  1104. 'msg' => 'Task completed'
  1105. ));
  1106. }
  1107. }
  1108. }
  1109. else {
  1110. echo json_encode(array(
  1111. 'type' => 'error',
  1112. 'msg' => 'Cannot find username array in post data'
  1113. ));
  1114. }
  1115. }
  1116. else {
  1117. echo json_encode(array(
  1118. 'type' => 'error',
  1119. 'msg' => 'Cannot find items in post data'
  1120. ));
  1121. }
  1122. break;
  1123. case "resource":
  1124. if (isset($_POST['items'])) {
  1125. $items = (array)json_decode($_POST['items'], true);
  1126. if (is_array($items)) {
  1127. if (mailbox('delete', 'resource', array('name' => $items)) === false) {
  1128. if (isset($_SESSION['return'])) {
  1129. echo json_encode($_SESSION['return']);
  1130. }
  1131. else {
  1132. echo json_encode(array(
  1133. 'type' => 'error',
  1134. 'msg' => 'Task failed'
  1135. ));
  1136. }
  1137. }
  1138. else {
  1139. if (isset($_SESSION['return'])) {
  1140. echo json_encode($_SESSION['return']);
  1141. }
  1142. else {
  1143. echo json_encode(array(
  1144. 'type' => 'success',
  1145. 'msg' => 'Task completed'
  1146. ));
  1147. }
  1148. }
  1149. }
  1150. else {
  1151. echo json_encode(array(
  1152. 'type' => 'error',
  1153. 'msg' => 'Cannot find name array in post data'
  1154. ));
  1155. }
  1156. }
  1157. else {
  1158. echo json_encode(array(
  1159. 'type' => 'error',
  1160. 'msg' => 'Cannot find items in post data'
  1161. ));
  1162. }
  1163. break;
  1164. case "mailbox-policy":
  1165. if (isset($_POST['items'])) {
  1166. $items = (array)json_decode($_POST['items'], true);
  1167. if (is_array($items)) {
  1168. if (policy('delete', 'mailbox', array('prefid' => $items)) === false) {
  1169. if (isset($_SESSION['return'])) {
  1170. echo json_encode($_SESSION['return']);
  1171. }
  1172. else {
  1173. echo json_encode(array(
  1174. 'type' => 'error',
  1175. 'msg' => 'Task failed'
  1176. ));
  1177. }
  1178. }
  1179. else {
  1180. if (isset($_SESSION['return'])) {
  1181. echo json_encode($_SESSION['return']);
  1182. }
  1183. else {
  1184. echo json_encode(array(
  1185. 'type' => 'success',
  1186. 'msg' => 'Task completed'
  1187. ));
  1188. }
  1189. }
  1190. }
  1191. else {
  1192. echo json_encode(array(
  1193. 'type' => 'error',
  1194. 'msg' => 'Cannot find name array in post data'
  1195. ));
  1196. }
  1197. }
  1198. else {
  1199. echo json_encode(array(
  1200. 'type' => 'error',
  1201. 'msg' => 'Cannot find items in post data'
  1202. ));
  1203. }
  1204. break;
  1205. case "domain-policy":
  1206. if (isset($_POST['items'])) {
  1207. $items = (array)json_decode($_POST['items'], true);
  1208. if (is_array($items)) {
  1209. if (policy('delete', 'domain', array('prefid' => $items)) === false) {
  1210. if (isset($_SESSION['return'])) {
  1211. echo json_encode($_SESSION['return']);
  1212. }
  1213. else {
  1214. echo json_encode(array(
  1215. 'type' => 'error',
  1216. 'msg' => 'Task failed'
  1217. ));
  1218. }
  1219. }
  1220. else {
  1221. if (isset($_SESSION['return'])) {
  1222. echo json_encode($_SESSION['return']);
  1223. }
  1224. else {
  1225. echo json_encode(array(
  1226. 'type' => 'success',
  1227. 'msg' => 'Task completed'
  1228. ));
  1229. }
  1230. }
  1231. }
  1232. else {
  1233. echo json_encode(array(
  1234. 'type' => 'error',
  1235. 'msg' => 'Cannot find name array in post data'
  1236. ));
  1237. }
  1238. }
  1239. else {
  1240. echo json_encode(array(
  1241. 'type' => 'error',
  1242. 'msg' => 'Cannot find items in post data'
  1243. ));
  1244. }
  1245. break;
  1246. case "time_limited_alias":
  1247. if (isset($_POST['items'])) {
  1248. $items = (array)json_decode($_POST['items'], true);
  1249. if (is_array($items)) {
  1250. if (mailbox('delete', 'time_limited_alias', array('address' => $items)) === false) {
  1251. if (isset($_SESSION['return'])) {
  1252. echo json_encode($_SESSION['return']);
  1253. }
  1254. else {
  1255. echo json_encode(array(
  1256. 'type' => 'error',
  1257. 'msg' => 'Task failed'
  1258. ));
  1259. }
  1260. }
  1261. else {
  1262. if (isset($_SESSION['return'])) {
  1263. echo json_encode($_SESSION['return']);
  1264. }
  1265. else {
  1266. echo json_encode(array(
  1267. 'type' => 'success',
  1268. 'msg' => 'Task completed'
  1269. ));
  1270. }
  1271. }
  1272. }
  1273. else {
  1274. echo json_encode(array(
  1275. 'type' => 'error',
  1276. 'msg' => 'Cannot find name array in post data'
  1277. ));
  1278. }
  1279. }
  1280. else {
  1281. echo json_encode(array(
  1282. 'type' => 'error',
  1283. 'msg' => 'Cannot find items in post data'
  1284. ));
  1285. }
  1286. break;
  1287. case "eas_cache":
  1288. if (isset($_POST['items'])) {
  1289. $items = (array)json_decode($_POST['items'], true);
  1290. if (is_array($items)) {
  1291. if (mailbox('delete', 'eas_cache', array('username' => $items)) === false) {
  1292. if (isset($_SESSION['return'])) {
  1293. echo json_encode($_SESSION['return']);
  1294. }
  1295. else {
  1296. echo json_encode(array(
  1297. 'type' => 'error',
  1298. 'msg' => 'Task failed'
  1299. ));
  1300. }
  1301. }
  1302. else {
  1303. if (isset($_SESSION['return'])) {
  1304. echo json_encode($_SESSION['return']);
  1305. }
  1306. else {
  1307. echo json_encode(array(
  1308. 'type' => 'success',
  1309. 'msg' => 'Task completed'
  1310. ));
  1311. }
  1312. }
  1313. }
  1314. else {
  1315. echo json_encode(array(
  1316. 'type' => 'error',
  1317. 'msg' => 'Cannot find name array in post data'
  1318. ));
  1319. }
  1320. }
  1321. else {
  1322. echo json_encode(array(
  1323. 'type' => 'error',
  1324. 'msg' => 'Cannot find items in post data'
  1325. ));
  1326. }
  1327. break;
  1328. case "domain-admin":
  1329. if (isset($_POST['items'])) {
  1330. $items = (array)json_decode($_POST['items'], true);
  1331. if (is_array($items)) {
  1332. if (delete_domain_admin(array('username' => $items)) === false) {
  1333. if (isset($_SESSION['return'])) {
  1334. echo json_encode($_SESSION['return']);
  1335. }
  1336. else {
  1337. echo json_encode(array(
  1338. 'type' => 'error',
  1339. 'msg' => 'Task failed'
  1340. ));
  1341. }
  1342. }
  1343. else {
  1344. if (isset($_SESSION['return'])) {
  1345. echo json_encode($_SESSION['return']);
  1346. }
  1347. else {
  1348. echo json_encode(array(
  1349. 'type' => 'success',
  1350. 'msg' => 'Task completed'
  1351. ));
  1352. }
  1353. }
  1354. }
  1355. else {
  1356. echo json_encode(array(
  1357. 'type' => 'error',
  1358. 'msg' => 'Cannot find name array in post data'
  1359. ));
  1360. }
  1361. }
  1362. else {
  1363. echo json_encode(array(
  1364. 'type' => 'error',
  1365. 'msg' => 'Cannot find items in post data'
  1366. ));
  1367. }
  1368. break;
  1369. }
  1370. break;
  1371. case "edit":
  1372. switch ($category) {
  1373. case "alias":
  1374. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1375. $items = (array)json_decode($_POST['items'], true);
  1376. $attr = (array)json_decode($_POST['attr'], true);
  1377. $postarray = array_merge(array('address' => $items), $attr);
  1378. if (is_array($postarray['address'])) {
  1379. if (mailbox('edit', 'alias', $postarray) === false) {
  1380. if (isset($_SESSION['return'])) {
  1381. echo json_encode($_SESSION['return']);
  1382. }
  1383. else {
  1384. echo json_encode(array(
  1385. 'type' => 'error',
  1386. 'msg' => 'Edit failed'
  1387. ));
  1388. }
  1389. exit();
  1390. }
  1391. else {
  1392. if (isset($_SESSION['return'])) {
  1393. echo json_encode($_SESSION['return']);
  1394. }
  1395. else {
  1396. echo json_encode(array(
  1397. 'type' => 'success',
  1398. 'msg' => 'Task completed'
  1399. ));
  1400. }
  1401. }
  1402. }
  1403. else {
  1404. echo json_encode(array(
  1405. 'type' => 'error',
  1406. 'msg' => 'Incomplete post data'
  1407. ));
  1408. }
  1409. }
  1410. else {
  1411. echo json_encode(array(
  1412. 'type' => 'error',
  1413. 'msg' => 'Incomplete post data'
  1414. ));
  1415. }
  1416. break;
  1417. case "delimiter_action":
  1418. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1419. $items = (array)json_decode($_POST['items'], true);
  1420. $attr = (array)json_decode($_POST['attr'], true);
  1421. $postarray = array_merge(array('username' => $items), $attr);
  1422. if (is_array($postarray['username'])) {
  1423. if (mailbox('edit', 'delimiter_action', $postarray) === false) {
  1424. if (isset($_SESSION['return'])) {
  1425. echo json_encode($_SESSION['return']);
  1426. }
  1427. else {
  1428. echo json_encode(array(
  1429. 'type' => 'error',
  1430. 'msg' => 'Edit failed'
  1431. ));
  1432. }
  1433. exit();
  1434. }
  1435. else {
  1436. if (isset($_SESSION['return'])) {
  1437. echo json_encode($_SESSION['return']);
  1438. }
  1439. else {
  1440. echo json_encode(array(
  1441. 'type' => 'success',
  1442. 'msg' => 'Task completed'
  1443. ));
  1444. }
  1445. }
  1446. }
  1447. else {
  1448. echo json_encode(array(
  1449. 'type' => 'error',
  1450. 'msg' => 'Incomplete post data'
  1451. ));
  1452. }
  1453. }
  1454. else {
  1455. echo json_encode(array(
  1456. 'type' => 'error',
  1457. 'msg' => 'Incomplete post data'
  1458. ));
  1459. }
  1460. break;
  1461. case "tls_policy":
  1462. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1463. $items = (array)json_decode($_POST['items'], true);
  1464. $attr = (array)json_decode($_POST['attr'], true);
  1465. $postarray = array_merge(array('username' => $items), $attr);
  1466. if (is_array($postarray['username'])) {
  1467. if (mailbox('edit', 'tls_policy', $postarray) === false) {
  1468. if (isset($_SESSION['return'])) {
  1469. echo json_encode($_SESSION['return']);
  1470. }
  1471. else {
  1472. echo json_encode(array(
  1473. 'type' => 'error',
  1474. 'msg' => 'Edit failed'
  1475. ));
  1476. }
  1477. exit();
  1478. }
  1479. else {
  1480. if (isset($_SESSION['return'])) {
  1481. echo json_encode($_SESSION['return']);
  1482. }
  1483. else {
  1484. echo json_encode(array(
  1485. 'type' => 'success',
  1486. 'msg' => 'Task completed'
  1487. ));
  1488. }
  1489. }
  1490. }
  1491. else {
  1492. echo json_encode(array(
  1493. 'type' => 'error',
  1494. 'msg' => 'Incomplete post data'
  1495. ));
  1496. }
  1497. }
  1498. else {
  1499. echo json_encode(array(
  1500. 'type' => 'error',
  1501. 'msg' => 'Incomplete post data'
  1502. ));
  1503. }
  1504. break;
  1505. case "time_limited_alias":
  1506. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1507. $items = (array)json_decode($_POST['items'], true);
  1508. $attr = (array)json_decode($_POST['attr'], true);
  1509. $postarray = array_merge(array('address' => $items), $attr);
  1510. if (is_array($postarray['address'])) {
  1511. if (mailbox('edit', 'time_limited_alias', $postarray) === false) {
  1512. if (isset($_SESSION['return'])) {
  1513. echo json_encode($_SESSION['return']);
  1514. }
  1515. else {
  1516. echo json_encode(array(
  1517. 'type' => 'error',
  1518. 'msg' => 'Edit failed'
  1519. ));
  1520. }
  1521. exit();
  1522. }
  1523. else {
  1524. if (isset($_SESSION['return'])) {
  1525. echo json_encode($_SESSION['return']);
  1526. }
  1527. else {
  1528. echo json_encode(array(
  1529. 'type' => 'success',
  1530. 'msg' => 'Task completed'
  1531. ));
  1532. }
  1533. }
  1534. }
  1535. else {
  1536. echo json_encode(array(
  1537. 'type' => 'error',
  1538. 'msg' => 'Incomplete post data'
  1539. ));
  1540. }
  1541. }
  1542. else {
  1543. echo json_encode(array(
  1544. 'type' => 'error',
  1545. 'msg' => 'Incomplete post data'
  1546. ));
  1547. }
  1548. break;
  1549. case "mailbox":
  1550. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1551. $items = (array)json_decode($_POST['items'], true);
  1552. $attr = (array)json_decode($_POST['attr'], true);
  1553. $postarray = array_merge(array('username' => $items), $attr);
  1554. if (is_array($postarray['username'])) {
  1555. if (mailbox('edit', 'mailbox', $postarray) === false) {
  1556. if (isset($_SESSION['return'])) {
  1557. echo json_encode($_SESSION['return']);
  1558. }
  1559. else {
  1560. echo json_encode(array(
  1561. 'type' => 'error',
  1562. 'msg' => 'Edit failed'
  1563. ));
  1564. }
  1565. exit();
  1566. }
  1567. else {
  1568. if (isset($_SESSION['return'])) {
  1569. echo json_encode($_SESSION['return']);
  1570. }
  1571. else {
  1572. echo json_encode(array(
  1573. 'type' => 'success',
  1574. 'msg' => 'Task completed'
  1575. ));
  1576. }
  1577. }
  1578. }
  1579. else {
  1580. echo json_encode(array(
  1581. 'type' => 'error',
  1582. 'msg' => 'Incomplete post data'
  1583. ));
  1584. }
  1585. }
  1586. else {
  1587. echo json_encode(array(
  1588. 'type' => 'error',
  1589. 'msg' => 'Incomplete post data'
  1590. ));
  1591. }
  1592. break;
  1593. case "syncjob":
  1594. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1595. $items = (array)json_decode($_POST['items'], true);
  1596. $attr = (array)json_decode($_POST['attr'], true);
  1597. $postarray = array_merge(array('id' => $items), $attr);
  1598. if (is_array($postarray['id'])) {
  1599. if (mailbox('edit', 'syncjob', $postarray) === false) {
  1600. if (isset($_SESSION['return'])) {
  1601. echo json_encode($_SESSION['return']);
  1602. }
  1603. else {
  1604. echo json_encode(array(
  1605. 'type' => 'error',
  1606. 'msg' => 'Edit failed'
  1607. ));
  1608. }
  1609. exit();
  1610. }
  1611. else {
  1612. if (isset($_SESSION['return'])) {
  1613. echo json_encode($_SESSION['return']);
  1614. }
  1615. else {
  1616. echo json_encode(array(
  1617. 'type' => 'success',
  1618. 'msg' => 'Task completed'
  1619. ));
  1620. }
  1621. }
  1622. }
  1623. else {
  1624. echo json_encode(array(
  1625. 'type' => 'error',
  1626. 'msg' => 'Incomplete post data'
  1627. ));
  1628. }
  1629. }
  1630. else {
  1631. echo json_encode(array(
  1632. 'type' => 'error',
  1633. 'msg' => 'Incomplete post data'
  1634. ));
  1635. }
  1636. break;
  1637. case "resource":
  1638. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1639. $items = (array)json_decode($_POST['items'], true);
  1640. $attr = (array)json_decode($_POST['attr'], true);
  1641. $postarray = array_merge(array('name' => $items), $attr);
  1642. if (is_array($postarray['name'])) {
  1643. if (mailbox('edit', 'resource', $postarray) === false) {
  1644. if (isset($_SESSION['return'])) {
  1645. echo json_encode($_SESSION['return']);
  1646. }
  1647. else {
  1648. echo json_encode(array(
  1649. 'type' => 'error',
  1650. 'msg' => 'Edit failed'
  1651. ));
  1652. }
  1653. exit();
  1654. }
  1655. else {
  1656. if (isset($_SESSION['return'])) {
  1657. echo json_encode($_SESSION['return']);
  1658. }
  1659. else {
  1660. echo json_encode(array(
  1661. 'type' => 'success',
  1662. 'msg' => 'Task completed'
  1663. ));
  1664. }
  1665. }
  1666. }
  1667. else {
  1668. echo json_encode(array(
  1669. 'type' => 'error',
  1670. 'msg' => 'Incomplete post data'
  1671. ));
  1672. }
  1673. }
  1674. else {
  1675. echo json_encode(array(
  1676. 'type' => 'error',
  1677. 'msg' => 'Incomplete post data'
  1678. ));
  1679. }
  1680. break;
  1681. case "domain":
  1682. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1683. $items = (array)json_decode($_POST['items'], true);
  1684. $attr = (array)json_decode($_POST['attr'], true);
  1685. $postarray = array_merge(array('domain' => $items), $attr);
  1686. if (is_array($postarray['domain'])) {
  1687. if (mailbox('edit', 'domain', $postarray) === false) {
  1688. if (isset($_SESSION['return'])) {
  1689. echo json_encode($_SESSION['return']);
  1690. }
  1691. else {
  1692. echo json_encode(array(
  1693. 'type' => 'error',
  1694. 'msg' => 'Edit failed'
  1695. ));
  1696. }
  1697. exit();
  1698. }
  1699. else {
  1700. if (isset($_SESSION['return'])) {
  1701. echo json_encode($_SESSION['return']);
  1702. }
  1703. else {
  1704. echo json_encode(array(
  1705. 'type' => 'success',
  1706. 'msg' => 'Task completed'
  1707. ));
  1708. }
  1709. }
  1710. }
  1711. else {
  1712. echo json_encode(array(
  1713. 'type' => 'error',
  1714. 'msg' => 'Incomplete post data'
  1715. ));
  1716. }
  1717. }
  1718. else {
  1719. echo json_encode(array(
  1720. 'type' => 'error',
  1721. 'msg' => 'Incomplete post data'
  1722. ));
  1723. }
  1724. break;
  1725. case "alias-domain":
  1726. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1727. $items = (array)json_decode($_POST['items'], true);
  1728. $attr = (array)json_decode($_POST['attr'], true);
  1729. $postarray = array_merge(array('alias_domain' => $items), $attr);
  1730. if (is_array($postarray['alias_domain'])) {
  1731. if (mailbox('edit', 'alias_domain', $postarray) === false) {
  1732. if (isset($_SESSION['return'])) {
  1733. echo json_encode($_SESSION['return']);
  1734. }
  1735. else {
  1736. echo json_encode(array(
  1737. 'type' => 'error',
  1738. 'msg' => 'Edit failed'
  1739. ));
  1740. }
  1741. exit();
  1742. }
  1743. else {
  1744. if (isset($_SESSION['return'])) {
  1745. echo json_encode($_SESSION['return']);
  1746. }
  1747. else {
  1748. echo json_encode(array(
  1749. 'type' => 'success',
  1750. 'msg' => 'Task completed'
  1751. ));
  1752. }
  1753. }
  1754. }
  1755. else {
  1756. echo json_encode(array(
  1757. 'type' => 'error',
  1758. 'msg' => 'Incomplete post data'
  1759. ));
  1760. }
  1761. }
  1762. else {
  1763. echo json_encode(array(
  1764. 'type' => 'error',
  1765. 'msg' => 'Incomplete post data'
  1766. ));
  1767. }
  1768. break;
  1769. case "spam_score":
  1770. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1771. $items = (array)json_decode($_POST['items'], true);
  1772. $attr = (array)json_decode($_POST['attr'], true);
  1773. $postarray = array_merge(array('username' => $items), $attr);
  1774. if (is_array($postarray['username'])) {
  1775. if (mailbox('edit', 'spam_score', $postarray) === false) {
  1776. if (isset($_SESSION['return'])) {
  1777. echo json_encode($_SESSION['return']);
  1778. }
  1779. else {
  1780. echo json_encode(array(
  1781. 'type' => 'error',
  1782. 'msg' => 'Edit failed'
  1783. ));
  1784. }
  1785. exit();
  1786. }
  1787. else {
  1788. if (isset($_SESSION['return'])) {
  1789. echo json_encode($_SESSION['return']);
  1790. }
  1791. else {
  1792. echo json_encode(array(
  1793. 'type' => 'success',
  1794. 'msg' => 'Task completed'
  1795. ));
  1796. }
  1797. }
  1798. }
  1799. else {
  1800. echo json_encode(array(
  1801. 'type' => 'error',
  1802. 'msg' => 'Incomplete post data'
  1803. ));
  1804. }
  1805. }
  1806. else {
  1807. echo json_encode(array(
  1808. 'type' => 'error',
  1809. 'msg' => 'Incomplete post data'
  1810. ));
  1811. }
  1812. break;
  1813. case "domain-admin":
  1814. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1815. $items = (array)json_decode($_POST['items'], true);
  1816. $attr = (array)json_decode($_POST['attr'], true);
  1817. $postarray = array_merge(array('username' => $items), $attr);
  1818. if (is_array($postarray['username'])) {
  1819. if (edit_domain_admin($postarray) === false) {
  1820. if (isset($_SESSION['return'])) {
  1821. echo json_encode($_SESSION['return']);
  1822. }
  1823. else {
  1824. echo json_encode(array(
  1825. 'type' => 'error',
  1826. 'msg' => 'Edit failed'
  1827. ));
  1828. }
  1829. exit();
  1830. }
  1831. else {
  1832. if (isset($_SESSION['return'])) {
  1833. echo json_encode($_SESSION['return']);
  1834. }
  1835. else {
  1836. echo json_encode(array(
  1837. 'type' => 'success',
  1838. 'msg' => 'Task completed'
  1839. ));
  1840. }
  1841. }
  1842. }
  1843. else {
  1844. echo json_encode(array(
  1845. 'type' => 'error',
  1846. 'msg' => 'Incomplete post data'
  1847. ));
  1848. }
  1849. }
  1850. else {
  1851. echo json_encode(array(
  1852. 'type' => 'error',
  1853. 'msg' => 'Incomplete post data'
  1854. ));
  1855. }
  1856. break;
  1857. case "fwdhost":
  1858. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1859. $items = (array)json_decode($_POST['items'], true);
  1860. $attr = (array)json_decode($_POST['attr'], true);
  1861. $postarray = array_merge(array('fwdhost' => $items), $attr);
  1862. if (is_array($postarray['fwdhost'])) {
  1863. if (fwdhost('edit', $postarray) === false) {
  1864. if (isset($_SESSION['return'])) {
  1865. echo json_encode($_SESSION['return']);
  1866. }
  1867. else {
  1868. echo json_encode(array(
  1869. 'type' => 'error',
  1870. 'msg' => 'Edit failed'
  1871. ));
  1872. }
  1873. exit();
  1874. }
  1875. else {
  1876. if (isset($_SESSION['return'])) {
  1877. echo json_encode($_SESSION['return']);
  1878. }
  1879. else {
  1880. echo json_encode(array(
  1881. 'type' => 'success',
  1882. 'msg' => 'Task completed'
  1883. ));
  1884. }
  1885. }
  1886. }
  1887. else {
  1888. echo json_encode(array(
  1889. 'type' => 'error',
  1890. 'msg' => 'Incomplete post data'
  1891. ));
  1892. }
  1893. }
  1894. else {
  1895. echo json_encode(array(
  1896. 'type' => 'error',
  1897. 'msg' => 'Incomplete post data'
  1898. ));
  1899. }
  1900. break;
  1901. case "admin":
  1902. // No items as there is only one admin
  1903. if (isset($_POST['attr'])) {
  1904. $attr = (array)json_decode($_POST['attr'], true);
  1905. if (edit_admin_account($attr) === false) {
  1906. if (isset($_SESSION['return'])) {
  1907. echo json_encode($_SESSION['return']);
  1908. }
  1909. else {
  1910. echo json_encode(array(
  1911. 'type' => 'error',
  1912. 'msg' => 'Edit failed'
  1913. ));
  1914. }
  1915. exit();
  1916. }
  1917. else {
  1918. if (isset($_SESSION['return'])) {
  1919. echo json_encode($_SESSION['return']);
  1920. }
  1921. else {
  1922. echo json_encode(array(
  1923. 'type' => 'success',
  1924. 'msg' => 'Task completed'
  1925. ));
  1926. }
  1927. }
  1928. }
  1929. else {
  1930. echo json_encode(array(
  1931. 'type' => 'error',
  1932. 'msg' => 'Incomplete post data'
  1933. ));
  1934. }
  1935. break;
  1936. }
  1937. break;
  1938. }
  1939. }
  1940. }