LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-27-2005, 12:58 AM   #1
PolishSausageof
LQ Newbie
 
Registered: Aug 2004
Location: Bloomington, Indiana
Distribution: FC2 and FC4
Posts: 27

Rep: Reputation: 15
help with a very simple CGI proxy


hey all,
i'm running an apache server and hosting a webpage that will act like a proxy. i have two frames, in the top i have a submit button with a textbox. i would like the user to input a URL into the textbox and when submit is pressed, the server goes and gets the wepage and displays it in the bottom frame. i'm learning perl now and i hear thats the easiest language to do it with. any help or suggestions would be much appreciated. thanks in advance to any replies!!
 
Old 04-27-2005, 09:28 AM   #2
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
You can do it in PHP with one line:

PHP Code:
<?php
     passthru
("/usr/bin/curl http://www.carumeen.com/index.php");
?>
Just replace that URL with a variable representing whatever URL you want, then reload that frame.

I won't make any claims as to security with this method though, but it works basically as a proxy browser. Note that they could use this to method download ANY URL, including trojans or bogus code, so you might want to have some extra security like an address whitelist or blacklist. But, that's the nature of a proxy.

PS: This will not make any clickable links work though, since those links are either relative or absolute and will either break or bypass your proxy page.

PPS: This will also (obviously) make all requests appear to come from your server, so if someone feels like doing something naughty you'll get blamed. Try to make your proxy authenticated if you can, at least with an .htaccess directive.

Last edited by michaelsanford; 04-27-2005 at 09:43 AM.
 
Old 04-27-2005, 11:02 AM   #3
PolishSausageof
LQ Newbie
 
Registered: Aug 2004
Location: Bloomington, Indiana
Distribution: FC2 and FC4
Posts: 27

Original Poster
Rep: Reputation: 15
Talking Thank you!!

Thanks a lot!! I'm not too worried about security because this is for a demonstration for a class project. However, I am going to look into those security issues for future reference! Again, thanks a lot for the info!!!
 
Old 04-27-2005, 11:12 AM   #4
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
I had a feeling it was for a class project

If you want to continue the security issue just reply and we'll (and anyone else who wants can) take it from there.
 
Old 04-28-2005, 01:50 PM   #5
PolishSausageof
LQ Newbie
 
Registered: Aug 2004
Location: Bloomington, Indiana
Distribution: FC2 and FC4
Posts: 27

Original Poster
Rep: Reputation: 15
Small problem

thanks again for all the help, but i'm new to PHP and im having trouble...or rather im not sure how, or even if it is possible to send variable information between two frames. Since my two frames are obviously two different files how would i pass the information from my input to the other frame? would i put the passthru() function in the top frame and have it pass the info to the bottom frame, or would i need to make it all in one file? thanks again!
 
Old 04-28-2005, 10:28 PM   #6
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
Does it really need to be in a separate frame? If not you could just put a form at the top of a page and separate it with a good old horizontal rule, then post the variable to the page itself.

This is the complete code for browser.php
PHP Code:
<html>
<form action="browser.php" method="POST">
<input name="address" id="address" type="text" size="30" value="http://" />
<input type="submit" name="go" value="go" />
</form>
<hr />
<?php
    
if (isset($_POST['address']) {
      
// If he entered something in the page and pressed go
      
$curl_command "/usr/bin/curl " $_POST['address'];
      
passthru($curl_command);
    } else {
      
// If the user hasn't entered anything yet, go here as the default
      
passthru("/usr/bin/curl http://www.defaultpage.com/index.html");
    }
?>
</html>
 
Old 04-30-2005, 11:46 AM   #7
PolishSausageof
LQ Newbie
 
Registered: Aug 2004
Location: Bloomington, Indiana
Distribution: FC2 and FC4
Posts: 27

Original Poster
Rep: Reputation: 15
i ended up doing just that. i (and several professors and grad students in the Indiana University School of Informatics) couldn't figure out, at least in the time i had allotted, a way for the two frames to send the URL information. i ended up doing something very similar to what you did, and finishing it just in time.

one idea that we had for transferring the URL information between the two frames was writing the URL to a text file, then having the bottom frame read it and refresh. i'm going to continue to work on this and see what i can come up with, i'm going to have some questions about security soon, but i'd like to try and get what i have to be a bit more refined before i worry about that. thanks again for the help!!!
 
Old 04-24-2006, 06:49 PM   #8
tekhead2
Member
 
Registered: Apr 2004
Distribution: slackware/FreeBSD/Vector
Posts: 291

Rep: Reputation: 52
cgi proxy

You could always take a look at cgiproxy.www.jmarshall.com/tools/cgiproxy
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why doesnt my simple html post to cgi script work? ginda Linux - Networking 10 03-15-2005 03:32 PM
bizarre python behavior - simple cgi variables SerfurJ Programming 2 04-14-2004 02:58 PM
How to run simple CGI program in browser ? amit_28oct Programming 5 03-23-2004 11:43 PM
Simple proxy/firewall server scammeh^ Linux - Networking 3 10-15-2003 01:11 PM
Simple Proxy Server in C The Bag Programming 0 03-05-2002 10:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration