ajax.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 'emby-image':
  26. qualifyUser(EMBYHOMEAUTH, true);
  27. getEmbyImage();
  28. die();
  29. break;
  30. case 'plex-image':
  31. qualifyUser(PLEXHOMEAUTH, true);
  32. getPlexImage();
  33. die();
  34. break;
  35. case 'emby-streams':
  36. qualifyUser(EMBYHOMEAUTH, true);
  37. echo getEmbyStreams(12);
  38. die();
  39. break;
  40. case 'plex-streams':
  41. qualifyUser(PLEXHOMEAUTH, true);
  42. echo getPlexStreams(12);
  43. die();
  44. break;
  45. case 'emby-recent':
  46. qualifyUser(EMBYHOMEAUTH, true);
  47. echo getEmbyRecent($_GET['type'], 12);
  48. die();
  49. break;
  50. case 'plex-recent':
  51. qualifyUser(PLEXHOMEAUTH, true);
  52. echo getPlexRecent($_GET['type'], 12);
  53. die();
  54. break;
  55. case 'sabnzbd-update':
  56. qualifyUser(SABNZBDHOMEAUTH, true);
  57. echo sabnzbdConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
  58. die();
  59. break;
  60. case 'nzbget-update':
  61. qualifyUser(NZBGETHOMEAUTH, true);
  62. echo nzbgetConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
  63. die();
  64. break;
  65. default:
  66. sendNotification(false, 'Unsupported Action!');
  67. }
  68. break;
  69. case 'POST':
  70. // Check if the user is an admin and is allowed to commit values
  71. qualifyUser('admin', true);
  72. switch ($action) {
  73. case 'upload-images':
  74. uploadFiles('images/', array('jpg', 'png', 'svg', 'jpeg', 'bmp'));
  75. sendNotification(true);
  76. break;
  77. case 'remove-images':
  78. removeFiles('images/'.(isset($_POST['file'])?$_POST['file']:''));
  79. sendNotification(true);
  80. break;
  81. case 'update-config':
  82. sendNotification(updateConfig($_POST));
  83. break;
  84. case 'update-appearance':
  85. // Custom CSS Special Case START
  86. if (isset($_POST['customCSS'])) {
  87. if ($_POST['customCSS']) {
  88. write_ini_file($_POST['customCSS'], 'custom.css');
  89. } else {
  90. unlink('custom.css');
  91. }
  92. $response['parent']['reload'] = true;
  93. }
  94. unset($_POST['customCSS']);
  95. // Custom CSS Special Case END
  96. $response['notify'] = sendNotification(updateDBOptions($_POST),false,false);
  97. break;
  98. case 'deleteDB':
  99. deleteDatabase();
  100. sendNotification(true, 'Database Deleted!');
  101. break;
  102. case 'upgradeInstall':
  103. upgradeInstall();
  104. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  105. $response['tab']['goto'] = 'updatedb.php';
  106. break;
  107. case 'forceBranchInstall':
  108. upgradeInstall(GIT_BRANCH);
  109. $response['notify'] = sendNotification(true, 'Performing Checks', false);
  110. $response['tab']['goto'] = 'updatedb.php';
  111. break;
  112. case 'deleteLog':
  113. sendNotification(unlink(FAIL_LOG));
  114. break;
  115. case 'submit-tabs':
  116. $response['notify'] = sendNotification(updateTabs($_POST) , false, false);
  117. $response['show_apply'] = true;
  118. break;
  119. default:
  120. sendNotification(false, 'Unsupported Action!');
  121. }
  122. break;
  123. case 'PUT':
  124. sendNotification(false, 'Unsupported Action!');
  125. break;
  126. case 'DELETE':
  127. sendNotification(false, 'Unsupported Action!');
  128. break;
  129. default:
  130. sendNotification(false, 'Unknown Request Type!');
  131. }
  132. if ($response) {
  133. header('Content-Type: application/json');
  134. echo json_encode($response);
  135. die();
  136. } else {
  137. sendNotification(false, 'Error: No Output Specified!');
  138. }