json_api.php 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189
  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. function api_log($postarray) {
  17. global $redis;
  18. $data_var = array();
  19. foreach ($postarray as $data => &$value) {
  20. if ($data == 'csrf_token') {
  21. continue;
  22. }
  23. if ($value = json_decode($value, true)) {
  24. unset($value["csrf_token"]);
  25. foreach ($value as $key => &$val) {
  26. if(preg_match("/pass/i", $key)) {
  27. $val = '********';
  28. }
  29. }
  30. $value = json_encode($value);
  31. }
  32. $data_var[] = $data . "='" . $value . "'";
  33. }
  34. try {
  35. $log_line = array(
  36. 'time' => time(),
  37. 'uri' => $_SERVER['REQUEST_URI'],
  38. 'method' => $_SERVER['REQUEST_METHOD'],
  39. 'remote' => $_SERVER['REMOTE_ADDR'],
  40. 'data' => implode(', ', $data_var)
  41. );
  42. $redis->lPush('API_LOG', json_encode($log_line));
  43. }
  44. catch (RedisException $e) {
  45. $_SESSION['return'] = array(
  46. 'type' => 'danger',
  47. 'msg' => 'Redis: '.$e
  48. );
  49. return false;
  50. }
  51. }
  52. api_log($_POST);
  53. if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_username'])) {
  54. if (isset($_GET['query'])) {
  55. $query = explode('/', $_GET['query']);
  56. $action = (isset($query[0])) ? $query[0] : null;
  57. $category = (isset($query[1])) ? $query[1] : null;
  58. $object = (isset($query[2])) ? $query[2] : null;
  59. $extra = (isset($query[3])) ? $query[3] : null;
  60. switch ($action) {
  61. case "add":
  62. switch ($category) {
  63. case "time_limited_alias":
  64. if (isset($_POST['attr'])) {
  65. $attr = (array)json_decode($_POST['attr'], true);
  66. if (mailbox('add', 'time_limited_alias', $attr) === false) {
  67. if (isset($_SESSION['return'])) {
  68. echo json_encode($_SESSION['return']);
  69. }
  70. else {
  71. echo json_encode(array(
  72. 'type' => 'error',
  73. 'msg' => 'Cannot add item'
  74. ));
  75. }
  76. }
  77. else {
  78. if (isset($_SESSION['return'])) {
  79. echo json_encode($_SESSION['return']);
  80. }
  81. else {
  82. echo json_encode(array(
  83. 'type' => 'success',
  84. 'msg' => 'Task completed'
  85. ));
  86. }
  87. }
  88. }
  89. else {
  90. echo json_encode(array(
  91. 'type' => 'error',
  92. 'msg' => 'Cannot find attributes in post data'
  93. ));
  94. }
  95. break;
  96. case "relayhost":
  97. if (isset($_POST['attr'])) {
  98. $attr = (array)json_decode($_POST['attr'], true);
  99. if (relayhost('add', $attr) === false) {
  100. if (isset($_SESSION['return'])) {
  101. echo json_encode($_SESSION['return']);
  102. }
  103. else {
  104. echo json_encode(array(
  105. 'type' => 'error',
  106. 'msg' => 'Cannot add item'
  107. ));
  108. }
  109. }
  110. else {
  111. if (isset($_SESSION['return'])) {
  112. echo json_encode($_SESSION['return']);
  113. }
  114. else {
  115. echo json_encode(array(
  116. 'type' => 'success',
  117. 'msg' => 'Task completed'
  118. ));
  119. }
  120. }
  121. }
  122. else {
  123. echo json_encode(array(
  124. 'type' => 'error',
  125. 'msg' => 'Cannot find attributes in post data'
  126. ));
  127. }
  128. break;
  129. case "mailbox":
  130. if (isset($_POST['attr'])) {
  131. $attr = (array)json_decode($_POST['attr'], true);
  132. if (mailbox('add', 'mailbox', $attr) === false) {
  133. if (isset($_SESSION['return'])) {
  134. echo json_encode($_SESSION['return']);
  135. }
  136. else {
  137. echo json_encode(array(
  138. 'type' => 'error',
  139. 'msg' => 'Cannot add item'
  140. ));
  141. }
  142. }
  143. else {
  144. if (isset($_SESSION['return'])) {
  145. echo json_encode($_SESSION['return']);
  146. }
  147. else {
  148. echo json_encode(array(
  149. 'type' => 'success',
  150. 'msg' => 'Task completed'
  151. ));
  152. }
  153. }
  154. }
  155. else {
  156. echo json_encode(array(
  157. 'type' => 'error',
  158. 'msg' => 'Cannot find attributes in post data'
  159. ));
  160. }
  161. break;
  162. case "domain":
  163. if (isset($_POST['attr'])) {
  164. $attr = (array)json_decode($_POST['attr'], true);
  165. if (mailbox('add', 'domain', $attr) === false) {
  166. if (isset($_SESSION['return'])) {
  167. echo json_encode($_SESSION['return']);
  168. }
  169. else {
  170. echo json_encode(array(
  171. 'type' => 'error',
  172. 'msg' => 'Cannot add item'
  173. ));
  174. }
  175. }
  176. else {
  177. if (isset($_SESSION['return'])) {
  178. echo json_encode($_SESSION['return']);
  179. }
  180. else {
  181. echo json_encode(array(
  182. 'type' => 'success',
  183. 'msg' => 'Task completed'
  184. ));
  185. }
  186. }
  187. }
  188. else {
  189. echo json_encode(array(
  190. 'type' => 'error',
  191. 'msg' => 'Cannot find attributes in post data'
  192. ));
  193. }
  194. break;
  195. case "resource":
  196. if (isset($_POST['attr'])) {
  197. $attr = (array)json_decode($_POST['attr'], true);
  198. if (mailbox('add', 'resource', $attr) === false) {
  199. if (isset($_SESSION['return'])) {
  200. echo json_encode($_SESSION['return']);
  201. }
  202. else {
  203. echo json_encode(array(
  204. 'type' => 'error',
  205. 'msg' => 'Cannot add item'
  206. ));
  207. }
  208. }
  209. else {
  210. if (isset($_SESSION['return'])) {
  211. echo json_encode($_SESSION['return']);
  212. }
  213. else {
  214. echo json_encode(array(
  215. 'type' => 'success',
  216. 'msg' => 'Task completed'
  217. ));
  218. }
  219. }
  220. }
  221. else {
  222. echo json_encode(array(
  223. 'type' => 'error',
  224. 'msg' => 'Cannot find attributes in post data'
  225. ));
  226. }
  227. break;
  228. case "alias":
  229. if (isset($_POST['attr'])) {
  230. $attr = (array)json_decode($_POST['attr'], true);
  231. if (mailbox('add', 'alias', $attr) === false) {
  232. if (isset($_SESSION['return'])) {
  233. echo json_encode($_SESSION['return']);
  234. }
  235. else {
  236. echo json_encode(array(
  237. 'type' => 'error',
  238. 'msg' => 'Cannot add item'
  239. ));
  240. }
  241. }
  242. else {
  243. if (isset($_SESSION['return'])) {
  244. echo json_encode($_SESSION['return']);
  245. }
  246. else {
  247. echo json_encode(array(
  248. 'type' => 'success',
  249. 'msg' => 'Task completed'
  250. ));
  251. }
  252. }
  253. }
  254. else {
  255. echo json_encode(array(
  256. 'type' => 'error',
  257. 'msg' => 'Cannot find attributes in post data'
  258. ));
  259. }
  260. break;
  261. case "filter":
  262. if (isset($_POST['attr'])) {
  263. $attr = (array)json_decode($_POST['attr'], true);
  264. if (mailbox('add', 'filter', $attr) === false) {
  265. if (isset($_SESSION['return'])) {
  266. echo json_encode($_SESSION['return']);
  267. }
  268. else {
  269. echo json_encode(array(
  270. 'type' => 'error',
  271. 'msg' => 'Cannot add item'
  272. ));
  273. }
  274. }
  275. else {
  276. if (isset($_SESSION['return'])) {
  277. echo json_encode($_SESSION['return']);
  278. }
  279. else {
  280. echo json_encode(array(
  281. 'type' => 'success',
  282. 'msg' => 'Task completed'
  283. ));
  284. }
  285. }
  286. }
  287. else {
  288. echo json_encode(array(
  289. 'type' => 'error',
  290. 'msg' => 'Cannot find attributes in post data'
  291. ));
  292. }
  293. break;
  294. case "domain-policy":
  295. if (isset($_POST['attr'])) {
  296. $attr = (array)json_decode($_POST['attr'], true);
  297. if (policy('add', 'domain', $attr) === false) {
  298. if (isset($_SESSION['return'])) {
  299. echo json_encode($_SESSION['return']);
  300. }
  301. else {
  302. echo json_encode(array(
  303. 'type' => 'error',
  304. 'msg' => 'Cannot add item'
  305. ));
  306. }
  307. }
  308. else {
  309. if (isset($_SESSION['return'])) {
  310. echo json_encode($_SESSION['return']);
  311. }
  312. else {
  313. echo json_encode(array(
  314. 'type' => 'success',
  315. 'msg' => 'Task completed'
  316. ));
  317. }
  318. }
  319. }
  320. else {
  321. echo json_encode(array(
  322. 'type' => 'error',
  323. 'msg' => 'Cannot find attributes in post data'
  324. ));
  325. }
  326. break;
  327. case "mailbox-policy":
  328. if (isset($_POST['attr'])) {
  329. $attr = (array)json_decode($_POST['attr'], true);
  330. if (policy('add', 'mailbox', $attr) === false) {
  331. if (isset($_SESSION['return'])) {
  332. echo json_encode($_SESSION['return']);
  333. }
  334. else {
  335. echo json_encode(array(
  336. 'type' => 'error',
  337. 'msg' => 'Cannot add item'
  338. ));
  339. }
  340. }
  341. else {
  342. if (isset($_SESSION['return'])) {
  343. echo json_encode($_SESSION['return']);
  344. }
  345. else {
  346. echo json_encode(array(
  347. 'type' => 'success',
  348. 'msg' => 'Task completed'
  349. ));
  350. }
  351. }
  352. }
  353. else {
  354. echo json_encode(array(
  355. 'type' => 'error',
  356. 'msg' => 'Cannot find attributes in post data'
  357. ));
  358. }
  359. break;
  360. case "alias-domain":
  361. if (isset($_POST['attr'])) {
  362. $attr = (array)json_decode($_POST['attr'], true);
  363. if (mailbox('add', 'alias_domain', $attr) === false) {
  364. if (isset($_SESSION['return'])) {
  365. echo json_encode($_SESSION['return']);
  366. }
  367. else {
  368. echo json_encode(array(
  369. 'type' => 'error',
  370. 'msg' => 'Cannot add item'
  371. ));
  372. }
  373. }
  374. else {
  375. if (isset($_SESSION['return'])) {
  376. echo json_encode($_SESSION['return']);
  377. }
  378. else {
  379. echo json_encode(array(
  380. 'type' => 'success',
  381. 'msg' => 'Task completed'
  382. ));
  383. }
  384. }
  385. }
  386. else {
  387. echo json_encode(array(
  388. 'type' => 'error',
  389. 'msg' => 'Cannot find attributes in post data'
  390. ));
  391. }
  392. break;
  393. case "fwdhost":
  394. if (isset($_POST['attr'])) {
  395. $attr = (array)json_decode($_POST['attr'], true);
  396. if (fwdhost('add', $attr) === false) {
  397. if (isset($_SESSION['return'])) {
  398. echo json_encode($_SESSION['return']);
  399. }
  400. else {
  401. echo json_encode(array(
  402. 'type' => 'error',
  403. 'msg' => 'Cannot add item'
  404. ));
  405. }
  406. }
  407. else {
  408. if (isset($_SESSION['return'])) {
  409. echo json_encode($_SESSION['return']);
  410. }
  411. else {
  412. echo json_encode(array(
  413. 'type' => 'success',
  414. 'msg' => 'Task completed'
  415. ));
  416. }
  417. }
  418. }
  419. else {
  420. echo json_encode(array(
  421. 'type' => 'error',
  422. 'msg' => 'Cannot find attributes in post data'
  423. ));
  424. }
  425. break;
  426. case "dkim":
  427. if (isset($_POST['attr'])) {
  428. $attr = (array)json_decode($_POST['attr'], true);
  429. if (dkim('add', $attr) === false) {
  430. if (isset($_SESSION['return'])) {
  431. echo json_encode($_SESSION['return']);
  432. }
  433. else {
  434. echo json_encode(array(
  435. 'type' => 'error',
  436. 'msg' => 'Cannot add item'
  437. ));
  438. }
  439. }
  440. else {
  441. if (isset($_SESSION['return'])) {
  442. echo json_encode($_SESSION['return']);
  443. }
  444. else {
  445. echo json_encode(array(
  446. 'type' => 'success',
  447. 'msg' => 'Task completed'
  448. ));
  449. }
  450. }
  451. }
  452. else {
  453. echo json_encode(array(
  454. 'type' => 'error',
  455. 'msg' => 'Cannot find attributes in post data'
  456. ));
  457. }
  458. break;
  459. case "dkim_import":
  460. if (isset($_POST['attr'])) {
  461. $attr = (array)json_decode($_POST['attr'], true);
  462. if (dkim('import', $attr) === false) {
  463. if (isset($_SESSION['return'])) {
  464. echo json_encode($_SESSION['return']);
  465. }
  466. else {
  467. echo json_encode(array(
  468. 'type' => 'error',
  469. 'msg' => 'Cannot add item'
  470. ));
  471. }
  472. }
  473. else {
  474. if (isset($_SESSION['return'])) {
  475. echo json_encode($_SESSION['return']);
  476. }
  477. else {
  478. echo json_encode(array(
  479. 'type' => 'success',
  480. 'msg' => 'Task completed'
  481. ));
  482. }
  483. }
  484. }
  485. else {
  486. echo json_encode(array(
  487. 'type' => 'error',
  488. 'msg' => 'Cannot find attributes in post data'
  489. ));
  490. }
  491. break;
  492. case "domain-admin":
  493. if (isset($_POST['attr'])) {
  494. $attr = (array)json_decode($_POST['attr'], true);
  495. if (domain_admin('add', $attr) === false) {
  496. if (isset($_SESSION['return'])) {
  497. echo json_encode($_SESSION['return']);
  498. }
  499. else {
  500. echo json_encode(array(
  501. 'type' => 'error',
  502. 'msg' => 'Cannot add item'
  503. ));
  504. }
  505. }
  506. else {
  507. if (isset($_SESSION['return'])) {
  508. echo json_encode($_SESSION['return']);
  509. }
  510. else {
  511. echo json_encode(array(
  512. 'type' => 'success',
  513. 'msg' => 'Task completed'
  514. ));
  515. }
  516. }
  517. }
  518. else {
  519. echo json_encode(array(
  520. 'type' => 'error',
  521. 'msg' => 'Cannot find attributes in post data'
  522. ));
  523. }
  524. break;
  525. case "syncjob":
  526. if (isset($_POST['attr'])) {
  527. $attr = (array)json_decode($_POST['attr'], true);
  528. if (mailbox('add', 'syncjob', $attr) === false) {
  529. if (isset($_SESSION['return'])) {
  530. echo json_encode($_SESSION['return']);
  531. }
  532. else {
  533. echo json_encode(array(
  534. 'type' => 'error',
  535. 'msg' => 'Cannot add item'
  536. ));
  537. }
  538. }
  539. else {
  540. if (isset($_SESSION['return'])) {
  541. echo json_encode($_SESSION['return']);
  542. }
  543. else {
  544. echo json_encode(array(
  545. 'type' => 'success',
  546. 'msg' => 'Task completed'
  547. ));
  548. }
  549. }
  550. }
  551. else {
  552. echo json_encode(array(
  553. 'type' => 'error',
  554. 'msg' => 'Cannot find attributes in post data'
  555. ));
  556. }
  557. break;
  558. case "bcc":
  559. if (isset($_POST['attr'])) {
  560. $attr = (array)json_decode($_POST['attr'], true);
  561. if (bcc('add', $attr) === false) {
  562. if (isset($_SESSION['return'])) {
  563. echo json_encode($_SESSION['return']);
  564. }
  565. else {
  566. echo json_encode(array(
  567. 'type' => 'error',
  568. 'msg' => 'Cannot add item'
  569. ));
  570. }
  571. }
  572. else {
  573. if (isset($_SESSION['return'])) {
  574. echo json_encode($_SESSION['return']);
  575. }
  576. else {
  577. echo json_encode(array(
  578. 'type' => 'success',
  579. 'msg' => 'Task completed'
  580. ));
  581. }
  582. }
  583. }
  584. else {
  585. echo json_encode(array(
  586. 'type' => 'error',
  587. 'msg' => 'Cannot find attributes in post data'
  588. ));
  589. }
  590. break;
  591. }
  592. break;
  593. case "get":
  594. switch ($category) {
  595. case "rspamd":
  596. switch ($object) {
  597. case "stat":
  598. $data = file_get_contents('http://rspamd-mailcow:11334/stat');
  599. if (!empty($data)) {
  600. echo $data;
  601. }
  602. elseif (!isset($data) || empty($data)) {
  603. echo '{}';
  604. }
  605. break;
  606. case "graph":
  607. switch ($extra) {
  608. case "hourly":
  609. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=hourly');
  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 "daily":
  644. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=daily');
  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. case "weekly":
  679. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=weekly');
  680. if (!empty($data)) {
  681. $data_array = json_decode($data, true);
  682. $rejected['label'] = "reject";
  683. foreach ($data_array[0] as $dataset) {
  684. $rejected['data'][] = $dataset;
  685. }
  686. $temp_reject['label'] = "temp_reject";
  687. foreach ($data_array[1] as $dataset) {
  688. $temp_reject['data'][] = $dataset;
  689. }
  690. $add_header['label'] = "add_header";
  691. foreach ($data_array[2] as $dataset) {
  692. $add_header['data'][] = $dataset;
  693. }
  694. $prob_spam['label'] = "prob_spam";
  695. foreach ($data_array[3] as $dataset) {
  696. $prob_spam['data'][] = $dataset;
  697. }
  698. $greylist['label'] = "greylist";
  699. foreach ($data_array[4] as $dataset) {
  700. $greylist['data'][] = $dataset;
  701. }
  702. $clean['label'] = "clean";
  703. $clean['pointStyle'] = "cross";
  704. foreach ($data_array[5] as $dataset) {
  705. $clean['data'][] = $dataset;
  706. }
  707. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  708. }
  709. elseif (!isset($data) || empty($data)) {
  710. echo '{}';
  711. }
  712. break;
  713. case "monthly":
  714. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=monthly');
  715. if (!empty($data)) {
  716. $data_array = json_decode($data, true);
  717. $rejected['label'] = "reject";
  718. foreach ($data_array[0] as $dataset) {
  719. $rejected['data'][] = $dataset;
  720. }
  721. $temp_reject['label'] = "temp_reject";
  722. foreach ($data_array[1] as $dataset) {
  723. $temp_reject['data'][] = $dataset;
  724. }
  725. $add_header['label'] = "add_header";
  726. foreach ($data_array[2] as $dataset) {
  727. $add_header['data'][] = $dataset;
  728. }
  729. $prob_spam['label'] = "prob_spam";
  730. foreach ($data_array[3] as $dataset) {
  731. $prob_spam['data'][] = $dataset;
  732. }
  733. $greylist['label'] = "greylist";
  734. foreach ($data_array[4] as $dataset) {
  735. $greylist['data'][] = $dataset;
  736. }
  737. $clean['label'] = "clean";
  738. $clean['pointStyle'] = "cross";
  739. foreach ($data_array[5] as $dataset) {
  740. $clean['data'][] = $dataset;
  741. }
  742. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  743. }
  744. elseif (!isset($data) || empty($data)) {
  745. echo '{}';
  746. }
  747. break;
  748. }
  749. break;
  750. }
  751. break;
  752. case "domain":
  753. switch ($object) {
  754. case "all":
  755. $domains = mailbox('get', 'domains');
  756. if (!empty($domains)) {
  757. foreach ($domains as $domain) {
  758. if ($details = mailbox('get', 'domain_details', $domain)) {
  759. $data[] = $details;
  760. }
  761. else {
  762. continue;
  763. }
  764. }
  765. if (!isset($data) || empty($data)) {
  766. echo '{}';
  767. }
  768. else {
  769. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  770. }
  771. }
  772. else {
  773. echo '{}';
  774. }
  775. break;
  776. default:
  777. $data = mailbox('get', 'domain_details', $object);
  778. if (!isset($data) || empty($data)) {
  779. echo '{}';
  780. }
  781. else {
  782. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  783. }
  784. break;
  785. }
  786. break;
  787. case "relayhost":
  788. switch ($object) {
  789. case "all":
  790. $relayhosts = relayhost('get');
  791. if (!empty($relayhosts)) {
  792. foreach ($relayhosts as $relayhost) {
  793. if ($details = relayhost('details', $relayhost['id'])) {
  794. $data[] = $details;
  795. }
  796. else {
  797. continue;
  798. }
  799. }
  800. if (!isset($data) || empty($data)) {
  801. echo '{}';
  802. }
  803. else {
  804. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  805. }
  806. }
  807. else {
  808. echo '{}';
  809. }
  810. break;
  811. default:
  812. $data = relayhost('details', $object);
  813. if (!isset($data) || empty($data)) {
  814. echo '{}';
  815. }
  816. else {
  817. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  818. }
  819. break;
  820. }
  821. break;
  822. case "logs":
  823. switch ($object) {
  824. case "dovecot":
  825. // 0 is first record, so empty is fine
  826. if (isset($extra)) {
  827. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  828. $logs = get_logs('dovecot-mailcow', $extra);
  829. }
  830. else {
  831. $logs = get_logs('dovecot-mailcow');
  832. }
  833. if (isset($logs) && !empty($logs)) {
  834. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  835. }
  836. else {
  837. echo '{}';
  838. }
  839. break;
  840. case "fail2ban":
  841. // 0 is first record, so empty is fine
  842. if (isset($extra)) {
  843. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  844. $logs = get_logs('fail2ban-mailcow', $extra);
  845. }
  846. else {
  847. $logs = get_logs('fail2ban-mailcow');
  848. }
  849. if (isset($logs) && !empty($logs)) {
  850. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  851. }
  852. else {
  853. echo '{}';
  854. }
  855. break;
  856. case "postfix":
  857. // 0 is first record, so empty is fine
  858. if (isset($extra)) {
  859. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  860. $logs = get_logs('postfix-mailcow', $extra);
  861. }
  862. else {
  863. $logs = get_logs('postfix-mailcow');
  864. }
  865. if (isset($logs) && !empty($logs)) {
  866. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  867. }
  868. else {
  869. echo '{}';
  870. }
  871. break;
  872. case "autodiscover":
  873. // 0 is first record, so empty is fine
  874. if (isset($extra)) {
  875. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  876. $logs = get_logs('autodiscover-mailcow', $extra);
  877. }
  878. else {
  879. $logs = get_logs('autodiscover-mailcow');
  880. }
  881. if (isset($logs) && !empty($logs)) {
  882. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  883. }
  884. else {
  885. echo '{}';
  886. }
  887. break;
  888. case "sogo":
  889. // 0 is first record, so empty is fine
  890. if (isset($extra)) {
  891. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  892. $logs = get_logs('sogo-mailcow', $extra);
  893. }
  894. else {
  895. $logs = get_logs('sogo-mailcow');
  896. }
  897. if (isset($logs) && !empty($logs)) {
  898. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  899. }
  900. else {
  901. echo '{}';
  902. }
  903. break;
  904. case "watchdog":
  905. // 0 is first record, so empty is fine
  906. if (isset($extra)) {
  907. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  908. $logs = get_logs('watchdog-mailcow', $extra);
  909. }
  910. else {
  911. $logs = get_logs('watchdog-mailcow');
  912. }
  913. if (isset($logs) && !empty($logs)) {
  914. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  915. }
  916. else {
  917. echo '{}';
  918. }
  919. break;
  920. case "acme":
  921. // 0 is first record, so empty is fine
  922. if (isset($extra)) {
  923. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  924. $logs = get_logs('acme-mailcow', $extra);
  925. }
  926. else {
  927. $logs = get_logs('acme-mailcow');
  928. }
  929. if (isset($logs) && !empty($logs)) {
  930. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  931. }
  932. else {
  933. echo '{}';
  934. }
  935. break;
  936. case "api":
  937. // 0 is first record, so empty is fine
  938. if (isset($extra)) {
  939. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  940. $logs = get_logs('api-mailcow', $extra);
  941. }
  942. else {
  943. $logs = get_logs('api-mailcow');
  944. }
  945. if (isset($logs) && !empty($logs)) {
  946. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  947. }
  948. else {
  949. echo '{}';
  950. }
  951. break;
  952. case "rspamd-history":
  953. // 0 is first record, so empty is fine
  954. if (isset($extra)) {
  955. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  956. $logs = get_logs('rspamd-history', $extra);
  957. }
  958. else {
  959. $logs = get_logs('rspamd-history');
  960. }
  961. if (isset($logs) && !empty($logs)) {
  962. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  963. }
  964. else {
  965. echo '{}';
  966. }
  967. break;
  968. }
  969. break;
  970. case "mailbox":
  971. switch ($object) {
  972. case "all":
  973. $domains = mailbox('get', 'domains');
  974. if (!empty($domains)) {
  975. foreach ($domains as $domain) {
  976. $mailboxes = mailbox('get', 'mailboxes', $domain);
  977. if (!empty($mailboxes)) {
  978. foreach ($mailboxes as $mailbox) {
  979. if ($details = mailbox('get', 'mailbox_details', $mailbox)) {
  980. $data[] = $details;
  981. }
  982. else {
  983. continue;
  984. }
  985. }
  986. }
  987. }
  988. if (!isset($data) || empty($data)) {
  989. echo '{}';
  990. }
  991. else {
  992. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  993. }
  994. }
  995. else {
  996. echo '{}';
  997. }
  998. break;
  999. default:
  1000. $data = mailbox('get', 'mailbox_details', $object);
  1001. if (!isset($data) || empty($data)) {
  1002. echo '{}';
  1003. }
  1004. else {
  1005. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1006. }
  1007. break;
  1008. }
  1009. break;
  1010. case "syncjobs":
  1011. switch ($object) {
  1012. case "all":
  1013. $domains = mailbox('get', 'domains');
  1014. if (!empty($domains)) {
  1015. foreach ($domains as $domain) {
  1016. $mailboxes = mailbox('get', 'mailboxes', $domain);
  1017. if (!empty($mailboxes)) {
  1018. foreach ($mailboxes as $mailbox) {
  1019. $syncjobs = mailbox('get', 'syncjobs', $mailbox);
  1020. if (!empty($syncjobs)) {
  1021. foreach ($syncjobs as $syncjob) {
  1022. if (isset($extra)) {
  1023. $details = mailbox('get', 'syncjob_details', $syncjob, explode(',', $extra));
  1024. }
  1025. else {
  1026. $details = mailbox('get', 'syncjob_details', $syncjob);
  1027. }
  1028. if ($details) {
  1029. $data[] = $details;
  1030. }
  1031. else {
  1032. continue;
  1033. }
  1034. }
  1035. }
  1036. }
  1037. }
  1038. }
  1039. if (!isset($data) || empty($data)) {
  1040. echo '{}';
  1041. }
  1042. else {
  1043. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1044. }
  1045. }
  1046. else {
  1047. echo '{}';
  1048. }
  1049. break;
  1050. default:
  1051. $syncjobs = mailbox('get', 'syncjobs', $object);
  1052. if (!empty($syncjobs)) {
  1053. foreach ($syncjobs as $syncjob) {
  1054. if (isset($extra)) {
  1055. $details = mailbox('get', 'syncjob_details', $syncjob, explode(',', $extra));
  1056. }
  1057. else {
  1058. $details = mailbox('get', 'syncjob_details', $syncjob);
  1059. }
  1060. if ($details) {
  1061. $data[] = $details;
  1062. }
  1063. else {
  1064. continue;
  1065. }
  1066. }
  1067. }
  1068. if (!isset($data) || empty($data)) {
  1069. echo '{}';
  1070. }
  1071. else {
  1072. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1073. }
  1074. break;
  1075. }
  1076. break;
  1077. case "active-user-sieve":
  1078. if (isset($object)) {
  1079. $sieve_filter = mailbox('get', 'active_user_sieve', $object);
  1080. if (!empty($sieve_filter)) {
  1081. $data[] = $sieve_filter;
  1082. }
  1083. }
  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. case "filters":
  1092. switch ($object) {
  1093. case "all":
  1094. $domains = mailbox('get', 'domains');
  1095. if (!empty($domains)) {
  1096. foreach ($domains as $domain) {
  1097. $mailboxes = mailbox('get', 'mailboxes', $domain);
  1098. if (!empty($mailboxes)) {
  1099. foreach ($mailboxes as $mailbox) {
  1100. $filters = mailbox('get', 'filters', $mailbox);
  1101. if (!empty($filters)) {
  1102. foreach ($filters as $filter) {
  1103. if ($details = mailbox('get', 'filter_details', $filter)) {
  1104. $data[] = $details;
  1105. }
  1106. else {
  1107. continue;
  1108. }
  1109. }
  1110. }
  1111. }
  1112. }
  1113. }
  1114. if (!isset($data) || empty($data)) {
  1115. echo '{}';
  1116. }
  1117. else {
  1118. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1119. }
  1120. }
  1121. else {
  1122. echo '{}';
  1123. }
  1124. break;
  1125. default:
  1126. $filters = mailbox('get', 'filters', $object);
  1127. if (!empty($filters)) {
  1128. foreach ($filters as $filter) {
  1129. if ($details = mailbox('get', 'filter_details', $filter)) {
  1130. $data[] = $details;
  1131. }
  1132. else {
  1133. continue;
  1134. }
  1135. }
  1136. }
  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. }
  1145. break;
  1146. case "bcc":
  1147. switch ($object) {
  1148. case "all":
  1149. $bcc_items = bcc('get');
  1150. if (!empty($bcc_items)) {
  1151. foreach ($bcc_items as $bcc_item) {
  1152. if ($details = bcc('details', $bcc_item)) {
  1153. $data[] = $details;
  1154. }
  1155. else {
  1156. continue;
  1157. }
  1158. }
  1159. }
  1160. if (!isset($data) || empty($data)) {
  1161. echo '{}';
  1162. }
  1163. else {
  1164. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1165. }
  1166. break;
  1167. default:
  1168. $data = bcc('details', $object);
  1169. if (!empty($data)) {
  1170. $data[] = $details;
  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. break;
  1179. }
  1180. break;
  1181. case "policy_wl_mailbox":
  1182. switch ($object) {
  1183. default:
  1184. $data = policy('get', 'mailbox', $object)['whitelist'];
  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 "policy_bl_mailbox":
  1195. switch ($object) {
  1196. default:
  1197. $data = policy('get', 'mailbox', $object)['blacklist'];
  1198. if (!isset($data) || empty($data)) {
  1199. echo '{}';
  1200. }
  1201. else {
  1202. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1203. }
  1204. break;
  1205. }
  1206. break;
  1207. case "policy_wl_domain":
  1208. switch ($object) {
  1209. default:
  1210. $data = policy('get', 'domain', $object)['whitelist'];
  1211. if (!isset($data) || empty($data)) {
  1212. echo '{}';
  1213. }
  1214. else {
  1215. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1216. }
  1217. break;
  1218. }
  1219. break;
  1220. case "policy_bl_domain":
  1221. switch ($object) {
  1222. default:
  1223. $data = policy('get', 'domain', $object)['blacklist'];
  1224. if (!isset($data) || empty($data)) {
  1225. echo '{}';
  1226. }
  1227. else {
  1228. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1229. }
  1230. break;
  1231. }
  1232. break;
  1233. case "time_limited_aliases":
  1234. switch ($object) {
  1235. default:
  1236. $data = mailbox('get', 'time_limited_aliases', $object);
  1237. if (!isset($data) || empty($data)) {
  1238. echo '{}';
  1239. }
  1240. else {
  1241. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1242. }
  1243. break;
  1244. }
  1245. break;
  1246. case "resource":
  1247. switch ($object) {
  1248. case "all":
  1249. $domains = mailbox('get', 'domains');
  1250. if (!empty($domains)) {
  1251. foreach ($domains as $domain) {
  1252. $resources = mailbox('get', 'resources', $domain);
  1253. if (!empty($resources)) {
  1254. foreach ($resources as $resource) {
  1255. if ($details = mailbox('get', 'resource_details', $resource)) {
  1256. $data[] = $details;
  1257. }
  1258. else {
  1259. continue;
  1260. }
  1261. }
  1262. }
  1263. }
  1264. if (!isset($data) || empty($data)) {
  1265. echo '{}';
  1266. }
  1267. else {
  1268. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1269. }
  1270. }
  1271. else {
  1272. echo '{}';
  1273. }
  1274. break;
  1275. default:
  1276. $data = mailbox('get', 'resource_details', $object);
  1277. if (!isset($data) || empty($data)) {
  1278. echo '{}';
  1279. }
  1280. else {
  1281. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1282. }
  1283. break;
  1284. }
  1285. break;
  1286. case "fwdhost":
  1287. switch ($object) {
  1288. case "all":
  1289. $data = fwdhost('get');
  1290. if (!isset($data) || empty($data)) {
  1291. echo '{}';
  1292. }
  1293. else {
  1294. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1295. }
  1296. break;
  1297. default:
  1298. $data = fwdhost('details', $object);
  1299. if (!isset($data) || empty($data)) {
  1300. echo '{}';
  1301. }
  1302. else {
  1303. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1304. }
  1305. break;
  1306. }
  1307. break;
  1308. case "quarantaine":
  1309. // "all" will not print details
  1310. switch ($object) {
  1311. case "all":
  1312. $data = quarantaine('get');
  1313. if (!isset($data) || empty($data)) {
  1314. echo '{}';
  1315. }
  1316. else {
  1317. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1318. }
  1319. break;
  1320. default:
  1321. $data = quarantaine('details', $object);
  1322. if (!isset($data) || empty($data)) {
  1323. echo '{}';
  1324. }
  1325. else {
  1326. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1327. }
  1328. break;
  1329. }
  1330. break;
  1331. case "alias-domain":
  1332. switch ($object) {
  1333. case "all":
  1334. $alias_domains = mailbox('get', 'alias_domains');
  1335. if (!empty($alias_domains)) {
  1336. foreach ($alias_domains as $alias_domain) {
  1337. if ($details = mailbox('get', 'alias_domain_details', $alias_domain)) {
  1338. $data[] = $details;
  1339. }
  1340. else {
  1341. continue;
  1342. }
  1343. }
  1344. }
  1345. if (!isset($data) || empty($data)) {
  1346. echo '{}';
  1347. }
  1348. else {
  1349. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1350. }
  1351. break;
  1352. default:
  1353. $data = mailbox('get', 'alias_domain_details', $object);
  1354. if (!isset($data) || empty($data)) {
  1355. echo '{}';
  1356. }
  1357. else {
  1358. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1359. }
  1360. break;
  1361. }
  1362. break;
  1363. case "alias":
  1364. switch ($object) {
  1365. case "all":
  1366. $domains = array_merge(mailbox('get', 'domains'),mailbox('get', 'alias_domains'));
  1367. if (!empty($domains)) {
  1368. foreach ($domains as $domain) {
  1369. $aliases = mailbox('get', 'aliases', $domain);
  1370. if (!empty($aliases)) {
  1371. foreach ($aliases as $alias) {
  1372. if ($details = mailbox('get', 'alias_details', $alias)) {
  1373. $data[] = $details;
  1374. }
  1375. else {
  1376. continue;
  1377. }
  1378. }
  1379. }
  1380. }
  1381. if (!isset($data) || empty($data)) {
  1382. echo '{}';
  1383. }
  1384. else {
  1385. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1386. }
  1387. }
  1388. else {
  1389. echo '{}';
  1390. }
  1391. break;
  1392. default:
  1393. $data = mailbox('get', 'alias_details', $object);
  1394. if (!isset($data) || empty($data)) {
  1395. echo '{}';
  1396. }
  1397. else {
  1398. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1399. }
  1400. break;
  1401. }
  1402. break;
  1403. case "domain-admin":
  1404. switch ($object) {
  1405. case "all":
  1406. $domain_admins = domain_admin('get');
  1407. if (!empty($domain_admins)) {
  1408. foreach ($domain_admins as $domain_admin) {
  1409. if ($details = domain_admin('details', $domain_admin)) {
  1410. $data[] = $details;
  1411. }
  1412. else {
  1413. continue;
  1414. }
  1415. }
  1416. if (!isset($data) || empty($data)) {
  1417. echo '{}';
  1418. }
  1419. else {
  1420. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1421. }
  1422. }
  1423. else {
  1424. echo '{}';
  1425. }
  1426. break;
  1427. default:
  1428. $data = domain_admin('details', $object);
  1429. if (!isset($data) || empty($data)) {
  1430. echo '{}';
  1431. }
  1432. else {
  1433. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1434. }
  1435. break;
  1436. }
  1437. break;
  1438. case "u2f-registration":
  1439. header('Content-Type: application/javascript');
  1440. if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
  1441. $data = $u2f->getRegisterData(get_u2f_registrations($object));
  1442. list($req, $sigs) = $data;
  1443. $_SESSION['regReq'] = json_encode($req);
  1444. echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';';
  1445. }
  1446. else {
  1447. return;
  1448. }
  1449. break;
  1450. case "u2f-authentication":
  1451. header('Content-Type: application/javascript');
  1452. if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
  1453. $reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
  1454. $_SESSION['authReq'] = $reqs;
  1455. echo 'var req = ' . $reqs . ';';
  1456. }
  1457. else {
  1458. return;
  1459. }
  1460. break;
  1461. default:
  1462. echo '{}';
  1463. break;
  1464. }
  1465. break;
  1466. case "delete":
  1467. switch ($category) {
  1468. case "alias":
  1469. if (isset($_POST['items'])) {
  1470. $items = (array)json_decode($_POST['items'], true);
  1471. if (is_array($items)) {
  1472. if (mailbox('delete', 'alias', array('address' => $items)) === false) {
  1473. if (isset($_SESSION['return'])) {
  1474. echo json_encode($_SESSION['return']);
  1475. }
  1476. else {
  1477. echo json_encode(array(
  1478. 'type' => 'error',
  1479. 'msg' => 'Deletion of items/s failed'
  1480. ));
  1481. }
  1482. }
  1483. else {
  1484. if (isset($_SESSION['return'])) {
  1485. echo json_encode($_SESSION['return']);
  1486. }
  1487. else {
  1488. echo json_encode(array(
  1489. 'type' => 'success',
  1490. 'msg' => 'Task completed'
  1491. ));
  1492. }
  1493. }
  1494. }
  1495. else {
  1496. echo json_encode(array(
  1497. 'type' => 'error',
  1498. 'msg' => 'Cannot find address array in post data'
  1499. ));
  1500. }
  1501. }
  1502. else {
  1503. echo json_encode(array(
  1504. 'type' => 'error',
  1505. 'msg' => 'Cannot find items in post data'
  1506. ));
  1507. }
  1508. break;
  1509. case "relayhost":
  1510. if (isset($_POST['items'])) {
  1511. $items = (array)json_decode($_POST['items'], true);
  1512. if (is_array($items)) {
  1513. if (relayhost('delete', array('id' => $items)) === false) {
  1514. if (isset($_SESSION['return'])) {
  1515. echo json_encode($_SESSION['return']);
  1516. }
  1517. else {
  1518. echo json_encode(array(
  1519. 'type' => 'error',
  1520. 'msg' => 'Deletion of items/s failed'
  1521. ));
  1522. }
  1523. }
  1524. else {
  1525. if (isset($_SESSION['return'])) {
  1526. echo json_encode($_SESSION['return']);
  1527. }
  1528. else {
  1529. echo json_encode(array(
  1530. 'type' => 'success',
  1531. 'msg' => 'Task completed'
  1532. ));
  1533. }
  1534. }
  1535. }
  1536. else {
  1537. echo json_encode(array(
  1538. 'type' => 'error',
  1539. 'msg' => 'Cannot find id array in post data'
  1540. ));
  1541. }
  1542. }
  1543. else {
  1544. echo json_encode(array(
  1545. 'type' => 'error',
  1546. 'msg' => 'Cannot find items in post data'
  1547. ));
  1548. }
  1549. break;
  1550. case "syncjob":
  1551. if (isset($_POST['items'])) {
  1552. $items = (array)json_decode($_POST['items'], true);
  1553. if (is_array($items)) {
  1554. if (mailbox('delete', 'syncjob', array('id' => $items)) === false) {
  1555. if (isset($_SESSION['return'])) {
  1556. echo json_encode($_SESSION['return']);
  1557. }
  1558. else {
  1559. echo json_encode(array(
  1560. 'type' => 'error',
  1561. 'msg' => 'Deletion of items/s failed'
  1562. ));
  1563. }
  1564. }
  1565. else {
  1566. if (isset($_SESSION['return'])) {
  1567. echo json_encode($_SESSION['return']);
  1568. }
  1569. else {
  1570. echo json_encode(array(
  1571. 'type' => 'success',
  1572. 'msg' => 'Task completed'
  1573. ));
  1574. }
  1575. }
  1576. }
  1577. else {
  1578. echo json_encode(array(
  1579. 'type' => 'error',
  1580. 'msg' => 'Cannot find id array in post data'
  1581. ));
  1582. }
  1583. }
  1584. else {
  1585. echo json_encode(array(
  1586. 'type' => 'error',
  1587. 'msg' => 'Cannot find items in post data'
  1588. ));
  1589. }
  1590. break;
  1591. case "filter":
  1592. if (isset($_POST['items'])) {
  1593. $items = (array)json_decode($_POST['items'], true);
  1594. if (is_array($items)) {
  1595. if (mailbox('delete', 'filter', array('id' => $items)) === false) {
  1596. if (isset($_SESSION['return'])) {
  1597. echo json_encode($_SESSION['return']);
  1598. }
  1599. else {
  1600. echo json_encode(array(
  1601. 'type' => 'error',
  1602. 'msg' => 'Deletion of items/s failed'
  1603. ));
  1604. }
  1605. }
  1606. else {
  1607. if (isset($_SESSION['return'])) {
  1608. echo json_encode($_SESSION['return']);
  1609. }
  1610. else {
  1611. echo json_encode(array(
  1612. 'type' => 'success',
  1613. 'msg' => 'Task completed'
  1614. ));
  1615. }
  1616. }
  1617. }
  1618. else {
  1619. echo json_encode(array(
  1620. 'type' => 'error',
  1621. 'msg' => 'Cannot find id array in post data'
  1622. ));
  1623. }
  1624. }
  1625. else {
  1626. echo json_encode(array(
  1627. 'type' => 'error',
  1628. 'msg' => 'Cannot find items in post data'
  1629. ));
  1630. }
  1631. break;
  1632. case "qitem":
  1633. if (isset($_POST['items'])) {
  1634. $items = (array)json_decode($_POST['items'], true);
  1635. if (is_array($items)) {
  1636. if (quarantaine('delete', array('id' => $items)) === false) {
  1637. if (isset($_SESSION['return'])) {
  1638. echo json_encode($_SESSION['return']);
  1639. }
  1640. else {
  1641. echo json_encode(array(
  1642. 'type' => 'error',
  1643. 'msg' => 'Deletion of items/s failed'
  1644. ));
  1645. }
  1646. }
  1647. else {
  1648. if (isset($_SESSION['return'])) {
  1649. echo json_encode($_SESSION['return']);
  1650. }
  1651. else {
  1652. echo json_encode(array(
  1653. 'type' => 'success',
  1654. 'msg' => 'Task completed'
  1655. ));
  1656. }
  1657. }
  1658. }
  1659. else {
  1660. echo json_encode(array(
  1661. 'type' => 'error',
  1662. 'msg' => 'Cannot find id array in post data'
  1663. ));
  1664. }
  1665. }
  1666. else {
  1667. echo json_encode(array(
  1668. 'type' => 'error',
  1669. 'msg' => 'Cannot find items in post data'
  1670. ));
  1671. }
  1672. break;
  1673. case "bcc":
  1674. if (isset($_POST['items'])) {
  1675. $items = (array)json_decode($_POST['items'], true);
  1676. if (is_array($items)) {
  1677. if (bcc('delete', array('id' => $items)) === false) {
  1678. if (isset($_SESSION['return'])) {
  1679. echo json_encode($_SESSION['return']);
  1680. }
  1681. else {
  1682. echo json_encode(array(
  1683. 'type' => 'error',
  1684. 'msg' => 'Deletion of items/s failed'
  1685. ));
  1686. }
  1687. }
  1688. else {
  1689. if (isset($_SESSION['return'])) {
  1690. echo json_encode($_SESSION['return']);
  1691. }
  1692. else {
  1693. echo json_encode(array(
  1694. 'type' => 'success',
  1695. 'msg' => 'Task completed'
  1696. ));
  1697. }
  1698. }
  1699. }
  1700. else {
  1701. echo json_encode(array(
  1702. 'type' => 'error',
  1703. 'msg' => 'Cannot find id array in post data'
  1704. ));
  1705. }
  1706. }
  1707. else {
  1708. echo json_encode(array(
  1709. 'type' => 'error',
  1710. 'msg' => 'Cannot find items in post data'
  1711. ));
  1712. }
  1713. break;
  1714. case "fwdhost":
  1715. if (isset($_POST['items'])) {
  1716. $items = (array)json_decode($_POST['items'], true);
  1717. if (is_array($items)) {
  1718. if (fwdhost('delete', array('forwardinghost' => $items)) === false) {
  1719. if (isset($_SESSION['return'])) {
  1720. echo json_encode($_SESSION['return']);
  1721. }
  1722. else {
  1723. echo json_encode(array(
  1724. 'type' => 'error',
  1725. 'msg' => 'Deletion of items/s failed'
  1726. ));
  1727. }
  1728. }
  1729. else {
  1730. if (isset($_SESSION['return'])) {
  1731. echo json_encode($_SESSION['return']);
  1732. }
  1733. else {
  1734. echo json_encode(array(
  1735. 'type' => 'success',
  1736. 'msg' => 'Task completed'
  1737. ));
  1738. }
  1739. }
  1740. }
  1741. else {
  1742. echo json_encode(array(
  1743. 'type' => 'error',
  1744. 'msg' => 'Cannot find forwardinghost array in post data'
  1745. ));
  1746. }
  1747. }
  1748. else {
  1749. echo json_encode(array(
  1750. 'type' => 'error',
  1751. 'msg' => 'Cannot find items in post data'
  1752. ));
  1753. }
  1754. break;
  1755. case "dkim":
  1756. if (isset($_POST['items'])) {
  1757. $items = (array)json_decode($_POST['items'], true);
  1758. if (is_array($items)) {
  1759. if (dkim('delete', array('domains' => $items)) === false) {
  1760. if (isset($_SESSION['return'])) {
  1761. echo json_encode($_SESSION['return']);
  1762. }
  1763. else {
  1764. echo json_encode(array(
  1765. 'type' => 'error',
  1766. 'msg' => 'Deletion of items/s failed'
  1767. ));
  1768. }
  1769. }
  1770. else {
  1771. if (isset($_SESSION['return'])) {
  1772. echo json_encode($_SESSION['return']);
  1773. }
  1774. else {
  1775. echo json_encode(array(
  1776. 'type' => 'success',
  1777. 'msg' => 'Task completed'
  1778. ));
  1779. }
  1780. }
  1781. }
  1782. else {
  1783. echo json_encode(array(
  1784. 'type' => 'error',
  1785. 'msg' => 'Cannot find domains array in post data'
  1786. ));
  1787. }
  1788. }
  1789. else {
  1790. echo json_encode(array(
  1791. 'type' => 'error',
  1792. 'msg' => 'Cannot find items in post data'
  1793. ));
  1794. }
  1795. break;
  1796. case "domain":
  1797. if (isset($_POST['items'])) {
  1798. $items = (array)json_decode($_POST['items'], true);
  1799. if (is_array($items)) {
  1800. if (mailbox('delete', 'domain', array('domain' => $items)) === false) {
  1801. if (isset($_SESSION['return'])) {
  1802. echo json_encode($_SESSION['return']);
  1803. }
  1804. else {
  1805. echo json_encode(array(
  1806. 'type' => 'error',
  1807. 'msg' => 'Task failed'
  1808. ));
  1809. }
  1810. }
  1811. else {
  1812. if (isset($_SESSION['return'])) {
  1813. echo json_encode($_SESSION['return']);
  1814. }
  1815. else {
  1816. echo json_encode(array(
  1817. 'type' => 'success',
  1818. 'msg' => 'Task completed'
  1819. ));
  1820. }
  1821. }
  1822. }
  1823. else {
  1824. echo json_encode(array(
  1825. 'type' => 'error',
  1826. 'msg' => 'Cannot find domain array in post data'
  1827. ));
  1828. }
  1829. }
  1830. else {
  1831. echo json_encode(array(
  1832. 'type' => 'error',
  1833. 'msg' => 'Cannot find items in post data'
  1834. ));
  1835. }
  1836. break;
  1837. case "alias-domain":
  1838. if (isset($_POST['items'])) {
  1839. $items = (array)json_decode($_POST['items'], true);
  1840. if (is_array($items)) {
  1841. if (mailbox('delete', 'alias_domain', array('alias_domain' => $items)) === false) {
  1842. if (isset($_SESSION['return'])) {
  1843. echo json_encode($_SESSION['return']);
  1844. }
  1845. else {
  1846. echo json_encode(array(
  1847. 'type' => 'error',
  1848. 'msg' => 'Task failed'
  1849. ));
  1850. }
  1851. }
  1852. else {
  1853. if (isset($_SESSION['return'])) {
  1854. echo json_encode($_SESSION['return']);
  1855. }
  1856. else {
  1857. echo json_encode(array(
  1858. 'type' => 'success',
  1859. 'msg' => 'Task completed'
  1860. ));
  1861. }
  1862. }
  1863. }
  1864. else {
  1865. echo json_encode(array(
  1866. 'type' => 'error',
  1867. 'msg' => 'Cannot find alias_domain array in post data'
  1868. ));
  1869. }
  1870. }
  1871. else {
  1872. echo json_encode(array(
  1873. 'type' => 'error',
  1874. 'msg' => 'Cannot find items in post data'
  1875. ));
  1876. }
  1877. break;
  1878. case "mailbox":
  1879. if (isset($_POST['items'])) {
  1880. $items = (array)json_decode($_POST['items'], true);
  1881. if (is_array($items)) {
  1882. if (mailbox('delete', 'mailbox', array('username' => $items)) === false) {
  1883. if (isset($_SESSION['return'])) {
  1884. echo json_encode($_SESSION['return']);
  1885. }
  1886. else {
  1887. echo json_encode(array(
  1888. 'type' => 'error',
  1889. 'msg' => 'Task failed'
  1890. ));
  1891. }
  1892. }
  1893. else {
  1894. if (isset($_SESSION['return'])) {
  1895. echo json_encode($_SESSION['return']);
  1896. }
  1897. else {
  1898. echo json_encode(array(
  1899. 'type' => 'success',
  1900. 'msg' => 'Task completed'
  1901. ));
  1902. }
  1903. }
  1904. }
  1905. else {
  1906. echo json_encode(array(
  1907. 'type' => 'error',
  1908. 'msg' => 'Cannot find username array in post data'
  1909. ));
  1910. }
  1911. }
  1912. else {
  1913. echo json_encode(array(
  1914. 'type' => 'error',
  1915. 'msg' => 'Cannot find items in post data'
  1916. ));
  1917. }
  1918. break;
  1919. case "resource":
  1920. if (isset($_POST['items'])) {
  1921. $items = (array)json_decode($_POST['items'], true);
  1922. if (is_array($items)) {
  1923. if (mailbox('delete', 'resource', array('name' => $items)) === false) {
  1924. if (isset($_SESSION['return'])) {
  1925. echo json_encode($_SESSION['return']);
  1926. }
  1927. else {
  1928. echo json_encode(array(
  1929. 'type' => 'error',
  1930. 'msg' => 'Task failed'
  1931. ));
  1932. }
  1933. }
  1934. else {
  1935. if (isset($_SESSION['return'])) {
  1936. echo json_encode($_SESSION['return']);
  1937. }
  1938. else {
  1939. echo json_encode(array(
  1940. 'type' => 'success',
  1941. 'msg' => 'Task completed'
  1942. ));
  1943. }
  1944. }
  1945. }
  1946. else {
  1947. echo json_encode(array(
  1948. 'type' => 'error',
  1949. 'msg' => 'Cannot find name array in post data'
  1950. ));
  1951. }
  1952. }
  1953. else {
  1954. echo json_encode(array(
  1955. 'type' => 'error',
  1956. 'msg' => 'Cannot find items in post data'
  1957. ));
  1958. }
  1959. break;
  1960. case "mailbox-policy":
  1961. if (isset($_POST['items'])) {
  1962. $items = (array)json_decode($_POST['items'], true);
  1963. if (is_array($items)) {
  1964. if (policy('delete', 'mailbox', array('prefid' => $items)) === false) {
  1965. if (isset($_SESSION['return'])) {
  1966. echo json_encode($_SESSION['return']);
  1967. }
  1968. else {
  1969. echo json_encode(array(
  1970. 'type' => 'error',
  1971. 'msg' => 'Task failed'
  1972. ));
  1973. }
  1974. }
  1975. else {
  1976. if (isset($_SESSION['return'])) {
  1977. echo json_encode($_SESSION['return']);
  1978. }
  1979. else {
  1980. echo json_encode(array(
  1981. 'type' => 'success',
  1982. 'msg' => 'Task completed'
  1983. ));
  1984. }
  1985. }
  1986. }
  1987. else {
  1988. echo json_encode(array(
  1989. 'type' => 'error',
  1990. 'msg' => 'Cannot find name array in post data'
  1991. ));
  1992. }
  1993. }
  1994. else {
  1995. echo json_encode(array(
  1996. 'type' => 'error',
  1997. 'msg' => 'Cannot find items in post data'
  1998. ));
  1999. }
  2000. break;
  2001. case "domain-policy":
  2002. if (isset($_POST['items'])) {
  2003. $items = (array)json_decode($_POST['items'], true);
  2004. if (is_array($items)) {
  2005. if (policy('delete', 'domain', array('prefid' => $items)) === false) {
  2006. if (isset($_SESSION['return'])) {
  2007. echo json_encode($_SESSION['return']);
  2008. }
  2009. else {
  2010. echo json_encode(array(
  2011. 'type' => 'error',
  2012. 'msg' => 'Task failed'
  2013. ));
  2014. }
  2015. }
  2016. else {
  2017. if (isset($_SESSION['return'])) {
  2018. echo json_encode($_SESSION['return']);
  2019. }
  2020. else {
  2021. echo json_encode(array(
  2022. 'type' => 'success',
  2023. 'msg' => 'Task completed'
  2024. ));
  2025. }
  2026. }
  2027. }
  2028. else {
  2029. echo json_encode(array(
  2030. 'type' => 'error',
  2031. 'msg' => 'Cannot find name array in post data'
  2032. ));
  2033. }
  2034. }
  2035. else {
  2036. echo json_encode(array(
  2037. 'type' => 'error',
  2038. 'msg' => 'Cannot find items in post data'
  2039. ));
  2040. }
  2041. break;
  2042. case "time_limited_alias":
  2043. if (isset($_POST['items'])) {
  2044. $items = (array)json_decode($_POST['items'], true);
  2045. if (is_array($items)) {
  2046. if (mailbox('delete', 'time_limited_alias', array('address' => $items)) === false) {
  2047. if (isset($_SESSION['return'])) {
  2048. echo json_encode($_SESSION['return']);
  2049. }
  2050. else {
  2051. echo json_encode(array(
  2052. 'type' => 'error',
  2053. 'msg' => 'Task failed'
  2054. ));
  2055. }
  2056. }
  2057. else {
  2058. if (isset($_SESSION['return'])) {
  2059. echo json_encode($_SESSION['return']);
  2060. }
  2061. else {
  2062. echo json_encode(array(
  2063. 'type' => 'success',
  2064. 'msg' => 'Task completed'
  2065. ));
  2066. }
  2067. }
  2068. }
  2069. else {
  2070. echo json_encode(array(
  2071. 'type' => 'error',
  2072. 'msg' => 'Cannot find name array in post data'
  2073. ));
  2074. }
  2075. }
  2076. else {
  2077. echo json_encode(array(
  2078. 'type' => 'error',
  2079. 'msg' => 'Cannot find items in post data'
  2080. ));
  2081. }
  2082. break;
  2083. case "eas_cache":
  2084. if (isset($_POST['items'])) {
  2085. $items = (array)json_decode($_POST['items'], true);
  2086. if (is_array($items)) {
  2087. if (mailbox('delete', 'eas_cache', array('username' => $items)) === false) {
  2088. if (isset($_SESSION['return'])) {
  2089. echo json_encode($_SESSION['return']);
  2090. }
  2091. else {
  2092. echo json_encode(array(
  2093. 'type' => 'error',
  2094. 'msg' => 'Task failed'
  2095. ));
  2096. }
  2097. }
  2098. else {
  2099. if (isset($_SESSION['return'])) {
  2100. echo json_encode($_SESSION['return']);
  2101. }
  2102. else {
  2103. echo json_encode(array(
  2104. 'type' => 'success',
  2105. 'msg' => 'Task completed'
  2106. ));
  2107. }
  2108. }
  2109. }
  2110. else {
  2111. echo json_encode(array(
  2112. 'type' => 'error',
  2113. 'msg' => 'Cannot find name array in post data'
  2114. ));
  2115. }
  2116. }
  2117. else {
  2118. echo json_encode(array(
  2119. 'type' => 'error',
  2120. 'msg' => 'Cannot find items in post data'
  2121. ));
  2122. }
  2123. break;
  2124. case "domain-admin":
  2125. if (isset($_POST['items'])) {
  2126. $items = (array)json_decode($_POST['items'], true);
  2127. if (is_array($items)) {
  2128. if (domain_admin('delete', array('username' => $items)) === false) {
  2129. if (isset($_SESSION['return'])) {
  2130. echo json_encode($_SESSION['return']);
  2131. }
  2132. else {
  2133. echo json_encode(array(
  2134. 'type' => 'error',
  2135. 'msg' => 'Task failed'
  2136. ));
  2137. }
  2138. }
  2139. else {
  2140. if (isset($_SESSION['return'])) {
  2141. echo json_encode($_SESSION['return']);
  2142. }
  2143. else {
  2144. echo json_encode(array(
  2145. 'type' => 'success',
  2146. 'msg' => 'Task completed'
  2147. ));
  2148. }
  2149. }
  2150. }
  2151. else {
  2152. echo json_encode(array(
  2153. 'type' => 'error',
  2154. 'msg' => 'Cannot find name array in post data'
  2155. ));
  2156. }
  2157. }
  2158. else {
  2159. echo json_encode(array(
  2160. 'type' => 'error',
  2161. 'msg' => 'Cannot find items in post data'
  2162. ));
  2163. }
  2164. break;
  2165. }
  2166. break;
  2167. case "edit":
  2168. switch ($category) {
  2169. case "bcc":
  2170. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2171. $items = (array)json_decode($_POST['items'], true);
  2172. $attr = (array)json_decode($_POST['attr'], true);
  2173. $postarray = array_merge(array('id' => $items), $attr);
  2174. if (is_array($postarray['id'])) {
  2175. if (bcc('edit', $postarray) === false) {
  2176. if (isset($_SESSION['return'])) {
  2177. echo json_encode($_SESSION['return']);
  2178. }
  2179. else {
  2180. echo json_encode(array(
  2181. 'type' => 'error',
  2182. 'msg' => 'Edit failed'
  2183. ));
  2184. }
  2185. exit();
  2186. }
  2187. else {
  2188. if (isset($_SESSION['return'])) {
  2189. echo json_encode($_SESSION['return']);
  2190. }
  2191. else {
  2192. echo json_encode(array(
  2193. 'type' => 'success',
  2194. 'msg' => 'Task completed'
  2195. ));
  2196. }
  2197. }
  2198. }
  2199. else {
  2200. echo json_encode(array(
  2201. 'type' => 'error',
  2202. 'msg' => 'Incomplete post data'
  2203. ));
  2204. }
  2205. }
  2206. else {
  2207. echo json_encode(array(
  2208. 'type' => 'error',
  2209. 'msg' => 'Incomplete post data'
  2210. ));
  2211. }
  2212. break;
  2213. case "alias":
  2214. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2215. $items = (array)json_decode($_POST['items'], true);
  2216. $attr = (array)json_decode($_POST['attr'], true);
  2217. $postarray = array_merge(array('address' => $items), $attr);
  2218. if (is_array($postarray['address'])) {
  2219. if (mailbox('edit', 'alias', $postarray) === false) {
  2220. if (isset($_SESSION['return'])) {
  2221. echo json_encode($_SESSION['return']);
  2222. }
  2223. else {
  2224. echo json_encode(array(
  2225. 'type' => 'error',
  2226. 'msg' => 'Edit failed'
  2227. ));
  2228. }
  2229. exit();
  2230. }
  2231. else {
  2232. if (isset($_SESSION['return'])) {
  2233. echo json_encode($_SESSION['return']);
  2234. }
  2235. else {
  2236. echo json_encode(array(
  2237. 'type' => 'success',
  2238. 'msg' => 'Task completed'
  2239. ));
  2240. }
  2241. }
  2242. }
  2243. else {
  2244. echo json_encode(array(
  2245. 'type' => 'error',
  2246. 'msg' => 'Incomplete post data'
  2247. ));
  2248. }
  2249. }
  2250. else {
  2251. echo json_encode(array(
  2252. 'type' => 'error',
  2253. 'msg' => 'Incomplete post data'
  2254. ));
  2255. }
  2256. break;
  2257. case "app_links":
  2258. if (isset($_POST['attr'])) {
  2259. $attr = (array)json_decode($_POST['attr'], true);
  2260. if (is_array($attr)) {
  2261. if (customize('edit', 'app_links', $attr) === false) {
  2262. if (isset($_SESSION['return'])) {
  2263. echo json_encode($_SESSION['return']);
  2264. }
  2265. else {
  2266. echo json_encode(array(
  2267. 'type' => 'error',
  2268. 'msg' => 'Edit failed'
  2269. ));
  2270. }
  2271. exit();
  2272. }
  2273. else {
  2274. if (isset($_SESSION['return'])) {
  2275. echo json_encode($_SESSION['return']);
  2276. }
  2277. else {
  2278. echo json_encode(array(
  2279. 'type' => 'success',
  2280. 'msg' => 'Task completed'
  2281. ));
  2282. }
  2283. }
  2284. }
  2285. else {
  2286. echo json_encode(array(
  2287. 'type' => 'error',
  2288. 'msg' => 'Incomplete post data'
  2289. ));
  2290. }
  2291. }
  2292. else {
  2293. echo json_encode(array(
  2294. 'type' => 'error',
  2295. 'msg' => 'Incomplete post data'
  2296. ));
  2297. }
  2298. break;
  2299. case "relayhost":
  2300. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2301. $items = (array)json_decode($_POST['items'], true);
  2302. $attr = (array)json_decode($_POST['attr'], true);
  2303. $postarray = array_merge(array('id' => $items), $attr);
  2304. if (is_array($postarray['id'])) {
  2305. if (relayhost('edit', $postarray) === false) {
  2306. if (isset($_SESSION['return'])) {
  2307. echo json_encode($_SESSION['return']);
  2308. }
  2309. else {
  2310. echo json_encode(array(
  2311. 'type' => 'error',
  2312. 'msg' => 'Edit failed'
  2313. ));
  2314. }
  2315. exit();
  2316. }
  2317. else {
  2318. if (isset($_SESSION['return'])) {
  2319. echo json_encode($_SESSION['return']);
  2320. }
  2321. else {
  2322. echo json_encode(array(
  2323. 'type' => 'success',
  2324. 'msg' => 'Task completed'
  2325. ));
  2326. }
  2327. }
  2328. }
  2329. else {
  2330. echo json_encode(array(
  2331. 'type' => 'error',
  2332. 'msg' => 'Incomplete post data'
  2333. ));
  2334. }
  2335. }
  2336. else {
  2337. echo json_encode(array(
  2338. 'type' => 'error',
  2339. 'msg' => 'Incomplete post data'
  2340. ));
  2341. }
  2342. break;
  2343. case "delimiter_action":
  2344. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2345. $items = (array)json_decode($_POST['items'], true);
  2346. $attr = (array)json_decode($_POST['attr'], true);
  2347. $postarray = array_merge(array('username' => $items), $attr);
  2348. if (is_array($postarray['username'])) {
  2349. if (mailbox('edit', 'delimiter_action', $postarray) === false) {
  2350. if (isset($_SESSION['return'])) {
  2351. echo json_encode($_SESSION['return']);
  2352. }
  2353. else {
  2354. echo json_encode(array(
  2355. 'type' => 'error',
  2356. 'msg' => 'Edit failed'
  2357. ));
  2358. }
  2359. exit();
  2360. }
  2361. else {
  2362. if (isset($_SESSION['return'])) {
  2363. echo json_encode($_SESSION['return']);
  2364. }
  2365. else {
  2366. echo json_encode(array(
  2367. 'type' => 'success',
  2368. 'msg' => 'Task completed'
  2369. ));
  2370. }
  2371. }
  2372. }
  2373. else {
  2374. echo json_encode(array(
  2375. 'type' => 'error',
  2376. 'msg' => 'Incomplete post data'
  2377. ));
  2378. }
  2379. }
  2380. else {
  2381. echo json_encode(array(
  2382. 'type' => 'error',
  2383. 'msg' => 'Incomplete post data'
  2384. ));
  2385. }
  2386. break;
  2387. case "tls_policy":
  2388. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2389. $items = (array)json_decode($_POST['items'], true);
  2390. $attr = (array)json_decode($_POST['attr'], true);
  2391. $postarray = array_merge(array('username' => $items), $attr);
  2392. if (is_array($postarray['username'])) {
  2393. if (mailbox('edit', 'tls_policy', $postarray) === false) {
  2394. if (isset($_SESSION['return'])) {
  2395. echo json_encode($_SESSION['return']);
  2396. }
  2397. else {
  2398. echo json_encode(array(
  2399. 'type' => 'error',
  2400. 'msg' => 'Edit failed'
  2401. ));
  2402. }
  2403. exit();
  2404. }
  2405. else {
  2406. if (isset($_SESSION['return'])) {
  2407. echo json_encode($_SESSION['return']);
  2408. }
  2409. else {
  2410. echo json_encode(array(
  2411. 'type' => 'success',
  2412. 'msg' => 'Task completed'
  2413. ));
  2414. }
  2415. }
  2416. }
  2417. else {
  2418. echo json_encode(array(
  2419. 'type' => 'error',
  2420. 'msg' => 'Incomplete post data'
  2421. ));
  2422. }
  2423. }
  2424. else {
  2425. echo json_encode(array(
  2426. 'type' => 'error',
  2427. 'msg' => 'Incomplete post data'
  2428. ));
  2429. }
  2430. break;
  2431. case "qitem":
  2432. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2433. $items = (array)json_decode($_POST['items'], true);
  2434. $attr = (array)json_decode($_POST['attr'], true);
  2435. $postarray = array_merge(array('id' => $items), $attr);
  2436. if (is_array($postarray['id'])) {
  2437. if (quarantaine('edit', $postarray) === false) {
  2438. if (isset($_SESSION['return'])) {
  2439. echo json_encode($_SESSION['return']);
  2440. }
  2441. else {
  2442. echo json_encode(array(
  2443. 'type' => 'error',
  2444. 'msg' => 'Edit failed'
  2445. ));
  2446. }
  2447. exit();
  2448. }
  2449. else {
  2450. if (isset($_SESSION['return'])) {
  2451. echo json_encode($_SESSION['return']);
  2452. }
  2453. else {
  2454. echo json_encode(array(
  2455. 'type' => 'success',
  2456. 'msg' => 'Task completed'
  2457. ));
  2458. }
  2459. }
  2460. }
  2461. else {
  2462. echo json_encode(array(
  2463. 'type' => 'error',
  2464. 'msg' => 'Incomplete post data'
  2465. ));
  2466. }
  2467. }
  2468. else {
  2469. echo json_encode(array(
  2470. 'type' => 'error',
  2471. 'msg' => 'Incomplete post data'
  2472. ));
  2473. }
  2474. break;
  2475. case "quarantaine":
  2476. // Edit settings, does not need IDs
  2477. if (isset($_POST['attr'])) {
  2478. $postarray = json_decode($_POST['attr'], true);
  2479. if (quarantaine('edit', $postarray) === false) {
  2480. if (isset($_SESSION['return'])) {
  2481. echo json_encode($_SESSION['return']);
  2482. }
  2483. else {
  2484. echo json_encode(array(
  2485. 'type' => 'error',
  2486. 'msg' => 'Edit failed'
  2487. ));
  2488. }
  2489. exit();
  2490. }
  2491. else {
  2492. if (isset($_SESSION['return'])) {
  2493. echo json_encode($_SESSION['return']);
  2494. }
  2495. else {
  2496. echo json_encode(array(
  2497. 'type' => 'success',
  2498. 'msg' => 'Task completed'
  2499. ));
  2500. }
  2501. }
  2502. }
  2503. else {
  2504. echo json_encode(array(
  2505. 'type' => 'error',
  2506. 'msg' => 'Incomplete post data'
  2507. ));
  2508. }
  2509. break;
  2510. case "time_limited_alias":
  2511. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2512. $items = (array)json_decode($_POST['items'], true);
  2513. $attr = (array)json_decode($_POST['attr'], true);
  2514. $postarray = array_merge(array('address' => $items), $attr);
  2515. if (is_array($postarray['address'])) {
  2516. if (mailbox('edit', 'time_limited_alias', $postarray) === false) {
  2517. if (isset($_SESSION['return'])) {
  2518. echo json_encode($_SESSION['return']);
  2519. }
  2520. else {
  2521. echo json_encode(array(
  2522. 'type' => 'error',
  2523. 'msg' => 'Edit failed'
  2524. ));
  2525. }
  2526. exit();
  2527. }
  2528. else {
  2529. if (isset($_SESSION['return'])) {
  2530. echo json_encode($_SESSION['return']);
  2531. }
  2532. else {
  2533. echo json_encode(array(
  2534. 'type' => 'success',
  2535. 'msg' => 'Task completed'
  2536. ));
  2537. }
  2538. }
  2539. }
  2540. else {
  2541. echo json_encode(array(
  2542. 'type' => 'error',
  2543. 'msg' => 'Incomplete post data'
  2544. ));
  2545. }
  2546. }
  2547. else {
  2548. echo json_encode(array(
  2549. 'type' => 'error',
  2550. 'msg' => 'Incomplete post data'
  2551. ));
  2552. }
  2553. break;
  2554. case "mailbox":
  2555. // sender_acl:0 removes all entries
  2556. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2557. $items = (array)json_decode($_POST['items'], true);
  2558. $attr = (array)json_decode($_POST['attr'], true);
  2559. $postarray = array_merge(array('username' => $items), $attr);
  2560. if (is_array($postarray['username'])) {
  2561. if (mailbox('edit', 'mailbox', $postarray) === false) {
  2562. if (isset($_SESSION['return'])) {
  2563. echo json_encode($_SESSION['return']);
  2564. }
  2565. else {
  2566. echo json_encode(array(
  2567. 'type' => 'error',
  2568. 'msg' => 'Edit failed'
  2569. ));
  2570. }
  2571. exit();
  2572. }
  2573. else {
  2574. if (isset($_SESSION['return'])) {
  2575. echo json_encode($_SESSION['return']);
  2576. }
  2577. else {
  2578. echo json_encode(array(
  2579. 'type' => 'success',
  2580. 'msg' => 'Task completed'
  2581. ));
  2582. }
  2583. }
  2584. }
  2585. else {
  2586. echo json_encode(array(
  2587. 'type' => 'error',
  2588. 'msg' => 'Incomplete post data'
  2589. ));
  2590. }
  2591. }
  2592. else {
  2593. echo json_encode(array(
  2594. 'type' => 'error',
  2595. 'msg' => 'Incomplete post data'
  2596. ));
  2597. }
  2598. break;
  2599. case "syncjob":
  2600. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2601. $items = (array)json_decode($_POST['items'], true);
  2602. $attr = (array)json_decode($_POST['attr'], true);
  2603. $postarray = array_merge(array('id' => $items), $attr);
  2604. if (is_array($postarray['id'])) {
  2605. if (mailbox('edit', 'syncjob', $postarray) === false) {
  2606. if (isset($_SESSION['return'])) {
  2607. echo json_encode($_SESSION['return']);
  2608. }
  2609. else {
  2610. echo json_encode(array(
  2611. 'type' => 'error',
  2612. 'msg' => 'Edit failed'
  2613. ));
  2614. }
  2615. exit();
  2616. }
  2617. else {
  2618. if (isset($_SESSION['return'])) {
  2619. echo json_encode($_SESSION['return']);
  2620. }
  2621. else {
  2622. echo json_encode(array(
  2623. 'type' => 'success',
  2624. 'msg' => 'Task completed'
  2625. ));
  2626. }
  2627. }
  2628. }
  2629. else {
  2630. echo json_encode(array(
  2631. 'type' => 'error',
  2632. 'msg' => 'Incomplete post data'
  2633. ));
  2634. }
  2635. }
  2636. else {
  2637. echo json_encode(array(
  2638. 'type' => 'error',
  2639. 'msg' => 'Incomplete post data'
  2640. ));
  2641. }
  2642. break;
  2643. case "filter":
  2644. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2645. $items = (array)json_decode($_POST['items'], true);
  2646. $attr = (array)json_decode($_POST['attr'], true);
  2647. $postarray = array_merge(array('id' => $items), $attr);
  2648. if (is_array($postarray['id'])) {
  2649. if (mailbox('edit', 'filter', $postarray) === false) {
  2650. if (isset($_SESSION['return'])) {
  2651. echo json_encode($_SESSION['return']);
  2652. }
  2653. else {
  2654. echo json_encode(array(
  2655. 'type' => 'error',
  2656. 'msg' => 'Edit failed'
  2657. ));
  2658. }
  2659. exit();
  2660. }
  2661. else {
  2662. if (isset($_SESSION['return'])) {
  2663. echo json_encode($_SESSION['return']);
  2664. }
  2665. else {
  2666. echo json_encode(array(
  2667. 'type' => 'success',
  2668. 'msg' => 'Task completed'
  2669. ));
  2670. }
  2671. }
  2672. }
  2673. else {
  2674. echo json_encode(array(
  2675. 'type' => 'error',
  2676. 'msg' => 'Incomplete post data'
  2677. ));
  2678. }
  2679. }
  2680. else {
  2681. echo json_encode(array(
  2682. 'type' => 'error',
  2683. 'msg' => 'Incomplete post data'
  2684. ));
  2685. }
  2686. break;
  2687. case "resource":
  2688. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2689. $items = (array)json_decode($_POST['items'], true);
  2690. $attr = (array)json_decode($_POST['attr'], true);
  2691. $postarray = array_merge(array('name' => $items), $attr);
  2692. if (is_array($postarray['name'])) {
  2693. if (mailbox('edit', 'resource', $postarray) === false) {
  2694. if (isset($_SESSION['return'])) {
  2695. echo json_encode($_SESSION['return']);
  2696. }
  2697. else {
  2698. echo json_encode(array(
  2699. 'type' => 'error',
  2700. 'msg' => 'Edit failed'
  2701. ));
  2702. }
  2703. exit();
  2704. }
  2705. else {
  2706. if (isset($_SESSION['return'])) {
  2707. echo json_encode($_SESSION['return']);
  2708. }
  2709. else {
  2710. echo json_encode(array(
  2711. 'type' => 'success',
  2712. 'msg' => 'Task completed'
  2713. ));
  2714. }
  2715. }
  2716. }
  2717. else {
  2718. echo json_encode(array(
  2719. 'type' => 'error',
  2720. 'msg' => 'Incomplete post data'
  2721. ));
  2722. }
  2723. }
  2724. else {
  2725. echo json_encode(array(
  2726. 'type' => 'error',
  2727. 'msg' => 'Incomplete post data'
  2728. ));
  2729. }
  2730. break;
  2731. case "domain":
  2732. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2733. $items = (array)json_decode($_POST['items'], true);
  2734. $attr = (array)json_decode($_POST['attr'], true);
  2735. $postarray = array_merge(array('domain' => $items), $attr);
  2736. if (is_array($postarray['domain'])) {
  2737. if (mailbox('edit', 'domain', $postarray)) {
  2738. if (isset($_SESSION['return'])) {
  2739. echo json_encode($_SESSION['return']);
  2740. }
  2741. else {
  2742. echo json_encode(array(
  2743. 'type' => 'error',
  2744. 'msg' => 'Edit failed'
  2745. ));
  2746. }
  2747. exit();
  2748. }
  2749. else {
  2750. if (isset($_SESSION['return'])) {
  2751. echo json_encode($_SESSION['return']);
  2752. }
  2753. else {
  2754. echo json_encode(array(
  2755. 'type' => 'success',
  2756. 'msg' => 'Task completed'
  2757. ));
  2758. }
  2759. }
  2760. }
  2761. else {
  2762. echo json_encode(array(
  2763. 'type' => 'error',
  2764. 'msg' => 'Incomplete post data'
  2765. ));
  2766. }
  2767. }
  2768. else {
  2769. echo json_encode(array(
  2770. 'type' => 'error',
  2771. 'msg' => 'Incomplete post data'
  2772. ));
  2773. }
  2774. break;
  2775. case "ratelimit":
  2776. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2777. $items = (array)json_decode($_POST['items'], true);
  2778. $attr = (array)json_decode($_POST['attr'], true);
  2779. $postarray = array_merge(array('object' => $items), $attr);
  2780. if (is_array($postarray['object'])) {
  2781. if (mailbox('edit', 'ratelimit', $postarray) === false) {
  2782. if (isset($_SESSION['return'])) {
  2783. echo json_encode($_SESSION['return']);
  2784. }
  2785. else {
  2786. echo json_encode(array(
  2787. 'type' => 'error',
  2788. 'msg' => 'Edit failed'
  2789. ));
  2790. }
  2791. exit();
  2792. }
  2793. else {
  2794. if (isset($_SESSION['return'])) {
  2795. echo json_encode($_SESSION['return']);
  2796. }
  2797. else {
  2798. echo json_encode(array(
  2799. 'type' => 'success',
  2800. 'msg' => 'Task completed'
  2801. ));
  2802. }
  2803. }
  2804. }
  2805. else {
  2806. echo json_encode(array(
  2807. 'type' => 'error',
  2808. 'msg' => 'Incomplete post data'
  2809. ));
  2810. }
  2811. }
  2812. else {
  2813. echo json_encode(array(
  2814. 'type' => 'error',
  2815. 'msg' => 'Incomplete post data'
  2816. ));
  2817. }
  2818. break;
  2819. case "alias-domain":
  2820. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2821. $items = (array)json_decode($_POST['items'], true);
  2822. $attr = (array)json_decode($_POST['attr'], true);
  2823. $postarray = array_merge(array('alias_domain' => $items), $attr);
  2824. if (is_array($postarray['alias_domain'])) {
  2825. if (mailbox('edit', 'alias_domain', $postarray) === false) {
  2826. if (isset($_SESSION['return'])) {
  2827. echo json_encode($_SESSION['return']);
  2828. }
  2829. else {
  2830. echo json_encode(array(
  2831. 'type' => 'error',
  2832. 'msg' => 'Edit failed'
  2833. ));
  2834. }
  2835. exit();
  2836. }
  2837. else {
  2838. if (isset($_SESSION['return'])) {
  2839. echo json_encode($_SESSION['return']);
  2840. }
  2841. else {
  2842. echo json_encode(array(
  2843. 'type' => 'success',
  2844. 'msg' => 'Task completed'
  2845. ));
  2846. }
  2847. }
  2848. }
  2849. else {
  2850. echo json_encode(array(
  2851. 'type' => 'error',
  2852. 'msg' => 'Incomplete post data'
  2853. ));
  2854. }
  2855. }
  2856. else {
  2857. echo json_encode(array(
  2858. 'type' => 'error',
  2859. 'msg' => 'Incomplete post data'
  2860. ));
  2861. }
  2862. break;
  2863. case "spam-score":
  2864. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2865. $items = (array)json_decode($_POST['items'], true);
  2866. $attr = (array)json_decode($_POST['attr'], true);
  2867. $postarray = array_merge(array('username' => $items), $attr);
  2868. if (is_array($postarray['username'])) {
  2869. if (mailbox('edit', 'spam_score', $postarray) === false) {
  2870. if (isset($_SESSION['return'])) {
  2871. echo json_encode($_SESSION['return']);
  2872. }
  2873. else {
  2874. echo json_encode(array(
  2875. 'type' => 'error',
  2876. 'msg' => 'Edit failed'
  2877. ));
  2878. }
  2879. exit();
  2880. }
  2881. else {
  2882. if (isset($_SESSION['return'])) {
  2883. echo json_encode($_SESSION['return']);
  2884. }
  2885. else {
  2886. echo json_encode(array(
  2887. 'type' => 'success',
  2888. 'msg' => 'Task completed'
  2889. ));
  2890. }
  2891. }
  2892. }
  2893. else {
  2894. echo json_encode(array(
  2895. 'type' => 'error',
  2896. 'msg' => 'Incomplete post data'
  2897. ));
  2898. }
  2899. }
  2900. else {
  2901. echo json_encode(array(
  2902. 'type' => 'error',
  2903. 'msg' => 'Incomplete post data'
  2904. ));
  2905. }
  2906. break;
  2907. case "domain-admin":
  2908. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2909. $items = (array)json_decode($_POST['items'], true);
  2910. $attr = (array)json_decode($_POST['attr'], true);
  2911. $postarray = array_merge(array('username' => $items), $attr);
  2912. if (is_array($postarray['username'])) {
  2913. if (domain_admin('edit', $postarray) === false) {
  2914. if (isset($_SESSION['return'])) {
  2915. echo json_encode($_SESSION['return']);
  2916. }
  2917. else {
  2918. echo json_encode(array(
  2919. 'type' => 'error',
  2920. 'msg' => 'Edit failed'
  2921. ));
  2922. }
  2923. exit();
  2924. }
  2925. else {
  2926. if (isset($_SESSION['return'])) {
  2927. echo json_encode($_SESSION['return']);
  2928. }
  2929. else {
  2930. echo json_encode(array(
  2931. 'type' => 'success',
  2932. 'msg' => 'Task completed'
  2933. ));
  2934. }
  2935. }
  2936. }
  2937. else {
  2938. echo json_encode(array(
  2939. 'type' => 'error',
  2940. 'msg' => 'Incomplete post data'
  2941. ));
  2942. }
  2943. }
  2944. else {
  2945. echo json_encode(array(
  2946. 'type' => 'error',
  2947. 'msg' => 'Incomplete post data'
  2948. ));
  2949. }
  2950. break;
  2951. case "fwdhost":
  2952. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2953. $items = (array)json_decode($_POST['items'], true);
  2954. $attr = (array)json_decode($_POST['attr'], true);
  2955. $postarray = array_merge(array('fwdhost' => $items), $attr);
  2956. if (is_array($postarray['fwdhost'])) {
  2957. if (fwdhost('edit', $postarray) === false) {
  2958. if (isset($_SESSION['return'])) {
  2959. echo json_encode($_SESSION['return']);
  2960. }
  2961. else {
  2962. echo json_encode(array(
  2963. 'type' => 'error',
  2964. 'msg' => 'Edit failed'
  2965. ));
  2966. }
  2967. exit();
  2968. }
  2969. else {
  2970. if (isset($_SESSION['return'])) {
  2971. echo json_encode($_SESSION['return']);
  2972. }
  2973. else {
  2974. echo json_encode(array(
  2975. 'type' => 'success',
  2976. 'msg' => 'Task completed'
  2977. ));
  2978. }
  2979. }
  2980. }
  2981. else {
  2982. echo json_encode(array(
  2983. 'type' => 'error',
  2984. 'msg' => 'Incomplete post data'
  2985. ));
  2986. }
  2987. }
  2988. else {
  2989. echo json_encode(array(
  2990. 'type' => 'error',
  2991. 'msg' => 'Incomplete post data'
  2992. ));
  2993. }
  2994. break;
  2995. case "fail2ban":
  2996. // No items
  2997. if (isset($_POST['attr'])) {
  2998. $attr = (array)json_decode($_POST['attr'], true);
  2999. if (fail2ban('edit', $attr) === false) {
  3000. if (isset($_SESSION['return'])) {
  3001. echo json_encode($_SESSION['return']);
  3002. }
  3003. else {
  3004. echo json_encode(array(
  3005. 'type' => 'error',
  3006. 'msg' => 'Edit failed'
  3007. ));
  3008. }
  3009. exit();
  3010. }
  3011. else {
  3012. if (isset($_SESSION['return'])) {
  3013. echo json_encode($_SESSION['return']);
  3014. }
  3015. else {
  3016. echo json_encode(array(
  3017. 'type' => 'success',
  3018. 'msg' => 'Task completed'
  3019. ));
  3020. }
  3021. }
  3022. }
  3023. else {
  3024. echo json_encode(array(
  3025. 'type' => 'error',
  3026. 'msg' => 'Incomplete post data'
  3027. ));
  3028. }
  3029. break;
  3030. case "ui_texts":
  3031. // No items
  3032. if (isset($_POST['attr'])) {
  3033. $attr = (array)json_decode($_POST['attr'], true);
  3034. if (customize('edit', 'ui_texts', $attr) === false) {
  3035. if (isset($_SESSION['return'])) {
  3036. echo json_encode($_SESSION['return']);
  3037. }
  3038. else {
  3039. echo json_encode(array(
  3040. 'type' => 'error',
  3041. 'msg' => 'Edit failed'
  3042. ));
  3043. }
  3044. exit();
  3045. }
  3046. else {
  3047. if (isset($_SESSION['return'])) {
  3048. echo json_encode($_SESSION['return']);
  3049. }
  3050. else {
  3051. echo json_encode(array(
  3052. 'type' => 'success',
  3053. 'msg' => 'Task completed'
  3054. ));
  3055. }
  3056. }
  3057. }
  3058. else {
  3059. echo json_encode(array(
  3060. 'type' => 'error',
  3061. 'msg' => 'Incomplete post data'
  3062. ));
  3063. }
  3064. break;
  3065. case "self":
  3066. // No items, logged-in user, users and domain admins
  3067. if ($_SESSION['mailcow_cc_role'] == "domainadmin") {
  3068. if (isset($_POST['attr'])) {
  3069. $attr = (array)json_decode($_POST['attr'], true);
  3070. if (domain_admin('edit', $attr) === false) {
  3071. if (isset($_SESSION['return'])) {
  3072. echo json_encode($_SESSION['return']);
  3073. }
  3074. else {
  3075. echo json_encode(array(
  3076. 'type' => 'error',
  3077. 'msg' => 'Edit failed'
  3078. ));
  3079. }
  3080. exit();
  3081. }
  3082. else {
  3083. if (isset($_SESSION['return'])) {
  3084. echo json_encode($_SESSION['return']);
  3085. }
  3086. else {
  3087. echo json_encode(array(
  3088. 'type' => 'success',
  3089. 'msg' => 'Task completed'
  3090. ));
  3091. }
  3092. }
  3093. }
  3094. else {
  3095. echo json_encode(array(
  3096. 'type' => 'error',
  3097. 'msg' => 'Incomplete post data'
  3098. ));
  3099. }
  3100. }
  3101. elseif ($_SESSION['mailcow_cc_role'] == "user") {
  3102. if (isset($_POST['attr'])) {
  3103. $attr = (array)json_decode($_POST['attr'], true);
  3104. if (edit_user_account($attr) === false) {
  3105. if (isset($_SESSION['return'])) {
  3106. echo json_encode($_SESSION['return']);
  3107. }
  3108. else {
  3109. echo json_encode(array(
  3110. 'type' => 'error',
  3111. 'msg' => 'Edit failed'
  3112. ));
  3113. }
  3114. exit();
  3115. }
  3116. else {
  3117. if (isset($_SESSION['return'])) {
  3118. echo json_encode($_SESSION['return']);
  3119. }
  3120. else {
  3121. echo json_encode(array(
  3122. 'type' => 'success',
  3123. 'msg' => 'Task completed'
  3124. ));
  3125. }
  3126. }
  3127. }
  3128. else {
  3129. echo json_encode(array(
  3130. 'type' => 'error',
  3131. 'msg' => 'Incomplete post data'
  3132. ));
  3133. }
  3134. }
  3135. elseif ($_SESSION['mailcow_cc_role'] == "admin") {
  3136. if (isset($_POST['attr'])) {
  3137. $attr = (array)json_decode($_POST['attr'], true);
  3138. if (edit_admin_account($attr) === false) {
  3139. if (isset($_SESSION['return'])) {
  3140. echo json_encode($_SESSION['return']);
  3141. }
  3142. else {
  3143. echo json_encode(array(
  3144. 'type' => 'error',
  3145. 'msg' => 'Edit failed'
  3146. ));
  3147. }
  3148. exit();
  3149. }
  3150. else {
  3151. if (isset($_SESSION['return'])) {
  3152. echo json_encode($_SESSION['return']);
  3153. }
  3154. else {
  3155. echo json_encode(array(
  3156. 'type' => 'success',
  3157. 'msg' => 'Task completed'
  3158. ));
  3159. }
  3160. }
  3161. }
  3162. else {
  3163. echo json_encode(array(
  3164. 'type' => 'error',
  3165. 'msg' => 'Incomplete post data'
  3166. ));
  3167. }
  3168. }
  3169. break;
  3170. }
  3171. break;
  3172. }
  3173. }
  3174. }