index.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /* GNUkebox -- a free software server for recording your listening habits
  3. Copyright (C) 2009 Free Software Foundation, Inc
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. require_once('../../database.php');
  16. require_once('../../scrobble-utils.php');
  17. require_once('../../auth-utils.php');
  18. header('Content-Type: text/plain');
  19. if (!isset($_POST['s']) || !isset($_POST['a']) || !isset($_POST['t'])) {
  20. die("FAILED Required POST parameters are not set\n");
  21. }
  22. //trim parameters
  23. $session_id = trim($_POST['s']);
  24. $artist = trim($_POST['a']);
  25. $artist = noSpamTracks($artist);
  26. $track = trim($_POST['t']);
  27. $track = noSpamTracks($track);
  28. if (empty($session_id) || empty($artist) || empty($track)) {
  29. die("FAILED Required POST parameters are empty\n");
  30. }
  31. if (isset($_POST['b'])) {
  32. $album = trim($_POST['b']);
  33. $album = noSpamTracks($album);
  34. }
  35. if (empty($album)) {
  36. $album = 'NULL';
  37. }
  38. if (isset($_POST['l']) && is_numeric($_POST['l'])) {
  39. $length = (int) $_POST['l'];
  40. if ($length > 5400) {
  41. $expires = time() + 600;
  42. } else {
  43. $expires = time() + (int) $_POST['l'];
  44. }
  45. } else {
  46. $expires = time() + 250; //Expire in 5 minutes if we don't know the track length
  47. }
  48. $mbid = validateMBID($_POST['m']);
  49. if (!$mbid) {
  50. $mbid = 'NULL';
  51. }
  52. //quote strings
  53. $session_id = $adodb->qstr($session_id);
  54. $artist = $adodb->qstr($artist);
  55. $track = $adodb->qstr($track);
  56. if($album != 'NULL') {
  57. $album = $adodb->qstr($album);
  58. }
  59. if ($mbid != 'NULL') {
  60. $mbid = $adodb->qstr($mbid);
  61. }
  62. //Delete this user's last playing song (if any)
  63. $adodb->Execute('DELETE FROM Now_Playing WHERE sessionid = ' . ($session_id));
  64. if (!check_session($session_id)) {
  65. die("BADSESSION\n");
  66. }
  67. try {
  68. $adodb->Execute('INSERT INTO Now_Playing (sessionid, artist, album, track, expires, mbid) VALUES ('
  69. . $session_id . ', '
  70. . $artist . ', '
  71. . $album . ', '
  72. . $track . ', '
  73. . $expires . ', '
  74. . $mbid . ')');
  75. } catch (Exception $e) {
  76. die('FAILED ' . $e->getMessage() . "\n");
  77. }
  78. getTrackCreateIfNew($artist, $album, $track, $mbid);
  79. //Expire old tracks
  80. $adodb->Execute('DELETE FROM Now_Playing WHERE expires < ' . time());
  81. die("OK\n");