Prev Previous Post   Next Post Next
Old 9th January 2004, 23:57   #1
jackherer
Major Dude
 
Join Date: Aug 2003
Posts: 942
scproxy+auth

I am trying to use this proxy script that tom wrote for authentication. The script seems to rely on the fact the the PHP register_globals setting be switched on in the php.ini configuration file which is off by default from PHP 4.2.0 onwards. I have tried to edit the script to get round this as follows.

PHP Code:
<?


// BEGIN CONFIG BLOCK ////////////////////////////////////////////
$db_hostname="localhost";
$db_login="scproxyuser";
$db_password="**********";
$db_database="scproxy";
$db_tablename="auth";
$db_username_field="username";
$db_password_field="password";
$db_timefield="timestamp";
$sc_host="81.137.214.186";
$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='".$_SERVER['PHP_AUTH_USER']."'");
  @
fclose($sp);
}  

if (!isset(
$_SERVER['PHP_AUTH_USER'])) {
  
header("WWW-Authenticate: Basic realm=\"SCProxy\"");
  
header("HTTP/1.0 401 Unauthorized");
  echo 
"This service requires a valid login/password 1.\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, username, password FROM $db_tablename WHERE $db_username_field= '".$_SERVER['PHP_AUTH_USER']."' AND $db_password_field= '".$_SERVER['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 2.\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, &$errstr10);
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='".$_SERVER['PHP_AUTH_USER']."'");
    
$lasttime=time();
  }
}

?>
which seemed to get round the initial problems i was having. The script now almost works and my SC server registers a successfull connection from the proxy script but winamp just says that it is connectint for about 20 secs then says error syncing to mpeg and tries to connect again. This process repeats untill all my slots are full of connections from the proxy script. Any ideas anyone ? I have only been learning PHP for 2 days so can anyone see if i have broken the script with the changes i made (mainly replacing $PHP_AUTH_USER with $_SERVER['PHP_AUTH_USER'])?


Do not PM me for tech support !
jackherer is offline   Reply With Quote
 
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