ajax.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. case 'validate-invite':
  76. $response = inviteCodes("check", $_POST['invitecode']);
  77. $response['notify'] = sendResult($response, "check", $_POST['checkurl'], "CODE_SUCCESS", "CODE_ERROR");
  78. break;
  79. case 'use-invite':
  80. //$response = inviteCodes("check", $_POST['invitecode']);
  81. //$response = inviteCodes("use", $_POST['invitecode']);
  82. if(inviteCodes("check", $_POST['invitecode'])){
  83. $response = inviteCodes("use", $_POST['invitecode'], $_POST['inviteuser']);
  84. $response['notify'] = sendResult(plexUserShare($_POST['inviteuser']), "check", $_POST['checkurl'], "INVITE_SUCCESS", "INVITE_ERROR");
  85. }
  86. break;
  87. case 'join-plex':
  88. $response = plexJoin($_POST['joinuser'], $_POST['joinemail'], $_POST['joinpassword']);
  89. $response['notify'] = sendResult($response, "check", $_POST['checkurl'], "JOIN_SUCCESS", "JOIN_ERROR");
  90. break;
  91. default: // Stuff that you need admin for
  92. qualifyUser('admin', true);
  93. switch ($action) {
  94. case 'check-url':
  95. sendResult(frameTest($_POST['checkurl']), "flask", $_POST['checkurl'], "IFRAME_CAN_BE_FRAMED", "IFRAME_CANNOT_BE_FRAMED");
  96. break;
  97. case 'upload-images':
  98. uploadFiles('images/', array('jpg', 'png', 'svg', 'jpeg', 'bmp'));
  99. sendNotification(true);
  100. break;
  101. case 'remove-images':
  102. removeFiles('images/'.(isset($_POST['file'])?$_POST['file']:''));
  103. sendNotification(true);
  104. break;
  105. case 'update-config':
  106. sendNotification(updateConfig($_POST));
  107. break;
  108. case 'update-appearance':
  109. // Custom CSS Special Case START
  110. if (isset($_POST['customCSS'])) {
  111. if ($_POST['customCSS']) {
  112. write_ini_file($_POST['customCSS'], 'custom.css');
  113. } else {
  114. unlink('custom.css');
  115. }
  116. $response['parent']['reload'] = true;
  117. }
  118. unset($_POST['customCSS']);
  119. // Custom CSS Special Case END
  120. $response['notify'] = sendNotification(updateDBOptions($_POST),false,false);
  121. break;
  122. case 'deleteDB':
  123. deleteDatabase();
  124. sendNotification(true, 'Database Deleted!');
  125. break;
  126. case 'upgradeInstall':
  127. upgradeInstall();
  128. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  129. $response['tab']['goto'] = 'updatedb.php';
  130. break;
  131. case 'forceBranchInstall':
  132. upgradeInstall(GIT_BRANCH);
  133. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  134. $response['tab']['goto'] = 'updatedb.php';
  135. break;
  136. case 'deleteLog':
  137. sendNotification(unlink(FAIL_LOG));
  138. break;
  139. case 'deleteOrgLog':
  140. sendNotification(unlink("org.log"));
  141. break;
  142. case 'submit-tabs':
  143. $response['notify'] = sendNotification(updateTabs($_POST) , false, false);
  144. $response['show_apply'] = true;
  145. break;
  146. default:
  147. sendNotification(false, 'Unsupported Action!');
  148. }
  149. }
  150. break;
  151. case 'PUT':
  152. sendNotification(false, 'Unsupported Action!');
  153. break;
  154. case 'DELETE':
  155. sendNotification(false, 'Unsupported Action!');
  156. break;
  157. default:
  158. sendNotification(false, 'Unknown Request Type!');
  159. }
  160. if ($response) {
  161. header('Content-Type: application/json');
  162. echo json_encode($response);
  163. die();
  164. } else {
  165. sendNotification(false, 'Error: No Output Specified!');
  166. }