json_api.php 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736
  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 "filter":
  225. if (isset($_POST['attr'])) {
  226. $attr = (array)json_decode($_POST['attr'], true);
  227. if (mailbox('add', 'filter', $attr) === false) {
  228. if (isset($_SESSION['return'])) {
  229. echo json_encode($_SESSION['return']);
  230. }
  231. else {
  232. echo json_encode(array(
  233. 'type' => 'error',
  234. 'msg' => 'Cannot add item'
  235. ));
  236. }
  237. }
  238. else {
  239. if (isset($_SESSION['return'])) {
  240. echo json_encode($_SESSION['return']);
  241. }
  242. else {
  243. echo json_encode(array(
  244. 'type' => 'success',
  245. 'msg' => 'Task completed'
  246. ));
  247. }
  248. }
  249. }
  250. else {
  251. echo json_encode(array(
  252. 'type' => 'error',
  253. 'msg' => 'Cannot find attributes in post data'
  254. ));
  255. }
  256. break;
  257. case "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. // 0 is first record, so empty is fine
  723. if (isset($extra)) {
  724. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  725. $logs = get_logs('dovecot-mailcow', $extra);
  726. }
  727. else {
  728. $logs = get_logs('dovecot-mailcow');
  729. }
  730. if (isset($logs) && !empty($logs)) {
  731. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  732. }
  733. else {
  734. echo '{}';
  735. }
  736. break;
  737. case "fail2ban":
  738. // 0 is first record, so empty is fine
  739. if (isset($extra)) {
  740. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  741. $logs = get_logs('fail2ban-mailcow', $extra);
  742. }
  743. else {
  744. $logs = get_logs('fail2ban-mailcow');
  745. }
  746. if (isset($logs) && !empty($logs)) {
  747. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  748. }
  749. else {
  750. echo '{}';
  751. }
  752. break;
  753. case "postfix":
  754. // 0 is first record, so empty is fine
  755. if (isset($extra)) {
  756. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  757. $logs = get_logs('postfix-mailcow', $extra);
  758. }
  759. else {
  760. $logs = get_logs('postfix-mailcow');
  761. }
  762. if (isset($logs) && !empty($logs)) {
  763. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  764. }
  765. else {
  766. echo '{}';
  767. }
  768. break;
  769. case "autodiscover":
  770. // 0 is first record, so empty is fine
  771. if (isset($extra)) {
  772. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  773. $logs = get_logs('autodiscover-mailcow', $extra);
  774. }
  775. else {
  776. $logs = get_logs('autodiscover-mailcow');
  777. }
  778. if (isset($logs) && !empty($logs)) {
  779. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  780. }
  781. else {
  782. echo '{}';
  783. }
  784. break;
  785. case "sogo":
  786. // 0 is first record, so empty is fine
  787. if (isset($extra)) {
  788. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  789. $logs = get_logs('sogo-mailcow', $extra);
  790. }
  791. else {
  792. $logs = get_logs('sogo-mailcow');
  793. }
  794. if (isset($logs) && !empty($logs)) {
  795. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  796. }
  797. else {
  798. echo '{}';
  799. }
  800. break;
  801. case "rspamd-history":
  802. // 0 is first record, so empty is fine
  803. if (isset($extra)) {
  804. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  805. $logs = get_logs('rspamd-history', $extra);
  806. }
  807. else {
  808. $logs = get_logs('rspamd-history');
  809. }
  810. if (isset($logs) && !empty($logs)) {
  811. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  812. }
  813. else {
  814. echo '{}';
  815. }
  816. break;
  817. }
  818. break;
  819. case "mailbox":
  820. switch ($object) {
  821. case "all":
  822. $domains = mailbox('get', 'domains');
  823. if (!empty($domains)) {
  824. foreach ($domains as $domain) {
  825. $mailboxes = mailbox('get', 'mailboxes', $domain);
  826. if (!empty($mailboxes)) {
  827. foreach ($mailboxes as $mailbox) {
  828. if ($details = mailbox('get', 'mailbox_details', $mailbox)) {
  829. $data[] = $details;
  830. }
  831. else {
  832. continue;
  833. }
  834. }
  835. }
  836. }
  837. if (!isset($data) || empty($data)) {
  838. echo '{}';
  839. }
  840. else {
  841. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  842. }
  843. }
  844. else {
  845. echo '{}';
  846. }
  847. break;
  848. default:
  849. $data = mailbox('get', 'mailbox_details', $object);
  850. if (!isset($data) || empty($data)) {
  851. echo '{}';
  852. }
  853. else {
  854. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  855. }
  856. break;
  857. }
  858. break;
  859. case "syncjobs":
  860. switch ($object) {
  861. case "all":
  862. $domains = mailbox('get', 'domains');
  863. if (!empty($domains)) {
  864. foreach ($domains as $domain) {
  865. $mailboxes = mailbox('get', 'mailboxes', $domain);
  866. if (!empty($mailboxes)) {
  867. foreach ($mailboxes as $mailbox) {
  868. $syncjobs = mailbox('get', 'syncjobs', $mailbox);
  869. if (!empty($syncjobs)) {
  870. foreach ($syncjobs as $syncjob) {
  871. if (isset($extra)) {
  872. $details = mailbox('get', 'syncjob_details', $syncjob, explode(',', $extra));
  873. }
  874. else {
  875. $details = mailbox('get', 'syncjob_details', $syncjob);
  876. }
  877. if ($details) {
  878. $data[] = $details;
  879. }
  880. else {
  881. continue;
  882. }
  883. }
  884. }
  885. }
  886. }
  887. }
  888. if (!isset($data) || empty($data)) {
  889. echo '{}';
  890. }
  891. else {
  892. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  893. }
  894. }
  895. else {
  896. echo '{}';
  897. }
  898. break;
  899. default:
  900. $syncjobs = mailbox('get', 'syncjobs', $object);
  901. if (!empty($syncjobs)) {
  902. foreach ($syncjobs as $syncjob) {
  903. if (isset($extra)) {
  904. $details = mailbox('get', 'syncjob_details', $syncjob, explode(',', $extra));
  905. }
  906. else {
  907. $details = mailbox('get', 'syncjob_details', $syncjob);
  908. }
  909. if ($details) {
  910. $data[] = $details;
  911. }
  912. else {
  913. continue;
  914. }
  915. }
  916. }
  917. if (!isset($data) || empty($data)) {
  918. echo '{}';
  919. }
  920. else {
  921. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  922. }
  923. break;
  924. }
  925. break;
  926. case "active-user-sieve":
  927. if (isset($object)) {
  928. $sieve_filter = mailbox('get', 'active_user_sieve', $object);
  929. if (!empty($sieve_filter)) {
  930. $data[] = $sieve_filter;
  931. }
  932. }
  933. if (!isset($data) || empty($data)) {
  934. echo '{}';
  935. }
  936. else {
  937. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  938. }
  939. break;
  940. case "filters":
  941. switch ($object) {
  942. case "all":
  943. $domains = mailbox('get', 'domains');
  944. if (!empty($domains)) {
  945. foreach ($domains as $domain) {
  946. $mailboxes = mailbox('get', 'mailboxes', $domain);
  947. if (!empty($mailboxes)) {
  948. foreach ($mailboxes as $mailbox) {
  949. $filters = mailbox('get', 'filters', $mailbox);
  950. if (!empty($filters)) {
  951. foreach ($filters as $filter) {
  952. if ($details = mailbox('get', 'filter_details', $filter)) {
  953. $data[] = $details;
  954. }
  955. else {
  956. continue;
  957. }
  958. }
  959. }
  960. }
  961. }
  962. }
  963. if (!isset($data) || empty($data)) {
  964. echo '{}';
  965. }
  966. else {
  967. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  968. }
  969. }
  970. else {
  971. echo '{}';
  972. }
  973. break;
  974. default:
  975. $filters = mailbox('get', 'filters', $object);
  976. if (!empty($filters)) {
  977. foreach ($filters as $filter) {
  978. if ($details = mailbox('get', 'filter_details', $filter)) {
  979. $data[] = $details;
  980. }
  981. else {
  982. continue;
  983. }
  984. }
  985. }
  986. if (!isset($data) || empty($data)) {
  987. echo '{}';
  988. }
  989. else {
  990. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  991. }
  992. break;
  993. }
  994. break;
  995. case "policy_wl_mailbox":
  996. switch ($object) {
  997. default:
  998. $data = policy('get', 'mailbox', $object)['whitelist'];
  999. if (!isset($data) || empty($data)) {
  1000. echo '{}';
  1001. }
  1002. else {
  1003. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1004. }
  1005. break;
  1006. }
  1007. break;
  1008. case "policy_bl_mailbox":
  1009. switch ($object) {
  1010. default:
  1011. $data = policy('get', 'mailbox', $object)['blacklist'];
  1012. if (!isset($data) || empty($data)) {
  1013. echo '{}';
  1014. }
  1015. else {
  1016. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1017. }
  1018. break;
  1019. }
  1020. break;
  1021. case "policy_wl_domain":
  1022. switch ($object) {
  1023. default:
  1024. $data = policy('get', 'domain', $object)['whitelist'];
  1025. if (!isset($data) || empty($data)) {
  1026. echo '{}';
  1027. }
  1028. else {
  1029. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1030. }
  1031. break;
  1032. }
  1033. break;
  1034. case "policy_bl_domain":
  1035. switch ($object) {
  1036. default:
  1037. $data = policy('get', 'domain', $object)['blacklist'];
  1038. if (!isset($data) || empty($data)) {
  1039. echo '{}';
  1040. }
  1041. else {
  1042. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1043. }
  1044. break;
  1045. }
  1046. break;
  1047. case "time_limited_aliases":
  1048. switch ($object) {
  1049. default:
  1050. $data = mailbox('get', 'time_limited_aliases', $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 "resource":
  1061. switch ($object) {
  1062. case "all":
  1063. $domains = mailbox('get', 'domains');
  1064. if (!empty($domains)) {
  1065. foreach ($domains as $domain) {
  1066. $resources = mailbox('get', 'resources', $domain);
  1067. if (!empty($resources)) {
  1068. foreach ($resources as $resource) {
  1069. if ($details = mailbox('get', 'resource_details', $resource)) {
  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', 'resource_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 "fwdhost":
  1101. switch ($object) {
  1102. case "all":
  1103. $data = fwdhost('get');
  1104. if (!isset($data) || empty($data)) {
  1105. echo '{}';
  1106. }
  1107. else {
  1108. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1109. }
  1110. break;
  1111. default:
  1112. $data = fwdhost('details', $object);
  1113. if (!isset($data) || empty($data)) {
  1114. echo '{}';
  1115. }
  1116. else {
  1117. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1118. }
  1119. break;
  1120. }
  1121. break;
  1122. case "alias-domain":
  1123. switch ($object) {
  1124. case "all":
  1125. $alias_domains = mailbox('get', 'alias_domains');
  1126. if (!empty($alias_domains)) {
  1127. foreach ($alias_domains as $alias_domain) {
  1128. if ($details = mailbox('get', 'alias_domain_details', $alias_domain)) {
  1129. $data[] = $details;
  1130. }
  1131. else {
  1132. continue;
  1133. }
  1134. }
  1135. }
  1136. if (!isset($data) || empty($data)) {
  1137. echo '{}';
  1138. }
  1139. else {
  1140. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1141. }
  1142. break;
  1143. default:
  1144. $data = mailbox('get', 'alias_domain_details', $object);
  1145. if (!isset($data) || empty($data)) {
  1146. echo '{}';
  1147. }
  1148. else {
  1149. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1150. }
  1151. break;
  1152. }
  1153. break;
  1154. case "alias":
  1155. switch ($object) {
  1156. case "all":
  1157. $domains = array_merge(mailbox('get', 'domains'),mailbox('get', 'alias_domains'));
  1158. if (!empty($domains)) {
  1159. foreach ($domains as $domain) {
  1160. $aliases = mailbox('get', 'aliases', $domain);
  1161. if (!empty($aliases)) {
  1162. foreach ($aliases as $alias) {
  1163. if ($details = mailbox('get', 'alias_details', $alias)) {
  1164. $data[] = $details;
  1165. }
  1166. else {
  1167. continue;
  1168. }
  1169. }
  1170. }
  1171. }
  1172. if (!isset($data) || empty($data)) {
  1173. echo '{}';
  1174. }
  1175. else {
  1176. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1177. }
  1178. }
  1179. else {
  1180. echo '{}';
  1181. }
  1182. break;
  1183. default:
  1184. $data = mailbox('get', 'alias_details', $object);
  1185. if (!isset($data) || empty($data)) {
  1186. echo '{}';
  1187. }
  1188. else {
  1189. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1190. }
  1191. break;
  1192. }
  1193. break;
  1194. case "domain-admin":
  1195. switch ($object) {
  1196. case "all":
  1197. $domain_admins = domain_admin('get');
  1198. if (!empty($domain_admins)) {
  1199. foreach ($domain_admins as $domain_admin) {
  1200. if ($details = domain_admin('details', $domain_admin)) {
  1201. $data[] = $details;
  1202. }
  1203. else {
  1204. continue;
  1205. }
  1206. }
  1207. if (!isset($data) || empty($data)) {
  1208. echo '{}';
  1209. }
  1210. else {
  1211. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1212. }
  1213. }
  1214. else {
  1215. echo '{}';
  1216. }
  1217. break;
  1218. default:
  1219. $data = domain_admin('details', $object);
  1220. if (!isset($data) || empty($data)) {
  1221. echo '{}';
  1222. }
  1223. else {
  1224. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1225. }
  1226. break;
  1227. }
  1228. break;
  1229. case "u2f-registration":
  1230. header('Content-Type: application/javascript');
  1231. if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
  1232. $data = $u2f->getRegisterData(get_u2f_registrations($object));
  1233. list($req, $sigs) = $data;
  1234. $_SESSION['regReq'] = json_encode($req);
  1235. echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';';
  1236. }
  1237. else {
  1238. return;
  1239. }
  1240. break;
  1241. case "u2f-authentication":
  1242. header('Content-Type: application/javascript');
  1243. if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
  1244. $reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
  1245. $_SESSION['authReq'] = $reqs;
  1246. echo 'var req = ' . $reqs . ';';
  1247. }
  1248. else {
  1249. return;
  1250. }
  1251. break;
  1252. default:
  1253. echo '{}';
  1254. break;
  1255. }
  1256. break;
  1257. case "delete":
  1258. switch ($category) {
  1259. case "alias":
  1260. if (isset($_POST['items'])) {
  1261. $items = (array)json_decode($_POST['items'], true);
  1262. if (is_array($items)) {
  1263. if (mailbox('delete', 'alias', array('address' => $items)) === false) {
  1264. if (isset($_SESSION['return'])) {
  1265. echo json_encode($_SESSION['return']);
  1266. }
  1267. else {
  1268. echo json_encode(array(
  1269. 'type' => 'error',
  1270. 'msg' => 'Deletion of items/s failed'
  1271. ));
  1272. }
  1273. }
  1274. else {
  1275. if (isset($_SESSION['return'])) {
  1276. echo json_encode($_SESSION['return']);
  1277. }
  1278. else {
  1279. echo json_encode(array(
  1280. 'type' => 'success',
  1281. 'msg' => 'Task completed'
  1282. ));
  1283. }
  1284. }
  1285. }
  1286. else {
  1287. echo json_encode(array(
  1288. 'type' => 'error',
  1289. 'msg' => 'Cannot find address array in post data'
  1290. ));
  1291. }
  1292. }
  1293. else {
  1294. echo json_encode(array(
  1295. 'type' => 'error',
  1296. 'msg' => 'Cannot find items in post data'
  1297. ));
  1298. }
  1299. break;
  1300. case "relayhost":
  1301. if (isset($_POST['items'])) {
  1302. $items = (array)json_decode($_POST['items'], true);
  1303. if (is_array($items)) {
  1304. if (relayhost('delete', array('id' => $items)) === false) {
  1305. if (isset($_SESSION['return'])) {
  1306. echo json_encode($_SESSION['return']);
  1307. }
  1308. else {
  1309. echo json_encode(array(
  1310. 'type' => 'error',
  1311. 'msg' => 'Deletion of items/s failed'
  1312. ));
  1313. }
  1314. }
  1315. else {
  1316. if (isset($_SESSION['return'])) {
  1317. echo json_encode($_SESSION['return']);
  1318. }
  1319. else {
  1320. echo json_encode(array(
  1321. 'type' => 'success',
  1322. 'msg' => 'Task completed'
  1323. ));
  1324. }
  1325. }
  1326. }
  1327. else {
  1328. echo json_encode(array(
  1329. 'type' => 'error',
  1330. 'msg' => 'Cannot find id array in post data'
  1331. ));
  1332. }
  1333. }
  1334. else {
  1335. echo json_encode(array(
  1336. 'type' => 'error',
  1337. 'msg' => 'Cannot find items in post data'
  1338. ));
  1339. }
  1340. break;
  1341. case "syncjob":
  1342. if (isset($_POST['items'])) {
  1343. $items = (array)json_decode($_POST['items'], true);
  1344. if (is_array($items)) {
  1345. if (mailbox('delete', 'syncjob', array('id' => $items)) === false) {
  1346. if (isset($_SESSION['return'])) {
  1347. echo json_encode($_SESSION['return']);
  1348. }
  1349. else {
  1350. echo json_encode(array(
  1351. 'type' => 'error',
  1352. 'msg' => 'Deletion of items/s failed'
  1353. ));
  1354. }
  1355. }
  1356. else {
  1357. if (isset($_SESSION['return'])) {
  1358. echo json_encode($_SESSION['return']);
  1359. }
  1360. else {
  1361. echo json_encode(array(
  1362. 'type' => 'success',
  1363. 'msg' => 'Task completed'
  1364. ));
  1365. }
  1366. }
  1367. }
  1368. else {
  1369. echo json_encode(array(
  1370. 'type' => 'error',
  1371. 'msg' => 'Cannot find id array in post data'
  1372. ));
  1373. }
  1374. }
  1375. else {
  1376. echo json_encode(array(
  1377. 'type' => 'error',
  1378. 'msg' => 'Cannot find items in post data'
  1379. ));
  1380. }
  1381. break;
  1382. case "filter":
  1383. if (isset($_POST['items'])) {
  1384. $items = (array)json_decode($_POST['items'], true);
  1385. if (is_array($items)) {
  1386. if (mailbox('delete', 'filter', array('id' => $items)) === false) {
  1387. if (isset($_SESSION['return'])) {
  1388. echo json_encode($_SESSION['return']);
  1389. }
  1390. else {
  1391. echo json_encode(array(
  1392. 'type' => 'error',
  1393. 'msg' => 'Deletion of items/s failed'
  1394. ));
  1395. }
  1396. }
  1397. else {
  1398. if (isset($_SESSION['return'])) {
  1399. echo json_encode($_SESSION['return']);
  1400. }
  1401. else {
  1402. echo json_encode(array(
  1403. 'type' => 'success',
  1404. 'msg' => 'Task completed'
  1405. ));
  1406. }
  1407. }
  1408. }
  1409. else {
  1410. echo json_encode(array(
  1411. 'type' => 'error',
  1412. 'msg' => 'Cannot find id array in post data'
  1413. ));
  1414. }
  1415. }
  1416. else {
  1417. echo json_encode(array(
  1418. 'type' => 'error',
  1419. 'msg' => 'Cannot find items in post data'
  1420. ));
  1421. }
  1422. break;
  1423. case "fwdhost":
  1424. if (isset($_POST['items'])) {
  1425. $items = (array)json_decode($_POST['items'], true);
  1426. if (is_array($items)) {
  1427. if (fwdhost('delete', array('forwardinghost' => $items)) === 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' => 'Deletion of items/s failed'
  1435. ));
  1436. }
  1437. }
  1438. else {
  1439. if (isset($_SESSION['return'])) {
  1440. echo json_encode($_SESSION['return']);
  1441. }
  1442. else {
  1443. echo json_encode(array(
  1444. 'type' => 'success',
  1445. 'msg' => 'Task completed'
  1446. ));
  1447. }
  1448. }
  1449. }
  1450. else {
  1451. echo json_encode(array(
  1452. 'type' => 'error',
  1453. 'msg' => 'Cannot find forwardinghost array in post data'
  1454. ));
  1455. }
  1456. }
  1457. else {
  1458. echo json_encode(array(
  1459. 'type' => 'error',
  1460. 'msg' => 'Cannot find items in post data'
  1461. ));
  1462. }
  1463. break;
  1464. case "dkim":
  1465. if (isset($_POST['items'])) {
  1466. $items = (array)json_decode($_POST['items'], true);
  1467. if (is_array($items)) {
  1468. if (dkim('delete', array('domains' => $items)) === false) {
  1469. if (isset($_SESSION['return'])) {
  1470. echo json_encode($_SESSION['return']);
  1471. }
  1472. else {
  1473. echo json_encode(array(
  1474. 'type' => 'error',
  1475. 'msg' => 'Deletion of items/s failed'
  1476. ));
  1477. }
  1478. }
  1479. else {
  1480. if (isset($_SESSION['return'])) {
  1481. echo json_encode($_SESSION['return']);
  1482. }
  1483. else {
  1484. echo json_encode(array(
  1485. 'type' => 'success',
  1486. 'msg' => 'Task completed'
  1487. ));
  1488. }
  1489. }
  1490. }
  1491. else {
  1492. echo json_encode(array(
  1493. 'type' => 'error',
  1494. 'msg' => 'Cannot find domains array in post data'
  1495. ));
  1496. }
  1497. }
  1498. else {
  1499. echo json_encode(array(
  1500. 'type' => 'error',
  1501. 'msg' => 'Cannot find items in post data'
  1502. ));
  1503. }
  1504. break;
  1505. case "domain":
  1506. if (isset($_POST['items'])) {
  1507. $items = (array)json_decode($_POST['items'], true);
  1508. if (is_array($items)) {
  1509. if (mailbox('delete', 'domain', array('domain' => $items)) === false) {
  1510. if (isset($_SESSION['return'])) {
  1511. echo json_encode($_SESSION['return']);
  1512. }
  1513. else {
  1514. echo json_encode(array(
  1515. 'type' => 'error',
  1516. 'msg' => 'Task failed'
  1517. ));
  1518. }
  1519. }
  1520. else {
  1521. if (isset($_SESSION['return'])) {
  1522. echo json_encode($_SESSION['return']);
  1523. }
  1524. else {
  1525. echo json_encode(array(
  1526. 'type' => 'success',
  1527. 'msg' => 'Task completed'
  1528. ));
  1529. }
  1530. }
  1531. }
  1532. else {
  1533. echo json_encode(array(
  1534. 'type' => 'error',
  1535. 'msg' => 'Cannot find domain array in post data'
  1536. ));
  1537. }
  1538. }
  1539. else {
  1540. echo json_encode(array(
  1541. 'type' => 'error',
  1542. 'msg' => 'Cannot find items in post data'
  1543. ));
  1544. }
  1545. break;
  1546. case "alias-domain":
  1547. if (isset($_POST['items'])) {
  1548. $items = (array)json_decode($_POST['items'], true);
  1549. if (is_array($items)) {
  1550. if (mailbox('delete', 'alias_domain', array('alias_domain' => $items)) === false) {
  1551. if (isset($_SESSION['return'])) {
  1552. echo json_encode($_SESSION['return']);
  1553. }
  1554. else {
  1555. echo json_encode(array(
  1556. 'type' => 'error',
  1557. 'msg' => 'Task failed'
  1558. ));
  1559. }
  1560. }
  1561. else {
  1562. if (isset($_SESSION['return'])) {
  1563. echo json_encode($_SESSION['return']);
  1564. }
  1565. else {
  1566. echo json_encode(array(
  1567. 'type' => 'success',
  1568. 'msg' => 'Task completed'
  1569. ));
  1570. }
  1571. }
  1572. }
  1573. else {
  1574. echo json_encode(array(
  1575. 'type' => 'error',
  1576. 'msg' => 'Cannot find alias_domain array in post data'
  1577. ));
  1578. }
  1579. }
  1580. else {
  1581. echo json_encode(array(
  1582. 'type' => 'error',
  1583. 'msg' => 'Cannot find items in post data'
  1584. ));
  1585. }
  1586. break;
  1587. case "mailbox":
  1588. if (isset($_POST['items'])) {
  1589. $items = (array)json_decode($_POST['items'], true);
  1590. if (is_array($items)) {
  1591. if (mailbox('delete', 'mailbox', array('username' => $items)) === false) {
  1592. if (isset($_SESSION['return'])) {
  1593. echo json_encode($_SESSION['return']);
  1594. }
  1595. else {
  1596. echo json_encode(array(
  1597. 'type' => 'error',
  1598. 'msg' => 'Task failed'
  1599. ));
  1600. }
  1601. }
  1602. else {
  1603. if (isset($_SESSION['return'])) {
  1604. echo json_encode($_SESSION['return']);
  1605. }
  1606. else {
  1607. echo json_encode(array(
  1608. 'type' => 'success',
  1609. 'msg' => 'Task completed'
  1610. ));
  1611. }
  1612. }
  1613. }
  1614. else {
  1615. echo json_encode(array(
  1616. 'type' => 'error',
  1617. 'msg' => 'Cannot find username array in post data'
  1618. ));
  1619. }
  1620. }
  1621. else {
  1622. echo json_encode(array(
  1623. 'type' => 'error',
  1624. 'msg' => 'Cannot find items in post data'
  1625. ));
  1626. }
  1627. break;
  1628. case "resource":
  1629. if (isset($_POST['items'])) {
  1630. $items = (array)json_decode($_POST['items'], true);
  1631. if (is_array($items)) {
  1632. if (mailbox('delete', 'resource', array('name' => $items)) === false) {
  1633. if (isset($_SESSION['return'])) {
  1634. echo json_encode($_SESSION['return']);
  1635. }
  1636. else {
  1637. echo json_encode(array(
  1638. 'type' => 'error',
  1639. 'msg' => 'Task failed'
  1640. ));
  1641. }
  1642. }
  1643. else {
  1644. if (isset($_SESSION['return'])) {
  1645. echo json_encode($_SESSION['return']);
  1646. }
  1647. else {
  1648. echo json_encode(array(
  1649. 'type' => 'success',
  1650. 'msg' => 'Task completed'
  1651. ));
  1652. }
  1653. }
  1654. }
  1655. else {
  1656. echo json_encode(array(
  1657. 'type' => 'error',
  1658. 'msg' => 'Cannot find name array in post data'
  1659. ));
  1660. }
  1661. }
  1662. else {
  1663. echo json_encode(array(
  1664. 'type' => 'error',
  1665. 'msg' => 'Cannot find items in post data'
  1666. ));
  1667. }
  1668. break;
  1669. case "mailbox-policy":
  1670. if (isset($_POST['items'])) {
  1671. $items = (array)json_decode($_POST['items'], true);
  1672. if (is_array($items)) {
  1673. if (policy('delete', 'mailbox', array('prefid' => $items)) === false) {
  1674. if (isset($_SESSION['return'])) {
  1675. echo json_encode($_SESSION['return']);
  1676. }
  1677. else {
  1678. echo json_encode(array(
  1679. 'type' => 'error',
  1680. 'msg' => 'Task failed'
  1681. ));
  1682. }
  1683. }
  1684. else {
  1685. if (isset($_SESSION['return'])) {
  1686. echo json_encode($_SESSION['return']);
  1687. }
  1688. else {
  1689. echo json_encode(array(
  1690. 'type' => 'success',
  1691. 'msg' => 'Task completed'
  1692. ));
  1693. }
  1694. }
  1695. }
  1696. else {
  1697. echo json_encode(array(
  1698. 'type' => 'error',
  1699. 'msg' => 'Cannot find name array in post data'
  1700. ));
  1701. }
  1702. }
  1703. else {
  1704. echo json_encode(array(
  1705. 'type' => 'error',
  1706. 'msg' => 'Cannot find items in post data'
  1707. ));
  1708. }
  1709. break;
  1710. case "domain-policy":
  1711. if (isset($_POST['items'])) {
  1712. $items = (array)json_decode($_POST['items'], true);
  1713. if (is_array($items)) {
  1714. if (policy('delete', 'domain', array('prefid' => $items)) === false) {
  1715. if (isset($_SESSION['return'])) {
  1716. echo json_encode($_SESSION['return']);
  1717. }
  1718. else {
  1719. echo json_encode(array(
  1720. 'type' => 'error',
  1721. 'msg' => 'Task failed'
  1722. ));
  1723. }
  1724. }
  1725. else {
  1726. if (isset($_SESSION['return'])) {
  1727. echo json_encode($_SESSION['return']);
  1728. }
  1729. else {
  1730. echo json_encode(array(
  1731. 'type' => 'success',
  1732. 'msg' => 'Task completed'
  1733. ));
  1734. }
  1735. }
  1736. }
  1737. else {
  1738. echo json_encode(array(
  1739. 'type' => 'error',
  1740. 'msg' => 'Cannot find name array in post data'
  1741. ));
  1742. }
  1743. }
  1744. else {
  1745. echo json_encode(array(
  1746. 'type' => 'error',
  1747. 'msg' => 'Cannot find items in post data'
  1748. ));
  1749. }
  1750. break;
  1751. case "time_limited_alias":
  1752. if (isset($_POST['items'])) {
  1753. $items = (array)json_decode($_POST['items'], true);
  1754. if (is_array($items)) {
  1755. if (mailbox('delete', 'time_limited_alias', array('address' => $items)) === false) {
  1756. if (isset($_SESSION['return'])) {
  1757. echo json_encode($_SESSION['return']);
  1758. }
  1759. else {
  1760. echo json_encode(array(
  1761. 'type' => 'error',
  1762. 'msg' => 'Task failed'
  1763. ));
  1764. }
  1765. }
  1766. else {
  1767. if (isset($_SESSION['return'])) {
  1768. echo json_encode($_SESSION['return']);
  1769. }
  1770. else {
  1771. echo json_encode(array(
  1772. 'type' => 'success',
  1773. 'msg' => 'Task completed'
  1774. ));
  1775. }
  1776. }
  1777. }
  1778. else {
  1779. echo json_encode(array(
  1780. 'type' => 'error',
  1781. 'msg' => 'Cannot find name array in post data'
  1782. ));
  1783. }
  1784. }
  1785. else {
  1786. echo json_encode(array(
  1787. 'type' => 'error',
  1788. 'msg' => 'Cannot find items in post data'
  1789. ));
  1790. }
  1791. break;
  1792. case "eas_cache":
  1793. if (isset($_POST['items'])) {
  1794. $items = (array)json_decode($_POST['items'], true);
  1795. if (is_array($items)) {
  1796. if (mailbox('delete', 'eas_cache', array('username' => $items)) === false) {
  1797. if (isset($_SESSION['return'])) {
  1798. echo json_encode($_SESSION['return']);
  1799. }
  1800. else {
  1801. echo json_encode(array(
  1802. 'type' => 'error',
  1803. 'msg' => 'Task failed'
  1804. ));
  1805. }
  1806. }
  1807. else {
  1808. if (isset($_SESSION['return'])) {
  1809. echo json_encode($_SESSION['return']);
  1810. }
  1811. else {
  1812. echo json_encode(array(
  1813. 'type' => 'success',
  1814. 'msg' => 'Task completed'
  1815. ));
  1816. }
  1817. }
  1818. }
  1819. else {
  1820. echo json_encode(array(
  1821. 'type' => 'error',
  1822. 'msg' => 'Cannot find name array in post data'
  1823. ));
  1824. }
  1825. }
  1826. else {
  1827. echo json_encode(array(
  1828. 'type' => 'error',
  1829. 'msg' => 'Cannot find items in post data'
  1830. ));
  1831. }
  1832. break;
  1833. case "domain-admin":
  1834. if (isset($_POST['items'])) {
  1835. $items = (array)json_decode($_POST['items'], true);
  1836. if (is_array($items)) {
  1837. if (domain_admin('delete', array('username' => $items)) === 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' => 'Task failed'
  1845. ));
  1846. }
  1847. }
  1848. else {
  1849. if (isset($_SESSION['return'])) {
  1850. echo json_encode($_SESSION['return']);
  1851. }
  1852. else {
  1853. echo json_encode(array(
  1854. 'type' => 'success',
  1855. 'msg' => 'Task completed'
  1856. ));
  1857. }
  1858. }
  1859. }
  1860. else {
  1861. echo json_encode(array(
  1862. 'type' => 'error',
  1863. 'msg' => 'Cannot find name array in post data'
  1864. ));
  1865. }
  1866. }
  1867. else {
  1868. echo json_encode(array(
  1869. 'type' => 'error',
  1870. 'msg' => 'Cannot find items in post data'
  1871. ));
  1872. }
  1873. break;
  1874. }
  1875. break;
  1876. case "edit":
  1877. switch ($category) {
  1878. case "alias":
  1879. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1880. $items = (array)json_decode($_POST['items'], true);
  1881. $attr = (array)json_decode($_POST['attr'], true);
  1882. $postarray = array_merge(array('address' => $items), $attr);
  1883. if (is_array($postarray['address'])) {
  1884. if (mailbox('edit', 'alias', $postarray) === false) {
  1885. if (isset($_SESSION['return'])) {
  1886. echo json_encode($_SESSION['return']);
  1887. }
  1888. else {
  1889. echo json_encode(array(
  1890. 'type' => 'error',
  1891. 'msg' => 'Edit failed'
  1892. ));
  1893. }
  1894. exit();
  1895. }
  1896. else {
  1897. if (isset($_SESSION['return'])) {
  1898. echo json_encode($_SESSION['return']);
  1899. }
  1900. else {
  1901. echo json_encode(array(
  1902. 'type' => 'success',
  1903. 'msg' => 'Task completed'
  1904. ));
  1905. }
  1906. }
  1907. }
  1908. else {
  1909. echo json_encode(array(
  1910. 'type' => 'error',
  1911. 'msg' => 'Incomplete post data'
  1912. ));
  1913. }
  1914. }
  1915. else {
  1916. echo json_encode(array(
  1917. 'type' => 'error',
  1918. 'msg' => 'Incomplete post data'
  1919. ));
  1920. }
  1921. break;
  1922. case "app_links":
  1923. if (isset($_POST['attr'])) {
  1924. $attr = (array)json_decode($_POST['attr'], true);
  1925. if (is_array($attr)) {
  1926. if (customize('edit', 'app_links', $attr) === false) {
  1927. if (isset($_SESSION['return'])) {
  1928. echo json_encode($_SESSION['return']);
  1929. }
  1930. else {
  1931. echo json_encode(array(
  1932. 'type' => 'error',
  1933. 'msg' => 'Edit failed'
  1934. ));
  1935. }
  1936. exit();
  1937. }
  1938. else {
  1939. if (isset($_SESSION['return'])) {
  1940. echo json_encode($_SESSION['return']);
  1941. }
  1942. else {
  1943. echo json_encode(array(
  1944. 'type' => 'success',
  1945. 'msg' => 'Task completed'
  1946. ));
  1947. }
  1948. }
  1949. }
  1950. else {
  1951. echo json_encode(array(
  1952. 'type' => 'error',
  1953. 'msg' => 'Incomplete post data'
  1954. ));
  1955. }
  1956. }
  1957. else {
  1958. echo json_encode(array(
  1959. 'type' => 'error',
  1960. 'msg' => 'Incomplete post data'
  1961. ));
  1962. }
  1963. break;
  1964. case "relayhost":
  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('id' => $items), $attr);
  1969. if (is_array($postarray['id'])) {
  1970. if (relayhost('edit', $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 "delimiter_action":
  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('username' => $items), $attr);
  2013. if (is_array($postarray['username'])) {
  2014. if (mailbox('edit', 'delimiter_action', $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 "tls_policy":
  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('username' => $items), $attr);
  2057. if (is_array($postarray['username'])) {
  2058. if (mailbox('edit', 'tls_policy', $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 "time_limited_alias":
  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('address' => $items), $attr);
  2101. if (is_array($postarray['address'])) {
  2102. if (mailbox('edit', 'time_limited_alias', $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 "mailbox":
  2141. // sender_acl:0 removes all entries
  2142. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2143. $items = (array)json_decode($_POST['items'], true);
  2144. $attr = (array)json_decode($_POST['attr'], true);
  2145. $postarray = array_merge(array('username' => $items), $attr);
  2146. if (is_array($postarray['username'])) {
  2147. if (mailbox('edit', 'mailbox', $postarray) === false) {
  2148. if (isset($_SESSION['return'])) {
  2149. echo json_encode($_SESSION['return']);
  2150. }
  2151. else {
  2152. echo json_encode(array(
  2153. 'type' => 'error',
  2154. 'msg' => 'Edit failed'
  2155. ));
  2156. }
  2157. exit();
  2158. }
  2159. else {
  2160. if (isset($_SESSION['return'])) {
  2161. echo json_encode($_SESSION['return']);
  2162. }
  2163. else {
  2164. echo json_encode(array(
  2165. 'type' => 'success',
  2166. 'msg' => 'Task completed'
  2167. ));
  2168. }
  2169. }
  2170. }
  2171. else {
  2172. echo json_encode(array(
  2173. 'type' => 'error',
  2174. 'msg' => 'Incomplete post data'
  2175. ));
  2176. }
  2177. }
  2178. else {
  2179. echo json_encode(array(
  2180. 'type' => 'error',
  2181. 'msg' => 'Incomplete post data'
  2182. ));
  2183. }
  2184. break;
  2185. case "syncjob":
  2186. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2187. $items = (array)json_decode($_POST['items'], true);
  2188. $attr = (array)json_decode($_POST['attr'], true);
  2189. $postarray = array_merge(array('id' => $items), $attr);
  2190. if (is_array($postarray['id'])) {
  2191. if (mailbox('edit', 'syncjob', $postarray) === false) {
  2192. if (isset($_SESSION['return'])) {
  2193. echo json_encode($_SESSION['return']);
  2194. }
  2195. else {
  2196. echo json_encode(array(
  2197. 'type' => 'error',
  2198. 'msg' => 'Edit failed'
  2199. ));
  2200. }
  2201. exit();
  2202. }
  2203. else {
  2204. if (isset($_SESSION['return'])) {
  2205. echo json_encode($_SESSION['return']);
  2206. }
  2207. else {
  2208. echo json_encode(array(
  2209. 'type' => 'success',
  2210. 'msg' => 'Task completed'
  2211. ));
  2212. }
  2213. }
  2214. }
  2215. else {
  2216. echo json_encode(array(
  2217. 'type' => 'error',
  2218. 'msg' => 'Incomplete post data'
  2219. ));
  2220. }
  2221. }
  2222. else {
  2223. echo json_encode(array(
  2224. 'type' => 'error',
  2225. 'msg' => 'Incomplete post data'
  2226. ));
  2227. }
  2228. break;
  2229. case "filter":
  2230. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2231. $items = (array)json_decode($_POST['items'], true);
  2232. $attr = (array)json_decode($_POST['attr'], true);
  2233. $postarray = array_merge(array('id' => $items), $attr);
  2234. if (is_array($postarray['id'])) {
  2235. if (mailbox('edit', 'filter', $postarray) === false) {
  2236. if (isset($_SESSION['return'])) {
  2237. echo json_encode($_SESSION['return']);
  2238. }
  2239. else {
  2240. echo json_encode(array(
  2241. 'type' => 'error',
  2242. 'msg' => 'Edit failed'
  2243. ));
  2244. }
  2245. exit();
  2246. }
  2247. else {
  2248. if (isset($_SESSION['return'])) {
  2249. echo json_encode($_SESSION['return']);
  2250. }
  2251. else {
  2252. echo json_encode(array(
  2253. 'type' => 'success',
  2254. 'msg' => 'Task completed'
  2255. ));
  2256. }
  2257. }
  2258. }
  2259. else {
  2260. echo json_encode(array(
  2261. 'type' => 'error',
  2262. 'msg' => 'Incomplete post data'
  2263. ));
  2264. }
  2265. }
  2266. else {
  2267. echo json_encode(array(
  2268. 'type' => 'error',
  2269. 'msg' => 'Incomplete post data'
  2270. ));
  2271. }
  2272. break;
  2273. case "resource":
  2274. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2275. $items = (array)json_decode($_POST['items'], true);
  2276. $attr = (array)json_decode($_POST['attr'], true);
  2277. $postarray = array_merge(array('name' => $items), $attr);
  2278. if (is_array($postarray['name'])) {
  2279. if (mailbox('edit', 'resource', $postarray) === false) {
  2280. if (isset($_SESSION['return'])) {
  2281. echo json_encode($_SESSION['return']);
  2282. }
  2283. else {
  2284. echo json_encode(array(
  2285. 'type' => 'error',
  2286. 'msg' => 'Edit failed'
  2287. ));
  2288. }
  2289. exit();
  2290. }
  2291. else {
  2292. if (isset($_SESSION['return'])) {
  2293. echo json_encode($_SESSION['return']);
  2294. }
  2295. else {
  2296. echo json_encode(array(
  2297. 'type' => 'success',
  2298. 'msg' => 'Task completed'
  2299. ));
  2300. }
  2301. }
  2302. }
  2303. else {
  2304. echo json_encode(array(
  2305. 'type' => 'error',
  2306. 'msg' => 'Incomplete post data'
  2307. ));
  2308. }
  2309. }
  2310. else {
  2311. echo json_encode(array(
  2312. 'type' => 'error',
  2313. 'msg' => 'Incomplete post data'
  2314. ));
  2315. }
  2316. break;
  2317. case "domain":
  2318. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2319. $items = (array)json_decode($_POST['items'], true);
  2320. $attr = (array)json_decode($_POST['attr'], true);
  2321. $postarray = array_merge(array('domain' => $items), $attr);
  2322. if (is_array($postarray['domain'])) {
  2323. if (mailbox('edit', 'domain', $postarray) === false) {
  2324. if (isset($_SESSION['return'])) {
  2325. echo json_encode($_SESSION['return']);
  2326. }
  2327. else {
  2328. echo json_encode(array(
  2329. 'type' => 'error',
  2330. 'msg' => 'Edit failed'
  2331. ));
  2332. }
  2333. exit();
  2334. }
  2335. else {
  2336. if (isset($_SESSION['return'])) {
  2337. echo json_encode($_SESSION['return']);
  2338. }
  2339. else {
  2340. echo json_encode(array(
  2341. 'type' => 'success',
  2342. 'msg' => 'Task completed'
  2343. ));
  2344. }
  2345. }
  2346. }
  2347. else {
  2348. echo json_encode(array(
  2349. 'type' => 'error',
  2350. 'msg' => 'Incomplete post data'
  2351. ));
  2352. }
  2353. }
  2354. else {
  2355. echo json_encode(array(
  2356. 'type' => 'error',
  2357. 'msg' => 'Incomplete post data'
  2358. ));
  2359. }
  2360. break;
  2361. case "ratelimit":
  2362. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2363. $items = (array)json_decode($_POST['items'], true);
  2364. $attr = (array)json_decode($_POST['attr'], true);
  2365. $postarray = array_merge(array('object' => $items), $attr);
  2366. if (is_array($postarray['object'])) {
  2367. if (mailbox('edit', 'ratelimit', $postarray) === false) {
  2368. if (isset($_SESSION['return'])) {
  2369. echo json_encode($_SESSION['return']);
  2370. }
  2371. else {
  2372. echo json_encode(array(
  2373. 'type' => 'error',
  2374. 'msg' => 'Edit failed'
  2375. ));
  2376. }
  2377. exit();
  2378. }
  2379. else {
  2380. if (isset($_SESSION['return'])) {
  2381. echo json_encode($_SESSION['return']);
  2382. }
  2383. else {
  2384. echo json_encode(array(
  2385. 'type' => 'success',
  2386. 'msg' => 'Task completed'
  2387. ));
  2388. }
  2389. }
  2390. }
  2391. else {
  2392. echo json_encode(array(
  2393. 'type' => 'error',
  2394. 'msg' => 'Incomplete post data'
  2395. ));
  2396. }
  2397. }
  2398. else {
  2399. echo json_encode(array(
  2400. 'type' => 'error',
  2401. 'msg' => 'Incomplete post data'
  2402. ));
  2403. }
  2404. break;
  2405. case "alias-domain":
  2406. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2407. $items = (array)json_decode($_POST['items'], true);
  2408. $attr = (array)json_decode($_POST['attr'], true);
  2409. $postarray = array_merge(array('alias_domain' => $items), $attr);
  2410. if (is_array($postarray['alias_domain'])) {
  2411. if (mailbox('edit', 'alias_domain', $postarray) === false) {
  2412. if (isset($_SESSION['return'])) {
  2413. echo json_encode($_SESSION['return']);
  2414. }
  2415. else {
  2416. echo json_encode(array(
  2417. 'type' => 'error',
  2418. 'msg' => 'Edit failed'
  2419. ));
  2420. }
  2421. exit();
  2422. }
  2423. else {
  2424. if (isset($_SESSION['return'])) {
  2425. echo json_encode($_SESSION['return']);
  2426. }
  2427. else {
  2428. echo json_encode(array(
  2429. 'type' => 'success',
  2430. 'msg' => 'Task completed'
  2431. ));
  2432. }
  2433. }
  2434. }
  2435. else {
  2436. echo json_encode(array(
  2437. 'type' => 'error',
  2438. 'msg' => 'Incomplete post data'
  2439. ));
  2440. }
  2441. }
  2442. else {
  2443. echo json_encode(array(
  2444. 'type' => 'error',
  2445. 'msg' => 'Incomplete post data'
  2446. ));
  2447. }
  2448. break;
  2449. case "spam-score":
  2450. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2451. $items = (array)json_decode($_POST['items'], true);
  2452. $attr = (array)json_decode($_POST['attr'], true);
  2453. $postarray = array_merge(array('username' => $items), $attr);
  2454. if (is_array($postarray['username'])) {
  2455. if (mailbox('edit', 'spam_score', $postarray) === false) {
  2456. if (isset($_SESSION['return'])) {
  2457. echo json_encode($_SESSION['return']);
  2458. }
  2459. else {
  2460. echo json_encode(array(
  2461. 'type' => 'error',
  2462. 'msg' => 'Edit failed'
  2463. ));
  2464. }
  2465. exit();
  2466. }
  2467. else {
  2468. if (isset($_SESSION['return'])) {
  2469. echo json_encode($_SESSION['return']);
  2470. }
  2471. else {
  2472. echo json_encode(array(
  2473. 'type' => 'success',
  2474. 'msg' => 'Task completed'
  2475. ));
  2476. }
  2477. }
  2478. }
  2479. else {
  2480. echo json_encode(array(
  2481. 'type' => 'error',
  2482. 'msg' => 'Incomplete post data'
  2483. ));
  2484. }
  2485. }
  2486. else {
  2487. echo json_encode(array(
  2488. 'type' => 'error',
  2489. 'msg' => 'Incomplete post data'
  2490. ));
  2491. }
  2492. break;
  2493. case "domain-admin":
  2494. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2495. $items = (array)json_decode($_POST['items'], true);
  2496. $attr = (array)json_decode($_POST['attr'], true);
  2497. $postarray = array_merge(array('username' => $items), $attr);
  2498. if (is_array($postarray['username'])) {
  2499. if (domain_admin('edit', $postarray) === false) {
  2500. if (isset($_SESSION['return'])) {
  2501. echo json_encode($_SESSION['return']);
  2502. }
  2503. else {
  2504. echo json_encode(array(
  2505. 'type' => 'error',
  2506. 'msg' => 'Edit failed'
  2507. ));
  2508. }
  2509. exit();
  2510. }
  2511. else {
  2512. if (isset($_SESSION['return'])) {
  2513. echo json_encode($_SESSION['return']);
  2514. }
  2515. else {
  2516. echo json_encode(array(
  2517. 'type' => 'success',
  2518. 'msg' => 'Task completed'
  2519. ));
  2520. }
  2521. }
  2522. }
  2523. else {
  2524. echo json_encode(array(
  2525. 'type' => 'error',
  2526. 'msg' => 'Incomplete post data'
  2527. ));
  2528. }
  2529. }
  2530. else {
  2531. echo json_encode(array(
  2532. 'type' => 'error',
  2533. 'msg' => 'Incomplete post data'
  2534. ));
  2535. }
  2536. break;
  2537. case "fwdhost":
  2538. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2539. $items = (array)json_decode($_POST['items'], true);
  2540. $attr = (array)json_decode($_POST['attr'], true);
  2541. $postarray = array_merge(array('fwdhost' => $items), $attr);
  2542. if (is_array($postarray['fwdhost'])) {
  2543. if (fwdhost('edit', $postarray) === false) {
  2544. if (isset($_SESSION['return'])) {
  2545. echo json_encode($_SESSION['return']);
  2546. }
  2547. else {
  2548. echo json_encode(array(
  2549. 'type' => 'error',
  2550. 'msg' => 'Edit failed'
  2551. ));
  2552. }
  2553. exit();
  2554. }
  2555. else {
  2556. if (isset($_SESSION['return'])) {
  2557. echo json_encode($_SESSION['return']);
  2558. }
  2559. else {
  2560. echo json_encode(array(
  2561. 'type' => 'success',
  2562. 'msg' => 'Task completed'
  2563. ));
  2564. }
  2565. }
  2566. }
  2567. else {
  2568. echo json_encode(array(
  2569. 'type' => 'error',
  2570. 'msg' => 'Incomplete post data'
  2571. ));
  2572. }
  2573. }
  2574. else {
  2575. echo json_encode(array(
  2576. 'type' => 'error',
  2577. 'msg' => 'Incomplete post data'
  2578. ));
  2579. }
  2580. break;
  2581. case "fail2ban":
  2582. // No items
  2583. if (isset($_POST['attr'])) {
  2584. $attr = (array)json_decode($_POST['attr'], true);
  2585. if (fail2ban('edit', $attr) === false) {
  2586. if (isset($_SESSION['return'])) {
  2587. echo json_encode($_SESSION['return']);
  2588. }
  2589. else {
  2590. echo json_encode(array(
  2591. 'type' => 'error',
  2592. 'msg' => 'Edit failed'
  2593. ));
  2594. }
  2595. exit();
  2596. }
  2597. else {
  2598. if (isset($_SESSION['return'])) {
  2599. echo json_encode($_SESSION['return']);
  2600. }
  2601. else {
  2602. echo json_encode(array(
  2603. 'type' => 'success',
  2604. 'msg' => 'Task completed'
  2605. ));
  2606. }
  2607. }
  2608. }
  2609. else {
  2610. echo json_encode(array(
  2611. 'type' => 'error',
  2612. 'msg' => 'Incomplete post data'
  2613. ));
  2614. }
  2615. break;
  2616. case "self":
  2617. // No items, logged-in user, users and domain admins
  2618. if ($_SESSION['mailcow_cc_role'] == "domainadmin") {
  2619. if (isset($_POST['attr'])) {
  2620. $attr = (array)json_decode($_POST['attr'], true);
  2621. if (domain_admin('edit', $attr) === false) {
  2622. if (isset($_SESSION['return'])) {
  2623. echo json_encode($_SESSION['return']);
  2624. }
  2625. else {
  2626. echo json_encode(array(
  2627. 'type' => 'error',
  2628. 'msg' => 'Edit failed'
  2629. ));
  2630. }
  2631. exit();
  2632. }
  2633. else {
  2634. if (isset($_SESSION['return'])) {
  2635. echo json_encode($_SESSION['return']);
  2636. }
  2637. else {
  2638. echo json_encode(array(
  2639. 'type' => 'success',
  2640. 'msg' => 'Task completed'
  2641. ));
  2642. }
  2643. }
  2644. }
  2645. else {
  2646. echo json_encode(array(
  2647. 'type' => 'error',
  2648. 'msg' => 'Incomplete post data'
  2649. ));
  2650. }
  2651. }
  2652. elseif ($_SESSION['mailcow_cc_role'] == "user") {
  2653. if (isset($_POST['attr'])) {
  2654. $attr = (array)json_decode($_POST['attr'], true);
  2655. if (edit_user_account($attr) === false) {
  2656. if (isset($_SESSION['return'])) {
  2657. echo json_encode($_SESSION['return']);
  2658. }
  2659. else {
  2660. echo json_encode(array(
  2661. 'type' => 'error',
  2662. 'msg' => 'Edit failed'
  2663. ));
  2664. }
  2665. exit();
  2666. }
  2667. else {
  2668. if (isset($_SESSION['return'])) {
  2669. echo json_encode($_SESSION['return']);
  2670. }
  2671. else {
  2672. echo json_encode(array(
  2673. 'type' => 'success',
  2674. 'msg' => 'Task completed'
  2675. ));
  2676. }
  2677. }
  2678. }
  2679. else {
  2680. echo json_encode(array(
  2681. 'type' => 'error',
  2682. 'msg' => 'Incomplete post data'
  2683. ));
  2684. }
  2685. }
  2686. elseif ($_SESSION['mailcow_cc_role'] == "admin") {
  2687. if (isset($_POST['attr'])) {
  2688. $attr = (array)json_decode($_POST['attr'], true);
  2689. if (edit_admin_account($attr) === false) {
  2690. if (isset($_SESSION['return'])) {
  2691. echo json_encode($_SESSION['return']);
  2692. }
  2693. else {
  2694. echo json_encode(array(
  2695. 'type' => 'error',
  2696. 'msg' => 'Edit failed'
  2697. ));
  2698. }
  2699. exit();
  2700. }
  2701. else {
  2702. if (isset($_SESSION['return'])) {
  2703. echo json_encode($_SESSION['return']);
  2704. }
  2705. else {
  2706. echo json_encode(array(
  2707. 'type' => 'success',
  2708. 'msg' => 'Task completed'
  2709. ));
  2710. }
  2711. }
  2712. }
  2713. else {
  2714. echo json_encode(array(
  2715. 'type' => 'error',
  2716. 'msg' => 'Incomplete post data'
  2717. ));
  2718. }
  2719. }
  2720. break;
  2721. }
  2722. break;
  2723. }
  2724. }
  2725. }