ajax.php 7.2 KB

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