Solved

IIS4 and perlscripts that write to a file

Posted on 1998-07-22
5
231 Views
Last Modified: 2010-03-05
I got my perlscripts running on IIS4, they respond ok to the browser.
But the scripts that are supposed to write to a file with this code:

open(OUTFILE, ">bla.txt");
print (OUTFILE "test\n");
close(OUTFILE);

Just don't write to the file. There is no error message.

print "Content-type: text/html\n\n";
print "here we are";

After the writing statement gives the right output to the browser.

Also when the script is run from the command prompt it works ok.

I checked security, and I don't think there is a problem there.
0
Comment
Question by:sybe
  • 3
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 200 total points
ID: 1208594
Does the file exist? Does the file exist in the directory you think it should exist in?
Try doing:

open(OUTFILE, ">bla.txt") || die "Content-type: text/html\n\n$!\n\n";

If that doesn't tell you anything good (like why the open failed), and you're sure of the directory that the file is being put in, and you're on a UNIX server, then perhaps something is odd with your umask, but cross that bridge when  you fall off it.
0
 
LVL 28

Author Comment

by:sybe
ID: 1208595
Now this is an interesting suggestion, When I do as you say, the code is as follows:
=======================
#!usr/local/bin/perl

open(OUTFILE, ">>/Inetpub/scripts/perl/test2/bla.txt") || die "Content-type: text/html\n\n$!\n\n";
print (OUTFILE "test\n");
close(OUTFILE);

open(READFILE, "/Inetpub/scripts/perl/test2/bla.txt");
$line = <READFILE>;
close(READFILE);

print "Content-type: text/html\n\n";
print "$line<BR>\n";
print "here we are";
============================

and the response in the browser is:

"Permission denied "


Using the code that I had before:
========================
#!usr/local/bin/perl

open(OUTFILE, ">>/Inetpub/scripts/perl/test2/bla.txt");
print (OUTFILE "test\n");
close(OUTFILE);

open(READFILE, "/Inetpub/scripts/perl/test2/bla.txt");
$line = <READFILE>;
close(READFILE);

print "Content-type: text/html\n\n";
print "$line<BR>\n";
print "here we are";
============================

The response in the browser is:

phrase from bla.txt
here we are

==========================

So it might after all be a permission thing.

What permissions are needed on NT ??

0
 
LVL 5

Expert Comment

by:b2pi
ID: 1208596
Clearly, you don't have write permissions.  Let me guess... the script works if you run it from the command line, but not if you run it from the server, right?  So the question is, what is the current directory when you're running from the server, and who cares, as you don't have write permissions there.  Thus, open the file in a directroy where you have write permissions.... (Ummm, for instance, the one you're in when you're running the script manually from the command line..., or /tmp, or the value of $ENV{tmp} or the value of $ENV{temp} or ....


0
 
LVL 28

Author Comment

by:sybe
ID: 1208597
When I give everyone -> full control, it works, now it's only a matter of denying what rights are not needed.

Thanks, it helped me a lot.

What does

|| die "Content-type: text/html\n\n$!\n\n

exactly do ? display the error message ?
so $! is the error message
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1208598
$! is indeed the error message.

But!!!! STOP!!!!!!!!!!!!!!!!!!!! STOP!!!!!!!!!!!!!!!!!!!!STOP!!!!!!!!!!!!!!!!!!!!STOP!!!!!!!!!!!!!!!!!!!!STOP!!!!!!!!!!!!!!!!!!!!
DO NOT GIVE EVERYONE FULL CONTROL!!! If you do, some nice person from the outside world could easily come in and take you down.  Hard!!!!  Instead, give everyone
full control to, say, C:\temp, and open the files there...

open (OUTFILE, ">>/temp/bla.txt") || die ....

You never want anyone writing to that scripts directory.  A better solution is to find out who the user is when executing cgi scripts (I can't remember for IIS, but it may well be "NOBODY") and give that user write rights to a data directory, which no-one else has write-rights to.

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

747 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

12 Experts available now in Live!

Get 1:1 Help Now