index.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?
  2. # Include the TV functions
  3. require_once 'includes/main.php';
  4. # Send our headers early
  5. header('Content-type: text/html; charset=utf-8');
  6. # Did the user request a specific series?
  7. $series = false;
  8. if (isset($_REQUEST['series'])) {
  9. # This is not a great filter, but it should make the string safe for use as a quoted path
  10. $series = preg_replace('/[\0\n\r]/', '', $_REQUEST['series']);
  11. $series = basename($series);
  12. }
  13. # Did the user request an update?
  14. if ($series !== false && isset($_POST['Save'])) {
  15. # Require auth (or for the time being, specific IP addresses)
  16. if (preg_match('/^(?:172\.19\.[17]\.|2602:3f:e50d:76|74\.93\.97\.65)/', $_SERVER['REMOTE_ADDR'])) {
  17. # Grab the current settings for comparison
  18. $series_last = readFlags($series);
  19. $seasons_last = findSeasons($series);
  20. # Save series and season data
  21. saveFlags($series, $_POST, $series_last, $seasons_last);
  22. saveSeasons($series, $_POST, $series_last, $seasons_last);
  23. } else {
  24. echo '<h4 style="color: red;">Cannot save: User not authenticated</h4>';
  25. }
  26. }
  27. # Did the user add a season?
  28. if ($series !== false && isset($_POST['AddSeason'])) {
  29. # Require auth (or for the time being, specific IP addresses)
  30. if (preg_match('/^(?:172\.19\.[17]\.|2602:3f:e50d:76|74\.93\.97\.65)/', $_SERVER['REMOTE_ADDR'])) {
  31. # Add a season folder
  32. $season = intval($_POST['season_add']);
  33. addSeason($series, $season);
  34. } else {
  35. echo '<h4 style="color: red;">Cannot save: User not authenticated</h4>';
  36. }
  37. }
  38. # Did the user delete a season?
  39. if ($series !== false) {
  40. $season = false;
  41. foreach (array_keys($_POST) as $key) {
  42. if (preg_match('/season_del_(\d+)/', $key, $matches)) {
  43. $season = intval($matches[1]);
  44. last;
  45. }
  46. }
  47. if ($season !== false) {
  48. # Require auth (or for the time being, specific IP addresses)
  49. if (preg_match('/^(?:172\.19\.[17]\.|2602:3f:e50d:76|74\.93\.97\.65)/', $_SERVER['REMOTE_ADDR'])) {
  50. # Remove a season folder (if empty)
  51. delSeason($series, $season);
  52. } else {
  53. echo '<h4 style="color: red;">Cannot save: User not authenticated</h4>';
  54. }
  55. }
  56. }
  57. #=========================================================================================
  58. # Generic XHTML 1.1 header
  59. print <<<ENDOLA
  60. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  61. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  62. <html xmlns="http://www.w3.org/1999/xhtml">
  63. <head>
  64. <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
  65. <title>UberZach TV</title>
  66. </head>
  67. <body>
  68. ENDOLA;
  69. if ($series === false) {
  70. printAllSeries();
  71. } else {
  72. printSeries($series);
  73. }
  74. # Generic XHTML 1.1 footer
  75. print <<<ENDOLA
  76. </body>
  77. </html>
  78. ENDOLA;
  79. ?>