Server-side redirection (a.k.a. tunneling) with PHP

Some web applications, like my own cPanel and Web Mail, use non-standard tcp ports. Usually this is because they are part of a software package that runs alongside Apache but does not use it to serve the pages.

Problem is many corporate and university firewalls do not allow access to ports such as 2095 and makes all the neat web apps like the ones above completely useless until you get home (where you probably have some other e-mail software anyway).

For some time I have used a simple port redirector installed on my home computer which allowed me to see my e-mails from my work place and my university. This is a bit annoying, though, because not only I have to leave my pc on the all day just for this but also because it is a slower connection and I am the only one who can use it (yes, I am thinking about my own hosting clients/partners who complain about the same problem).

So, I am starting a journey to make a ‘transparent’ PHP application that can successfully accept an incoming HTTP connection, grab the headers and open a server-side connection to another service and use the incoming headers for the request. Upon reception of the response, the script must alter *all* tags to its own name and append a single GET variable with the original href.

Thus, on a simple page, where there is a:

<a xhref="www.skyhorse.org/abc.html?I=rule" mce_href="www.skyhorse.org/abc.html?I=rule">

there will be a:

<a xhref="redirector.php?requestedURL='www.skyhorse.org/abc.html?I=rule'" mce_href="redirector.php?requestedURL='www.skyhorse.org/abc.html?I=rule'">
.

I still don’t know if the use of ‘ or even ” will be tolerated by the HTTP request, but I think as a last resort I can always do some kind of two-way encoding (like base64 or something similar) to encode the original request in an AsciiSimple format.

For now, I have some proof of concept working (yikes, I can open a server-side socket in PHP!) but I am still a long way before I turn off my home computer during the day :)

If anyone has any information on how to accomplish what I am trying to do, please, do give me a shout :)

— Update 1

After some time I discovered another major issue: Images!
I think I will have to make a standalone script or function in PHP just to handle the redirection of images… yes, because there has to be a request for images to a PHP script and those images have to be quested server-side and returned… mmm … maybe not that complicated, just a redirect.php?requestImage=originalURL and the request.php will take care of returning just the binary information taken directly from the server-side connection made to the service… could work… will work!

–Update 2

Ok, so, I finally discovered I was re-inventing the wheel…
I had already looked for this on the web, but couldn’t find anything. But now I stumbled upon cpanelproxy .
It does exactly what is says on the label: server-side proxy to cPanel.
It’s funny how the script I was writting was starting to look like the script they made! Unfortunatelly it does not yet support SSL, perhaps I could find a way to implement it, but I think it would be almost impossible…


Posted

in

, ,

by