ajax.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. // Include functions and user
  3. require_once('functions.php');
  4. require_once("user.php");
  5. $GLOBALS['USER'] = new User('registration_callback');
  6. // Upgrade environment
  7. upgradeCheck();
  8. // Lazyload settings
  9. $databaseConfig = configLazy('config/config.php');
  10. // Get Action
  11. if (isset($_POST['submit'])) { $action = $_POST['submit']; }
  12. if (isset($_POST['action'])) { $action = $_POST['action']; }
  13. if (isset($_GET['action'])) { $action = $_GET['action']; }
  14. if (isset($_GET['a'])) { $action = $_GET['a']; }
  15. unset($_POST['action']);
  16. // No Action
  17. if (!isset($action)) {
  18. sendNotification(false, 'No Action Specified!');
  19. }
  20. // Process Request
  21. $response = array();
  22. switch ($_SERVER['REQUEST_METHOD']) {
  23. case 'GET':
  24. switch ($action) {
  25. case 'emby-image':
  26. qualifyUser(EMBYHOMEAUTH, true);
  27. getEmbyImage();
  28. die();
  29. break;
  30. case 'plex-image':
  31. qualifyUser(PLEXHOMEAUTH, true);
  32. getPlexImage();
  33. die();
  34. break;
  35. case 'emby-streams':
  36. qualifyUser(EMBYHOMEAUTH, true);
  37. echo getEmbyStreams(12, EMBYSHOWNAMES, $GLOBALS['USER']->role);
  38. die();
  39. break;
  40. case 'plex-streams':
  41. qualifyUser(PLEXHOMEAUTH, true);
  42. echo getPlexStreams(12, PLEXSHOWNAMES, $GLOBALS['USER']->role);
  43. die();
  44. break;
  45. case 'emby-recent':
  46. qualifyUser(EMBYHOMEAUTH, true);
  47. echo getEmbyRecent($_GET['type'], 12);
  48. die();
  49. break;
  50. case 'plex-recent':
  51. qualifyUser(PLEXHOMEAUTH, true);
  52. echo getPlexRecent(array("movie" => PLEXRECENTMOVIE, "season" => PLEXRECENTTV, "album" => PLEXRECENTMUSIC));
  53. die();
  54. break;
  55. case 'sabnzbd-update':
  56. qualifyUser(SABNZBDHOMEAUTH, true);
  57. echo sabnzbdConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
  58. die();
  59. break;
  60. case 'nzbget-update':
  61. qualifyUser(NZBGETHOMEAUTH, true);
  62. echo nzbgetConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
  63. die();
  64. break;
  65. default:
  66. sendNotification(false, 'Unsupported Action!');
  67. }
  68. break;
  69. case 'POST':
  70. // Check if the user is an admin and is allowed to commit values
  71. switch ($action) {
  72. case 'search-plex':
  73. $response = searchPlex($_POST['searchtitle']);
  74. break;
  75. default: // Stuff that you need admin for
  76. qualifyUser('admin', true);
  77. switch ($action) {
  78. case 'check-url':
  79. sendResult(frameTest($_POST['checkurl']), "flask", $_POST['checkurl'], "IFRAME_CAN_BE_FRAMED", "IFRAME_CANNOT_BE_FRAMED");
  80. break;
  81. case 'upload-images':
  82. uploadFiles('images/', array('jpg', 'png', 'svg', 'jpeg', 'bmp'));
  83. sendNotification(true);
  84. break;
  85. case 'remove-images':
  86. removeFiles('images/'.(isset($_POST['file'])?$_POST['file']:''));
  87. sendNotification(true);
  88. break;
  89. case 'update-config':
  90. sendNotification(updateConfig($_POST));
  91. break;
  92. case 'update-appearance':
  93. // Custom CSS Special Case START
  94. if (isset($_POST['customCSS'])) {
  95. if ($_POST['customCSS']) {
  96. write_ini_file($_POST['customCSS'], 'custom.css');
  97. } else {
  98. unlink('custom.css');
  99. }
  100. $response['parent']['reload'] = true;
  101. }
  102. unset($_POST['customCSS']);
  103. // Custom CSS Special Case END
  104. $response['notify'] = sendNotification(updateDBOptions($_POST),false,false);
  105. break;
  106. case 'deleteDB':
  107. deleteDatabase();
  108. sendNotification(true, 'Database Deleted!');
  109. break;
  110. case 'upgradeInstall':
  111. upgradeInstall();
  112. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  113. $response['tab']['goto'] = 'updatedb.php';
  114. break;
  115. case 'forceBranchInstall':
  116. upgradeInstall(GIT_BRANCH);
  117. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  118. $response['tab']['goto'] = 'updatedb.php';
  119. break;
  120. case 'deleteLog':
  121. sendNotification(unlink(FAIL_LOG));
  122. break;
  123. case 'deleteOrgLog':
  124. sendNotification(unlink("org.log"));
  125. break;
  126. case 'submit-tabs':
  127. $response['notify'] = sendNotification(updateTabs($_POST) , false, false);
  128. $response['show_apply'] = true;
  129. break;
  130. default:
  131. sendNotification(false, 'Unsupported Action!');
  132. }
  133. }
  134. break;
  135. case 'PUT':
  136. sendNotification(false, 'Unsupported Action!');
  137. break;
  138. case 'DELETE':
  139. sendNotification(false, 'Unsupported Action!');
  140. break;
  141. default:
  142. sendNotification(false, 'Unknown Request Type!');
  143. }
  144. if ($response) {
  145. header('Content-Type: application/json');
  146. echo json_encode($response);
  147. die();
  148. } else {
  149. sendNotification(false, 'Error: No Output Specified!');
  150. }