json_api.php 70 KB

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