Perl

Moderators: Jonathan
Number of threads: 1236
Number of posts: 3605

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
CGI file permissions Posted by Weirdofreak on 12 Dec 2003 at 9:12 AM
I'm trying to write a script that will update the news on a site's front page. However, I can't get the script to write to the page. This is the important bit:

open FILE, '> test.php' or die $!;
print FILE "Hello" or die $!;

I know that using the > will overwrite the file instead of appending to it, but I'm just running this for a test right now, and >> doesn't do anything either. It doesn't throw any errors, but I can't seem to make it write to the file. It just appears to get lost somewhere between the script and the rest of the server.

If it helps, I'm stuck with a Windoze server, and the rest of the script executes fine.

Any ideas?
Report
Re: CGI file permissions Posted by Jonathan on 12 Dec 2003 at 9:37 AM
: I'm trying to write a script that will update the news on a site's
: front page. However, I can't get the script to write to the page.
: This is the important bit:
:
: open FILE, '> test.php' or die $!;
: print FILE "Hello" or die $!;
:
: I know that using the > will overwrite the file instead of appending
: to it, but I'm just running this for a test right now, and >>
: doesn't do anything either. It doesn't throw any errors, but I can't
: seem to make it write to the file. It just appears to get lost
: somewhere between the script and the rest of the server.
:
: If it helps, I'm stuck with a Windoze server, and the rest of the
: script executes fine.
It'll be a permissions issue msot likely (seems you think so). You need to give the user the Perl script runs as the correct permissions (e.g. write) on the folder you are creating the file in (e.g. the folder containing the script itself). This doesn't seem to be the default on most Windows servers. What is the message it dies with?

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Report
Re: CGI file permissions Posted by Weirdofreak on 12 Dec 2003 at 9:48 AM
That's the confusing thing - it doesn't. If it did, I might be able to work out what the problem is, even if not how to fix it.

I didn't actually realise Windoze had permissions, but that seemed like the sort of problem it is.
Report
Re: CGI file permissions Posted by Jonathan on 12 Dec 2003 at 10:00 AM
: That's the confusing thing - it doesn't. If it did, I might be able
: to work out what the problem is, even if not how to fix it.
Have you tried using print instead of die? Problem with die is if you run the script over the web (what you are doing?) then messages printed to STDERR, which is where die messages go, don't get sent. Of course, your script won't terminate but at least you can temporarily do that to get the message.

: I didn't actually realise Windoze had permissions, but that seemed
: like the sort of problem it is.
Depends on the version of Windows you're running and how it's set up. WinNT is the only Windows I've recently deployed a Perl developed solution on, and we had to do this kind of thing.

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Report
Re: CGI file permissions Posted by Weirdofreak on 12 Dec 2003 at 12:22 PM
This message was edited by Weirdofreak at 2003-12-12 12:38:51

Well, that would explain why it doesn't give an error. I'll try print in a mo.

As for the version, I don't know. I think it's something like XP professional or 2000 or something like that. I'm sure I've seen it on the site (hostonce.com), but I can't find it again.

EDIT: Okay, the errors given are 'Permission denied' for the open, and 'Bad file descriptor' for the print FILE. Having looked around a bit, it seems that all the files have a chmod of 666, except for two folders, which are 000 - _vti_cnf and _vti_pvt. Strange and icky.
Report
Re: CGI file permissions Posted by Jonathan on 12 Dec 2003 at 5:49 PM
: Well, that would explain why it doesn't give an error. I'll try
: print in a mo.
As an aside, the messages may appear in the error logs.

: As for the version, I don't know. I think it's something like XP
: professional or 2000 or something like that. I'm sure I've seen it
: on the site (hostonce.com), but I can't find it again.
I'd be pretty certain it'll be 2000 if a hosting company are providing it. XP is a desktop OS, not a server one. And 2000 will have proper permissions set up etc.

: EDIT: Okay, the errors given are 'Permission denied' for the open,
: and 'Bad file descriptor' for the print FILE.
This pretty much confirms it is a permissions issue then. Bad file descriptor is a result of the open failing, so you don't have a valid file handle.

: Having looked around a bit, it seems that all the files have a chmod
: of 666, except for two folders, which are 000 - _vti_cnf and
: _vti_pvt. Strange and icky.
Ugh... Windows permissions aren't really (at all) like UNIX ones, so chmod support is a kinda hack anyway. What is most important is the permissions on the directory that the Perl script is in, as this is what it is trying to write to.

My only thought is to contact your host and ask them to configure their servers so you can create files. Unless you are able to change permissions etc through your control panel, I don't know there's a lot you can do.

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Report
Re: CGI file permissions Posted by Weirdofreak on 13 Dec 2003 at 12:34 PM
That cleared things up, thanks.

Apparently, the lack of CHMOD isn't a bug, or even a hindrance (ignoring the fact that I might have had it running a day or so ago if it existed), but a feature. A feature that improves security, even. :)

Still, after I got in touch, and assured them that my problem was not with executing the script (which they said I could do if I changed the extension to .pl. It worked fine with .cgi.), but with the permissions, they said I'd have to ask them to do it every time. So I have to wait until they can do it before it's up and running. Go figure.
Report
Re: CGI file permissions Posted by Jonathan on 13 Dec 2003 at 2:33 PM
: That cleared things up, thanks.
Welcome.

: Apparently, the lack of CHMOD isn't a bug, or even a hindrance
: (ignoring the fact that I might have had it running a day or so ago
: if it existed), but a feature. A feature that improves security,
: even. :)
Lack of chmod is nothing to do with improving security. Windows just uses a different permissions model to UNIX, and Perl originated in the UNIX environment and is still more common there. It has modules for managing Windows permissions too. Someone who knows the permissions model of the OS well enough will be able to set up a secure system either way.

: Still, after I got in touch, and assured them that my problem was
: not with executing the script (which they said I could do if I
: changed the extension to .pl. It worked fine with .cgi.),
I wouldn't be too surprised if that really didn't make any difference...

: but with the permissions, they said I'd have to ask them to do it
: every time. So I have to wait until they can do it before it's up
: and running. Go figure.
Yeah, that's why you don't host on Windows. <grins evily> Only kidding, it has to be done now and then. Hopefully they'll get it set up properly for you.

Good luck, anyway,

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Report
Re: CGI file permissions Posted by Weirdofreak on 14 Dec 2003 at 2:35 AM
Most of that post was sarcasm, or cynicism. It's not technically my site, I just do the technical stuff for it. If I could, I'd use a *NIX server.
Report
Re: CGI file permissions Posted by Jonathan on 14 Dec 2003 at 7:49 AM
: Most of that post was sarcasm, or cynicism.
Indeed.

: It's not technically my site, I just do the technical stuff for it.
: If I could, I'd use a *NIX server.
It's a situation most of us have to work in from time to time. Hope things work out for you, anyway.

Jonathan


###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.