ajax.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 'show-file':
  26. showFile();
  27. die();
  28. break;
  29. case 'emby-image':
  30. qualifyUser(EMBYHOMEAUTH, true);
  31. getEmbyImage();
  32. die();
  33. break;
  34. case 'plex-image':
  35. qualifyUser(PLEXHOMEAUTH, true);
  36. getPlexImage();
  37. die();
  38. break;
  39. case 'emby-streams':
  40. qualifyUser(EMBYHOMEAUTH, true);
  41. echo getEmbyStreams(12, EMBYSHOWNAMES, $GLOBALS['USER']->role);
  42. die();
  43. break;
  44. case 'plex-streams':
  45. qualifyUser(PLEXHOMEAUTH, true);
  46. echo getPlexStreams(12, PLEXSHOWNAMES, $GLOBALS['USER']->role);
  47. die();
  48. break;
  49. case 'emby-recent':
  50. qualifyUser(EMBYHOMEAUTH, true);
  51. echo getEmbyRecent($_GET['type'], 12);
  52. die();
  53. break;
  54. case 'plex-recent':
  55. qualifyUser(PLEXHOMEAUTH, true);
  56. echo getPlexRecent(array("movie" => PLEXRECENTMOVIE, "season" => PLEXRECENTTV, "album" => PLEXRECENTMUSIC));
  57. die();
  58. break;
  59. case 'sabnzbd-update':
  60. qualifyUser(SABNZBDHOMEAUTH, true);
  61. echo sabnzbdConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
  62. die();
  63. break;
  64. case 'nzbget-update':
  65. qualifyUser(NZBGETHOMEAUTH, true);
  66. echo nzbgetConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
  67. die();
  68. break;
  69. case 'show-image':
  70. qualifyUser(NZBGETHOMEAUTH, true);
  71. header('Content-type: image/jpeg');
  72. echo file_get_contents($_GET['image']);
  73. die();
  74. break;
  75. default:
  76. sendNotification(false, 'Unsupported Action!');
  77. }
  78. break;
  79. case 'POST':
  80. // Check if the user is an admin and is allowed to commit values
  81. switch ($action) {
  82. case 'tvdb-get':
  83. $response = tvdbGet($_POST['id']);
  84. break;
  85. case 'search-plex':
  86. $response = searchPlex($_POST['searchtitle']);
  87. break;
  88. case 'validate-invite':
  89. $response = inviteCodes("check", $_POST['invitecode']);
  90. $response['notify'] = sendResult($response, "check", $_POST['checkurl'], "CODE_SUCCESS", "CODE_ERROR");
  91. break;
  92. case 'use-invite':
  93. //$response = inviteCodes("check", $_POST['invitecode']);
  94. //$response = inviteCodes("use", $_POST['invitecode']);
  95. if(inviteCodes("check", $_POST['invitecode'])){
  96. $response = inviteCodes("use", $_POST['invitecode'], $_POST['inviteuser']);
  97. $response['notify'] = sendResult(plexUserShare($_POST['inviteuser']), "check", $_POST['checkurl'], "INVITE_SUCCESS", "INVITE_ERROR");
  98. }
  99. break;
  100. case 'join-plex':
  101. $response = plexJoin($_POST['joinuser'], $_POST['joinemail'], $_POST['joinpassword']);
  102. $response['notify'] = sendResult($response, "check", $_POST['checkurl'], "JOIN_SUCCESS", "JOIN_ERROR");
  103. break;
  104. default: // Stuff that you need admin for
  105. qualifyUser('admin', true);
  106. switch ($action) {
  107. case 'test-email':
  108. 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");
  109. break;
  110. case 'check-url':
  111. sendResult(frameTest($_POST['checkurl']), "flask", $_POST['checkurl'], "IFRAME_CAN_BE_FRAMED", "IFRAME_CANNOT_BE_FRAMED");
  112. break;
  113. case 'upload-images':
  114. uploadFiles('images/', array('jpg', 'png', 'svg', 'jpeg', 'bmp', 'gif'));
  115. sendNotification(true);
  116. break;
  117. case 'remove-images':
  118. removeFiles('images/'.(isset($_POST['file'])?$_POST['file']:''));
  119. sendNotification(true);
  120. break;
  121. case 'update-config':
  122. sendNotification(updateConfig($_POST));
  123. break;
  124. case 'update-appearance':
  125. // Custom CSS Special Case START
  126. if (isset($_POST['customCSS'])) {
  127. if ($_POST['customCSS']) {
  128. write_ini_file($_POST['customCSS'], 'custom.css');
  129. } else {
  130. unlink('custom.css');
  131. }
  132. $response['show_apply'] = true;
  133. }
  134. unset($_POST['customCSS']);
  135. // Custom CSS Special Case END
  136. if (!empty($_POST)) {
  137. $response['notify'] = sendNotification(updateDBOptions($_POST),false,false);
  138. }
  139. break;
  140. case 'deleteDB':
  141. deleteDatabase();
  142. sendNotification(true, 'Database Deleted!');
  143. break;
  144. case 'upgradeInstall':
  145. upgradeInstall();
  146. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  147. $response['tab']['goto'] = 'updatedb.php';
  148. break;
  149. case 'forceBranchInstall':
  150. upgradeInstall(GIT_BRANCH);
  151. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  152. $response['tab']['goto'] = 'updatedb.php';
  153. break;
  154. case 'deleteLog':
  155. sendNotification(unlink(FAIL_LOG));
  156. break;
  157. case 'deleteOrgLog':
  158. sendNotification(unlink("org.log"));
  159. break;
  160. case 'submit-tabs':
  161. $response['notify'] = sendNotification(updateTabs($_POST) , false, false);
  162. $response['show_apply'] = true;
  163. break;
  164. default:
  165. sendNotification(false, 'Unsupported Action!');
  166. }
  167. }
  168. break;
  169. case 'PUT':
  170. sendNotification(false, 'Unsupported Action!');
  171. break;
  172. case 'DELETE':
  173. sendNotification(false, 'Unsupported Action!');
  174. break;
  175. default:
  176. sendNotification(false, 'Unknown Request Type!');
  177. }
  178. if ($response) {
  179. header('Content-Type: application/json');
  180. echo json_encode($response);
  181. die();
  182. } else {
  183. sendNotification(false, 'Error: No Output Specified!');
  184. }