| View previous topic :: View next topic |
| Author |
Message |
Anonymous Guest
|
Posted: Sat Sep 30, 2006 4:21 pm Post subject: Help with URL authentication from another program |
|
|
Hi,
I'm running Icecast 2.3.1 on FreeBSD 6.1 using ices as the real time source. Everything is running perfectly. This system is paralleling a Windows machine acting as a player/webpage/music selector written in perl. It also has a WM encoder sending to another machine running a Windows Media Server. The player machine is passing audio via sound cards to both itself (for the encoder) and to the FreeBSD machine running ices/icecast.
Communication between the web page, player selections is via http from the web page perl scripts to the actual player software. This has worked very well for a long time.
Now I want the music selection perl software to also update the meta-data on Icecast each time a new title is selected for play. Adding this capability to the perl scripts was trivial and it 'sort of' works. I'm using the perl IO::Socket library to talk to the various http servers involved in this. Where I'm stuck is at the authentication necessary to do a metadata updatein Icecast. I know about the [user]:[password]@hostname syntax which works in a browser, but the browser is interacting with the server internally to exchange the login information, and it doesn't work if you send the same info raw to the socket (assuming you could, since the socket connect info is part of an array).
Is there a perl library for browser-type authentication, or does someone know the steps that happen between browser and server when the [user]:[password]@hostname syntax is used? The browser version of my meta-update line that works looks like this:
http://login:passwd@myhostname:8000/admin/metadata?mount=/mymount.ogg&mode=updinfo&song=some+song+title
In perl, the code looks something like this:
use IO::Socket;
use Filehandle;
....
if($socket = IO::Socket::INET->new(
Proto => 'tcp',
PeerAddr => $host,
PeerPort => $port)) {
print $socket "GET $cmd HTTP/1.1\r\n\r\n";
....
where $cmd is "/admin/metadata?mount= ... etc.
Anyone that can help?
Thanks.
--Bill |
|
| Back to top |
|
 |
Anonymous Guest
|
Posted: Sat Sep 30, 2006 5:14 pm Post subject: |
|
|
You should send a "Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=" header to the server on each request.
The "dXNlcm5hbWU6cGFzc3dvcmQ=" is the base64 encoding of the text "username:password".
Normally when you request a page, the server replies with a "200 OK". In the case authentication is needed, it will reply with a "401 Unauthorized" header. This is the moment the client knows it has to send the "Authorization" header. In practice you can simply send this header straight away in the first connect.
I'm not a perl developper, but I guess it will look like:
print $socket "GET $cmd HTTP/1.1\r\nAuthorization: Basic $auth64\r\n\r\n";
(you have to base64 encode the username and password to $auth64 ofcourse)
More info:
http://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html
http://en.wikipedia.org/wiki/Basic_authentication_scheme |
|
| Back to top |
|
 |
Anonymous Guest
|
Posted: Sat Sep 30, 2006 7:01 pm Post subject: |
|
|
Thanks for the quick response and that info!
You were exactly correct, even in the perl code. I found it necessary to add a third party base64 library to the FreeBSD version of perl (from www.cpan.org), but the windows version already had one. The addition was simple and it works perfectly!
sub base64 {
my ($e) = @_;
use MIME::base64;
return encode_base64($e);
}
Implemented as a subroutine, but would be fine inline..
--Bill |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group subRebel style by ktauber
|