json_api.php 89 KB

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