json_api.php 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998
  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 "mailbox":
  60. if (isset($_POST['attr'])) {
  61. $attr = (array)json_decode($_POST['attr'], true);
  62. if (mailbox('add', 'mailbox', $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 "domain":
  93. if (isset($_POST['attr'])) {
  94. $attr = (array)json_decode($_POST['attr'], true);
  95. if (mailbox('add', 'domain', $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 "resource":
  126. if (isset($_POST['attr'])) {
  127. $attr = (array)json_decode($_POST['attr'], true);
  128. if (mailbox('add', 'resource', $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 "alias":
  159. if (isset($_POST['attr'])) {
  160. $attr = (array)json_decode($_POST['attr'], true);
  161. if (mailbox('add', 'alias', $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 "syncjob":
  192. if (isset($_POST['attr'])) {
  193. $attr = (array)json_decode($_POST['attr'], true);
  194. if (mailbox('add', 'syncjob', $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 "domain-policy":
  225. if (isset($_POST['attr'])) {
  226. $attr = (array)json_decode($_POST['attr'], true);
  227. if (policy('add', 'domain', $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 "mailbox-policy":
  258. if (isset($_POST['attr'])) {
  259. $attr = (array)json_decode($_POST['attr'], true);
  260. if (policy('add', 'mailbox', $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 "alias-domain":
  291. if (isset($_POST['attr'])) {
  292. $attr = (array)json_decode($_POST['attr'], true);
  293. if (mailbox('add', 'alias_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 "fwdhost":
  324. if (isset($_POST['attr'])) {
  325. $attr = (array)json_decode($_POST['attr'], true);
  326. if (fwdhost('add', $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 "dkim":
  357. if (isset($_POST['attr'])) {
  358. $attr = (array)json_decode($_POST['attr'], true);
  359. if (dkim('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 "domain-admin":
  390. if (isset($_POST['attr'])) {
  391. $attr = (array)json_decode($_POST['attr'], true);
  392. if (add_domain_admin($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. }
  423. break;
  424. case "get":
  425. switch ($category) {
  426. case "domain":
  427. switch ($object) {
  428. case "all":
  429. $domains = mailbox('get', 'domains');
  430. if (!empty($domains)) {
  431. foreach ($domains as $domain) {
  432. if ($details = mailbox('get', 'domain_details', $domain)) {
  433. $data[] = $details;
  434. }
  435. else {
  436. continue;
  437. }
  438. }
  439. if (!isset($data) || empty($data)) {
  440. echo '{}';
  441. }
  442. else {
  443. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  444. }
  445. }
  446. else {
  447. echo '{}';
  448. }
  449. break;
  450. default:
  451. $data = mailbox('get', 'domain_details', $object);
  452. if (!isset($data) || empty($data)) {
  453. echo '{}';
  454. }
  455. else {
  456. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  457. }
  458. break;
  459. }
  460. break;
  461. case "logs":
  462. switch ($object) {
  463. case "dovecot":
  464. if (isset($extra) && !empty($extra)) {
  465. $extra = intval($extra);
  466. $logs = get_logs('dovecot-mailcow', $extra);
  467. }
  468. else {
  469. $logs = get_logs('dovecot-mailcow', -1);
  470. }
  471. if (isset($logs) && !empty($logs)) {
  472. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  473. }
  474. else {
  475. echo '{}';
  476. }
  477. break;
  478. case "fail2ban":
  479. if (isset($extra) && !empty($extra)) {
  480. $extra = intval($extra);
  481. $logs = get_logs('fail2ban-mailcow', $extra);
  482. }
  483. else {
  484. $logs = get_logs('fail2ban-mailcow', -1);
  485. }
  486. if (isset($logs) && !empty($logs)) {
  487. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  488. }
  489. else {
  490. echo '{}';
  491. }
  492. break;
  493. case "postfix":
  494. if (isset($extra) && !empty($extra)) {
  495. $extra = intval($extra);
  496. $logs = get_logs('postfix-mailcow', $extra);
  497. }
  498. else {
  499. $logs = get_logs('postfix-mailcow', -1);
  500. }
  501. if (isset($logs) && !empty($logs)) {
  502. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  503. }
  504. else {
  505. echo '{}';
  506. }
  507. break;
  508. case "sogo":
  509. if (isset($extra) && !empty($extra)) {
  510. $extra = intval($extra);
  511. $logs = get_logs('sogo-mailcow', $extra);
  512. }
  513. else {
  514. $logs = get_logs('sogo-mailcow', -1);
  515. }
  516. if (isset($logs) && !empty($logs)) {
  517. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  518. }
  519. else {
  520. echo '{}';
  521. }
  522. break;
  523. case "rspamd-history":
  524. $logs = get_logs('rspamd-history');
  525. if (isset($logs) && !empty($logs)) {
  526. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  527. }
  528. else {
  529. echo '{}';
  530. }
  531. break;
  532. }
  533. break;
  534. case "mailbox":
  535. switch ($object) {
  536. case "all":
  537. $domains = mailbox('get', 'domains');
  538. if (!empty($domains)) {
  539. foreach ($domains as $domain) {
  540. $mailboxes = mailbox('get', 'mailboxes', $domain);
  541. if (!empty($mailboxes)) {
  542. foreach ($mailboxes as $mailbox) {
  543. if ($details = mailbox('get', 'mailbox_details', $mailbox)) {
  544. $data[] = $details;
  545. }
  546. else {
  547. continue;
  548. }
  549. }
  550. }
  551. }
  552. if (!isset($data) || empty($data)) {
  553. echo '{}';
  554. }
  555. else {
  556. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  557. }
  558. }
  559. else {
  560. echo '{}';
  561. }
  562. break;
  563. default:
  564. $data = mailbox('get', 'mailbox_details', $object);
  565. if (!isset($data) || empty($data)) {
  566. echo '{}';
  567. }
  568. else {
  569. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  570. }
  571. break;
  572. }
  573. break;
  574. case "syncjobs":
  575. switch ($object) {
  576. default:
  577. $data = mailbox('get', 'syncjobs', $object);
  578. if (!isset($data) || empty($data)) {
  579. echo '{}';
  580. }
  581. else {
  582. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  583. }
  584. break;
  585. }
  586. break;
  587. case "policy_wl_mailbox":
  588. switch ($object) {
  589. default:
  590. $data = policy('get', 'mailbox', $object)['whitelist'];
  591. if (!isset($data) || empty($data)) {
  592. echo '{}';
  593. }
  594. else {
  595. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  596. }
  597. break;
  598. }
  599. break;
  600. case "policy_bl_mailbox":
  601. switch ($object) {
  602. default:
  603. $data = policy('get', 'mailbox', $object)['blacklist'];
  604. if (!isset($data) || empty($data)) {
  605. echo '{}';
  606. }
  607. else {
  608. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  609. }
  610. break;
  611. }
  612. break;
  613. case "policy_wl_domain":
  614. switch ($object) {
  615. default:
  616. $data = policy('get', 'domain', $object)['whitelist'];
  617. if (!isset($data) || empty($data)) {
  618. echo '{}';
  619. }
  620. else {
  621. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  622. }
  623. break;
  624. }
  625. break;
  626. case "policy_bl_domain":
  627. switch ($object) {
  628. default:
  629. $data = policy('get', 'domain', $object)['blacklist'];
  630. if (!isset($data) || empty($data)) {
  631. echo '{}';
  632. }
  633. else {
  634. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  635. }
  636. break;
  637. }
  638. break;
  639. case "time_limited_aliases":
  640. switch ($object) {
  641. default:
  642. $data = mailbox('get', 'time_limited_aliases', $object);
  643. if (!isset($data) || empty($data)) {
  644. echo '{}';
  645. }
  646. else {
  647. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  648. }
  649. break;
  650. }
  651. break;
  652. case "resource":
  653. switch ($object) {
  654. case "all":
  655. $domains = mailbox('get', 'domains');
  656. if (!empty($domains)) {
  657. foreach ($domains as $domain) {
  658. $resources = mailbox('get', 'resources', $domain);
  659. if (!empty($resources)) {
  660. foreach ($resources as $resource) {
  661. if ($details = mailbox('get', 'resource_details', $resource)) {
  662. $data[] = $details;
  663. }
  664. else {
  665. continue;
  666. }
  667. }
  668. }
  669. }
  670. if (!isset($data) || empty($data)) {
  671. echo '{}';
  672. }
  673. else {
  674. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  675. }
  676. }
  677. else {
  678. echo '{}';
  679. }
  680. break;
  681. default:
  682. $data = mailbox('get', 'resource_details', $object);
  683. if (!isset($data) || empty($data)) {
  684. echo '{}';
  685. }
  686. else {
  687. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  688. }
  689. break;
  690. }
  691. break;
  692. case "fwdhost":
  693. switch ($object) {
  694. case "all":
  695. $data = fwdhost('get');
  696. if (!isset($data) || empty($data)) {
  697. echo '{}';
  698. }
  699. else {
  700. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  701. }
  702. break;
  703. default:
  704. $data = fwdhost('details', $object);
  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 "alias-domain":
  715. switch ($object) {
  716. case "all":
  717. $alias_domains = mailbox('get', 'alias_domains');
  718. if (!empty($alias_domains)) {
  719. foreach ($alias_domains as $alias_domain) {
  720. if ($details = mailbox('get', 'alias_domain_details', $alias_domain)) {
  721. $data[] = $details;
  722. }
  723. else {
  724. continue;
  725. }
  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. break;
  735. default:
  736. $data = mailbox('get', 'alias_domain_details', $object);
  737. if (!isset($data) || empty($data)) {
  738. echo '{}';
  739. }
  740. else {
  741. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  742. }
  743. break;
  744. }
  745. break;
  746. case "alias":
  747. switch ($object) {
  748. case "all":
  749. $domains = array_merge(mailbox('get', 'domains'),mailbox('get', 'alias_domains'));
  750. if (!empty($domains)) {
  751. foreach ($domains as $domain) {
  752. $aliases = mailbox('get', 'aliases', $domain);
  753. if (!empty($aliases)) {
  754. foreach ($aliases as $alias) {
  755. if ($details = mailbox('get', 'alias_details', $alias)) {
  756. $data[] = $details;
  757. }
  758. else {
  759. continue;
  760. }
  761. }
  762. }
  763. }
  764. if (!isset($data) || empty($data)) {
  765. echo '{}';
  766. }
  767. else {
  768. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  769. }
  770. }
  771. else {
  772. echo '{}';
  773. }
  774. break;
  775. default:
  776. $data = mailbox('get', 'alias_details', $object);
  777. if (!isset($data) || empty($data)) {
  778. echo '{}';
  779. }
  780. else {
  781. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  782. }
  783. break;
  784. }
  785. break;
  786. case "domain-admin":
  787. switch ($object) {
  788. case "all":
  789. $domain_admins = get_domain_admins();
  790. if (!empty($domain_admins)) {
  791. foreach ($domain_admins as $domain_admin) {
  792. if ($details = get_domain_admin_details($domain_admin)) {
  793. $data[] = $details;
  794. }
  795. else {
  796. continue;
  797. }
  798. }
  799. if (!isset($data) || empty($data)) {
  800. echo '{}';
  801. }
  802. else {
  803. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  804. }
  805. }
  806. else {
  807. echo '{}';
  808. }
  809. break;
  810. default:
  811. $data = get_domain_admin_details($object);
  812. if (!isset($data) || empty($data)) {
  813. echo '{}';
  814. }
  815. else {
  816. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  817. }
  818. break;
  819. }
  820. break;
  821. case "u2f-registration":
  822. header('Content-Type: application/javascript');
  823. if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
  824. $data = $u2f->getRegisterData(get_u2f_registrations($object));
  825. list($req, $sigs) = $data;
  826. $_SESSION['regReq'] = json_encode($req);
  827. echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';';
  828. }
  829. else {
  830. return;
  831. }
  832. break;
  833. case "u2f-authentication":
  834. header('Content-Type: application/javascript');
  835. if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
  836. $reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
  837. $_SESSION['authReq'] = $reqs;
  838. echo 'var req = ' . $reqs . ';';
  839. }
  840. else {
  841. return;
  842. }
  843. break;
  844. default:
  845. echo '{}';
  846. break;
  847. }
  848. break;
  849. case "delete":
  850. switch ($category) {
  851. case "alias":
  852. if (isset($_POST['items'])) {
  853. $items = (array)json_decode($_POST['items'], true);
  854. if (is_array($items)) {
  855. if (mailbox('delete', 'alias', array('address' => $items)) === false) {
  856. if (isset($_SESSION['return'])) {
  857. echo json_encode($_SESSION['return']);
  858. }
  859. else {
  860. echo json_encode(array(
  861. 'type' => 'error',
  862. 'msg' => 'Deletion of items/s failed'
  863. ));
  864. }
  865. }
  866. else {
  867. if (isset($_SESSION['return'])) {
  868. echo json_encode($_SESSION['return']);
  869. }
  870. else {
  871. echo json_encode(array(
  872. 'type' => 'success',
  873. 'msg' => 'Task completed'
  874. ));
  875. }
  876. }
  877. }
  878. else {
  879. echo json_encode(array(
  880. 'type' => 'error',
  881. 'msg' => 'Cannot find address array in post data'
  882. ));
  883. }
  884. }
  885. else {
  886. echo json_encode(array(
  887. 'type' => 'error',
  888. 'msg' => 'Cannot find items in post data'
  889. ));
  890. }
  891. break;
  892. case "syncjob":
  893. if (isset($_POST['items'])) {
  894. $items = (array)json_decode($_POST['items'], true);
  895. if (is_array($items)) {
  896. if (mailbox('delete', 'syncjob', array('id' => $items)) === false) {
  897. if (isset($_SESSION['return'])) {
  898. echo json_encode($_SESSION['return']);
  899. }
  900. else {
  901. echo json_encode(array(
  902. 'type' => 'error',
  903. 'msg' => 'Deletion of items/s failed'
  904. ));
  905. }
  906. }
  907. else {
  908. if (isset($_SESSION['return'])) {
  909. echo json_encode($_SESSION['return']);
  910. }
  911. else {
  912. echo json_encode(array(
  913. 'type' => 'success',
  914. 'msg' => 'Task completed'
  915. ));
  916. }
  917. }
  918. }
  919. else {
  920. echo json_encode(array(
  921. 'type' => 'error',
  922. 'msg' => 'Cannot find id array in post data'
  923. ));
  924. }
  925. }
  926. else {
  927. echo json_encode(array(
  928. 'type' => 'error',
  929. 'msg' => 'Cannot find items in post data'
  930. ));
  931. }
  932. break;
  933. case "fwdhost":
  934. if (isset($_POST['items'])) {
  935. $items = (array)json_decode($_POST['items'], true);
  936. if (is_array($items)) {
  937. if (fwdhost('delete', array('forwardinghost' => $items)) === false) {
  938. if (isset($_SESSION['return'])) {
  939. echo json_encode($_SESSION['return']);
  940. }
  941. else {
  942. echo json_encode(array(
  943. 'type' => 'error',
  944. 'msg' => 'Deletion of items/s failed'
  945. ));
  946. }
  947. }
  948. else {
  949. if (isset($_SESSION['return'])) {
  950. echo json_encode($_SESSION['return']);
  951. }
  952. else {
  953. echo json_encode(array(
  954. 'type' => 'success',
  955. 'msg' => 'Task completed'
  956. ));
  957. }
  958. }
  959. }
  960. else {
  961. echo json_encode(array(
  962. 'type' => 'error',
  963. 'msg' => 'Cannot find forwardinghost array in post data'
  964. ));
  965. }
  966. }
  967. else {
  968. echo json_encode(array(
  969. 'type' => 'error',
  970. 'msg' => 'Cannot find items in post data'
  971. ));
  972. }
  973. break;
  974. case "dkim":
  975. if (isset($_POST['items'])) {
  976. $items = (array)json_decode($_POST['items'], true);
  977. if (is_array($items)) {
  978. if (dkim('delete', array('domains' => $items)) === false) {
  979. if (isset($_SESSION['return'])) {
  980. echo json_encode($_SESSION['return']);
  981. }
  982. else {
  983. echo json_encode(array(
  984. 'type' => 'error',
  985. 'msg' => 'Deletion of items/s failed'
  986. ));
  987. }
  988. }
  989. else {
  990. if (isset($_SESSION['return'])) {
  991. echo json_encode($_SESSION['return']);
  992. }
  993. else {
  994. echo json_encode(array(
  995. 'type' => 'success',
  996. 'msg' => 'Task completed'
  997. ));
  998. }
  999. }
  1000. }
  1001. else {
  1002. echo json_encode(array(
  1003. 'type' => 'error',
  1004. 'msg' => 'Cannot find domains array in post data'
  1005. ));
  1006. }
  1007. }
  1008. else {
  1009. echo json_encode(array(
  1010. 'type' => 'error',
  1011. 'msg' => 'Cannot find items in post data'
  1012. ));
  1013. }
  1014. break;
  1015. case "domain":
  1016. if (isset($_POST['items'])) {
  1017. $items = (array)json_decode($_POST['items'], true);
  1018. if (is_array($items)) {
  1019. if (mailbox('delete', 'domain', array('domain' => $items)) === false) {
  1020. if (isset($_SESSION['return'])) {
  1021. echo json_encode($_SESSION['return']);
  1022. }
  1023. else {
  1024. echo json_encode(array(
  1025. 'type' => 'error',
  1026. 'msg' => 'Task failed'
  1027. ));
  1028. }
  1029. }
  1030. else {
  1031. if (isset($_SESSION['return'])) {
  1032. echo json_encode($_SESSION['return']);
  1033. }
  1034. else {
  1035. echo json_encode(array(
  1036. 'type' => 'success',
  1037. 'msg' => 'Task completed'
  1038. ));
  1039. }
  1040. }
  1041. }
  1042. else {
  1043. echo json_encode(array(
  1044. 'type' => 'error',
  1045. 'msg' => 'Cannot find domain array in post data'
  1046. ));
  1047. }
  1048. }
  1049. else {
  1050. echo json_encode(array(
  1051. 'type' => 'error',
  1052. 'msg' => 'Cannot find items in post data'
  1053. ));
  1054. }
  1055. break;
  1056. case "alias-domain":
  1057. if (isset($_POST['items'])) {
  1058. $items = (array)json_decode($_POST['items'], true);
  1059. if (is_array($items)) {
  1060. if (mailbox('delete', 'alias_domain', array('alias_domain' => $items)) === false) {
  1061. if (isset($_SESSION['return'])) {
  1062. echo json_encode($_SESSION['return']);
  1063. }
  1064. else {
  1065. echo json_encode(array(
  1066. 'type' => 'error',
  1067. 'msg' => 'Task failed'
  1068. ));
  1069. }
  1070. }
  1071. else {
  1072. if (isset($_SESSION['return'])) {
  1073. echo json_encode($_SESSION['return']);
  1074. }
  1075. else {
  1076. echo json_encode(array(
  1077. 'type' => 'success',
  1078. 'msg' => 'Task completed'
  1079. ));
  1080. }
  1081. }
  1082. }
  1083. else {
  1084. echo json_encode(array(
  1085. 'type' => 'error',
  1086. 'msg' => 'Cannot find alias_domain array in post data'
  1087. ));
  1088. }
  1089. }
  1090. else {
  1091. echo json_encode(array(
  1092. 'type' => 'error',
  1093. 'msg' => 'Cannot find items in post data'
  1094. ));
  1095. }
  1096. break;
  1097. case "mailbox":
  1098. if (isset($_POST['items'])) {
  1099. $items = (array)json_decode($_POST['items'], true);
  1100. if (is_array($items)) {
  1101. if (mailbox('delete', 'mailbox', array('username' => $items)) === false) {
  1102. if (isset($_SESSION['return'])) {
  1103. echo json_encode($_SESSION['return']);
  1104. }
  1105. else {
  1106. echo json_encode(array(
  1107. 'type' => 'error',
  1108. 'msg' => 'Task failed'
  1109. ));
  1110. }
  1111. }
  1112. else {
  1113. if (isset($_SESSION['return'])) {
  1114. echo json_encode($_SESSION['return']);
  1115. }
  1116. else {
  1117. echo json_encode(array(
  1118. 'type' => 'success',
  1119. 'msg' => 'Task completed'
  1120. ));
  1121. }
  1122. }
  1123. }
  1124. else {
  1125. echo json_encode(array(
  1126. 'type' => 'error',
  1127. 'msg' => 'Cannot find username array in post data'
  1128. ));
  1129. }
  1130. }
  1131. else {
  1132. echo json_encode(array(
  1133. 'type' => 'error',
  1134. 'msg' => 'Cannot find items in post data'
  1135. ));
  1136. }
  1137. break;
  1138. case "resource":
  1139. if (isset($_POST['items'])) {
  1140. $items = (array)json_decode($_POST['items'], true);
  1141. if (is_array($items)) {
  1142. if (mailbox('delete', 'resource', array('name' => $items)) === false) {
  1143. if (isset($_SESSION['return'])) {
  1144. echo json_encode($_SESSION['return']);
  1145. }
  1146. else {
  1147. echo json_encode(array(
  1148. 'type' => 'error',
  1149. 'msg' => 'Task failed'
  1150. ));
  1151. }
  1152. }
  1153. else {
  1154. if (isset($_SESSION['return'])) {
  1155. echo json_encode($_SESSION['return']);
  1156. }
  1157. else {
  1158. echo json_encode(array(
  1159. 'type' => 'success',
  1160. 'msg' => 'Task completed'
  1161. ));
  1162. }
  1163. }
  1164. }
  1165. else {
  1166. echo json_encode(array(
  1167. 'type' => 'error',
  1168. 'msg' => 'Cannot find name array in post data'
  1169. ));
  1170. }
  1171. }
  1172. else {
  1173. echo json_encode(array(
  1174. 'type' => 'error',
  1175. 'msg' => 'Cannot find items in post data'
  1176. ));
  1177. }
  1178. break;
  1179. case "mailbox-policy":
  1180. if (isset($_POST['items'])) {
  1181. $items = (array)json_decode($_POST['items'], true);
  1182. if (is_array($items)) {
  1183. if (policy('delete', 'mailbox', array('prefid' => $items)) === false) {
  1184. if (isset($_SESSION['return'])) {
  1185. echo json_encode($_SESSION['return']);
  1186. }
  1187. else {
  1188. echo json_encode(array(
  1189. 'type' => 'error',
  1190. 'msg' => 'Task failed'
  1191. ));
  1192. }
  1193. }
  1194. else {
  1195. if (isset($_SESSION['return'])) {
  1196. echo json_encode($_SESSION['return']);
  1197. }
  1198. else {
  1199. echo json_encode(array(
  1200. 'type' => 'success',
  1201. 'msg' => 'Task completed'
  1202. ));
  1203. }
  1204. }
  1205. }
  1206. else {
  1207. echo json_encode(array(
  1208. 'type' => 'error',
  1209. 'msg' => 'Cannot find name array in post data'
  1210. ));
  1211. }
  1212. }
  1213. else {
  1214. echo json_encode(array(
  1215. 'type' => 'error',
  1216. 'msg' => 'Cannot find items in post data'
  1217. ));
  1218. }
  1219. break;
  1220. case "domain-policy":
  1221. if (isset($_POST['items'])) {
  1222. $items = (array)json_decode($_POST['items'], true);
  1223. if (is_array($items)) {
  1224. if (policy('delete', 'domain', array('prefid' => $items)) === false) {
  1225. if (isset($_SESSION['return'])) {
  1226. echo json_encode($_SESSION['return']);
  1227. }
  1228. else {
  1229. echo json_encode(array(
  1230. 'type' => 'error',
  1231. 'msg' => 'Task failed'
  1232. ));
  1233. }
  1234. }
  1235. else {
  1236. if (isset($_SESSION['return'])) {
  1237. echo json_encode($_SESSION['return']);
  1238. }
  1239. else {
  1240. echo json_encode(array(
  1241. 'type' => 'success',
  1242. 'msg' => 'Task completed'
  1243. ));
  1244. }
  1245. }
  1246. }
  1247. else {
  1248. echo json_encode(array(
  1249. 'type' => 'error',
  1250. 'msg' => 'Cannot find name array in post data'
  1251. ));
  1252. }
  1253. }
  1254. else {
  1255. echo json_encode(array(
  1256. 'type' => 'error',
  1257. 'msg' => 'Cannot find items in post data'
  1258. ));
  1259. }
  1260. break;
  1261. case "time_limited_alias":
  1262. if (isset($_POST['items'])) {
  1263. $items = (array)json_decode($_POST['items'], true);
  1264. if (is_array($items)) {
  1265. if (mailbox('delete', 'time_limited_alias', array('address' => $items)) === false) {
  1266. if (isset($_SESSION['return'])) {
  1267. echo json_encode($_SESSION['return']);
  1268. }
  1269. else {
  1270. echo json_encode(array(
  1271. 'type' => 'error',
  1272. 'msg' => 'Task failed'
  1273. ));
  1274. }
  1275. }
  1276. else {
  1277. if (isset($_SESSION['return'])) {
  1278. echo json_encode($_SESSION['return']);
  1279. }
  1280. else {
  1281. echo json_encode(array(
  1282. 'type' => 'success',
  1283. 'msg' => 'Task completed'
  1284. ));
  1285. }
  1286. }
  1287. }
  1288. else {
  1289. echo json_encode(array(
  1290. 'type' => 'error',
  1291. 'msg' => 'Cannot find name array in post data'
  1292. ));
  1293. }
  1294. }
  1295. else {
  1296. echo json_encode(array(
  1297. 'type' => 'error',
  1298. 'msg' => 'Cannot find items in post data'
  1299. ));
  1300. }
  1301. break;
  1302. case "eas_cache":
  1303. if (isset($_POST['items'])) {
  1304. $items = (array)json_decode($_POST['items'], true);
  1305. if (is_array($items)) {
  1306. if (mailbox('delete', 'eas_cache', array('username' => $items)) === false) {
  1307. if (isset($_SESSION['return'])) {
  1308. echo json_encode($_SESSION['return']);
  1309. }
  1310. else {
  1311. echo json_encode(array(
  1312. 'type' => 'error',
  1313. 'msg' => 'Task failed'
  1314. ));
  1315. }
  1316. }
  1317. else {
  1318. if (isset($_SESSION['return'])) {
  1319. echo json_encode($_SESSION['return']);
  1320. }
  1321. else {
  1322. echo json_encode(array(
  1323. 'type' => 'success',
  1324. 'msg' => 'Task completed'
  1325. ));
  1326. }
  1327. }
  1328. }
  1329. else {
  1330. echo json_encode(array(
  1331. 'type' => 'error',
  1332. 'msg' => 'Cannot find name array in post data'
  1333. ));
  1334. }
  1335. }
  1336. else {
  1337. echo json_encode(array(
  1338. 'type' => 'error',
  1339. 'msg' => 'Cannot find items in post data'
  1340. ));
  1341. }
  1342. break;
  1343. case "domain-admin":
  1344. if (isset($_POST['items'])) {
  1345. $items = (array)json_decode($_POST['items'], true);
  1346. if (is_array($items)) {
  1347. if (delete_domain_admin(array('username' => $items)) === false) {
  1348. if (isset($_SESSION['return'])) {
  1349. echo json_encode($_SESSION['return']);
  1350. }
  1351. else {
  1352. echo json_encode(array(
  1353. 'type' => 'error',
  1354. 'msg' => 'Task failed'
  1355. ));
  1356. }
  1357. }
  1358. else {
  1359. if (isset($_SESSION['return'])) {
  1360. echo json_encode($_SESSION['return']);
  1361. }
  1362. else {
  1363. echo json_encode(array(
  1364. 'type' => 'success',
  1365. 'msg' => 'Task completed'
  1366. ));
  1367. }
  1368. }
  1369. }
  1370. else {
  1371. echo json_encode(array(
  1372. 'type' => 'error',
  1373. 'msg' => 'Cannot find name array in post data'
  1374. ));
  1375. }
  1376. }
  1377. else {
  1378. echo json_encode(array(
  1379. 'type' => 'error',
  1380. 'msg' => 'Cannot find items in post data'
  1381. ));
  1382. }
  1383. break;
  1384. }
  1385. break;
  1386. case "edit":
  1387. switch ($category) {
  1388. case "alias":
  1389. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1390. $items = (array)json_decode($_POST['items'], true);
  1391. $attr = (array)json_decode($_POST['attr'], true);
  1392. $postarray = array_merge(array('address' => $items), $attr);
  1393. if (is_array($postarray['address'])) {
  1394. if (mailbox('edit', 'alias', $postarray) === false) {
  1395. if (isset($_SESSION['return'])) {
  1396. echo json_encode($_SESSION['return']);
  1397. }
  1398. else {
  1399. echo json_encode(array(
  1400. 'type' => 'error',
  1401. 'msg' => 'Edit failed'
  1402. ));
  1403. }
  1404. exit();
  1405. }
  1406. else {
  1407. if (isset($_SESSION['return'])) {
  1408. echo json_encode($_SESSION['return']);
  1409. }
  1410. else {
  1411. echo json_encode(array(
  1412. 'type' => 'success',
  1413. 'msg' => 'Task completed'
  1414. ));
  1415. }
  1416. }
  1417. }
  1418. else {
  1419. echo json_encode(array(
  1420. 'type' => 'error',
  1421. 'msg' => 'Incomplete post data'
  1422. ));
  1423. }
  1424. }
  1425. else {
  1426. echo json_encode(array(
  1427. 'type' => 'error',
  1428. 'msg' => 'Incomplete post data'
  1429. ));
  1430. }
  1431. break;
  1432. case "delimiter_action":
  1433. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1434. $items = (array)json_decode($_POST['items'], true);
  1435. $attr = (array)json_decode($_POST['attr'], true);
  1436. $postarray = array_merge(array('username' => $items), $attr);
  1437. if (is_array($postarray['username'])) {
  1438. if (mailbox('edit', 'delimiter_action', $postarray) === false) {
  1439. if (isset($_SESSION['return'])) {
  1440. echo json_encode($_SESSION['return']);
  1441. }
  1442. else {
  1443. echo json_encode(array(
  1444. 'type' => 'error',
  1445. 'msg' => 'Edit failed'
  1446. ));
  1447. }
  1448. exit();
  1449. }
  1450. else {
  1451. if (isset($_SESSION['return'])) {
  1452. echo json_encode($_SESSION['return']);
  1453. }
  1454. else {
  1455. echo json_encode(array(
  1456. 'type' => 'success',
  1457. 'msg' => 'Task completed'
  1458. ));
  1459. }
  1460. }
  1461. }
  1462. else {
  1463. echo json_encode(array(
  1464. 'type' => 'error',
  1465. 'msg' => 'Incomplete post data'
  1466. ));
  1467. }
  1468. }
  1469. else {
  1470. echo json_encode(array(
  1471. 'type' => 'error',
  1472. 'msg' => 'Incomplete post data'
  1473. ));
  1474. }
  1475. break;
  1476. case "tls_policy":
  1477. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1478. $items = (array)json_decode($_POST['items'], true);
  1479. $attr = (array)json_decode($_POST['attr'], true);
  1480. $postarray = array_merge(array('username' => $items), $attr);
  1481. if (is_array($postarray['username'])) {
  1482. if (mailbox('edit', 'tls_policy', $postarray) === false) {
  1483. if (isset($_SESSION['return'])) {
  1484. echo json_encode($_SESSION['return']);
  1485. }
  1486. else {
  1487. echo json_encode(array(
  1488. 'type' => 'error',
  1489. 'msg' => 'Edit failed'
  1490. ));
  1491. }
  1492. exit();
  1493. }
  1494. else {
  1495. if (isset($_SESSION['return'])) {
  1496. echo json_encode($_SESSION['return']);
  1497. }
  1498. else {
  1499. echo json_encode(array(
  1500. 'type' => 'success',
  1501. 'msg' => 'Task completed'
  1502. ));
  1503. }
  1504. }
  1505. }
  1506. else {
  1507. echo json_encode(array(
  1508. 'type' => 'error',
  1509. 'msg' => 'Incomplete post data'
  1510. ));
  1511. }
  1512. }
  1513. else {
  1514. echo json_encode(array(
  1515. 'type' => 'error',
  1516. 'msg' => 'Incomplete post data'
  1517. ));
  1518. }
  1519. break;
  1520. case "time_limited_alias":
  1521. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1522. $items = (array)json_decode($_POST['items'], true);
  1523. $attr = (array)json_decode($_POST['attr'], true);
  1524. $postarray = array_merge(array('address' => $items), $attr);
  1525. if (is_array($postarray['address'])) {
  1526. if (mailbox('edit', 'time_limited_alias', $postarray) === false) {
  1527. if (isset($_SESSION['return'])) {
  1528. echo json_encode($_SESSION['return']);
  1529. }
  1530. else {
  1531. echo json_encode(array(
  1532. 'type' => 'error',
  1533. 'msg' => 'Edit failed'
  1534. ));
  1535. }
  1536. exit();
  1537. }
  1538. else {
  1539. if (isset($_SESSION['return'])) {
  1540. echo json_encode($_SESSION['return']);
  1541. }
  1542. else {
  1543. echo json_encode(array(
  1544. 'type' => 'success',
  1545. 'msg' => 'Task completed'
  1546. ));
  1547. }
  1548. }
  1549. }
  1550. else {
  1551. echo json_encode(array(
  1552. 'type' => 'error',
  1553. 'msg' => 'Incomplete post data'
  1554. ));
  1555. }
  1556. }
  1557. else {
  1558. echo json_encode(array(
  1559. 'type' => 'error',
  1560. 'msg' => 'Incomplete post data'
  1561. ));
  1562. }
  1563. break;
  1564. case "mailbox":
  1565. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1566. $items = (array)json_decode($_POST['items'], true);
  1567. $attr = (array)json_decode($_POST['attr'], true);
  1568. $postarray = array_merge(array('username' => $items), $attr);
  1569. if (is_array($postarray['username'])) {
  1570. if (mailbox('edit', 'mailbox', $postarray) === false) {
  1571. if (isset($_SESSION['return'])) {
  1572. echo json_encode($_SESSION['return']);
  1573. }
  1574. else {
  1575. echo json_encode(array(
  1576. 'type' => 'error',
  1577. 'msg' => 'Edit failed'
  1578. ));
  1579. }
  1580. exit();
  1581. }
  1582. else {
  1583. if (isset($_SESSION['return'])) {
  1584. echo json_encode($_SESSION['return']);
  1585. }
  1586. else {
  1587. echo json_encode(array(
  1588. 'type' => 'success',
  1589. 'msg' => 'Task completed'
  1590. ));
  1591. }
  1592. }
  1593. }
  1594. else {
  1595. echo json_encode(array(
  1596. 'type' => 'error',
  1597. 'msg' => 'Incomplete post data'
  1598. ));
  1599. }
  1600. }
  1601. else {
  1602. echo json_encode(array(
  1603. 'type' => 'error',
  1604. 'msg' => 'Incomplete post data'
  1605. ));
  1606. }
  1607. break;
  1608. case "syncjob":
  1609. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1610. $items = (array)json_decode($_POST['items'], true);
  1611. $attr = (array)json_decode($_POST['attr'], true);
  1612. $postarray = array_merge(array('id' => $items), $attr);
  1613. if (is_array($postarray['id'])) {
  1614. if (mailbox('edit', 'syncjob', $postarray) === false) {
  1615. if (isset($_SESSION['return'])) {
  1616. echo json_encode($_SESSION['return']);
  1617. }
  1618. else {
  1619. echo json_encode(array(
  1620. 'type' => 'error',
  1621. 'msg' => 'Edit failed'
  1622. ));
  1623. }
  1624. exit();
  1625. }
  1626. else {
  1627. if (isset($_SESSION['return'])) {
  1628. echo json_encode($_SESSION['return']);
  1629. }
  1630. else {
  1631. echo json_encode(array(
  1632. 'type' => 'success',
  1633. 'msg' => 'Task completed'
  1634. ));
  1635. }
  1636. }
  1637. }
  1638. else {
  1639. echo json_encode(array(
  1640. 'type' => 'error',
  1641. 'msg' => 'Incomplete post data'
  1642. ));
  1643. }
  1644. }
  1645. else {
  1646. echo json_encode(array(
  1647. 'type' => 'error',
  1648. 'msg' => 'Incomplete post data'
  1649. ));
  1650. }
  1651. break;
  1652. case "resource":
  1653. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1654. $items = (array)json_decode($_POST['items'], true);
  1655. $attr = (array)json_decode($_POST['attr'], true);
  1656. $postarray = array_merge(array('name' => $items), $attr);
  1657. if (is_array($postarray['name'])) {
  1658. if (mailbox('edit', 'resource', $postarray) === false) {
  1659. if (isset($_SESSION['return'])) {
  1660. echo json_encode($_SESSION['return']);
  1661. }
  1662. else {
  1663. echo json_encode(array(
  1664. 'type' => 'error',
  1665. 'msg' => 'Edit failed'
  1666. ));
  1667. }
  1668. exit();
  1669. }
  1670. else {
  1671. if (isset($_SESSION['return'])) {
  1672. echo json_encode($_SESSION['return']);
  1673. }
  1674. else {
  1675. echo json_encode(array(
  1676. 'type' => 'success',
  1677. 'msg' => 'Task completed'
  1678. ));
  1679. }
  1680. }
  1681. }
  1682. else {
  1683. echo json_encode(array(
  1684. 'type' => 'error',
  1685. 'msg' => 'Incomplete post data'
  1686. ));
  1687. }
  1688. }
  1689. else {
  1690. echo json_encode(array(
  1691. 'type' => 'error',
  1692. 'msg' => 'Incomplete post data'
  1693. ));
  1694. }
  1695. break;
  1696. case "domain":
  1697. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1698. $items = (array)json_decode($_POST['items'], true);
  1699. $attr = (array)json_decode($_POST['attr'], true);
  1700. $postarray = array_merge(array('domain' => $items), $attr);
  1701. if (is_array($postarray['domain'])) {
  1702. if (mailbox('edit', 'domain', $postarray) === false) {
  1703. if (isset($_SESSION['return'])) {
  1704. echo json_encode($_SESSION['return']);
  1705. }
  1706. else {
  1707. echo json_encode(array(
  1708. 'type' => 'error',
  1709. 'msg' => 'Edit failed'
  1710. ));
  1711. }
  1712. exit();
  1713. }
  1714. else {
  1715. if (isset($_SESSION['return'])) {
  1716. echo json_encode($_SESSION['return']);
  1717. }
  1718. else {
  1719. echo json_encode(array(
  1720. 'type' => 'success',
  1721. 'msg' => 'Task completed'
  1722. ));
  1723. }
  1724. }
  1725. }
  1726. else {
  1727. echo json_encode(array(
  1728. 'type' => 'error',
  1729. 'msg' => 'Incomplete post data'
  1730. ));
  1731. }
  1732. }
  1733. else {
  1734. echo json_encode(array(
  1735. 'type' => 'error',
  1736. 'msg' => 'Incomplete post data'
  1737. ));
  1738. }
  1739. break;
  1740. case "alias-domain":
  1741. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1742. $items = (array)json_decode($_POST['items'], true);
  1743. $attr = (array)json_decode($_POST['attr'], true);
  1744. $postarray = array_merge(array('alias_domain' => $items), $attr);
  1745. if (is_array($postarray['alias_domain'])) {
  1746. if (mailbox('edit', 'alias_domain', $postarray) === 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' => 'Edit failed'
  1754. ));
  1755. }
  1756. exit();
  1757. }
  1758. else {
  1759. if (isset($_SESSION['return'])) {
  1760. echo json_encode($_SESSION['return']);
  1761. }
  1762. else {
  1763. echo json_encode(array(
  1764. 'type' => 'success',
  1765. 'msg' => 'Task completed'
  1766. ));
  1767. }
  1768. }
  1769. }
  1770. else {
  1771. echo json_encode(array(
  1772. 'type' => 'error',
  1773. 'msg' => 'Incomplete post data'
  1774. ));
  1775. }
  1776. }
  1777. else {
  1778. echo json_encode(array(
  1779. 'type' => 'error',
  1780. 'msg' => 'Incomplete post data'
  1781. ));
  1782. }
  1783. break;
  1784. case "spam_score":
  1785. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1786. $items = (array)json_decode($_POST['items'], true);
  1787. $attr = (array)json_decode($_POST['attr'], true);
  1788. $postarray = array_merge(array('username' => $items), $attr);
  1789. if (is_array($postarray['username'])) {
  1790. if (mailbox('edit', 'spam_score', $postarray) === false) {
  1791. if (isset($_SESSION['return'])) {
  1792. echo json_encode($_SESSION['return']);
  1793. }
  1794. else {
  1795. echo json_encode(array(
  1796. 'type' => 'error',
  1797. 'msg' => 'Edit failed'
  1798. ));
  1799. }
  1800. exit();
  1801. }
  1802. else {
  1803. if (isset($_SESSION['return'])) {
  1804. echo json_encode($_SESSION['return']);
  1805. }
  1806. else {
  1807. echo json_encode(array(
  1808. 'type' => 'success',
  1809. 'msg' => 'Task completed'
  1810. ));
  1811. }
  1812. }
  1813. }
  1814. else {
  1815. echo json_encode(array(
  1816. 'type' => 'error',
  1817. 'msg' => 'Incomplete post data'
  1818. ));
  1819. }
  1820. }
  1821. else {
  1822. echo json_encode(array(
  1823. 'type' => 'error',
  1824. 'msg' => 'Incomplete post data'
  1825. ));
  1826. }
  1827. break;
  1828. case "domain-admin":
  1829. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1830. $items = (array)json_decode($_POST['items'], true);
  1831. $attr = (array)json_decode($_POST['attr'], true);
  1832. $postarray = array_merge(array('username' => $items), $attr);
  1833. if (is_array($postarray['username'])) {
  1834. if (edit_domain_admin($postarray) === false) {
  1835. if (isset($_SESSION['return'])) {
  1836. echo json_encode($_SESSION['return']);
  1837. }
  1838. else {
  1839. echo json_encode(array(
  1840. 'type' => 'error',
  1841. 'msg' => 'Edit failed'
  1842. ));
  1843. }
  1844. exit();
  1845. }
  1846. else {
  1847. if (isset($_SESSION['return'])) {
  1848. echo json_encode($_SESSION['return']);
  1849. }
  1850. else {
  1851. echo json_encode(array(
  1852. 'type' => 'success',
  1853. 'msg' => 'Task completed'
  1854. ));
  1855. }
  1856. }
  1857. }
  1858. else {
  1859. echo json_encode(array(
  1860. 'type' => 'error',
  1861. 'msg' => 'Incomplete post data'
  1862. ));
  1863. }
  1864. }
  1865. else {
  1866. echo json_encode(array(
  1867. 'type' => 'error',
  1868. 'msg' => 'Incomplete post data'
  1869. ));
  1870. }
  1871. break;
  1872. case "fwdhost":
  1873. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1874. $items = (array)json_decode($_POST['items'], true);
  1875. $attr = (array)json_decode($_POST['attr'], true);
  1876. $postarray = array_merge(array('fwdhost' => $items), $attr);
  1877. if (is_array($postarray['fwdhost'])) {
  1878. if (fwdhost('edit', $postarray) === false) {
  1879. if (isset($_SESSION['return'])) {
  1880. echo json_encode($_SESSION['return']);
  1881. }
  1882. else {
  1883. echo json_encode(array(
  1884. 'type' => 'error',
  1885. 'msg' => 'Edit failed'
  1886. ));
  1887. }
  1888. exit();
  1889. }
  1890. else {
  1891. if (isset($_SESSION['return'])) {
  1892. echo json_encode($_SESSION['return']);
  1893. }
  1894. else {
  1895. echo json_encode(array(
  1896. 'type' => 'success',
  1897. 'msg' => 'Task completed'
  1898. ));
  1899. }
  1900. }
  1901. }
  1902. else {
  1903. echo json_encode(array(
  1904. 'type' => 'error',
  1905. 'msg' => 'Incomplete post data'
  1906. ));
  1907. }
  1908. }
  1909. else {
  1910. echo json_encode(array(
  1911. 'type' => 'error',
  1912. 'msg' => 'Incomplete post data'
  1913. ));
  1914. }
  1915. break;
  1916. case "fail2ban":
  1917. // No items
  1918. if (isset($_POST['attr'])) {
  1919. $attr = (array)json_decode($_POST['attr'], true);
  1920. if (edit_f2b_parameters($attr) === false) {
  1921. if (isset($_SESSION['return'])) {
  1922. echo json_encode($_SESSION['return']);
  1923. }
  1924. else {
  1925. echo json_encode(array(
  1926. 'type' => 'error',
  1927. 'msg' => 'Edit failed'
  1928. ));
  1929. }
  1930. exit();
  1931. }
  1932. else {
  1933. if (isset($_SESSION['return'])) {
  1934. echo json_encode($_SESSION['return']);
  1935. }
  1936. else {
  1937. echo json_encode(array(
  1938. 'type' => 'success',
  1939. 'msg' => 'Task completed'
  1940. ));
  1941. }
  1942. }
  1943. }
  1944. else {
  1945. echo json_encode(array(
  1946. 'type' => 'error',
  1947. 'msg' => 'Incomplete post data'
  1948. ));
  1949. }
  1950. break;
  1951. case "admin":
  1952. // No items as there is only one admin
  1953. if (isset($_POST['attr'])) {
  1954. $attr = (array)json_decode($_POST['attr'], true);
  1955. if (edit_admin_account($attr) === false) {
  1956. if (isset($_SESSION['return'])) {
  1957. echo json_encode($_SESSION['return']);
  1958. }
  1959. else {
  1960. echo json_encode(array(
  1961. 'type' => 'error',
  1962. 'msg' => 'Edit failed'
  1963. ));
  1964. }
  1965. exit();
  1966. }
  1967. else {
  1968. if (isset($_SESSION['return'])) {
  1969. echo json_encode($_SESSION['return']);
  1970. }
  1971. else {
  1972. echo json_encode(array(
  1973. 'type' => 'success',
  1974. 'msg' => 'Task completed'
  1975. ));
  1976. }
  1977. }
  1978. }
  1979. else {
  1980. echo json_encode(array(
  1981. 'type' => 'error',
  1982. 'msg' => 'Incomplete post data'
  1983. ));
  1984. }
  1985. break;
  1986. }
  1987. break;
  1988. }
  1989. }
  1990. }