Old 27th September 2003, 10:52   #1
melliot
Junior Member
 
Join Date: Sep 2003
Posts: 10
I need help with SCPROXY+AUTH script

Help! I can't get this script to work and I really need it! Everything seems to work okay, however when the Authorization box appears after Winamp starts it keeps rejecting the username and password. I know that I have the MySQL table setup correct.

Any help would be appreciated.

NOTE: I even tried commenting out the line below as suggested by someone.

// set_socket_blocking($sp,false);

Thanks!

Marc Elliot
http://www.hothitsjukebox.com


<?

// SCPROXY+AUTH 0.1a tom@winamp.com 01.18.2002
// http://beta.shoutcast.com/~tpepper/scproxy.phps
//
// requires: php 4.0.5+ compiled with --enable-sockets and --with-mysql
//
// this script will act as a liason between a private shoutcast server and
// a public listener, providing an auth mechanism for subscription-only
// services. This script is currently configured for a mysql database,
// but should be fairly trivial to convert to another db. It expects by
// default a database table with two entries, username and password, both
// in cleartext. If the incoming auth request matches these fields, the
// connection is put through. If not, byebye.
//
// the script also has a mechanism for disallowing concurrent logins, so only
// one authpair can proxy at a given moment. (only one person can listen to
// the stream per authentication pair is the intended effect)
//
// You will need some knowledge of mysql to create the database and
// table. An example, given the defaults, might be:
//
// mysqladmin create scproxy
// mysql scproxy
// mysql> CREATE TABLE auth(username VARCHAR(255) NOT NULL PRIMARY KEY,
// -> password VARCHAR(255) NOT NULL,
// -> timestamp INT NOT NULL);
// mysql> INSERT INTO auth VALUES ('test','password',0);
//
// then, configure the sc_host and sc_port below (and db_login/db_password
// if necessary,) then test by connecting winamp to this script via
//
// once you get it working, remove the test auth pair with:
// mysql> DELETE FROM auth WHERE username='test';



// BEGIN CONFIG BLOCK ////////////////////////////////////////////
$db_hostname="192.168.100";
$db_login="******";
$db_password="*******";
$db_database="scproxy";
$db_tablename="auth";
$db_username_field="username";
$db_password_field="password";
$db_timefield="timestamp";
$sc_host="192.168.1.100";
$sc_port=8000;
// END CONFIG BLOCK //////////////////////////////////////////////

set_time_limit(0);
ignore_user_abort();
register_shutdown_function("byebye");

function byebye() {
global $shutdown_flag,$db_tablename,$db_timefield,$db_username_field,$PHP_AUTH_USER;
$shutdown_flag=1;
@mysql_query("UPDATE $db_tablename SET $db_timefield=0 WHERE $db_username_field='$PHP_AUTH_USER'");
@fclose($sp);
}

if (!isset($PHP_AUTH_USER)) {
header("WWW-Authenticate: Basic realm=\"SCProxy\"");
header("HTTP/1.0 401 Unauthorized");
echo "This service requires a valid login/password.\n";
exit;
}

$linkid=@mysql_connect($db_hostname, $db_login, $db_password) or die("Cannot connect to authentication database to verify login.");
@mysql_select_db($db_database) or die("Unable to select database $db_database.\n");

$query="SELECT $db_timefield AS lastupdate FROM $db_tablename WHERE $db_username_field='$PHP_AUTH_USER' AND $db_password_field='$PHP_AUTH_PW'";

$matches=0;
$lastupdate=0;
$res=@mysql_query($query);
if($obj=@mysql_fetch_object($res)) {
$lastupdate=$obj->lastupdate;
$matches=mysql_num_rows($res);
}

if(!$matches) {
header("WWW-Authenticate: Basic realm=\"SCProxy\"");
header("HTTP/1.0 401 Unauthorized");
echo "This service requires a valid login/password.\n";
exit;
}

