CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How do i do this...

 



doc
newbie

Jun 11, 2000, 4:05 AM

Post #1 of 10 (1395 views)
How do i do this... Can't Post

i would be grateful if one of you experts out there could tell me how to do this:
I want to send information via a simple text area using the post method to a cgi script on another site, and parse the result from between the <P><PRE> and </PRE></P> tags, as well as be able to display the result using a simple header and footer txt file. I am sure it can't be more than 1k of text.
My email address is: netdoc@mad.scientist.com
Thanking you in advance.


TheGame+
Deleted

Jun 13, 2000, 3:20 AM

Post #2 of 10 (1395 views)
Re: How do i do this... [In reply to] Can't Post

Probably less than 1k of text Smile

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

#!/usr/bin/perl -w
#
# Copyright TheGame, 13 June 2000
#
# This script may not be used to retrieve copyrighted material
# without the author's permission
#

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use strict;

my $header = '/home/users/scriptkiddie/header.txt';
my $footer = '/home/users/scriptkiddie/footer.txt';
my $url = 'http://www.whatever.com/cgi-bin/copy_protected.cgi';
my $site = 'Some Copyrighted Site';

print header,start_html("This is an illegal copy from $site");

open(FILE,"<$header") &#0124; &#0124; die "Can't open header - $!\n";
while (<FILE> ) {
print;
}
close(FILE);

if (param) {
my $text = param('some_text');

my $ua = new LWP::UserAgent;
my $req = POST "$url",
[ some_field => $text,
other_field => 'Some other stuff',
];

my $res = $ua->request($req);
if (!$res->is_success) {
print "Sorry, <A HREF=\"$url\">$site</A> has banned me...";
}
else {
print "<A HREF=\"$url\">$site</A> was kind enough to send this :";
print "<P><PRE>\n";
print $res->content;
print "</PRE></P>\n";
}
}
else {
print <<EOT;
Retrieve an illegal copy from <A HREF="$url">$site</A> :<P>
<FORM METHOD="POST">
<TEXTAREA NAME="some_text">
</TEXTAREA>
<INPUT TYPE="submit" VALUE="Go !">
</FORM>
EOT
}

open(FILE,"<$footer") &#0124; &#0124; die "Can't open footer - $!\n";
while (<FILE> ) {
print;
}
close(FILE);

print end_html;

exit;
</pre><HR></BLOCKQUOTE>


TheGame+
Deleted

Jun 14, 2000, 6:29 AM

Post #3 of 10 (1395 views)
Re: How do i do this... [In reply to] Can't Post

Well, you probably adapted the script to your own needs, and you may have made a typo somewhere.
To check that, try it on your own system by typing "perl -wc parse.cgi" in a DOS box or on a command line. This will compile the script and tell you if there's anything seriously wrong with it (like a missing ' or something).

Once you've corrected all compilation errors locally, you can upload it to your webserver again (in ASCII) and change its permission to 755 (rwxr-xr-x).
Make sure Perl is located in /usr/bin on the server, and if it isn't, adapt the first line of the script accordingly.
And make sure your header and footer files are in the correct location, and are readable by the script when it is run by the webserver.

Now you're ready to try it out. If you see an error appear in the browser, saying it can't find HTTP::Request::Common or LWP::UserAgent in @INC, that means the webserver does not allow you to do what you want to do.
Unless you can convince the administrator of the server to install those (standard) modules, you're stuck.

Note that many free webservers don't allow outgoing socket connections at all, so they won't run this kind of script either.


Cure
User

Jun 14, 2000, 6:43 AM

Post #4 of 10 (1395 views)
Re: How do i do this... [In reply to] Can't Post

your getting the error because you have this in your code |space|, there shouldnt be a space in between the &#0124; &#0124;.


Cure

[This message has been edited by Cure (edited 06-14-2000).]


doc
newbie

Jun 14, 2000, 10:52 AM

Post #5 of 10 (1395 views)
Re: How do i do this... [In reply to] Can't Post

Thanks for replying so soon!
Unfortunately, i am getting this error message:

Software error:
Execution of parse.cgi aborted due to compilation errors.

Please Help.
Thanks again.


[This message has been edited by doc (edited 06-14-2000).]


DrZed
User

Jun 14, 2000, 5:21 PM

Post #6 of 10 (1395 views)
Re: How do i do this... [In reply to] Can't Post

You can thank UBB for that space....

--> &#0124; &#0124; <-- try it yourself....

Maybe |'s are just anti-social.

Dr. Zed


Kanji
User / Moderator

Jun 14, 2000, 5:50 PM

Post #7 of 10 (1395 views)
Re: How do i do this... [In reply to] Can't Post

Nah, UBB (IMHO) is just a big pile of doo-doo.


doc
newbie

Jun 15, 2000, 12:00 AM

Post #8 of 10 (1395 views)
Re: How do i do this... [In reply to] Can't Post

Thanks a lot Cure!!!
You Too TheGame!!!
It works now... the only problem is that it doesn't only parse everything between the <P><PRE> and </PRE></P>, it simply returns the whole page. Is there a line or two i could add to parse only what is between the <P><PRE> and </PRE></P>?
Any help would be most appreciated.
Thanks.


Kanji
User / Moderator

Jun 15, 2000, 7:27 AM

Post #9 of 10 (1395 views)
Re: How do i do this... [In reply to] Can't Post

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if ( $res->content =~ /<p><pre>(.*?)<\/pre><\/p>/is ) {
print $1;
} else {
print "Nada. Zilch. Bugger all.";
}</pre><HR></BLOCKQUOTE>


[This message has been edited by Kanji (edited 06-15-2000).]


doc
newbie

Jun 15, 2000, 11:10 PM

Post #10 of 10 (1395 views)
Re: How do i do this... [In reply to] Can't Post

Thanks Kanji! The script works perfectly now!
This board has really proved useful to perl beginners. Who knows, maybe when i get to know some tricks, i might be able to help those in need.
Thanks again.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives