json_api.php 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557
  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 "relayhost":
  60. if (isset($_POST['attr'])) {
  61. $attr = (array)json_decode($_POST['attr'], true);
  62. if (relayhost('add', $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 "mailbox":
  93. if (isset($_POST['attr'])) {
  94. $attr = (array)json_decode($_POST['attr'], true);
  95. if (mailbox('add', 'mailbox', $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 "domain":
  126. if (isset($_POST['attr'])) {
  127. $attr = (array)json_decode($_POST['attr'], true);
  128. if (mailbox('add', 'domain', $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 "resource":
  159. if (isset($_POST['attr'])) {
  160. $attr = (array)json_decode($_POST['attr'], true);
  161. if (mailbox('add', 'resource', $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 "alias":
  192. if (isset($_POST['attr'])) {
  193. $attr = (array)json_decode($_POST['attr'], true);
  194. if (mailbox('add', 'alias', $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 "syncjob":
  225. if (isset($_POST['attr'])) {
  226. $attr = (array)json_decode($_POST['attr'], true);
  227. if (mailbox('add', 'syncjob', $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 "domain-policy":
  258. if (isset($_POST['attr'])) {
  259. $attr = (array)json_decode($_POST['attr'], true);
  260. if (policy('add', 'domain', $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 "mailbox-policy":
  291. if (isset($_POST['attr'])) {
  292. $attr = (array)json_decode($_POST['attr'], true);
  293. if (policy('add', 'mailbox', $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 "alias-domain":
  324. if (isset($_POST['attr'])) {
  325. $attr = (array)json_decode($_POST['attr'], true);
  326. if (mailbox('add', 'alias_domain', $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 "fwdhost":
  357. if (isset($_POST['attr'])) {
  358. $attr = (array)json_decode($_POST['attr'], true);
  359. if (fwdhost('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 "dkim":
  390. if (isset($_POST['attr'])) {
  391. $attr = (array)json_decode($_POST['attr'], true);
  392. if (dkim('add', $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. case "dkim_import":
  423. if (isset($_POST['attr'])) {
  424. $attr = (array)json_decode($_POST['attr'], true);
  425. if (dkim('import', $attr) === false) {
  426. if (isset($_SESSION['return'])) {
  427. echo json_encode($_SESSION['return']);
  428. }
  429. else {
  430. echo json_encode(array(
  431. 'type' => 'error',
  432. 'msg' => 'Cannot add item'
  433. ));
  434. }
  435. }
  436. else {
  437. if (isset($_SESSION['return'])) {
  438. echo json_encode($_SESSION['return']);
  439. }
  440. else {
  441. echo json_encode(array(
  442. 'type' => 'success',
  443. 'msg' => 'Task completed'
  444. ));
  445. }
  446. }
  447. }
  448. else {
  449. echo json_encode(array(
  450. 'type' => 'error',
  451. 'msg' => 'Cannot find attributes in post data'
  452. ));
  453. }
  454. break;
  455. case "domain-admin":
  456. if (isset($_POST['attr'])) {
  457. $attr = (array)json_decode($_POST['attr'], true);
  458. if (domain_admin('add', $attr) === false) {
  459. if (isset($_SESSION['return'])) {
  460. echo json_encode($_SESSION['return']);
  461. }
  462. else {
  463. echo json_encode(array(
  464. 'type' => 'error',
  465. 'msg' => 'Cannot add item'
  466. ));
  467. }
  468. }
  469. else {
  470. if (isset($_SESSION['return'])) {
  471. echo json_encode($_SESSION['return']);
  472. }
  473. else {
  474. echo json_encode(array(
  475. 'type' => 'success',
  476. 'msg' => 'Task completed'
  477. ));
  478. }
  479. }
  480. }
  481. else {
  482. echo json_encode(array(
  483. 'type' => 'error',
  484. 'msg' => 'Cannot find attributes in post data'
  485. ));
  486. }
  487. break;
  488. }
  489. break;
  490. case "get":
  491. switch ($category) {
  492. case "rspamd":
  493. switch ($object) {
  494. case "stat":
  495. $data = file_get_contents('http://rspamd-mailcow:11334/stat');
  496. if (!empty($data)) {
  497. echo $data;
  498. }
  499. elseif (!isset($data) || empty($data)) {
  500. echo '{}';
  501. }
  502. break;
  503. case "graph":
  504. switch ($extra) {
  505. case "hourly":
  506. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=hourly');
  507. if (!empty($data)) {
  508. $data_array = json_decode($data, true);
  509. $rejected['label'] = "reject";
  510. foreach ($data_array[0] as $dataset) {
  511. $rejected['data'][] = $dataset;
  512. }
  513. $temp_reject['label'] = "temp_reject";
  514. foreach ($data_array[1] as $dataset) {
  515. $temp_reject['data'][] = $dataset;
  516. }
  517. $add_header['label'] = "add_header";
  518. foreach ($data_array[2] as $dataset) {
  519. $add_header['data'][] = $dataset;
  520. }
  521. $prob_spam['label'] = "prob_spam";
  522. foreach ($data_array[3] as $dataset) {
  523. $prob_spam['data'][] = $dataset;
  524. }
  525. $greylist['label'] = "greylist";
  526. foreach ($data_array[4] as $dataset) {
  527. $greylist['data'][] = $dataset;
  528. }
  529. $clean['label'] = "clean";
  530. $clean['pointStyle'] = "cross";
  531. foreach ($data_array[5] as $dataset) {
  532. $clean['data'][] = $dataset;
  533. }
  534. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  535. }
  536. elseif (!isset($data) || empty($data)) {
  537. echo '{}';
  538. }
  539. break;
  540. case "daily":
  541. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=daily');
  542. if (!empty($data)) {
  543. $data_array = json_decode($data, true);
  544. $rejected['label'] = "reject";
  545. foreach ($data_array[0] as $dataset) {
  546. $rejected['data'][] = $dataset;
  547. }
  548. $temp_reject['label'] = "temp_reject";
  549. foreach ($data_array[1] as $dataset) {
  550. $temp_reject['data'][] = $dataset;
  551. }
  552. $add_header['label'] = "add_header";
  553. foreach ($data_array[2] as $dataset) {
  554. $add_header['data'][] = $dataset;
  555. }
  556. $prob_spam['label'] = "prob_spam";
  557. foreach ($data_array[3] as $dataset) {
  558. $prob_spam['data'][] = $dataset;
  559. }
  560. $greylist['label'] = "greylist";
  561. foreach ($data_array[4] as $dataset) {
  562. $greylist['data'][] = $dataset;
  563. }
  564. $clean['label'] = "clean";
  565. $clean['pointStyle'] = "cross";
  566. foreach ($data_array[5] as $dataset) {
  567. $clean['data'][] = $dataset;
  568. }
  569. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  570. }
  571. elseif (!isset($data) || empty($data)) {
  572. echo '{}';
  573. }
  574. break;
  575. case "weekly":
  576. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=weekly');
  577. if (!empty($data)) {
  578. $data_array = json_decode($data, true);
  579. $rejected['label'] = "reject";
  580. foreach ($data_array[0] as $dataset) {
  581. $rejected['data'][] = $dataset;
  582. }
  583. $temp_reject['label'] = "temp_reject";
  584. foreach ($data_array[1] as $dataset) {
  585. $temp_reject['data'][] = $dataset;
  586. }
  587. $add_header['label'] = "add_header";
  588. foreach ($data_array[2] as $dataset) {
  589. $add_header['data'][] = $dataset;
  590. }
  591. $prob_spam['label'] = "prob_spam";
  592. foreach ($data_array[3] as $dataset) {
  593. $prob_spam['data'][] = $dataset;
  594. }
  595. $greylist['label'] = "greylist";
  596. foreach ($data_array[4] as $dataset) {
  597. $greylist['data'][] = $dataset;
  598. }
  599. $clean['label'] = "clean";
  600. $clean['pointStyle'] = "cross";
  601. foreach ($data_array[5] as $dataset) {
  602. $clean['data'][] = $dataset;
  603. }
  604. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  605. }
  606. elseif (!isset($data) || empty($data)) {
  607. echo '{}';
  608. }
  609. break;
  610. case "monthly":
  611. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=monthly');
  612. if (!empty($data)) {
  613. $data_array = json_decode($data, true);
  614. $rejected['label'] = "reject";
  615. foreach ($data_array[0] as $dataset) {
  616. $rejected['data'][] = $dataset;
  617. }
  618. $temp_reject['label'] = "temp_reject";
  619. foreach ($data_array[1] as $dataset) {
  620. $temp_reject['data'][] = $dataset;
  621. }
  622. $add_header['label'] = "add_header";
  623. foreach ($data_array[2] as $dataset) {
  624. $add_header['data'][] = $dataset;
  625. }
  626. $prob_spam['label'] = "prob_spam";
  627. foreach ($data_array[3] as $dataset) {
  628. $prob_spam['data'][] = $dataset;
  629. }
  630. $greylist['label'] = "greylist";
  631. foreach ($data_array[4] as $dataset) {
  632. $greylist['data'][] = $dataset;
  633. }
  634. $clean['label'] = "clean";
  635. $clean['pointStyle'] = "cross";
  636. foreach ($data_array[5] as $dataset) {
  637. $clean['data'][] = $dataset;
  638. }
  639. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  640. }
  641. elseif (!isset($data) || empty($data)) {
  642. echo '{}';
  643. }
  644. break;
  645. }
  646. break;
  647. }
  648. break;
  649. case "domain":
  650. switch ($object) {
  651. case "all":
  652. $domains = mailbox('get', 'domains');
  653. if (!empty($domains)) {
  654. foreach ($domains as $domain) {
  655. if ($details = mailbox('get', 'domain_details', $domain)) {
  656. $data[] = $details;
  657. }
  658. else {
  659. continue;
  660. }
  661. }
  662. if (!isset($data) || empty($data)) {
  663. echo '{}';
  664. }
  665. else {
  666. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  667. }
  668. }
  669. else {
  670. echo '{}';
  671. }
  672. break;
  673. default:
  674. $data = mailbox('get', 'domain_details', $object);
  675. if (!isset($data) || empty($data)) {
  676. echo '{}';
  677. }
  678. else {
  679. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  680. }
  681. break;
  682. }
  683. break;
  684. case "relayhost":
  685. switch ($object) {
  686. case "all":
  687. $relayhosts = relayhost('get');
  688. if (!empty($relayhosts)) {
  689. foreach ($relayhosts as $relayhost) {
  690. if ($details = relayhost('details', $relayhost['id'])) {
  691. $data[] = $details;
  692. }
  693. else {
  694. continue;
  695. }
  696. }
  697. if (!isset($data) || empty($data)) {
  698. echo '{}';
  699. }
  700. else {
  701. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  702. }
  703. }
  704. else {
  705. echo '{}';
  706. }
  707. break;
  708. default:
  709. $data = relayhost('details', $object);
  710. if (!isset($data) || empty($data)) {
  711. echo '{}';
  712. }
  713. else {
  714. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  715. }
  716. break;
  717. }
  718. break;
  719. case "logs":
  720. switch ($object) {
  721. case "dovecot":
  722. if (isset($extra) && !empty($extra)) {
  723. $extra = intval($extra);
  724. $logs = get_logs('dovecot-mailcow', $extra);
  725. }
  726. else {
  727. $logs = get_logs('dovecot-mailcow', -1);
  728. }
  729. if (isset($logs) && !empty($logs)) {
  730. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  731. }
  732. else {
  733. echo '{}';
  734. }
  735. break;
  736. case "fail2ban":
  737. if (isset($extra) && !empty($extra)) {
  738. $extra = intval($extra);
  739. $logs = get_logs('fail2ban-mailcow', $extra);
  740. }
  741. else {
  742. $logs = get_logs('fail2ban-mailcow', -1);
  743. }
  744. if (isset($logs) && !empty($logs)) {
  745. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  746. }
  747. else {
  748. echo '{}';
  749. }
  750. break;
  751. case "postfix":
  752. if (isset($extra) && !empty($extra)) {
  753. $extra = intval($extra);
  754. $logs = get_logs('postfix-mailcow', $extra);
  755. }
  756. else {
  757. $logs = get_logs('postfix-mailcow', -1);
  758. }
  759. if (isset($logs) && !empty($logs)) {
  760. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  761. }
  762. else {
  763. echo '{}';
  764. }
  765. break;
  766. case "autodiscover":
  767. if (isset($extra) && !empty($extra)) {
  768. $extra = intval($extra);
  769. $logs = get_logs('autodiscover-mailcow', $extra);
  770. }
  771. else {
  772. $logs = get_logs('autodiscover-mailcow', -1);
  773. }
  774. if (isset($logs) && !empty($logs)) {
  775. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  776. }
  777. else {
  778. echo '{}';
  779. }
  780. break;
  781. case "sogo":
  782. if (isset($extra) && !empty($extra)) {
  783. $extra = intval($extra);
  784. $logs = get_logs('sogo-mailcow', $extra);
  785. }
  786. else {
  787. $logs = get_logs('sogo-mailcow', -1);
  788. }
  789. if (isset($logs) && !empty($logs)) {
  790. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  791. }
  792. else {
  793. echo '{}';
  794. }
  795. break;
  796. case "rspamd-history":
  797. $logs = get_logs('rspamd-history');
  798. if (isset($logs) && !empty($logs)) {
  799. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  800. }
  801. else {
  802. echo '{}';
  803. }
  804. break;
  805. }
  806. break;
  807. case "mailbox":
  808. switch ($object) {
  809. case "all":
  810. $domains = mailbox('get', 'domains');
  811. if (!empty($domains)) {
  812. foreach ($domains as $domain) {
  813. $mailboxes = mailbox('get', 'mailboxes', $domain);
  814. if (!empty($mailboxes)) {
  815. foreach ($mailboxes as $mailbox) {
  816. if ($details = mailbox('get', 'mailbox_details', $mailbox)) {
  817. $data[] = $details;
  818. }
  819. else {
  820. continue;
  821. }
  822. }
  823. }
  824. }
  825. if (!isset($data) || empty($data)) {
  826. echo '{}';
  827. }
  828. else {
  829. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  830. }
  831. }
  832. else {
  833. echo '{}';
  834. }
  835. break;
  836. default:
  837. $data = mailbox('get', 'mailbox_details', $object);
  838. if (!isset($data) || empty($data)) {
  839. echo '{}';
  840. }
  841. else {
  842. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  843. }
  844. break;
  845. }
  846. break;
  847. case "syncjobs":
  848. switch ($object) {
  849. case "all":
  850. $domains = mailbox('get', 'domains');
  851. if (!empty($domains)) {
  852. foreach ($domains as $domain) {
  853. $mailboxes = mailbox('get', 'mailboxes', $domain);
  854. if (!empty($mailboxes)) {
  855. foreach ($mailboxes as $mailbox) {
  856. $syncjobs = mailbox('get', 'syncjobs', $mailbox);
  857. if (!empty($syncjobs)) {
  858. foreach ($syncjobs as $syncjob) {
  859. if ($details = mailbox('get', 'syncjob_details', $syncjob)) {
  860. $data[] = $details;
  861. }
  862. else {
  863. continue;
  864. }
  865. }
  866. }
  867. }
  868. }
  869. }
  870. if (!isset($data) || empty($data)) {
  871. echo '{}';
  872. }
  873. else {
  874. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  875. }
  876. }
  877. else {
  878. echo '{}';
  879. }
  880. break;
  881. default:
  882. $syncjobs = mailbox('get', 'syncjobs', $object);
  883. if (!empty($syncjobs)) {
  884. foreach ($syncjobs as $syncjob) {
  885. if ($details = mailbox('get', 'syncjob_details', $syncjob)) {
  886. $data[] = $details;
  887. }
  888. else {
  889. continue;
  890. }
  891. }
  892. }
  893. if (!isset($data) || empty($data)) {
  894. echo '{}';
  895. }
  896. else {
  897. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  898. }
  899. break;
  900. }
  901. break;
  902. case "policy_wl_mailbox":
  903. switch ($object) {
  904. default:
  905. $data = policy('get', 'mailbox', $object)['whitelist'];
  906. if (!isset($data) || empty($data)) {
  907. echo '{}';
  908. }
  909. else {
  910. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  911. }
  912. break;
  913. }
  914. break;
  915. case "policy_bl_mailbox":
  916. switch ($object) {
  917. default:
  918. $data = policy('get', 'mailbox', $object)['blacklist'];
  919. if (!isset($data) || empty($data)) {
  920. echo '{}';
  921. }
  922. else {
  923. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  924. }
  925. break;
  926. }
  927. break;
  928. case "policy_wl_domain":
  929. switch ($object) {
  930. default:
  931. $data = policy('get', 'domain', $object)['whitelist'];
  932. if (!isset($data) || empty($data)) {
  933. echo '{}';
  934. }
  935. else {
  936. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  937. }
  938. break;
  939. }
  940. break;
  941. case "policy_bl_domain":
  942. switch ($object) {
  943. default:
  944. $data = policy('get', 'domain', $object)['blacklist'];
  945. if (!isset($data) || empty($data)) {
  946. echo '{}';
  947. }
  948. else {
  949. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  950. }
  951. break;
  952. }
  953. break;
  954. case "time_limited_aliases":
  955. switch ($object) {
  956. default:
  957. $data = mailbox('get', 'time_limited_aliases', $object);
  958. if (!isset($data) || empty($data)) {
  959. echo '{}';
  960. }
  961. else {
  962. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  963. }
  964. break;
  965. }
  966. break;
  967. case "resource":
  968. switch ($object) {
  969. case "all":
  970. $domains = mailbox('get', 'domains');
  971. if (!empty($domains)) {
  972. foreach ($domains as $domain) {
  973. $resources = mailbox('get', 'resources', $domain);
  974. if (!empty($resources)) {
  975. foreach ($resources as $resource) {
  976. if ($details = mailbox('get', 'resource_details', $resource)) {
  977. $data[] = $details;
  978. }
  979. else {
  980. continue;
  981. }
  982. }
  983. }
  984. }
  985. if (!isset($data) || empty($data)) {
  986. echo '{}';
  987. }
  988. else {
  989. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  990. }
  991. }
  992. else {
  993. echo '{}';
  994. }
  995. break;
  996. default:
  997. $data = mailbox('get', 'resource_details', $object);
  998. if (!isset($data) || empty($data)) {
  999. echo '{}';
  1000. }
  1001. else {
  1002. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1003. }
  1004. break;
  1005. }
  1006. break;
  1007. case "fwdhost":
  1008. switch ($object) {
  1009. case "all":
  1010. $data = fwdhost('get');
  1011. if (!isset($data) || empty($data)) {
  1012. echo '{}';
  1013. }
  1014. else {
  1015. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1016. }
  1017. break;
  1018. default:
  1019. $data = fwdhost('details', $object);
  1020. if (!isset($data) || empty($data)) {
  1021. echo '{}';
  1022. }
  1023. else {
  1024. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1025. }
  1026. break;
  1027. }
  1028. break;
  1029. case "alias-domain":
  1030. switch ($object) {
  1031. case "all":
  1032. $alias_domains = mailbox('get', 'alias_domains');
  1033. if (!empty($alias_domains)) {
  1034. foreach ($alias_domains as $alias_domain) {
  1035. if ($details = mailbox('get', 'alias_domain_details', $alias_domain)) {
  1036. $data[] = $details;
  1037. }
  1038. else {
  1039. continue;
  1040. }
  1041. }
  1042. }
  1043. if (!isset($data) || empty($data)) {
  1044. echo '{}';
  1045. }
  1046. else {
  1047. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1048. }
  1049. break;
  1050. default:
  1051. $data = mailbox('get', 'alias_domain_details', $object);
  1052. if (!isset($data) || empty($data)) {
  1053. echo '{}';
  1054. }
  1055. else {
  1056. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1057. }
  1058. break;
  1059. }
  1060. break;
  1061. case "alias":
  1062. switch ($object) {
  1063. case "all":
  1064. $domains = array_merge(mailbox('get', 'domains'),mailbox('get', 'alias_domains'));
  1065. if (!empty($domains)) {
  1066. foreach ($domains as $domain) {
  1067. $aliases = mailbox('get', 'aliases', $domain);
  1068. if (!empty($aliases)) {
  1069. foreach ($aliases as $alias) {
  1070. if ($details = mailbox('get', 'alias_details', $alias)) {
  1071. $data[] = $details;
  1072. }
  1073. else {
  1074. continue;
  1075. }
  1076. }
  1077. }
  1078. }
  1079. if (!isset($data) || empty($data)) {
  1080. echo '{}';
  1081. }
  1082. else {
  1083. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1084. }
  1085. }
  1086. else {
  1087. echo '{}';
  1088. }
  1089. break;
  1090. default:
  1091. $data = mailbox('get', 'alias_details', $object);
  1092. if (!isset($data) || empty($data)) {
  1093. echo '{}';
  1094. }
  1095. else {
  1096. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1097. }
  1098. break;
  1099. }
  1100. break;
  1101. case "domain-admin":
  1102. switch ($object) {
  1103. case "all":
  1104. $domain_admins = domain_admin('get');
  1105. if (!empty($domain_admins)) {
  1106. foreach ($domain_admins as $domain_admin) {
  1107. if ($details = domain_admin('details', $domain_admin)) {
  1108. $data[] = $details;
  1109. }
  1110. else {
  1111. continue;
  1112. }
  1113. }
  1114. if (!isset($data) || empty($data)) {
  1115. echo '{}';
  1116. }
  1117. else {
  1118. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1119. }
  1120. }
  1121. else {
  1122. echo '{}';
  1123. }
  1124. break;
  1125. default:
  1126. $data = domain_admin('details', $object);
  1127. if (!isset($data) || empty($data)) {
  1128. echo '{}';
  1129. }
  1130. else {
  1131. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1132. }
  1133. break;
  1134. }
  1135. break;
  1136. case "u2f-registration":
  1137. header('Content-Type: application/javascript');
  1138. if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
  1139. $data = $u2f->getRegisterData(get_u2f_registrations($object));
  1140. list($req, $sigs) = $data;
  1141. $_SESSION['regReq'] = json_encode($req);
  1142. echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';';
  1143. }
  1144. else {
  1145. return;
  1146. }
  1147. break;
  1148. case "u2f-authentication":
  1149. header('Content-Type: application/javascript');
  1150. if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
  1151. $reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
  1152. $_SESSION['authReq'] = $reqs;
  1153. echo 'var req = ' . $reqs . ';';
  1154. }
  1155. else {
  1156. return;
  1157. }
  1158. break;
  1159. default:
  1160. echo '{}';
  1161. break;
  1162. }
  1163. break;
  1164. case "delete":
  1165. switch ($category) {
  1166. case "alias":
  1167. if (isset($_POST['items'])) {
  1168. $items = (array)json_decode($_POST['items'], true);
  1169. if (is_array($items)) {
  1170. if (mailbox('delete', 'alias', array('address' => $items)) === false) {
  1171. if (isset($_SESSION['return'])) {
  1172. echo json_encode($_SESSION['return']);
  1173. }
  1174. else {
  1175. echo json_encode(array(
  1176. 'type' => 'error',
  1177. 'msg' => 'Deletion of items/s failed'
  1178. ));
  1179. }
  1180. }
  1181. else {
  1182. if (isset($_SESSION['return'])) {
  1183. echo json_encode($_SESSION['return']);
  1184. }
  1185. else {
  1186. echo json_encode(array(
  1187. 'type' => 'success',
  1188. 'msg' => 'Task completed'
  1189. ));
  1190. }
  1191. }
  1192. }
  1193. else {
  1194. echo json_encode(array(
  1195. 'type' => 'error',
  1196. 'msg' => 'Cannot find address array in post data'
  1197. ));
  1198. }
  1199. }
  1200. else {
  1201. echo json_encode(array(
  1202. 'type' => 'error',
  1203. 'msg' => 'Cannot find items in post data'
  1204. ));
  1205. }
  1206. break;
  1207. case "relayhost":
  1208. if (isset($_POST['items'])) {
  1209. $items = (array)json_decode($_POST['items'], true);
  1210. if (is_array($items)) {
  1211. if (relayhost('delete', array('id' => $items)) === false) {
  1212. if (isset($_SESSION['return'])) {
  1213. echo json_encode($_SESSION['return']);
  1214. }
  1215. else {
  1216. echo json_encode(array(
  1217. 'type' => 'error',
  1218. 'msg' => 'Deletion of items/s failed'
  1219. ));
  1220. }
  1221. }
  1222. else {
  1223. if (isset($_SESSION['return'])) {
  1224. echo json_encode($_SESSION['return']);
  1225. }
  1226. else {
  1227. echo json_encode(array(
  1228. 'type' => 'success',
  1229. 'msg' => 'Task completed'
  1230. ));
  1231. }
  1232. }
  1233. }
  1234. else {
  1235. echo json_encode(array(
  1236. 'type' => 'error',
  1237. 'msg' => 'Cannot find id array in post data'
  1238. ));
  1239. }
  1240. }
  1241. else {
  1242. echo json_encode(array(
  1243. 'type' => 'error',
  1244. 'msg' => 'Cannot find items in post data'
  1245. ));
  1246. }
  1247. break;
  1248. case "syncjob":
  1249. if (isset($_POST['items'])) {
  1250. $items = (array)json_decode($_POST['items'], true);
  1251. if (is_array($items)) {
  1252. if (mailbox('delete', 'syncjob', array('id' => $items)) === false) {
  1253. if (isset($_SESSION['return'])) {
  1254. echo json_encode($_SESSION['return']);
  1255. }
  1256. else {
  1257. echo json_encode(array(
  1258. 'type' => 'error',
  1259. 'msg' => 'Deletion of items/s failed'
  1260. ));
  1261. }
  1262. }
  1263. else {
  1264. if (isset($_SESSION['return'])) {
  1265. echo json_encode($_SESSION['return']);
  1266. }
  1267. else {
  1268. echo json_encode(array(
  1269. 'type' => 'success',
  1270. 'msg' => 'Task completed'
  1271. ));
  1272. }
  1273. }
  1274. }
  1275. else {
  1276. echo json_encode(array(
  1277. 'type' => 'error',
  1278. 'msg' => 'Cannot find id array in post data'
  1279. ));
  1280. }
  1281. }
  1282. else {
  1283. echo json_encode(array(
  1284. 'type' => 'error',
  1285. 'msg' => 'Cannot find items in post data'
  1286. ));
  1287. }
  1288. break;
  1289. case "fwdhost":
  1290. if (isset($_POST['items'])) {
  1291. $items = (array)json_decode($_POST['items'], true);
  1292. if (is_array($items)) {
  1293. if (fwdhost('delete', array('forwardinghost' => $items)) === false) {
  1294. if (isset($_SESSION['return'])) {
  1295. echo json_encode($_SESSION['return']);
  1296. }
  1297. else {
  1298. echo json_encode(array(
  1299. 'type' => 'error',
  1300. 'msg' => 'Deletion of items/s failed'
  1301. ));
  1302. }
  1303. }
  1304. else {
  1305. if (isset($_SESSION['return'])) {
  1306. echo json_encode($_SESSION['return']);
  1307. }
  1308. else {
  1309. echo json_encode(array(
  1310. 'type' => 'success',
  1311. 'msg' => 'Task completed'
  1312. ));
  1313. }
  1314. }
  1315. }
  1316. else {
  1317. echo json_encode(array(
  1318. 'type' => 'error',
  1319. 'msg' => 'Cannot find forwardinghost array in post data'
  1320. ));
  1321. }
  1322. }
  1323. else {
  1324. echo json_encode(array(
  1325. 'type' => 'error',
  1326. 'msg' => 'Cannot find items in post data'
  1327. ));
  1328. }
  1329. break;
  1330. case "dkim":
  1331. if (isset($_POST['items'])) {
  1332. $items = (array)json_decode($_POST['items'], true);
  1333. if (is_array($items)) {
  1334. if (dkim('delete', array('domains' => $items)) === false) {
  1335. if (isset($_SESSION['return'])) {
  1336. echo json_encode($_SESSION['return']);
  1337. }
  1338. else {
  1339. echo json_encode(array(
  1340. 'type' => 'error',
  1341. 'msg' => 'Deletion of items/s failed'
  1342. ));
  1343. }
  1344. }
  1345. else {
  1346. if (isset($_SESSION['return'])) {
  1347. echo json_encode($_SESSION['return']);
  1348. }
  1349. else {
  1350. echo json_encode(array(
  1351. 'type' => 'success',
  1352. 'msg' => 'Task completed'
  1353. ));
  1354. }
  1355. }
  1356. }
  1357. else {
  1358. echo json_encode(array(
  1359. 'type' => 'error',
  1360. 'msg' => 'Cannot find domains array in post data'
  1361. ));
  1362. }
  1363. }
  1364. else {
  1365. echo json_encode(array(
  1366. 'type' => 'error',
  1367. 'msg' => 'Cannot find items in post data'
  1368. ));
  1369. }
  1370. break;
  1371. case "domain":
  1372. if (isset($_POST['items'])) {
  1373. $items = (array)json_decode($_POST['items'], true);
  1374. if (is_array($items)) {
  1375. if (mailbox('delete', 'domain', array('domain' => $items)) === false) {
  1376. if (isset($_SESSION['return'])) {
  1377. echo json_encode($_SESSION['return']);
  1378. }
  1379. else {
  1380. echo json_encode(array(
  1381. 'type' => 'error',
  1382. 'msg' => 'Task failed'
  1383. ));
  1384. }
  1385. }
  1386. else {
  1387. if (isset($_SESSION['return'])) {
  1388. echo json_encode($_SESSION['return']);
  1389. }
  1390. else {
  1391. echo json_encode(array(
  1392. 'type' => 'success',
  1393. 'msg' => 'Task completed'
  1394. ));
  1395. }
  1396. }
  1397. }
  1398. else {
  1399. echo json_encode(array(
  1400. 'type' => 'error',
  1401. 'msg' => 'Cannot find domain array in post data'
  1402. ));
  1403. }
  1404. }
  1405. else {
  1406. echo json_encode(array(
  1407. 'type' => 'error',
  1408. 'msg' => 'Cannot find items in post data'
  1409. ));
  1410. }
  1411. break;
  1412. case "alias-domain":
  1413. if (isset($_POST['items'])) {
  1414. $items = (array)json_decode($_POST['items'], true);
  1415. if (is_array($items)) {
  1416. if (mailbox('delete', 'alias_domain', array('alias_domain' => $items)) === false) {
  1417. if (isset($_SESSION['return'])) {
  1418. echo json_encode($_SESSION['return']);
  1419. }
  1420. else {
  1421. echo json_encode(array(
  1422. 'type' => 'error',
  1423. 'msg' => 'Task failed'
  1424. ));
  1425. }
  1426. }
  1427. else {
  1428. if (isset($_SESSION['return'])) {
  1429. echo json_encode($_SESSION['return']);
  1430. }
  1431. else {
  1432. echo json_encode(array(
  1433. 'type' => 'success',
  1434. 'msg' => 'Task completed'
  1435. ));
  1436. }
  1437. }
  1438. }
  1439. else {
  1440. echo json_encode(array(
  1441. 'type' => 'error',
  1442. 'msg' => 'Cannot find alias_domain array in post data'
  1443. ));
  1444. }
  1445. }
  1446. else {
  1447. echo json_encode(array(
  1448. 'type' => 'error',
  1449. 'msg' => 'Cannot find items in post data'
  1450. ));
  1451. }
  1452. break;
  1453. case "mailbox":
  1454. if (isset($_POST['items'])) {
  1455. $items = (array)json_decode($_POST['items'], true);
  1456. if (is_array($items)) {
  1457. if (mailbox('delete', 'mailbox', array('username' => $items)) === false) {
  1458. if (isset($_SESSION['return'])) {
  1459. echo json_encode($_SESSION['return']);
  1460. }
  1461. else {
  1462. echo json_encode(array(
  1463. 'type' => 'error',
  1464. 'msg' => 'Task failed'
  1465. ));
  1466. }
  1467. }
  1468. else {
  1469. if (isset($_SESSION['return'])) {
  1470. echo json_encode($_SESSION['return']);
  1471. }
  1472. else {
  1473. echo json_encode(array(
  1474. 'type' => 'success',
  1475. 'msg' => 'Task completed'
  1476. ));
  1477. }
  1478. }
  1479. }
  1480. else {
  1481. echo json_encode(array(
  1482. 'type' => 'error',
  1483. 'msg' => 'Cannot find username array in post data'
  1484. ));
  1485. }
  1486. }
  1487. else {
  1488. echo json_encode(array(
  1489. 'type' => 'error',
  1490. 'msg' => 'Cannot find items in post data'
  1491. ));
  1492. }
  1493. break;
  1494. case "resource":
  1495. if (isset($_POST['items'])) {
  1496. $items = (array)json_decode($_POST['items'], true);
  1497. if (is_array($items)) {
  1498. if (mailbox('delete', 'resource', array('name' => $items)) === false) {
  1499. if (isset($_SESSION['return'])) {
  1500. echo json_encode($_SESSION['return']);
  1501. }
  1502. else {
  1503. echo json_encode(array(
  1504. 'type' => 'error',
  1505. 'msg' => 'Task failed'
  1506. ));
  1507. }
  1508. }
  1509. else {
  1510. if (isset($_SESSION['return'])) {
  1511. echo json_encode($_SESSION['return']);
  1512. }
  1513. else {
  1514. echo json_encode(array(
  1515. 'type' => 'success',
  1516. 'msg' => 'Task completed'
  1517. ));
  1518. }
  1519. }
  1520. }
  1521. else {
  1522. echo json_encode(array(
  1523. 'type' => 'error',
  1524. 'msg' => 'Cannot find name array in post data'
  1525. ));
  1526. }
  1527. }
  1528. else {
  1529. echo json_encode(array(
  1530. 'type' => 'error',
  1531. 'msg' => 'Cannot find items in post data'
  1532. ));
  1533. }
  1534. break;
  1535. case "mailbox-policy":
  1536. if (isset($_POST['items'])) {
  1537. $items = (array)json_decode($_POST['items'], true);
  1538. if (is_array($items)) {
  1539. if (policy('delete', 'mailbox', array('prefid' => $items)) === false) {
  1540. if (isset($_SESSION['return'])) {
  1541. echo json_encode($_SESSION['return']);
  1542. }
  1543. else {
  1544. echo json_encode(array(
  1545. 'type' => 'error',
  1546. 'msg' => 'Task failed'
  1547. ));
  1548. }
  1549. }
  1550. else {
  1551. if (isset($_SESSION['return'])) {
  1552. echo json_encode($_SESSION['return']);
  1553. }
  1554. else {
  1555. echo json_encode(array(
  1556. 'type' => 'success',
  1557. 'msg' => 'Task completed'
  1558. ));
  1559. }
  1560. }
  1561. }
  1562. else {
  1563. echo json_encode(array(
  1564. 'type' => 'error',
  1565. 'msg' => 'Cannot find name array in post data'
  1566. ));
  1567. }
  1568. }
  1569. else {
  1570. echo json_encode(array(
  1571. 'type' => 'error',
  1572. 'msg' => 'Cannot find items in post data'
  1573. ));
  1574. }
  1575. break;
  1576. case "domain-policy":
  1577. if (isset($_POST['items'])) {
  1578. $items = (array)json_decode($_POST['items'], true);
  1579. if (is_array($items)) {
  1580. if (policy('delete', 'domain', array('prefid' => $items)) === false) {
  1581. if (isset($_SESSION['return'])) {
  1582. echo json_encode($_SESSION['return']);
  1583. }
  1584. else {
  1585. echo json_encode(array(
  1586. 'type' => 'error',
  1587. 'msg' => 'Task failed'
  1588. ));
  1589. }
  1590. }
  1591. else {
  1592. if (isset($_SESSION['return'])) {
  1593. echo json_encode($_SESSION['return']);
  1594. }
  1595. else {
  1596. echo json_encode(array(
  1597. 'type' => 'success',
  1598. 'msg' => 'Task completed'
  1599. ));
  1600. }
  1601. }
  1602. }
  1603. else {
  1604. echo json_encode(array(
  1605. 'type' => 'error',
  1606. 'msg' => 'Cannot find name array in post data'
  1607. ));
  1608. }
  1609. }
  1610. else {
  1611. echo json_encode(array(
  1612. 'type' => 'error',
  1613. 'msg' => 'Cannot find items in post data'
  1614. ));
  1615. }
  1616. break;
  1617. case "time_limited_alias":
  1618. if (isset($_POST['items'])) {
  1619. $items = (array)json_decode($_POST['items'], true);
  1620. if (is_array($items)) {
  1621. if (mailbox('delete', 'time_limited_alias', array('address' => $items)) === false) {
  1622. if (isset($_SESSION['return'])) {
  1623. echo json_encode($_SESSION['return']);
  1624. }
  1625. else {
  1626. echo json_encode(array(
  1627. 'type' => 'error',
  1628. 'msg' => 'Task failed'
  1629. ));
  1630. }
  1631. }
  1632. else {
  1633. if (isset($_SESSION['return'])) {
  1634. echo json_encode($_SESSION['return']);
  1635. }
  1636. else {
  1637. echo json_encode(array(
  1638. 'type' => 'success',
  1639. 'msg' => 'Task completed'
  1640. ));
  1641. }
  1642. }
  1643. }
  1644. else {
  1645. echo json_encode(array(
  1646. 'type' => 'error',
  1647. 'msg' => 'Cannot find name array in post data'
  1648. ));
  1649. }
  1650. }
  1651. else {
  1652. echo json_encode(array(
  1653. 'type' => 'error',
  1654. 'msg' => 'Cannot find items in post data'
  1655. ));
  1656. }
  1657. break;
  1658. case "eas_cache":
  1659. if (isset($_POST['items'])) {
  1660. $items = (array)json_decode($_POST['items'], true);
  1661. if (is_array($items)) {
  1662. if (mailbox('delete', 'eas_cache', array('username' => $items)) === false) {
  1663. if (isset($_SESSION['return'])) {
  1664. echo json_encode($_SESSION['return']);
  1665. }
  1666. else {
  1667. echo json_encode(array(
  1668. 'type' => 'error',
  1669. 'msg' => 'Task failed'
  1670. ));
  1671. }
  1672. }
  1673. else {
  1674. if (isset($_SESSION['return'])) {
  1675. echo json_encode($_SESSION['return']);
  1676. }
  1677. else {
  1678. echo json_encode(array(
  1679. 'type' => 'success',
  1680. 'msg' => 'Task completed'
  1681. ));
  1682. }
  1683. }
  1684. }
  1685. else {
  1686. echo json_encode(array(
  1687. 'type' => 'error',
  1688. 'msg' => 'Cannot find name array in post data'
  1689. ));
  1690. }
  1691. }
  1692. else {
  1693. echo json_encode(array(
  1694. 'type' => 'error',
  1695. 'msg' => 'Cannot find items in post data'
  1696. ));
  1697. }
  1698. break;
  1699. case "domain-admin":
  1700. if (isset($_POST['items'])) {
  1701. $items = (array)json_decode($_POST['items'], true);
  1702. if (is_array($items)) {
  1703. if (domain_admin('delete', array('username' => $items)) === false) {
  1704. if (isset($_SESSION['return'])) {
  1705. echo json_encode($_SESSION['return']);
  1706. }
  1707. else {
  1708. echo json_encode(array(
  1709. 'type' => 'error',
  1710. 'msg' => 'Task failed'
  1711. ));
  1712. }
  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' => 'Cannot find name array in post data'
  1730. ));
  1731. }
  1732. }
  1733. else {
  1734. echo json_encode(array(
  1735. 'type' => 'error',
  1736. 'msg' => 'Cannot find items in post data'
  1737. ));
  1738. }
  1739. break;
  1740. }
  1741. break;
  1742. case "edit":
  1743. switch ($category) {
  1744. case "alias":
  1745. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1746. $items = (array)json_decode($_POST['items'], true);
  1747. $attr = (array)json_decode($_POST['attr'], true);
  1748. $postarray = array_merge(array('address' => $items), $attr);
  1749. if (is_array($postarray['address'])) {
  1750. if (mailbox('edit', 'alias', $postarray) === false) {
  1751. if (isset($_SESSION['return'])) {
  1752. echo json_encode($_SESSION['return']);
  1753. }
  1754. else {
  1755. echo json_encode(array(
  1756. 'type' => 'error',
  1757. 'msg' => 'Edit failed'
  1758. ));
  1759. }
  1760. exit();
  1761. }
  1762. else {
  1763. if (isset($_SESSION['return'])) {
  1764. echo json_encode($_SESSION['return']);
  1765. }
  1766. else {
  1767. echo json_encode(array(
  1768. 'type' => 'success',
  1769. 'msg' => 'Task completed'
  1770. ));
  1771. }
  1772. }
  1773. }
  1774. else {
  1775. echo json_encode(array(
  1776. 'type' => 'error',
  1777. 'msg' => 'Incomplete post data'
  1778. ));
  1779. }
  1780. }
  1781. else {
  1782. echo json_encode(array(
  1783. 'type' => 'error',
  1784. 'msg' => 'Incomplete post data'
  1785. ));
  1786. }
  1787. break;
  1788. case "app_links":
  1789. if (isset($_POST['attr'])) {
  1790. $attr = (array)json_decode($_POST['attr'], true);
  1791. if (is_array($attr)) {
  1792. if (customize('edit', 'app_links', $attr) === false) {
  1793. if (isset($_SESSION['return'])) {
  1794. echo json_encode($_SESSION['return']);
  1795. }
  1796. else {
  1797. echo json_encode(array(
  1798. 'type' => 'error',
  1799. 'msg' => 'Edit failed'
  1800. ));
  1801. }
  1802. exit();
  1803. }
  1804. else {
  1805. if (isset($_SESSION['return'])) {
  1806. echo json_encode($_SESSION['return']);
  1807. }
  1808. else {
  1809. echo json_encode(array(
  1810. 'type' => 'success',
  1811. 'msg' => 'Task completed'
  1812. ));
  1813. }
  1814. }
  1815. }
  1816. else {
  1817. echo json_encode(array(
  1818. 'type' => 'error',
  1819. 'msg' => 'Incomplete post data'
  1820. ));
  1821. }
  1822. }
  1823. else {
  1824. echo json_encode(array(
  1825. 'type' => 'error',
  1826. 'msg' => 'Incomplete post data'
  1827. ));
  1828. }
  1829. break;
  1830. case "relayhost":
  1831. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1832. $items = (array)json_decode($_POST['items'], true);
  1833. $attr = (array)json_decode($_POST['attr'], true);
  1834. $postarray = array_merge(array('id' => $items), $attr);
  1835. if (is_array($postarray['id'])) {
  1836. if (relayhost('edit', $postarray) === false) {
  1837. if (isset($_SESSION['return'])) {
  1838. echo json_encode($_SESSION['return']);
  1839. }
  1840. else {
  1841. echo json_encode(array(
  1842. 'type' => 'error',
  1843. 'msg' => 'Edit failed'
  1844. ));
  1845. }
  1846. exit();
  1847. }
  1848. else {
  1849. if (isset($_SESSION['return'])) {
  1850. echo json_encode($_SESSION['return']);
  1851. }
  1852. else {
  1853. echo json_encode(array(
  1854. 'type' => 'success',
  1855. 'msg' => 'Task completed'
  1856. ));
  1857. }
  1858. }
  1859. }
  1860. else {
  1861. echo json_encode(array(
  1862. 'type' => 'error',
  1863. 'msg' => 'Incomplete post data'
  1864. ));
  1865. }
  1866. }
  1867. else {
  1868. echo json_encode(array(
  1869. 'type' => 'error',
  1870. 'msg' => 'Incomplete post data'
  1871. ));
  1872. }
  1873. break;
  1874. case "delimiter_action":
  1875. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1876. $items = (array)json_decode($_POST['items'], true);
  1877. $attr = (array)json_decode($_POST['attr'], true);
  1878. $postarray = array_merge(array('username' => $items), $attr);
  1879. if (is_array($postarray['username'])) {
  1880. if (mailbox('edit', 'delimiter_action', $postarray) === false) {
  1881. if (isset($_SESSION['return'])) {
  1882. echo json_encode($_SESSION['return']);
  1883. }
  1884. else {
  1885. echo json_encode(array(
  1886. 'type' => 'error',
  1887. 'msg' => 'Edit failed'
  1888. ));
  1889. }
  1890. exit();
  1891. }
  1892. else {
  1893. if (isset($_SESSION['return'])) {
  1894. echo json_encode($_SESSION['return']);
  1895. }
  1896. else {
  1897. echo json_encode(array(
  1898. 'type' => 'success',
  1899. 'msg' => 'Task completed'
  1900. ));
  1901. }
  1902. }
  1903. }
  1904. else {
  1905. echo json_encode(array(
  1906. 'type' => 'error',
  1907. 'msg' => 'Incomplete post data'
  1908. ));
  1909. }
  1910. }
  1911. else {
  1912. echo json_encode(array(
  1913. 'type' => 'error',
  1914. 'msg' => 'Incomplete post data'
  1915. ));
  1916. }
  1917. break;
  1918. case "tls_policy":
  1919. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1920. $items = (array)json_decode($_POST['items'], true);
  1921. $attr = (array)json_decode($_POST['attr'], true);
  1922. $postarray = array_merge(array('username' => $items), $attr);
  1923. if (is_array($postarray['username'])) {
  1924. if (mailbox('edit', 'tls_policy', $postarray) === false) {
  1925. if (isset($_SESSION['return'])) {
  1926. echo json_encode($_SESSION['return']);
  1927. }
  1928. else {
  1929. echo json_encode(array(
  1930. 'type' => 'error',
  1931. 'msg' => 'Edit failed'
  1932. ));
  1933. }
  1934. exit();
  1935. }
  1936. else {
  1937. if (isset($_SESSION['return'])) {
  1938. echo json_encode($_SESSION['return']);
  1939. }
  1940. else {
  1941. echo json_encode(array(
  1942. 'type' => 'success',
  1943. 'msg' => 'Task completed'
  1944. ));
  1945. }
  1946. }
  1947. }
  1948. else {
  1949. echo json_encode(array(
  1950. 'type' => 'error',
  1951. 'msg' => 'Incomplete post data'
  1952. ));
  1953. }
  1954. }
  1955. else {
  1956. echo json_encode(array(
  1957. 'type' => 'error',
  1958. 'msg' => 'Incomplete post data'
  1959. ));
  1960. }
  1961. break;
  1962. case "time_limited_alias":
  1963. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1964. $items = (array)json_decode($_POST['items'], true);
  1965. $attr = (array)json_decode($_POST['attr'], true);
  1966. $postarray = array_merge(array('address' => $items), $attr);
  1967. if (is_array($postarray['address'])) {
  1968. if (mailbox('edit', 'time_limited_alias', $postarray) === false) {
  1969. if (isset($_SESSION['return'])) {
  1970. echo json_encode($_SESSION['return']);
  1971. }
  1972. else {
  1973. echo json_encode(array(
  1974. 'type' => 'error',
  1975. 'msg' => 'Edit failed'
  1976. ));
  1977. }
  1978. exit();
  1979. }
  1980. else {
  1981. if (isset($_SESSION['return'])) {
  1982. echo json_encode($_SESSION['return']);
  1983. }
  1984. else {
  1985. echo json_encode(array(
  1986. 'type' => 'success',
  1987. 'msg' => 'Task completed'
  1988. ));
  1989. }
  1990. }
  1991. }
  1992. else {
  1993. echo json_encode(array(
  1994. 'type' => 'error',
  1995. 'msg' => 'Incomplete post data'
  1996. ));
  1997. }
  1998. }
  1999. else {
  2000. echo json_encode(array(
  2001. 'type' => 'error',
  2002. 'msg' => 'Incomplete post data'
  2003. ));
  2004. }
  2005. break;
  2006. case "mailbox":
  2007. // sender_acl:0 removes all entries
  2008. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2009. $items = (array)json_decode($_POST['items'], true);
  2010. $attr = (array)json_decode($_POST['attr'], true);
  2011. $postarray = array_merge(array('username' => $items), $attr);
  2012. if (is_array($postarray['username'])) {
  2013. if (mailbox('edit', 'mailbox', $postarray) === false) {
  2014. if (isset($_SESSION['return'])) {
  2015. echo json_encode($_SESSION['return']);
  2016. }
  2017. else {
  2018. echo json_encode(array(
  2019. 'type' => 'error',
  2020. 'msg' => 'Edit failed'
  2021. ));
  2022. }
  2023. exit();
  2024. }
  2025. else {
  2026. if (isset($_SESSION['return'])) {
  2027. echo json_encode($_SESSION['return']);
  2028. }
  2029. else {
  2030. echo json_encode(array(
  2031. 'type' => 'success',
  2032. 'msg' => 'Task completed'
  2033. ));
  2034. }
  2035. }
  2036. }
  2037. else {
  2038. echo json_encode(array(
  2039. 'type' => 'error',
  2040. 'msg' => 'Incomplete post data'
  2041. ));
  2042. }
  2043. }
  2044. else {
  2045. echo json_encode(array(
  2046. 'type' => 'error',
  2047. 'msg' => 'Incomplete post data'
  2048. ));
  2049. }
  2050. break;
  2051. case "syncjob":
  2052. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2053. $items = (array)json_decode($_POST['items'], true);
  2054. $attr = (array)json_decode($_POST['attr'], true);
  2055. $postarray = array_merge(array('id' => $items), $attr);
  2056. if (is_array($postarray['id'])) {
  2057. if (mailbox('edit', 'syncjob', $postarray) === false) {
  2058. if (isset($_SESSION['return'])) {
  2059. echo json_encode($_SESSION['return']);
  2060. }
  2061. else {
  2062. echo json_encode(array(
  2063. 'type' => 'error',
  2064. 'msg' => 'Edit failed'
  2065. ));
  2066. }
  2067. exit();
  2068. }
  2069. else {
  2070. if (isset($_SESSION['return'])) {
  2071. echo json_encode($_SESSION['return']);
  2072. }
  2073. else {
  2074. echo json_encode(array(
  2075. 'type' => 'success',
  2076. 'msg' => 'Task completed'
  2077. ));
  2078. }
  2079. }
  2080. }
  2081. else {
  2082. echo json_encode(array(
  2083. 'type' => 'error',
  2084. 'msg' => 'Incomplete post data'
  2085. ));
  2086. }
  2087. }
  2088. else {
  2089. echo json_encode(array(
  2090. 'type' => 'error',
  2091. 'msg' => 'Incomplete post data'
  2092. ));
  2093. }
  2094. break;
  2095. case "resource":
  2096. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2097. $items = (array)json_decode($_POST['items'], true);
  2098. $attr = (array)json_decode($_POST['attr'], true);
  2099. $postarray = array_merge(array('name' => $items), $attr);
  2100. if (is_array($postarray['name'])) {
  2101. if (mailbox('edit', 'resource', $postarray) === false) {
  2102. if (isset($_SESSION['return'])) {
  2103. echo json_encode($_SESSION['return']);
  2104. }
  2105. else {
  2106. echo json_encode(array(
  2107. 'type' => 'error',
  2108. 'msg' => 'Edit failed'
  2109. ));
  2110. }
  2111. exit();
  2112. }
  2113. else {
  2114. if (isset($_SESSION['return'])) {
  2115. echo json_encode($_SESSION['return']);
  2116. }
  2117. else {
  2118. echo json_encode(array(
  2119. 'type' => 'success',
  2120. 'msg' => 'Task completed'
  2121. ));
  2122. }
  2123. }
  2124. }
  2125. else {
  2126. echo json_encode(array(
  2127. 'type' => 'error',
  2128. 'msg' => 'Incomplete post data'
  2129. ));
  2130. }
  2131. }
  2132. else {
  2133. echo json_encode(array(
  2134. 'type' => 'error',
  2135. 'msg' => 'Incomplete post data'
  2136. ));
  2137. }
  2138. break;
  2139. case "domain":
  2140. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2141. $items = (array)json_decode($_POST['items'], true);
  2142. $attr = (array)json_decode($_POST['attr'], true);
  2143. $postarray = array_merge(array('domain' => $items), $attr);
  2144. if (is_array($postarray['domain'])) {
  2145. if (mailbox('edit', 'domain', $postarray) === false) {
  2146. if (isset($_SESSION['return'])) {
  2147. echo json_encode($_SESSION['return']);
  2148. }
  2149. else {
  2150. echo json_encode(array(
  2151. 'type' => 'error',
  2152. 'msg' => 'Edit failed'
  2153. ));
  2154. }
  2155. exit();
  2156. }
  2157. else {
  2158. if (isset($_SESSION['return'])) {
  2159. echo json_encode($_SESSION['return']);
  2160. }
  2161. else {
  2162. echo json_encode(array(
  2163. 'type' => 'success',
  2164. 'msg' => 'Task completed'
  2165. ));
  2166. }
  2167. }
  2168. }
  2169. else {
  2170. echo json_encode(array(
  2171. 'type' => 'error',
  2172. 'msg' => 'Incomplete post data'
  2173. ));
  2174. }
  2175. }
  2176. else {
  2177. echo json_encode(array(
  2178. 'type' => 'error',
  2179. 'msg' => 'Incomplete post data'
  2180. ));
  2181. }
  2182. break;
  2183. case "ratelimit":
  2184. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2185. $items = (array)json_decode($_POST['items'], true);
  2186. $attr = (array)json_decode($_POST['attr'], true);
  2187. $postarray = array_merge(array('object' => $items), $attr);
  2188. if (is_array($postarray['object'])) {
  2189. if (mailbox('edit', 'ratelimit', $postarray) === false) {
  2190. if (isset($_SESSION['return'])) {
  2191. echo json_encode($_SESSION['return']);
  2192. }
  2193. else {
  2194. echo json_encode(array(
  2195. 'type' => 'error',
  2196. 'msg' => 'Edit failed'
  2197. ));
  2198. }
  2199. exit();
  2200. }
  2201. else {
  2202. if (isset($_SESSION['return'])) {
  2203. echo json_encode($_SESSION['return']);
  2204. }
  2205. else {
  2206. echo json_encode(array(
  2207. 'type' => 'success',
  2208. 'msg' => 'Task completed'
  2209. ));
  2210. }
  2211. }
  2212. }
  2213. else {
  2214. echo json_encode(array(
  2215. 'type' => 'error',
  2216. 'msg' => 'Incomplete post data'
  2217. ));
  2218. }
  2219. }
  2220. else {
  2221. echo json_encode(array(
  2222. 'type' => 'error',
  2223. 'msg' => 'Incomplete post data'
  2224. ));
  2225. }
  2226. break;
  2227. case "alias-domain":
  2228. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2229. $items = (array)json_decode($_POST['items'], true);
  2230. $attr = (array)json_decode($_POST['attr'], true);
  2231. $postarray = array_merge(array('alias_domain' => $items), $attr);
  2232. if (is_array($postarray['alias_domain'])) {
  2233. if (mailbox('edit', 'alias_domain', $postarray) === false) {
  2234. if (isset($_SESSION['return'])) {
  2235. echo json_encode($_SESSION['return']);
  2236. }
  2237. else {
  2238. echo json_encode(array(
  2239. 'type' => 'error',
  2240. 'msg' => 'Edit failed'
  2241. ));
  2242. }
  2243. exit();
  2244. }
  2245. else {
  2246. if (isset($_SESSION['return'])) {
  2247. echo json_encode($_SESSION['return']);
  2248. }
  2249. else {
  2250. echo json_encode(array(
  2251. 'type' => 'success',
  2252. 'msg' => 'Task completed'
  2253. ));
  2254. }
  2255. }
  2256. }
  2257. else {
  2258. echo json_encode(array(
  2259. 'type' => 'error',
  2260. 'msg' => 'Incomplete post data'
  2261. ));
  2262. }
  2263. }
  2264. else {
  2265. echo json_encode(array(
  2266. 'type' => 'error',
  2267. 'msg' => 'Incomplete post data'
  2268. ));
  2269. }
  2270. break;
  2271. case "spam-score":
  2272. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2273. $items = (array)json_decode($_POST['items'], true);
  2274. $attr = (array)json_decode($_POST['attr'], true);
  2275. $postarray = array_merge(array('username' => $items), $attr);
  2276. if (is_array($postarray['username'])) {
  2277. if (mailbox('edit', 'spam_score', $postarray) === false) {
  2278. if (isset($_SESSION['return'])) {
  2279. echo json_encode($_SESSION['return']);
  2280. }
  2281. else {
  2282. echo json_encode(array(
  2283. 'type' => 'error',
  2284. 'msg' => 'Edit failed'
  2285. ));
  2286. }
  2287. exit();
  2288. }
  2289. else {
  2290. if (isset($_SESSION['return'])) {
  2291. echo json_encode($_SESSION['return']);
  2292. }
  2293. else {
  2294. echo json_encode(array(
  2295. 'type' => 'success',
  2296. 'msg' => 'Task completed'
  2297. ));
  2298. }
  2299. }
  2300. }
  2301. else {
  2302. echo json_encode(array(
  2303. 'type' => 'error',
  2304. 'msg' => 'Incomplete post data'
  2305. ));
  2306. }
  2307. }
  2308. else {
  2309. echo json_encode(array(
  2310. 'type' => 'error',
  2311. 'msg' => 'Incomplete post data'
  2312. ));
  2313. }
  2314. break;
  2315. case "domain-admin":
  2316. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2317. $items = (array)json_decode($_POST['items'], true);
  2318. $attr = (array)json_decode($_POST['attr'], true);
  2319. $postarray = array_merge(array('username' => $items), $attr);
  2320. if (is_array($postarray['username'])) {
  2321. if (domain_admin('edit', $postarray) === false) {
  2322. if (isset($_SESSION['return'])) {
  2323. echo json_encode($_SESSION['return']);
  2324. }
  2325. else {
  2326. echo json_encode(array(
  2327. 'type' => 'error',
  2328. 'msg' => 'Edit failed'
  2329. ));
  2330. }
  2331. exit();
  2332. }
  2333. else {
  2334. if (isset($_SESSION['return'])) {
  2335. echo json_encode($_SESSION['return']);
  2336. }
  2337. else {
  2338. echo json_encode(array(
  2339. 'type' => 'success',
  2340. 'msg' => 'Task completed'
  2341. ));
  2342. }
  2343. }
  2344. }
  2345. else {
  2346. echo json_encode(array(
  2347. 'type' => 'error',
  2348. 'msg' => 'Incomplete post data'
  2349. ));
  2350. }
  2351. }
  2352. else {
  2353. echo json_encode(array(
  2354. 'type' => 'error',
  2355. 'msg' => 'Incomplete post data'
  2356. ));
  2357. }
  2358. break;
  2359. case "fwdhost":
  2360. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2361. $items = (array)json_decode($_POST['items'], true);
  2362. $attr = (array)json_decode($_POST['attr'], true);
  2363. $postarray = array_merge(array('fwdhost' => $items), $attr);
  2364. if (is_array($postarray['fwdhost'])) {
  2365. if (fwdhost('edit', $postarray) === false) {
  2366. if (isset($_SESSION['return'])) {
  2367. echo json_encode($_SESSION['return']);
  2368. }
  2369. else {
  2370. echo json_encode(array(
  2371. 'type' => 'error',
  2372. 'msg' => 'Edit failed'
  2373. ));
  2374. }
  2375. exit();
  2376. }
  2377. else {
  2378. if (isset($_SESSION['return'])) {
  2379. echo json_encode($_SESSION['return']);
  2380. }
  2381. else {
  2382. echo json_encode(array(
  2383. 'type' => 'success',
  2384. 'msg' => 'Task completed'
  2385. ));
  2386. }
  2387. }
  2388. }
  2389. else {
  2390. echo json_encode(array(
  2391. 'type' => 'error',
  2392. 'msg' => 'Incomplete post data'
  2393. ));
  2394. }
  2395. }
  2396. else {
  2397. echo json_encode(array(
  2398. 'type' => 'error',
  2399. 'msg' => 'Incomplete post data'
  2400. ));
  2401. }
  2402. break;
  2403. case "fail2ban":
  2404. // No items
  2405. if (isset($_POST['attr'])) {
  2406. $attr = (array)json_decode($_POST['attr'], true);
  2407. if (fail2ban('edit', $attr) === false) {
  2408. if (isset($_SESSION['return'])) {
  2409. echo json_encode($_SESSION['return']);
  2410. }
  2411. else {
  2412. echo json_encode(array(
  2413. 'type' => 'error',
  2414. 'msg' => 'Edit failed'
  2415. ));
  2416. }
  2417. exit();
  2418. }
  2419. else {
  2420. if (isset($_SESSION['return'])) {
  2421. echo json_encode($_SESSION['return']);
  2422. }
  2423. else {
  2424. echo json_encode(array(
  2425. 'type' => 'success',
  2426. 'msg' => 'Task completed'
  2427. ));
  2428. }
  2429. }
  2430. }
  2431. else {
  2432. echo json_encode(array(
  2433. 'type' => 'error',
  2434. 'msg' => 'Incomplete post data'
  2435. ));
  2436. }
  2437. break;
  2438. case "self":
  2439. // No items, logged-in user, users and domain admins
  2440. if ($_SESSION['mailcow_cc_role'] == "domainadmin") {
  2441. if (isset($_POST['attr'])) {
  2442. $attr = (array)json_decode($_POST['attr'], true);
  2443. if (domain_admin('edit', $attr) === false) {
  2444. if (isset($_SESSION['return'])) {
  2445. echo json_encode($_SESSION['return']);
  2446. }
  2447. else {
  2448. echo json_encode(array(
  2449. 'type' => 'error',
  2450. 'msg' => 'Edit failed'
  2451. ));
  2452. }
  2453. exit();
  2454. }
  2455. else {
  2456. if (isset($_SESSION['return'])) {
  2457. echo json_encode($_SESSION['return']);
  2458. }
  2459. else {
  2460. echo json_encode(array(
  2461. 'type' => 'success',
  2462. 'msg' => 'Task completed'
  2463. ));
  2464. }
  2465. }
  2466. }
  2467. else {
  2468. echo json_encode(array(
  2469. 'type' => 'error',
  2470. 'msg' => 'Incomplete post data'
  2471. ));
  2472. }
  2473. }
  2474. elseif ($_SESSION['mailcow_cc_role'] == "user") {
  2475. if (isset($_POST['attr'])) {
  2476. $attr = (array)json_decode($_POST['attr'], true);
  2477. if (edit_user_account($attr) === false) {
  2478. if (isset($_SESSION['return'])) {
  2479. echo json_encode($_SESSION['return']);
  2480. }
  2481. else {
  2482. echo json_encode(array(
  2483. 'type' => 'error',
  2484. 'msg' => 'Edit failed'
  2485. ));
  2486. }
  2487. exit();
  2488. }
  2489. else {
  2490. if (isset($_SESSION['return'])) {
  2491. echo json_encode($_SESSION['return']);
  2492. }
  2493. else {
  2494. echo json_encode(array(
  2495. 'type' => 'success',
  2496. 'msg' => 'Task completed'
  2497. ));
  2498. }
  2499. }
  2500. }
  2501. else {
  2502. echo json_encode(array(
  2503. 'type' => 'error',
  2504. 'msg' => 'Incomplete post data'
  2505. ));
  2506. }
  2507. }
  2508. elseif ($_SESSION['mailcow_cc_role'] == "admin") {
  2509. if (isset($_POST['attr'])) {
  2510. $attr = (array)json_decode($_POST['attr'], true);
  2511. if (edit_admin_account($attr) === false) {
  2512. if (isset($_SESSION['return'])) {
  2513. echo json_encode($_SESSION['return']);
  2514. }
  2515. else {
  2516. echo json_encode(array(
  2517. 'type' => 'error',
  2518. 'msg' => 'Edit failed'
  2519. ));
  2520. }
  2521. exit();
  2522. }
  2523. else {
  2524. if (isset($_SESSION['return'])) {
  2525. echo json_encode($_SESSION['return']);
  2526. }
  2527. else {
  2528. echo json_encode(array(
  2529. 'type' => 'success',
  2530. 'msg' => 'Task completed'
  2531. ));
  2532. }
  2533. }
  2534. }
  2535. else {
  2536. echo json_encode(array(
  2537. 'type' => 'error',
  2538. 'msg' => 'Incomplete post data'
  2539. ));
  2540. }
  2541. }
  2542. break;
  2543. }
  2544. break;
  2545. }
  2546. }
  2547. }