if(time()-$lastupdate<600) {
header("ICY 404 The account is already in use. If account is inactive, wait 10 minutes and try again.");
exit("The account is already in use. If account is inactive, wait 10 minutes and try again.");
}

$sp = fsockopen($sc_host, $sc_port, &$errno, &$errstr, 10);
if (!$sp) exit("Could not connect to SHOUTcast server.\n");

// set_socket_blocking($sp,false);

fwrite($sp,"GET / HTTP/1.0\nUser-Agent:SHOUTcast PHP Proxy 0.1\nicy-metadata:1\n\n");

$sockack=0;

for ($i=0; $i<120; $i++) {
if (feof($sp)) break;
$str.=fread($sp,4096);
usleep(200000);
if (strpos($str,"\r\n\r\n")) break;
}


if(strpos($str,"\r\n\r\n")===false) exit("Unable to establish stream with SHOUTcast server.\n");
else {
$head=substr($str,0,strpos($str,"\r\n\r\n"));
$head=eregi_replace("ICY 200 OK\r\n","",$head);
header($head);
}

flush();
echo substr($str,strpos($str,"\r\n\r\n")+4);
flush();
while(!$shutdown_flag) {
$buf=fread($sp,4096);
if (feof($sp)) $shutdown_flag=1;
echo $buf;
flush();
usleep(75000);
if(time()-$lasttime>300) {
@mysql_query("UPDATE $db_tablename SET $db_timefield=".time()." WHERE $db_username_field='$PHP_AUTH_USER'");
$lasttime=time();
}
}

?>
melliot is offline   Reply With Quote
Old 27th September 2003, 11:09   #2
melliot
Junior Member
 
Join Date: Sep 2003
Posts: 10
One thing I am unsure about is the line in the comments "compiled with --enable-sockets."

I've checked my PHP settings and the only thing on sockets I can find are these two lines and their settings.

Directive Local Value Master Value
mysql.default_socket no value no value
default_socket_timeout 60 60

Thanks!
melliot is offline   Reply With Quote
Old 27th September 2003, 19:20   #3
FesterHead
Alumni
 
FesterHead's Avatar
 
Join Date: Sep 2001
Location: Maui, Hawaii
Posts: 14,108
Not sure what could be wrong if you have the MySQL table setup.

Have you tried the ghetto method?

Please see this thread.

FesterHead is offline   Reply With Quote
Old 28th September 2003, 12:44   #4
melliot
Junior Member
 
Join Date: Sep 2003
Posts: 10
festerhead,

Thanks! But, every time I tried accessing the stream it caused an error that killed the server? As far as I can tell I setup everything okay. As soon as I took out the authorization line from the config the server would come back up and connect on request.

Also, each time I restarted the server it would attempt to connect on the first request from a client request. It would give me the password dialog box and then it would start to buffer, but then it would give the error message "error connecting to mpeg." I would then look at the server and it was dead.


serv.ini

; ***************************
; Optional Parameters
; ***************************

;***************************
; Private Stream
;***************************

AuthFile=authfile.txt
AuthRealm=Pirate Radio 107.5 FM

; ***************************
; Logging configuration
; ***************************

serv.log

