SunQuest
           Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old January 12th, 2002, 12:17 PM
the_pedestrian the_pedestrian is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Posts: 210 the_pedestrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Unhappy basic PERL question....

Hi,

Im trying to create a script that;

(i) creates a .htm page based on form input and saves it in directory. The filename is based on the form input

then

(ii) prints a frameset with the above .htm, and another static html file.

check out the code...ive tried to cut out the superflous stuff


#!/usr/bin/perl

require "cgi-lib.pl";

&ReadParse(*input);

$uname= $input{'handle'};
$pass= $input{'password'};
$file = "http://www.whatever.org/$uname.htm" ##problem area?????



# open/create $file

open(FILE, ">$file");
print <<X;

[html stuff]

X
close(FILE);


#redirect to frames

print <<END;

<html><head><title>test page</title></head>

<frameset rows="80%,20%">
<frame name="one" src="http://whatever.com">
<frame name="two" src="$file">
</frameset>
</html>
END


any input would be appreciated......i know this is pretty basic


thanks

Reply With Quote
  #2  
Old January 12th, 2002, 12:58 PM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,632 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 12 m 33 sec
Reputation Power: 77
Send a message via AIM to Hero Zzyzzx
Hey there!

Hmm. Here's a few things-

cgi-lib.pl was crusty back in 1996. It's a really, really poor thing to develop around. You should use the modern, well-documented and super-powerful CGI.pm, which is basically the standard for perl CGI scripting. If a book recommended that you use cgi-lib.pl, you should throw that book out, it's either too old or written by the clue-impaired.

Basing filenames strictly on info that a user enters into a form is VERY insecure- what if a user enters "../../cgi-bin/yourscript.pl"? Your script would destroy itself, because it would be writing over itself. You need to "untaint" the data sent from the user with a regular expression.

Learning to code perl by writing CGI scripts is kind of a difficult way to go about it- frequently, CGI scripts are being used in an environment where there is always a potential for attacks. I suggest you start by getting the O'Reilly "Learning Perl" books, and then moving on to "CGI Programming with Perl" by the same publisher. Most other CGI books suck, and are written by newbies with a little bit of knowledge who are just trying to sell books.

A really good CGI tutorial, written by a coder with a good understanding of perl and security is at the URL below.

http://www.easystreet.com/~ovid/cgi_course/

Reply With Quote
  #3  
Old January 12th, 2002, 01:27 PM
the_pedestrian the_pedestrian is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Posts: 210 the_pedestrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Dan,

what the hell would i do without you?

Its not for the site...just fooling around with a script for learning purposes.

I figure;

$file = "http://www.whatever.org/$uname.htm"

makes PERL look for a variable $uname.htm instead of a file ($uname).htm.

so, concatenation? this is where im stuck.


I appreciate the security/cgi-lib stuff......but now my curiosity is aroused.

anyone?

Reply With Quote
  #4  
Old January 12th, 2002, 02:26 PM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,632 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 12 m 33 sec
Reputation Power: 77
Send a message via AIM to Hero Zzyzzx
The major problem with your script, besides the stuff I mentioned already, is that you're trying to open "http://www.whatever.org/$uname.htm" as a local file, and then write to it.

This ain't going to work. Files on your filesystem are addressed like local files- e.g., on linux machines "/path/to/directory/$filename", not as URLs.

On the concatenation question- Your corrected filename might look something like:

Code:
$filename='/path/to/file/'.$filename.'.htm';


note the different way of creating the string. Fine to play with this, but for gods sake take it off your server when you're done.

Oh, and when a variable is put into double-quotes with perl, it is interpreted, when you put it in single-quotes it isn't.

Code:
$poo='bar';

print "$poo $poo $poo";

output would be bar bar bar
Code:
$poo='bar';

print '$poo $poo $poo';

output would be $poo $poo $poo

In the future, I'd just post all perl questions, including total newbie ones, into the perl forum.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > basic PERL question....


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway