Solved

Socket, Bind, Connect: Remapping The Server

Posted on 1998-09-16
12
271 Views
Last Modified: 2013-12-25
I am beginning to use the Perl commands SOCKET, BIND, and CONNECT to establish a connection to another website. What I do is set SOCKET appropriately, set BIND to my server name, and then set CONNECT to the website I want to connect to.  It all seems to work perfectly.

Now I have a CGI Perl script called Getgraphic.CGI.  My website has an IMG tag which calls this script (<img src="http://www.mysite.com/cgi-bin/getgraphic.cgi">).  Now I realize that a browser like Netscape must do the same procedure with the Socket, Bind, and Connect so as to make a connection to my CGI script.  Therefore when my CGI script begins to run a SOCKET path has been established to the client so that data can flow to and from.

What I would like to do is instead of my GetGraphic.CGI to output its image graphics I would like to "map" this existing socket connection to another server's CGI script for it to output its image graphics, all from within my GetGraphics.CGI.  Is there any way to do this?  Perhaps altering BIND (the command which took in my server name)?
0
Comment
Question by:ratboy
  • 7
  • 5
12 Comments
 
LVL 1

Accepted Solution

by:
stormerider earned 200 total points
Comment Utility
So what you want to do is to basically tunnel the traffic through your cgi? You could make a connection to where it needs to go and then grab the result, store it locally, and then send it to the connection being made to it. Or you could basically make a connection to the location, retrieve and print to the incoming location and not store it. Couple of different options there. Why are you doing this? You might also want to look at some port redirectors as well that do essentially this type of work.

0
 

Author Comment

by:ratboy
Comment Utility
But if i make the call to that other server to get the picture then "my" IP address goes with it.  I want the clients ip address to fetch it instead. It's like i remapped the socket connection from me to the other server. Can these port redirectors do such things?
0
 

Author Comment

by:ratboy
Comment Utility
I could use the Location:  command output from my CGI script which would do the trick perfectly, but I also want the Referer value to be set to a specific page; the CGI call can be made from multiple different pages but I want the Referer value to be set to a single, unchanging name.  How do I do that?

Sorry for the extra difficulties.  And thanks so far...
0
 
LVL 1

Expert Comment

by:stormerider
Comment Utility
Port redirectors would mark the ip as well. In re: to the referrer, assuming you're using perl with the cgi-lib.pl package,

if ($ENV{'HTTP_REFERER'} ne "http://www.my.domain/this_page.html") {
   &serve_some_blank_image;
   &do_ordinary_cleanup;
   exit(1);
}


0
 

Author Comment

by:ratboy
Comment Utility
To Stormerider:
  Unfortunately i don't see how that piece of Perl code can help me with that location and referrer problem. Can you explain to me in detail what you mean.

And for the port redirectors, you mean the IP Address will still be my own as opposed to the clients?
0
 
LVL 1

Expert Comment

by:stormerider
Comment Utility
It should show it as originating from the client. If they do intensive logging, it should show that it routed through you, but that's unlikely.

Analyzing the code:
1.) If the page they are coming from ($ENV{'HTTP_REFERER'}) does not match the one you want (replace the one i put with your own, it was an example)
2.) Some subroutine to serve them a blank image, not the image they would get via the CGI
3.) Do whatever ordinary CGI cleanup you do
4.) Exit the CGI
5.) Needed for syntax.

This will block from anyone accessing this cgi who is not coming from that page.

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:ratboy
Comment Utility
Truly I thank you Stormerider for being so patient with me.  Writing of the above message and comments have been a 30 second thing as I run in and out of the house.  Now I have more time to write what I want in more detail.

I have a website with 10 webpages on it (webpage 1 to 10).  What I would like to do is have a CGI script, called COCO.CGI, on webpage 1 which is called with <IMG src="cgi-bin/COCO.CGI">.  It takes in the HTTP_REFERER and REMOTE_ADDR and returns a graphical image if the HTTP_REFERER was set to webpage 1.

Now I would like to make a call to COCO.CGI from webpage 2 to 10 but unfortuantely the HTTP_REFERER will be set to webpage 2 to 10 instead of the required webpage 1.

This kind of problem sounds very trivial, even pointless/stupid but its something I need to figure out considering all those restrictions.

What I was thinking is to have a <IMG src="cgi-bin/MAPPER.CGI"> where MAPPER.CGI is a CGI script which is called from webpage 2 to 10.  Inside the script it will simply "redirect" (print "Location: http://mywebsite.com/webpage1.htm\n\n";) the incoming call to the webpage 1 in hopes of 'triggering' the COCO.CGI.  Unfortunately the call to MAPPER.CGI, and so webpage1.htm, returns an error since the returned data is not a graphical image but an HTML file (due to the error, the HTM page isn't triggered and nor is COCO.CGI).  Now if I simply redirected to COCO.CGI instead of webpage1.htm, the HTTP_REFERER won't be set to webpage 1.  Tricky eh?

Now I'm probably over thinking the situation (I hope) and there's most likely an easy solution, but it just continues to elude me.  Any help you can provide in successfully "mapping" a call from one CGI script to another "while altering the HTTP_REFERER" to a new value would be greatly appreciated!

Thanks for your patience.  I'm crossing my fingers.   :>
0
 
LVL 1

Expert Comment

by:stormerider
Comment Utility
Well, if this is the case, then I would save yourself a hell of a lot of grief and forget MAPPER.CGI. As far as I can tell, you don't need it. Basically what you want to do is along the lines of:

$http1 = "http://www.my.domain/page1.html";
$http2 = "http://www.my.domain/page2.html";
$http3 = "http://www.my.domain/page3.html";
$http4 = "http://www.my.domain/page4.html";
$http5 = "http://www.my.domain/page5.html";
<etc.>

if ($ENV{'HTTP_REFERER'} eq $http1 {
    &show_them_image_1;
} else if ($ENV{'HTTP_REFERER'} eq $http2) {
    &show_them_image_2;
} else if ($ENV{'HTTP_REFERER'} eq $http3) {
    &show_them_image_3;
} else if ($ENV{'HTTP_REFERER'} eq $http4) {
    &show_them_image_4;
} else if ($ENV{'HTTP_REFERER'} eq $http5) {
    &show_them_image_5;
} else <etc...> {
    &show_them_error_image;
}

Does that help any?

0
 

Author Comment

by:ratboy
Comment Utility
Great message Stormerider.   It does help!  Now just one last thing.  Those graphical images I send back to the client need to come from another server (my site is http://mysite.com  and I need to fetch the graphics from http://anothersite.com/pics/grfx1.jpg).  

If I use BIND/SOCKET/CONNECT then I'd be binding to my IP address and not the clients, unless I'm able to route BIND to the client and just send him/her the graphic directly from that server.  When I make this BIND/SOCKET/CONNECT call I can then set the Referer field to whatever I want.

So close to solving this problem. I can almost taste it. Any solutions with this added restricition?

Thanks for everything!
0
 
LVL 1

Expert Comment

by:stormerider
Comment Utility
The only thing I can think of in regards to that, if the client IP has to be saved is to either route it through with a port redirector or use SSI. Rather than <IMG SRC=blah.cgi>, try
<!--#exec cgi="blah.cgi"--> and have it spit back <IMG SRC="http://anothersite.com/pics/grfx1.jpg">.

Make sense?
0
 

Author Comment

by:ratboy
Comment Utility
Thanks a bunch Storemrider for everything!  You definitely deserve the points!

One last thing, what if the graphic that is returned is not an actual graphic file (http://anothersite.com/pics/grfx1.jpg) but is actually an output from a cgi script (http://anothersite.com/cgi/otherscript.cgi) which outputs a graphical image.  The CGI script then checks IP # and Referer!

Thanks and here's your points!
0
 

Author Comment

by:ratboy
Comment Utility
That's strange, the point worth was for 200 not 20.  Make sure you get the proper amount!  You deserve it.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now