<09/28/03@06:11:08> [SHOUTcast] DNAS/win32 v1.9.2 (Nov 25 2002) starting up...
<09/28/03@06:11:08> [main] loaded config from C:\Program Files\SHOUTcast\sc_serv.ini
<09/28/03@06:11:08> [main] initializing (usermax:3 portbase:8000)...
<09/28/03@06:11:08> [main] Loading ban list (sc_serv.ban)
<09/28/03@06:11:08> [ban] Banned 2 IP's
<09/28/03@06:11:08> [main] Loading rip list (sc_serv.rip)
<09/28/03@06:11:08> [rip] Added 2 IP's to Reserve List
<09/28/03@06:11:08> [main] auth file thread starting
<09/28/03@06:11:08> [main] opening source socket
<09/28/03@06:11:08> [auth] auth file thread started
<09/28/03@06:11:08> [main] source thread starting
<09/28/03@06:11:08> [main] opening client socket
<09/28/03@06:11:08> [main] Client Stream thread [0] starting
<09/28/03@06:11:08> [main] client main thread starting
<09/28/03@06:11:08> [source] listening for connection on port 8001
<09/28/03@06:11:20> [source] connected from 192.168.1.101
<09/28/03@06:11:20> [source] icy-name:Pirate Radio 107.5 FM - The Best Of The 80's & More! mp3PRO Broadcast ; icy-genre:80s
<09/28/03@06:11:20> [source] icy-pub:0 ; icy-br:32 ; icy-url:http://www.hothitsjukebox.com
<09/28/03@06:11:20> [source] icy-irc:N/A ; icy-icq:N/A ; icy-aim:N/A
<09/28/03@06:22:26> [main] shutting down via UI.
melliot is offline   Reply With Quote
Old 28th September 2003, 19:31   #5
FesterHead
Alumni
 
FesterHead's Avatar
 
Join Date: Sep 2001
Location: Maui, Hawaii
Posts: 14,108
Is each user and password seperated by a colon, followed by a newline?

FesterHead is offline   Reply With Quote
Old 29th September 2003, 15:59   #6
melliot
Junior Member
 
Join Date: Sep 2003
Posts: 10
Yes,

Here is the contents of authfile.txt...

free:free
melliot is offline   Reply With Quote
Old 29th September 2003, 16:43   #7
FesterHead
Alumni
 
FesterHead's Avatar
 
Join Date: Sep 2001
Location: Maui, Hawaii
Posts: 14,108
Please post a link to the DNAS.

I'd like to give it a go.

FesterHead is offline   Reply With Quote
Old 29th September 2003, 23:17   #8
melliot
Junior Member
 
Join Date: Sep 2003
Posts: 10
The DNAS is:

http://www.hothitsjukebox.com:8000/index.html

I have commented out the AuthFile section right now, so the stream is working. Send me an e-mail at webmaster@hothitsjukebox.com and we can setup a time to take the server down and put the password back in.
melliot is offline   Reply With Quote
Old 30th September 2003, 00:04   #9
FesterHead
Alumni
 
FesterHead's Avatar
 
Join Date: Sep 2001
Location: Maui, Hawaii
Posts: 14,108
Just make a low-bitrate 1 listener max DNAS and PM me the address and login info.

FesterHead is offline   Reply With Quote
Old 30th September 2003, 14:34   #10
melliot
Junior Member
 
Join Date: Sep 2003
Posts: 10
Okay... it's been a while, how do I call up a second server on the same machine with a different config file.

Is it c:\progra~\winamp\winamp.exe name_of second_config.ini
melliot is offline   Reply With Quote
Old 30th September 2003, 15:12   #11
melliot
Junior Member
 
Join Date: Sep 2003
Posts: 10
Ignore the last post... I have the test server up and running for you. I just sent another PM because I actually have two test servers running. One with the AuthFile and one without.
melliot is offline   Reply With Quote
Old 1st October 2003, 02:39   #12
Tom
Moderator
 
Join Date: Apr 2000
Posts: 4,491
Try leaving AuthRealm= undefined.

Tom

Tom is offline   Reply With Quote
Old 1st October 2003, 04:09   #13
melliot
Junior Member
 
Join Date: Sep 2003
Posts: 10
I already tried that... but to make sure it's not causing a problem I'll take it out.
melliot is offline   Reply With Quote
Old 3rd October 2003, 12:29   #14
melliot
Junior Member
 
Join Date: Sep 2003
Posts: 10
Tom?
melliot is offline   Reply With Quote
Old 15th October 2003, 08:42   #15
Joackim
Junior Member
 
Join Date: Dec 2001
Posts: 8
Simply change $PHP_AUTH_USER to $_SERVER['PHP_AUTH_USER'].

Works for me =)
Joackim is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Technical Support

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump