Set correct base_url for old radio handshake
[foocorp:gnu-fm.git] / nixtape / radio / handshake.php
1 <?php
2 /* GNU FM -- a free network service for sharing your music listening habits
3
4    Copyright (C) 2009 Free Software Foundation, Inc
5
6    This program is free software: you can redistribute it and/or modify
7    it under the terms of the GNU Affero General Public License as published by
8    the Free Software Foundation, either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU Affero General Public License for more details.
15
16    You should have received a copy of the GNU Affero General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 require_once('../database.php');
22
23 if (!isset($_GET['username']) || !isset($_GET['passwordmd5'])) {
24         die("BADAUTH\n");
25 }
26
27 $username = $_GET['username'];
28 $passmd5 = $_GET['passwordmd5'];
29
30 $res = $adodb->GetOne('SELECT username FROM Users WHERE lower(username) = ' . $adodb->qstr(strtolower($username)) . ' AND password = ' . $adodb->qstr($passmd5));
31 if (!$res) {
32         die("BADAUTH\n");
33 }
34
35 $session = md5($passmd5 . time());
36
37 $adodb->Execute('DELETE FROM Radio_Sessions WHERE expires < ' . (int)(time()));
38
39 $adodb->Execute('INSERT INTO Radio_Sessions (username, session, expires) VALUES ( ' . $adodb->qstr($username) . ', ' . $adodb->qstr($session) . ', ' . (int)(time() + 259200) . ')');
40
41 $radio_base = preg_replace('/https?:\/\//i', '', $base_url, 1);
42
43 echo 'session=' . $session . "\n";
44 echo "stream_url=this.is.broken.{$username}.example.com\n";
45 echo "subscriber=0\n";
46 echo "framehack=0..\n";
47 echo "base_url=$radio_base\n";
48 echo "base_path=/radio\n";
49 echo "info_message=\n";
50 echo "fingerprint_upload_url=http://this.is.broken.example.com/fingerprint/upload.php\n";
51 echo "permit_bootstrap=0\n";
52 echo "freetrial=0\n";