ajax.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 'test-email':
  104. sendResult(sendTestEmail($_POST['emailto'], $_POST['emailsenderemail'], $_POST['emailhost'], $_POST['emailauth'], $_POST['emailusername'], $_POST['emailpassword'], $_POST['emailtype'], $_POST['emailport'], $_POST['emailsendername']), "flask", "E-Mail TEST", "SUCCESS", "ERROR");
  105. break;
  106. case 'check-url':
  107. sendResult(frameTest($_POST['checkurl']), "flask", $_POST['checkurl'], "IFRAME_CAN_BE_FRAMED", "IFRAME_CANNOT_BE_FRAMED");
  108. break;
  109. case 'upload-images':
  110. uploadFiles('images/', array('jpg', 'png', 'svg', 'jpeg', 'bmp', 'gif'));
  111. sendNotification(true);
  112. break;
  113. case 'remove-images':
  114. removeFiles('images/'.(isset($_POST['file'])?$_POST['file']:''));
  115. sendNotification(true);
  116. break;
  117. case 'update-config':
  118. sendNotification(updateConfig($_POST));
  119. break;
  120. case 'update-appearance':
  121. // Custom CSS Special Case START
  122. if (isset($_POST['customCSS'])) {
  123. if ($_POST['customCSS']) {
  124. write_ini_file($_POST['customCSS'], 'custom.css');
  125. } else {
  126. unlink('custom.css');
  127. }
  128. $response['parent']['reload'] = true;
  129. }
  130. unset($_POST['customCSS']);
  131. // Custom CSS Special Case END
  132. $response['notify'] = sendNotification(updateDBOptions($_POST),false,false);
  133. break;
  134. case 'deleteDB':
  135. deleteDatabase();
  136. sendNotification(true, 'Database Deleted!');
  137. break;
  138. case 'upgradeInstall':
  139. upgradeInstall();
  140. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  141. $response['tab']['goto'] = 'updatedb.php';
  142. break;
  143. case 'forceBranchInstall':
  144. upgradeInstall(GIT_BRANCH);
  145. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  146. $response['tab']['goto'] = 'updatedb.php';
  147. break;
  148. case 'deleteLog':
  149. sendNotification(unlink(FAIL_LOG));
  150. break;
  151. case 'deleteOrgLog':
  152. sendNotification(unlink("org.log"));
  153. break;
  154. case 'submit-tabs':
  155. $response['notify'] = sendNotification(updateTabs($_POST) , false, false);
  156. $response['show_apply'] = true;
  157. break;
  158. default:
  159. sendNotification(false, 'Unsupported Action!');
  160. }
  161. }
  162. break;
  163. case 'PUT':
  164. sendNotification(false, 'Unsupported Action!');
  165. break;
  166. case 'DELETE':
  167. sendNotification(false, 'Unsupported Action!');
  168. break;
  169. default:
  170. sendNotification(false, 'Unknown Request Type!');
  171. }
  172. if ($response) {
  173. header('Content-Type: application/json');
  174. echo json_encode($response);
  175. die();
  176. } else {
  177. sendNotification(false, 'Error: No Output Specified!');
  178. }