json_api.php 113 KB

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