ajax.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. // Include functions if not already included
  3. require_once('functions.php');
  4. // Upgrade environment
  5. upgradeCheck();
  6. // Lazyload settings
  7. $databaseConfig = configLazy('config/config.php');
  8. // Get Action
  9. if (isset($_POST['submit'])) { $action = $_POST['submit']; }
  10. if (isset($_POST['action'])) { $action = $_POST['action']; }
  11. if (isset($_GET['action'])) { $action = $_GET['action']; }
  12. if (isset($_GET['a'])) { $action = $_GET['a']; }
  13. unset($_POST['action']);
  14. // No Action
  15. if (!isset($action)) {
  16. sendNotification(false, 'No Action Specified!');
  17. }
  18. // Process Request
  19. $response = array();
  20. switch ($_SERVER['REQUEST_METHOD']) {
  21. case 'GET':
  22. switch ($action) {
  23. case 'emby-image':
  24. qualifyUser(EMBYHOMEAUTH, true);
  25. getEmbyImage();
  26. die();
  27. break;
  28. case 'plex-image':
  29. qualifyUser(PLEXHOMEAUTH, true);
  30. getPlexImage();
  31. die();
  32. break;
  33. case 'emby-streams':
  34. qualifyUser(EMBYHOMEAUTH, true);
  35. echo getEmbyStreams(12);
  36. die();
  37. break;
  38. case 'plex-streams':
  39. qualifyUser(PLEXHOMEAUTH, true);
  40. echo getPlexStreams(12);
  41. die();
  42. break;
  43. case 'emby-recent':
  44. qualifyUser(EMBYHOMEAUTH, true);
  45. echo getEmbyRecent($_GET['type'], 12);
  46. die();
  47. break;
  48. case 'plex-recent':
  49. qualifyUser(PLEXHOMEAUTH, true);
  50. echo getPlexRecent($_GET['type'], 12);
  51. die();
  52. break;
  53. case 'sabnzbd-update':
  54. qualifyUser(SABNZBDHOMEAUTH, true);
  55. echo sabnzbdConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
  56. die();
  57. break;
  58. case 'nzbget-update':
  59. qualifyUser(NZBGETHOMEAUTH, true);
  60. echo nzbgetConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
  61. die();
  62. break;
  63. default:
  64. sendNotification(false, 'Unsupported Action!');
  65. }
  66. break;
  67. case 'POST':
  68. // Check if the user is an admin and is allowed to commit values
  69. qualifyUser('admin', true);
  70. switch ($action) {
  71. case 'upload-images':
  72. uploadFiles('images/', array('jpg', 'png', 'svg', 'jpeg', 'bmp'));
  73. sendNotification(true);
  74. break;
  75. case 'remove-images':
  76. removeFiles('images/'.(isset($_POST['file'])?$_POST['file']:''));
  77. sendNotification(true);
  78. break;
  79. case 'update-config':
  80. sendNotification(updateConfig($_POST));
  81. break;
  82. case 'editCSS':
  83. write_ini_file($_POST["css-show"], "custom.css");
  84. $response['parent']['reload'] = true;
  85. break;
  86. case 'update-appearance':
  87. sendNotification(updateDBOptions($_POST));
  88. break;
  89. case 'deleteDB':
  90. deleteDatabase();
  91. sendNotification(true, 'Database Deleted!');
  92. break;
  93. case 'upgradeInstall':
  94. upgradeInstall();
  95. $response['notify'] = sendNotification(true, 'Performing Checks',false);
  96. $response['tab']['goto'] = 'updatedb.php';
  97. break;
  98. case 'deleteLog':
  99. sendNotification(unlink(FAIL_LOG));
  100. break;
  101. case 'nav-test-tab':
  102. $response['tab']['goto'] = 'homepage.php';
  103. break;
  104. case 'nav-test-tab':
  105. $response['parent']['goto'] = 'homepage.php';
  106. break;
  107. default:
  108. sendNotification(false, 'Unsupported Action!');
  109. }
  110. break;
  111. case 'PUT':
  112. sendNotification(false, 'Unsupported Action!');
  113. break;
  114. case 'DELETE':
  115. sendNotification(false, 'Unsupported Action!');
  116. break;
  117. default:
  118. sendNotification(false, 'Unknown Request Type!');
  119. }
  120. if ($response) {
  121. header('Content-Type: application/json');
  122. echo json_encode($response);
  123. die();
  124. } else {
  125. sendNotification(false, 'Error: No Output Specified!');
  126. }