handshake.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /* GNU FM -- a free network service for sharing your music 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. if (!isset($_GET['username']) || !isset($_GET['passwordmd5'])) {
  17. die("BADAUTH\n");
  18. }
  19. $username = $_GET['username'];
  20. $passmd5 = $_GET['passwordmd5'];
  21. $res = $adodb->GetOne('SELECT username FROM Users WHERE lower(username) = ' . $adodb->qstr(strtolower($username)) . ' AND password = ' . $adodb->qstr($passmd5));
  22. if (!$res) {
  23. die("BADAUTH\n");
  24. }
  25. $session = md5($passmd5 . time());
  26. $adodb->Execute('DELETE FROM Radio_Sessions WHERE expires < ' . (int)(time()));
  27. $adodb->Execute('INSERT INTO Radio_Sessions (username, session, expires) VALUES ( ' . $adodb->qstr($username) . ', ' . $adodb->qstr($session) . ', ' . (int)(time() + 259200) . ')');
  28. $radio_base = preg_replace('/https?:\/\//i', '', $base_url, 1);
  29. $radio_base = preg_replace('/^\/\//', '', $radio_base, 1);
  30. echo 'session=' . $session . "\n";
  31. echo "stream_url=this.is.broken.{$username}.example.com\n";
  32. echo "subscriber=0\n";
  33. echo "framehack=0..\n";
  34. echo "base_url=$radio_base\n";
  35. echo "base_path=/radio\n";
  36. echo "info_message=\n";
  37. echo "fingerprint_upload_url=http://this.is.broken.example.com/fingerprint/upload.php\n";
  38. echo "permit_bootstrap=0\n";
  39. echo "freetrial=0\n";