Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

CGI file permissions

WeirdofreakWeirdofreak Posts: 439Member
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?

Comments

  • JonathanJonathan Posts: 2,914Member
    : 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.");

  • WeirdofreakWeirdofreak Posts: 439Member
    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.
  • JonathanJonathan Posts: 2,914Member
    : 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.");

  • WeirdofreakWeirdofreak Posts: 439Member
    [b][red]This message was edited by Weirdofreak at 2003-12-12 12:38:51[/red][/b][hr]
    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.
  • JonathanJonathan Posts: 2,914Member
    : 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.");

  • WeirdofreakWeirdofreak Posts: 439Member
    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.
  • JonathanJonathan Posts: 2,914Member
    : 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. 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.");

  • WeirdofreakWeirdofreak Posts: 439Member
    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.
  • JonathanJonathan Posts: 2,914Member
    : 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.");

Sign In or Register to comment.