ajax.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 'upload-avatar':
  127. uploadAvatar(USER_HOME.$GLOBALS['USER']->username.'/', array('jpg', 'png', 'svg', 'jpeg', 'bmp', 'gif'));
  128. sendNotification(true);
  129. break;
  130. case 'remove-images':
  131. removeFiles('images/'.(isset($_POST['file'])?$_POST['file']:''));
  132. sendNotification(true);
  133. break;
  134. case 'update-config':
  135. sendNotification(updateConfig($_POST));
  136. break;
  137. case 'update-appearance':
  138. // Custom CSS Special Case START
  139. if (isset($_POST['customCSS'])) {
  140. if ($_POST['customCSS']) {
  141. write_ini_file($_POST['customCSS'], 'custom.css');
  142. } else {
  143. unlink('custom.css');
  144. }
  145. $response['show_apply'] = true;
  146. }
  147. unset($_POST['customCSS']);
  148. // Custom CSS Special Case END
  149. if (!empty($_POST)) {
  150. $response['notify'] = sendNotification(updateDBOptions($_POST),false,false);
  151. }
  152. break;
  153. case 'deleteDB':
  154. deleteDatabase();
  155. sendNotification(true, 'Database Deleted!');
  156. break;
  157. case 'upgradeInstall':
  158. upgradeInstall();
  159. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  160. $response['tab']['goto'] = 'updatedb.php';
  161. break;
  162. case 'forceBranchInstall':
  163. upgradeInstall(GIT_BRANCH);
  164. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  165. $response['tab']['goto'] = 'updatedb.php';
  166. break;
  167. case 'deleteLog':
  168. sendNotification(unlink(FAIL_LOG));
  169. break;
  170. case 'deleteOrgLog':
  171. sendNotification(unlink("org.log"));
  172. break;
  173. case 'submit-tabs':
  174. $response['notify'] = sendNotification(updateTabs($_POST) , false, false);
  175. $response['show_apply'] = true;
  176. break;
  177. default:
  178. sendNotification(false, 'Unsupported Action!');
  179. }
  180. }
  181. break;
  182. case 'PUT':
  183. sendNotification(false, 'Unsupported Action!');
  184. break;
  185. case 'DELETE':
  186. sendNotification(false, 'Unsupported Action!');
  187. break;
  188. default:
  189. sendNotification(false, 'Unknown Request Type!');
  190. }
  191. if ($response) {
  192. header('Content-Type: application/json');
  193. echo json_encode($response);
  194. die();
  195. } else {
  196. sendNotification(false, 'Error: No Output Specified!');
  197. }