Icecast Streaming Media Server Forum Index Icecast Streaming Media Server
Icecast is a Xiph Foundation Project
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Apache mod_rewrite for firewall connection
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Icecast Streaming Media Server Forum Index -> Icecast Server
View previous topic :: View next topic  
Author Message
kaneza



Joined: 09 May 2008
Posts: 31

PostPosted: Sun Oct 26, 2008 9:57 pm    Post subject: Apache mod_rewrite for firewall connection Reply with quote

Hello,
i have been trying to listen my radio over a firewall connection that allows only port 80. Using apache mod_rewrite i rewrote my request to map my icecasr server correctly,

but i cant get the original IP address. icast is showing me that the originating IP is 12.0.0.1 and i cant get the X-Forwarded-For (which is the original client IP) how to get it passed to my auth_-url?

thanks
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Mon Oct 27, 2008 12:02 am    Post subject: Reply with quote

You should really use the forwarding rules of the NAT to do this, not an application. While it could be possible to use the header to indicate the source address, that would lead to potential faking of addresses in the common case usage.

If you really want to do this then extract the header where the client _t is created and set the IP up based on the header instead of the incoming address.

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kaneza



Joined: 09 May 2008
Posts: 31

PostPosted: Mon Oct 27, 2008 7:47 am    Post subject: Reply with quote

so you mean using the apache mod_rewrite is not the best way to get icecast running on port 80? can you give me an example on how to do it?
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Mon Oct 27, 2008 3:47 pm    Post subject: Reply with quote

running on port 80 just requires the OS to bind to that port, normally it's reserved for root user only which is why there is the <changeowner> directive, ie start as root (so the bind works) then changeowner to the stated user. Alternatively you could use a NAT rule to change the destination port number to say port 8000

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kaneza



Joined: 09 May 2008
Posts: 31

PostPosted: Mon Oct 27, 2008 6:02 pm    Post subject: Reply with quote

Let me explain more my current situation, i have icecast running on port 8000 and i want listeners to be able to listen on port 80, using apache mod rewrite i created a rule that interprete the reqests though a specific virtual host and rewrite it into icecast link (server:port/mount)

<VirtualHost *:80>
ServerName music.myserver.dev
DocumentRoot /srv/www/htdocs
ServerAdmin root@myserver.dev
RewriteEngine On
RewriteRule ^/(.*) http://127.0.0.1:8000/mount [P]
UseCanonicalName Off
</VirtualHost>

i can listen to the radio connecting to music.myserver.dev but internal IP (127.0.0.1) is the one passed to my script as the originating IP. not the real client IP. So i was wondering if icecast can forward me the real client IP
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Mon Oct 27, 2008 9:11 pm    Post subject: Reply with quote

As I've already said, you can do but you have to patch the code to get the IP from a supplied header instead of the socket..

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kaneza



Joined: 09 May 2008
Posts: 31

PostPosted: Tue Oct 28, 2008 7:00 am    Post subject: Reply with quote

can you help me see where i have to change in the source code in order to get it working? i would like to add an additional information in those information sent when doing url_auth such as forward-ip
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Tue Oct 28, 2008 7:35 pm    Post subject: Reply with quote

depends on which way you want to do it, if you want to add extra fields to auth_url POST then you'll need to edit the auth_url.c file and send whatever you want from there. You could just get the IP from the header (httpp_getvar X_FORWARD_FROM) in there instead of the ip in the connection_t, that would work for POST only, not for say listclients. The other way is to replace the real IP with the one from the header after the httpp_parse is successful in connection.c

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kaneza



Joined: 09 May 2008
Posts: 31

PostPosted: Tue Oct 28, 2008 7:44 pm    Post subject: Reply with quote

i think that adding an additional parameter is better, i will have a look into the source code tomorrow and maybe it will be committed to the icecast future editions. as we all know running icecast on firewalled connections is always an issue and that rewrite is a good solution.
Back to top
View user's profile Send private message
kaneza



Joined: 09 May 2008
Posts: 31

PostPosted: Thu Apr 09, 2009 11:22 pm    Post subject: Reply with quote

i have changed auth_url.c like this but it doesnt work


ipaddr = util_url_escape (client->con->ip);
ipaddrk = httpp_getvar (client->parser, X_FORWARD_FROM);

if (ipaddr =='127.0.0.1')
ipaddr = util_url_escape (ipaddrk);
else
ipaddr = ipaddr;
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Fri Apr 10, 2009 1:06 am    Post subject: Reply with quote

try something like


Code:

const char *ip;
...
ip = client->con->ip;
if (strcmp (ip, "127.0.0.1") == 0)
{
     const char *ipaddrk = httpp_getvar (client->parser, X_FORWARD_FROM);
    if (ipaddrk)
       ip = ipaddrk;
}
ipaddr = util_url_escape (ip);

Back to top
View user's profile Send private message Send e-mail Visit poster's website
kaneza



Joined: 09 May 2008
Posts: 31

PostPosted: Fri Apr 10, 2009 8:20 am    Post subject: Reply with quote

when i compile i get the following error:


Code:
auth_url.c: In function âurl_add_listenerâ:
auth_url.c:293: error: âX_FORWARD_FROMâ undeclared (first use in this function)
auth_url.c:293: error: (Each undeclared identifier is reported only once
auth_url.c:293: error: for each function it appears in.)
make[3]: *** [auth_url.o] Error 1
make[3]: Leaving directory `/root/icecast-2.3.2/src'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/root/icecast-2.3.2/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/icecast-2.3.2'
make: *** [all] Error 2
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Fri Apr 10, 2009 1:00 pm    Post subject: Reply with quote

if you haven't got the symbol defined as you had with your sample then use the real header name in in double quote eg "x-forward-from"

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kaneza



Joined: 09 May 2008
Posts: 31

PostPosted: Fri Apr 10, 2009 1:05 pm    Post subject: Reply with quote

so my code should be then




Code:
  const char *ip;
 
  ip = client->con->ip;
if (strcmp (ip, "127.0.0.1") == 0)
{
     const char *ipaddrk = httpp_getvar (client->parser,"X_FORWARDED_FOR");
    if (ipaddrk)
       ip = ipaddrk;
}
ipaddr = util_url_escape (ip);
 
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Fri Apr 10, 2009 4:42 pm    Post subject: Reply with quote

yes, assuming that is the header you are checking for

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Icecast Streaming Media Server Forum Index -> Icecast Server All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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