Solved

Socket, Bind, Connect: Remapping The Server

Posted on 1998-09-16
12
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 1

Accepted Solution

by:
stormerider earned 200 total points
ID: 1828646
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
ID: 1828647
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
ID: 1828648
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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
LVL 1

Expert Comment

by:stormerider
ID: 1828649
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
ID: 1828650
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
ID: 1828651
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
 

Author Comment

by:ratboy
ID: 1828652
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
ID: 1828653
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
ID: 1828654
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
ID: 1828655
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
ID: 1828656
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
ID: 1828657
That's strange, the point worth was for 200 not 20.  Make sure you get the proper amount!  You deserve it.
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

726 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