json_api.php 105 KB

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