json_api.php 104 KB

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