Hi,

I'm trying to create a module that allows users to write a .forward file in their home-dir from a webpage. Basically a module that a user can use to get sendmail to forward their email.

The problem I have is that the code works on my Windows machine, however when I port the code to my Linux server, the code appears to work, the file is never written. Not only can I not seem to write it to a users home directory, I can't get it to write the file at all when the code is executed from the webpage. However, I created a command line version of the code and that works just fine.

I have tried various combinations of the code including:
a) having a .forward in the users home directory that is created and owned by the apache user who has read and write access.
b) Changing permissions on my perl scripts dir so that the directory is owned by the apache user
c) trying to write to a directory that is created and owned by the apache user.

I suspect this has something to do with perl security, can anyone help me? Also, if this wont work, can someone suggest a script or an other way of creating a web-based user interface that allows users to configure sendmail to forward email.

I AM USEING PERL 5.6.0 on my Linux box
(It works on windows which runs 5.8.0 but I dont think this is the reason).
All help is appriciated.

My perl code is below:

#!/usr/bin/perl use Fcntl; print "Content-type:text/html\n\n"; print "hello world"; if ($ENV{'REQUEST_METHOD'} eq "GET") { $request = $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $request,$ENV{'CONTENT_LENGTH'}) || die "Could not get query\n"; } @parameter_list = split(/&/,$request); foreach (@parameter_list) { # split each va +riable=value pair ($name, $value) = split(/=/); $name =~ s/\+/ /g; # replace "+" w +ith spaces $name =~ s/%([0-9A-F][0-9A-F])/pack("c",hex($1))/ge; # replace %nn w +ith characters $value =~ s/\+/ /g; # repeat for th +e value ... $name =~ s/%([0-9A-F][0-9A-F])/pack("c",hex($1))/ge; if (!(defined $passed{$name})) { $passed{$name} = $value; } else { $passed{$name} .= ":$value"; } } #print "$request"; #print "$passed{'username'}"; #print "<br/>$passed{'Submit'}"; print "<br/>"; print "<input type=submit name=Back value=Back onClick='Javascipt:hist +ory.back(0);'/>"; $file = ".forward"; #$file = "/home/$passed{'username'}/>.forward"; #$file = "c:/$passed{'username'}/.forward"; print "<br/>$file"; if($passed{'Submit'} eq "Submit"){ if($passed{'mforward'} eq "on"){ print "<br/>turn mail forward on"; sysopen (FWD, $file, O_RDWR|O_EXCL|O_CREAT, 0644); if($passed{'rcopy'} eq "Yes"){ printf FWD "\\$passed{'username'}\n"; } print FWD "$passed{'faddress'}"; close (FWD); print "<br/>Mail Forwarding ON mail for: "; print "$passed{'username'} forward to $passed{'faddress'} <br/ +>"; print "$passed{'rcopy'} Copy Retained!"; } else{ print "<br/>turn mail forward off<br/>"; if (unlink($file) == 0) { print "Forward Removed"; } else { print "ERROR Forward NOT REMOVED"; } } } else { }

In reply to File Writing & Deleting on Linux through Web-Interface by ali.muzaffar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.