Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Technical Support

View Poll Results: Am I Even Close?
Yes 0 0%
No 0 0%
No Clue 1 100.00%
Voters: 1. You may not vote on this poll

Reply
Thread Tools Search this Thread Display Modes
Old 26th November 2008, 19:38   #1
Deth101
Junior Member
 
Join Date: Oct 2008
Location: Philly
Posts: 6
DNAS: Using cURL for admin.cgi...

I've been trying for 3 friggin' days to get cURL even to gain access to the DNAS streamer thingy. I know nearly nothing about how it works but I have some small understanding of cURL and quite frankly I'm stumped. The majority of my time spent on this was with research of the "curl_setopt(resource,option,value);" method, looking for 'tweaks' that might help me overcome these boundaries.

First, my code...

PHP Code:
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
$scip "myexternalip"// runs on local machine, php host is not local
$scport "8000"// http://localhost:8000 model
$scpass "myadminpass"// sure as hell not giving it to you guys
$url "http://$scip:$scport/admin.cgi";
function 
grabdata() {
$ch curl_init();
curl_setopt($chCURLOPT_URL$url);
curl_setopt($chCURLOPT_VERBOSE1);
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
curl_setopt($chCURLOPT_FRESH_CONNECTTRUE);
curl_setopt($chCURLOPT_USERPWD"admin:$scpass");
curl_setopt($chCURLOPT_TIMEOUT10);
curl_setopt($chCURLOPT_HTTPAUTHCURLAUTH_BASIC);
curl_setopt($chCURLOPT_HEADERTRUE);
curl_setopt ($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1)");
$odat curl_exec($ch);
$error curl_error($ch);
return array(
$odat,$error);
curl_close($ch);
}
$data grabdata();
echo 
$data[0] . " --- " $data[1]; 
Overview of what I'm trying to do:

declare a variable as the array returned by the function "grabdata();"

output it.
...
grabdata (obvious to some) initiates a cURL session, and sets the following options:
-the url (of course)
-printing of verbose information activated
-output to variable as opposed to output buffer (returntransfer)
-make sure each attempt is not taken from a list of cached sessions
-add the username;password extension for the basic auth (later)
-quick server (generally), set 10 second maximum timeout
-set the authentication mode to basic, as admin.cgi asks for the username and password this way through the browser, much like setting the WWW-Authenticate: Basic header in PHP.
-include header information in the gathered data
-a convincing user-agent string
then
executes the session: put all data into a variable, throw any error information to a variable, output the data to an array.

...

when I execute this most basic of scripts, I'm just looking for any type of data that would show me that I've gotten a connection to my DNAS...NOPE!!!. The only data ever output is " --- ". No error information, no page information, no headers or raw numeric codes even sent. I understand that most modems or internet routers do not allow connections from your external ip back to your external ip...like say for instance if your ext ip is

123.45.67.890
and your port is
8001
and your streaming through the DNAS, you can't manually listen to your local stream from your media player by inputting
http://123.45.67.890:8001
...
in most cases you'd have to plug in localhost or 127.0.0.1 or whatever your network is set up to use as the local address.

I don't know if this has anything to do with it. my php host is on a completely separate IP. I've just realized perhaps there's an option to set the port through cURL, I'll try that if there is and adjust accordingly, probably won't help. My options are strict: MUST USE cURL!! If anyone knows how to get even remotely closer to this goal and share it I would be forever grateful.
Deth101 is offline   Reply With Quote
Old 27th November 2008, 04:43   #2
Tom
Moderator
 
Join Date: Apr 2000
Posts: 4,491
I've used this in the past for curl and it has worked (if $curl is set to 1 then it uses curl otherwise it will try to use fsockopen):

PHP Code:
<?
function streaminfo($ip,$port$message){
  
$curl=1;
  if(
$curl==1){
   
$stream = `curl http://$ip:$port/7.html -A \"Mozilla\"`;
   
$fp=1;
  }
  else{
    
$fp =@fsockopen ($ip$port, &$errno, &$errstr2);
  }
  if(!
$fp){
    echo 
"Could not connect to <b>{$ip}:{$port}</b> ({$errno}) - {$errstr}\n";
   } 
   else{
     if(
$curl!=1){
       
fputs ($fp"GET /7 HTTP/1.1\r\nUser-Agent:Mozilla\r\n\r\n");
       while (!
feof($fp)){
         
$stream fgets($fp,1024);
       }
     }
     list(,
$stream) = explode("<body>",$stream);
     list(
$stream) = explode("</body>",$stream);
     list(
$user$status$user_peak$user_max, ,$bitrate$song) = explode(",",$stream);
     if(
$status=="0"){
       echo
"Offline";
     } 
     else{
       
$status="Online";
       
$message=str_replace("%up"$user_peak$message);
       
$message=str_replace("%um"$user_max$message);
       
$message=str_replace("%u"$user$message);
       
$message=str_replace("%st"$status$message);
       
$message=str_replace("%b"$bitrate$message);
       
$message=str_replace("%s"$song$message);
       echo 
$message;
     }
   if(
$curl!=1){
     
fclose($fp);
   }
  }
}
streaminfo($_GET['ip'], $_GET['port'], $_GET['message']);

?>
You can change the IP and PORT in the function call along with what info to display, right now it is expecting those to be get variables. Also I believe you can still do user:pass@IP:PORT rather than try to pass post variables.

Hope this helps.

Tom
Tom is offline   Reply With Quote
Old 27th November 2008, 09:06   #3
Jkey
Forum King
 
Join Date: Jul 2004
Location: E*arth
Posts: 3,031
I remember using curl to do this on a godday account
which had a strict php policy after a long time pulling out what little hair i have left,i got it working by setting up port forwarding port 80 - > 8000 on my dnas box and curl using port 80 worked fine.

So Long, and Thanks for All the Fish.
Jkey is offline   Reply With Quote
Old 28th February 2009, 21:16   #4
kdh
Member
 
Join Date: Nov 2008
Posts: 55
Send a message via AIM to kdh
i wrote this nifty perl script, it'll output the viewxml to std out.. might help.

#!/usr/bin/perl
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->agent(Mozilla);
$pass="blablaba";
$host="localhost";
$port="8666";


my $response = $ua->get("http://$host:$port/admin.cgi?pass=$pass&mode=viewxml");

if ($response->is_success) {
print $response->decoded_content; # or whatever
}
else {
die $response->status_line;
}
kdh 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