I have looked around the various archives but have been unable to find a perl script that would simply copy /abc/def/hello.html over to /ghi/jkl/hello.html, over-writing the old version of the file on simple cgi command from a browser.
The environment is a FrontPage web where I have allocated a friend access to a FP sub-web (but not the main web, Telnet or FTP, as I have clients in that space), and there is a SIG Discussion Forum I have set up for him in the main web he needs to update an info strip on without having access permissions.
I have instead set up a crontab to copy the file every night, but I see that as a temporary measure and I would like to make it possible for him to update the included file from a browser command line without having to ask me every time.
I have also looked at several other ways around it but none are practical for one reason or another - for instance, the Forum's index file is generated on the fly, so I can't just change it to an .shtml extension and insert SSI code.
Any ideas? I'm very html, perl and js literate, but please KISS (Keep It Simple, Sarge!)...
TIA.
Jim Lynch
#call from browser, www.domain.com/cgi-bin/mover.cgi?file=THESRC&dest=DEST
#where THESRC is the full path to the source file, and DEST is full path to the destination file.
print "Content-type: text/html\n\n";
&parseform;
$src = $FORM{'file'};
$destination = $FORM{'dest'};
print qq¦<li>src: $src¦;
if (-e $src) {
open(FILE,"$src");
flock(FILE,2) if $operatingsystem eq "unix";
@filedata = <FILE>;
chomp @filedata;
close(FILE);
}
else {
print "<b>*error*</b> source file not found: $src";
exit;
}
chomp @filedata;
$ls =@filedata;
print qq¦ lines: $ls <li>dest: $dest¦;
print "*warning* destination file exists - will be overwritten<br>" if -e $destination;
open(FILE,">$destination");
foreach $_ (@filedata) {
print FILE "$_\n";
}
close(FILE);
print "File copy appears to have been a big success.<br>" if -e $destination;
sub parseform {
#debug level >4 = print forms;
my ($buffer, @pairs, $name, $value);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\r//g;
$FORM{$name} = $value;
if ($debug >4) {
print "<br>Form name : <b>$name</b> Value : <b> $value </b>\n";
}
}
}
Also tried leaving the filename off the destination path.
All efforts result in "src: *error* source file not found:".
Any ideas?
The file is at
9a/includes/discussionstrip.html
and needs to be copied to
x9a/includes/discussionstrip.html
The Telnet pwd path is
usr/www/users/candoo4u/9a/includes/discussionstrip.html
which is actually one of the paths I tried before (I use a diag.cgi script that passes me the server parameters).
I also just tried
usr/home/candoo4u/public_html/9a/includes/discussionstrip.html
which is really the virtual path, and - as expected - that did not work either.
Just in case you were wondering, the script is in fact running - it's returning the error message as coded - and I am transferring the file and its changes as ASCII, as well as chmod'ing it 755.
I also tried running it under both perl and perl5 (the server has both), same results.
The error is that the file is not found. It's there, I know that for sure from the directory listing and from putting the address in a browser, so path MUST be the problem.
Grrrrr.
Jim
J
Also, try it as the full path but without the forward slash!
drwxr-xr-x 9a
drwxr-xr-x includes
-rw-r--r-- discussionstrip.html
Took the suggestion of dropping the leading slash - same thing. Even tried the path from the html root without the slash...
I can't even blame Good Ole Bill for this one... it's UNIX/Apache.
Here's the file - I just have to prove it really exists...
[candoo.com...]
Right now it's a pop-up in the Forum at
[candoo.com...]
(it's still blank because the file with the test message has not been transferred - that's what I'm still trying to do).
J
This I don't understand, because I have access to the entire Domain using WS_FTP, Telnet and the crontab... the perl script should also have universal access.
Ah, well...
Thanks, guys, anyway. I appreciate the help, and this is a great resource I just found.
Have a good one...
Jim