json_api.php 82 KB

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