json_api.php 114 KB

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