json_api.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  1. <?php
  2. /*
  3. edit/alias => POST data:
  4. {
  5. address: {a, b, c}, (where a, b, c represent alias addresses)
  6. active: 1 (0 or 1)
  7. }
  8. delete/alias => POST data:
  9. {
  10. address: {a, b, c}, (where a, b, c represent alias addresses)
  11. }
  12. */
  13. header('Content-Type: application/json');
  14. require_once 'inc/prerequisites.inc.php';
  15. error_reporting(0);
  16. if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_username'])) {
  17. if (isset($_GET['query'])) {
  18. $query = explode('/', $_GET['query']);
  19. $action = (isset($query[0])) ? $query[0] : null;
  20. $category = (isset($query[1])) ? $query[1] : null;
  21. $object = (isset($query[2])) ? $query[2] : null;
  22. $extra = (isset($query[3])) ? $query[3] : null;
  23. switch ($action) {
  24. case "add":
  25. switch ($category) {
  26. case "time_limited_alias":
  27. if (isset($_POST['attr'])) {
  28. $attr = (array)json_decode($_POST['attr'], true);
  29. if (mailbox('add', 'time_limited_alias', $attr) === false) {
  30. if (isset($_SESSION['return'])) {
  31. echo json_encode($_SESSION['return']);
  32. }
  33. else {
  34. echo json_encode(array(
  35. 'type' => 'error',
  36. 'msg' => 'Cannot add item'
  37. ));
  38. }
  39. }
  40. else {
  41. if (isset($_SESSION['return'])) {
  42. echo json_encode($_SESSION['return']);
  43. }
  44. else {
  45. echo json_encode(array(
  46. 'type' => 'success',
  47. 'msg' => 'Task completed'
  48. ));
  49. }
  50. }
  51. }
  52. else {
  53. echo json_encode(array(
  54. 'type' => 'error',
  55. 'msg' => 'Cannot find attributes in post data'
  56. ));
  57. }
  58. break;
  59. case "domain_admin":
  60. if (isset($_POST['attr'])) {
  61. $attr = (array)json_decode($_POST['attr'], true);
  62. if (add_domain_admin($attr) === false) {
  63. if (isset($_SESSION['return'])) {
  64. echo json_encode($_SESSION['return']);
  65. }
  66. else {
  67. echo json_encode(array(
  68. 'type' => 'error',
  69. 'msg' => 'Cannot add item'
  70. ));
  71. }
  72. }
  73. else {
  74. if (isset($_SESSION['return'])) {
  75. echo json_encode($_SESSION['return']);
  76. }
  77. else {
  78. echo json_encode(array(
  79. 'type' => 'success',
  80. 'msg' => 'Task completed'
  81. ));
  82. }
  83. }
  84. }
  85. else {
  86. echo json_encode(array(
  87. 'type' => 'error',
  88. 'msg' => 'Cannot find attributes in post data'
  89. ));
  90. }
  91. break;
  92. }
  93. break;
  94. case "get":
  95. switch ($category) {
  96. case "domain":
  97. switch ($object) {
  98. case "all":
  99. $domains = mailbox('get', 'domains');
  100. if (!empty($domains)) {
  101. foreach ($domains as $domain) {
  102. if ($details = mailbox('get', 'domain_details', $domain)) {
  103. $data[] = $details;
  104. }
  105. else {
  106. continue;
  107. }
  108. }
  109. if (!isset($data) || empty($data)) {
  110. echo '{}';
  111. }
  112. else {
  113. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  114. }
  115. }
  116. else {
  117. echo '{}';
  118. }
  119. break;
  120. default:
  121. $data = mailbox('get', 'domain_details', $object);
  122. if (!isset($data) || empty($data)) {
  123. echo '{}';
  124. }
  125. else {
  126. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  127. }
  128. break;
  129. }
  130. break;
  131. case "logs":
  132. switch ($object) {
  133. case "dovecot":
  134. if (isset($extra) && !empty($extra)) {
  135. $extra = intval($extra);
  136. $logs = get_logs('dovecot-mailcow', $extra);
  137. }
  138. else {
  139. $logs = get_logs('dovecot-mailcow', -1);
  140. }
  141. if (isset($logs) && !empty($logs)) {
  142. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  143. }
  144. else {
  145. echo '{}';
  146. }
  147. break;
  148. case "postfix":
  149. if (isset($extra) && !empty($extra)) {
  150. $extra = intval($extra);
  151. $logs = get_logs('postfix-mailcow', $extra);
  152. }
  153. else {
  154. $logs = get_logs('postfix-mailcow', -1);
  155. }
  156. if (isset($logs) && !empty($logs)) {
  157. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  158. }
  159. else {
  160. echo '{}';
  161. }
  162. break;
  163. case "sogo":
  164. if (isset($extra) && !empty($extra)) {
  165. $extra = intval($extra);
  166. $logs = get_logs('sogo-mailcow', $extra);
  167. }
  168. else {
  169. $logs = get_logs('sogo-mailcow', -1);
  170. }
  171. if (isset($logs) && !empty($logs)) {
  172. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  173. }
  174. else {
  175. echo '{}';
  176. }
  177. break;
  178. case "rspamd-history":
  179. $logs = get_logs('rspamd-history');
  180. if (isset($logs) && !empty($logs)) {
  181. echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  182. }
  183. else {
  184. echo '{}';
  185. }
  186. break;
  187. }
  188. break;
  189. case "mailbox":
  190. switch ($object) {
  191. case "all":
  192. $domains = mailbox('get', 'domains');
  193. if (!empty($domains)) {
  194. foreach ($domains as $domain) {
  195. $mailboxes = mailbox('get', 'mailboxes', $domain);
  196. if (!empty($mailboxes)) {
  197. foreach ($mailboxes as $mailbox) {
  198. if ($details = mailbox('get', 'mailbox_details', $mailbox)) {
  199. $data[] = $details;
  200. }
  201. else {
  202. continue;
  203. }
  204. }
  205. }
  206. }
  207. if (!isset($data) || empty($data)) {
  208. echo '{}';
  209. }
  210. else {
  211. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  212. }
  213. }
  214. else {
  215. echo '{}';
  216. }
  217. break;
  218. default:
  219. $data = mailbox('get', 'mailbox_details', $object);
  220. if (!isset($data) || empty($data)) {
  221. echo '{}';
  222. }
  223. else {
  224. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  225. }
  226. break;
  227. }
  228. break;
  229. case "syncjobs":
  230. switch ($object) {
  231. default:
  232. $data = mailbox('get', 'syncjobs', $object);
  233. if (!isset($data) || empty($data)) {
  234. echo '{}';
  235. }
  236. else {
  237. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  238. }
  239. break;
  240. }
  241. break;
  242. case "policy_wl_mailbox":
  243. switch ($object) {
  244. default:
  245. $data = policy('get', 'mailbox', $object)['whitelist'];
  246. if (!isset($data) || empty($data)) {
  247. echo '{}';
  248. }
  249. else {
  250. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  251. }
  252. break;
  253. }
  254. break;
  255. case "policy_bl_mailbox":
  256. switch ($object) {
  257. default:
  258. $data = policy('get', 'mailbox', $object)['blacklist'];
  259. if (!isset($data) || empty($data)) {
  260. echo '{}';
  261. }
  262. else {
  263. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  264. }
  265. break;
  266. }
  267. break;
  268. case "policy_wl_domain":
  269. switch ($object) {
  270. default:
  271. $data = policy('get', 'domain', $object)['whitelist'];
  272. if (!isset($data) || empty($data)) {
  273. echo '{}';
  274. }
  275. else {
  276. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  277. }
  278. break;
  279. }
  280. break;
  281. case "policy_bl_domain":
  282. switch ($object) {
  283. default:
  284. $data = policy('get', 'domain', $object)['blacklist'];
  285. if (!isset($data) || empty($data)) {
  286. echo '{}';
  287. }
  288. else {
  289. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  290. }
  291. break;
  292. }
  293. break;
  294. case "time_limited_aliases":
  295. switch ($object) {
  296. default:
  297. $data = mailbox('get', 'time_limited_aliases', $object);
  298. if (!isset($data) || empty($data)) {
  299. echo '{}';
  300. }
  301. else {
  302. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  303. }
  304. break;
  305. }
  306. break;
  307. case "resource":
  308. switch ($object) {
  309. case "all":
  310. $domains = mailbox('get', 'domains');
  311. if (!empty($domains)) {
  312. foreach ($domains as $domain) {
  313. $resources = mailbox('get', 'resources', $domain);
  314. if (!empty($resources)) {
  315. foreach ($resources as $resource) {
  316. if ($details = mailbox('get', 'resource_details', $resource)) {
  317. $data[] = $details;
  318. }
  319. else {
  320. continue;
  321. }
  322. }
  323. }
  324. }
  325. if (!isset($data) || empty($data)) {
  326. echo '{}';
  327. }
  328. else {
  329. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  330. }
  331. }
  332. else {
  333. echo '{}';
  334. }
  335. break;
  336. default:
  337. $data = mailbox('get', 'resource_details', $object);
  338. if (!isset($data) || empty($data)) {
  339. echo '{}';
  340. }
  341. else {
  342. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  343. }
  344. break;
  345. }
  346. break;
  347. case "fwdhost":
  348. switch ($object) {
  349. case "all":
  350. $fwdhosts = get_forwarding_hosts();
  351. if (!empty($fwdhosts)) {
  352. foreach ($fwdhosts as $fwdhost) {
  353. if ($details = get_forwarding_host_details($fwdhost)) {
  354. $data[] = $details;
  355. }
  356. else {
  357. continue;
  358. }
  359. }
  360. }
  361. if (!isset($data) || empty($data)) {
  362. echo '{}';
  363. }
  364. else {
  365. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  366. }
  367. break;
  368. default:
  369. $data = get_forwarding_host_details($object);
  370. if (!isset($data) || empty($data)) {
  371. echo '{}';
  372. }
  373. else {
  374. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  375. }
  376. break;
  377. }
  378. break;
  379. case "alias-domain":
  380. switch ($object) {
  381. case "all":
  382. $domains = mailbox('get', 'domains');
  383. if (!empty($domains)) {
  384. foreach ($domains as $domain) {
  385. $alias_domains = mailbox('get', 'alias_domains', $domain);
  386. if (!empty($alias_domains)) {
  387. foreach ($alias_domains as $alias_domain) {
  388. if ($details = mailbox('get', 'alias_domain_details', $alias_domain)) {
  389. $data[] = $details;
  390. }
  391. else {
  392. continue;
  393. }
  394. }
  395. }
  396. }
  397. if (!isset($data) || empty($data)) {
  398. echo '{}';
  399. }
  400. else {
  401. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  402. }
  403. }
  404. else {
  405. echo '{}';
  406. }
  407. break;
  408. default:
  409. $data = mailbox('get', 'alias_domains', $object);
  410. if (!isset($data) || empty($data)) {
  411. echo '{}';
  412. }
  413. else {
  414. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  415. }
  416. break;
  417. }
  418. break;
  419. case "alias":
  420. switch ($object) {
  421. case "all":
  422. $domains = array_merge(mailbox('get', 'domains'),mailbox('get', 'alias_domains'));
  423. if (!empty($domains)) {
  424. foreach ($domains as $domain) {
  425. $aliases = mailbox('get', 'aliases', $domain);
  426. if (!empty($aliases)) {
  427. foreach ($aliases as $alias) {
  428. if ($details = mailbox('get', 'alias_details', $alias)) {
  429. $data[] = $details;
  430. }
  431. else {
  432. continue;
  433. }
  434. }
  435. }
  436. }
  437. if (!isset($data) || empty($data)) {
  438. echo '{}';
  439. }
  440. else {
  441. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  442. }
  443. }
  444. else {
  445. echo '{}';
  446. }
  447. break;
  448. default:
  449. $data = mailbox('get', 'alias_details', $object);
  450. if (!isset($data) || empty($data)) {
  451. echo '{}';
  452. }
  453. else {
  454. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  455. }
  456. break;
  457. }
  458. break;
  459. case "domain-admin":
  460. switch ($object) {
  461. case "all":
  462. $domain_admins = get_domain_admins();
  463. if (!empty($domain_admins)) {
  464. foreach ($domain_admins as $domain_admin) {
  465. if ($details = get_domain_admin_details($domain_admin)) {
  466. $data[] = $details;
  467. }
  468. else {
  469. continue;
  470. }
  471. }
  472. if (!isset($data) || empty($data)) {
  473. echo '{}';
  474. }
  475. else {
  476. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  477. }
  478. }
  479. else {
  480. echo '{}';
  481. }
  482. break;
  483. default:
  484. $data = get_domain_admin_details($object);
  485. if (!isset($data) || empty($data)) {
  486. echo '{}';
  487. }
  488. else {
  489. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  490. }
  491. break;
  492. }
  493. break;
  494. case "u2f-registration":
  495. header('Content-Type: application/javascript');
  496. if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
  497. $data = $u2f->getRegisterData(get_u2f_registrations($object));
  498. list($req, $sigs) = $data;
  499. $_SESSION['regReq'] = json_encode($req);
  500. echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';';
  501. }
  502. else {
  503. return;
  504. }
  505. break;
  506. case "u2f-authentication":
  507. header('Content-Type: application/javascript');
  508. if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
  509. $reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
  510. $_SESSION['authReq'] = $reqs;
  511. echo 'var req = ' . $reqs . ';';
  512. }
  513. else {
  514. return;
  515. }
  516. break;
  517. default:
  518. echo '{}';
  519. break;
  520. }
  521. break;
  522. case "delete":
  523. switch ($category) {
  524. case "alias":
  525. if (isset($_POST['items'])) {
  526. $items = (array)json_decode($_POST['items'], true);
  527. if (is_array($items)) {
  528. if (mailbox('delete', 'alias', array('address' => $items)) === 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' => 'Deletion of items/s failed'
  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 address array in post data'
  555. ));
  556. }
  557. }
  558. else {
  559. echo json_encode(array(
  560. 'type' => 'error',
  561. 'msg' => 'Cannot find items in post data'
  562. ));
  563. }
  564. break;
  565. case "syncjob":
  566. if (isset($_POST['items'])) {
  567. $items = (array)json_decode($_POST['items'], true);
  568. if (is_array($items)) {
  569. if (mailbox('delete', 'syncjob', array('id' => $items)) === false) {
  570. if (isset($_SESSION['return'])) {
  571. echo json_encode($_SESSION['return']);
  572. }
  573. else {
  574. echo json_encode(array(
  575. 'type' => 'error',
  576. 'msg' => 'Deletion of items/s failed'
  577. ));
  578. }
  579. }
  580. else {
  581. if (isset($_SESSION['return'])) {
  582. echo json_encode($_SESSION['return']);
  583. }
  584. else {
  585. echo json_encode(array(
  586. 'type' => 'success',
  587. 'msg' => 'Task completed'
  588. ));
  589. }
  590. }
  591. }
  592. else {
  593. echo json_encode(array(
  594. 'type' => 'error',
  595. 'msg' => 'Cannot find id array in post data'
  596. ));
  597. }
  598. }
  599. else {
  600. echo json_encode(array(
  601. 'type' => 'error',
  602. 'msg' => 'Cannot find items in post data'
  603. ));
  604. }
  605. break;
  606. case "fwdhost":
  607. if (isset($_POST['items'])) {
  608. $items = (array)json_decode($_POST['items'], true);
  609. if (is_array($items)) {
  610. if (delete_forwarding_host(array('forwardinghost' => $items)) === false) {
  611. if (isset($_SESSION['return'])) {
  612. echo json_encode($_SESSION['return']);
  613. }
  614. else {
  615. echo json_encode(array(
  616. 'type' => 'error',
  617. 'msg' => 'Deletion of items/s failed'
  618. ));
  619. }
  620. }
  621. else {
  622. if (isset($_SESSION['return'])) {
  623. echo json_encode($_SESSION['return']);
  624. }
  625. else {
  626. echo json_encode(array(
  627. 'type' => 'success',
  628. 'msg' => 'Task completed'
  629. ));
  630. }
  631. }
  632. }
  633. else {
  634. echo json_encode(array(
  635. 'type' => 'error',
  636. 'msg' => 'Cannot find forwardinghost array in post data'
  637. ));
  638. }
  639. }
  640. else {
  641. echo json_encode(array(
  642. 'type' => 'error',
  643. 'msg' => 'Cannot find items in post data'
  644. ));
  645. }
  646. break;
  647. case "dkim":
  648. if (isset($_POST['items'])) {
  649. $items = (array)json_decode($_POST['items'], true);
  650. if (is_array($items)) {
  651. if (dkim_delete_key(array('domains' => $items)) === false) {
  652. if (isset($_SESSION['return'])) {
  653. echo json_encode($_SESSION['return']);
  654. }
  655. else {
  656. echo json_encode(array(
  657. 'type' => 'error',
  658. 'msg' => 'Deletion of items/s failed'
  659. ));
  660. }
  661. }
  662. else {
  663. if (isset($_SESSION['return'])) {
  664. echo json_encode($_SESSION['return']);
  665. }
  666. else {
  667. echo json_encode(array(
  668. 'type' => 'success',
  669. 'msg' => 'Task completed'
  670. ));
  671. }
  672. }
  673. }
  674. else {
  675. echo json_encode(array(
  676. 'type' => 'error',
  677. 'msg' => 'Cannot find domains array in post data'
  678. ));
  679. }
  680. }
  681. else {
  682. echo json_encode(array(
  683. 'type' => 'error',
  684. 'msg' => 'Cannot find items in post data'
  685. ));
  686. }
  687. break;
  688. case "domain":
  689. if (isset($_POST['items'])) {
  690. $items = (array)json_decode($_POST['items'], true);
  691. if (is_array($items)) {
  692. if (mailbox('delete', 'domain', array('domain' => $items)) === false) {
  693. if (isset($_SESSION['return'])) {
  694. echo json_encode($_SESSION['return']);
  695. }
  696. else {
  697. echo json_encode(array(
  698. 'type' => 'error',
  699. 'msg' => 'Task failed'
  700. ));
  701. }
  702. }
  703. else {
  704. if (isset($_SESSION['return'])) {
  705. echo json_encode($_SESSION['return']);
  706. }
  707. else {
  708. echo json_encode(array(
  709. 'type' => 'success',
  710. 'msg' => 'Task completed'
  711. ));
  712. }
  713. }
  714. }
  715. else {
  716. echo json_encode(array(
  717. 'type' => 'error',
  718. 'msg' => 'Cannot find domain array in post data'
  719. ));
  720. }
  721. }
  722. else {
  723. echo json_encode(array(
  724. 'type' => 'error',
  725. 'msg' => 'Cannot find items in post data'
  726. ));
  727. }
  728. break;
  729. case "alias-domain":
  730. if (isset($_POST['items'])) {
  731. $items = (array)json_decode($_POST['items'], true);
  732. if (is_array($items)) {
  733. if (mailbox('delete', 'alias_domain', array('alias_domain' => $items)) === false) {
  734. if (isset($_SESSION['return'])) {
  735. echo json_encode($_SESSION['return']);
  736. }
  737. else {
  738. echo json_encode(array(
  739. 'type' => 'error',
  740. 'msg' => 'Task failed'
  741. ));
  742. }
  743. }
  744. else {
  745. if (isset($_SESSION['return'])) {
  746. echo json_encode($_SESSION['return']);
  747. }
  748. else {
  749. echo json_encode(array(
  750. 'type' => 'success',
  751. 'msg' => 'Task completed'
  752. ));
  753. }
  754. }
  755. }
  756. else {
  757. echo json_encode(array(
  758. 'type' => 'error',
  759. 'msg' => 'Cannot find alias_domain array in post data'
  760. ));
  761. }
  762. }
  763. else {
  764. echo json_encode(array(
  765. 'type' => 'error',
  766. 'msg' => 'Cannot find items in post data'
  767. ));
  768. }
  769. break;
  770. case "mailbox":
  771. if (isset($_POST['items'])) {
  772. $items = (array)json_decode($_POST['items'], true);
  773. if (is_array($items)) {
  774. if (mailbox('delete', 'mailbox', array('username' => $items)) === false) {
  775. if (isset($_SESSION['return'])) {
  776. echo json_encode($_SESSION['return']);
  777. }
  778. else {
  779. echo json_encode(array(
  780. 'type' => 'error',
  781. 'msg' => 'Task failed'
  782. ));
  783. }
  784. }
  785. else {
  786. if (isset($_SESSION['return'])) {
  787. echo json_encode($_SESSION['return']);
  788. }
  789. else {
  790. echo json_encode(array(
  791. 'type' => 'success',
  792. 'msg' => 'Task completed'
  793. ));
  794. }
  795. }
  796. }
  797. else {
  798. echo json_encode(array(
  799. 'type' => 'error',
  800. 'msg' => 'Cannot find username array in post data'
  801. ));
  802. }
  803. }
  804. else {
  805. echo json_encode(array(
  806. 'type' => 'error',
  807. 'msg' => 'Cannot find items in post data'
  808. ));
  809. }
  810. break;
  811. case "resource":
  812. if (isset($_POST['items'])) {
  813. $items = (array)json_decode($_POST['items'], true);
  814. if (is_array($items)) {
  815. if (mailbox('delete', 'resource', array('name' => $items)) === false) {
  816. if (isset($_SESSION['return'])) {
  817. echo json_encode($_SESSION['return']);
  818. }
  819. else {
  820. echo json_encode(array(
  821. 'type' => 'error',
  822. 'msg' => 'Task failed'
  823. ));
  824. }
  825. }
  826. else {
  827. if (isset($_SESSION['return'])) {
  828. echo json_encode($_SESSION['return']);
  829. }
  830. else {
  831. echo json_encode(array(
  832. 'type' => 'success',
  833. 'msg' => 'Task completed'
  834. ));
  835. }
  836. }
  837. }
  838. else {
  839. echo json_encode(array(
  840. 'type' => 'error',
  841. 'msg' => 'Cannot find name array in post data'
  842. ));
  843. }
  844. }
  845. else {
  846. echo json_encode(array(
  847. 'type' => 'error',
  848. 'msg' => 'Cannot find items in post data'
  849. ));
  850. }
  851. break;
  852. case "policy_mailbox":
  853. if (isset($_POST['items'])) {
  854. $items = (array)json_decode($_POST['items'], true);
  855. if (is_array($items)) {
  856. if (policy('delete', 'mailbox', array('prefid' => $items)) === false) {
  857. if (isset($_SESSION['return'])) {
  858. echo json_encode($_SESSION['return']);
  859. }
  860. else {
  861. echo json_encode(array(
  862. 'type' => 'error',
  863. 'msg' => 'Task failed'
  864. ));
  865. }
  866. }
  867. else {
  868. if (isset($_SESSION['return'])) {
  869. echo json_encode($_SESSION['return']);
  870. }
  871. else {
  872. echo json_encode(array(
  873. 'type' => 'success',
  874. 'msg' => 'Task completed'
  875. ));
  876. }
  877. }
  878. }
  879. else {
  880. echo json_encode(array(
  881. 'type' => 'error',
  882. 'msg' => 'Cannot find name array in post data'
  883. ));
  884. }
  885. }
  886. else {
  887. echo json_encode(array(
  888. 'type' => 'error',
  889. 'msg' => 'Cannot find items in post data'
  890. ));
  891. }
  892. break;
  893. case "time_limited_alias":
  894. if (isset($_POST['items'])) {
  895. $items = (array)json_decode($_POST['items'], true);
  896. if (is_array($items)) {
  897. if (mailbox('delete', 'time_limited_alias', array('address' => $items)) === false) {
  898. if (isset($_SESSION['return'])) {
  899. echo json_encode($_SESSION['return']);
  900. }
  901. else {
  902. echo json_encode(array(
  903. 'type' => 'error',
  904. 'msg' => 'Task failed'
  905. ));
  906. }
  907. }
  908. else {
  909. if (isset($_SESSION['return'])) {
  910. echo json_encode($_SESSION['return']);
  911. }
  912. else {
  913. echo json_encode(array(
  914. 'type' => 'success',
  915. 'msg' => 'Task completed'
  916. ));
  917. }
  918. }
  919. }
  920. else {
  921. echo json_encode(array(
  922. 'type' => 'error',
  923. 'msg' => 'Cannot find name array in post data'
  924. ));
  925. }
  926. }
  927. else {
  928. echo json_encode(array(
  929. 'type' => 'error',
  930. 'msg' => 'Cannot find items in post data'
  931. ));
  932. }
  933. break;
  934. case "eas_cache":
  935. if (isset($_POST['items'])) {
  936. $items = (array)json_decode($_POST['items'], true);
  937. if (is_array($items)) {
  938. if (mailbox('delete', 'eas_cache', array('username' => $items)) === false) {
  939. if (isset($_SESSION['return'])) {
  940. echo json_encode($_SESSION['return']);
  941. }
  942. else {
  943. echo json_encode(array(
  944. 'type' => 'error',
  945. 'msg' => 'Task failed'
  946. ));
  947. }
  948. }
  949. else {
  950. if (isset($_SESSION['return'])) {
  951. echo json_encode($_SESSION['return']);
  952. }
  953. else {
  954. echo json_encode(array(
  955. 'type' => 'success',
  956. 'msg' => 'Task completed'
  957. ));
  958. }
  959. }
  960. }
  961. else {
  962. echo json_encode(array(
  963. 'type' => 'error',
  964. 'msg' => 'Cannot find name array in post data'
  965. ));
  966. }
  967. }
  968. else {
  969. echo json_encode(array(
  970. 'type' => 'error',
  971. 'msg' => 'Cannot find items in post data'
  972. ));
  973. }
  974. break;
  975. case "domain_admin":
  976. if (isset($_POST['items'])) {
  977. $items = (array)json_decode($_POST['items'], true);
  978. if (is_array($items)) {
  979. if (delete_domain_admin(array('username' => $items)) === false) {
  980. if (isset($_SESSION['return'])) {
  981. echo json_encode($_SESSION['return']);
  982. }
  983. else {
  984. echo json_encode(array(
  985. 'type' => 'error',
  986. 'msg' => 'Task failed'
  987. ));
  988. }
  989. }
  990. else {
  991. if (isset($_SESSION['return'])) {
  992. echo json_encode($_SESSION['return']);
  993. }
  994. else {
  995. echo json_encode(array(
  996. 'type' => 'success',
  997. 'msg' => 'Task completed'
  998. ));
  999. }
  1000. }
  1001. }
  1002. else {
  1003. echo json_encode(array(
  1004. 'type' => 'error',
  1005. 'msg' => 'Cannot find name array in post data'
  1006. ));
  1007. }
  1008. }
  1009. else {
  1010. echo json_encode(array(
  1011. 'type' => 'error',
  1012. 'msg' => 'Cannot find items in post data'
  1013. ));
  1014. }
  1015. break;
  1016. }
  1017. break;
  1018. case "edit":
  1019. switch ($category) {
  1020. case "alias":
  1021. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1022. $items = (array)json_decode($_POST['items'], true);
  1023. $attr = (array)json_decode($_POST['attr'], true);
  1024. $postarray = array_merge(array('address' => $items), $attr);
  1025. if (is_array($postarray['address'])) {
  1026. if (mailbox('edit', 'alias', $postarray) === false) {
  1027. if (isset($_SESSION['return'])) {
  1028. echo json_encode($_SESSION['return']);
  1029. }
  1030. else {
  1031. echo json_encode(array(
  1032. 'type' => 'error',
  1033. 'msg' => 'Edit failed'
  1034. ));
  1035. }
  1036. exit();
  1037. }
  1038. else {
  1039. if (isset($_SESSION['return'])) {
  1040. echo json_encode($_SESSION['return']);
  1041. }
  1042. else {
  1043. echo json_encode(array(
  1044. 'type' => 'success',
  1045. 'msg' => 'Task completed'
  1046. ));
  1047. }
  1048. }
  1049. }
  1050. else {
  1051. echo json_encode(array(
  1052. 'type' => 'error',
  1053. 'msg' => 'Incomplete post data'
  1054. ));
  1055. }
  1056. }
  1057. else {
  1058. echo json_encode(array(
  1059. 'type' => 'error',
  1060. 'msg' => 'Incomplete post data'
  1061. ));
  1062. }
  1063. break;
  1064. case "delimiter_action":
  1065. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1066. $items = (array)json_decode($_POST['items'], true);
  1067. $attr = (array)json_decode($_POST['attr'], true);
  1068. $postarray = array_merge(array('username' => $items), $attr);
  1069. if (is_array($postarray['username'])) {
  1070. if (mailbox('edit', 'delimiter_action', $postarray) === false) {
  1071. if (isset($_SESSION['return'])) {
  1072. echo json_encode($_SESSION['return']);
  1073. }
  1074. else {
  1075. echo json_encode(array(
  1076. 'type' => 'error',
  1077. 'msg' => 'Edit failed'
  1078. ));
  1079. }
  1080. exit();
  1081. }
  1082. else {
  1083. if (isset($_SESSION['return'])) {
  1084. echo json_encode($_SESSION['return']);
  1085. }
  1086. else {
  1087. echo json_encode(array(
  1088. 'type' => 'success',
  1089. 'msg' => 'Task completed'
  1090. ));
  1091. }
  1092. }
  1093. }
  1094. else {
  1095. echo json_encode(array(
  1096. 'type' => 'error',
  1097. 'msg' => 'Incomplete post data'
  1098. ));
  1099. }
  1100. }
  1101. else {
  1102. echo json_encode(array(
  1103. 'type' => 'error',
  1104. 'msg' => 'Incomplete post data'
  1105. ));
  1106. }
  1107. break;
  1108. case "tls_policy":
  1109. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1110. $items = (array)json_decode($_POST['items'], true);
  1111. $attr = (array)json_decode($_POST['attr'], true);
  1112. $postarray = array_merge(array('username' => $items), $attr);
  1113. if (is_array($postarray['username'])) {
  1114. if (mailbox('edit', 'tls_policy', $postarray) === false) {
  1115. if (isset($_SESSION['return'])) {
  1116. echo json_encode($_SESSION['return']);
  1117. }
  1118. else {
  1119. echo json_encode(array(
  1120. 'type' => 'error',
  1121. 'msg' => 'Edit failed'
  1122. ));
  1123. }
  1124. exit();
  1125. }
  1126. else {
  1127. if (isset($_SESSION['return'])) {
  1128. echo json_encode($_SESSION['return']);
  1129. }
  1130. else {
  1131. echo json_encode(array(
  1132. 'type' => 'success',
  1133. 'msg' => 'Task completed'
  1134. ));
  1135. }
  1136. }
  1137. }
  1138. else {
  1139. echo json_encode(array(
  1140. 'type' => 'error',
  1141. 'msg' => 'Incomplete post data'
  1142. ));
  1143. }
  1144. }
  1145. else {
  1146. echo json_encode(array(
  1147. 'type' => 'error',
  1148. 'msg' => 'Incomplete post data'
  1149. ));
  1150. }
  1151. break;
  1152. case "time_limited_alias":
  1153. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1154. $items = (array)json_decode($_POST['items'], true);
  1155. $attr = (array)json_decode($_POST['attr'], true);
  1156. $postarray = array_merge(array('address' => $items), $attr);
  1157. if (is_array($postarray['address'])) {
  1158. if (mailbox('edit', 'time_limited_alias', $postarray) === false) {
  1159. if (isset($_SESSION['return'])) {
  1160. echo json_encode($_SESSION['return']);
  1161. }
  1162. else {
  1163. echo json_encode(array(
  1164. 'type' => 'error',
  1165. 'msg' => 'Edit failed'
  1166. ));
  1167. }
  1168. exit();
  1169. }
  1170. else {
  1171. if (isset($_SESSION['return'])) {
  1172. echo json_encode($_SESSION['return']);
  1173. }
  1174. else {
  1175. echo json_encode(array(
  1176. 'type' => 'success',
  1177. 'msg' => 'Task completed'
  1178. ));
  1179. }
  1180. }
  1181. }
  1182. else {
  1183. echo json_encode(array(
  1184. 'type' => 'error',
  1185. 'msg' => 'Incomplete post data'
  1186. ));
  1187. }
  1188. }
  1189. else {
  1190. echo json_encode(array(
  1191. 'type' => 'error',
  1192. 'msg' => 'Incomplete post data'
  1193. ));
  1194. }
  1195. break;
  1196. case "mailbox":
  1197. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1198. $items = (array)json_decode($_POST['items'], true);
  1199. $attr = (array)json_decode($_POST['attr'], true);
  1200. $postarray = array_merge(array('username' => $items), $attr);
  1201. if (is_array($postarray['username'])) {
  1202. if (mailbox('edit', 'mailbox', $postarray) === false) {
  1203. if (isset($_SESSION['return'])) {
  1204. echo json_encode($_SESSION['return']);
  1205. }
  1206. else {
  1207. echo json_encode(array(
  1208. 'type' => 'error',
  1209. 'msg' => 'Edit failed'
  1210. ));
  1211. }
  1212. exit();
  1213. }
  1214. else {
  1215. if (isset($_SESSION['return'])) {
  1216. echo json_encode($_SESSION['return']);
  1217. }
  1218. else {
  1219. echo json_encode(array(
  1220. 'type' => 'success',
  1221. 'msg' => 'Task completed'
  1222. ));
  1223. }
  1224. }
  1225. }
  1226. else {
  1227. echo json_encode(array(
  1228. 'type' => 'error',
  1229. 'msg' => 'Incomplete post data'
  1230. ));
  1231. }
  1232. }
  1233. else {
  1234. echo json_encode(array(
  1235. 'type' => 'error',
  1236. 'msg' => 'Incomplete post data'
  1237. ));
  1238. }
  1239. break;
  1240. case "syncjob":
  1241. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1242. $items = (array)json_decode($_POST['items'], true);
  1243. $attr = (array)json_decode($_POST['attr'], true);
  1244. $postarray = array_merge(array('id' => $items), $attr);
  1245. if (is_array($postarray['id'])) {
  1246. if (mailbox('edit', 'syncjob', $postarray) === false) {
  1247. if (isset($_SESSION['return'])) {
  1248. echo json_encode($_SESSION['return']);
  1249. }
  1250. else {
  1251. echo json_encode(array(
  1252. 'type' => 'error',
  1253. 'msg' => 'Edit failed'
  1254. ));
  1255. }
  1256. exit();
  1257. }
  1258. else {
  1259. if (isset($_SESSION['return'])) {
  1260. echo json_encode($_SESSION['return']);
  1261. }
  1262. else {
  1263. echo json_encode(array(
  1264. 'type' => 'success',
  1265. 'msg' => 'Task completed'
  1266. ));
  1267. }
  1268. }
  1269. }
  1270. else {
  1271. echo json_encode(array(
  1272. 'type' => 'error',
  1273. 'msg' => 'Incomplete post data'
  1274. ));
  1275. }
  1276. }
  1277. else {
  1278. echo json_encode(array(
  1279. 'type' => 'error',
  1280. 'msg' => 'Incomplete post data'
  1281. ));
  1282. }
  1283. break;
  1284. case "resource":
  1285. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1286. $items = (array)json_decode($_POST['items'], true);
  1287. $attr = (array)json_decode($_POST['attr'], true);
  1288. $postarray = array_merge(array('name' => $items), $attr);
  1289. if (is_array($postarray['name'])) {
  1290. if (mailbox('edit', 'resource', $postarray) === false) {
  1291. if (isset($_SESSION['return'])) {
  1292. echo json_encode($_SESSION['return']);
  1293. }
  1294. else {
  1295. echo json_encode(array(
  1296. 'type' => 'error',
  1297. 'msg' => 'Edit failed'
  1298. ));
  1299. }
  1300. exit();
  1301. }
  1302. else {
  1303. if (isset($_SESSION['return'])) {
  1304. echo json_encode($_SESSION['return']);
  1305. }
  1306. else {
  1307. echo json_encode(array(
  1308. 'type' => 'success',
  1309. 'msg' => 'Task completed'
  1310. ));
  1311. }
  1312. }
  1313. }
  1314. else {
  1315. echo json_encode(array(
  1316. 'type' => 'error',
  1317. 'msg' => 'Incomplete post data'
  1318. ));
  1319. }
  1320. }
  1321. else {
  1322. echo json_encode(array(
  1323. 'type' => 'error',
  1324. 'msg' => 'Incomplete post data'
  1325. ));
  1326. }
  1327. break;
  1328. case "domain":
  1329. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1330. $items = (array)json_decode($_POST['items'], true);
  1331. $attr = (array)json_decode($_POST['attr'], true);
  1332. $postarray = array_merge(array('domain' => $items), $attr);
  1333. if (is_array($postarray['domain'])) {
  1334. if (mailbox('edit', 'domain', $postarray) === false) {
  1335. if (isset($_SESSION['return'])) {
  1336. echo json_encode($_SESSION['return']);
  1337. }
  1338. else {
  1339. echo json_encode(array(
  1340. 'type' => 'error',
  1341. 'msg' => 'Edit failed'
  1342. ));
  1343. }
  1344. exit();
  1345. }
  1346. else {
  1347. if (isset($_SESSION['return'])) {
  1348. echo json_encode($_SESSION['return']);
  1349. }
  1350. else {
  1351. echo json_encode(array(
  1352. 'type' => 'success',
  1353. 'msg' => 'Task completed'
  1354. ));
  1355. }
  1356. }
  1357. }
  1358. else {
  1359. echo json_encode(array(
  1360. 'type' => 'error',
  1361. 'msg' => 'Incomplete post data'
  1362. ));
  1363. }
  1364. }
  1365. else {
  1366. echo json_encode(array(
  1367. 'type' => 'error',
  1368. 'msg' => 'Incomplete post data'
  1369. ));
  1370. }
  1371. break;
  1372. case "alias-domain":
  1373. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1374. $items = (array)json_decode($_POST['items'], true);
  1375. $attr = (array)json_decode($_POST['attr'], true);
  1376. $postarray = array_merge(array('alias_domain' => $items), $attr);
  1377. if (is_array($postarray['alias_domain'])) {
  1378. if (mailbox('edit', 'alias_domain', $postarray) === false) {
  1379. if (isset($_SESSION['return'])) {
  1380. echo json_encode($_SESSION['return']);
  1381. }
  1382. else {
  1383. echo json_encode(array(
  1384. 'type' => 'error',
  1385. 'msg' => 'Edit failed'
  1386. ));
  1387. }
  1388. exit();
  1389. }
  1390. else {
  1391. if (isset($_SESSION['return'])) {
  1392. echo json_encode($_SESSION['return']);
  1393. }
  1394. else {
  1395. echo json_encode(array(
  1396. 'type' => 'success',
  1397. 'msg' => 'Task completed'
  1398. ));
  1399. }
  1400. }
  1401. }
  1402. else {
  1403. echo json_encode(array(
  1404. 'type' => 'error',
  1405. 'msg' => 'Incomplete post data'
  1406. ));
  1407. }
  1408. }
  1409. else {
  1410. echo json_encode(array(
  1411. 'type' => 'error',
  1412. 'msg' => 'Incomplete post data'
  1413. ));
  1414. }
  1415. break;
  1416. case "spam_score":
  1417. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1418. $items = (array)json_decode($_POST['items'], true);
  1419. $attr = (array)json_decode($_POST['attr'], true);
  1420. $postarray = array_merge(array('username' => $items), $attr);
  1421. if (is_array($postarray['username'])) {
  1422. if (mailbox('edit', 'spam_score', $postarray) === false) {
  1423. if (isset($_SESSION['return'])) {
  1424. echo json_encode($_SESSION['return']);
  1425. }
  1426. else {
  1427. echo json_encode(array(
  1428. 'type' => 'error',
  1429. 'msg' => 'Edit failed'
  1430. ));
  1431. }
  1432. exit();
  1433. }
  1434. else {
  1435. if (isset($_SESSION['return'])) {
  1436. echo json_encode($_SESSION['return']);
  1437. }
  1438. else {
  1439. echo json_encode(array(
  1440. 'type' => 'success',
  1441. 'msg' => 'Task completed'
  1442. ));
  1443. }
  1444. }
  1445. }
  1446. else {
  1447. echo json_encode(array(
  1448. 'type' => 'error',
  1449. 'msg' => 'Incomplete post data'
  1450. ));
  1451. }
  1452. }
  1453. else {
  1454. echo json_encode(array(
  1455. 'type' => 'error',
  1456. 'msg' => 'Incomplete post data'
  1457. ));
  1458. }
  1459. break;
  1460. case "domain_admin":
  1461. if (isset($_POST['items']) && isset($_POST['attr'])) {
  1462. $items = (array)json_decode($_POST['items'], true);
  1463. $attr = (array)json_decode($_POST['attr'], true);
  1464. $postarray = array_merge(array('username' => $items), $attr);
  1465. if (is_array($postarray['username'])) {
  1466. if (edit_domain_admin($postarray) === false) {
  1467. if (isset($_SESSION['return'])) {
  1468. echo json_encode($_SESSION['return']);
  1469. }
  1470. else {
  1471. echo json_encode(array(
  1472. 'type' => 'error',
  1473. 'msg' => 'Edit failed'
  1474. ));
  1475. }
  1476. exit();
  1477. }
  1478. else {
  1479. if (isset($_SESSION['return'])) {
  1480. echo json_encode($_SESSION['return']);
  1481. }
  1482. else {
  1483. echo json_encode(array(
  1484. 'type' => 'success',
  1485. 'msg' => 'Task completed'
  1486. ));
  1487. }
  1488. }
  1489. }
  1490. else {
  1491. echo json_encode(array(
  1492. 'type' => 'error',
  1493. 'msg' => 'Incomplete post data'
  1494. ));
  1495. }
  1496. }
  1497. else {
  1498. echo json_encode(array(
  1499. 'type' => 'error',
  1500. 'msg' => 'Incomplete post data'
  1501. ));
  1502. }
  1503. break;
  1504. case "admin":
  1505. // No items as there is only one admin
  1506. if (isset($_POST['attr'])) {
  1507. $attr = (array)json_decode($_POST['attr'], true);
  1508. if (edit_admin_account($attr) === false) {
  1509. if (isset($_SESSION['return'])) {
  1510. echo json_encode($_SESSION['return']);
  1511. }
  1512. else {
  1513. echo json_encode(array(
  1514. 'type' => 'error',
  1515. 'msg' => 'Edit failed'
  1516. ));
  1517. }
  1518. exit();
  1519. }
  1520. else {
  1521. if (isset($_SESSION['return'])) {
  1522. echo json_encode($_SESSION['return']);
  1523. }
  1524. else {
  1525. echo json_encode(array(
  1526. 'type' => 'success',
  1527. 'msg' => 'Task completed'
  1528. ));
  1529. }
  1530. }
  1531. }
  1532. else {
  1533. echo json_encode(array(
  1534. 'type' => 'error',
  1535. 'msg' => 'Incomplete post data'
  1536. ));
  1537. }
  1538. break;
  1539. }
  1540. break;
  1541. }
  1542. }
  1543. }