json_api.php 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963
  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 "fail2ban":
  479. if (isset($extra) && !empty($extra)) {
  480. $extra = intval($extra);
  481. $logs = get_logs('fail2ban-mailcow', $extra);
  482. }
  483. else {
  484. $logs = get_logs('fail2ban-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 "postfix":
  494. if (isset($extra) && !empty($extra)) {
  495. $extra = intval($extra);
  496. $logs = get_logs('postfix-mailcow', $extra);
  497. }
  498. else {
  499. $logs = get_logs('postfix-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 "sogo":
  509. if (isset($extra) && !empty($extra)) {
  510. $extra = intval($extra);
  511. $logs = get_logs('sogo-mailcow', $extra);
  512. }
  513. else {
  514. $logs = get_logs('sogo-mailcow', -1);
  515. }
  516. if (isset($logs) && !empty($logs)) {
  517. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  518. }
  519. else {
  520. echo '{}';
  521. }
  522. break;
  523. case "rspamd-history":
  524. $logs = get_logs('rspamd-history');
  525. if (isset($logs) && !empty($logs)) {
  526. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  527. }
  528. else {
  529. echo '{}';
  530. }
  531. break;
  532. }
  533. break;
  534. case "mailbox":
  535. switch ($object) {
  536. case "all":
  537. $domains = mailbox('get', 'domains');
  538. if (!empty($domains)) {
  539. foreach ($domains as $domain) {
  540. $mailboxes = mailbox('get', 'mailboxes', $domain);
  541. if (!empty($mailboxes)) {
  542. foreach ($mailboxes as $mailbox) {
  543. if ($details = mailbox('get', 'mailbox_details', $mailbox)) {
  544. $data[] = $details;
  545. }
  546. else {
  547. continue;
  548. }
  549. }
  550. }
  551. }
  552. if (!isset($data) || empty($data)) {
  553. echo '{}';
  554. }
  555. else {
  556. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  557. }
  558. }
  559. else {
  560. echo '{}';
  561. }
  562. break;
  563. default:
  564. $data = mailbox('get', 'mailbox_details', $object);
  565. if (!isset($data) || empty($data)) {
  566. echo '{}';
  567. }
  568. else {
  569. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  570. }
  571. break;
  572. }
  573. break;
  574. case "syncjobs":
  575. switch ($object) {
  576. default:
  577. $data = mailbox('get', 'syncjobs', $object);
  578. if (!isset($data) || empty($data)) {
  579. echo '{}';
  580. }
  581. else {
  582. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  583. }
  584. break;
  585. }
  586. break;
  587. case "policy_wl_mailbox":
  588. switch ($object) {
  589. default:
  590. $data = policy('get', 'mailbox', $object)['whitelist'];
  591. if (!isset($data) || empty($data)) {
  592. echo '{}';
  593. }
  594. else {
  595. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  596. }
  597. break;
  598. }
  599. break;
  600. case "policy_bl_mailbox":
  601. switch ($object) {
  602. default:
  603. $data = policy('get', 'mailbox', $object)['blacklist'];
  604. if (!isset($data) || empty($data)) {
  605. echo '{}';
  606. }
  607. else {
  608. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  609. }
  610. break;
  611. }
  612. break;
  613. case "policy_wl_domain":
  614. switch ($object) {
  615. default:
  616. $data = policy('get', 'domain', $object)['whitelist'];
  617. if (!isset($data) || empty($data)) {
  618. echo '{}';
  619. }
  620. else {
  621. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  622. }
  623. break;
  624. }
  625. break;
  626. case "policy_bl_domain":
  627. switch ($object) {
  628. default:
  629. $data = policy('get', 'domain', $object)['blacklist'];
  630. if (!isset($data) || empty($data)) {
  631. echo '{}';
  632. }
  633. else {
  634. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  635. }
  636. break;
  637. }
  638. break;
  639. case "time_limited_aliases":
  640. switch ($object) {
  641. default:
  642. $data = mailbox('get', 'time_limited_aliases', $object);
  643. if (!isset($data) || empty($data)) {
  644. echo '{}';
  645. }
  646. else {
  647. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  648. }
  649. break;
  650. }
  651. break;
  652. case "resource":
  653. switch ($object) {
  654. case "all":
  655. $domains = mailbox('get', 'domains');
  656. if (!empty($domains)) {
  657. foreach ($domains as $domain) {
  658. $resources = mailbox('get', 'resources', $domain);
  659. if (!empty($resources)) {
  660. foreach ($resources as $resource) {
  661. if ($details = mailbox('get', 'resource_details', $resource)) {
  662. $data[] = $details;
  663. }
  664. else {
  665. continue;
  666. }
  667. }
  668. }
  669. }
  670. if (!isset($data) || empty($data)) {
  671. echo '{}';
  672. }
  673. else {
  674. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  675. }
  676. }
  677. else {
  678. echo '{}';
  679. }
  680. break;
  681. default:
  682. $data = mailbox('get', 'resource_details', $object);
  683. if (!isset($data) || empty($data)) {
  684. echo '{}';
  685. }
  686. else {
  687. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  688. }
  689. break;
  690. }
  691. break;
  692. case "fwdhost":
  693. switch ($object) {
  694. case "all":
  695. $data = fwdhost('get');
  696. if (!isset($data) || empty($data)) {
  697. echo '{}';
  698. }
  699. else {
  700. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  701. }
  702. break;
  703. default:
  704. $data = fwdhost('details', $object);
  705. if (!isset($data) || empty($data)) {
  706. echo '{}';
  707. }
  708. else {
  709. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  710. }
  711. break;
  712. }
  713. break;
  714. case "alias-domain":
  715. switch ($object) {
  716. case "all":
  717. $alias_domains = mailbox('get', 'alias_domains');
  718. if (!empty($alias_domains)) {
  719. foreach ($alias_domains as $alias_domain) {
  720. if ($details = mailbox('get', 'alias_domain_details', $alias_domain)) {
  721. $data[] = $details;
  722. }
  723. else {
  724. continue;
  725. }
  726. }
  727. }
  728. if (!isset($data) || empty($data)) {
  729. echo '{}';
  730. }
  731. else {
  732. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  733. }
  734. break;
  735. default:
  736. $data = mailbox('get', 'alias_domain_details', $object);
  737. if (!isset($data) || empty($data)) {
  738. echo '{}';
  739. }
  740. else {
  741. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  742. }
  743. break;
  744. }
  745. break;
  746. case "alias":
  747. switch ($object) {
  748. case "all":
  749. $domains = array_merge(mailbox('get', 'domains'),mailbox('get', 'alias_domains'));
  750. if (!empty($domains)) {
  751. foreach ($domains as $domain) {
  752. $aliases = mailbox('get', 'aliases', $domain);
  753. if (!empty($aliases)) {
  754. foreach ($aliases as $alias) {
  755. if ($details = mailbox('get', 'alias_details', $alias)) {
  756. $data[] = $details;
  757. }
  758. else {
  759. continue;
  760. }
  761. }
  762. }
  763. }
  764. if (!isset($data) || empty($data)) {
  765. echo '{}';
  766. }
  767. else {
  768. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  769. }
  770. }
  771. else {
  772. echo '{}';
  773. }
  774. break;
  775. default:
  776. $data = mailbox('get', 'alias_details', $object);
  777. if (!isset($data) || empty($data)) {
  778. echo '{}';
  779. }
  780. else {
  781. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  782. }
  783. break;
  784. }
  785. break;
  786. case "domain-admin":
  787. switch ($object) {
  788. case "all":
  789. $domain_admins = get_domain_admins();
  790. if (!empty($domain_admins)) {
  791. foreach ($domain_admins as $domain_admin) {
  792. if ($details = get_domain_admin_details($domain_admin)) {
  793. $data[] = $details;
  794. }
  795. else {
  796. continue;
  797. }
  798. }
  799. if (!isset($data) || empty($data)) {
  800. echo '{}';
  801. }
  802. else {
  803. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  804. }
  805. }
  806. else {
  807. echo '{}';
  808. }
  809. break;
  810. default:
  811. $data = get_domain_admin_details($object);
  812. if (!isset($data) || empty($data)) {
  813. echo '{}';
  814. }
  815. else {
  816. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  817. }
  818. break;
  819. }
  820. break;
  821. case "u2f-registration":
  822. header('Content-Type: application/javascript');
  823. if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
  824. $data = $u2f->getRegisterData(get_u2f_registrations($object));
  825. list($req, $sigs) = $data;
  826. $_SESSION['regReq'] = json_encode($req);
  827. echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';';
  828. }
  829. else {
  830. return;
  831. }
  832. break;
  833. case "u2f-authentication":
  834. header('Content-Type: application/javascript');
  835. if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
  836. $reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
  837. $_SESSION['authReq'] = $reqs;
  838. echo 'var req = ' . $reqs . ';';
  839. }
  840. else {
  841. return;
  842. }
  843. break;
  844. default:
  845. echo '{}';
  846. break;
  847. }
  848. break;
  849. case "delete":
  850. switch ($category) {
  851. case "alias":
  852. if (isset($_POST['items'])) {
  853. $items = (array)json_decode($_POST['items'], true);
  854. if (is_array($items)) {
  855. if (mailbox('delete', 'alias', array('address' => $items)) === false) {
  856. if (isset($_SESSION['return'])) {
  857. echo json_encode($_SESSION['return']);
  858. }
  859. else {
  860. echo json_encode(array(
  861. 'type' => 'error',
  862. 'msg' => 'Deletion of items/s failed'
  863. ));
  864. }
  865. }
  866. else {
  867. if (isset($_SESSION['return'])) {
  868. echo json_encode($_SESSION['return']);
  869. }
  870. else {
  871. echo json_encode(array(
  872. 'type' => 'success',
  873. 'msg' => 'Task completed'
  874. ));
  875. }
  876. }
  877. }
  878. else {
  879. echo json_encode(array(
  880. 'type' => 'error',
  881. 'msg' => 'Cannot find address array in post data'
  882. ));
  883. }
  884. }
  885. else {
  886. echo json_encode(array(
  887. 'type' => 'error',
  888. 'msg' => 'Cannot find items in post data'
  889. ));
  890. }
  891. break;
  892. case "syncjob":
  893. if (isset($_POST['items'])) {
  894. $items = (array)json_decode($_POST['items'], true);
  895. if (is_array($items)) {
  896. if (mailbox('delete', 'syncjob', array('id' => $items)) === false) {
  897. if (isset($_SESSION['return'])) {
  898. echo json_encode($_SESSION['return']);
  899. }
  900. else {
  901. echo json_encode(array(
  902. 'type' => 'error',
  903. 'msg' => 'Deletion of items/s failed'
  904. ));
  905. }
  906. }
  907. else {
  908. if (isset($_SESSION['return'])) {
  909. echo json_encode($_SESSION['return']);
  910. }
  911. else {
  912. echo json_encode(array(
  913. 'type' => 'success',
  914. 'msg' => 'Task completed'
  915. ));
  916. }
  917. }
  918. }
  919. else {
  920. echo json_encode(array(
  921. 'type' => 'error',
  922. 'msg' => 'Cannot find id array in post data'
  923. ));
  924. }
  925. }
  926. else {
  927. echo json_encode(array(
  928. 'type' => 'error',
  929. 'msg' => 'Cannot find items in post data'
  930. ));
  931. }
  932. break;
  933. case "fwdhost":
  934. if (isset($_POST['items'])) {
  935. $items = (array)json_decode($_POST['items'], true);
  936. if (is_array($items)) {
  937. if (fwdhost('delete', array('forwardinghost' => $items)) === false) {
  938. if (isset($_SESSION['return'])) {
  939. echo json_encode($_SESSION['return']);
  940. }
  941. else {
  942. echo json_encode(array(
  943. 'type' => 'error',
  944. 'msg' => 'Deletion of items/s failed'
  945. ));
  946. }
  947. }
  948. else {
  949. if (isset($_SESSION['return'])) {
  950. echo json_encode($_SESSION['return']);
  951. }
  952. else {
  953. echo json_encode(array(
  954. 'type' => 'success',
  955. 'msg' => 'Task completed'
  956. ));
  957. }
  958. }
  959. }
  960. else {
  961. echo json_encode(array(
  962. 'type' => 'error',
  963. 'msg' => 'Cannot find forwardinghost array in post data'
  964. ));
  965. }
  966. }
  967. else {
  968. echo json_encode(array(
  969. 'type' => 'error',
  970. 'msg' => 'Cannot find items in post data'
  971. ));
  972. }
  973. break;
  974. case "dkim":
  975. if (isset($_POST['items'])) {
  976. $items = (array)json_decode($_POST['items'], true);
  977. if (is_array($items)) {
  978. if (dkim('delete', array('domains' => $items)) === false) {
  979. if (isset($_SESSION['return'])) {
  980. echo json_encode($_SESSION['return']);
  981. }
  982. else {
  983. echo json_encode(array(
  984. 'type' => 'error',
  985. 'msg' => 'Deletion of items/s failed'
  986. ));
  987. }
  988. }
  989. else {
  990. if (isset($_SESSION['return'])) {
  991. echo json_encode($_SESSION['return']);
  992. }
  993. else {
  994. echo json_encode(array(
  995. 'type' => 'success',
  996. 'msg' => 'Task completed'
  997. ));
  998. }
  999. }
  1000. }
  1001. else {
  1002. echo json_encode(array(
  1003. 'type' => 'error',
  1004. 'msg' => 'Cannot find domains array in post data'
  1005. ));
  1006. }
  1007. }
  1008. else {
  1009. echo json_encode(array(
  1010. 'type' => 'error',
  1011. 'msg' => 'Cannot find items in post data'
  1012. ));
  1013. }
  1014. break;
  1015. case "domain":
  1016. if (isset($_POST['items'])) {
  1017. $items = (array)json_decode($_POST['items'], true);
  1018. if (is_array($items)) {
  1019. if (mailbox('delete', 'domain', array('domain' => $items)) === false) {
  1020. if (isset($_SESSION['return'])) {
  1021. echo json_encode($_SESSION['return']);
  1022. }
  1023. else {
  1024. echo json_encode(array(
  1025. 'type' => 'error',
  1026. 'msg' => 'Task failed'
  1027. ));
  1028. }
  1029. }
  1030. else {
  1031. if (isset($_SESSION['return'])) {
  1032. echo json_encode($_SESSION['return']);
  1033. }
  1034. else {
  1035. echo json_encode(array(
  1036. 'type' => 'success',
  1037. 'msg' => 'Task completed'
  1038. ));
  1039. }
  1040. }
  1041. }
  1042. else {
  1043. echo json_encode(array(
  1044. 'type' => 'error',
  1045. 'msg' => 'Cannot find domain array in post data'
  1046. ));
  1047. }
  1048. }
  1049. else {
  1050. echo json_encode(array(
  1051. 'type' => 'error',
  1052. 'msg' => 'Cannot find items in post data'
  1053. ));
  1054. }
  1055. break;
  1056. case "alias-domain":
  1057. if (isset($_POST['items'])) {
  1058. $items = (array)json_decode($_POST['items'], true);
  1059. if (is_array($items)) {
  1060. if (mailbox('delete', 'alias_domain', array('alias_domain' => $items)) === false) {
  1061. if (isset($_SESSION['return'])) {
  1062. echo json_encode($_SESSION['return']);
  1063. }
  1064. else {
  1065. echo json_encode(array(
  1066. 'type' => 'error',
  1067. 'msg' => 'Task failed'
  1068. ));
  1069. }
  1070. }
  1071. else {
  1072. if (isset($_SESSION['return'])) {
  1073. echo json_encode($_SESSION['return']);
  1074. }
  1075. else {
  1076. echo json_encode(array(
  1077. 'type' => 'success',
  1078. 'msg' => 'Task completed'
  1079. ));
  1080. }
  1081. }
  1082. }
  1083. else {
  1084. echo json_encode(array(
  1085. 'type' => 'error',
  1086. 'msg' => 'Cannot find alias_domain array in post data'
  1087. ));
  1088. }
  1089. }
  1090. else {
  1091. echo json_encode(array(
  1092. 'type' => 'error',
  1093. 'msg' => 'Cannot find items in post data'
  1094. ));
  1095. }
  1096. break;
  1097. case "mailbox":
  1098. if (isset($_POST['items'])) {
  1099. $items = (array)json_decode($_POST['items'], true);
  1100. if (is_array($items)) {
  1101. if (mailbox('delete', 'mailbox', array('username' => $items)) === false) {
  1102. if (isset($_SESSION['return'])) {
  1103. echo json_encode($_SESSION['return']);
  1104. }
  1105. else {
  1106. echo json_encode(array(
  1107. 'type' => 'error',
  1108. 'msg' => 'Task failed'
  1109. ));
  1110. }
  1111. }
  1112. else {
  1113. if (isset($_SESSION['return'])) {
  1114. echo json_encode($_SESSION['return']);
  1115. }
  1116. else {
  1117. echo json_encode(array(
  1118. 'type' => 'success',
  1119. 'msg' => 'Task completed'
  1120. ));
  1121. }
  1122. }
  1123. }
  1124. else {
  1125. echo json_encode(array(
  1126. 'type' => 'error',
  1127. 'msg' => 'Cannot find username array in post data'
  1128. ));
  1129. }
  1130. }
  1131. else {
  1132. echo json_encode(array(
  1133. 'type' => 'error',
  1134. 'msg' => 'Cannot find items in post data'
  1135. ));
  1136. }
  1137. break;
  1138. case "resource":
  1139. if (isset($_POST['items'])) {
  1140. $items = (array)json_decode($_POST['items'], true);
  1141. if (is_array($items)) {
  1142. if (mailbox('delete', 'resource', array('name' => $items)) === false) {
  1143. if (isset($_SESSION['return'])) {
  1144. echo json_encode($_SESSION['return']);
  1145. }
  1146. else {
  1147. echo json_encode(array(
  1148. 'type' => 'error',
  1149. 'msg' => 'Task failed'
  1150. ));
  1151. }
  1152. }
  1153. else {
  1154. if (isset($_SESSION['return'])) {
  1155. echo json_encode($_SESSION['return']);
  1156. }
  1157. else {
  1158. echo json_encode(array(
  1159. 'type' => 'success',
  1160. 'msg' => 'Task completed'
  1161. ));
  1162. }
  1163. }
  1164. }
  1165. else {
  1166. echo json_encode(array(
  1167. 'type' => 'error',
  1168. 'msg' => 'Cannot find name array in post data'
  1169. ));
  1170. }
  1171. }
  1172. else {
  1173. echo json_encode(array(
  1174. 'type' => 'error',
  1175. 'msg' => 'Cannot find items in post data'
  1176. ));
  1177. }
  1178. break;
  1179. case "mailbox-policy":
  1180. if (isset($_POST['items'])) {
  1181. $items = (array)json_decode($_POST['items'], true);
  1182. if (is_array($items)) {
  1183. if (policy('delete', 'mailbox', array('prefid' => $items)) === false) {
  1184. if (isset($_SESSION['return'])) {
  1185. echo json_encode($_SESSION['return']);
  1186. }
  1187. else {
  1188. echo json_encode(array(
  1189. 'type' => 'error',
  1190. 'msg' => 'Task failed'
  1191. ));
  1192. }
  1193. }
  1194. else {
  1195. if (isset($_SESSION['return'])) {
  1196. echo json_encode($_SESSION['return']);
  1197. }
  1198. else {
  1199. echo json_encode(array(
  1200. 'type' => 'success',
  1201. 'msg' => 'Task completed'
  1202. ));
  1203. }
  1204. }
  1205. }
  1206. else {
  1207. echo json_encode(array(
  1208. 'type' => 'error',
  1209. 'msg' => 'Cannot find name array in post data'
  1210. ));
  1211. }
  1212. }
  1213. else {
  1214. echo json_encode(array(
  1215. 'type' => 'error',
  1216. 'msg' => 'Cannot find items in post data'
  1217. ));
  1218. }
  1219. break;
  1220. case "domain-policy":
  1221. if (isset($_POST['items'])) {
  1222. $items = (array)json_decode($_POST['items'], true);
  1223. if (is_array($items)) {
  1224. if (policy('delete', 'domain', array('prefid' => $items)) === false) {
  1225. if (isset($_SESSION['return'])) {
  1226. echo json_encode($_SESSION['return']);
  1227. }
  1228. else {
  1229. echo json_encode(array(
  1230. 'type' => 'error',
  1231. 'msg' => 'Task failed'
  1232. ));
  1233. }
  1234. }
  1235. else {
  1236. if (isset($_SESSION['return'])) {
  1237. echo json_encode($_SESSION['return']);
  1238. }
  1239. else {
  1240. echo json_encode(array(
  1241. 'type' => 'success',
  1242. 'msg' => 'Task completed'
  1243. ));
  1244. }
  1245. }
  1246. }
  1247. else {
  1248. echo json_encode(array(
  1249. 'type' => 'error',
  1250. 'msg' => 'Cannot find name array in post data'
  1251. ));
  1252. }
  1253. }
  1254. else {
  1255. echo json_encode(array(
  1256. 'type' => 'error',
  1257. 'msg' => 'Cannot find items in post data'
  1258. ));
  1259. }
  1260. break;
  1261. case "time_limited_alias":
  1262. if (isset($_POST['items'])) {
  1263. $items = (array)json_decode($_POST['items'], true);
  1264. if (is_array($items)) {
  1265. if (mailbox('delete', 'time_limited_alias', array('address' => $items)) === false) {
  1266. if (isset($_SESSION['return'])) {
  1267. echo json_encode($_SESSION['return']);
  1268. }
  1269. else {
  1270. echo json_encode(array(
  1271. 'type' => 'error',
  1272. 'msg' => 'Task failed'
  1273. ));
  1274. }
  1275. }
  1276. else {
  1277. if (isset($_SESSION['return'])) {
  1278. echo json_encode($_SESSION['return']);
  1279. }
  1280. else {
  1281. echo json_encode(array(
  1282. 'type' => 'success',
  1283. 'msg' => 'Task completed'
  1284. ));
  1285. }
  1286. }
  1287. }
  1288. else {
  1289. echo json_encode(array(
  1290. 'type' => 'error',
  1291. 'msg' => 'Cannot find name array in post data'
  1292. ));
  1293. }
  1294. }
  1295. else {
  1296. echo json_encode(array(
  1297. 'type' => 'error',
  1298. 'msg' => 'Cannot find items in post data'
  1299. ));
  1300. }
  1301. break;
  1302. case "eas_cache":
  1303. if (isset($_POST['items'])) {
  1304. $items = (array)json_decode($_POST['items'], true);
  1305. if (is_array($items)) {
  1306. if (mailbox('delete', 'eas_cache', array('username' => $items)) === false) {
  1307. if (isset($_SESSION['return'])) {
  1308. echo json_encode($_SESSION['return']);
  1309. }
  1310. else {
  1311. echo json_encode(array(
  1312. 'type' => 'error',
  1313. 'msg' => 'Task failed'
  1314. ));
  1315. }
  1316. }
  1317. else {
  1318. if (isset($_SESSION['return'])) {
  1319. echo json_encode($_SESSION['return']);
  1320. }
  1321. else {
  1322. echo json_encode(array(
  1323. 'type' => 'success',
  1324. 'msg' => 'Task completed'
  1325. ));
  1326. }
  1327. }
  1328. }
  1329. else {
  1330. echo json_encode(array(
  1331. 'type' => 'error',
  1332. 'msg' => 'Cannot find name array in post data'
  1333. ));
  1334. }
  1335. }
  1336. else {
  1337. echo json_encode(array(
  1338. 'type' => 'error',
  1339. 'msg' => 'Cannot find items in post data'
  1340. ));
  1341. }
  1342. break;
  1343. case "domain-admin":
  1344. if (isset($_POST['items'])) {
  1345. $items = (array)json_decode($_POST['items'], true);
  1346. if (is_array($items)) {
  1347. if (delete_domain_admin(array('username' => $items)) === false) {
  1348. if (isset($_SESSION['return'])) {
  1349. echo json_encode($_SESSION['return']);
  1350. }
  1351. else {
  1352. echo json_encode(array(
  1353. 'type' => 'error',
  1354. 'msg' => 'Task failed'
  1355. ));
  1356. }
  1357. }
  1358. else {
  1359. if (isset($_SESSION['return'])) {
  1360. echo json_encode($_SESSION['return']);
  1361. }
  1362. else {
  1363. echo json_encode(array(
  1364. 'type' => 'success',
  1365. 'msg' => 'Task completed'
  1366. ));
  1367. }
  1368. }
  1369. }
  1370. else {
  1371. echo json_encode(array(
  1372. 'type' => 'error',
  1373. 'msg' => 'Cannot find name array in post data'
  1374. ));
  1375. }
  1376. }
  1377. else {
  1378. echo json_encode(array(
  1379. 'type' => 'error',
  1380. 'msg' => 'Cannot find items in post data'
  1381. ));
  1382. }
  1383. break;
  1384. }
  1385. break;
  1386. case "edit":
  1387. switch ($category) {
  1388. case "alias":
  1389. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1390. $items = (array)json_decode($_POST['items'], true);
  1391. $attr = (array)json_decode($_POST['attr'], true);
  1392. $postarray = array_merge(array('address' => $items), $attr);
  1393. if (is_array($postarray['address'])) {
  1394. if (mailbox('edit', 'alias', $postarray) === false) {
  1395. if (isset($_SESSION['return'])) {
  1396. echo json_encode($_SESSION['return']);
  1397. }
  1398. else {
  1399. echo json_encode(array(
  1400. 'type' => 'error',
  1401. 'msg' => 'Edit failed'
  1402. ));
  1403. }
  1404. exit();
  1405. }
  1406. else {
  1407. if (isset($_SESSION['return'])) {
  1408. echo json_encode($_SESSION['return']);
  1409. }
  1410. else {
  1411. echo json_encode(array(
  1412. 'type' => 'success',
  1413. 'msg' => 'Task completed'
  1414. ));
  1415. }
  1416. }
  1417. }
  1418. else {
  1419. echo json_encode(array(
  1420. 'type' => 'error',
  1421. 'msg' => 'Incomplete post data'
  1422. ));
  1423. }
  1424. }
  1425. else {
  1426. echo json_encode(array(
  1427. 'type' => 'error',
  1428. 'msg' => 'Incomplete post data'
  1429. ));
  1430. }
  1431. break;
  1432. case "delimiter_action":
  1433. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1434. $items = (array)json_decode($_POST['items'], true);
  1435. $attr = (array)json_decode($_POST['attr'], true);
  1436. $postarray = array_merge(array('username' => $items), $attr);
  1437. if (is_array($postarray['username'])) {
  1438. if (mailbox('edit', 'delimiter_action', $postarray) === false) {
  1439. if (isset($_SESSION['return'])) {
  1440. echo json_encode($_SESSION['return']);
  1441. }
  1442. else {
  1443. echo json_encode(array(
  1444. 'type' => 'error',
  1445. 'msg' => 'Edit failed'
  1446. ));
  1447. }
  1448. exit();
  1449. }
  1450. else {
  1451. if (isset($_SESSION['return'])) {
  1452. echo json_encode($_SESSION['return']);
  1453. }
  1454. else {
  1455. echo json_encode(array(
  1456. 'type' => 'success',
  1457. 'msg' => 'Task completed'
  1458. ));
  1459. }
  1460. }
  1461. }
  1462. else {
  1463. echo json_encode(array(
  1464. 'type' => 'error',
  1465. 'msg' => 'Incomplete post data'
  1466. ));
  1467. }
  1468. }
  1469. else {
  1470. echo json_encode(array(
  1471. 'type' => 'error',
  1472. 'msg' => 'Incomplete post data'
  1473. ));
  1474. }
  1475. break;
  1476. case "tls_policy":
  1477. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1478. $items = (array)json_decode($_POST['items'], true);
  1479. $attr = (array)json_decode($_POST['attr'], true);
  1480. $postarray = array_merge(array('username' => $items), $attr);
  1481. if (is_array($postarray['username'])) {
  1482. if (mailbox('edit', 'tls_policy', $postarray) === false) {
  1483. if (isset($_SESSION['return'])) {
  1484. echo json_encode($_SESSION['return']);
  1485. }
  1486. else {
  1487. echo json_encode(array(
  1488. 'type' => 'error',
  1489. 'msg' => 'Edit failed'
  1490. ));
  1491. }
  1492. exit();
  1493. }
  1494. else {
  1495. if (isset($_SESSION['return'])) {
  1496. echo json_encode($_SESSION['return']);
  1497. }
  1498. else {
  1499. echo json_encode(array(
  1500. 'type' => 'success',
  1501. 'msg' => 'Task completed'
  1502. ));
  1503. }
  1504. }
  1505. }
  1506. else {
  1507. echo json_encode(array(
  1508. 'type' => 'error',
  1509. 'msg' => 'Incomplete post data'
  1510. ));
  1511. }
  1512. }
  1513. else {
  1514. echo json_encode(array(
  1515. 'type' => 'error',
  1516. 'msg' => 'Incomplete post data'
  1517. ));
  1518. }
  1519. break;
  1520. case "time_limited_alias":
  1521. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1522. $items = (array)json_decode($_POST['items'], true);
  1523. $attr = (array)json_decode($_POST['attr'], true);
  1524. $postarray = array_merge(array('address' => $items), $attr);
  1525. if (is_array($postarray['address'])) {
  1526. if (mailbox('edit', 'time_limited_alias', $postarray) === false) {
  1527. if (isset($_SESSION['return'])) {
  1528. echo json_encode($_SESSION['return']);
  1529. }
  1530. else {
  1531. echo json_encode(array(
  1532. 'type' => 'error',
  1533. 'msg' => 'Edit failed'
  1534. ));
  1535. }
  1536. exit();
  1537. }
  1538. else {
  1539. if (isset($_SESSION['return'])) {
  1540. echo json_encode($_SESSION['return']);
  1541. }
  1542. else {
  1543. echo json_encode(array(
  1544. 'type' => 'success',
  1545. 'msg' => 'Task completed'
  1546. ));
  1547. }
  1548. }
  1549. }
  1550. else {
  1551. echo json_encode(array(
  1552. 'type' => 'error',
  1553. 'msg' => 'Incomplete post data'
  1554. ));
  1555. }
  1556. }
  1557. else {
  1558. echo json_encode(array(
  1559. 'type' => 'error',
  1560. 'msg' => 'Incomplete post data'
  1561. ));
  1562. }
  1563. break;
  1564. case "mailbox":
  1565. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1566. $items = (array)json_decode($_POST['items'], true);
  1567. $attr = (array)json_decode($_POST['attr'], true);
  1568. $postarray = array_merge(array('username' => $items), $attr);
  1569. if (is_array($postarray['username'])) {
  1570. if (mailbox('edit', 'mailbox', $postarray) === false) {
  1571. if (isset($_SESSION['return'])) {
  1572. echo json_encode($_SESSION['return']);
  1573. }
  1574. else {
  1575. echo json_encode(array(
  1576. 'type' => 'error',
  1577. 'msg' => 'Edit failed'
  1578. ));
  1579. }
  1580. exit();
  1581. }
  1582. else {
  1583. if (isset($_SESSION['return'])) {
  1584. echo json_encode($_SESSION['return']);
  1585. }
  1586. else {
  1587. echo json_encode(array(
  1588. 'type' => 'success',
  1589. 'msg' => 'Task completed'
  1590. ));
  1591. }
  1592. }
  1593. }
  1594. else {
  1595. echo json_encode(array(
  1596. 'type' => 'error',
  1597. 'msg' => 'Incomplete post data'
  1598. ));
  1599. }
  1600. }
  1601. else {
  1602. echo json_encode(array(
  1603. 'type' => 'error',
  1604. 'msg' => 'Incomplete post data'
  1605. ));
  1606. }
  1607. break;
  1608. case "syncjob":
  1609. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1610. $items = (array)json_decode($_POST['items'], true);
  1611. $attr = (array)json_decode($_POST['attr'], true);
  1612. $postarray = array_merge(array('id' => $items), $attr);
  1613. if (is_array($postarray['id'])) {
  1614. if (mailbox('edit', 'syncjob', $postarray) === false) {
  1615. if (isset($_SESSION['return'])) {
  1616. echo json_encode($_SESSION['return']);
  1617. }
  1618. else {
  1619. echo json_encode(array(
  1620. 'type' => 'error',
  1621. 'msg' => 'Edit failed'
  1622. ));
  1623. }
  1624. exit();
  1625. }
  1626. else {
  1627. if (isset($_SESSION['return'])) {
  1628. echo json_encode($_SESSION['return']);
  1629. }
  1630. else {
  1631. echo json_encode(array(
  1632. 'type' => 'success',
  1633. 'msg' => 'Task completed'
  1634. ));
  1635. }
  1636. }
  1637. }
  1638. else {
  1639. echo json_encode(array(
  1640. 'type' => 'error',
  1641. 'msg' => 'Incomplete post data'
  1642. ));
  1643. }
  1644. }
  1645. else {
  1646. echo json_encode(array(
  1647. 'type' => 'error',
  1648. 'msg' => 'Incomplete post data'
  1649. ));
  1650. }
  1651. break;
  1652. case "resource":
  1653. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1654. $items = (array)json_decode($_POST['items'], true);
  1655. $attr = (array)json_decode($_POST['attr'], true);
  1656. $postarray = array_merge(array('name' => $items), $attr);
  1657. if (is_array($postarray['name'])) {
  1658. if (mailbox('edit', 'resource', $postarray) === false) {
  1659. if (isset($_SESSION['return'])) {
  1660. echo json_encode($_SESSION['return']);
  1661. }
  1662. else {
  1663. echo json_encode(array(
  1664. 'type' => 'error',
  1665. 'msg' => 'Edit failed'
  1666. ));
  1667. }
  1668. exit();
  1669. }
  1670. else {
  1671. if (isset($_SESSION['return'])) {
  1672. echo json_encode($_SESSION['return']);
  1673. }
  1674. else {
  1675. echo json_encode(array(
  1676. 'type' => 'success',
  1677. 'msg' => 'Task completed'
  1678. ));
  1679. }
  1680. }
  1681. }
  1682. else {
  1683. echo json_encode(array(
  1684. 'type' => 'error',
  1685. 'msg' => 'Incomplete post data'
  1686. ));
  1687. }
  1688. }
  1689. else {
  1690. echo json_encode(array(
  1691. 'type' => 'error',
  1692. 'msg' => 'Incomplete post data'
  1693. ));
  1694. }
  1695. break;
  1696. case "domain":
  1697. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1698. $items = (array)json_decode($_POST['items'], true);
  1699. $attr = (array)json_decode($_POST['attr'], true);
  1700. $postarray = array_merge(array('domain' => $items), $attr);
  1701. if (is_array($postarray['domain'])) {
  1702. if (mailbox('edit', 'domain', $postarray) === false) {
  1703. if (isset($_SESSION['return'])) {
  1704. echo json_encode($_SESSION['return']);
  1705. }
  1706. else {
  1707. echo json_encode(array(
  1708. 'type' => 'error',
  1709. 'msg' => 'Edit failed'
  1710. ));
  1711. }
  1712. exit();
  1713. }
  1714. else {
  1715. if (isset($_SESSION['return'])) {
  1716. echo json_encode($_SESSION['return']);
  1717. }
  1718. else {
  1719. echo json_encode(array(
  1720. 'type' => 'success',
  1721. 'msg' => 'Task completed'
  1722. ));
  1723. }
  1724. }
  1725. }
  1726. else {
  1727. echo json_encode(array(
  1728. 'type' => 'error',
  1729. 'msg' => 'Incomplete post data'
  1730. ));
  1731. }
  1732. }
  1733. else {
  1734. echo json_encode(array(
  1735. 'type' => 'error',
  1736. 'msg' => 'Incomplete post data'
  1737. ));
  1738. }
  1739. break;
  1740. case "alias-domain":
  1741. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1742. $items = (array)json_decode($_POST['items'], true);
  1743. $attr = (array)json_decode($_POST['attr'], true);
  1744. $postarray = array_merge(array('alias_domain' => $items), $attr);
  1745. if (is_array($postarray['alias_domain'])) {
  1746. if (mailbox('edit', 'alias_domain', $postarray) === false) {
  1747. if (isset($_SESSION['return'])) {
  1748. echo json_encode($_SESSION['return']);
  1749. }
  1750. else {
  1751. echo json_encode(array(
  1752. 'type' => 'error',
  1753. 'msg' => 'Edit failed'
  1754. ));
  1755. }
  1756. exit();
  1757. }
  1758. else {
  1759. if (isset($_SESSION['return'])) {
  1760. echo json_encode($_SESSION['return']);
  1761. }
  1762. else {
  1763. echo json_encode(array(
  1764. 'type' => 'success',
  1765. 'msg' => 'Task completed'
  1766. ));
  1767. }
  1768. }
  1769. }
  1770. else {
  1771. echo json_encode(array(
  1772. 'type' => 'error',
  1773. 'msg' => 'Incomplete post data'
  1774. ));
  1775. }
  1776. }
  1777. else {
  1778. echo json_encode(array(
  1779. 'type' => 'error',
  1780. 'msg' => 'Incomplete post data'
  1781. ));
  1782. }
  1783. break;
  1784. case "spam_score":
  1785. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1786. $items = (array)json_decode($_POST['items'], true);
  1787. $attr = (array)json_decode($_POST['attr'], true);
  1788. $postarray = array_merge(array('username' => $items), $attr);
  1789. if (is_array($postarray['username'])) {
  1790. if (mailbox('edit', 'spam_score', $postarray) === false) {
  1791. if (isset($_SESSION['return'])) {
  1792. echo json_encode($_SESSION['return']);
  1793. }
  1794. else {
  1795. echo json_encode(array(
  1796. 'type' => 'error',
  1797. 'msg' => 'Edit failed'
  1798. ));
  1799. }
  1800. exit();
  1801. }
  1802. else {
  1803. if (isset($_SESSION['return'])) {
  1804. echo json_encode($_SESSION['return']);
  1805. }
  1806. else {
  1807. echo json_encode(array(
  1808. 'type' => 'success',
  1809. 'msg' => 'Task completed'
  1810. ));
  1811. }
  1812. }
  1813. }
  1814. else {
  1815. echo json_encode(array(
  1816. 'type' => 'error',
  1817. 'msg' => 'Incomplete post data'
  1818. ));
  1819. }
  1820. }
  1821. else {
  1822. echo json_encode(array(
  1823. 'type' => 'error',
  1824. 'msg' => 'Incomplete post data'
  1825. ));
  1826. }
  1827. break;
  1828. case "domain-admin":
  1829. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1830. $items = (array)json_decode($_POST['items'], true);
  1831. $attr = (array)json_decode($_POST['attr'], true);
  1832. $postarray = array_merge(array('username' => $items), $attr);
  1833. if (is_array($postarray['username'])) {
  1834. if (edit_domain_admin($postarray) === false) {
  1835. if (isset($_SESSION['return'])) {
  1836. echo json_encode($_SESSION['return']);
  1837. }
  1838. else {
  1839. echo json_encode(array(
  1840. 'type' => 'error',
  1841. 'msg' => 'Edit failed'
  1842. ));
  1843. }
  1844. exit();
  1845. }
  1846. else {
  1847. if (isset($_SESSION['return'])) {
  1848. echo json_encode($_SESSION['return']);
  1849. }
  1850. else {
  1851. echo json_encode(array(
  1852. 'type' => 'success',
  1853. 'msg' => 'Task completed'
  1854. ));
  1855. }
  1856. }
  1857. }
  1858. else {
  1859. echo json_encode(array(
  1860. 'type' => 'error',
  1861. 'msg' => 'Incomplete post data'
  1862. ));
  1863. }
  1864. }
  1865. else {
  1866. echo json_encode(array(
  1867. 'type' => 'error',
  1868. 'msg' => 'Incomplete post data'
  1869. ));
  1870. }
  1871. break;
  1872. case "fwdhost":
  1873. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1874. $items = (array)json_decode($_POST['items'], true);
  1875. $attr = (array)json_decode($_POST['attr'], true);
  1876. $postarray = array_merge(array('fwdhost' => $items), $attr);
  1877. if (is_array($postarray['fwdhost'])) {
  1878. if (fwdhost('edit', $postarray) === false) {
  1879. if (isset($_SESSION['return'])) {
  1880. echo json_encode($_SESSION['return']);
  1881. }
  1882. else {
  1883. echo json_encode(array(
  1884. 'type' => 'error',
  1885. 'msg' => 'Edit failed'
  1886. ));
  1887. }
  1888. exit();
  1889. }
  1890. else {
  1891. if (isset($_SESSION['return'])) {
  1892. echo json_encode($_SESSION['return']);
  1893. }
  1894. else {
  1895. echo json_encode(array(
  1896. 'type' => 'success',
  1897. 'msg' => 'Task completed'
  1898. ));
  1899. }
  1900. }
  1901. }
  1902. else {
  1903. echo json_encode(array(
  1904. 'type' => 'error',
  1905. 'msg' => 'Incomplete post data'
  1906. ));
  1907. }
  1908. }
  1909. else {
  1910. echo json_encode(array(
  1911. 'type' => 'error',
  1912. 'msg' => 'Incomplete post data'
  1913. ));
  1914. }
  1915. break;
  1916. case "admin":
  1917. // No items as there is only one admin
  1918. if (isset($_POST['attr'])) {
  1919. $attr = (array)json_decode($_POST['attr'], true);
  1920. if (edit_admin_account($attr) === false) {
  1921. if (isset($_SESSION['return'])) {
  1922. echo json_encode($_SESSION['return']);
  1923. }
  1924. else {
  1925. echo json_encode(array(
  1926. 'type' => 'error',
  1927. 'msg' => 'Edit failed'
  1928. ));
  1929. }
  1930. exit();
  1931. }
  1932. else {
  1933. if (isset($_SESSION['return'])) {
  1934. echo json_encode($_SESSION['return']);
  1935. }
  1936. else {
  1937. echo json_encode(array(
  1938. 'type' => 'success',
  1939. 'msg' => 'Task completed'
  1940. ));
  1941. }
  1942. }
  1943. }
  1944. else {
  1945. echo json_encode(array(
  1946. 'type' => 'error',
  1947. 'msg' => 'Incomplete post data'
  1948. ));
  1949. }
  1950. break;
  1951. }
  1952. break;
  1953. }
  1954. }
  1955. }