json_api.php 90 KB

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