ajax.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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-backups':
  26. qualifyUser("admin", true);
  27. $response = implode("\n",getBackups());
  28. break;
  29. case 'get-calendar':
  30. echo json_encode(getCalendar());
  31. die();
  32. break;
  33. case 'get-ping':
  34. echo getPing($_GET['url'], $_GET['style'], true);
  35. die();
  36. break;
  37. case 'show-file':
  38. $auth = ($_SERVER['HTTP_REFERER'] ? true : false);
  39. if ($auth === false) { die("WTF? Bro! This is an internal function only"); }
  40. showFile();
  41. die();
  42. break;
  43. case 'emby-image':
  44. qualifyUser(EMBYHOMEAUTH, true);
  45. getEmbyImage();
  46. die();
  47. break;
  48. case 'plex-image':
  49. qualifyUser(PLEXHOMEAUTH, true);
  50. getPlexImage();
  51. die();
  52. break;
  53. case 'emby-streams':
  54. qualifyUser(EMBYHOMEAUTH, true);
  55. echo getEmbyStreams(12, EMBYSHOWNAMES, $GLOBALS['USER']->role);
  56. die();
  57. break;
  58. case 'plex-streams':
  59. qualifyUser(PLEXHOMEAUTH, true);
  60. echo getPlexStreams(12, PLEXSHOWNAMES, $GLOBALS['USER']->role);
  61. die();
  62. break;
  63. case 'ombi-requests':
  64. qualifyUser(PLEXHOMEAUTH, true);
  65. echo buildOmbiList($GLOBALS['USER']->role, $GLOBALS['USER']->username);
  66. die();
  67. break;
  68. case 'emby-recent':
  69. qualifyUser(EMBYHOMEAUTH, true);
  70. echo getEmbyRecent(array("Movie" => EMBYRECENTMOVIE, "Episode" => EMBYRECENTTV, "MusicAlbum" => EMBYRECENTMUSIC, "Series" => EMBYRECENTTV));
  71. die();
  72. break;
  73. case 'plex-recent':
  74. qualifyUser(PLEXHOMEAUTH, true);
  75. echo getPlexRecent(array("movie" => PLEXRECENTMOVIE, "season" => PLEXRECENTTV, "album" => PLEXRECENTMUSIC));
  76. die();
  77. break;
  78. case 'sabnzbd-update':
  79. qualifyUser(SABNZBDHOMEAUTH, true);
  80. echo sabnzbdConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
  81. die();
  82. break;
  83. case 'nzbget-update':
  84. qualifyUser(NZBGETHOMEAUTH, true);
  85. echo nzbgetConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
  86. die();
  87. break;
  88. case 'transmission-update':
  89. qualifyUser(TRANSMISSIONHOMEAUTH, true);
  90. echo transmissionConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
  91. die();
  92. break;
  93. case 'show-image':
  94. qualifyUser(NZBGETHOMEAUTH, true);
  95. header('Content-type: image/jpeg');
  96. echo file_get_contents($_GET['image']);
  97. die();
  98. break;
  99. default:
  100. sendNotification(false, 'Unsupported Action!');
  101. }
  102. break;
  103. case 'POST':
  104. // Check if the user is an admin and is allowed to commit values
  105. switch ($action) {
  106. case 'tvdb-get':
  107. $response = tvdbGet($_POST['id']);
  108. break;
  109. case 'tvdb-search':
  110. $response = tvdbSearch($_POST['name'], $_POST['type']);
  111. break;
  112. case 'search-plex':
  113. $response = searchPlex($_POST['searchtitle']);
  114. break;
  115. case 'validate-invite':
  116. $response = inviteCodes("check", $_POST['invitecode']);
  117. $response['notify'] = sendResult($response, "check", 'Invite System', "CODE_SUCCESS", "CODE_ERROR");
  118. break;
  119. case 'use-invite':
  120. if(inviteCodes("check", $_POST['invitecode'])){
  121. $response = inviteCodes("use", $_POST['invitecode'], $_POST['inviteuser']);
  122. $response['notify'] = sendResult(plexUserShare($_POST['inviteuser']), "check", 'Invite System', "INVITE_SUCCESS", "INVITE_ERROR");
  123. }
  124. break;
  125. case 'join-plex':
  126. $response = plexJoin($_POST['joinuser'], $_POST['joinemail'], $_POST['joinpassword']);
  127. $response['notify'] = sendResult($response, "check", 'Invite System', "JOIN_SUCCESS", "JOIN_ERROR");
  128. break;
  129. default: // Stuff that you need admin for
  130. qualifyUser('admin', true);
  131. switch ($action) {
  132. case 'ombi-action':
  133. sendResult(ombiAction($_POST['id'], $_POST['action_type'], $_POST['type']), "search", "OMBI ", "action completed successfully", "an error occured");
  134. break;
  135. case 'get-emails':
  136. $response = printEmails(getEmails($_POST['type']));
  137. break;
  138. case 'mass-email':
  139. massEmail($_POST['emailto'],$_POST['emailsubject'],$_POST['emailmessage']);
  140. $response['notify'] = sendNotification(true, 'E-Mail Sent', false);
  141. break;
  142. case 'test-email':
  143. 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");
  144. break;
  145. case 'check-url':
  146. sendResult(frameTest($_POST['checkurl']), "flask", $_POST['checkurl'], "IFRAME_CAN_BE_FRAMED", "IFRAME_CANNOT_BE_FRAMED");
  147. break;
  148. case 'backup-now':
  149. sendResult(backupDB(), "database", "Backup", "BACKUP_CREATED", "BACKUP_ERROR");
  150. break;
  151. case 'upload-images':
  152. uploadFiles('images/', array('jpg', 'png', 'svg', 'jpeg', 'bmp', 'gif'));
  153. sendNotification(true);
  154. break;
  155. case 'upload-avatar':
  156. uploadAvatar(USER_HOME.$GLOBALS['USER']->username.'/', array('jpg', 'png', 'svg', 'jpeg', 'bmp', 'gif'));
  157. sendNotification(true);
  158. break;
  159. case 'remove-images':
  160. removeFiles('images/'.(isset($_POST['file'])?$_POST['file']:''));
  161. sendNotification(true);
  162. break;
  163. case 'remove-file':
  164. removeFiles($_POST['file']);
  165. sendNotification(true);
  166. break;
  167. case 'update-config':
  168. $response['notify'] = sendNotification(updateConfig($_POST));
  169. $response['show_apply'] = true;
  170. break;
  171. case 'update-appearance':
  172. // Custom CSS Special Case START
  173. if (isset($_POST['customCSS'])) {
  174. if ($_POST['customCSS']) {
  175. write_ini_file($_POST['customCSS'], 'custom.css');
  176. } else {
  177. unlink('custom.css');
  178. }
  179. $response['notify'] = sendNotification(true,false,false);
  180. $response['show_apply'] = true;
  181. }
  182. unset($_POST['customCSS']);
  183. // Custom CSS Special Case END
  184. if (!empty($_POST)) {
  185. $response['notify'] = sendNotification(updateDBOptions($_POST),false,false);
  186. $response['show_apply'] = true;
  187. }
  188. break;
  189. case 'deleteDB':
  190. deleteDatabase();
  191. sendNotification(true, 'Database Deleted!');
  192. break;
  193. case 'upgradeInstall':
  194. upgradeInstall();
  195. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  196. $response['tab']['goto'] = 'updatedb.php';
  197. break;
  198. case 'forceBranchInstall':
  199. upgradeInstall(GIT_BRANCH);
  200. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  201. $response['tab']['goto'] = 'updatedb.php';
  202. break;
  203. case 'deleteLog':
  204. $response['notify'] = sendNotification(unlink(FAIL_LOG));
  205. $response['show_apply'] = true;
  206. break;
  207. case 'deleteChat':
  208. $response['notify'] = sendNotification(unlink("chatpack.db"));
  209. $response['show_apply'] = true;
  210. $response['reload'] = true;
  211. break;
  212. case 'deleteOrgLog':
  213. $response['notify'] = sendNotification(unlink("org.log"));
  214. $response['show_apply'] = true;
  215. break;
  216. case 'submit-tabs':
  217. $response['notify'] = sendNotification(updateTabs($_POST) , false, false);
  218. $response['show_apply'] = true;
  219. break;
  220. default:
  221. sendNotification(false, 'Unsupported Action!');
  222. }
  223. }
  224. break;
  225. case 'PUT':
  226. sendNotification(false, 'Unsupported Action!');
  227. break;
  228. case 'DELETE':
  229. sendNotification(false, 'Unsupported Action!');
  230. break;
  231. default:
  232. sendNotification(false, 'Unknown Request Type!');
  233. }
  234. if ($response) {
  235. header('Content-Type: application/json');
  236. echo json_encode($response);
  237. die();
  238. } else {
  239. sendNotification(false, 'Error: No Output Specified!');
  240. }