• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

IIS4 and perlscripts that write to a file

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
sybe
Asked:
sybe
  • 3
  • 2
1 Solution
 
b2piCommented:
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
 
sybeAuthor Commented:
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
 
b2piCommented:
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
 
sybeAuthor Commented:
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
 
b2piCommented:
$! 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now