ajax.php 7.3 KB

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