json_api.php 80 KB

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