json_api.php 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366
  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. case "recipient_map":
  592. if (isset($_POST['attr'])) {
  593. $attr = (array)json_decode($_POST['attr'], true);
  594. if (recipient_map('add', $attr) === false) {
  595. if (isset($_SESSION['return'])) {
  596. echo json_encode($_SESSION['return']);
  597. }
  598. else {
  599. echo json_encode(array(
  600. 'type' => 'error',
  601. 'msg' => 'Cannot add item'
  602. ));
  603. }
  604. }
  605. else {
  606. if (isset($_SESSION['return'])) {
  607. echo json_encode($_SESSION['return']);
  608. }
  609. else {
  610. echo json_encode(array(
  611. 'type' => 'success',
  612. 'msg' => 'Task completed'
  613. ));
  614. }
  615. }
  616. }
  617. else {
  618. echo json_encode(array(
  619. 'type' => 'error',
  620. 'msg' => 'Cannot find attributes in post data'
  621. ));
  622. }
  623. break;
  624. }
  625. break;
  626. case "get":
  627. switch ($category) {
  628. case "rspamd":
  629. switch ($object) {
  630. case "actions":
  631. $curl = curl_init();
  632. curl_setopt($curl, CURLOPT_UNIX_SOCKET_PATH, '/rspamd-sock/rspamd.sock');
  633. curl_setopt($curl, CURLOPT_URL,"http://rspamd/stat");
  634. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  635. $data = curl_exec($curl);
  636. if ($data) {
  637. $return = array();
  638. $stats_array = json_decode($data, true)['actions'];
  639. $stats_array['soft reject'] = $stats_array['soft reject'] + $stats_array['greylist'];
  640. unset($stats_array['greylist']);
  641. foreach ($stats_array as $action => $count) {
  642. $return[] = array($action, $count);
  643. }
  644. echo json_encode($return, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  645. }
  646. elseif (!isset($data) || empty($data)) {
  647. echo '{}';
  648. }
  649. break;
  650. case "graph":
  651. switch ($extra) {
  652. case "hourly":
  653. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=hourly');
  654. if (!empty($data)) {
  655. $data_array = json_decode($data, true);
  656. $rejected['label'] = "reject";
  657. foreach ($data_array[0] as $dataset) {
  658. $rejected['data'][] = $dataset;
  659. }
  660. $temp_reject['label'] = "temp_reject";
  661. foreach ($data_array[1] as $dataset) {
  662. $temp_reject['data'][] = $dataset;
  663. }
  664. $add_header['label'] = "add_header";
  665. foreach ($data_array[2] as $dataset) {
  666. $add_header['data'][] = $dataset;
  667. }
  668. $prob_spam['label'] = "prob_spam";
  669. foreach ($data_array[3] as $dataset) {
  670. $prob_spam['data'][] = $dataset;
  671. }
  672. $greylist['label'] = "greylist";
  673. foreach ($data_array[4] as $dataset) {
  674. $greylist['data'][] = $dataset;
  675. }
  676. $clean['label'] = "clean";
  677. $clean['pointStyle'] = "cross";
  678. foreach ($data_array[5] as $dataset) {
  679. $clean['data'][] = $dataset;
  680. }
  681. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  682. }
  683. elseif (!isset($data) || empty($data)) {
  684. echo '{}';
  685. }
  686. break;
  687. case "daily":
  688. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=daily');
  689. if (!empty($data)) {
  690. $data_array = json_decode($data, true);
  691. $rejected['label'] = "reject";
  692. foreach ($data_array[0] as $dataset) {
  693. $rejected['data'][] = $dataset;
  694. }
  695. $temp_reject['label'] = "temp_reject";
  696. foreach ($data_array[1] as $dataset) {
  697. $temp_reject['data'][] = $dataset;
  698. }
  699. $add_header['label'] = "add_header";
  700. foreach ($data_array[2] as $dataset) {
  701. $add_header['data'][] = $dataset;
  702. }
  703. $prob_spam['label'] = "prob_spam";
  704. foreach ($data_array[3] as $dataset) {
  705. $prob_spam['data'][] = $dataset;
  706. }
  707. $greylist['label'] = "greylist";
  708. foreach ($data_array[4] as $dataset) {
  709. $greylist['data'][] = $dataset;
  710. }
  711. $clean['label'] = "clean";
  712. $clean['pointStyle'] = "cross";
  713. foreach ($data_array[5] as $dataset) {
  714. $clean['data'][] = $dataset;
  715. }
  716. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  717. }
  718. elseif (!isset($data) || empty($data)) {
  719. echo '{}';
  720. }
  721. break;
  722. case "weekly":
  723. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=weekly');
  724. if (!empty($data)) {
  725. $data_array = json_decode($data, true);
  726. $rejected['label'] = "reject";
  727. foreach ($data_array[0] as $dataset) {
  728. $rejected['data'][] = $dataset;
  729. }
  730. $temp_reject['label'] = "temp_reject";
  731. foreach ($data_array[1] as $dataset) {
  732. $temp_reject['data'][] = $dataset;
  733. }
  734. $add_header['label'] = "add_header";
  735. foreach ($data_array[2] as $dataset) {
  736. $add_header['data'][] = $dataset;
  737. }
  738. $prob_spam['label'] = "prob_spam";
  739. foreach ($data_array[3] as $dataset) {
  740. $prob_spam['data'][] = $dataset;
  741. }
  742. $greylist['label'] = "greylist";
  743. foreach ($data_array[4] as $dataset) {
  744. $greylist['data'][] = $dataset;
  745. }
  746. $clean['label'] = "clean";
  747. $clean['pointStyle'] = "cross";
  748. foreach ($data_array[5] as $dataset) {
  749. $clean['data'][] = $dataset;
  750. }
  751. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  752. }
  753. elseif (!isset($data) || empty($data)) {
  754. echo '{}';
  755. }
  756. break;
  757. case "monthly":
  758. $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=monthly');
  759. if (!empty($data)) {
  760. $data_array = json_decode($data, true);
  761. $rejected['label'] = "reject";
  762. foreach ($data_array[0] as $dataset) {
  763. $rejected['data'][] = $dataset;
  764. }
  765. $temp_reject['label'] = "temp_reject";
  766. foreach ($data_array[1] as $dataset) {
  767. $temp_reject['data'][] = $dataset;
  768. }
  769. $add_header['label'] = "add_header";
  770. foreach ($data_array[2] as $dataset) {
  771. $add_header['data'][] = $dataset;
  772. }
  773. $prob_spam['label'] = "prob_spam";
  774. foreach ($data_array[3] as $dataset) {
  775. $prob_spam['data'][] = $dataset;
  776. }
  777. $greylist['label'] = "greylist";
  778. foreach ($data_array[4] as $dataset) {
  779. $greylist['data'][] = $dataset;
  780. }
  781. $clean['label'] = "clean";
  782. $clean['pointStyle'] = "cross";
  783. foreach ($data_array[5] as $dataset) {
  784. $clean['data'][] = $dataset;
  785. }
  786. echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  787. }
  788. elseif (!isset($data) || empty($data)) {
  789. echo '{}';
  790. }
  791. break;
  792. }
  793. break;
  794. }
  795. break;
  796. case "domain":
  797. switch ($object) {
  798. case "all":
  799. $domains = mailbox('get', 'domains');
  800. if (!empty($domains)) {
  801. foreach ($domains as $domain) {
  802. if ($details = mailbox('get', 'domain_details', $domain)) {
  803. $data[] = $details;
  804. }
  805. else {
  806. continue;
  807. }
  808. }
  809. if (!isset($data) || empty($data)) {
  810. echo '{}';
  811. }
  812. else {
  813. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  814. }
  815. }
  816. else {
  817. echo '{}';
  818. }
  819. break;
  820. default:
  821. $data = mailbox('get', 'domain_details', $object);
  822. if (!isset($data) || empty($data)) {
  823. echo '{}';
  824. }
  825. else {
  826. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  827. }
  828. break;
  829. }
  830. break;
  831. case "relayhost":
  832. switch ($object) {
  833. case "all":
  834. $relayhosts = relayhost('get');
  835. if (!empty($relayhosts)) {
  836. foreach ($relayhosts as $relayhost) {
  837. if ($details = relayhost('details', $relayhost['id'])) {
  838. $data[] = $details;
  839. }
  840. else {
  841. continue;
  842. }
  843. }
  844. if (!isset($data) || empty($data)) {
  845. echo '{}';
  846. }
  847. else {
  848. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  849. }
  850. }
  851. else {
  852. echo '{}';
  853. }
  854. break;
  855. default:
  856. $data = relayhost('details', $object);
  857. if (!isset($data) || empty($data)) {
  858. echo '{}';
  859. }
  860. else {
  861. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  862. }
  863. break;
  864. }
  865. break;
  866. case "logs":
  867. switch ($object) {
  868. case "dovecot":
  869. // 0 is first record, so empty is fine
  870. if (isset($extra)) {
  871. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  872. $logs = get_logs('dovecot-mailcow', $extra);
  873. }
  874. else {
  875. $logs = get_logs('dovecot-mailcow');
  876. }
  877. if (isset($logs) && !empty($logs)) {
  878. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  879. }
  880. else {
  881. echo '{}';
  882. }
  883. break;
  884. case "netfilter":
  885. // 0 is first record, so empty is fine
  886. if (isset($extra)) {
  887. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  888. $logs = get_logs('netfilter-mailcow', $extra);
  889. }
  890. else {
  891. $logs = get_logs('netfilter-mailcow');
  892. }
  893. if (isset($logs) && !empty($logs)) {
  894. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  895. }
  896. else {
  897. echo '{}';
  898. }
  899. break;
  900. case "postfix":
  901. // 0 is first record, so empty is fine
  902. if (isset($extra)) {
  903. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  904. $logs = get_logs('postfix-mailcow', $extra);
  905. }
  906. else {
  907. $logs = get_logs('postfix-mailcow');
  908. }
  909. if (isset($logs) && !empty($logs)) {
  910. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  911. }
  912. else {
  913. echo '{}';
  914. }
  915. break;
  916. case "autodiscover":
  917. // 0 is first record, so empty is fine
  918. if (isset($extra)) {
  919. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  920. $logs = get_logs('autodiscover-mailcow', $extra);
  921. }
  922. else {
  923. $logs = get_logs('autodiscover-mailcow');
  924. }
  925. if (isset($logs) && !empty($logs)) {
  926. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  927. }
  928. else {
  929. echo '{}';
  930. }
  931. break;
  932. case "sogo":
  933. // 0 is first record, so empty is fine
  934. if (isset($extra)) {
  935. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  936. $logs = get_logs('sogo-mailcow', $extra);
  937. }
  938. else {
  939. $logs = get_logs('sogo-mailcow');
  940. }
  941. if (isset($logs) && !empty($logs)) {
  942. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  943. }
  944. else {
  945. echo '{}';
  946. }
  947. break;
  948. case "watchdog":
  949. // 0 is first record, so empty is fine
  950. if (isset($extra)) {
  951. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  952. $logs = get_logs('watchdog-mailcow', $extra);
  953. }
  954. else {
  955. $logs = get_logs('watchdog-mailcow');
  956. }
  957. if (isset($logs) && !empty($logs)) {
  958. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  959. }
  960. else {
  961. echo '{}';
  962. }
  963. break;
  964. case "acme":
  965. // 0 is first record, so empty is fine
  966. if (isset($extra)) {
  967. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  968. $logs = get_logs('acme-mailcow', $extra);
  969. }
  970. else {
  971. $logs = get_logs('acme-mailcow');
  972. }
  973. if (isset($logs) && !empty($logs)) {
  974. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  975. }
  976. else {
  977. echo '{}';
  978. }
  979. break;
  980. case "api":
  981. // 0 is first record, so empty is fine
  982. if (isset($extra)) {
  983. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  984. $logs = get_logs('api-mailcow', $extra);
  985. }
  986. else {
  987. $logs = get_logs('api-mailcow');
  988. }
  989. if (isset($logs) && !empty($logs)) {
  990. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  991. }
  992. else {
  993. echo '{}';
  994. }
  995. break;
  996. case "rspamd-history":
  997. // 0 is first record, so empty is fine
  998. if (isset($extra)) {
  999. $extra = preg_replace('/[^\d\-]/i', '', $extra);
  1000. $logs = get_logs('rspamd-history', $extra);
  1001. }
  1002. else {
  1003. $logs = get_logs('rspamd-history');
  1004. }
  1005. if (isset($logs) && !empty($logs)) {
  1006. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1007. }
  1008. else {
  1009. echo '{}';
  1010. }
  1011. break;
  1012. }
  1013. break;
  1014. case "mailbox":
  1015. switch ($object) {
  1016. case "all":
  1017. $domains = mailbox('get', 'domains');
  1018. if (!empty($domains)) {
  1019. foreach ($domains as $domain) {
  1020. $mailboxes = mailbox('get', 'mailboxes', $domain);
  1021. if (!empty($mailboxes)) {
  1022. foreach ($mailboxes as $mailbox) {
  1023. if ($details = mailbox('get', 'mailbox_details', $mailbox)) {
  1024. $data[] = $details;
  1025. }
  1026. else {
  1027. continue;
  1028. }
  1029. }
  1030. }
  1031. }
  1032. if (!isset($data) || empty($data)) {
  1033. echo '{}';
  1034. }
  1035. else {
  1036. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1037. }
  1038. }
  1039. else {
  1040. echo '{}';
  1041. }
  1042. break;
  1043. default:
  1044. $data = mailbox('get', 'mailbox_details', $object);
  1045. if (!isset($data) || empty($data)) {
  1046. echo '{}';
  1047. }
  1048. else {
  1049. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1050. }
  1051. break;
  1052. }
  1053. break;
  1054. case "syncjobs":
  1055. switch ($object) {
  1056. case "all":
  1057. $domains = mailbox('get', 'domains');
  1058. if (!empty($domains)) {
  1059. foreach ($domains as $domain) {
  1060. $mailboxes = mailbox('get', 'mailboxes', $domain);
  1061. if (!empty($mailboxes)) {
  1062. foreach ($mailboxes as $mailbox) {
  1063. $syncjobs = mailbox('get', 'syncjobs', $mailbox);
  1064. if (!empty($syncjobs)) {
  1065. foreach ($syncjobs as $syncjob) {
  1066. if (isset($extra)) {
  1067. $details = mailbox('get', 'syncjob_details', $syncjob, explode(',', $extra));
  1068. }
  1069. else {
  1070. $details = mailbox('get', 'syncjob_details', $syncjob);
  1071. }
  1072. if ($details) {
  1073. $data[] = $details;
  1074. }
  1075. else {
  1076. continue;
  1077. }
  1078. }
  1079. }
  1080. }
  1081. }
  1082. }
  1083. if (!isset($data) || empty($data)) {
  1084. echo '{}';
  1085. }
  1086. else {
  1087. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1088. }
  1089. }
  1090. else {
  1091. echo '{}';
  1092. }
  1093. break;
  1094. default:
  1095. $syncjobs = mailbox('get', 'syncjobs', $object);
  1096. if (!empty($syncjobs)) {
  1097. foreach ($syncjobs as $syncjob) {
  1098. if (isset($extra)) {
  1099. $details = mailbox('get', 'syncjob_details', $syncjob, explode(',', $extra));
  1100. }
  1101. else {
  1102. $details = mailbox('get', 'syncjob_details', $syncjob);
  1103. }
  1104. if ($details) {
  1105. $data[] = $details;
  1106. }
  1107. else {
  1108. continue;
  1109. }
  1110. }
  1111. }
  1112. if (!isset($data) || empty($data)) {
  1113. echo '{}';
  1114. }
  1115. else {
  1116. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1117. }
  1118. break;
  1119. }
  1120. break;
  1121. case "active-user-sieve":
  1122. if (isset($object)) {
  1123. $sieve_filter = mailbox('get', 'active_user_sieve', $object);
  1124. if (!empty($sieve_filter)) {
  1125. $data[] = $sieve_filter;
  1126. }
  1127. }
  1128. if (!isset($data) || empty($data)) {
  1129. echo '{}';
  1130. }
  1131. else {
  1132. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1133. }
  1134. break;
  1135. case "filters":
  1136. switch ($object) {
  1137. case "all":
  1138. $domains = mailbox('get', 'domains');
  1139. if (!empty($domains)) {
  1140. foreach ($domains as $domain) {
  1141. $mailboxes = mailbox('get', 'mailboxes', $domain);
  1142. if (!empty($mailboxes)) {
  1143. foreach ($mailboxes as $mailbox) {
  1144. $filters = mailbox('get', 'filters', $mailbox);
  1145. if (!empty($filters)) {
  1146. foreach ($filters as $filter) {
  1147. if ($details = mailbox('get', 'filter_details', $filter)) {
  1148. $data[] = $details;
  1149. }
  1150. else {
  1151. continue;
  1152. }
  1153. }
  1154. }
  1155. }
  1156. }
  1157. }
  1158. if (!isset($data) || empty($data)) {
  1159. echo '{}';
  1160. }
  1161. else {
  1162. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1163. }
  1164. }
  1165. else {
  1166. echo '{}';
  1167. }
  1168. break;
  1169. default:
  1170. $filters = mailbox('get', 'filters', $object);
  1171. if (!empty($filters)) {
  1172. foreach ($filters as $filter) {
  1173. if ($details = mailbox('get', 'filter_details', $filter)) {
  1174. $data[] = $details;
  1175. }
  1176. else {
  1177. continue;
  1178. }
  1179. }
  1180. }
  1181. if (!isset($data) || empty($data)) {
  1182. echo '{}';
  1183. }
  1184. else {
  1185. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1186. }
  1187. break;
  1188. }
  1189. break;
  1190. case "bcc":
  1191. switch ($object) {
  1192. case "all":
  1193. $bcc_items = bcc('get');
  1194. if (!empty($bcc_items)) {
  1195. foreach ($bcc_items as $bcc_item) {
  1196. if ($details = bcc('details', $bcc_item)) {
  1197. $data[] = $details;
  1198. }
  1199. else {
  1200. continue;
  1201. }
  1202. }
  1203. }
  1204. if (!isset($data) || empty($data)) {
  1205. echo '{}';
  1206. }
  1207. else {
  1208. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1209. }
  1210. break;
  1211. default:
  1212. $data = bcc('details', $object);
  1213. if (!empty($data)) {
  1214. $data[] = $details;
  1215. }
  1216. if (!isset($data) || empty($data)) {
  1217. echo '{}';
  1218. }
  1219. else {
  1220. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1221. }
  1222. break;
  1223. }
  1224. break;
  1225. case "recipient_map":
  1226. switch ($object) {
  1227. case "all":
  1228. $recipient_map_items = recipient_map('get');
  1229. if (!empty($recipient_map_items)) {
  1230. foreach ($recipient_map_items as $recipient_map_item) {
  1231. if ($details = recipient_map('details', $recipient_map_item)) {
  1232. $data[] = $details;
  1233. }
  1234. else {
  1235. continue;
  1236. }
  1237. }
  1238. }
  1239. if (!isset($data) || empty($data)) {
  1240. echo '{}';
  1241. }
  1242. else {
  1243. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1244. }
  1245. break;
  1246. default:
  1247. $data = recipient_map('details', $object);
  1248. if (!empty($data)) {
  1249. $data[] = $details;
  1250. }
  1251. if (!isset($data) || empty($data)) {
  1252. echo '{}';
  1253. }
  1254. else {
  1255. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1256. }
  1257. break;
  1258. }
  1259. break;
  1260. case "policy_wl_mailbox":
  1261. switch ($object) {
  1262. default:
  1263. $data = policy('get', 'mailbox', $object)['whitelist'];
  1264. if (!isset($data) || empty($data)) {
  1265. echo '{}';
  1266. }
  1267. else {
  1268. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1269. }
  1270. break;
  1271. }
  1272. break;
  1273. case "policy_bl_mailbox":
  1274. switch ($object) {
  1275. default:
  1276. $data = policy('get', 'mailbox', $object)['blacklist'];
  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 "policy_wl_domain":
  1287. switch ($object) {
  1288. default:
  1289. $data = policy('get', 'domain', $object)['whitelist'];
  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. }
  1298. break;
  1299. case "policy_bl_domain":
  1300. switch ($object) {
  1301. default:
  1302. $data = policy('get', 'domain', $object)['blacklist'];
  1303. if (!isset($data) || empty($data)) {
  1304. echo '{}';
  1305. }
  1306. else {
  1307. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1308. }
  1309. break;
  1310. }
  1311. break;
  1312. case "time_limited_aliases":
  1313. switch ($object) {
  1314. default:
  1315. $data = mailbox('get', 'time_limited_aliases', $object);
  1316. if (!isset($data) || empty($data)) {
  1317. echo '{}';
  1318. }
  1319. else {
  1320. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1321. }
  1322. break;
  1323. }
  1324. break;
  1325. case "resource":
  1326. switch ($object) {
  1327. case "all":
  1328. $domains = mailbox('get', 'domains');
  1329. if (!empty($domains)) {
  1330. foreach ($domains as $domain) {
  1331. $resources = mailbox('get', 'resources', $domain);
  1332. if (!empty($resources)) {
  1333. foreach ($resources as $resource) {
  1334. if ($details = mailbox('get', 'resource_details', $resource)) {
  1335. $data[] = $details;
  1336. }
  1337. else {
  1338. continue;
  1339. }
  1340. }
  1341. }
  1342. }
  1343. if (!isset($data) || empty($data)) {
  1344. echo '{}';
  1345. }
  1346. else {
  1347. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1348. }
  1349. }
  1350. else {
  1351. echo '{}';
  1352. }
  1353. break;
  1354. default:
  1355. $data = mailbox('get', 'resource_details', $object);
  1356. if (!isset($data) || empty($data)) {
  1357. echo '{}';
  1358. }
  1359. else {
  1360. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1361. }
  1362. break;
  1363. }
  1364. break;
  1365. case "fwdhost":
  1366. switch ($object) {
  1367. case "all":
  1368. $data = fwdhost('get');
  1369. if (!isset($data) || empty($data)) {
  1370. echo '{}';
  1371. }
  1372. else {
  1373. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1374. }
  1375. break;
  1376. default:
  1377. $data = fwdhost('details', $object);
  1378. if (!isset($data) || empty($data)) {
  1379. echo '{}';
  1380. }
  1381. else {
  1382. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1383. }
  1384. break;
  1385. }
  1386. break;
  1387. case "quarantine":
  1388. // "all" will not print details
  1389. switch ($object) {
  1390. case "all":
  1391. $data = quarantine('get');
  1392. if (!isset($data) || empty($data)) {
  1393. echo '{}';
  1394. }
  1395. else {
  1396. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1397. }
  1398. break;
  1399. default:
  1400. $data = quarantine('details', $object);
  1401. if (!isset($data) || empty($data)) {
  1402. echo '{}';
  1403. }
  1404. else {
  1405. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1406. }
  1407. break;
  1408. }
  1409. break;
  1410. case "alias-domain":
  1411. switch ($object) {
  1412. case "all":
  1413. $alias_domains = mailbox('get', 'alias_domains');
  1414. if (!empty($alias_domains)) {
  1415. foreach ($alias_domains as $alias_domain) {
  1416. if ($details = mailbox('get', 'alias_domain_details', $alias_domain)) {
  1417. $data[] = $details;
  1418. }
  1419. else {
  1420. continue;
  1421. }
  1422. }
  1423. }
  1424. if (!isset($data) || empty($data)) {
  1425. echo '{}';
  1426. }
  1427. else {
  1428. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1429. }
  1430. break;
  1431. default:
  1432. $data = mailbox('get', 'alias_domain_details', $object);
  1433. if (!isset($data) || empty($data)) {
  1434. echo '{}';
  1435. }
  1436. else {
  1437. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1438. }
  1439. break;
  1440. }
  1441. break;
  1442. case "alias":
  1443. switch ($object) {
  1444. case "all":
  1445. $domains = array_merge(mailbox('get', 'domains'),mailbox('get', 'alias_domains'));
  1446. if (!empty($domains)) {
  1447. foreach ($domains as $domain) {
  1448. $aliases = mailbox('get', 'aliases', $domain);
  1449. if (!empty($aliases)) {
  1450. foreach ($aliases as $alias) {
  1451. if ($details = mailbox('get', 'alias_details', $alias)) {
  1452. $data[] = $details;
  1453. }
  1454. else {
  1455. continue;
  1456. }
  1457. }
  1458. }
  1459. }
  1460. if (!isset($data) || empty($data)) {
  1461. echo '{}';
  1462. }
  1463. else {
  1464. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1465. }
  1466. }
  1467. else {
  1468. echo '{}';
  1469. }
  1470. break;
  1471. default:
  1472. $data = mailbox('get', 'alias_details', $object);
  1473. if (!isset($data) || empty($data)) {
  1474. echo '{}';
  1475. }
  1476. else {
  1477. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1478. }
  1479. break;
  1480. }
  1481. break;
  1482. case "domain-admin":
  1483. switch ($object) {
  1484. case "all":
  1485. $domain_admins = domain_admin('get');
  1486. if (!empty($domain_admins)) {
  1487. foreach ($domain_admins as $domain_admin) {
  1488. if ($details = domain_admin('details', $domain_admin)) {
  1489. $data[] = $details;
  1490. }
  1491. else {
  1492. continue;
  1493. }
  1494. }
  1495. if (!isset($data) || empty($data)) {
  1496. echo '{}';
  1497. }
  1498. else {
  1499. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1500. }
  1501. }
  1502. else {
  1503. echo '{}';
  1504. }
  1505. break;
  1506. default:
  1507. $data = domain_admin('details', $object);
  1508. if (!isset($data) || empty($data)) {
  1509. echo '{}';
  1510. }
  1511. else {
  1512. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  1513. }
  1514. break;
  1515. }
  1516. break;
  1517. case "u2f-registration":
  1518. header('Content-Type: application/javascript');
  1519. if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
  1520. list($req, $sigs) = $u2f->getRegisterData(get_u2f_registrations($object));
  1521. $_SESSION['regReq'] = json_encode($req);
  1522. $_SESSION['regSigs'] = json_encode($sigs);
  1523. echo 'var req = ' . json_encode($req) . ';';
  1524. echo 'var registeredKeys = ' . json_encode($sigs) . ';';
  1525. echo 'var appId = req.appId;';
  1526. echo 'var registerRequests = [{version: req.version, challenge: req.challenge}];';
  1527. }
  1528. else {
  1529. return;
  1530. }
  1531. break;
  1532. case "u2f-authentication":
  1533. header('Content-Type: application/javascript');
  1534. if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
  1535. $auth_data = $u2f->getAuthenticateData(get_u2f_registrations($object));
  1536. $challenge = $auth_data[0]->challenge;
  1537. $appId = $auth_data[0]->appId;
  1538. foreach ($auth_data as $each) {
  1539. $key = array(); // Empty array
  1540. $key['version'] = $each->version;
  1541. $key['keyHandle'] = $each->keyHandle;
  1542. $registeredKey[] = $key;
  1543. }
  1544. $_SESSION['authReq'] = json_encode($auth_data);
  1545. echo 'var appId = "' . $appId . '";';
  1546. echo 'var challenge = ' . json_encode($challenge) . ';';
  1547. echo 'var registeredKeys = ' . json_encode($registeredKey) . ';';
  1548. }
  1549. else {
  1550. return;
  1551. }
  1552. break;
  1553. default:
  1554. echo '{}';
  1555. break;
  1556. }
  1557. break;
  1558. case "delete":
  1559. switch ($category) {
  1560. case "alias":
  1561. if (isset($_POST['items'])) {
  1562. $items = (array)json_decode($_POST['items'], true);
  1563. if (is_array($items)) {
  1564. if (mailbox('delete', 'alias', array('address' => $items)) === false) {
  1565. if (isset($_SESSION['return'])) {
  1566. echo json_encode($_SESSION['return']);
  1567. }
  1568. else {
  1569. echo json_encode(array(
  1570. 'type' => 'error',
  1571. 'msg' => 'Deletion of items/s failed'
  1572. ));
  1573. }
  1574. }
  1575. else {
  1576. if (isset($_SESSION['return'])) {
  1577. echo json_encode($_SESSION['return']);
  1578. }
  1579. else {
  1580. echo json_encode(array(
  1581. 'type' => 'success',
  1582. 'msg' => 'Task completed'
  1583. ));
  1584. }
  1585. }
  1586. }
  1587. else {
  1588. echo json_encode(array(
  1589. 'type' => 'error',
  1590. 'msg' => 'Cannot find address array in post data'
  1591. ));
  1592. }
  1593. }
  1594. else {
  1595. echo json_encode(array(
  1596. 'type' => 'error',
  1597. 'msg' => 'Cannot find items in post data'
  1598. ));
  1599. }
  1600. break;
  1601. case "relayhost":
  1602. if (isset($_POST['items'])) {
  1603. $items = (array)json_decode($_POST['items'], true);
  1604. if (is_array($items)) {
  1605. if (relayhost('delete', array('id' => $items)) === false) {
  1606. if (isset($_SESSION['return'])) {
  1607. echo json_encode($_SESSION['return']);
  1608. }
  1609. else {
  1610. echo json_encode(array(
  1611. 'type' => 'error',
  1612. 'msg' => 'Deletion of items/s failed'
  1613. ));
  1614. }
  1615. }
  1616. else {
  1617. if (isset($_SESSION['return'])) {
  1618. echo json_encode($_SESSION['return']);
  1619. }
  1620. else {
  1621. echo json_encode(array(
  1622. 'type' => 'success',
  1623. 'msg' => 'Task completed'
  1624. ));
  1625. }
  1626. }
  1627. }
  1628. else {
  1629. echo json_encode(array(
  1630. 'type' => 'error',
  1631. 'msg' => 'Cannot find id array in post data'
  1632. ));
  1633. }
  1634. }
  1635. else {
  1636. echo json_encode(array(
  1637. 'type' => 'error',
  1638. 'msg' => 'Cannot find items in post data'
  1639. ));
  1640. }
  1641. break;
  1642. case "syncjob":
  1643. if (isset($_POST['items'])) {
  1644. $items = (array)json_decode($_POST['items'], true);
  1645. if (is_array($items)) {
  1646. if (mailbox('delete', 'syncjob', array('id' => $items)) === false) {
  1647. if (isset($_SESSION['return'])) {
  1648. echo json_encode($_SESSION['return']);
  1649. }
  1650. else {
  1651. echo json_encode(array(
  1652. 'type' => 'error',
  1653. 'msg' => 'Deletion of items/s failed'
  1654. ));
  1655. }
  1656. }
  1657. else {
  1658. if (isset($_SESSION['return'])) {
  1659. echo json_encode($_SESSION['return']);
  1660. }
  1661. else {
  1662. echo json_encode(array(
  1663. 'type' => 'success',
  1664. 'msg' => 'Task completed'
  1665. ));
  1666. }
  1667. }
  1668. }
  1669. else {
  1670. echo json_encode(array(
  1671. 'type' => 'error',
  1672. 'msg' => 'Cannot find id array in post data'
  1673. ));
  1674. }
  1675. }
  1676. else {
  1677. echo json_encode(array(
  1678. 'type' => 'error',
  1679. 'msg' => 'Cannot find items in post data'
  1680. ));
  1681. }
  1682. break;
  1683. case "filter":
  1684. if (isset($_POST['items'])) {
  1685. $items = (array)json_decode($_POST['items'], true);
  1686. if (is_array($items)) {
  1687. if (mailbox('delete', 'filter', array('id' => $items)) === false) {
  1688. if (isset($_SESSION['return'])) {
  1689. echo json_encode($_SESSION['return']);
  1690. }
  1691. else {
  1692. echo json_encode(array(
  1693. 'type' => 'error',
  1694. 'msg' => 'Deletion of items/s failed'
  1695. ));
  1696. }
  1697. }
  1698. else {
  1699. if (isset($_SESSION['return'])) {
  1700. echo json_encode($_SESSION['return']);
  1701. }
  1702. else {
  1703. echo json_encode(array(
  1704. 'type' => 'success',
  1705. 'msg' => 'Task completed'
  1706. ));
  1707. }
  1708. }
  1709. }
  1710. else {
  1711. echo json_encode(array(
  1712. 'type' => 'error',
  1713. 'msg' => 'Cannot find id array in post data'
  1714. ));
  1715. }
  1716. }
  1717. else {
  1718. echo json_encode(array(
  1719. 'type' => 'error',
  1720. 'msg' => 'Cannot find items in post data'
  1721. ));
  1722. }
  1723. break;
  1724. case "qitem":
  1725. if (isset($_POST['items'])) {
  1726. $items = (array)json_decode($_POST['items'], true);
  1727. if (is_array($items)) {
  1728. if (quarantine('delete', array('id' => $items)) === false) {
  1729. if (isset($_SESSION['return'])) {
  1730. echo json_encode($_SESSION['return']);
  1731. }
  1732. else {
  1733. echo json_encode(array(
  1734. 'type' => 'error',
  1735. 'msg' => 'Deletion of items/s failed'
  1736. ));
  1737. }
  1738. }
  1739. else {
  1740. if (isset($_SESSION['return'])) {
  1741. echo json_encode($_SESSION['return']);
  1742. }
  1743. else {
  1744. echo json_encode(array(
  1745. 'type' => 'success',
  1746. 'msg' => 'Task completed'
  1747. ));
  1748. }
  1749. }
  1750. }
  1751. else {
  1752. echo json_encode(array(
  1753. 'type' => 'error',
  1754. 'msg' => 'Cannot find id array in post data'
  1755. ));
  1756. }
  1757. }
  1758. else {
  1759. echo json_encode(array(
  1760. 'type' => 'error',
  1761. 'msg' => 'Cannot find items in post data'
  1762. ));
  1763. }
  1764. break;
  1765. case "bcc":
  1766. if (isset($_POST['items'])) {
  1767. $items = (array)json_decode($_POST['items'], true);
  1768. if (is_array($items)) {
  1769. if (bcc('delete', array('id' => $items)) === false) {
  1770. if (isset($_SESSION['return'])) {
  1771. echo json_encode($_SESSION['return']);
  1772. }
  1773. else {
  1774. echo json_encode(array(
  1775. 'type' => 'error',
  1776. 'msg' => 'Deletion of items/s failed'
  1777. ));
  1778. }
  1779. }
  1780. else {
  1781. if (isset($_SESSION['return'])) {
  1782. echo json_encode($_SESSION['return']);
  1783. }
  1784. else {
  1785. echo json_encode(array(
  1786. 'type' => 'success',
  1787. 'msg' => 'Task completed'
  1788. ));
  1789. }
  1790. }
  1791. }
  1792. else {
  1793. echo json_encode(array(
  1794. 'type' => 'error',
  1795. 'msg' => 'Cannot find id array in post data'
  1796. ));
  1797. }
  1798. }
  1799. else {
  1800. echo json_encode(array(
  1801. 'type' => 'error',
  1802. 'msg' => 'Cannot find items in post data'
  1803. ));
  1804. }
  1805. break;
  1806. case "recipient_map":
  1807. if (isset($_POST['items'])) {
  1808. $items = (array)json_decode($_POST['items'], true);
  1809. if (is_array($items)) {
  1810. if (recipient_map('delete', array('id' => $items)) === false) {
  1811. if (isset($_SESSION['return'])) {
  1812. echo json_encode($_SESSION['return']);
  1813. }
  1814. else {
  1815. echo json_encode(array(
  1816. 'type' => 'error',
  1817. 'msg' => 'Deletion of items/s failed'
  1818. ));
  1819. }
  1820. }
  1821. else {
  1822. if (isset($_SESSION['return'])) {
  1823. echo json_encode($_SESSION['return']);
  1824. }
  1825. else {
  1826. echo json_encode(array(
  1827. 'type' => 'success',
  1828. 'msg' => 'Task completed'
  1829. ));
  1830. }
  1831. }
  1832. }
  1833. else {
  1834. echo json_encode(array(
  1835. 'type' => 'error',
  1836. 'msg' => 'Cannot find id array in post data'
  1837. ));
  1838. }
  1839. }
  1840. else {
  1841. echo json_encode(array(
  1842. 'type' => 'error',
  1843. 'msg' => 'Cannot find items in post data'
  1844. ));
  1845. }
  1846. break;
  1847. case "fwdhost":
  1848. if (isset($_POST['items'])) {
  1849. $items = (array)json_decode($_POST['items'], true);
  1850. if (is_array($items)) {
  1851. if (fwdhost('delete', array('forwardinghost' => $items)) === false) {
  1852. if (isset($_SESSION['return'])) {
  1853. echo json_encode($_SESSION['return']);
  1854. }
  1855. else {
  1856. echo json_encode(array(
  1857. 'type' => 'error',
  1858. 'msg' => 'Deletion of items/s failed'
  1859. ));
  1860. }
  1861. }
  1862. else {
  1863. if (isset($_SESSION['return'])) {
  1864. echo json_encode($_SESSION['return']);
  1865. }
  1866. else {
  1867. echo json_encode(array(
  1868. 'type' => 'success',
  1869. 'msg' => 'Task completed'
  1870. ));
  1871. }
  1872. }
  1873. }
  1874. else {
  1875. echo json_encode(array(
  1876. 'type' => 'error',
  1877. 'msg' => 'Cannot find forwardinghost array in post data'
  1878. ));
  1879. }
  1880. }
  1881. else {
  1882. echo json_encode(array(
  1883. 'type' => 'error',
  1884. 'msg' => 'Cannot find items in post data'
  1885. ));
  1886. }
  1887. break;
  1888. case "dkim":
  1889. if (isset($_POST['items'])) {
  1890. $items = (array)json_decode($_POST['items'], true);
  1891. if (is_array($items)) {
  1892. if (dkim('delete', array('domains' => $items)) === false) {
  1893. if (isset($_SESSION['return'])) {
  1894. echo json_encode($_SESSION['return']);
  1895. }
  1896. else {
  1897. echo json_encode(array(
  1898. 'type' => 'error',
  1899. 'msg' => 'Deletion of items/s failed'
  1900. ));
  1901. }
  1902. }
  1903. else {
  1904. if (isset($_SESSION['return'])) {
  1905. echo json_encode($_SESSION['return']);
  1906. }
  1907. else {
  1908. echo json_encode(array(
  1909. 'type' => 'success',
  1910. 'msg' => 'Task completed'
  1911. ));
  1912. }
  1913. }
  1914. }
  1915. else {
  1916. echo json_encode(array(
  1917. 'type' => 'error',
  1918. 'msg' => 'Cannot find domains array in post data'
  1919. ));
  1920. }
  1921. }
  1922. else {
  1923. echo json_encode(array(
  1924. 'type' => 'error',
  1925. 'msg' => 'Cannot find items in post data'
  1926. ));
  1927. }
  1928. break;
  1929. case "domain":
  1930. if (isset($_POST['items'])) {
  1931. $items = (array)json_decode($_POST['items'], true);
  1932. if (is_array($items)) {
  1933. if (mailbox('delete', 'domain', array('domain' => $items)) === false) {
  1934. if (isset($_SESSION['return'])) {
  1935. echo json_encode($_SESSION['return']);
  1936. }
  1937. else {
  1938. echo json_encode(array(
  1939. 'type' => 'error',
  1940. 'msg' => 'Task failed'
  1941. ));
  1942. }
  1943. }
  1944. else {
  1945. if (isset($_SESSION['return'])) {
  1946. echo json_encode($_SESSION['return']);
  1947. }
  1948. else {
  1949. echo json_encode(array(
  1950. 'type' => 'success',
  1951. 'msg' => 'Task completed'
  1952. ));
  1953. }
  1954. }
  1955. }
  1956. else {
  1957. echo json_encode(array(
  1958. 'type' => 'error',
  1959. 'msg' => 'Cannot find domain array in post data'
  1960. ));
  1961. }
  1962. }
  1963. else {
  1964. echo json_encode(array(
  1965. 'type' => 'error',
  1966. 'msg' => 'Cannot find items in post data'
  1967. ));
  1968. }
  1969. break;
  1970. case "alias-domain":
  1971. if (isset($_POST['items'])) {
  1972. $items = (array)json_decode($_POST['items'], true);
  1973. if (is_array($items)) {
  1974. if (mailbox('delete', 'alias_domain', array('alias_domain' => $items)) === false) {
  1975. if (isset($_SESSION['return'])) {
  1976. echo json_encode($_SESSION['return']);
  1977. }
  1978. else {
  1979. echo json_encode(array(
  1980. 'type' => 'error',
  1981. 'msg' => 'Task failed'
  1982. ));
  1983. }
  1984. }
  1985. else {
  1986. if (isset($_SESSION['return'])) {
  1987. echo json_encode($_SESSION['return']);
  1988. }
  1989. else {
  1990. echo json_encode(array(
  1991. 'type' => 'success',
  1992. 'msg' => 'Task completed'
  1993. ));
  1994. }
  1995. }
  1996. }
  1997. else {
  1998. echo json_encode(array(
  1999. 'type' => 'error',
  2000. 'msg' => 'Cannot find alias_domain array in post data'
  2001. ));
  2002. }
  2003. }
  2004. else {
  2005. echo json_encode(array(
  2006. 'type' => 'error',
  2007. 'msg' => 'Cannot find items in post data'
  2008. ));
  2009. }
  2010. break;
  2011. case "mailbox":
  2012. if (isset($_POST['items'])) {
  2013. $items = (array)json_decode($_POST['items'], true);
  2014. if (is_array($items)) {
  2015. if (mailbox('delete', 'mailbox', array('username' => $items)) === false) {
  2016. if (isset($_SESSION['return'])) {
  2017. echo json_encode($_SESSION['return']);
  2018. }
  2019. else {
  2020. echo json_encode(array(
  2021. 'type' => 'error',
  2022. 'msg' => 'Task failed'
  2023. ));
  2024. }
  2025. }
  2026. else {
  2027. if (isset($_SESSION['return'])) {
  2028. echo json_encode($_SESSION['return']);
  2029. }
  2030. else {
  2031. echo json_encode(array(
  2032. 'type' => 'success',
  2033. 'msg' => 'Task completed'
  2034. ));
  2035. }
  2036. }
  2037. }
  2038. else {
  2039. echo json_encode(array(
  2040. 'type' => 'error',
  2041. 'msg' => 'Cannot find username array in post data'
  2042. ));
  2043. }
  2044. }
  2045. else {
  2046. echo json_encode(array(
  2047. 'type' => 'error',
  2048. 'msg' => 'Cannot find items in post data'
  2049. ));
  2050. }
  2051. break;
  2052. case "resource":
  2053. if (isset($_POST['items'])) {
  2054. $items = (array)json_decode($_POST['items'], true);
  2055. if (is_array($items)) {
  2056. if (mailbox('delete', 'resource', array('name' => $items)) === false) {
  2057. if (isset($_SESSION['return'])) {
  2058. echo json_encode($_SESSION['return']);
  2059. }
  2060. else {
  2061. echo json_encode(array(
  2062. 'type' => 'error',
  2063. 'msg' => 'Task failed'
  2064. ));
  2065. }
  2066. }
  2067. else {
  2068. if (isset($_SESSION['return'])) {
  2069. echo json_encode($_SESSION['return']);
  2070. }
  2071. else {
  2072. echo json_encode(array(
  2073. 'type' => 'success',
  2074. 'msg' => 'Task completed'
  2075. ));
  2076. }
  2077. }
  2078. }
  2079. else {
  2080. echo json_encode(array(
  2081. 'type' => 'error',
  2082. 'msg' => 'Cannot find name array in post data'
  2083. ));
  2084. }
  2085. }
  2086. else {
  2087. echo json_encode(array(
  2088. 'type' => 'error',
  2089. 'msg' => 'Cannot find items in post data'
  2090. ));
  2091. }
  2092. break;
  2093. case "mailbox-policy":
  2094. if (isset($_POST['items'])) {
  2095. $items = (array)json_decode($_POST['items'], true);
  2096. if (is_array($items)) {
  2097. if (policy('delete', 'mailbox', array('prefid' => $items)) === false) {
  2098. if (isset($_SESSION['return'])) {
  2099. echo json_encode($_SESSION['return']);
  2100. }
  2101. else {
  2102. echo json_encode(array(
  2103. 'type' => 'error',
  2104. 'msg' => 'Task failed'
  2105. ));
  2106. }
  2107. }
  2108. else {
  2109. if (isset($_SESSION['return'])) {
  2110. echo json_encode($_SESSION['return']);
  2111. }
  2112. else {
  2113. echo json_encode(array(
  2114. 'type' => 'success',
  2115. 'msg' => 'Task completed'
  2116. ));
  2117. }
  2118. }
  2119. }
  2120. else {
  2121. echo json_encode(array(
  2122. 'type' => 'error',
  2123. 'msg' => 'Cannot find name array in post data'
  2124. ));
  2125. }
  2126. }
  2127. else {
  2128. echo json_encode(array(
  2129. 'type' => 'error',
  2130. 'msg' => 'Cannot find items in post data'
  2131. ));
  2132. }
  2133. break;
  2134. case "domain-policy":
  2135. if (isset($_POST['items'])) {
  2136. $items = (array)json_decode($_POST['items'], true);
  2137. if (is_array($items)) {
  2138. if (policy('delete', 'domain', array('prefid' => $items)) === false) {
  2139. if (isset($_SESSION['return'])) {
  2140. echo json_encode($_SESSION['return']);
  2141. }
  2142. else {
  2143. echo json_encode(array(
  2144. 'type' => 'error',
  2145. 'msg' => 'Task failed'
  2146. ));
  2147. }
  2148. }
  2149. else {
  2150. if (isset($_SESSION['return'])) {
  2151. echo json_encode($_SESSION['return']);
  2152. }
  2153. else {
  2154. echo json_encode(array(
  2155. 'type' => 'success',
  2156. 'msg' => 'Task completed'
  2157. ));
  2158. }
  2159. }
  2160. }
  2161. else {
  2162. echo json_encode(array(
  2163. 'type' => 'error',
  2164. 'msg' => 'Cannot find name array in post data'
  2165. ));
  2166. }
  2167. }
  2168. else {
  2169. echo json_encode(array(
  2170. 'type' => 'error',
  2171. 'msg' => 'Cannot find items in post data'
  2172. ));
  2173. }
  2174. break;
  2175. case "time_limited_alias":
  2176. if (isset($_POST['items'])) {
  2177. $items = (array)json_decode($_POST['items'], true);
  2178. if (is_array($items)) {
  2179. if (mailbox('delete', 'time_limited_alias', array('address' => $items)) === false) {
  2180. if (isset($_SESSION['return'])) {
  2181. echo json_encode($_SESSION['return']);
  2182. }
  2183. else {
  2184. echo json_encode(array(
  2185. 'type' => 'error',
  2186. 'msg' => 'Task failed'
  2187. ));
  2188. }
  2189. }
  2190. else {
  2191. if (isset($_SESSION['return'])) {
  2192. echo json_encode($_SESSION['return']);
  2193. }
  2194. else {
  2195. echo json_encode(array(
  2196. 'type' => 'success',
  2197. 'msg' => 'Task completed'
  2198. ));
  2199. }
  2200. }
  2201. }
  2202. else {
  2203. echo json_encode(array(
  2204. 'type' => 'error',
  2205. 'msg' => 'Cannot find name array in post data'
  2206. ));
  2207. }
  2208. }
  2209. else {
  2210. echo json_encode(array(
  2211. 'type' => 'error',
  2212. 'msg' => 'Cannot find items in post data'
  2213. ));
  2214. }
  2215. break;
  2216. case "eas_cache":
  2217. if (isset($_POST['items'])) {
  2218. $items = (array)json_decode($_POST['items'], true);
  2219. if (is_array($items)) {
  2220. if (mailbox('delete', 'eas_cache', array('username' => $items)) === false) {
  2221. if (isset($_SESSION['return'])) {
  2222. echo json_encode($_SESSION['return']);
  2223. }
  2224. else {
  2225. echo json_encode(array(
  2226. 'type' => 'error',
  2227. 'msg' => 'Task failed'
  2228. ));
  2229. }
  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' => 'Cannot find name array in post data'
  2247. ));
  2248. }
  2249. }
  2250. else {
  2251. echo json_encode(array(
  2252. 'type' => 'error',
  2253. 'msg' => 'Cannot find items in post data'
  2254. ));
  2255. }
  2256. break;
  2257. case "domain-admin":
  2258. if (isset($_POST['items'])) {
  2259. $items = (array)json_decode($_POST['items'], true);
  2260. if (is_array($items)) {
  2261. if (domain_admin('delete', array('username' => $items)) === 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' => 'Task failed'
  2269. ));
  2270. }
  2271. }
  2272. else {
  2273. if (isset($_SESSION['return'])) {
  2274. echo json_encode($_SESSION['return']);
  2275. }
  2276. else {
  2277. echo json_encode(array(
  2278. 'type' => 'success',
  2279. 'msg' => 'Task completed'
  2280. ));
  2281. }
  2282. }
  2283. }
  2284. else {
  2285. echo json_encode(array(
  2286. 'type' => 'error',
  2287. 'msg' => 'Cannot find name array in post data'
  2288. ));
  2289. }
  2290. }
  2291. else {
  2292. echo json_encode(array(
  2293. 'type' => 'error',
  2294. 'msg' => 'Cannot find items in post data'
  2295. ));
  2296. }
  2297. break;
  2298. }
  2299. break;
  2300. case "edit":
  2301. switch ($category) {
  2302. case "bcc":
  2303. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2304. $items = (array)json_decode($_POST['items'], true);
  2305. $attr = (array)json_decode($_POST['attr'], true);
  2306. $postarray = array_merge(array('id' => $items), $attr);
  2307. if (is_array($postarray['id'])) {
  2308. if (bcc('edit', $postarray) === false) {
  2309. if (isset($_SESSION['return'])) {
  2310. echo json_encode($_SESSION['return']);
  2311. }
  2312. else {
  2313. echo json_encode(array(
  2314. 'type' => 'error',
  2315. 'msg' => 'Edit failed'
  2316. ));
  2317. }
  2318. exit();
  2319. }
  2320. else {
  2321. if (isset($_SESSION['return'])) {
  2322. echo json_encode($_SESSION['return']);
  2323. }
  2324. else {
  2325. echo json_encode(array(
  2326. 'type' => 'success',
  2327. 'msg' => 'Task completed'
  2328. ));
  2329. }
  2330. }
  2331. }
  2332. else {
  2333. echo json_encode(array(
  2334. 'type' => 'error',
  2335. 'msg' => 'Incomplete post data'
  2336. ));
  2337. }
  2338. }
  2339. else {
  2340. echo json_encode(array(
  2341. 'type' => 'error',
  2342. 'msg' => 'Incomplete post data'
  2343. ));
  2344. }
  2345. break;
  2346. case "recipient_map":
  2347. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2348. $items = (array)json_decode($_POST['items'], true);
  2349. $attr = (array)json_decode($_POST['attr'], true);
  2350. $postarray = array_merge(array('id' => $items), $attr);
  2351. if (is_array($postarray['id'])) {
  2352. if (recipient_map('edit', $postarray) === false) {
  2353. if (isset($_SESSION['return'])) {
  2354. echo json_encode($_SESSION['return']);
  2355. }
  2356. else {
  2357. echo json_encode(array(
  2358. 'type' => 'error',
  2359. 'msg' => 'Edit failed'
  2360. ));
  2361. }
  2362. exit();
  2363. }
  2364. else {
  2365. if (isset($_SESSION['return'])) {
  2366. echo json_encode($_SESSION['return']);
  2367. }
  2368. else {
  2369. echo json_encode(array(
  2370. 'type' => 'success',
  2371. 'msg' => 'Task completed'
  2372. ));
  2373. }
  2374. }
  2375. }
  2376. else {
  2377. echo json_encode(array(
  2378. 'type' => 'error',
  2379. 'msg' => 'Incomplete post data'
  2380. ));
  2381. }
  2382. }
  2383. else {
  2384. echo json_encode(array(
  2385. 'type' => 'error',
  2386. 'msg' => 'Incomplete post data'
  2387. ));
  2388. }
  2389. break;
  2390. case "alias":
  2391. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2392. $items = (array)json_decode($_POST['items'], true);
  2393. $attr = (array)json_decode($_POST['attr'], true);
  2394. $postarray = array_merge(array('address' => $items), $attr);
  2395. if (is_array($postarray['address'])) {
  2396. if (mailbox('edit', 'alias', $postarray) === false) {
  2397. if (isset($_SESSION['return'])) {
  2398. echo json_encode($_SESSION['return']);
  2399. }
  2400. else {
  2401. echo json_encode(array(
  2402. 'type' => 'error',
  2403. 'msg' => 'Edit failed'
  2404. ));
  2405. }
  2406. exit();
  2407. }
  2408. else {
  2409. if (isset($_SESSION['return'])) {
  2410. echo json_encode($_SESSION['return']);
  2411. }
  2412. else {
  2413. echo json_encode(array(
  2414. 'type' => 'success',
  2415. 'msg' => 'Task completed'
  2416. ));
  2417. }
  2418. }
  2419. }
  2420. else {
  2421. echo json_encode(array(
  2422. 'type' => 'error',
  2423. 'msg' => 'Incomplete post data'
  2424. ));
  2425. }
  2426. }
  2427. else {
  2428. echo json_encode(array(
  2429. 'type' => 'error',
  2430. 'msg' => 'Incomplete post data'
  2431. ));
  2432. }
  2433. break;
  2434. case "app_links":
  2435. if (isset($_POST['attr'])) {
  2436. $attr = (array)json_decode($_POST['attr'], true);
  2437. if (is_array($attr)) {
  2438. if (customize('edit', 'app_links', $attr) === false) {
  2439. if (isset($_SESSION['return'])) {
  2440. echo json_encode($_SESSION['return']);
  2441. }
  2442. else {
  2443. echo json_encode(array(
  2444. 'type' => 'error',
  2445. 'msg' => 'Edit failed'
  2446. ));
  2447. }
  2448. exit();
  2449. }
  2450. else {
  2451. if (isset($_SESSION['return'])) {
  2452. echo json_encode($_SESSION['return']);
  2453. }
  2454. else {
  2455. echo json_encode(array(
  2456. 'type' => 'success',
  2457. 'msg' => 'Task completed'
  2458. ));
  2459. }
  2460. }
  2461. }
  2462. else {
  2463. echo json_encode(array(
  2464. 'type' => 'error',
  2465. 'msg' => 'Incomplete post data'
  2466. ));
  2467. }
  2468. }
  2469. else {
  2470. echo json_encode(array(
  2471. 'type' => 'error',
  2472. 'msg' => 'Incomplete post data'
  2473. ));
  2474. }
  2475. break;
  2476. case "relayhost":
  2477. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2478. $items = (array)json_decode($_POST['items'], true);
  2479. $attr = (array)json_decode($_POST['attr'], true);
  2480. $postarray = array_merge(array('id' => $items), $attr);
  2481. if (is_array($postarray['id'])) {
  2482. if (relayhost('edit', $postarray) === false) {
  2483. if (isset($_SESSION['return'])) {
  2484. echo json_encode($_SESSION['return']);
  2485. }
  2486. else {
  2487. echo json_encode(array(
  2488. 'type' => 'error',
  2489. 'msg' => 'Edit failed'
  2490. ));
  2491. }
  2492. exit();
  2493. }
  2494. else {
  2495. if (isset($_SESSION['return'])) {
  2496. echo json_encode($_SESSION['return']);
  2497. }
  2498. else {
  2499. echo json_encode(array(
  2500. 'type' => 'success',
  2501. 'msg' => 'Task completed'
  2502. ));
  2503. }
  2504. }
  2505. }
  2506. else {
  2507. echo json_encode(array(
  2508. 'type' => 'error',
  2509. 'msg' => 'Incomplete post data'
  2510. ));
  2511. }
  2512. }
  2513. else {
  2514. echo json_encode(array(
  2515. 'type' => 'error',
  2516. 'msg' => 'Incomplete post data'
  2517. ));
  2518. }
  2519. break;
  2520. case "delimiter_action":
  2521. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2522. $items = (array)json_decode($_POST['items'], true);
  2523. $attr = (array)json_decode($_POST['attr'], true);
  2524. $postarray = array_merge(array('username' => $items), $attr);
  2525. if (is_array($postarray['username'])) {
  2526. if (mailbox('edit', 'delimiter_action', $postarray) === false) {
  2527. if (isset($_SESSION['return'])) {
  2528. echo json_encode($_SESSION['return']);
  2529. }
  2530. else {
  2531. echo json_encode(array(
  2532. 'type' => 'error',
  2533. 'msg' => 'Edit failed'
  2534. ));
  2535. }
  2536. exit();
  2537. }
  2538. else {
  2539. if (isset($_SESSION['return'])) {
  2540. echo json_encode($_SESSION['return']);
  2541. }
  2542. else {
  2543. echo json_encode(array(
  2544. 'type' => 'success',
  2545. 'msg' => 'Task completed'
  2546. ));
  2547. }
  2548. }
  2549. }
  2550. else {
  2551. echo json_encode(array(
  2552. 'type' => 'error',
  2553. 'msg' => 'Incomplete post data'
  2554. ));
  2555. }
  2556. }
  2557. else {
  2558. echo json_encode(array(
  2559. 'type' => 'error',
  2560. 'msg' => 'Incomplete post data'
  2561. ));
  2562. }
  2563. break;
  2564. case "tls_policy":
  2565. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2566. $items = (array)json_decode($_POST['items'], true);
  2567. $attr = (array)json_decode($_POST['attr'], true);
  2568. $postarray = array_merge(array('username' => $items), $attr);
  2569. if (is_array($postarray['username'])) {
  2570. if (mailbox('edit', 'tls_policy', $postarray) === false) {
  2571. if (isset($_SESSION['return'])) {
  2572. echo json_encode($_SESSION['return']);
  2573. }
  2574. else {
  2575. echo json_encode(array(
  2576. 'type' => 'error',
  2577. 'msg' => 'Edit failed'
  2578. ));
  2579. }
  2580. exit();
  2581. }
  2582. else {
  2583. if (isset($_SESSION['return'])) {
  2584. echo json_encode($_SESSION['return']);
  2585. }
  2586. else {
  2587. echo json_encode(array(
  2588. 'type' => 'success',
  2589. 'msg' => 'Task completed'
  2590. ));
  2591. }
  2592. }
  2593. }
  2594. else {
  2595. echo json_encode(array(
  2596. 'type' => 'error',
  2597. 'msg' => 'Incomplete post data'
  2598. ));
  2599. }
  2600. }
  2601. else {
  2602. echo json_encode(array(
  2603. 'type' => 'error',
  2604. 'msg' => 'Incomplete post data'
  2605. ));
  2606. }
  2607. break;
  2608. case "qitem":
  2609. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2610. $items = (array)json_decode($_POST['items'], true);
  2611. $attr = (array)json_decode($_POST['attr'], true);
  2612. $postarray = array_merge(array('id' => $items), $attr);
  2613. if (is_array($postarray['id'])) {
  2614. if (quarantine('edit', $postarray) === false) {
  2615. if (isset($_SESSION['return'])) {
  2616. echo json_encode($_SESSION['return']);
  2617. }
  2618. else {
  2619. echo json_encode(array(
  2620. 'type' => 'error',
  2621. 'msg' => 'Edit failed'
  2622. ));
  2623. }
  2624. exit();
  2625. }
  2626. else {
  2627. if (isset($_SESSION['return'])) {
  2628. echo json_encode($_SESSION['return']);
  2629. }
  2630. else {
  2631. echo json_encode(array(
  2632. 'type' => 'success',
  2633. 'msg' => 'Task completed'
  2634. ));
  2635. }
  2636. }
  2637. }
  2638. else {
  2639. echo json_encode(array(
  2640. 'type' => 'error',
  2641. 'msg' => 'Incomplete post data'
  2642. ));
  2643. }
  2644. }
  2645. else {
  2646. echo json_encode(array(
  2647. 'type' => 'error',
  2648. 'msg' => 'Incomplete post data'
  2649. ));
  2650. }
  2651. break;
  2652. case "quarantine":
  2653. // Edit settings, does not need IDs
  2654. if (isset($_POST['attr'])) {
  2655. $postarray = json_decode($_POST['attr'], true);
  2656. if (quarantine('edit', $postarray) === false) {
  2657. if (isset($_SESSION['return'])) {
  2658. echo json_encode($_SESSION['return']);
  2659. }
  2660. else {
  2661. echo json_encode(array(
  2662. 'type' => 'error',
  2663. 'msg' => 'Edit failed'
  2664. ));
  2665. }
  2666. exit();
  2667. }
  2668. else {
  2669. if (isset($_SESSION['return'])) {
  2670. echo json_encode($_SESSION['return']);
  2671. }
  2672. else {
  2673. echo json_encode(array(
  2674. 'type' => 'success',
  2675. 'msg' => 'Task completed'
  2676. ));
  2677. }
  2678. }
  2679. }
  2680. else {
  2681. echo json_encode(array(
  2682. 'type' => 'error',
  2683. 'msg' => 'Incomplete post data'
  2684. ));
  2685. }
  2686. break;
  2687. case "time_limited_alias":
  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('address' => $items), $attr);
  2692. if (is_array($postarray['address'])) {
  2693. if (mailbox('edit', 'time_limited_alias', $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 "mailbox":
  2732. // sender_acl:0 removes all entries
  2733. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2734. $items = (array)json_decode($_POST['items'], true);
  2735. $attr = (array)json_decode($_POST['attr'], true);
  2736. $postarray = array_merge(array('username' => $items), $attr);
  2737. if (is_array($postarray['username'])) {
  2738. if (mailbox('edit', 'mailbox', $postarray) === false) {
  2739. if (isset($_SESSION['return'])) {
  2740. echo json_encode($_SESSION['return']);
  2741. }
  2742. else {
  2743. echo json_encode(array(
  2744. 'type' => 'error',
  2745. 'msg' => 'Edit failed'
  2746. ));
  2747. }
  2748. exit();
  2749. }
  2750. else {
  2751. if (isset($_SESSION['return'])) {
  2752. echo json_encode($_SESSION['return']);
  2753. }
  2754. else {
  2755. echo json_encode(array(
  2756. 'type' => 'success',
  2757. 'msg' => 'Task completed'
  2758. ));
  2759. }
  2760. }
  2761. }
  2762. else {
  2763. echo json_encode(array(
  2764. 'type' => 'error',
  2765. 'msg' => 'Incomplete post data'
  2766. ));
  2767. }
  2768. }
  2769. else {
  2770. echo json_encode(array(
  2771. 'type' => 'error',
  2772. 'msg' => 'Incomplete post data'
  2773. ));
  2774. }
  2775. break;
  2776. case "syncjob":
  2777. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2778. $items = (array)json_decode($_POST['items'], true);
  2779. $attr = (array)json_decode($_POST['attr'], true);
  2780. $postarray = array_merge(array('id' => $items), $attr);
  2781. if (is_array($postarray['id'])) {
  2782. if (mailbox('edit', 'syncjob', $postarray) === false) {
  2783. if (isset($_SESSION['return'])) {
  2784. echo json_encode($_SESSION['return']);
  2785. }
  2786. else {
  2787. echo json_encode(array(
  2788. 'type' => 'error',
  2789. 'msg' => 'Edit failed'
  2790. ));
  2791. }
  2792. exit();
  2793. }
  2794. else {
  2795. if (isset($_SESSION['return'])) {
  2796. echo json_encode($_SESSION['return']);
  2797. }
  2798. else {
  2799. echo json_encode(array(
  2800. 'type' => 'success',
  2801. 'msg' => 'Task completed'
  2802. ));
  2803. }
  2804. }
  2805. }
  2806. else {
  2807. echo json_encode(array(
  2808. 'type' => 'error',
  2809. 'msg' => 'Incomplete post data'
  2810. ));
  2811. }
  2812. }
  2813. else {
  2814. echo json_encode(array(
  2815. 'type' => 'error',
  2816. 'msg' => 'Incomplete post data'
  2817. ));
  2818. }
  2819. break;
  2820. case "filter":
  2821. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2822. $items = (array)json_decode($_POST['items'], true);
  2823. $attr = (array)json_decode($_POST['attr'], true);
  2824. $postarray = array_merge(array('id' => $items), $attr);
  2825. if (is_array($postarray['id'])) {
  2826. if (mailbox('edit', 'filter', $postarray) === false) {
  2827. if (isset($_SESSION['return'])) {
  2828. echo json_encode($_SESSION['return']);
  2829. }
  2830. else {
  2831. echo json_encode(array(
  2832. 'type' => 'error',
  2833. 'msg' => 'Edit failed'
  2834. ));
  2835. }
  2836. exit();
  2837. }
  2838. else {
  2839. if (isset($_SESSION['return'])) {
  2840. echo json_encode($_SESSION['return']);
  2841. }
  2842. else {
  2843. echo json_encode(array(
  2844. 'type' => 'success',
  2845. 'msg' => 'Task completed'
  2846. ));
  2847. }
  2848. }
  2849. }
  2850. else {
  2851. echo json_encode(array(
  2852. 'type' => 'error',
  2853. 'msg' => 'Incomplete post data'
  2854. ));
  2855. }
  2856. }
  2857. else {
  2858. echo json_encode(array(
  2859. 'type' => 'error',
  2860. 'msg' => 'Incomplete post data'
  2861. ));
  2862. }
  2863. break;
  2864. case "resource":
  2865. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2866. $items = (array)json_decode($_POST['items'], true);
  2867. $attr = (array)json_decode($_POST['attr'], true);
  2868. $postarray = array_merge(array('name' => $items), $attr);
  2869. if (is_array($postarray['name'])) {
  2870. if (mailbox('edit', 'resource', $postarray) === false) {
  2871. if (isset($_SESSION['return'])) {
  2872. echo json_encode($_SESSION['return']);
  2873. }
  2874. else {
  2875. echo json_encode(array(
  2876. 'type' => 'error',
  2877. 'msg' => 'Edit failed'
  2878. ));
  2879. }
  2880. exit();
  2881. }
  2882. else {
  2883. if (isset($_SESSION['return'])) {
  2884. echo json_encode($_SESSION['return']);
  2885. }
  2886. else {
  2887. echo json_encode(array(
  2888. 'type' => 'success',
  2889. 'msg' => 'Task completed'
  2890. ));
  2891. }
  2892. }
  2893. }
  2894. else {
  2895. echo json_encode(array(
  2896. 'type' => 'error',
  2897. 'msg' => 'Incomplete post data'
  2898. ));
  2899. }
  2900. }
  2901. else {
  2902. echo json_encode(array(
  2903. 'type' => 'error',
  2904. 'msg' => 'Incomplete post data'
  2905. ));
  2906. }
  2907. break;
  2908. case "domain":
  2909. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2910. $items = (array)json_decode($_POST['items'], true);
  2911. $attr = (array)json_decode($_POST['attr'], true);
  2912. $postarray = array_merge(array('domain' => $items), $attr);
  2913. if (is_array($postarray['domain'])) {
  2914. if (mailbox('edit', 'domain', $postarray)) {
  2915. if (isset($_SESSION['return'])) {
  2916. echo json_encode($_SESSION['return']);
  2917. }
  2918. else {
  2919. echo json_encode(array(
  2920. 'type' => 'error',
  2921. 'msg' => 'Edit failed'
  2922. ));
  2923. }
  2924. exit();
  2925. }
  2926. else {
  2927. if (isset($_SESSION['return'])) {
  2928. echo json_encode($_SESSION['return']);
  2929. }
  2930. else {
  2931. echo json_encode(array(
  2932. 'type' => 'success',
  2933. 'msg' => 'Task completed'
  2934. ));
  2935. }
  2936. }
  2937. }
  2938. else {
  2939. echo json_encode(array(
  2940. 'type' => 'error',
  2941. 'msg' => 'Incomplete post data'
  2942. ));
  2943. }
  2944. }
  2945. else {
  2946. echo json_encode(array(
  2947. 'type' => 'error',
  2948. 'msg' => 'Incomplete post data'
  2949. ));
  2950. }
  2951. break;
  2952. case "ratelimit":
  2953. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2954. $items = (array)json_decode($_POST['items'], true);
  2955. $attr = (array)json_decode($_POST['attr'], true);
  2956. $postarray = array_merge(array('object' => $items), $attr);
  2957. if (is_array($postarray['object'])) {
  2958. if (mailbox('edit', 'ratelimit', $postarray) === false) {
  2959. if (isset($_SESSION['return'])) {
  2960. echo json_encode($_SESSION['return']);
  2961. }
  2962. else {
  2963. echo json_encode(array(
  2964. 'type' => 'error',
  2965. 'msg' => 'Edit failed'
  2966. ));
  2967. }
  2968. exit();
  2969. }
  2970. else {
  2971. if (isset($_SESSION['return'])) {
  2972. echo json_encode($_SESSION['return']);
  2973. }
  2974. else {
  2975. echo json_encode(array(
  2976. 'type' => 'success',
  2977. 'msg' => 'Task completed'
  2978. ));
  2979. }
  2980. }
  2981. }
  2982. else {
  2983. echo json_encode(array(
  2984. 'type' => 'error',
  2985. 'msg' => 'Incomplete post data'
  2986. ));
  2987. }
  2988. }
  2989. else {
  2990. echo json_encode(array(
  2991. 'type' => 'error',
  2992. 'msg' => 'Incomplete post data'
  2993. ));
  2994. }
  2995. break;
  2996. case "alias-domain":
  2997. if (isset($_POST['items']) && isset($_POST['attr'])) {
  2998. $items = (array)json_decode($_POST['items'], true);
  2999. $attr = (array)json_decode($_POST['attr'], true);
  3000. $postarray = array_merge(array('alias_domain' => $items), $attr);
  3001. if (is_array($postarray['alias_domain'])) {
  3002. if (mailbox('edit', 'alias_domain', $postarray) === false) {
  3003. if (isset($_SESSION['return'])) {
  3004. echo json_encode($_SESSION['return']);
  3005. }
  3006. else {
  3007. echo json_encode(array(
  3008. 'type' => 'error',
  3009. 'msg' => 'Edit failed'
  3010. ));
  3011. }
  3012. exit();
  3013. }
  3014. else {
  3015. if (isset($_SESSION['return'])) {
  3016. echo json_encode($_SESSION['return']);
  3017. }
  3018. else {
  3019. echo json_encode(array(
  3020. 'type' => 'success',
  3021. 'msg' => 'Task completed'
  3022. ));
  3023. }
  3024. }
  3025. }
  3026. else {
  3027. echo json_encode(array(
  3028. 'type' => 'error',
  3029. 'msg' => 'Incomplete post data'
  3030. ));
  3031. }
  3032. }
  3033. else {
  3034. echo json_encode(array(
  3035. 'type' => 'error',
  3036. 'msg' => 'Incomplete post data'
  3037. ));
  3038. }
  3039. break;
  3040. case "spam-score":
  3041. if (isset($_POST['items']) && isset($_POST['attr'])) {
  3042. $items = (array)json_decode($_POST['items'], true);
  3043. $attr = (array)json_decode($_POST['attr'], true);
  3044. $postarray = array_merge(array('username' => $items), $attr);
  3045. if (is_array($postarray['username'])) {
  3046. if (mailbox('edit', 'spam_score', $postarray) === false) {
  3047. if (isset($_SESSION['return'])) {
  3048. echo json_encode($_SESSION['return']);
  3049. }
  3050. else {
  3051. echo json_encode(array(
  3052. 'type' => 'error',
  3053. 'msg' => 'Edit failed'
  3054. ));
  3055. }
  3056. exit();
  3057. }
  3058. else {
  3059. if (isset($_SESSION['return'])) {
  3060. echo json_encode($_SESSION['return']);
  3061. }
  3062. else {
  3063. echo json_encode(array(
  3064. 'type' => 'success',
  3065. 'msg' => 'Task completed'
  3066. ));
  3067. }
  3068. }
  3069. }
  3070. else {
  3071. echo json_encode(array(
  3072. 'type' => 'error',
  3073. 'msg' => 'Incomplete post data'
  3074. ));
  3075. }
  3076. }
  3077. else {
  3078. echo json_encode(array(
  3079. 'type' => 'error',
  3080. 'msg' => 'Incomplete post data'
  3081. ));
  3082. }
  3083. break;
  3084. case "domain-admin":
  3085. if (isset($_POST['items']) && isset($_POST['attr'])) {
  3086. $items = (array)json_decode($_POST['items'], true);
  3087. $attr = (array)json_decode($_POST['attr'], true);
  3088. $postarray = array_merge(array('username' => $items), $attr);
  3089. if (is_array($postarray['username'])) {
  3090. if (domain_admin('edit', $postarray) === false) {
  3091. if (isset($_SESSION['return'])) {
  3092. echo json_encode($_SESSION['return']);
  3093. }
  3094. else {
  3095. echo json_encode(array(
  3096. 'type' => 'error',
  3097. 'msg' => 'Edit failed'
  3098. ));
  3099. }
  3100. exit();
  3101. }
  3102. else {
  3103. if (isset($_SESSION['return'])) {
  3104. echo json_encode($_SESSION['return']);
  3105. }
  3106. else {
  3107. echo json_encode(array(
  3108. 'type' => 'success',
  3109. 'msg' => 'Task completed'
  3110. ));
  3111. }
  3112. }
  3113. }
  3114. else {
  3115. echo json_encode(array(
  3116. 'type' => 'error',
  3117. 'msg' => 'Incomplete post data'
  3118. ));
  3119. }
  3120. }
  3121. else {
  3122. echo json_encode(array(
  3123. 'type' => 'error',
  3124. 'msg' => 'Incomplete post data'
  3125. ));
  3126. }
  3127. break;
  3128. case "fwdhost":
  3129. if (isset($_POST['items']) && isset($_POST['attr'])) {
  3130. $items = (array)json_decode($_POST['items'], true);
  3131. $attr = (array)json_decode($_POST['attr'], true);
  3132. $postarray = array_merge(array('fwdhost' => $items), $attr);
  3133. if (is_array($postarray['fwdhost'])) {
  3134. if (fwdhost('edit', $postarray) === false) {
  3135. if (isset($_SESSION['return'])) {
  3136. echo json_encode($_SESSION['return']);
  3137. }
  3138. else {
  3139. echo json_encode(array(
  3140. 'type' => 'error',
  3141. 'msg' => 'Edit failed'
  3142. ));
  3143. }
  3144. exit();
  3145. }
  3146. else {
  3147. if (isset($_SESSION['return'])) {
  3148. echo json_encode($_SESSION['return']);
  3149. }
  3150. else {
  3151. echo json_encode(array(
  3152. 'type' => 'success',
  3153. 'msg' => 'Task completed'
  3154. ));
  3155. }
  3156. }
  3157. }
  3158. else {
  3159. echo json_encode(array(
  3160. 'type' => 'error',
  3161. 'msg' => 'Incomplete post data'
  3162. ));
  3163. }
  3164. }
  3165. else {
  3166. echo json_encode(array(
  3167. 'type' => 'error',
  3168. 'msg' => 'Incomplete post data'
  3169. ));
  3170. }
  3171. break;
  3172. case "fail2ban":
  3173. // No items
  3174. if (isset($_POST['attr'])) {
  3175. $attr = (array)json_decode($_POST['attr'], true);
  3176. if (fail2ban('edit', $attr) === false) {
  3177. if (isset($_SESSION['return'])) {
  3178. echo json_encode($_SESSION['return']);
  3179. }
  3180. else {
  3181. echo json_encode(array(
  3182. 'type' => 'error',
  3183. 'msg' => 'Edit failed'
  3184. ));
  3185. }
  3186. exit();
  3187. }
  3188. else {
  3189. if (isset($_SESSION['return'])) {
  3190. echo json_encode($_SESSION['return']);
  3191. }
  3192. else {
  3193. echo json_encode(array(
  3194. 'type' => 'success',
  3195. 'msg' => 'Task completed'
  3196. ));
  3197. }
  3198. }
  3199. }
  3200. else {
  3201. echo json_encode(array(
  3202. 'type' => 'error',
  3203. 'msg' => 'Incomplete post data'
  3204. ));
  3205. }
  3206. break;
  3207. case "ui_texts":
  3208. // No items
  3209. if (isset($_POST['attr'])) {
  3210. $attr = (array)json_decode($_POST['attr'], true);
  3211. if (customize('edit', 'ui_texts', $attr) === false) {
  3212. if (isset($_SESSION['return'])) {
  3213. echo json_encode($_SESSION['return']);
  3214. }
  3215. else {
  3216. echo json_encode(array(
  3217. 'type' => 'error',
  3218. 'msg' => 'Edit failed'
  3219. ));
  3220. }
  3221. exit();
  3222. }
  3223. else {
  3224. if (isset($_SESSION['return'])) {
  3225. echo json_encode($_SESSION['return']);
  3226. }
  3227. else {
  3228. echo json_encode(array(
  3229. 'type' => 'success',
  3230. 'msg' => 'Task completed'
  3231. ));
  3232. }
  3233. }
  3234. }
  3235. else {
  3236. echo json_encode(array(
  3237. 'type' => 'error',
  3238. 'msg' => 'Incomplete post data'
  3239. ));
  3240. }
  3241. break;
  3242. case "self":
  3243. // No items, logged-in user, users and domain admins
  3244. if ($_SESSION['mailcow_cc_role'] == "domainadmin") {
  3245. if (isset($_POST['attr'])) {
  3246. $attr = (array)json_decode($_POST['attr'], true);
  3247. if (domain_admin('edit', $attr) === false) {
  3248. if (isset($_SESSION['return'])) {
  3249. echo json_encode($_SESSION['return']);
  3250. }
  3251. else {
  3252. echo json_encode(array(
  3253. 'type' => 'error',
  3254. 'msg' => 'Edit failed'
  3255. ));
  3256. }
  3257. exit();
  3258. }
  3259. else {
  3260. if (isset($_SESSION['return'])) {
  3261. echo json_encode($_SESSION['return']);
  3262. }
  3263. else {
  3264. echo json_encode(array(
  3265. 'type' => 'success',
  3266. 'msg' => 'Task completed'
  3267. ));
  3268. }
  3269. }
  3270. }
  3271. else {
  3272. echo json_encode(array(
  3273. 'type' => 'error',
  3274. 'msg' => 'Incomplete post data'
  3275. ));
  3276. }
  3277. }
  3278. elseif ($_SESSION['mailcow_cc_role'] == "user") {
  3279. if (isset($_POST['attr'])) {
  3280. $attr = (array)json_decode($_POST['attr'], true);
  3281. if (edit_user_account($attr) === false) {
  3282. if (isset($_SESSION['return'])) {
  3283. echo json_encode($_SESSION['return']);
  3284. }
  3285. else {
  3286. echo json_encode(array(
  3287. 'type' => 'error',
  3288. 'msg' => 'Edit failed'
  3289. ));
  3290. }
  3291. exit();
  3292. }
  3293. else {
  3294. if (isset($_SESSION['return'])) {
  3295. echo json_encode($_SESSION['return']);
  3296. }
  3297. else {
  3298. echo json_encode(array(
  3299. 'type' => 'success',
  3300. 'msg' => 'Task completed'
  3301. ));
  3302. }
  3303. }
  3304. }
  3305. else {
  3306. echo json_encode(array(
  3307. 'type' => 'error',
  3308. 'msg' => 'Incomplete post data'
  3309. ));
  3310. }
  3311. }
  3312. elseif ($_SESSION['mailcow_cc_role'] == "admin") {
  3313. if (isset($_POST['attr'])) {
  3314. $attr = (array)json_decode($_POST['attr'], true);
  3315. if (edit_admin_account($attr) === false) {
  3316. if (isset($_SESSION['return'])) {
  3317. echo json_encode($_SESSION['return']);
  3318. }
  3319. else {
  3320. echo json_encode(array(
  3321. 'type' => 'error',
  3322. 'msg' => 'Edit failed'
  3323. ));
  3324. }
  3325. exit();
  3326. }
  3327. else {
  3328. if (isset($_SESSION['return'])) {
  3329. echo json_encode($_SESSION['return']);
  3330. }
  3331. else {
  3332. echo json_encode(array(
  3333. 'type' => 'success',
  3334. 'msg' => 'Task completed'
  3335. ));
  3336. }
  3337. }
  3338. }
  3339. else {
  3340. echo json_encode(array(
  3341. 'type' => 'error',
  3342. 'msg' => 'Incomplete post data'
  3343. ));
  3344. }
  3345. }
  3346. break;
  3347. }
  3348. break;
  3349. }
  3350. }
  3351. }