json_api.php 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769
  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 $_SERVER['DOCUMENT_ROOT'] . '/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. case "syncjob":
  489. if (isset($_POST['attr'])) {
  490. $attr = (array)json_decode($_POST['attr'], true);
  491. if (mailbox('add', 'syncjob', $attr) === false) {
  492. if (isset($_SESSION['return'])) {
  493. echo json_encode($_SESSION['return']);
  494. }
  495. else {
  496. echo json_encode(array(
  497. 'type' => 'error',
  498. 'msg' => 'Cannot add item'
  499. ));
  500. }
  501. }
  502. else {
  503. if (isset($_SESSION['return'])) {
  504. echo json_encode($_SESSION['return']);
  505. }
  506. else {
  507. echo json_encode(array(
  508. 'type' => 'success',
  509. 'msg' => 'Task completed'
  510. ));
  511. }
  512. }
  513. }
  514. else {
  515. echo json_encode(array(
  516. 'type' => 'error',
  517. 'msg' => 'Cannot find attributes in post data'
  518. ));
  519. }
  520. break;
  521. }
  522. break;
  523. case "get":
  524. switch ($category) {
  525. case "rspamd":
  526. switch ($object) {
  527. case "stat":
  528. $data = file_get_contents('http://rspamd-mailcow:11334/stat');
  529. if (!empty($data)) {
  530. echo $data;
  531. }
  532. elseif (!isset($data) || empty($data)) {
  533. echo '{}';
  534. }
  535. break;
  536. case "graph":
  537. switch ($extra) {
  538. case "hourly":
  539. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=hourly');
  540. if (!empty($data)) {
  541. $data_array = json_decode($data, true);
  542. $rejected['label'] = "reject";
  543. foreach ($data_array[0] as $dataset) {
  544. $rejected['data'][] = $dataset;
  545. }
  546. $temp_reject['label'] = "temp_reject";
  547. foreach ($data_array[1] as $dataset) {
  548. $temp_reject['data'][] = $dataset;
  549. }
  550. $add_header['label'] = "add_header";
  551. foreach ($data_array[2] as $dataset) {
  552. $add_header['data'][] = $dataset;
  553. }
  554. $prob_spam['label'] = "prob_spam";
  555. foreach ($data_array[3] as $dataset) {
  556. $prob_spam['data'][] = $dataset;
  557. }
  558. $greylist['label'] = "greylist";
  559. foreach ($data_array[4] as $dataset) {
  560. $greylist['data'][] = $dataset;
  561. }
  562. $clean['label'] = "clean";
  563. $clean['pointStyle'] = "cross";
  564. foreach ($data_array[5] as $dataset) {
  565. $clean['data'][] = $dataset;
  566. }
  567. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  568. }
  569. elseif (!isset($data) || empty($data)) {
  570. echo '{}';
  571. }
  572. break;
  573. case "daily":
  574. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=daily');
  575. if (!empty($data)) {
  576. $data_array = json_decode($data, true);
  577. $rejected['label'] = "reject";
  578. foreach ($data_array[0] as $dataset) {
  579. $rejected['data'][] = $dataset;
  580. }
  581. $temp_reject['label'] = "temp_reject";
  582. foreach ($data_array[1] as $dataset) {
  583. $temp_reject['data'][] = $dataset;
  584. }
  585. $add_header['label'] = "add_header";
  586. foreach ($data_array[2] as $dataset) {
  587. $add_header['data'][] = $dataset;
  588. }
  589. $prob_spam['label'] = "prob_spam";
  590. foreach ($data_array[3] as $dataset) {
  591. $prob_spam['data'][] = $dataset;
  592. }
  593. $greylist['label'] = "greylist";
  594. foreach ($data_array[4] as $dataset) {
  595. $greylist['data'][] = $dataset;
  596. }
  597. $clean['label'] = "clean";
  598. $clean['pointStyle'] = "cross";
  599. foreach ($data_array[5] as $dataset) {
  600. $clean['data'][] = $dataset;
  601. }
  602. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  603. }
  604. elseif (!isset($data) || empty($data)) {
  605. echo '{}';
  606. }
  607. break;
  608. case "weekly":
  609. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=weekly');
  610. if (!empty($data)) {
  611. $data_array = json_decode($data, true);
  612. $rejected['label'] = "reject";
  613. foreach ($data_array[0] as $dataset) {
  614. $rejected['data'][] = $dataset;
  615. }
  616. $temp_reject['label'] = "temp_reject";
  617. foreach ($data_array[1] as $dataset) {
  618. $temp_reject['data'][] = $dataset;
  619. }
  620. $add_header['label'] = "add_header";
  621. foreach ($data_array[2] as $dataset) {
  622. $add_header['data'][] = $dataset;
  623. }
  624. $prob_spam['label'] = "prob_spam";
  625. foreach ($data_array[3] as $dataset) {
  626. $prob_spam['data'][] = $dataset;
  627. }
  628. $greylist['label'] = "greylist";
  629. foreach ($data_array[4] as $dataset) {
  630. $greylist['data'][] = $dataset;
  631. }
  632. $clean['label'] = "clean";
  633. $clean['pointStyle'] = "cross";
  634. foreach ($data_array[5] as $dataset) {
  635. $clean['data'][] = $dataset;
  636. }
  637. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  638. }
  639. elseif (!isset($data) || empty($data)) {
  640. echo '{}';
  641. }
  642. break;
  643. case "monthly":
  644. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=monthly');
  645. if (!empty($data)) {
  646. $data_array = json_decode($data, true);
  647. $rejected['label'] = "reject";
  648. foreach ($data_array[0] as $dataset) {
  649. $rejected['data'][] = $dataset;
  650. }
  651. $temp_reject['label'] = "temp_reject";
  652. foreach ($data_array[1] as $dataset) {
  653. $temp_reject['data'][] = $dataset;
  654. }
  655. $add_header['label'] = "add_header";
  656. foreach ($data_array[2] as $dataset) {
  657. $add_header['data'][] = $dataset;
  658. }
  659. $prob_spam['label'] = "prob_spam";
  660. foreach ($data_array[3] as $dataset) {
  661. $prob_spam['data'][] = $dataset;
  662. }
  663. $greylist['label'] = "greylist";
  664. foreach ($data_array[4] as $dataset) {
  665. $greylist['data'][] = $dataset;
  666. }
  667. $clean['label'] = "clean";
  668. $clean['pointStyle'] = "cross";
  669. foreach ($data_array[5] as $dataset) {
  670. $clean['data'][] = $dataset;
  671. }
  672. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  673. }
  674. elseif (!isset($data) || empty($data)) {
  675. echo '{}';
  676. }
  677. break;
  678. }
  679. break;
  680. }
  681. break;
  682. case "domain":
  683. switch ($object) {
  684. case "all":
  685. $domains = mailbox('get', 'domains');
  686. if (!empty($domains)) {
  687. foreach ($domains as $domain) {
  688. if ($details = mailbox('get', 'domain_details', $domain)) {
  689. $data[] = $details;
  690. }
  691. else {
  692. continue;
  693. }
  694. }
  695. if (!isset($data) || empty($data)) {
  696. echo '{}';
  697. }
  698. else {
  699. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  700. }
  701. }
  702. else {
  703. echo '{}';
  704. }
  705. break;
  706. default:
  707. $data = mailbox('get', 'domain_details', $object);
  708. if (!isset($data) || empty($data)) {
  709. echo '{}';
  710. }
  711. else {
  712. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  713. }
  714. break;
  715. }
  716. break;
  717. case "relayhost":
  718. switch ($object) {
  719. case "all":
  720. $relayhosts = relayhost('get');
  721. if (!empty($relayhosts)) {
  722. foreach ($relayhosts as $relayhost) {
  723. if ($details = relayhost('details', $relayhost['id'])) {
  724. $data[] = $details;
  725. }
  726. else {
  727. continue;
  728. }
  729. }
  730. if (!isset($data) || empty($data)) {
  731. echo '{}';
  732. }
  733. else {
  734. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  735. }
  736. }
  737. else {
  738. echo '{}';
  739. }
  740. break;
  741. default:
  742. $data = relayhost('details', $object);
  743. if (!isset($data) || empty($data)) {
  744. echo '{}';
  745. }
  746. else {
  747. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  748. }
  749. break;
  750. }
  751. break;
  752. case "logs":
  753. switch ($object) {
  754. case "dovecot":
  755. // 0 is first record, so empty is fine
  756. if (isset($extra)) {
  757. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  758. $logs = get_logs('dovecot-mailcow', $extra);
  759. }
  760. else {
  761. $logs = get_logs('dovecot-mailcow');
  762. }
  763. if (isset($logs) && !empty($logs)) {
  764. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  765. }
  766. else {
  767. echo '{}';
  768. }
  769. break;
  770. case "fail2ban":
  771. // 0 is first record, so empty is fine
  772. if (isset($extra)) {
  773. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  774. $logs = get_logs('fail2ban-mailcow', $extra);
  775. }
  776. else {
  777. $logs = get_logs('fail2ban-mailcow');
  778. }
  779. if (isset($logs) && !empty($logs)) {
  780. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  781. }
  782. else {
  783. echo '{}';
  784. }
  785. break;
  786. case "postfix":
  787. // 0 is first record, so empty is fine
  788. if (isset($extra)) {
  789. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  790. $logs = get_logs('postfix-mailcow', $extra);
  791. }
  792. else {
  793. $logs = get_logs('postfix-mailcow');
  794. }
  795. if (isset($logs) && !empty($logs)) {
  796. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  797. }
  798. else {
  799. echo '{}';
  800. }
  801. break;
  802. case "autodiscover":
  803. // 0 is first record, so empty is fine
  804. if (isset($extra)) {
  805. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  806. $logs = get_logs('autodiscover-mailcow', $extra);
  807. }
  808. else {
  809. $logs = get_logs('autodiscover-mailcow');
  810. }
  811. if (isset($logs) && !empty($logs)) {
  812. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  813. }
  814. else {
  815. echo '{}';
  816. }
  817. break;
  818. case "sogo":
  819. // 0 is first record, so empty is fine
  820. if (isset($extra)) {
  821. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  822. $logs = get_logs('sogo-mailcow', $extra);
  823. }
  824. else {
  825. $logs = get_logs('sogo-mailcow');
  826. }
  827. if (isset($logs) && !empty($logs)) {
  828. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  829. }
  830. else {
  831. echo '{}';
  832. }
  833. break;
  834. case "rspamd-history":
  835. // 0 is first record, so empty is fine
  836. if (isset($extra)) {
  837. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  838. $logs = get_logs('rspamd-history', $extra);
  839. }
  840. else {
  841. $logs = get_logs('rspamd-history');
  842. }
  843. if (isset($logs) && !empty($logs)) {
  844. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  845. }
  846. else {
  847. echo '{}';
  848. }
  849. break;
  850. }
  851. break;
  852. case "mailbox":
  853. switch ($object) {
  854. case "all":
  855. $domains = mailbox('get', 'domains');
  856. if (!empty($domains)) {
  857. foreach ($domains as $domain) {
  858. $mailboxes = mailbox('get', 'mailboxes', $domain);
  859. if (!empty($mailboxes)) {
  860. foreach ($mailboxes as $mailbox) {
  861. if ($details = mailbox('get', 'mailbox_details', $mailbox)) {
  862. $data[] = $details;
  863. }
  864. else {
  865. continue;
  866. }
  867. }
  868. }
  869. }
  870. if (!isset($data) || empty($data)) {
  871. echo '{}';
  872. }
  873. else {
  874. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  875. }
  876. }
  877. else {
  878. echo '{}';
  879. }
  880. break;
  881. default:
  882. $data = mailbox('get', 'mailbox_details', $object);
  883. if (!isset($data) || empty($data)) {
  884. echo '{}';
  885. }
  886. else {
  887. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  888. }
  889. break;
  890. }
  891. break;
  892. case "syncjobs":
  893. switch ($object) {
  894. case "all":
  895. $domains = mailbox('get', 'domains');
  896. if (!empty($domains)) {
  897. foreach ($domains as $domain) {
  898. $mailboxes = mailbox('get', 'mailboxes', $domain);
  899. if (!empty($mailboxes)) {
  900. foreach ($mailboxes as $mailbox) {
  901. $syncjobs = mailbox('get', 'syncjobs', $mailbox);
  902. if (!empty($syncjobs)) {
  903. foreach ($syncjobs as $syncjob) {
  904. if (isset($extra)) {
  905. $details = mailbox('get', 'syncjob_details', $syncjob, explode(',', $extra));
  906. }
  907. else {
  908. $details = mailbox('get', 'syncjob_details', $syncjob);
  909. }
  910. if ($details) {
  911. $data[] = $details;
  912. }
  913. else {
  914. continue;
  915. }
  916. }
  917. }
  918. }
  919. }
  920. }
  921. if (!isset($data) || empty($data)) {
  922. echo '{}';
  923. }
  924. else {
  925. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  926. }
  927. }
  928. else {
  929. echo '{}';
  930. }
  931. break;
  932. default:
  933. $syncjobs = mailbox('get', 'syncjobs', $object);
  934. if (!empty($syncjobs)) {
  935. foreach ($syncjobs as $syncjob) {
  936. if (isset($extra)) {
  937. $details = mailbox('get', 'syncjob_details', $syncjob, explode(',', $extra));
  938. }
  939. else {
  940. $details = mailbox('get', 'syncjob_details', $syncjob);
  941. }
  942. if ($details) {
  943. $data[] = $details;
  944. }
  945. else {
  946. continue;
  947. }
  948. }
  949. }
  950. if (!isset($data) || empty($data)) {
  951. echo '{}';
  952. }
  953. else {
  954. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  955. }
  956. break;
  957. }
  958. break;
  959. case "active-user-sieve":
  960. if (isset($object)) {
  961. $sieve_filter = mailbox('get', 'active_user_sieve', $object);
  962. if (!empty($sieve_filter)) {
  963. $data[] = $sieve_filter;
  964. }
  965. }
  966. if (!isset($data) || empty($data)) {
  967. echo '{}';
  968. }
  969. else {
  970. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  971. }
  972. break;
  973. case "filters":
  974. switch ($object) {
  975. case "all":
  976. $domains = mailbox('get', 'domains');
  977. if (!empty($domains)) {
  978. foreach ($domains as $domain) {
  979. $mailboxes = mailbox('get', 'mailboxes', $domain);
  980. if (!empty($mailboxes)) {
  981. foreach ($mailboxes as $mailbox) {
  982. $filters = mailbox('get', 'filters', $mailbox);
  983. if (!empty($filters)) {
  984. foreach ($filters as $filter) {
  985. if ($details = mailbox('get', 'filter_details', $filter)) {
  986. $data[] = $details;
  987. }
  988. else {
  989. continue;
  990. }
  991. }
  992. }
  993. }
  994. }
  995. }
  996. if (!isset($data) || empty($data)) {
  997. echo '{}';
  998. }
  999. else {
  1000. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1001. }
  1002. }
  1003. else {
  1004. echo '{}';
  1005. }
  1006. break;
  1007. default:
  1008. $filters = mailbox('get', 'filters', $object);
  1009. if (!empty($filters)) {
  1010. foreach ($filters as $filter) {
  1011. if ($details = mailbox('get', 'filter_details', $filter)) {
  1012. $data[] = $details;
  1013. }
  1014. else {
  1015. continue;
  1016. }
  1017. }
  1018. }
  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 "policy_wl_mailbox":
  1029. switch ($object) {
  1030. default:
  1031. $data = policy('get', 'mailbox', $object)['whitelist'];
  1032. if (!isset($data) || empty($data)) {
  1033. echo '{}';
  1034. }
  1035. else {
  1036. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1037. }
  1038. break;
  1039. }
  1040. break;
  1041. case "policy_bl_mailbox":
  1042. switch ($object) {
  1043. default:
  1044. $data = policy('get', 'mailbox', $object)['blacklist'];
  1045. if (!isset($data) || empty($data)) {
  1046. echo '{}';
  1047. }
  1048. else {
  1049. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1050. }
  1051. break;
  1052. }
  1053. break;
  1054. case "policy_wl_domain":
  1055. switch ($object) {
  1056. default:
  1057. $data = policy('get', 'domain', $object)['whitelist'];
  1058. if (!isset($data) || empty($data)) {
  1059. echo '{}';
  1060. }
  1061. else {
  1062. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1063. }
  1064. break;
  1065. }
  1066. break;
  1067. case "policy_bl_domain":
  1068. switch ($object) {
  1069. default:
  1070. $data = policy('get', 'domain', $object)['blacklist'];
  1071. if (!isset($data) || empty($data)) {
  1072. echo '{}';
  1073. }
  1074. else {
  1075. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1076. }
  1077. break;
  1078. }
  1079. break;
  1080. case "time_limited_aliases":
  1081. switch ($object) {
  1082. default:
  1083. $data = mailbox('get', 'time_limited_aliases', $object);
  1084. if (!isset($data) || empty($data)) {
  1085. echo '{}';
  1086. }
  1087. else {
  1088. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1089. }
  1090. break;
  1091. }
  1092. break;
  1093. case "resource":
  1094. switch ($object) {
  1095. case "all":
  1096. $domains = mailbox('get', 'domains');
  1097. if (!empty($domains)) {
  1098. foreach ($domains as $domain) {
  1099. $resources = mailbox('get', 'resources', $domain);
  1100. if (!empty($resources)) {
  1101. foreach ($resources as $resource) {
  1102. if ($details = mailbox('get', 'resource_details', $resource)) {
  1103. $data[] = $details;
  1104. }
  1105. else {
  1106. continue;
  1107. }
  1108. }
  1109. }
  1110. }
  1111. if (!isset($data) || empty($data)) {
  1112. echo '{}';
  1113. }
  1114. else {
  1115. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1116. }
  1117. }
  1118. else {
  1119. echo '{}';
  1120. }
  1121. break;
  1122. default:
  1123. $data = mailbox('get', 'resource_details', $object);
  1124. if (!isset($data) || empty($data)) {
  1125. echo '{}';
  1126. }
  1127. else {
  1128. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1129. }
  1130. break;
  1131. }
  1132. break;
  1133. case "fwdhost":
  1134. switch ($object) {
  1135. case "all":
  1136. $data = fwdhost('get');
  1137. if (!isset($data) || empty($data)) {
  1138. echo '{}';
  1139. }
  1140. else {
  1141. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1142. }
  1143. break;
  1144. default:
  1145. $data = fwdhost('details', $object);
  1146. if (!isset($data) || empty($data)) {
  1147. echo '{}';
  1148. }
  1149. else {
  1150. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1151. }
  1152. break;
  1153. }
  1154. break;
  1155. case "alias-domain":
  1156. switch ($object) {
  1157. case "all":
  1158. $alias_domains = mailbox('get', 'alias_domains');
  1159. if (!empty($alias_domains)) {
  1160. foreach ($alias_domains as $alias_domain) {
  1161. if ($details = mailbox('get', 'alias_domain_details', $alias_domain)) {
  1162. $data[] = $details;
  1163. }
  1164. else {
  1165. continue;
  1166. }
  1167. }
  1168. }
  1169. if (!isset($data) || empty($data)) {
  1170. echo '{}';
  1171. }
  1172. else {
  1173. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1174. }
  1175. break;
  1176. default:
  1177. $data = mailbox('get', 'alias_domain_details', $object);
  1178. if (!isset($data) || empty($data)) {
  1179. echo '{}';
  1180. }
  1181. else {
  1182. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1183. }
  1184. break;
  1185. }
  1186. break;
  1187. case "alias":
  1188. switch ($object) {
  1189. case "all":
  1190. $domains = array_merge(mailbox('get', 'domains'),mailbox('get', 'alias_domains'));
  1191. if (!empty($domains)) {
  1192. foreach ($domains as $domain) {
  1193. $aliases = mailbox('get', 'aliases', $domain);
  1194. if (!empty($aliases)) {
  1195. foreach ($aliases as $alias) {
  1196. if ($details = mailbox('get', 'alias_details', $alias)) {
  1197. $data[] = $details;
  1198. }
  1199. else {
  1200. continue;
  1201. }
  1202. }
  1203. }
  1204. }
  1205. if (!isset($data) || empty($data)) {
  1206. echo '{}';
  1207. }
  1208. else {
  1209. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1210. }
  1211. }
  1212. else {
  1213. echo '{}';
  1214. }
  1215. break;
  1216. default:
  1217. $data = mailbox('get', 'alias_details', $object);
  1218. if (!isset($data) || empty($data)) {
  1219. echo '{}';
  1220. }
  1221. else {
  1222. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1223. }
  1224. break;
  1225. }
  1226. break;
  1227. case "domain-admin":
  1228. switch ($object) {
  1229. case "all":
  1230. $domain_admins = domain_admin('get');
  1231. if (!empty($domain_admins)) {
  1232. foreach ($domain_admins as $domain_admin) {
  1233. if ($details = domain_admin('details', $domain_admin)) {
  1234. $data[] = $details;
  1235. }
  1236. else {
  1237. continue;
  1238. }
  1239. }
  1240. if (!isset($data) || empty($data)) {
  1241. echo '{}';
  1242. }
  1243. else {
  1244. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1245. }
  1246. }
  1247. else {
  1248. echo '{}';
  1249. }
  1250. break;
  1251. default:
  1252. $data = domain_admin('details', $object);
  1253. if (!isset($data) || empty($data)) {
  1254. echo '{}';
  1255. }
  1256. else {
  1257. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1258. }
  1259. break;
  1260. }
  1261. break;
  1262. case "u2f-registration":
  1263. header('Content-Type: application/javascript');
  1264. if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
  1265. $data = $u2f->getRegisterData(get_u2f_registrations($object));
  1266. list($req, $sigs) = $data;
  1267. $_SESSION['regReq'] = json_encode($req);
  1268. echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';';
  1269. }
  1270. else {
  1271. return;
  1272. }
  1273. break;
  1274. case "u2f-authentication":
  1275. header('Content-Type: application/javascript');
  1276. if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
  1277. $reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
  1278. $_SESSION['authReq'] = $reqs;
  1279. echo 'var req = ' . $reqs . ';';
  1280. }
  1281. else {
  1282. return;
  1283. }
  1284. break;
  1285. default:
  1286. echo '{}';
  1287. break;
  1288. }
  1289. break;
  1290. case "delete":
  1291. switch ($category) {
  1292. case "alias":
  1293. if (isset($_POST['items'])) {
  1294. $items = (array)json_decode($_POST['items'], true);
  1295. if (is_array($items)) {
  1296. if (mailbox('delete', 'alias', array('address' => $items)) === false) {
  1297. if (isset($_SESSION['return'])) {
  1298. echo json_encode($_SESSION['return']);
  1299. }
  1300. else {
  1301. echo json_encode(array(
  1302. 'type' => 'error',
  1303. 'msg' => 'Deletion of items/s failed'
  1304. ));
  1305. }
  1306. }
  1307. else {
  1308. if (isset($_SESSION['return'])) {
  1309. echo json_encode($_SESSION['return']);
  1310. }
  1311. else {
  1312. echo json_encode(array(
  1313. 'type' => 'success',
  1314. 'msg' => 'Task completed'
  1315. ));
  1316. }
  1317. }
  1318. }
  1319. else {
  1320. echo json_encode(array(
  1321. 'type' => 'error',
  1322. 'msg' => 'Cannot find address array in post data'
  1323. ));
  1324. }
  1325. }
  1326. else {
  1327. echo json_encode(array(
  1328. 'type' => 'error',
  1329. 'msg' => 'Cannot find items in post data'
  1330. ));
  1331. }
  1332. break;
  1333. case "relayhost":
  1334. if (isset($_POST['items'])) {
  1335. $items = (array)json_decode($_POST['items'], true);
  1336. if (is_array($items)) {
  1337. if (relayhost('delete', array('id' => $items)) === false) {
  1338. if (isset($_SESSION['return'])) {
  1339. echo json_encode($_SESSION['return']);
  1340. }
  1341. else {
  1342. echo json_encode(array(
  1343. 'type' => 'error',
  1344. 'msg' => 'Deletion of items/s failed'
  1345. ));
  1346. }
  1347. }
  1348. else {
  1349. if (isset($_SESSION['return'])) {
  1350. echo json_encode($_SESSION['return']);
  1351. }
  1352. else {
  1353. echo json_encode(array(
  1354. 'type' => 'success',
  1355. 'msg' => 'Task completed'
  1356. ));
  1357. }
  1358. }
  1359. }
  1360. else {
  1361. echo json_encode(array(
  1362. 'type' => 'error',
  1363. 'msg' => 'Cannot find id array in post data'
  1364. ));
  1365. }
  1366. }
  1367. else {
  1368. echo json_encode(array(
  1369. 'type' => 'error',
  1370. 'msg' => 'Cannot find items in post data'
  1371. ));
  1372. }
  1373. break;
  1374. case "syncjob":
  1375. if (isset($_POST['items'])) {
  1376. $items = (array)json_decode($_POST['items'], true);
  1377. if (is_array($items)) {
  1378. if (mailbox('delete', 'syncjob', array('id' => $items)) === false) {
  1379. if (isset($_SESSION['return'])) {
  1380. echo json_encode($_SESSION['return']);
  1381. }
  1382. else {
  1383. echo json_encode(array(
  1384. 'type' => 'error',
  1385. 'msg' => 'Deletion of items/s failed'
  1386. ));
  1387. }
  1388. }
  1389. else {
  1390. if (isset($_SESSION['return'])) {
  1391. echo json_encode($_SESSION['return']);
  1392. }
  1393. else {
  1394. echo json_encode(array(
  1395. 'type' => 'success',
  1396. 'msg' => 'Task completed'
  1397. ));
  1398. }
  1399. }
  1400. }
  1401. else {
  1402. echo json_encode(array(
  1403. 'type' => 'error',
  1404. 'msg' => 'Cannot find id array in post data'
  1405. ));
  1406. }
  1407. }
  1408. else {
  1409. echo json_encode(array(
  1410. 'type' => 'error',
  1411. 'msg' => 'Cannot find items in post data'
  1412. ));
  1413. }
  1414. break;
  1415. case "filter":
  1416. if (isset($_POST['items'])) {
  1417. $items = (array)json_decode($_POST['items'], true);
  1418. if (is_array($items)) {
  1419. if (mailbox('delete', 'filter', array('id' => $items)) === false) {
  1420. if (isset($_SESSION['return'])) {
  1421. echo json_encode($_SESSION['return']);
  1422. }
  1423. else {
  1424. echo json_encode(array(
  1425. 'type' => 'error',
  1426. 'msg' => 'Deletion of items/s failed'
  1427. ));
  1428. }
  1429. }
  1430. else {
  1431. if (isset($_SESSION['return'])) {
  1432. echo json_encode($_SESSION['return']);
  1433. }
  1434. else {
  1435. echo json_encode(array(
  1436. 'type' => 'success',
  1437. 'msg' => 'Task completed'
  1438. ));
  1439. }
  1440. }
  1441. }
  1442. else {
  1443. echo json_encode(array(
  1444. 'type' => 'error',
  1445. 'msg' => 'Cannot find id array in post data'
  1446. ));
  1447. }
  1448. }
  1449. else {
  1450. echo json_encode(array(
  1451. 'type' => 'error',
  1452. 'msg' => 'Cannot find items in post data'
  1453. ));
  1454. }
  1455. break;
  1456. case "fwdhost":
  1457. if (isset($_POST['items'])) {
  1458. $items = (array)json_decode($_POST['items'], true);
  1459. if (is_array($items)) {
  1460. if (fwdhost('delete', array('forwardinghost' => $items)) === false) {
  1461. if (isset($_SESSION['return'])) {
  1462. echo json_encode($_SESSION['return']);
  1463. }
  1464. else {
  1465. echo json_encode(array(
  1466. 'type' => 'error',
  1467. 'msg' => 'Deletion of items/s failed'
  1468. ));
  1469. }
  1470. }
  1471. else {
  1472. if (isset($_SESSION['return'])) {
  1473. echo json_encode($_SESSION['return']);
  1474. }
  1475. else {
  1476. echo json_encode(array(
  1477. 'type' => 'success',
  1478. 'msg' => 'Task completed'
  1479. ));
  1480. }
  1481. }
  1482. }
  1483. else {
  1484. echo json_encode(array(
  1485. 'type' => 'error',
  1486. 'msg' => 'Cannot find forwardinghost array in post data'
  1487. ));
  1488. }
  1489. }
  1490. else {
  1491. echo json_encode(array(
  1492. 'type' => 'error',
  1493. 'msg' => 'Cannot find items in post data'
  1494. ));
  1495. }
  1496. break;
  1497. case "dkim":
  1498. if (isset($_POST['items'])) {
  1499. $items = (array)json_decode($_POST['items'], true);
  1500. if (is_array($items)) {
  1501. if (dkim('delete', array('domains' => $items)) === false) {
  1502. if (isset($_SESSION['return'])) {
  1503. echo json_encode($_SESSION['return']);
  1504. }
  1505. else {
  1506. echo json_encode(array(
  1507. 'type' => 'error',
  1508. 'msg' => 'Deletion of items/s failed'
  1509. ));
  1510. }
  1511. }
  1512. else {
  1513. if (isset($_SESSION['return'])) {
  1514. echo json_encode($_SESSION['return']);
  1515. }
  1516. else {
  1517. echo json_encode(array(
  1518. 'type' => 'success',
  1519. 'msg' => 'Task completed'
  1520. ));
  1521. }
  1522. }
  1523. }
  1524. else {
  1525. echo json_encode(array(
  1526. 'type' => 'error',
  1527. 'msg' => 'Cannot find domains array in post data'
  1528. ));
  1529. }
  1530. }
  1531. else {
  1532. echo json_encode(array(
  1533. 'type' => 'error',
  1534. 'msg' => 'Cannot find items in post data'
  1535. ));
  1536. }
  1537. break;
  1538. case "domain":
  1539. if (isset($_POST['items'])) {
  1540. $items = (array)json_decode($_POST['items'], true);
  1541. if (is_array($items)) {
  1542. if (mailbox('delete', 'domain', array('domain' => $items)) === false) {
  1543. if (isset($_SESSION['return'])) {
  1544. echo json_encode($_SESSION['return']);
  1545. }
  1546. else {
  1547. echo json_encode(array(
  1548. 'type' => 'error',
  1549. 'msg' => 'Task failed'
  1550. ));
  1551. }
  1552. }
  1553. else {
  1554. if (isset($_SESSION['return'])) {
  1555. echo json_encode($_SESSION['return']);
  1556. }
  1557. else {
  1558. echo json_encode(array(
  1559. 'type' => 'success',
  1560. 'msg' => 'Task completed'
  1561. ));
  1562. }
  1563. }
  1564. }
  1565. else {
  1566. echo json_encode(array(
  1567. 'type' => 'error',
  1568. 'msg' => 'Cannot find domain array in post data'
  1569. ));
  1570. }
  1571. }
  1572. else {
  1573. echo json_encode(array(
  1574. 'type' => 'error',
  1575. 'msg' => 'Cannot find items in post data'
  1576. ));
  1577. }
  1578. break;
  1579. case "alias-domain":
  1580. if (isset($_POST['items'])) {
  1581. $items = (array)json_decode($_POST['items'], true);
  1582. if (is_array($items)) {
  1583. if (mailbox('delete', 'alias_domain', array('alias_domain' => $items)) === false) {
  1584. if (isset($_SESSION['return'])) {
  1585. echo json_encode($_SESSION['return']);
  1586. }
  1587. else {
  1588. echo json_encode(array(
  1589. 'type' => 'error',
  1590. 'msg' => 'Task failed'
  1591. ));
  1592. }
  1593. }
  1594. else {
  1595. if (isset($_SESSION['return'])) {
  1596. echo json_encode($_SESSION['return']);
  1597. }
  1598. else {
  1599. echo json_encode(array(
  1600. 'type' => 'success',
  1601. 'msg' => 'Task completed'
  1602. ));
  1603. }
  1604. }
  1605. }
  1606. else {
  1607. echo json_encode(array(
  1608. 'type' => 'error',
  1609. 'msg' => 'Cannot find alias_domain array in post data'
  1610. ));
  1611. }
  1612. }
  1613. else {
  1614. echo json_encode(array(
  1615. 'type' => 'error',
  1616. 'msg' => 'Cannot find items in post data'
  1617. ));
  1618. }
  1619. break;
  1620. case "mailbox":
  1621. if (isset($_POST['items'])) {
  1622. $items = (array)json_decode($_POST['items'], true);
  1623. if (is_array($items)) {
  1624. if (mailbox('delete', 'mailbox', array('username' => $items)) === false) {
  1625. if (isset($_SESSION['return'])) {
  1626. echo json_encode($_SESSION['return']);
  1627. }
  1628. else {
  1629. echo json_encode(array(
  1630. 'type' => 'error',
  1631. 'msg' => 'Task failed'
  1632. ));
  1633. }
  1634. }
  1635. else {
  1636. if (isset($_SESSION['return'])) {
  1637. echo json_encode($_SESSION['return']);
  1638. }
  1639. else {
  1640. echo json_encode(array(
  1641. 'type' => 'success',
  1642. 'msg' => 'Task completed'
  1643. ));
  1644. }
  1645. }
  1646. }
  1647. else {
  1648. echo json_encode(array(
  1649. 'type' => 'error',
  1650. 'msg' => 'Cannot find username array in post data'
  1651. ));
  1652. }
  1653. }
  1654. else {
  1655. echo json_encode(array(
  1656. 'type' => 'error',
  1657. 'msg' => 'Cannot find items in post data'
  1658. ));
  1659. }
  1660. break;
  1661. case "resource":
  1662. if (isset($_POST['items'])) {
  1663. $items = (array)json_decode($_POST['items'], true);
  1664. if (is_array($items)) {
  1665. if (mailbox('delete', 'resource', array('name' => $items)) === false) {
  1666. if (isset($_SESSION['return'])) {
  1667. echo json_encode($_SESSION['return']);
  1668. }
  1669. else {
  1670. echo json_encode(array(
  1671. 'type' => 'error',
  1672. 'msg' => 'Task failed'
  1673. ));
  1674. }
  1675. }
  1676. else {
  1677. if (isset($_SESSION['return'])) {
  1678. echo json_encode($_SESSION['return']);
  1679. }
  1680. else {
  1681. echo json_encode(array(
  1682. 'type' => 'success',
  1683. 'msg' => 'Task completed'
  1684. ));
  1685. }
  1686. }
  1687. }
  1688. else {
  1689. echo json_encode(array(
  1690. 'type' => 'error',
  1691. 'msg' => 'Cannot find name array in post data'
  1692. ));
  1693. }
  1694. }
  1695. else {
  1696. echo json_encode(array(
  1697. 'type' => 'error',
  1698. 'msg' => 'Cannot find items in post data'
  1699. ));
  1700. }
  1701. break;
  1702. case "mailbox-policy":
  1703. if (isset($_POST['items'])) {
  1704. $items = (array)json_decode($_POST['items'], true);
  1705. if (is_array($items)) {
  1706. if (policy('delete', 'mailbox', array('prefid' => $items)) === false) {
  1707. if (isset($_SESSION['return'])) {
  1708. echo json_encode($_SESSION['return']);
  1709. }
  1710. else {
  1711. echo json_encode(array(
  1712. 'type' => 'error',
  1713. 'msg' => 'Task failed'
  1714. ));
  1715. }
  1716. }
  1717. else {
  1718. if (isset($_SESSION['return'])) {
  1719. echo json_encode($_SESSION['return']);
  1720. }
  1721. else {
  1722. echo json_encode(array(
  1723. 'type' => 'success',
  1724. 'msg' => 'Task completed'
  1725. ));
  1726. }
  1727. }
  1728. }
  1729. else {
  1730. echo json_encode(array(
  1731. 'type' => 'error',
  1732. 'msg' => 'Cannot find name array in post data'
  1733. ));
  1734. }
  1735. }
  1736. else {
  1737. echo json_encode(array(
  1738. 'type' => 'error',
  1739. 'msg' => 'Cannot find items in post data'
  1740. ));
  1741. }
  1742. break;
  1743. case "domain-policy":
  1744. if (isset($_POST['items'])) {
  1745. $items = (array)json_decode($_POST['items'], true);
  1746. if (is_array($items)) {
  1747. if (policy('delete', 'domain', array('prefid' => $items)) === false) {
  1748. if (isset($_SESSION['return'])) {
  1749. echo json_encode($_SESSION['return']);
  1750. }
  1751. else {
  1752. echo json_encode(array(
  1753. 'type' => 'error',
  1754. 'msg' => 'Task failed'
  1755. ));
  1756. }
  1757. }
  1758. else {
  1759. if (isset($_SESSION['return'])) {
  1760. echo json_encode($_SESSION['return']);
  1761. }
  1762. else {
  1763. echo json_encode(array(
  1764. 'type' => 'success',
  1765. 'msg' => 'Task completed'
  1766. ));
  1767. }
  1768. }
  1769. }
  1770. else {
  1771. echo json_encode(array(
  1772. 'type' => 'error',
  1773. 'msg' => 'Cannot find name array in post data'
  1774. ));
  1775. }
  1776. }
  1777. else {
  1778. echo json_encode(array(
  1779. 'type' => 'error',
  1780. 'msg' => 'Cannot find items in post data'
  1781. ));
  1782. }
  1783. break;
  1784. case "time_limited_alias":
  1785. if (isset($_POST['items'])) {
  1786. $items = (array)json_decode($_POST['items'], true);
  1787. if (is_array($items)) {
  1788. if (mailbox('delete', 'time_limited_alias', array('address' => $items)) === false) {
  1789. if (isset($_SESSION['return'])) {
  1790. echo json_encode($_SESSION['return']);
  1791. }
  1792. else {
  1793. echo json_encode(array(
  1794. 'type' => 'error',
  1795. 'msg' => 'Task failed'
  1796. ));
  1797. }
  1798. }
  1799. else {
  1800. if (isset($_SESSION['return'])) {
  1801. echo json_encode($_SESSION['return']);
  1802. }
  1803. else {
  1804. echo json_encode(array(
  1805. 'type' => 'success',
  1806. 'msg' => 'Task completed'
  1807. ));
  1808. }
  1809. }
  1810. }
  1811. else {
  1812. echo json_encode(array(
  1813. 'type' => 'error',
  1814. 'msg' => 'Cannot find name array in post data'
  1815. ));
  1816. }
  1817. }
  1818. else {
  1819. echo json_encode(array(
  1820. 'type' => 'error',
  1821. 'msg' => 'Cannot find items in post data'
  1822. ));
  1823. }
  1824. break;
  1825. case "eas_cache":
  1826. if (isset($_POST['items'])) {
  1827. $items = (array)json_decode($_POST['items'], true);
  1828. if (is_array($items)) {
  1829. if (mailbox('delete', 'eas_cache', array('username' => $items)) === false) {
  1830. if (isset($_SESSION['return'])) {
  1831. echo json_encode($_SESSION['return']);
  1832. }
  1833. else {
  1834. echo json_encode(array(
  1835. 'type' => 'error',
  1836. 'msg' => 'Task failed'
  1837. ));
  1838. }
  1839. }
  1840. else {
  1841. if (isset($_SESSION['return'])) {
  1842. echo json_encode($_SESSION['return']);
  1843. }
  1844. else {
  1845. echo json_encode(array(
  1846. 'type' => 'success',
  1847. 'msg' => 'Task completed'
  1848. ));
  1849. }
  1850. }
  1851. }
  1852. else {
  1853. echo json_encode(array(
  1854. 'type' => 'error',
  1855. 'msg' => 'Cannot find name array in post data'
  1856. ));
  1857. }
  1858. }
  1859. else {
  1860. echo json_encode(array(
  1861. 'type' => 'error',
  1862. 'msg' => 'Cannot find items in post data'
  1863. ));
  1864. }
  1865. break;
  1866. case "domain-admin":
  1867. if (isset($_POST['items'])) {
  1868. $items = (array)json_decode($_POST['items'], true);
  1869. if (is_array($items)) {
  1870. if (domain_admin('delete', array('username' => $items)) === false) {
  1871. if (isset($_SESSION['return'])) {
  1872. echo json_encode($_SESSION['return']);
  1873. }
  1874. else {
  1875. echo json_encode(array(
  1876. 'type' => 'error',
  1877. 'msg' => 'Task failed'
  1878. ));
  1879. }
  1880. }
  1881. else {
  1882. if (isset($_SESSION['return'])) {
  1883. echo json_encode($_SESSION['return']);
  1884. }
  1885. else {
  1886. echo json_encode(array(
  1887. 'type' => 'success',
  1888. 'msg' => 'Task completed'
  1889. ));
  1890. }
  1891. }
  1892. }
  1893. else {
  1894. echo json_encode(array(
  1895. 'type' => 'error',
  1896. 'msg' => 'Cannot find name array in post data'
  1897. ));
  1898. }
  1899. }
  1900. else {
  1901. echo json_encode(array(
  1902. 'type' => 'error',
  1903. 'msg' => 'Cannot find items in post data'
  1904. ));
  1905. }
  1906. break;
  1907. }
  1908. break;
  1909. case "edit":
  1910. switch ($category) {
  1911. case "alias":
  1912. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1913. $items = (array)json_decode($_POST['items'], true);
  1914. $attr = (array)json_decode($_POST['attr'], true);
  1915. $postarray = array_merge(array('address' => $items), $attr);
  1916. if (is_array($postarray['address'])) {
  1917. if (mailbox('edit', 'alias', $postarray) === false) {
  1918. if (isset($_SESSION['return'])) {
  1919. echo json_encode($_SESSION['return']);
  1920. }
  1921. else {
  1922. echo json_encode(array(
  1923. 'type' => 'error',
  1924. 'msg' => 'Edit failed'
  1925. ));
  1926. }
  1927. exit();
  1928. }
  1929. else {
  1930. if (isset($_SESSION['return'])) {
  1931. echo json_encode($_SESSION['return']);
  1932. }
  1933. else {
  1934. echo json_encode(array(
  1935. 'type' => 'success',
  1936. 'msg' => 'Task completed'
  1937. ));
  1938. }
  1939. }
  1940. }
  1941. else {
  1942. echo json_encode(array(
  1943. 'type' => 'error',
  1944. 'msg' => 'Incomplete post data'
  1945. ));
  1946. }
  1947. }
  1948. else {
  1949. echo json_encode(array(
  1950. 'type' => 'error',
  1951. 'msg' => 'Incomplete post data'
  1952. ));
  1953. }
  1954. break;
  1955. case "app_links":
  1956. if (isset($_POST['attr'])) {
  1957. $attr = (array)json_decode($_POST['attr'], true);
  1958. if (is_array($attr)) {
  1959. if (customize('edit', 'app_links', $attr) === false) {
  1960. if (isset($_SESSION['return'])) {
  1961. echo json_encode($_SESSION['return']);
  1962. }
  1963. else {
  1964. echo json_encode(array(
  1965. 'type' => 'error',
  1966. 'msg' => 'Edit failed'
  1967. ));
  1968. }
  1969. exit();
  1970. }
  1971. else {
  1972. if (isset($_SESSION['return'])) {
  1973. echo json_encode($_SESSION['return']);
  1974. }
  1975. else {
  1976. echo json_encode(array(
  1977. 'type' => 'success',
  1978. 'msg' => 'Task completed'
  1979. ));
  1980. }
  1981. }
  1982. }
  1983. else {
  1984. echo json_encode(array(
  1985. 'type' => 'error',
  1986. 'msg' => 'Incomplete post data'
  1987. ));
  1988. }
  1989. }
  1990. else {
  1991. echo json_encode(array(
  1992. 'type' => 'error',
  1993. 'msg' => 'Incomplete post data'
  1994. ));
  1995. }
  1996. break;
  1997. case "relayhost":
  1998. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1999. $items = (array)json_decode($_POST['items'], true);
  2000. $attr = (array)json_decode($_POST['attr'], true);
  2001. $postarray = array_merge(array('id' => $items), $attr);
  2002. if (is_array($postarray['id'])) {
  2003. if (relayhost('edit', $postarray) === false) {
  2004. if (isset($_SESSION['return'])) {
  2005. echo json_encode($_SESSION['return']);
  2006. }
  2007. else {
  2008. echo json_encode(array(
  2009. 'type' => 'error',
  2010. 'msg' => 'Edit failed'
  2011. ));
  2012. }
  2013. exit();
  2014. }
  2015. else {
  2016. if (isset($_SESSION['return'])) {
  2017. echo json_encode($_SESSION['return']);
  2018. }
  2019. else {
  2020. echo json_encode(array(
  2021. 'type' => 'success',
  2022. 'msg' => 'Task completed'
  2023. ));
  2024. }
  2025. }
  2026. }
  2027. else {
  2028. echo json_encode(array(
  2029. 'type' => 'error',
  2030. 'msg' => 'Incomplete post data'
  2031. ));
  2032. }
  2033. }
  2034. else {
  2035. echo json_encode(array(
  2036. 'type' => 'error',
  2037. 'msg' => 'Incomplete post data'
  2038. ));
  2039. }
  2040. break;
  2041. case "delimiter_action":
  2042. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2043. $items = (array)json_decode($_POST['items'], true);
  2044. $attr = (array)json_decode($_POST['attr'], true);
  2045. $postarray = array_merge(array('username' => $items), $attr);
  2046. if (is_array($postarray['username'])) {
  2047. if (mailbox('edit', 'delimiter_action', $postarray) === false) {
  2048. if (isset($_SESSION['return'])) {
  2049. echo json_encode($_SESSION['return']);
  2050. }
  2051. else {
  2052. echo json_encode(array(
  2053. 'type' => 'error',
  2054. 'msg' => 'Edit failed'
  2055. ));
  2056. }
  2057. exit();
  2058. }
  2059. else {
  2060. if (isset($_SESSION['return'])) {
  2061. echo json_encode($_SESSION['return']);
  2062. }
  2063. else {
  2064. echo json_encode(array(
  2065. 'type' => 'success',
  2066. 'msg' => 'Task completed'
  2067. ));
  2068. }
  2069. }
  2070. }
  2071. else {
  2072. echo json_encode(array(
  2073. 'type' => 'error',
  2074. 'msg' => 'Incomplete post data'
  2075. ));
  2076. }
  2077. }
  2078. else {
  2079. echo json_encode(array(
  2080. 'type' => 'error',
  2081. 'msg' => 'Incomplete post data'
  2082. ));
  2083. }
  2084. break;
  2085. case "tls_policy":
  2086. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2087. $items = (array)json_decode($_POST['items'], true);
  2088. $attr = (array)json_decode($_POST['attr'], true);
  2089. $postarray = array_merge(array('username' => $items), $attr);
  2090. if (is_array($postarray['username'])) {
  2091. if (mailbox('edit', 'tls_policy', $postarray) === false) {
  2092. if (isset($_SESSION['return'])) {
  2093. echo json_encode($_SESSION['return']);
  2094. }
  2095. else {
  2096. echo json_encode(array(
  2097. 'type' => 'error',
  2098. 'msg' => 'Edit failed'
  2099. ));
  2100. }
  2101. exit();
  2102. }
  2103. else {
  2104. if (isset($_SESSION['return'])) {
  2105. echo json_encode($_SESSION['return']);
  2106. }
  2107. else {
  2108. echo json_encode(array(
  2109. 'type' => 'success',
  2110. 'msg' => 'Task completed'
  2111. ));
  2112. }
  2113. }
  2114. }
  2115. else {
  2116. echo json_encode(array(
  2117. 'type' => 'error',
  2118. 'msg' => 'Incomplete post data'
  2119. ));
  2120. }
  2121. }
  2122. else {
  2123. echo json_encode(array(
  2124. 'type' => 'error',
  2125. 'msg' => 'Incomplete post data'
  2126. ));
  2127. }
  2128. break;
  2129. case "time_limited_alias":
  2130. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2131. $items = (array)json_decode($_POST['items'], true);
  2132. $attr = (array)json_decode($_POST['attr'], true);
  2133. $postarray = array_merge(array('address' => $items), $attr);
  2134. if (is_array($postarray['address'])) {
  2135. if (mailbox('edit', 'time_limited_alias', $postarray) === false) {
  2136. if (isset($_SESSION['return'])) {
  2137. echo json_encode($_SESSION['return']);
  2138. }
  2139. else {
  2140. echo json_encode(array(
  2141. 'type' => 'error',
  2142. 'msg' => 'Edit failed'
  2143. ));
  2144. }
  2145. exit();
  2146. }
  2147. else {
  2148. if (isset($_SESSION['return'])) {
  2149. echo json_encode($_SESSION['return']);
  2150. }
  2151. else {
  2152. echo json_encode(array(
  2153. 'type' => 'success',
  2154. 'msg' => 'Task completed'
  2155. ));
  2156. }
  2157. }
  2158. }
  2159. else {
  2160. echo json_encode(array(
  2161. 'type' => 'error',
  2162. 'msg' => 'Incomplete post data'
  2163. ));
  2164. }
  2165. }
  2166. else {
  2167. echo json_encode(array(
  2168. 'type' => 'error',
  2169. 'msg' => 'Incomplete post data'
  2170. ));
  2171. }
  2172. break;
  2173. case "mailbox":
  2174. // sender_acl:0 removes all entries
  2175. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2176. $items = (array)json_decode($_POST['items'], true);
  2177. $attr = (array)json_decode($_POST['attr'], true);
  2178. $postarray = array_merge(array('username' => $items), $attr);
  2179. if (is_array($postarray['username'])) {
  2180. if (mailbox('edit', 'mailbox', $postarray) === false) {
  2181. if (isset($_SESSION['return'])) {
  2182. echo json_encode($_SESSION['return']);
  2183. }
  2184. else {
  2185. echo json_encode(array(
  2186. 'type' => 'error',
  2187. 'msg' => 'Edit failed'
  2188. ));
  2189. }
  2190. exit();
  2191. }
  2192. else {
  2193. if (isset($_SESSION['return'])) {
  2194. echo json_encode($_SESSION['return']);
  2195. }
  2196. else {
  2197. echo json_encode(array(
  2198. 'type' => 'success',
  2199. 'msg' => 'Task completed'
  2200. ));
  2201. }
  2202. }
  2203. }
  2204. else {
  2205. echo json_encode(array(
  2206. 'type' => 'error',
  2207. 'msg' => 'Incomplete post data'
  2208. ));
  2209. }
  2210. }
  2211. else {
  2212. echo json_encode(array(
  2213. 'type' => 'error',
  2214. 'msg' => 'Incomplete post data'
  2215. ));
  2216. }
  2217. break;
  2218. case "syncjob":
  2219. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2220. $items = (array)json_decode($_POST['items'], true);
  2221. $attr = (array)json_decode($_POST['attr'], true);
  2222. $postarray = array_merge(array('id' => $items), $attr);
  2223. if (is_array($postarray['id'])) {
  2224. if (mailbox('edit', 'syncjob', $postarray) === false) {
  2225. if (isset($_SESSION['return'])) {
  2226. echo json_encode($_SESSION['return']);
  2227. }
  2228. else {
  2229. echo json_encode(array(
  2230. 'type' => 'error',
  2231. 'msg' => 'Edit failed'
  2232. ));
  2233. }
  2234. exit();
  2235. }
  2236. else {
  2237. if (isset($_SESSION['return'])) {
  2238. echo json_encode($_SESSION['return']);
  2239. }
  2240. else {
  2241. echo json_encode(array(
  2242. 'type' => 'success',
  2243. 'msg' => 'Task completed'
  2244. ));
  2245. }
  2246. }
  2247. }
  2248. else {
  2249. echo json_encode(array(
  2250. 'type' => 'error',
  2251. 'msg' => 'Incomplete post data'
  2252. ));
  2253. }
  2254. }
  2255. else {
  2256. echo json_encode(array(
  2257. 'type' => 'error',
  2258. 'msg' => 'Incomplete post data'
  2259. ));
  2260. }
  2261. break;
  2262. case "filter":
  2263. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2264. $items = (array)json_decode($_POST['items'], true);
  2265. $attr = (array)json_decode($_POST['attr'], true);
  2266. $postarray = array_merge(array('id' => $items), $attr);
  2267. if (is_array($postarray['id'])) {
  2268. if (mailbox('edit', 'filter', $postarray) === false) {
  2269. if (isset($_SESSION['return'])) {
  2270. echo json_encode($_SESSION['return']);
  2271. }
  2272. else {
  2273. echo json_encode(array(
  2274. 'type' => 'error',
  2275. 'msg' => 'Edit failed'
  2276. ));
  2277. }
  2278. exit();
  2279. }
  2280. else {
  2281. if (isset($_SESSION['return'])) {
  2282. echo json_encode($_SESSION['return']);
  2283. }
  2284. else {
  2285. echo json_encode(array(
  2286. 'type' => 'success',
  2287. 'msg' => 'Task completed'
  2288. ));
  2289. }
  2290. }
  2291. }
  2292. else {
  2293. echo json_encode(array(
  2294. 'type' => 'error',
  2295. 'msg' => 'Incomplete post data'
  2296. ));
  2297. }
  2298. }
  2299. else {
  2300. echo json_encode(array(
  2301. 'type' => 'error',
  2302. 'msg' => 'Incomplete post data'
  2303. ));
  2304. }
  2305. break;
  2306. case "resource":
  2307. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2308. $items = (array)json_decode($_POST['items'], true);
  2309. $attr = (array)json_decode($_POST['attr'], true);
  2310. $postarray = array_merge(array('name' => $items), $attr);
  2311. if (is_array($postarray['name'])) {
  2312. if (mailbox('edit', 'resource', $postarray) === false) {
  2313. if (isset($_SESSION['return'])) {
  2314. echo json_encode($_SESSION['return']);
  2315. }
  2316. else {
  2317. echo json_encode(array(
  2318. 'type' => 'error',
  2319. 'msg' => 'Edit failed'
  2320. ));
  2321. }
  2322. exit();
  2323. }
  2324. else {
  2325. if (isset($_SESSION['return'])) {
  2326. echo json_encode($_SESSION['return']);
  2327. }
  2328. else {
  2329. echo json_encode(array(
  2330. 'type' => 'success',
  2331. 'msg' => 'Task completed'
  2332. ));
  2333. }
  2334. }
  2335. }
  2336. else {
  2337. echo json_encode(array(
  2338. 'type' => 'error',
  2339. 'msg' => 'Incomplete post data'
  2340. ));
  2341. }
  2342. }
  2343. else {
  2344. echo json_encode(array(
  2345. 'type' => 'error',
  2346. 'msg' => 'Incomplete post data'
  2347. ));
  2348. }
  2349. break;
  2350. case "domain":
  2351. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2352. $items = (array)json_decode($_POST['items'], true);
  2353. $attr = (array)json_decode($_POST['attr'], true);
  2354. $postarray = array_merge(array('domain' => $items), $attr);
  2355. if (is_array($postarray['domain'])) {
  2356. if (mailbox('edit', 'domain', $postarray) === false) {
  2357. if (isset($_SESSION['return'])) {
  2358. echo json_encode($_SESSION['return']);
  2359. }
  2360. else {
  2361. echo json_encode(array(
  2362. 'type' => 'error',
  2363. 'msg' => 'Edit failed'
  2364. ));
  2365. }
  2366. exit();
  2367. }
  2368. else {
  2369. if (isset($_SESSION['return'])) {
  2370. echo json_encode($_SESSION['return']);
  2371. }
  2372. else {
  2373. echo json_encode(array(
  2374. 'type' => 'success',
  2375. 'msg' => 'Task completed'
  2376. ));
  2377. }
  2378. }
  2379. }
  2380. else {
  2381. echo json_encode(array(
  2382. 'type' => 'error',
  2383. 'msg' => 'Incomplete post data'
  2384. ));
  2385. }
  2386. }
  2387. else {
  2388. echo json_encode(array(
  2389. 'type' => 'error',
  2390. 'msg' => 'Incomplete post data'
  2391. ));
  2392. }
  2393. break;
  2394. case "ratelimit":
  2395. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2396. $items = (array)json_decode($_POST['items'], true);
  2397. $attr = (array)json_decode($_POST['attr'], true);
  2398. $postarray = array_merge(array('object' => $items), $attr);
  2399. if (is_array($postarray['object'])) {
  2400. if (mailbox('edit', 'ratelimit', $postarray) === 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. else {
  2432. echo json_encode(array(
  2433. 'type' => 'error',
  2434. 'msg' => 'Incomplete post data'
  2435. ));
  2436. }
  2437. break;
  2438. case "alias-domain":
  2439. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2440. $items = (array)json_decode($_POST['items'], true);
  2441. $attr = (array)json_decode($_POST['attr'], true);
  2442. $postarray = array_merge(array('alias_domain' => $items), $attr);
  2443. if (is_array($postarray['alias_domain'])) {
  2444. if (mailbox('edit', 'alias_domain', $postarray) === false) {
  2445. if (isset($_SESSION['return'])) {
  2446. echo json_encode($_SESSION['return']);
  2447. }
  2448. else {
  2449. echo json_encode(array(
  2450. 'type' => 'error',
  2451. 'msg' => 'Edit failed'
  2452. ));
  2453. }
  2454. exit();
  2455. }
  2456. else {
  2457. if (isset($_SESSION['return'])) {
  2458. echo json_encode($_SESSION['return']);
  2459. }
  2460. else {
  2461. echo json_encode(array(
  2462. 'type' => 'success',
  2463. 'msg' => 'Task completed'
  2464. ));
  2465. }
  2466. }
  2467. }
  2468. else {
  2469. echo json_encode(array(
  2470. 'type' => 'error',
  2471. 'msg' => 'Incomplete post data'
  2472. ));
  2473. }
  2474. }
  2475. else {
  2476. echo json_encode(array(
  2477. 'type' => 'error',
  2478. 'msg' => 'Incomplete post data'
  2479. ));
  2480. }
  2481. break;
  2482. case "spam-score":
  2483. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2484. $items = (array)json_decode($_POST['items'], true);
  2485. $attr = (array)json_decode($_POST['attr'], true);
  2486. $postarray = array_merge(array('username' => $items), $attr);
  2487. if (is_array($postarray['username'])) {
  2488. if (mailbox('edit', 'spam_score', $postarray) === false) {
  2489. if (isset($_SESSION['return'])) {
  2490. echo json_encode($_SESSION['return']);
  2491. }
  2492. else {
  2493. echo json_encode(array(
  2494. 'type' => 'error',
  2495. 'msg' => 'Edit failed'
  2496. ));
  2497. }
  2498. exit();
  2499. }
  2500. else {
  2501. if (isset($_SESSION['return'])) {
  2502. echo json_encode($_SESSION['return']);
  2503. }
  2504. else {
  2505. echo json_encode(array(
  2506. 'type' => 'success',
  2507. 'msg' => 'Task completed'
  2508. ));
  2509. }
  2510. }
  2511. }
  2512. else {
  2513. echo json_encode(array(
  2514. 'type' => 'error',
  2515. 'msg' => 'Incomplete post data'
  2516. ));
  2517. }
  2518. }
  2519. else {
  2520. echo json_encode(array(
  2521. 'type' => 'error',
  2522. 'msg' => 'Incomplete post data'
  2523. ));
  2524. }
  2525. break;
  2526. case "domain-admin":
  2527. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2528. $items = (array)json_decode($_POST['items'], true);
  2529. $attr = (array)json_decode($_POST['attr'], true);
  2530. $postarray = array_merge(array('username' => $items), $attr);
  2531. if (is_array($postarray['username'])) {
  2532. if (domain_admin('edit', $postarray) === false) {
  2533. if (isset($_SESSION['return'])) {
  2534. echo json_encode($_SESSION['return']);
  2535. }
  2536. else {
  2537. echo json_encode(array(
  2538. 'type' => 'error',
  2539. 'msg' => 'Edit failed'
  2540. ));
  2541. }
  2542. exit();
  2543. }
  2544. else {
  2545. if (isset($_SESSION['return'])) {
  2546. echo json_encode($_SESSION['return']);
  2547. }
  2548. else {
  2549. echo json_encode(array(
  2550. 'type' => 'success',
  2551. 'msg' => 'Task completed'
  2552. ));
  2553. }
  2554. }
  2555. }
  2556. else {
  2557. echo json_encode(array(
  2558. 'type' => 'error',
  2559. 'msg' => 'Incomplete post data'
  2560. ));
  2561. }
  2562. }
  2563. else {
  2564. echo json_encode(array(
  2565. 'type' => 'error',
  2566. 'msg' => 'Incomplete post data'
  2567. ));
  2568. }
  2569. break;
  2570. case "fwdhost":
  2571. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2572. $items = (array)json_decode($_POST['items'], true);
  2573. $attr = (array)json_decode($_POST['attr'], true);
  2574. $postarray = array_merge(array('fwdhost' => $items), $attr);
  2575. if (is_array($postarray['fwdhost'])) {
  2576. if (fwdhost('edit', $postarray) === false) {
  2577. if (isset($_SESSION['return'])) {
  2578. echo json_encode($_SESSION['return']);
  2579. }
  2580. else {
  2581. echo json_encode(array(
  2582. 'type' => 'error',
  2583. 'msg' => 'Edit failed'
  2584. ));
  2585. }
  2586. exit();
  2587. }
  2588. else {
  2589. if (isset($_SESSION['return'])) {
  2590. echo json_encode($_SESSION['return']);
  2591. }
  2592. else {
  2593. echo json_encode(array(
  2594. 'type' => 'success',
  2595. 'msg' => 'Task completed'
  2596. ));
  2597. }
  2598. }
  2599. }
  2600. else {
  2601. echo json_encode(array(
  2602. 'type' => 'error',
  2603. 'msg' => 'Incomplete post data'
  2604. ));
  2605. }
  2606. }
  2607. else {
  2608. echo json_encode(array(
  2609. 'type' => 'error',
  2610. 'msg' => 'Incomplete post data'
  2611. ));
  2612. }
  2613. break;
  2614. case "fail2ban":
  2615. // No items
  2616. if (isset($_POST['attr'])) {
  2617. $attr = (array)json_decode($_POST['attr'], true);
  2618. if (fail2ban('edit', $attr) === false) {
  2619. if (isset($_SESSION['return'])) {
  2620. echo json_encode($_SESSION['return']);
  2621. }
  2622. else {
  2623. echo json_encode(array(
  2624. 'type' => 'error',
  2625. 'msg' => 'Edit failed'
  2626. ));
  2627. }
  2628. exit();
  2629. }
  2630. else {
  2631. if (isset($_SESSION['return'])) {
  2632. echo json_encode($_SESSION['return']);
  2633. }
  2634. else {
  2635. echo json_encode(array(
  2636. 'type' => 'success',
  2637. 'msg' => 'Task completed'
  2638. ));
  2639. }
  2640. }
  2641. }
  2642. else {
  2643. echo json_encode(array(
  2644. 'type' => 'error',
  2645. 'msg' => 'Incomplete post data'
  2646. ));
  2647. }
  2648. break;
  2649. case "self":
  2650. // No items, logged-in user, users and domain admins
  2651. if ($_SESSION['mailcow_cc_role'] == "domainadmin") {
  2652. if (isset($_POST['attr'])) {
  2653. $attr = (array)json_decode($_POST['attr'], true);
  2654. if (domain_admin('edit', $attr) === false) {
  2655. if (isset($_SESSION['return'])) {
  2656. echo json_encode($_SESSION['return']);
  2657. }
  2658. else {
  2659. echo json_encode(array(
  2660. 'type' => 'error',
  2661. 'msg' => 'Edit failed'
  2662. ));
  2663. }
  2664. exit();
  2665. }
  2666. else {
  2667. if (isset($_SESSION['return'])) {
  2668. echo json_encode($_SESSION['return']);
  2669. }
  2670. else {
  2671. echo json_encode(array(
  2672. 'type' => 'success',
  2673. 'msg' => 'Task completed'
  2674. ));
  2675. }
  2676. }
  2677. }
  2678. else {
  2679. echo json_encode(array(
  2680. 'type' => 'error',
  2681. 'msg' => 'Incomplete post data'
  2682. ));
  2683. }
  2684. }
  2685. elseif ($_SESSION['mailcow_cc_role'] == "user") {
  2686. if (isset($_POST['attr'])) {
  2687. $attr = (array)json_decode($_POST['attr'], true);
  2688. if (edit_user_account($attr) === false) {
  2689. if (isset($_SESSION['return'])) {
  2690. echo json_encode($_SESSION['return']);
  2691. }
  2692. else {
  2693. echo json_encode(array(
  2694. 'type' => 'error',
  2695. 'msg' => 'Edit failed'
  2696. ));
  2697. }
  2698. exit();
  2699. }
  2700. else {
  2701. if (isset($_SESSION['return'])) {
  2702. echo json_encode($_SESSION['return']);
  2703. }
  2704. else {
  2705. echo json_encode(array(
  2706. 'type' => 'success',
  2707. 'msg' => 'Task completed'
  2708. ));
  2709. }
  2710. }
  2711. }
  2712. else {
  2713. echo json_encode(array(
  2714. 'type' => 'error',
  2715. 'msg' => 'Incomplete post data'
  2716. ));
  2717. }
  2718. }
  2719. elseif ($_SESSION['mailcow_cc_role'] == "admin") {
  2720. if (isset($_POST['attr'])) {
  2721. $attr = (array)json_decode($_POST['attr'], true);
  2722. if (edit_admin_account($attr) === false) {
  2723. if (isset($_SESSION['return'])) {
  2724. echo json_encode($_SESSION['return']);
  2725. }
  2726. else {
  2727. echo json_encode(array(
  2728. 'type' => 'error',
  2729. 'msg' => 'Edit failed'
  2730. ));
  2731. }
  2732. exit();
  2733. }
  2734. else {
  2735. if (isset($_SESSION['return'])) {
  2736. echo json_encode($_SESSION['return']);
  2737. }
  2738. else {
  2739. echo json_encode(array(
  2740. 'type' => 'success',
  2741. 'msg' => 'Task completed'
  2742. ));
  2743. }
  2744. }
  2745. }
  2746. else {
  2747. echo json_encode(array(
  2748. 'type' => 'error',
  2749. 'msg' => 'Incomplete post data'
  2750. ));
  2751. }
  2752. }
  2753. break;
  2754. }
  2755. break;
  2756. }
  2757. }
  2758. }