2
0

json_api.php 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355
  1. <?php
  2. /*
  3. edit/alias => POST data:
  4. {
  5. address: {a, b, c}, (where a, b, c represent alias addresses)
  6. active: 1 (0 or 1)
  7. }
  8. delete/alias => POST data:
  9. {
  10. address: {a, b, c}, (where a, b, c represent alias addresses)
  11. }
  12. */
  13. header('Content-Type: application/json');
  14. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
  15. error_reporting(0);
  16. function api_log($postarray) {
  17. global $redis;
  18. $data_var = array();
  19. foreach ($postarray as $data => &$value) {
  20. if ($data == 'csrf_token') {
  21. continue;
  22. }
  23. if ($value = json_decode($value, true)) {
  24. unset($value["csrf_token"]);
  25. foreach ($value as $key => &$val) {
  26. if(preg_match("/pass/i", $key)) {
  27. $val = '********';
  28. }
  29. }
  30. $value = json_encode($value);
  31. }
  32. $data_var[] = $data . "='" . $value . "'";
  33. }
  34. try {
  35. $log_line = array(
  36. 'time' => time(),
  37. 'uri' => $_SERVER['REQUEST_URI'],
  38. 'method' => $_SERVER['REQUEST_METHOD'],
  39. 'remote' => $_SERVER['REMOTE_ADDR'],
  40. 'data' => implode(', ', $data_var)
  41. );
  42. $redis->lPush('API_LOG', json_encode($log_line));
  43. }
  44. catch (RedisException $e) {
  45. $_SESSION['return'] = array(
  46. 'type' => 'danger',
  47. 'msg' => 'Redis: '.$e
  48. );
  49. return false;
  50. }
  51. }
  52. api_log($_POST);
  53. if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_username'])) {
  54. if (isset($_GET['query'])) {
  55. $query = explode('/', $_GET['query']);
  56. $action = (isset($query[0])) ? $query[0] : null;
  57. $category = (isset($query[1])) ? $query[1] : null;
  58. $object = (isset($query[2])) ? $query[2] : null;
  59. $extra = (isset($query[3])) ? $query[3] : null;
  60. switch ($action) {
  61. case "add":
  62. switch ($category) {
  63. case "time_limited_alias":
  64. if (isset($_POST['attr'])) {
  65. $attr = (array)json_decode($_POST['attr'], true);
  66. if (mailbox('add', 'time_limited_alias', $attr) === false) {
  67. if (isset($_SESSION['return'])) {
  68. echo json_encode($_SESSION['return']);
  69. }
  70. else {
  71. echo json_encode(array(
  72. 'type' => 'error',
  73. 'msg' => 'Cannot add item'
  74. ));
  75. }
  76. }
  77. else {
  78. if (isset($_SESSION['return'])) {
  79. echo json_encode($_SESSION['return']);
  80. }
  81. else {
  82. echo json_encode(array(
  83. 'type' => 'success',
  84. 'msg' => 'Task completed'
  85. ));
  86. }
  87. }
  88. }
  89. else {
  90. echo json_encode(array(
  91. 'type' => 'error',
  92. 'msg' => 'Cannot find attributes in post data'
  93. ));
  94. }
  95. break;
  96. case "relayhost":
  97. if (isset($_POST['attr'])) {
  98. $attr = (array)json_decode($_POST['attr'], true);
  99. if (relayhost('add', $attr) === false) {
  100. if (isset($_SESSION['return'])) {
  101. echo json_encode($_SESSION['return']);
  102. }
  103. else {
  104. echo json_encode(array(
  105. 'type' => 'error',
  106. 'msg' => 'Cannot add item'
  107. ));
  108. }
  109. }
  110. else {
  111. if (isset($_SESSION['return'])) {
  112. echo json_encode($_SESSION['return']);
  113. }
  114. else {
  115. echo json_encode(array(
  116. 'type' => 'success',
  117. 'msg' => 'Task completed'
  118. ));
  119. }
  120. }
  121. }
  122. else {
  123. echo json_encode(array(
  124. 'type' => 'error',
  125. 'msg' => 'Cannot find attributes in post data'
  126. ));
  127. }
  128. break;
  129. case "mailbox":
  130. if (isset($_POST['attr'])) {
  131. $attr = (array)json_decode($_POST['attr'], true);
  132. if (mailbox('add', 'mailbox', $attr) === false) {
  133. if (isset($_SESSION['return'])) {
  134. echo json_encode($_SESSION['return']);
  135. }
  136. else {
  137. echo json_encode(array(
  138. 'type' => 'error',
  139. 'msg' => 'Cannot add item'
  140. ));
  141. }
  142. }
  143. else {
  144. if (isset($_SESSION['return'])) {
  145. echo json_encode($_SESSION['return']);
  146. }
  147. else {
  148. echo json_encode(array(
  149. 'type' => 'success',
  150. 'msg' => 'Task completed'
  151. ));
  152. }
  153. }
  154. }
  155. else {
  156. echo json_encode(array(
  157. 'type' => 'error',
  158. 'msg' => 'Cannot find attributes in post data'
  159. ));
  160. }
  161. break;
  162. case "domain":
  163. if (isset($_POST['attr'])) {
  164. $attr = (array)json_decode($_POST['attr'], true);
  165. if (mailbox('add', 'domain', $attr) === false) {
  166. if (isset($_SESSION['return'])) {
  167. echo json_encode($_SESSION['return']);
  168. }
  169. else {
  170. echo json_encode(array(
  171. 'type' => 'error',
  172. 'msg' => 'Cannot add item'
  173. ));
  174. }
  175. }
  176. else {
  177. if (isset($_SESSION['return'])) {
  178. echo json_encode($_SESSION['return']);
  179. }
  180. else {
  181. echo json_encode(array(
  182. 'type' => 'success',
  183. 'msg' => 'Task completed'
  184. ));
  185. }
  186. }
  187. }
  188. else {
  189. echo json_encode(array(
  190. 'type' => 'error',
  191. 'msg' => 'Cannot find attributes in post data'
  192. ));
  193. }
  194. break;
  195. case "resource":
  196. if (isset($_POST['attr'])) {
  197. $attr = (array)json_decode($_POST['attr'], true);
  198. if (mailbox('add', 'resource', $attr) === false) {
  199. if (isset($_SESSION['return'])) {
  200. echo json_encode($_SESSION['return']);
  201. }
  202. else {
  203. echo json_encode(array(
  204. 'type' => 'error',
  205. 'msg' => 'Cannot add item'
  206. ));
  207. }
  208. }
  209. else {
  210. if (isset($_SESSION['return'])) {
  211. echo json_encode($_SESSION['return']);
  212. }
  213. else {
  214. echo json_encode(array(
  215. 'type' => 'success',
  216. 'msg' => 'Task completed'
  217. ));
  218. }
  219. }
  220. }
  221. else {
  222. echo json_encode(array(
  223. 'type' => 'error',
  224. 'msg' => 'Cannot find attributes in post data'
  225. ));
  226. }
  227. break;
  228. case "alias":
  229. if (isset($_POST['attr'])) {
  230. $attr = (array)json_decode($_POST['attr'], true);
  231. if (mailbox('add', 'alias', $attr) === false) {
  232. if (isset($_SESSION['return'])) {
  233. echo json_encode($_SESSION['return']);
  234. }
  235. else {
  236. echo json_encode(array(
  237. 'type' => 'error',
  238. 'msg' => 'Cannot add item'
  239. ));
  240. }
  241. }
  242. else {
  243. if (isset($_SESSION['return'])) {
  244. echo json_encode($_SESSION['return']);
  245. }
  246. else {
  247. echo json_encode(array(
  248. 'type' => 'success',
  249. 'msg' => 'Task completed'
  250. ));
  251. }
  252. }
  253. }
  254. else {
  255. echo json_encode(array(
  256. 'type' => 'error',
  257. 'msg' => 'Cannot find attributes in post data'
  258. ));
  259. }
  260. break;
  261. case "filter":
  262. if (isset($_POST['attr'])) {
  263. $attr = (array)json_decode($_POST['attr'], true);
  264. if (mailbox('add', 'filter', $attr) === false) {
  265. if (isset($_SESSION['return'])) {
  266. echo json_encode($_SESSION['return']);
  267. }
  268. else {
  269. echo json_encode(array(
  270. 'type' => 'error',
  271. 'msg' => 'Cannot add item'
  272. ));
  273. }
  274. }
  275. else {
  276. if (isset($_SESSION['return'])) {
  277. echo json_encode($_SESSION['return']);
  278. }
  279. else {
  280. echo json_encode(array(
  281. 'type' => 'success',
  282. 'msg' => 'Task completed'
  283. ));
  284. }
  285. }
  286. }
  287. else {
  288. echo json_encode(array(
  289. 'type' => 'error',
  290. 'msg' => 'Cannot find attributes in post data'
  291. ));
  292. }
  293. break;
  294. case "domain-policy":
  295. if (isset($_POST['attr'])) {
  296. $attr = (array)json_decode($_POST['attr'], true);
  297. if (policy('add', 'domain', $attr) === false) {
  298. if (isset($_SESSION['return'])) {
  299. echo json_encode($_SESSION['return']);
  300. }
  301. else {
  302. echo json_encode(array(
  303. 'type' => 'error',
  304. 'msg' => 'Cannot add item'
  305. ));
  306. }
  307. }
  308. else {
  309. if (isset($_SESSION['return'])) {
  310. echo json_encode($_SESSION['return']);
  311. }
  312. else {
  313. echo json_encode(array(
  314. 'type' => 'success',
  315. 'msg' => 'Task completed'
  316. ));
  317. }
  318. }
  319. }
  320. else {
  321. echo json_encode(array(
  322. 'type' => 'error',
  323. 'msg' => 'Cannot find attributes in post data'
  324. ));
  325. }
  326. break;
  327. case "mailbox-policy":
  328. if (isset($_POST['attr'])) {
  329. $attr = (array)json_decode($_POST['attr'], true);
  330. if (policy('add', 'mailbox', $attr) === false) {
  331. if (isset($_SESSION['return'])) {
  332. echo json_encode($_SESSION['return']);
  333. }
  334. else {
  335. echo json_encode(array(
  336. 'type' => 'error',
  337. 'msg' => 'Cannot add item'
  338. ));
  339. }
  340. }
  341. else {
  342. if (isset($_SESSION['return'])) {
  343. echo json_encode($_SESSION['return']);
  344. }
  345. else {
  346. echo json_encode(array(
  347. 'type' => 'success',
  348. 'msg' => 'Task completed'
  349. ));
  350. }
  351. }
  352. }
  353. else {
  354. echo json_encode(array(
  355. 'type' => 'error',
  356. 'msg' => 'Cannot find attributes in post data'
  357. ));
  358. }
  359. break;
  360. case "alias-domain":
  361. if (isset($_POST['attr'])) {
  362. $attr = (array)json_decode($_POST['attr'], true);
  363. if (mailbox('add', 'alias_domain', $attr) === false) {
  364. if (isset($_SESSION['return'])) {
  365. echo json_encode($_SESSION['return']);
  366. }
  367. else {
  368. echo json_encode(array(
  369. 'type' => 'error',
  370. 'msg' => 'Cannot add item'
  371. ));
  372. }
  373. }
  374. else {
  375. if (isset($_SESSION['return'])) {
  376. echo json_encode($_SESSION['return']);
  377. }
  378. else {
  379. echo json_encode(array(
  380. 'type' => 'success',
  381. 'msg' => 'Task completed'
  382. ));
  383. }
  384. }
  385. }
  386. else {
  387. echo json_encode(array(
  388. 'type' => 'error',
  389. 'msg' => 'Cannot find attributes in post data'
  390. ));
  391. }
  392. break;
  393. case "fwdhost":
  394. if (isset($_POST['attr'])) {
  395. $attr = (array)json_decode($_POST['attr'], true);
  396. if (fwdhost('add', $attr) === false) {
  397. if (isset($_SESSION['return'])) {
  398. echo json_encode($_SESSION['return']);
  399. }
  400. else {
  401. echo json_encode(array(
  402. 'type' => 'error',
  403. 'msg' => 'Cannot add item'
  404. ));
  405. }
  406. }
  407. else {
  408. if (isset($_SESSION['return'])) {
  409. echo json_encode($_SESSION['return']);
  410. }
  411. else {
  412. echo json_encode(array(
  413. 'type' => 'success',
  414. 'msg' => 'Task completed'
  415. ));
  416. }
  417. }
  418. }
  419. else {
  420. echo json_encode(array(
  421. 'type' => 'error',
  422. 'msg' => 'Cannot find attributes in post data'
  423. ));
  424. }
  425. break;
  426. case "dkim":
  427. if (isset($_POST['attr'])) {
  428. $attr = (array)json_decode($_POST['attr'], true);
  429. if (dkim('add', $attr) === false) {
  430. if (isset($_SESSION['return'])) {
  431. echo json_encode($_SESSION['return']);
  432. }
  433. else {
  434. echo json_encode(array(
  435. 'type' => 'error',
  436. 'msg' => 'Cannot add item'
  437. ));
  438. }
  439. }
  440. else {
  441. if (isset($_SESSION['return'])) {
  442. echo json_encode($_SESSION['return']);
  443. }
  444. else {
  445. echo json_encode(array(
  446. 'type' => 'success',
  447. 'msg' => 'Task completed'
  448. ));
  449. }
  450. }
  451. }
  452. else {
  453. echo json_encode(array(
  454. 'type' => 'error',
  455. 'msg' => 'Cannot find attributes in post data'
  456. ));
  457. }
  458. break;
  459. case "dkim_import":
  460. if (isset($_POST['attr'])) {
  461. $attr = (array)json_decode($_POST['attr'], true);
  462. if (dkim('import', $attr) === false) {
  463. if (isset($_SESSION['return'])) {
  464. echo json_encode($_SESSION['return']);
  465. }
  466. else {
  467. echo json_encode(array(
  468. 'type' => 'error',
  469. 'msg' => 'Cannot add item'
  470. ));
  471. }
  472. }
  473. else {
  474. if (isset($_SESSION['return'])) {
  475. echo json_encode($_SESSION['return']);
  476. }
  477. else {
  478. echo json_encode(array(
  479. 'type' => 'success',
  480. 'msg' => 'Task completed'
  481. ));
  482. }
  483. }
  484. }
  485. else {
  486. echo json_encode(array(
  487. 'type' => 'error',
  488. 'msg' => 'Cannot find attributes in post data'
  489. ));
  490. }
  491. break;
  492. case "domain-admin":
  493. if (isset($_POST['attr'])) {
  494. $attr = (array)json_decode($_POST['attr'], true);
  495. if (domain_admin('add', $attr) === false) {
  496. if (isset($_SESSION['return'])) {
  497. echo json_encode($_SESSION['return']);
  498. }
  499. else {
  500. echo json_encode(array(
  501. 'type' => 'error',
  502. 'msg' => 'Cannot add item'
  503. ));
  504. }
  505. }
  506. else {
  507. if (isset($_SESSION['return'])) {
  508. echo json_encode($_SESSION['return']);
  509. }
  510. else {
  511. echo json_encode(array(
  512. 'type' => 'success',
  513. 'msg' => 'Task completed'
  514. ));
  515. }
  516. }
  517. }
  518. else {
  519. echo json_encode(array(
  520. 'type' => 'error',
  521. 'msg' => 'Cannot find attributes in post data'
  522. ));
  523. }
  524. break;
  525. case "syncjob":
  526. if (isset($_POST['attr'])) {
  527. $attr = (array)json_decode($_POST['attr'], true);
  528. if (mailbox('add', 'syncjob', $attr) === false) {
  529. if (isset($_SESSION['return'])) {
  530. echo json_encode($_SESSION['return']);
  531. }
  532. else {
  533. echo json_encode(array(
  534. 'type' => 'error',
  535. 'msg' => 'Cannot add item'
  536. ));
  537. }
  538. }
  539. else {
  540. if (isset($_SESSION['return'])) {
  541. echo json_encode($_SESSION['return']);
  542. }
  543. else {
  544. echo json_encode(array(
  545. 'type' => 'success',
  546. 'msg' => 'Task completed'
  547. ));
  548. }
  549. }
  550. }
  551. else {
  552. echo json_encode(array(
  553. 'type' => 'error',
  554. 'msg' => 'Cannot find attributes in post data'
  555. ));
  556. }
  557. break;
  558. case "bcc":
  559. if (isset($_POST['attr'])) {
  560. $attr = (array)json_decode($_POST['attr'], true);
  561. if (bcc('add', $attr) === false) {
  562. if (isset($_SESSION['return'])) {
  563. echo json_encode($_SESSION['return']);
  564. }
  565. else {
  566. echo json_encode(array(
  567. 'type' => 'error',
  568. 'msg' => 'Cannot add item'
  569. ));
  570. }
  571. }
  572. else {
  573. if (isset($_SESSION['return'])) {
  574. echo json_encode($_SESSION['return']);
  575. }
  576. else {
  577. echo json_encode(array(
  578. 'type' => 'success',
  579. 'msg' => 'Task completed'
  580. ));
  581. }
  582. }
  583. }
  584. else {
  585. echo json_encode(array(
  586. 'type' => 'error',
  587. 'msg' => 'Cannot find attributes in post data'
  588. ));
  589. }
  590. break;
  591. case "recipient_map":
  592. if (isset($_POST['attr'])) {
  593. $attr = (array)json_decode($_POST['attr'], true);
  594. if (recipient_map('add', $attr) === false) {
  595. if (isset($_SESSION['return'])) {
  596. echo json_encode($_SESSION['return']);
  597. }
  598. else {
  599. echo json_encode(array(
  600. 'type' => 'error',
  601. 'msg' => 'Cannot add item'
  602. ));
  603. }
  604. }
  605. else {
  606. if (isset($_SESSION['return'])) {
  607. echo json_encode($_SESSION['return']);
  608. }
  609. else {
  610. echo json_encode(array(
  611. 'type' => 'success',
  612. 'msg' => 'Task completed'
  613. ));
  614. }
  615. }
  616. }
  617. else {
  618. echo json_encode(array(
  619. 'type' => 'error',
  620. 'msg' => 'Cannot find attributes in post data'
  621. ));
  622. }
  623. break;
  624. }
  625. break;
  626. case "get":
  627. switch ($category) {
  628. case "rspamd":
  629. switch ($object) {
  630. case "stat":
  631. $data = file_get_contents('http://rspamd-mailcow:11334/stat');
  632. if (!empty($data)) {
  633. echo $data;
  634. }
  635. elseif (!isset($data) || empty($data)) {
  636. echo '{}';
  637. }
  638. break;
  639. case "graph":
  640. switch ($extra) {
  641. case "hourly":
  642. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=hourly');
  643. if (!empty($data)) {
  644. $data_array = json_decode($data, true);
  645. $rejected['label'] = "reject";
  646. foreach ($data_array[0] as $dataset) {
  647. $rejected['data'][] = $dataset;
  648. }
  649. $temp_reject['label'] = "temp_reject";
  650. foreach ($data_array[1] as $dataset) {
  651. $temp_reject['data'][] = $dataset;
  652. }
  653. $add_header['label'] = "add_header";
  654. foreach ($data_array[2] as $dataset) {
  655. $add_header['data'][] = $dataset;
  656. }
  657. $prob_spam['label'] = "prob_spam";
  658. foreach ($data_array[3] as $dataset) {
  659. $prob_spam['data'][] = $dataset;
  660. }
  661. $greylist['label'] = "greylist";
  662. foreach ($data_array[4] as $dataset) {
  663. $greylist['data'][] = $dataset;
  664. }
  665. $clean['label'] = "clean";
  666. $clean['pointStyle'] = "cross";
  667. foreach ($data_array[5] as $dataset) {
  668. $clean['data'][] = $dataset;
  669. }
  670. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  671. }
  672. elseif (!isset($data) || empty($data)) {
  673. echo '{}';
  674. }
  675. break;
  676. case "daily":
  677. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=daily');
  678. if (!empty($data)) {
  679. $data_array = json_decode($data, true);
  680. $rejected['label'] = "reject";
  681. foreach ($data_array[0] as $dataset) {
  682. $rejected['data'][] = $dataset;
  683. }
  684. $temp_reject['label'] = "temp_reject";
  685. foreach ($data_array[1] as $dataset) {
  686. $temp_reject['data'][] = $dataset;
  687. }
  688. $add_header['label'] = "add_header";
  689. foreach ($data_array[2] as $dataset) {
  690. $add_header['data'][] = $dataset;
  691. }
  692. $prob_spam['label'] = "prob_spam";
  693. foreach ($data_array[3] as $dataset) {
  694. $prob_spam['data'][] = $dataset;
  695. }
  696. $greylist['label'] = "greylist";
  697. foreach ($data_array[4] as $dataset) {
  698. $greylist['data'][] = $dataset;
  699. }
  700. $clean['label'] = "clean";
  701. $clean['pointStyle'] = "cross";
  702. foreach ($data_array[5] as $dataset) {
  703. $clean['data'][] = $dataset;
  704. }
  705. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  706. }
  707. elseif (!isset($data) || empty($data)) {
  708. echo '{}';
  709. }
  710. break;
  711. case "weekly":
  712. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=weekly');
  713. if (!empty($data)) {
  714. $data_array = json_decode($data, true);
  715. $rejected['label'] = "reject";
  716. foreach ($data_array[0] as $dataset) {
  717. $rejected['data'][] = $dataset;
  718. }
  719. $temp_reject['label'] = "temp_reject";
  720. foreach ($data_array[1] as $dataset) {
  721. $temp_reject['data'][] = $dataset;
  722. }
  723. $add_header['label'] = "add_header";
  724. foreach ($data_array[2] as $dataset) {
  725. $add_header['data'][] = $dataset;
  726. }
  727. $prob_spam['label'] = "prob_spam";
  728. foreach ($data_array[3] as $dataset) {
  729. $prob_spam['data'][] = $dataset;
  730. }
  731. $greylist['label'] = "greylist";
  732. foreach ($data_array[4] as $dataset) {
  733. $greylist['data'][] = $dataset;
  734. }
  735. $clean['label'] = "clean";
  736. $clean['pointStyle'] = "cross";
  737. foreach ($data_array[5] as $dataset) {
  738. $clean['data'][] = $dataset;
  739. }
  740. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  741. }
  742. elseif (!isset($data) || empty($data)) {
  743. echo '{}';
  744. }
  745. break;
  746. case "monthly":
  747. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=monthly');
  748. if (!empty($data)) {
  749. $data_array = json_decode($data, true);
  750. $rejected['label'] = "reject";
  751. foreach ($data_array[0] as $dataset) {
  752. $rejected['data'][] = $dataset;
  753. }
  754. $temp_reject['label'] = "temp_reject";
  755. foreach ($data_array[1] as $dataset) {
  756. $temp_reject['data'][] = $dataset;
  757. }
  758. $add_header['label'] = "add_header";
  759. foreach ($data_array[2] as $dataset) {
  760. $add_header['data'][] = $dataset;
  761. }
  762. $prob_spam['label'] = "prob_spam";
  763. foreach ($data_array[3] as $dataset) {
  764. $prob_spam['data'][] = $dataset;
  765. }
  766. $greylist['label'] = "greylist";
  767. foreach ($data_array[4] as $dataset) {
  768. $greylist['data'][] = $dataset;
  769. }
  770. $clean['label'] = "clean";
  771. $clean['pointStyle'] = "cross";
  772. foreach ($data_array[5] as $dataset) {
  773. $clean['data'][] = $dataset;
  774. }
  775. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  776. }
  777. elseif (!isset($data) || empty($data)) {
  778. echo '{}';
  779. }
  780. break;
  781. }
  782. break;
  783. }
  784. break;
  785. case "domain":
  786. switch ($object) {
  787. case "all":
  788. $domains = mailbox('get', 'domains');
  789. if (!empty($domains)) {
  790. foreach ($domains as $domain) {
  791. if ($details = mailbox('get', 'domain_details', $domain)) {
  792. $data[] = $details;
  793. }
  794. else {
  795. continue;
  796. }
  797. }
  798. if (!isset($data) || empty($data)) {
  799. echo '{}';
  800. }
  801. else {
  802. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  803. }
  804. }
  805. else {
  806. echo '{}';
  807. }
  808. break;
  809. default:
  810. $data = mailbox('get', 'domain_details', $object);
  811. if (!isset($data) || empty($data)) {
  812. echo '{}';
  813. }
  814. else {
  815. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  816. }
  817. break;
  818. }
  819. break;
  820. case "relayhost":
  821. switch ($object) {
  822. case "all":
  823. $relayhosts = relayhost('get');
  824. if (!empty($relayhosts)) {
  825. foreach ($relayhosts as $relayhost) {
  826. if ($details = relayhost('details', $relayhost['id'])) {
  827. $data[] = $details;
  828. }
  829. else {
  830. continue;
  831. }
  832. }
  833. if (!isset($data) || empty($data)) {
  834. echo '{}';
  835. }
  836. else {
  837. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  838. }
  839. }
  840. else {
  841. echo '{}';
  842. }
  843. break;
  844. default:
  845. $data = relayhost('details', $object);
  846. if (!isset($data) || empty($data)) {
  847. echo '{}';
  848. }
  849. else {
  850. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  851. }
  852. break;
  853. }
  854. break;
  855. case "logs":
  856. switch ($object) {
  857. case "dovecot":
  858. // 0 is first record, so empty is fine
  859. if (isset($extra)) {
  860. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  861. $logs = get_logs('dovecot-mailcow', $extra);
  862. }
  863. else {
  864. $logs = get_logs('dovecot-mailcow');
  865. }
  866. if (isset($logs) && !empty($logs)) {
  867. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  868. }
  869. else {
  870. echo '{}';
  871. }
  872. break;
  873. case "netfilter":
  874. // 0 is first record, so empty is fine
  875. if (isset($extra)) {
  876. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  877. $logs = get_logs('netfilter-mailcow', $extra);
  878. }
  879. else {
  880. $logs = get_logs('netfilter-mailcow');
  881. }
  882. if (isset($logs) && !empty($logs)) {
  883. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  884. }
  885. else {
  886. echo '{}';
  887. }
  888. break;
  889. case "postfix":
  890. // 0 is first record, so empty is fine
  891. if (isset($extra)) {
  892. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  893. $logs = get_logs('postfix-mailcow', $extra);
  894. }
  895. else {
  896. $logs = get_logs('postfix-mailcow');
  897. }
  898. if (isset($logs) && !empty($logs)) {
  899. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  900. }
  901. else {
  902. echo '{}';
  903. }
  904. break;
  905. case "autodiscover":
  906. // 0 is first record, so empty is fine
  907. if (isset($extra)) {
  908. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  909. $logs = get_logs('autodiscover-mailcow', $extra);
  910. }
  911. else {
  912. $logs = get_logs('autodiscover-mailcow');
  913. }
  914. if (isset($logs) && !empty($logs)) {
  915. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  916. }
  917. else {
  918. echo '{}';
  919. }
  920. break;
  921. case "sogo":
  922. // 0 is first record, so empty is fine
  923. if (isset($extra)) {
  924. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  925. $logs = get_logs('sogo-mailcow', $extra);
  926. }
  927. else {
  928. $logs = get_logs('sogo-mailcow');
  929. }
  930. if (isset($logs) && !empty($logs)) {
  931. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  932. }
  933. else {
  934. echo '{}';
  935. }
  936. break;
  937. case "watchdog":
  938. // 0 is first record, so empty is fine
  939. if (isset($extra)) {
  940. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  941. $logs = get_logs('watchdog-mailcow', $extra);
  942. }
  943. else {
  944. $logs = get_logs('watchdog-mailcow');
  945. }
  946. if (isset($logs) && !empty($logs)) {
  947. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  948. }
  949. else {
  950. echo '{}';
  951. }
  952. break;
  953. case "acme":
  954. // 0 is first record, so empty is fine
  955. if (isset($extra)) {
  956. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  957. $logs = get_logs('acme-mailcow', $extra);
  958. }
  959. else {
  960. $logs = get_logs('acme-mailcow');
  961. }
  962. if (isset($logs) && !empty($logs)) {
  963. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  964. }
  965. else {
  966. echo '{}';
  967. }
  968. break;
  969. case "api":
  970. // 0 is first record, so empty is fine
  971. if (isset($extra)) {
  972. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  973. $logs = get_logs('api-mailcow', $extra);
  974. }
  975. else {
  976. $logs = get_logs('api-mailcow');
  977. }
  978. if (isset($logs) && !empty($logs)) {
  979. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  980. }
  981. else {
  982. echo '{}';
  983. }
  984. break;
  985. case "rspamd-history":
  986. // 0 is first record, so empty is fine
  987. if (isset($extra)) {
  988. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  989. $logs = get_logs('rspamd-history', $extra);
  990. }
  991. else {
  992. $logs = get_logs('rspamd-history');
  993. }
  994. if (isset($logs) && !empty($logs)) {
  995. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  996. }
  997. else {
  998. echo '{}';
  999. }
  1000. break;
  1001. }
  1002. break;
  1003. case "mailbox":
  1004. switch ($object) {
  1005. case "all":
  1006. $domains = mailbox('get', 'domains');
  1007. if (!empty($domains)) {
  1008. foreach ($domains as $domain) {
  1009. $mailboxes = mailbox('get', 'mailboxes', $domain);
  1010. if (!empty($mailboxes)) {
  1011. foreach ($mailboxes as $mailbox) {
  1012. if ($details = mailbox('get', 'mailbox_details', $mailbox)) {
  1013. $data[] = $details;
  1014. }
  1015. else {
  1016. continue;
  1017. }
  1018. }
  1019. }
  1020. }
  1021. if (!isset($data) || empty($data)) {
  1022. echo '{}';
  1023. }
  1024. else {
  1025. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1026. }
  1027. }
  1028. else {
  1029. echo '{}';
  1030. }
  1031. break;
  1032. default:
  1033. $data = mailbox('get', 'mailbox_details', $object);
  1034. if (!isset($data) || empty($data)) {
  1035. echo '{}';
  1036. }
  1037. else {
  1038. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1039. }
  1040. break;
  1041. }
  1042. break;
  1043. case "syncjobs":
  1044. switch ($object) {
  1045. case "all":
  1046. $domains = mailbox('get', 'domains');
  1047. if (!empty($domains)) {
  1048. foreach ($domains as $domain) {
  1049. $mailboxes = mailbox('get', 'mailboxes', $domain);
  1050. if (!empty($mailboxes)) {
  1051. foreach ($mailboxes as $mailbox) {
  1052. $syncjobs = mailbox('get', 'syncjobs', $mailbox);
  1053. if (!empty($syncjobs)) {
  1054. foreach ($syncjobs as $syncjob) {
  1055. if (isset($extra)) {
  1056. $details = mailbox('get', 'syncjob_details', $syncjob, explode(',', $extra));
  1057. }
  1058. else {
  1059. $details = mailbox('get', 'syncjob_details', $syncjob);
  1060. }
  1061. if ($details) {
  1062. $data[] = $details;
  1063. }
  1064. else {
  1065. continue;
  1066. }
  1067. }
  1068. }
  1069. }
  1070. }
  1071. }
  1072. if (!isset($data) || empty($data)) {
  1073. echo '{}';
  1074. }
  1075. else {
  1076. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1077. }
  1078. }
  1079. else {
  1080. echo '{}';
  1081. }
  1082. break;
  1083. default:
  1084. $syncjobs = mailbox('get', 'syncjobs', $object);
  1085. if (!empty($syncjobs)) {
  1086. foreach ($syncjobs as $syncjob) {
  1087. if (isset($extra)) {
  1088. $details = mailbox('get', 'syncjob_details', $syncjob, explode(',', $extra));
  1089. }
  1090. else {
  1091. $details = mailbox('get', 'syncjob_details', $syncjob);
  1092. }
  1093. if ($details) {
  1094. $data[] = $details;
  1095. }
  1096. else {
  1097. continue;
  1098. }
  1099. }
  1100. }
  1101. if (!isset($data) || empty($data)) {
  1102. echo '{}';
  1103. }
  1104. else {
  1105. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1106. }
  1107. break;
  1108. }
  1109. break;
  1110. case "active-user-sieve":
  1111. if (isset($object)) {
  1112. $sieve_filter = mailbox('get', 'active_user_sieve', $object);
  1113. if (!empty($sieve_filter)) {
  1114. $data[] = $sieve_filter;
  1115. }
  1116. }
  1117. if (!isset($data) || empty($data)) {
  1118. echo '{}';
  1119. }
  1120. else {
  1121. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1122. }
  1123. break;
  1124. case "filters":
  1125. switch ($object) {
  1126. case "all":
  1127. $domains = mailbox('get', 'domains');
  1128. if (!empty($domains)) {
  1129. foreach ($domains as $domain) {
  1130. $mailboxes = mailbox('get', 'mailboxes', $domain);
  1131. if (!empty($mailboxes)) {
  1132. foreach ($mailboxes as $mailbox) {
  1133. $filters = mailbox('get', 'filters', $mailbox);
  1134. if (!empty($filters)) {
  1135. foreach ($filters as $filter) {
  1136. if ($details = mailbox('get', 'filter_details', $filter)) {
  1137. $data[] = $details;
  1138. }
  1139. else {
  1140. continue;
  1141. }
  1142. }
  1143. }
  1144. }
  1145. }
  1146. }
  1147. if (!isset($data) || empty($data)) {
  1148. echo '{}';
  1149. }
  1150. else {
  1151. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1152. }
  1153. }
  1154. else {
  1155. echo '{}';
  1156. }
  1157. break;
  1158. default:
  1159. $filters = mailbox('get', 'filters', $object);
  1160. if (!empty($filters)) {
  1161. foreach ($filters as $filter) {
  1162. if ($details = mailbox('get', 'filter_details', $filter)) {
  1163. $data[] = $details;
  1164. }
  1165. else {
  1166. continue;
  1167. }
  1168. }
  1169. }
  1170. if (!isset($data) || empty($data)) {
  1171. echo '{}';
  1172. }
  1173. else {
  1174. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1175. }
  1176. break;
  1177. }
  1178. break;
  1179. case "bcc":
  1180. switch ($object) {
  1181. case "all":
  1182. $bcc_items = bcc('get');
  1183. if (!empty($bcc_items)) {
  1184. foreach ($bcc_items as $bcc_item) {
  1185. if ($details = bcc('details', $bcc_item)) {
  1186. $data[] = $details;
  1187. }
  1188. else {
  1189. continue;
  1190. }
  1191. }
  1192. }
  1193. if (!isset($data) || empty($data)) {
  1194. echo '{}';
  1195. }
  1196. else {
  1197. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1198. }
  1199. break;
  1200. default:
  1201. $data = bcc('details', $object);
  1202. if (!empty($data)) {
  1203. $data[] = $details;
  1204. }
  1205. if (!isset($data) || empty($data)) {
  1206. echo '{}';
  1207. }
  1208. else {
  1209. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1210. }
  1211. break;
  1212. }
  1213. break;
  1214. case "recipient_map":
  1215. switch ($object) {
  1216. case "all":
  1217. $recipient_map_items = recipient_map('get');
  1218. if (!empty($recipient_map_items)) {
  1219. foreach ($recipient_map_items as $recipient_map_item) {
  1220. if ($details = recipient_map('details', $recipient_map_item)) {
  1221. $data[] = $details;
  1222. }
  1223. else {
  1224. continue;
  1225. }
  1226. }
  1227. }
  1228. if (!isset($data) || empty($data)) {
  1229. echo '{}';
  1230. }
  1231. else {
  1232. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1233. }
  1234. break;
  1235. default:
  1236. $data = recipient_map('details', $object);
  1237. if (!empty($data)) {
  1238. $data[] = $details;
  1239. }
  1240. if (!isset($data) || empty($data)) {
  1241. echo '{}';
  1242. }
  1243. else {
  1244. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1245. }
  1246. break;
  1247. }
  1248. break;
  1249. case "policy_wl_mailbox":
  1250. switch ($object) {
  1251. default:
  1252. $data = policy('get', 'mailbox', $object)['whitelist'];
  1253. if (!isset($data) || empty($data)) {
  1254. echo '{}';
  1255. }
  1256. else {
  1257. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1258. }
  1259. break;
  1260. }
  1261. break;
  1262. case "policy_bl_mailbox":
  1263. switch ($object) {
  1264. default:
  1265. $data = policy('get', 'mailbox', $object)['blacklist'];
  1266. if (!isset($data) || empty($data)) {
  1267. echo '{}';
  1268. }
  1269. else {
  1270. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1271. }
  1272. break;
  1273. }
  1274. break;
  1275. case "policy_wl_domain":
  1276. switch ($object) {
  1277. default:
  1278. $data = policy('get', 'domain', $object)['whitelist'];
  1279. if (!isset($data) || empty($data)) {
  1280. echo '{}';
  1281. }
  1282. else {
  1283. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1284. }
  1285. break;
  1286. }
  1287. break;
  1288. case "policy_bl_domain":
  1289. switch ($object) {
  1290. default:
  1291. $data = policy('get', 'domain', $object)['blacklist'];
  1292. if (!isset($data) || empty($data)) {
  1293. echo '{}';
  1294. }
  1295. else {
  1296. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1297. }
  1298. break;
  1299. }
  1300. break;
  1301. case "time_limited_aliases":
  1302. switch ($object) {
  1303. default:
  1304. $data = mailbox('get', 'time_limited_aliases', $object);
  1305. if (!isset($data) || empty($data)) {
  1306. echo '{}';
  1307. }
  1308. else {
  1309. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1310. }
  1311. break;
  1312. }
  1313. break;
  1314. case "resource":
  1315. switch ($object) {
  1316. case "all":
  1317. $domains = mailbox('get', 'domains');
  1318. if (!empty($domains)) {
  1319. foreach ($domains as $domain) {
  1320. $resources = mailbox('get', 'resources', $domain);
  1321. if (!empty($resources)) {
  1322. foreach ($resources as $resource) {
  1323. if ($details = mailbox('get', 'resource_details', $resource)) {
  1324. $data[] = $details;
  1325. }
  1326. else {
  1327. continue;
  1328. }
  1329. }
  1330. }
  1331. }
  1332. if (!isset($data) || empty($data)) {
  1333. echo '{}';
  1334. }
  1335. else {
  1336. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1337. }
  1338. }
  1339. else {
  1340. echo '{}';
  1341. }
  1342. break;
  1343. default:
  1344. $data = mailbox('get', 'resource_details', $object);
  1345. if (!isset($data) || empty($data)) {
  1346. echo '{}';
  1347. }
  1348. else {
  1349. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1350. }
  1351. break;
  1352. }
  1353. break;
  1354. case "fwdhost":
  1355. switch ($object) {
  1356. case "all":
  1357. $data = fwdhost('get');
  1358. if (!isset($data) || empty($data)) {
  1359. echo '{}';
  1360. }
  1361. else {
  1362. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1363. }
  1364. break;
  1365. default:
  1366. $data = fwdhost('details', $object);
  1367. if (!isset($data) || empty($data)) {
  1368. echo '{}';
  1369. }
  1370. else {
  1371. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1372. }
  1373. break;
  1374. }
  1375. break;
  1376. case "quarantine":
  1377. // "all" will not print details
  1378. switch ($object) {
  1379. case "all":
  1380. $data = quarantine('get');
  1381. if (!isset($data) || empty($data)) {
  1382. echo '{}';
  1383. }
  1384. else {
  1385. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1386. }
  1387. break;
  1388. default:
  1389. $data = quarantine('details', $object);
  1390. if (!isset($data) || empty($data)) {
  1391. echo '{}';
  1392. }
  1393. else {
  1394. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1395. }
  1396. break;
  1397. }
  1398. break;
  1399. case "alias-domain":
  1400. switch ($object) {
  1401. case "all":
  1402. $alias_domains = mailbox('get', 'alias_domains');
  1403. if (!empty($alias_domains)) {
  1404. foreach ($alias_domains as $alias_domain) {
  1405. if ($details = mailbox('get', 'alias_domain_details', $alias_domain)) {
  1406. $data[] = $details;
  1407. }
  1408. else {
  1409. continue;
  1410. }
  1411. }
  1412. }
  1413. if (!isset($data) || empty($data)) {
  1414. echo '{}';
  1415. }
  1416. else {
  1417. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1418. }
  1419. break;
  1420. default:
  1421. $data = mailbox('get', 'alias_domain_details', $object);
  1422. if (!isset($data) || empty($data)) {
  1423. echo '{}';
  1424. }
  1425. else {
  1426. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1427. }
  1428. break;
  1429. }
  1430. break;
  1431. case "alias":
  1432. switch ($object) {
  1433. case "all":
  1434. $domains = array_merge(mailbox('get', 'domains'),mailbox('get', 'alias_domains'));
  1435. if (!empty($domains)) {
  1436. foreach ($domains as $domain) {
  1437. $aliases = mailbox('get', 'aliases', $domain);
  1438. if (!empty($aliases)) {
  1439. foreach ($aliases as $alias) {
  1440. if ($details = mailbox('get', 'alias_details', $alias)) {
  1441. $data[] = $details;
  1442. }
  1443. else {
  1444. continue;
  1445. }
  1446. }
  1447. }
  1448. }
  1449. if (!isset($data) || empty($data)) {
  1450. echo '{}';
  1451. }
  1452. else {
  1453. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1454. }
  1455. }
  1456. else {
  1457. echo '{}';
  1458. }
  1459. break;
  1460. default:
  1461. $data = mailbox('get', 'alias_details', $object);
  1462. if (!isset($data) || empty($data)) {
  1463. echo '{}';
  1464. }
  1465. else {
  1466. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1467. }
  1468. break;
  1469. }
  1470. break;
  1471. case "domain-admin":
  1472. switch ($object) {
  1473. case "all":
  1474. $domain_admins = domain_admin('get');
  1475. if (!empty($domain_admins)) {
  1476. foreach ($domain_admins as $domain_admin) {
  1477. if ($details = domain_admin('details', $domain_admin)) {
  1478. $data[] = $details;
  1479. }
  1480. else {
  1481. continue;
  1482. }
  1483. }
  1484. if (!isset($data) || empty($data)) {
  1485. echo '{}';
  1486. }
  1487. else {
  1488. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1489. }
  1490. }
  1491. else {
  1492. echo '{}';
  1493. }
  1494. break;
  1495. default:
  1496. $data = domain_admin('details', $object);
  1497. if (!isset($data) || empty($data)) {
  1498. echo '{}';
  1499. }
  1500. else {
  1501. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1502. }
  1503. break;
  1504. }
  1505. break;
  1506. case "u2f-registration":
  1507. header('Content-Type: application/javascript');
  1508. if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
  1509. list($req, $sigs) = $u2f->getRegisterData(get_u2f_registrations($object));
  1510. $_SESSION['regReq'] = json_encode($req);
  1511. $_SESSION['regSigs'] = json_encode($sigs);
  1512. echo 'var req = ' . json_encode($req) . ';';
  1513. echo 'var registeredKeys = ' . json_encode($sigs) . ';';
  1514. echo 'var appId = req.appId;';
  1515. echo 'var registerRequests = [{version: req.version, challenge: req.challenge}];';
  1516. }
  1517. else {
  1518. return;
  1519. }
  1520. break;
  1521. case "u2f-authentication":
  1522. header('Content-Type: application/javascript');
  1523. if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
  1524. $auth_data = $u2f->getAuthenticateData(get_u2f_registrations($object));
  1525. $challenge = $auth_data[0]->challenge;
  1526. $appId = $auth_data[0]->appId;
  1527. foreach ($auth_data as $each) {
  1528. $key = array(); // Empty array
  1529. $key['version'] = $each->version;
  1530. $key['keyHandle'] = $each->keyHandle;
  1531. $registeredKey[] = $key;
  1532. }
  1533. $_SESSION['authReq'] = json_encode($auth_data);
  1534. echo 'var appId = "' . $appId . '";';
  1535. echo 'var challenge = ' . json_encode($challenge) . ';';
  1536. echo 'var registeredKeys = ' . json_encode($registeredKey) . ';';
  1537. }
  1538. else {
  1539. return;
  1540. }
  1541. break;
  1542. default:
  1543. echo '{}';
  1544. break;
  1545. }
  1546. break;
  1547. case "delete":
  1548. switch ($category) {
  1549. case "alias":
  1550. if (isset($_POST['items'])) {
  1551. $items = (array)json_decode($_POST['items'], true);
  1552. if (is_array($items)) {
  1553. if (mailbox('delete', 'alias', array('address' => $items)) === false) {
  1554. if (isset($_SESSION['return'])) {
  1555. echo json_encode($_SESSION['return']);
  1556. }
  1557. else {
  1558. echo json_encode(array(
  1559. 'type' => 'error',
  1560. 'msg' => 'Deletion of items/s failed'
  1561. ));
  1562. }
  1563. }
  1564. else {
  1565. if (isset($_SESSION['return'])) {
  1566. echo json_encode($_SESSION['return']);
  1567. }
  1568. else {
  1569. echo json_encode(array(
  1570. 'type' => 'success',
  1571. 'msg' => 'Task completed'
  1572. ));
  1573. }
  1574. }
  1575. }
  1576. else {
  1577. echo json_encode(array(
  1578. 'type' => 'error',
  1579. 'msg' => 'Cannot find address array in post data'
  1580. ));
  1581. }
  1582. }
  1583. else {
  1584. echo json_encode(array(
  1585. 'type' => 'error',
  1586. 'msg' => 'Cannot find items in post data'
  1587. ));
  1588. }
  1589. break;
  1590. case "relayhost":
  1591. if (isset($_POST['items'])) {
  1592. $items = (array)json_decode($_POST['items'], true);
  1593. if (is_array($items)) {
  1594. if (relayhost('delete', array('id' => $items)) === false) {
  1595. if (isset($_SESSION['return'])) {
  1596. echo json_encode($_SESSION['return']);
  1597. }
  1598. else {
  1599. echo json_encode(array(
  1600. 'type' => 'error',
  1601. 'msg' => 'Deletion of items/s failed'
  1602. ));
  1603. }
  1604. }
  1605. else {
  1606. if (isset($_SESSION['return'])) {
  1607. echo json_encode($_SESSION['return']);
  1608. }
  1609. else {
  1610. echo json_encode(array(
  1611. 'type' => 'success',
  1612. 'msg' => 'Task completed'
  1613. ));
  1614. }
  1615. }
  1616. }
  1617. else {
  1618. echo json_encode(array(
  1619. 'type' => 'error',
  1620. 'msg' => 'Cannot find id array in post data'
  1621. ));
  1622. }
  1623. }
  1624. else {
  1625. echo json_encode(array(
  1626. 'type' => 'error',
  1627. 'msg' => 'Cannot find items in post data'
  1628. ));
  1629. }
  1630. break;
  1631. case "syncjob":
  1632. if (isset($_POST['items'])) {
  1633. $items = (array)json_decode($_POST['items'], true);
  1634. if (is_array($items)) {
  1635. if (mailbox('delete', 'syncjob', array('id' => $items)) === false) {
  1636. if (isset($_SESSION['return'])) {
  1637. echo json_encode($_SESSION['return']);
  1638. }
  1639. else {
  1640. echo json_encode(array(
  1641. 'type' => 'error',
  1642. 'msg' => 'Deletion of items/s failed'
  1643. ));
  1644. }
  1645. }
  1646. else {
  1647. if (isset($_SESSION['return'])) {
  1648. echo json_encode($_SESSION['return']);
  1649. }
  1650. else {
  1651. echo json_encode(array(
  1652. 'type' => 'success',
  1653. 'msg' => 'Task completed'
  1654. ));
  1655. }
  1656. }
  1657. }
  1658. else {
  1659. echo json_encode(array(
  1660. 'type' => 'error',
  1661. 'msg' => 'Cannot find id array in post data'
  1662. ));
  1663. }
  1664. }
  1665. else {
  1666. echo json_encode(array(
  1667. 'type' => 'error',
  1668. 'msg' => 'Cannot find items in post data'
  1669. ));
  1670. }
  1671. break;
  1672. case "filter":
  1673. if (isset($_POST['items'])) {
  1674. $items = (array)json_decode($_POST['items'], true);
  1675. if (is_array($items)) {
  1676. if (mailbox('delete', 'filter', array('id' => $items)) === false) {
  1677. if (isset($_SESSION['return'])) {
  1678. echo json_encode($_SESSION['return']);
  1679. }
  1680. else {
  1681. echo json_encode(array(
  1682. 'type' => 'error',
  1683. 'msg' => 'Deletion of items/s failed'
  1684. ));
  1685. }
  1686. }
  1687. else {
  1688. if (isset($_SESSION['return'])) {
  1689. echo json_encode($_SESSION['return']);
  1690. }
  1691. else {
  1692. echo json_encode(array(
  1693. 'type' => 'success',
  1694. 'msg' => 'Task completed'
  1695. ));
  1696. }
  1697. }
  1698. }
  1699. else {
  1700. echo json_encode(array(
  1701. 'type' => 'error',
  1702. 'msg' => 'Cannot find id array in post data'
  1703. ));
  1704. }
  1705. }
  1706. else {
  1707. echo json_encode(array(
  1708. 'type' => 'error',
  1709. 'msg' => 'Cannot find items in post data'
  1710. ));
  1711. }
  1712. break;
  1713. case "qitem":
  1714. if (isset($_POST['items'])) {
  1715. $items = (array)json_decode($_POST['items'], true);
  1716. if (is_array($items)) {
  1717. if (quarantine('delete', array('id' => $items)) === false) {
  1718. if (isset($_SESSION['return'])) {
  1719. echo json_encode($_SESSION['return']);
  1720. }
  1721. else {
  1722. echo json_encode(array(
  1723. 'type' => 'error',
  1724. 'msg' => 'Deletion of items/s failed'
  1725. ));
  1726. }
  1727. }
  1728. else {
  1729. if (isset($_SESSION['return'])) {
  1730. echo json_encode($_SESSION['return']);
  1731. }
  1732. else {
  1733. echo json_encode(array(
  1734. 'type' => 'success',
  1735. 'msg' => 'Task completed'
  1736. ));
  1737. }
  1738. }
  1739. }
  1740. else {
  1741. echo json_encode(array(
  1742. 'type' => 'error',
  1743. 'msg' => 'Cannot find id array in post data'
  1744. ));
  1745. }
  1746. }
  1747. else {
  1748. echo json_encode(array(
  1749. 'type' => 'error',
  1750. 'msg' => 'Cannot find items in post data'
  1751. ));
  1752. }
  1753. break;
  1754. case "bcc":
  1755. if (isset($_POST['items'])) {
  1756. $items = (array)json_decode($_POST['items'], true);
  1757. if (is_array($items)) {
  1758. if (bcc('delete', array('id' => $items)) === false) {
  1759. if (isset($_SESSION['return'])) {
  1760. echo json_encode($_SESSION['return']);
  1761. }
  1762. else {
  1763. echo json_encode(array(
  1764. 'type' => 'error',
  1765. 'msg' => 'Deletion of items/s failed'
  1766. ));
  1767. }
  1768. }
  1769. else {
  1770. if (isset($_SESSION['return'])) {
  1771. echo json_encode($_SESSION['return']);
  1772. }
  1773. else {
  1774. echo json_encode(array(
  1775. 'type' => 'success',
  1776. 'msg' => 'Task completed'
  1777. ));
  1778. }
  1779. }
  1780. }
  1781. else {
  1782. echo json_encode(array(
  1783. 'type' => 'error',
  1784. 'msg' => 'Cannot find id array in post data'
  1785. ));
  1786. }
  1787. }
  1788. else {
  1789. echo json_encode(array(
  1790. 'type' => 'error',
  1791. 'msg' => 'Cannot find items in post data'
  1792. ));
  1793. }
  1794. break;
  1795. case "recipient_map":
  1796. if (isset($_POST['items'])) {
  1797. $items = (array)json_decode($_POST['items'], true);
  1798. if (is_array($items)) {
  1799. if (recipient_map('delete', array('id' => $items)) === false) {
  1800. if (isset($_SESSION['return'])) {
  1801. echo json_encode($_SESSION['return']);
  1802. }
  1803. else {
  1804. echo json_encode(array(
  1805. 'type' => 'error',
  1806. 'msg' => 'Deletion of items/s failed'
  1807. ));
  1808. }
  1809. }
  1810. else {
  1811. if (isset($_SESSION['return'])) {
  1812. echo json_encode($_SESSION['return']);
  1813. }
  1814. else {
  1815. echo json_encode(array(
  1816. 'type' => 'success',
  1817. 'msg' => 'Task completed'
  1818. ));
  1819. }
  1820. }
  1821. }
  1822. else {
  1823. echo json_encode(array(
  1824. 'type' => 'error',
  1825. 'msg' => 'Cannot find id array in post data'
  1826. ));
  1827. }
  1828. }
  1829. else {
  1830. echo json_encode(array(
  1831. 'type' => 'error',
  1832. 'msg' => 'Cannot find items in post data'
  1833. ));
  1834. }
  1835. break;
  1836. case "fwdhost":
  1837. if (isset($_POST['items'])) {
  1838. $items = (array)json_decode($_POST['items'], true);
  1839. if (is_array($items)) {
  1840. if (fwdhost('delete', array('forwardinghost' => $items)) === false) {
  1841. if (isset($_SESSION['return'])) {
  1842. echo json_encode($_SESSION['return']);
  1843. }
  1844. else {
  1845. echo json_encode(array(
  1846. 'type' => 'error',
  1847. 'msg' => 'Deletion of items/s failed'
  1848. ));
  1849. }
  1850. }
  1851. else {
  1852. if (isset($_SESSION['return'])) {
  1853. echo json_encode($_SESSION['return']);
  1854. }
  1855. else {
  1856. echo json_encode(array(
  1857. 'type' => 'success',
  1858. 'msg' => 'Task completed'
  1859. ));
  1860. }
  1861. }
  1862. }
  1863. else {
  1864. echo json_encode(array(
  1865. 'type' => 'error',
  1866. 'msg' => 'Cannot find forwardinghost array in post data'
  1867. ));
  1868. }
  1869. }
  1870. else {
  1871. echo json_encode(array(
  1872. 'type' => 'error',
  1873. 'msg' => 'Cannot find items in post data'
  1874. ));
  1875. }
  1876. break;
  1877. case "dkim":
  1878. if (isset($_POST['items'])) {
  1879. $items = (array)json_decode($_POST['items'], true);
  1880. if (is_array($items)) {
  1881. if (dkim('delete', array('domains' => $items)) === false) {
  1882. if (isset($_SESSION['return'])) {
  1883. echo json_encode($_SESSION['return']);
  1884. }
  1885. else {
  1886. echo json_encode(array(
  1887. 'type' => 'error',
  1888. 'msg' => 'Deletion of items/s failed'
  1889. ));
  1890. }
  1891. }
  1892. else {
  1893. if (isset($_SESSION['return'])) {
  1894. echo json_encode($_SESSION['return']);
  1895. }
  1896. else {
  1897. echo json_encode(array(
  1898. 'type' => 'success',
  1899. 'msg' => 'Task completed'
  1900. ));
  1901. }
  1902. }
  1903. }
  1904. else {
  1905. echo json_encode(array(
  1906. 'type' => 'error',
  1907. 'msg' => 'Cannot find domains array in post data'
  1908. ));
  1909. }
  1910. }
  1911. else {
  1912. echo json_encode(array(
  1913. 'type' => 'error',
  1914. 'msg' => 'Cannot find items in post data'
  1915. ));
  1916. }
  1917. break;
  1918. case "domain":
  1919. if (isset($_POST['items'])) {
  1920. $items = (array)json_decode($_POST['items'], true);
  1921. if (is_array($items)) {
  1922. if (mailbox('delete', 'domain', array('domain' => $items)) === false) {
  1923. if (isset($_SESSION['return'])) {
  1924. echo json_encode($_SESSION['return']);
  1925. }
  1926. else {
  1927. echo json_encode(array(
  1928. 'type' => 'error',
  1929. 'msg' => 'Task failed'
  1930. ));
  1931. }
  1932. }
  1933. else {
  1934. if (isset($_SESSION['return'])) {
  1935. echo json_encode($_SESSION['return']);
  1936. }
  1937. else {
  1938. echo json_encode(array(
  1939. 'type' => 'success',
  1940. 'msg' => 'Task completed'
  1941. ));
  1942. }
  1943. }
  1944. }
  1945. else {
  1946. echo json_encode(array(
  1947. 'type' => 'error',
  1948. 'msg' => 'Cannot find domain array in post data'
  1949. ));
  1950. }
  1951. }
  1952. else {
  1953. echo json_encode(array(
  1954. 'type' => 'error',
  1955. 'msg' => 'Cannot find items in post data'
  1956. ));
  1957. }
  1958. break;
  1959. case "alias-domain":
  1960. if (isset($_POST['items'])) {
  1961. $items = (array)json_decode($_POST['items'], true);
  1962. if (is_array($items)) {
  1963. if (mailbox('delete', 'alias_domain', array('alias_domain' => $items)) === false) {
  1964. if (isset($_SESSION['return'])) {
  1965. echo json_encode($_SESSION['return']);
  1966. }
  1967. else {
  1968. echo json_encode(array(
  1969. 'type' => 'error',
  1970. 'msg' => 'Task failed'
  1971. ));
  1972. }
  1973. }
  1974. else {
  1975. if (isset($_SESSION['return'])) {
  1976. echo json_encode($_SESSION['return']);
  1977. }
  1978. else {
  1979. echo json_encode(array(
  1980. 'type' => 'success',
  1981. 'msg' => 'Task completed'
  1982. ));
  1983. }
  1984. }
  1985. }
  1986. else {
  1987. echo json_encode(array(
  1988. 'type' => 'error',
  1989. 'msg' => 'Cannot find alias_domain array in post data'
  1990. ));
  1991. }
  1992. }
  1993. else {
  1994. echo json_encode(array(
  1995. 'type' => 'error',
  1996. 'msg' => 'Cannot find items in post data'
  1997. ));
  1998. }
  1999. break;
  2000. case "mailbox":
  2001. if (isset($_POST['items'])) {
  2002. $items = (array)json_decode($_POST['items'], true);
  2003. if (is_array($items)) {
  2004. if (mailbox('delete', 'mailbox', array('username' => $items)) === false) {
  2005. if (isset($_SESSION['return'])) {
  2006. echo json_encode($_SESSION['return']);
  2007. }
  2008. else {
  2009. echo json_encode(array(
  2010. 'type' => 'error',
  2011. 'msg' => 'Task failed'
  2012. ));
  2013. }
  2014. }
  2015. else {
  2016. if (isset($_SESSION['return'])) {
  2017. echo json_encode($_SESSION['return']);
  2018. }
  2019. else {
  2020. echo json_encode(array(
  2021. 'type' => 'success',
  2022. 'msg' => 'Task completed'
  2023. ));
  2024. }
  2025. }
  2026. }
  2027. else {
  2028. echo json_encode(array(
  2029. 'type' => 'error',
  2030. 'msg' => 'Cannot find username array in post data'
  2031. ));
  2032. }
  2033. }
  2034. else {
  2035. echo json_encode(array(
  2036. 'type' => 'error',
  2037. 'msg' => 'Cannot find items in post data'
  2038. ));
  2039. }
  2040. break;
  2041. case "resource":
  2042. if (isset($_POST['items'])) {
  2043. $items = (array)json_decode($_POST['items'], true);
  2044. if (is_array($items)) {
  2045. if (mailbox('delete', 'resource', array('name' => $items)) === false) {
  2046. if (isset($_SESSION['return'])) {
  2047. echo json_encode($_SESSION['return']);
  2048. }
  2049. else {
  2050. echo json_encode(array(
  2051. 'type' => 'error',
  2052. 'msg' => 'Task failed'
  2053. ));
  2054. }
  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' => 'Cannot find name array in post data'
  2072. ));
  2073. }
  2074. }
  2075. else {
  2076. echo json_encode(array(
  2077. 'type' => 'error',
  2078. 'msg' => 'Cannot find items in post data'
  2079. ));
  2080. }
  2081. break;
  2082. case "mailbox-policy":
  2083. if (isset($_POST['items'])) {
  2084. $items = (array)json_decode($_POST['items'], true);
  2085. if (is_array($items)) {
  2086. if (policy('delete', 'mailbox', array('prefid' => $items)) === false) {
  2087. if (isset($_SESSION['return'])) {
  2088. echo json_encode($_SESSION['return']);
  2089. }
  2090. else {
  2091. echo json_encode(array(
  2092. 'type' => 'error',
  2093. 'msg' => 'Task failed'
  2094. ));
  2095. }
  2096. }
  2097. else {
  2098. if (isset($_SESSION['return'])) {
  2099. echo json_encode($_SESSION['return']);
  2100. }
  2101. else {
  2102. echo json_encode(array(
  2103. 'type' => 'success',
  2104. 'msg' => 'Task completed'
  2105. ));
  2106. }
  2107. }
  2108. }
  2109. else {
  2110. echo json_encode(array(
  2111. 'type' => 'error',
  2112. 'msg' => 'Cannot find name array in post data'
  2113. ));
  2114. }
  2115. }
  2116. else {
  2117. echo json_encode(array(
  2118. 'type' => 'error',
  2119. 'msg' => 'Cannot find items in post data'
  2120. ));
  2121. }
  2122. break;
  2123. case "domain-policy":
  2124. if (isset($_POST['items'])) {
  2125. $items = (array)json_decode($_POST['items'], true);
  2126. if (is_array($items)) {
  2127. if (policy('delete', 'domain', array('prefid' => $items)) === false) {
  2128. if (isset($_SESSION['return'])) {
  2129. echo json_encode($_SESSION['return']);
  2130. }
  2131. else {
  2132. echo json_encode(array(
  2133. 'type' => 'error',
  2134. 'msg' => 'Task failed'
  2135. ));
  2136. }
  2137. }
  2138. else {
  2139. if (isset($_SESSION['return'])) {
  2140. echo json_encode($_SESSION['return']);
  2141. }
  2142. else {
  2143. echo json_encode(array(
  2144. 'type' => 'success',
  2145. 'msg' => 'Task completed'
  2146. ));
  2147. }
  2148. }
  2149. }
  2150. else {
  2151. echo json_encode(array(
  2152. 'type' => 'error',
  2153. 'msg' => 'Cannot find name array in post data'
  2154. ));
  2155. }
  2156. }
  2157. else {
  2158. echo json_encode(array(
  2159. 'type' => 'error',
  2160. 'msg' => 'Cannot find items in post data'
  2161. ));
  2162. }
  2163. break;
  2164. case "time_limited_alias":
  2165. if (isset($_POST['items'])) {
  2166. $items = (array)json_decode($_POST['items'], true);
  2167. if (is_array($items)) {
  2168. if (mailbox('delete', 'time_limited_alias', array('address' => $items)) === false) {
  2169. if (isset($_SESSION['return'])) {
  2170. echo json_encode($_SESSION['return']);
  2171. }
  2172. else {
  2173. echo json_encode(array(
  2174. 'type' => 'error',
  2175. 'msg' => 'Task failed'
  2176. ));
  2177. }
  2178. }
  2179. else {
  2180. if (isset($_SESSION['return'])) {
  2181. echo json_encode($_SESSION['return']);
  2182. }
  2183. else {
  2184. echo json_encode(array(
  2185. 'type' => 'success',
  2186. 'msg' => 'Task completed'
  2187. ));
  2188. }
  2189. }
  2190. }
  2191. else {
  2192. echo json_encode(array(
  2193. 'type' => 'error',
  2194. 'msg' => 'Cannot find name array in post data'
  2195. ));
  2196. }
  2197. }
  2198. else {
  2199. echo json_encode(array(
  2200. 'type' => 'error',
  2201. 'msg' => 'Cannot find items in post data'
  2202. ));
  2203. }
  2204. break;
  2205. case "eas_cache":
  2206. if (isset($_POST['items'])) {
  2207. $items = (array)json_decode($_POST['items'], true);
  2208. if (is_array($items)) {
  2209. if (mailbox('delete', 'eas_cache', array('username' => $items)) === false) {
  2210. if (isset($_SESSION['return'])) {
  2211. echo json_encode($_SESSION['return']);
  2212. }
  2213. else {
  2214. echo json_encode(array(
  2215. 'type' => 'error',
  2216. 'msg' => 'Task failed'
  2217. ));
  2218. }
  2219. }
  2220. else {
  2221. if (isset($_SESSION['return'])) {
  2222. echo json_encode($_SESSION['return']);
  2223. }
  2224. else {
  2225. echo json_encode(array(
  2226. 'type' => 'success',
  2227. 'msg' => 'Task completed'
  2228. ));
  2229. }
  2230. }
  2231. }
  2232. else {
  2233. echo json_encode(array(
  2234. 'type' => 'error',
  2235. 'msg' => 'Cannot find name array in post data'
  2236. ));
  2237. }
  2238. }
  2239. else {
  2240. echo json_encode(array(
  2241. 'type' => 'error',
  2242. 'msg' => 'Cannot find items in post data'
  2243. ));
  2244. }
  2245. break;
  2246. case "domain-admin":
  2247. if (isset($_POST['items'])) {
  2248. $items = (array)json_decode($_POST['items'], true);
  2249. if (is_array($items)) {
  2250. if (domain_admin('delete', array('username' => $items)) === false) {
  2251. if (isset($_SESSION['return'])) {
  2252. echo json_encode($_SESSION['return']);
  2253. }
  2254. else {
  2255. echo json_encode(array(
  2256. 'type' => 'error',
  2257. 'msg' => 'Task failed'
  2258. ));
  2259. }
  2260. }
  2261. else {
  2262. if (isset($_SESSION['return'])) {
  2263. echo json_encode($_SESSION['return']);
  2264. }
  2265. else {
  2266. echo json_encode(array(
  2267. 'type' => 'success',
  2268. 'msg' => 'Task completed'
  2269. ));
  2270. }
  2271. }
  2272. }
  2273. else {
  2274. echo json_encode(array(
  2275. 'type' => 'error',
  2276. 'msg' => 'Cannot find name array in post data'
  2277. ));
  2278. }
  2279. }
  2280. else {
  2281. echo json_encode(array(
  2282. 'type' => 'error',
  2283. 'msg' => 'Cannot find items in post data'
  2284. ));
  2285. }
  2286. break;
  2287. }
  2288. break;
  2289. case "edit":
  2290. switch ($category) {
  2291. case "bcc":
  2292. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2293. $items = (array)json_decode($_POST['items'], true);
  2294. $attr = (array)json_decode($_POST['attr'], true);
  2295. $postarray = array_merge(array('id' => $items), $attr);
  2296. if (is_array($postarray['id'])) {
  2297. if (bcc('edit', $postarray) === false) {
  2298. if (isset($_SESSION['return'])) {
  2299. echo json_encode($_SESSION['return']);
  2300. }
  2301. else {
  2302. echo json_encode(array(
  2303. 'type' => 'error',
  2304. 'msg' => 'Edit failed'
  2305. ));
  2306. }
  2307. exit();
  2308. }
  2309. else {
  2310. if (isset($_SESSION['return'])) {
  2311. echo json_encode($_SESSION['return']);
  2312. }
  2313. else {
  2314. echo json_encode(array(
  2315. 'type' => 'success',
  2316. 'msg' => 'Task completed'
  2317. ));
  2318. }
  2319. }
  2320. }
  2321. else {
  2322. echo json_encode(array(
  2323. 'type' => 'error',
  2324. 'msg' => 'Incomplete post data'
  2325. ));
  2326. }
  2327. }
  2328. else {
  2329. echo json_encode(array(
  2330. 'type' => 'error',
  2331. 'msg' => 'Incomplete post data'
  2332. ));
  2333. }
  2334. break;
  2335. case "recipient_map":
  2336. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2337. $items = (array)json_decode($_POST['items'], true);
  2338. $attr = (array)json_decode($_POST['attr'], true);
  2339. $postarray = array_merge(array('id' => $items), $attr);
  2340. if (is_array($postarray['id'])) {
  2341. if (recipient_map('edit', $postarray) === false) {
  2342. if (isset($_SESSION['return'])) {
  2343. echo json_encode($_SESSION['return']);
  2344. }
  2345. else {
  2346. echo json_encode(array(
  2347. 'type' => 'error',
  2348. 'msg' => 'Edit failed'
  2349. ));
  2350. }
  2351. exit();
  2352. }
  2353. else {
  2354. if (isset($_SESSION['return'])) {
  2355. echo json_encode($_SESSION['return']);
  2356. }
  2357. else {
  2358. echo json_encode(array(
  2359. 'type' => 'success',
  2360. 'msg' => 'Task completed'
  2361. ));
  2362. }
  2363. }
  2364. }
  2365. else {
  2366. echo json_encode(array(
  2367. 'type' => 'error',
  2368. 'msg' => 'Incomplete post data'
  2369. ));
  2370. }
  2371. }
  2372. else {
  2373. echo json_encode(array(
  2374. 'type' => 'error',
  2375. 'msg' => 'Incomplete post data'
  2376. ));
  2377. }
  2378. break;
  2379. case "alias":
  2380. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2381. $items = (array)json_decode($_POST['items'], true);
  2382. $attr = (array)json_decode($_POST['attr'], true);
  2383. $postarray = array_merge(array('address' => $items), $attr);
  2384. if (is_array($postarray['address'])) {
  2385. if (mailbox('edit', 'alias', $postarray) === false) {
  2386. if (isset($_SESSION['return'])) {
  2387. echo json_encode($_SESSION['return']);
  2388. }
  2389. else {
  2390. echo json_encode(array(
  2391. 'type' => 'error',
  2392. 'msg' => 'Edit failed'
  2393. ));
  2394. }
  2395. exit();
  2396. }
  2397. else {
  2398. if (isset($_SESSION['return'])) {
  2399. echo json_encode($_SESSION['return']);
  2400. }
  2401. else {
  2402. echo json_encode(array(
  2403. 'type' => 'success',
  2404. 'msg' => 'Task completed'
  2405. ));
  2406. }
  2407. }
  2408. }
  2409. else {
  2410. echo json_encode(array(
  2411. 'type' => 'error',
  2412. 'msg' => 'Incomplete post data'
  2413. ));
  2414. }
  2415. }
  2416. else {
  2417. echo json_encode(array(
  2418. 'type' => 'error',
  2419. 'msg' => 'Incomplete post data'
  2420. ));
  2421. }
  2422. break;
  2423. case "app_links":
  2424. if (isset($_POST['attr'])) {
  2425. $attr = (array)json_decode($_POST['attr'], true);
  2426. if (is_array($attr)) {
  2427. if (customize('edit', 'app_links', $attr) === false) {
  2428. if (isset($_SESSION['return'])) {
  2429. echo json_encode($_SESSION['return']);
  2430. }
  2431. else {
  2432. echo json_encode(array(
  2433. 'type' => 'error',
  2434. 'msg' => 'Edit failed'
  2435. ));
  2436. }
  2437. exit();
  2438. }
  2439. else {
  2440. if (isset($_SESSION['return'])) {
  2441. echo json_encode($_SESSION['return']);
  2442. }
  2443. else {
  2444. echo json_encode(array(
  2445. 'type' => 'success',
  2446. 'msg' => 'Task completed'
  2447. ));
  2448. }
  2449. }
  2450. }
  2451. else {
  2452. echo json_encode(array(
  2453. 'type' => 'error',
  2454. 'msg' => 'Incomplete post data'
  2455. ));
  2456. }
  2457. }
  2458. else {
  2459. echo json_encode(array(
  2460. 'type' => 'error',
  2461. 'msg' => 'Incomplete post data'
  2462. ));
  2463. }
  2464. break;
  2465. case "relayhost":
  2466. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2467. $items = (array)json_decode($_POST['items'], true);
  2468. $attr = (array)json_decode($_POST['attr'], true);
  2469. $postarray = array_merge(array('id' => $items), $attr);
  2470. if (is_array($postarray['id'])) {
  2471. if (relayhost('edit', $postarray) === false) {
  2472. if (isset($_SESSION['return'])) {
  2473. echo json_encode($_SESSION['return']);
  2474. }
  2475. else {
  2476. echo json_encode(array(
  2477. 'type' => 'error',
  2478. 'msg' => 'Edit failed'
  2479. ));
  2480. }
  2481. exit();
  2482. }
  2483. else {
  2484. if (isset($_SESSION['return'])) {
  2485. echo json_encode($_SESSION['return']);
  2486. }
  2487. else {
  2488. echo json_encode(array(
  2489. 'type' => 'success',
  2490. 'msg' => 'Task completed'
  2491. ));
  2492. }
  2493. }
  2494. }
  2495. else {
  2496. echo json_encode(array(
  2497. 'type' => 'error',
  2498. 'msg' => 'Incomplete post data'
  2499. ));
  2500. }
  2501. }
  2502. else {
  2503. echo json_encode(array(
  2504. 'type' => 'error',
  2505. 'msg' => 'Incomplete post data'
  2506. ));
  2507. }
  2508. break;
  2509. case "delimiter_action":
  2510. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2511. $items = (array)json_decode($_POST['items'], true);
  2512. $attr = (array)json_decode($_POST['attr'], true);
  2513. $postarray = array_merge(array('username' => $items), $attr);
  2514. if (is_array($postarray['username'])) {
  2515. if (mailbox('edit', 'delimiter_action', $postarray) === false) {
  2516. if (isset($_SESSION['return'])) {
  2517. echo json_encode($_SESSION['return']);
  2518. }
  2519. else {
  2520. echo json_encode(array(
  2521. 'type' => 'error',
  2522. 'msg' => 'Edit failed'
  2523. ));
  2524. }
  2525. exit();
  2526. }
  2527. else {
  2528. if (isset($_SESSION['return'])) {
  2529. echo json_encode($_SESSION['return']);
  2530. }
  2531. else {
  2532. echo json_encode(array(
  2533. 'type' => 'success',
  2534. 'msg' => 'Task completed'
  2535. ));
  2536. }
  2537. }
  2538. }
  2539. else {
  2540. echo json_encode(array(
  2541. 'type' => 'error',
  2542. 'msg' => 'Incomplete post data'
  2543. ));
  2544. }
  2545. }
  2546. else {
  2547. echo json_encode(array(
  2548. 'type' => 'error',
  2549. 'msg' => 'Incomplete post data'
  2550. ));
  2551. }
  2552. break;
  2553. case "tls_policy":
  2554. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2555. $items = (array)json_decode($_POST['items'], true);
  2556. $attr = (array)json_decode($_POST['attr'], true);
  2557. $postarray = array_merge(array('username' => $items), $attr);
  2558. if (is_array($postarray['username'])) {
  2559. if (mailbox('edit', 'tls_policy', $postarray) === false) {
  2560. if (isset($_SESSION['return'])) {
  2561. echo json_encode($_SESSION['return']);
  2562. }
  2563. else {
  2564. echo json_encode(array(
  2565. 'type' => 'error',
  2566. 'msg' => 'Edit failed'
  2567. ));
  2568. }
  2569. exit();
  2570. }
  2571. else {
  2572. if (isset($_SESSION['return'])) {
  2573. echo json_encode($_SESSION['return']);
  2574. }
  2575. else {
  2576. echo json_encode(array(
  2577. 'type' => 'success',
  2578. 'msg' => 'Task completed'
  2579. ));
  2580. }
  2581. }
  2582. }
  2583. else {
  2584. echo json_encode(array(
  2585. 'type' => 'error',
  2586. 'msg' => 'Incomplete post data'
  2587. ));
  2588. }
  2589. }
  2590. else {
  2591. echo json_encode(array(
  2592. 'type' => 'error',
  2593. 'msg' => 'Incomplete post data'
  2594. ));
  2595. }
  2596. break;
  2597. case "qitem":
  2598. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2599. $items = (array)json_decode($_POST['items'], true);
  2600. $attr = (array)json_decode($_POST['attr'], true);
  2601. $postarray = array_merge(array('id' => $items), $attr);
  2602. if (is_array($postarray['id'])) {
  2603. if (quarantine('edit', $postarray) === false) {
  2604. if (isset($_SESSION['return'])) {
  2605. echo json_encode($_SESSION['return']);
  2606. }
  2607. else {
  2608. echo json_encode(array(
  2609. 'type' => 'error',
  2610. 'msg' => 'Edit failed'
  2611. ));
  2612. }
  2613. exit();
  2614. }
  2615. else {
  2616. if (isset($_SESSION['return'])) {
  2617. echo json_encode($_SESSION['return']);
  2618. }
  2619. else {
  2620. echo json_encode(array(
  2621. 'type' => 'success',
  2622. 'msg' => 'Task completed'
  2623. ));
  2624. }
  2625. }
  2626. }
  2627. else {
  2628. echo json_encode(array(
  2629. 'type' => 'error',
  2630. 'msg' => 'Incomplete post data'
  2631. ));
  2632. }
  2633. }
  2634. else {
  2635. echo json_encode(array(
  2636. 'type' => 'error',
  2637. 'msg' => 'Incomplete post data'
  2638. ));
  2639. }
  2640. break;
  2641. case "quarantine":
  2642. // Edit settings, does not need IDs
  2643. if (isset($_POST['attr'])) {
  2644. $postarray = json_decode($_POST['attr'], true);
  2645. if (quarantine('edit', $postarray) === false) {
  2646. if (isset($_SESSION['return'])) {
  2647. echo json_encode($_SESSION['return']);
  2648. }
  2649. else {
  2650. echo json_encode(array(
  2651. 'type' => 'error',
  2652. 'msg' => 'Edit failed'
  2653. ));
  2654. }
  2655. exit();
  2656. }
  2657. else {
  2658. if (isset($_SESSION['return'])) {
  2659. echo json_encode($_SESSION['return']);
  2660. }
  2661. else {
  2662. echo json_encode(array(
  2663. 'type' => 'success',
  2664. 'msg' => 'Task completed'
  2665. ));
  2666. }
  2667. }
  2668. }
  2669. else {
  2670. echo json_encode(array(
  2671. 'type' => 'error',
  2672. 'msg' => 'Incomplete post data'
  2673. ));
  2674. }
  2675. break;
  2676. case "time_limited_alias":
  2677. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2678. $items = (array)json_decode($_POST['items'], true);
  2679. $attr = (array)json_decode($_POST['attr'], true);
  2680. $postarray = array_merge(array('address' => $items), $attr);
  2681. if (is_array($postarray['address'])) {
  2682. if (mailbox('edit', 'time_limited_alias', $postarray) === false) {
  2683. if (isset($_SESSION['return'])) {
  2684. echo json_encode($_SESSION['return']);
  2685. }
  2686. else {
  2687. echo json_encode(array(
  2688. 'type' => 'error',
  2689. 'msg' => 'Edit failed'
  2690. ));
  2691. }
  2692. exit();
  2693. }
  2694. else {
  2695. if (isset($_SESSION['return'])) {
  2696. echo json_encode($_SESSION['return']);
  2697. }
  2698. else {
  2699. echo json_encode(array(
  2700. 'type' => 'success',
  2701. 'msg' => 'Task completed'
  2702. ));
  2703. }
  2704. }
  2705. }
  2706. else {
  2707. echo json_encode(array(
  2708. 'type' => 'error',
  2709. 'msg' => 'Incomplete post data'
  2710. ));
  2711. }
  2712. }
  2713. else {
  2714. echo json_encode(array(
  2715. 'type' => 'error',
  2716. 'msg' => 'Incomplete post data'
  2717. ));
  2718. }
  2719. break;
  2720. case "mailbox":
  2721. // sender_acl:0 removes all entries
  2722. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2723. $items = (array)json_decode($_POST['items'], true);
  2724. $attr = (array)json_decode($_POST['attr'], true);
  2725. $postarray = array_merge(array('username' => $items), $attr);
  2726. if (is_array($postarray['username'])) {
  2727. if (mailbox('edit', 'mailbox', $postarray) === false) {
  2728. if (isset($_SESSION['return'])) {
  2729. echo json_encode($_SESSION['return']);
  2730. }
  2731. else {
  2732. echo json_encode(array(
  2733. 'type' => 'error',
  2734. 'msg' => 'Edit failed'
  2735. ));
  2736. }
  2737. exit();
  2738. }
  2739. else {
  2740. if (isset($_SESSION['return'])) {
  2741. echo json_encode($_SESSION['return']);
  2742. }
  2743. else {
  2744. echo json_encode(array(
  2745. 'type' => 'success',
  2746. 'msg' => 'Task completed'
  2747. ));
  2748. }
  2749. }
  2750. }
  2751. else {
  2752. echo json_encode(array(
  2753. 'type' => 'error',
  2754. 'msg' => 'Incomplete post data'
  2755. ));
  2756. }
  2757. }
  2758. else {
  2759. echo json_encode(array(
  2760. 'type' => 'error',
  2761. 'msg' => 'Incomplete post data'
  2762. ));
  2763. }
  2764. break;
  2765. case "syncjob":
  2766. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2767. $items = (array)json_decode($_POST['items'], true);
  2768. $attr = (array)json_decode($_POST['attr'], true);
  2769. $postarray = array_merge(array('id' => $items), $attr);
  2770. if (is_array($postarray['id'])) {
  2771. if (mailbox('edit', 'syncjob', $postarray) === false) {
  2772. if (isset($_SESSION['return'])) {
  2773. echo json_encode($_SESSION['return']);
  2774. }
  2775. else {
  2776. echo json_encode(array(
  2777. 'type' => 'error',
  2778. 'msg' => 'Edit failed'
  2779. ));
  2780. }
  2781. exit();
  2782. }
  2783. else {
  2784. if (isset($_SESSION['return'])) {
  2785. echo json_encode($_SESSION['return']);
  2786. }
  2787. else {
  2788. echo json_encode(array(
  2789. 'type' => 'success',
  2790. 'msg' => 'Task completed'
  2791. ));
  2792. }
  2793. }
  2794. }
  2795. else {
  2796. echo json_encode(array(
  2797. 'type' => 'error',
  2798. 'msg' => 'Incomplete post data'
  2799. ));
  2800. }
  2801. }
  2802. else {
  2803. echo json_encode(array(
  2804. 'type' => 'error',
  2805. 'msg' => 'Incomplete post data'
  2806. ));
  2807. }
  2808. break;
  2809. case "filter":
  2810. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2811. $items = (array)json_decode($_POST['items'], true);
  2812. $attr = (array)json_decode($_POST['attr'], true);
  2813. $postarray = array_merge(array('id' => $items), $attr);
  2814. if (is_array($postarray['id'])) {
  2815. if (mailbox('edit', 'filter', $postarray) === false) {
  2816. if (isset($_SESSION['return'])) {
  2817. echo json_encode($_SESSION['return']);
  2818. }
  2819. else {
  2820. echo json_encode(array(
  2821. 'type' => 'error',
  2822. 'msg' => 'Edit failed'
  2823. ));
  2824. }
  2825. exit();
  2826. }
  2827. else {
  2828. if (isset($_SESSION['return'])) {
  2829. echo json_encode($_SESSION['return']);
  2830. }
  2831. else {
  2832. echo json_encode(array(
  2833. 'type' => 'success',
  2834. 'msg' => 'Task completed'
  2835. ));
  2836. }
  2837. }
  2838. }
  2839. else {
  2840. echo json_encode(array(
  2841. 'type' => 'error',
  2842. 'msg' => 'Incomplete post data'
  2843. ));
  2844. }
  2845. }
  2846. else {
  2847. echo json_encode(array(
  2848. 'type' => 'error',
  2849. 'msg' => 'Incomplete post data'
  2850. ));
  2851. }
  2852. break;
  2853. case "resource":
  2854. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2855. $items = (array)json_decode($_POST['items'], true);
  2856. $attr = (array)json_decode($_POST['attr'], true);
  2857. $postarray = array_merge(array('name' => $items), $attr);
  2858. if (is_array($postarray['name'])) {
  2859. if (mailbox('edit', 'resource', $postarray) === false) {
  2860. if (isset($_SESSION['return'])) {
  2861. echo json_encode($_SESSION['return']);
  2862. }
  2863. else {
  2864. echo json_encode(array(
  2865. 'type' => 'error',
  2866. 'msg' => 'Edit failed'
  2867. ));
  2868. }
  2869. exit();
  2870. }
  2871. else {
  2872. if (isset($_SESSION['return'])) {
  2873. echo json_encode($_SESSION['return']);
  2874. }
  2875. else {
  2876. echo json_encode(array(
  2877. 'type' => 'success',
  2878. 'msg' => 'Task completed'
  2879. ));
  2880. }
  2881. }
  2882. }
  2883. else {
  2884. echo json_encode(array(
  2885. 'type' => 'error',
  2886. 'msg' => 'Incomplete post data'
  2887. ));
  2888. }
  2889. }
  2890. else {
  2891. echo json_encode(array(
  2892. 'type' => 'error',
  2893. 'msg' => 'Incomplete post data'
  2894. ));
  2895. }
  2896. break;
  2897. case "domain":
  2898. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2899. $items = (array)json_decode($_POST['items'], true);
  2900. $attr = (array)json_decode($_POST['attr'], true);
  2901. $postarray = array_merge(array('domain' => $items), $attr);
  2902. if (is_array($postarray['domain'])) {
  2903. if (mailbox('edit', 'domain', $postarray)) {
  2904. if (isset($_SESSION['return'])) {
  2905. echo json_encode($_SESSION['return']);
  2906. }
  2907. else {
  2908. echo json_encode(array(
  2909. 'type' => 'error',
  2910. 'msg' => 'Edit failed'
  2911. ));
  2912. }
  2913. exit();
  2914. }
  2915. else {
  2916. if (isset($_SESSION['return'])) {
  2917. echo json_encode($_SESSION['return']);
  2918. }
  2919. else {
  2920. echo json_encode(array(
  2921. 'type' => 'success',
  2922. 'msg' => 'Task completed'
  2923. ));
  2924. }
  2925. }
  2926. }
  2927. else {
  2928. echo json_encode(array(
  2929. 'type' => 'error',
  2930. 'msg' => 'Incomplete post data'
  2931. ));
  2932. }
  2933. }
  2934. else {
  2935. echo json_encode(array(
  2936. 'type' => 'error',
  2937. 'msg' => 'Incomplete post data'
  2938. ));
  2939. }
  2940. break;
  2941. case "ratelimit":
  2942. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2943. $items = (array)json_decode($_POST['items'], true);
  2944. $attr = (array)json_decode($_POST['attr'], true);
  2945. $postarray = array_merge(array('object' => $items), $attr);
  2946. if (is_array($postarray['object'])) {
  2947. if (mailbox('edit', 'ratelimit', $postarray) === false) {
  2948. if (isset($_SESSION['return'])) {
  2949. echo json_encode($_SESSION['return']);
  2950. }
  2951. else {
  2952. echo json_encode(array(
  2953. 'type' => 'error',
  2954. 'msg' => 'Edit failed'
  2955. ));
  2956. }
  2957. exit();
  2958. }
  2959. else {
  2960. if (isset($_SESSION['return'])) {
  2961. echo json_encode($_SESSION['return']);
  2962. }
  2963. else {
  2964. echo json_encode(array(
  2965. 'type' => 'success',
  2966. 'msg' => 'Task completed'
  2967. ));
  2968. }
  2969. }
  2970. }
  2971. else {
  2972. echo json_encode(array(
  2973. 'type' => 'error',
  2974. 'msg' => 'Incomplete post data'
  2975. ));
  2976. }
  2977. }
  2978. else {
  2979. echo json_encode(array(
  2980. 'type' => 'error',
  2981. 'msg' => 'Incomplete post data'
  2982. ));
  2983. }
  2984. break;
  2985. case "alias-domain":
  2986. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2987. $items = (array)json_decode($_POST['items'], true);
  2988. $attr = (array)json_decode($_POST['attr'], true);
  2989. $postarray = array_merge(array('alias_domain' => $items), $attr);
  2990. if (is_array($postarray['alias_domain'])) {
  2991. if (mailbox('edit', 'alias_domain', $postarray) === false) {
  2992. if (isset($_SESSION['return'])) {
  2993. echo json_encode($_SESSION['return']);
  2994. }
  2995. else {
  2996. echo json_encode(array(
  2997. 'type' => 'error',
  2998. 'msg' => 'Edit failed'
  2999. ));
  3000. }
  3001. exit();
  3002. }
  3003. else {
  3004. if (isset($_SESSION['return'])) {
  3005. echo json_encode($_SESSION['return']);
  3006. }
  3007. else {
  3008. echo json_encode(array(
  3009. 'type' => 'success',
  3010. 'msg' => 'Task completed'
  3011. ));
  3012. }
  3013. }
  3014. }
  3015. else {
  3016. echo json_encode(array(
  3017. 'type' => 'error',
  3018. 'msg' => 'Incomplete post data'
  3019. ));
  3020. }
  3021. }
  3022. else {
  3023. echo json_encode(array(
  3024. 'type' => 'error',
  3025. 'msg' => 'Incomplete post data'
  3026. ));
  3027. }
  3028. break;
  3029. case "spam-score":
  3030. if (isset($_POST['items']) && isset($_POST['attr'])) {
  3031. $items = (array)json_decode($_POST['items'], true);
  3032. $attr = (array)json_decode($_POST['attr'], true);
  3033. $postarray = array_merge(array('username' => $items), $attr);
  3034. if (is_array($postarray['username'])) {
  3035. if (mailbox('edit', 'spam_score', $postarray) === false) {
  3036. if (isset($_SESSION['return'])) {
  3037. echo json_encode($_SESSION['return']);
  3038. }
  3039. else {
  3040. echo json_encode(array(
  3041. 'type' => 'error',
  3042. 'msg' => 'Edit failed'
  3043. ));
  3044. }
  3045. exit();
  3046. }
  3047. else {
  3048. if (isset($_SESSION['return'])) {
  3049. echo json_encode($_SESSION['return']);
  3050. }
  3051. else {
  3052. echo json_encode(array(
  3053. 'type' => 'success',
  3054. 'msg' => 'Task completed'
  3055. ));
  3056. }
  3057. }
  3058. }
  3059. else {
  3060. echo json_encode(array(
  3061. 'type' => 'error',
  3062. 'msg' => 'Incomplete post data'
  3063. ));
  3064. }
  3065. }
  3066. else {
  3067. echo json_encode(array(
  3068. 'type' => 'error',
  3069. 'msg' => 'Incomplete post data'
  3070. ));
  3071. }
  3072. break;
  3073. case "domain-admin":
  3074. if (isset($_POST['items']) && isset($_POST['attr'])) {
  3075. $items = (array)json_decode($_POST['items'], true);
  3076. $attr = (array)json_decode($_POST['attr'], true);
  3077. $postarray = array_merge(array('username' => $items), $attr);
  3078. if (is_array($postarray['username'])) {
  3079. if (domain_admin('edit', $postarray) === false) {
  3080. if (isset($_SESSION['return'])) {
  3081. echo json_encode($_SESSION['return']);
  3082. }
  3083. else {
  3084. echo json_encode(array(
  3085. 'type' => 'error',
  3086. 'msg' => 'Edit failed'
  3087. ));
  3088. }
  3089. exit();
  3090. }
  3091. else {
  3092. if (isset($_SESSION['return'])) {
  3093. echo json_encode($_SESSION['return']);
  3094. }
  3095. else {
  3096. echo json_encode(array(
  3097. 'type' => 'success',
  3098. 'msg' => 'Task completed'
  3099. ));
  3100. }
  3101. }
  3102. }
  3103. else {
  3104. echo json_encode(array(
  3105. 'type' => 'error',
  3106. 'msg' => 'Incomplete post data'
  3107. ));
  3108. }
  3109. }
  3110. else {
  3111. echo json_encode(array(
  3112. 'type' => 'error',
  3113. 'msg' => 'Incomplete post data'
  3114. ));
  3115. }
  3116. break;
  3117. case "fwdhost":
  3118. if (isset($_POST['items']) && isset($_POST['attr'])) {
  3119. $items = (array)json_decode($_POST['items'], true);
  3120. $attr = (array)json_decode($_POST['attr'], true);
  3121. $postarray = array_merge(array('fwdhost' => $items), $attr);
  3122. if (is_array($postarray['fwdhost'])) {
  3123. if (fwdhost('edit', $postarray) === false) {
  3124. if (isset($_SESSION['return'])) {
  3125. echo json_encode($_SESSION['return']);
  3126. }
  3127. else {
  3128. echo json_encode(array(
  3129. 'type' => 'error',
  3130. 'msg' => 'Edit failed'
  3131. ));
  3132. }
  3133. exit();
  3134. }
  3135. else {
  3136. if (isset($_SESSION['return'])) {
  3137. echo json_encode($_SESSION['return']);
  3138. }
  3139. else {
  3140. echo json_encode(array(
  3141. 'type' => 'success',
  3142. 'msg' => 'Task completed'
  3143. ));
  3144. }
  3145. }
  3146. }
  3147. else {
  3148. echo json_encode(array(
  3149. 'type' => 'error',
  3150. 'msg' => 'Incomplete post data'
  3151. ));
  3152. }
  3153. }
  3154. else {
  3155. echo json_encode(array(
  3156. 'type' => 'error',
  3157. 'msg' => 'Incomplete post data'
  3158. ));
  3159. }
  3160. break;
  3161. case "fail2ban":
  3162. // No items
  3163. if (isset($_POST['attr'])) {
  3164. $attr = (array)json_decode($_POST['attr'], true);
  3165. if (fail2ban('edit', $attr) === false) {
  3166. if (isset($_SESSION['return'])) {
  3167. echo json_encode($_SESSION['return']);
  3168. }
  3169. else {
  3170. echo json_encode(array(
  3171. 'type' => 'error',
  3172. 'msg' => 'Edit failed'
  3173. ));
  3174. }
  3175. exit();
  3176. }
  3177. else {
  3178. if (isset($_SESSION['return'])) {
  3179. echo json_encode($_SESSION['return']);
  3180. }
  3181. else {
  3182. echo json_encode(array(
  3183. 'type' => 'success',
  3184. 'msg' => 'Task completed'
  3185. ));
  3186. }
  3187. }
  3188. }
  3189. else {
  3190. echo json_encode(array(
  3191. 'type' => 'error',
  3192. 'msg' => 'Incomplete post data'
  3193. ));
  3194. }
  3195. break;
  3196. case "ui_texts":
  3197. // No items
  3198. if (isset($_POST['attr'])) {
  3199. $attr = (array)json_decode($_POST['attr'], true);
  3200. if (customize('edit', 'ui_texts', $attr) === false) {
  3201. if (isset($_SESSION['return'])) {
  3202. echo json_encode($_SESSION['return']);
  3203. }
  3204. else {
  3205. echo json_encode(array(
  3206. 'type' => 'error',
  3207. 'msg' => 'Edit failed'
  3208. ));
  3209. }
  3210. exit();
  3211. }
  3212. else {
  3213. if (isset($_SESSION['return'])) {
  3214. echo json_encode($_SESSION['return']);
  3215. }
  3216. else {
  3217. echo json_encode(array(
  3218. 'type' => 'success',
  3219. 'msg' => 'Task completed'
  3220. ));
  3221. }
  3222. }
  3223. }
  3224. else {
  3225. echo json_encode(array(
  3226. 'type' => 'error',
  3227. 'msg' => 'Incomplete post data'
  3228. ));
  3229. }
  3230. break;
  3231. case "self":
  3232. // No items, logged-in user, users and domain admins
  3233. if ($_SESSION['mailcow_cc_role'] == "domainadmin") {
  3234. if (isset($_POST['attr'])) {
  3235. $attr = (array)json_decode($_POST['attr'], true);
  3236. if (domain_admin('edit', $attr) === false) {
  3237. if (isset($_SESSION['return'])) {
  3238. echo json_encode($_SESSION['return']);
  3239. }
  3240. else {
  3241. echo json_encode(array(
  3242. 'type' => 'error',
  3243. 'msg' => 'Edit failed'
  3244. ));
  3245. }
  3246. exit();
  3247. }
  3248. else {
  3249. if (isset($_SESSION['return'])) {
  3250. echo json_encode($_SESSION['return']);
  3251. }
  3252. else {
  3253. echo json_encode(array(
  3254. 'type' => 'success',
  3255. 'msg' => 'Task completed'
  3256. ));
  3257. }
  3258. }
  3259. }
  3260. else {
  3261. echo json_encode(array(
  3262. 'type' => 'error',
  3263. 'msg' => 'Incomplete post data'
  3264. ));
  3265. }
  3266. }
  3267. elseif ($_SESSION['mailcow_cc_role'] == "user") {
  3268. if (isset($_POST['attr'])) {
  3269. $attr = (array)json_decode($_POST['attr'], true);
  3270. if (edit_user_account($attr) === false) {
  3271. if (isset($_SESSION['return'])) {
  3272. echo json_encode($_SESSION['return']);
  3273. }
  3274. else {
  3275. echo json_encode(array(
  3276. 'type' => 'error',
  3277. 'msg' => 'Edit failed'
  3278. ));
  3279. }
  3280. exit();
  3281. }
  3282. else {
  3283. if (isset($_SESSION['return'])) {
  3284. echo json_encode($_SESSION['return']);
  3285. }
  3286. else {
  3287. echo json_encode(array(
  3288. 'type' => 'success',
  3289. 'msg' => 'Task completed'
  3290. ));
  3291. }
  3292. }
  3293. }
  3294. else {
  3295. echo json_encode(array(
  3296. 'type' => 'error',
  3297. 'msg' => 'Incomplete post data'
  3298. ));
  3299. }
  3300. }
  3301. elseif ($_SESSION['mailcow_cc_role'] == "admin") {
  3302. if (isset($_POST['attr'])) {
  3303. $attr = (array)json_decode($_POST['attr'], true);
  3304. if (edit_admin_account($attr) === false) {
  3305. if (isset($_SESSION['return'])) {
  3306. echo json_encode($_SESSION['return']);
  3307. }
  3308. else {
  3309. echo json_encode(array(
  3310. 'type' => 'error',
  3311. 'msg' => 'Edit failed'
  3312. ));
  3313. }
  3314. exit();
  3315. }
  3316. else {
  3317. if (isset($_SESSION['return'])) {
  3318. echo json_encode($_SESSION['return']);
  3319. }
  3320. else {
  3321. echo json_encode(array(
  3322. 'type' => 'success',
  3323. 'msg' => 'Task completed'
  3324. ));
  3325. }
  3326. }
  3327. }
  3328. else {
  3329. echo json_encode(array(
  3330. 'type' => 'error',
  3331. 'msg' => 'Incomplete post data'
  3332. ));
  3333. }
  3334. }
  3335. break;
  3336. }
  3337. break;
  3338. }
  3339. }
  3340. }