ajax.php 6.5 KB

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