Question
I've installed and configured TWiki on my system but I'm not able to upload files as attachments. I get as far as being able to select the file and click the upload button. Then I get an internal server error.
Error pasted below:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator,
postmaster@cncPLEASENOSPAM.bc.ca and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Apache/1.3.27 Server at spam.cnc.bc.ca Port 80
Line from access_log below:
"POST /twiki/bin/upload/Main/DListRelated HTTP/1.1" 500 611
Line from error_log below:
[Mon Dec 23 13:21:38 2002] [error] [client ] attempt to invoke directory as script: /home/httpd/twiki/bin
Insecure dependency in open while running with -T switch at /usr/lib/perl5/5.6.1/File/Copy.pm line 97.
[Mon Dec 23 13:22:13 2002] [error] [client ] Premature end of script headers: /home/httpd/twiki/bin/upload
- TWiki version:01 Dec, 2001
- Perl version:5.6.1 for i386-Linux
- Web server & version:Apache 1.3.27
- Server OS:Linux RH 7.3
- Web browser & version: IE 6sp1,mozila .9.9
- Client OS: WindowsXP
--
KevinGagel - 23 Dec 2002
Answer
Not sure what the cause of this problem is. Try to debug (e.g. with
TWiki::writeDebug( "..." ) statements) to see what parameters you get in
TWiki::Store::saveAttachment and what parameters are passed to
copy() in
lib/TWiki/Store.pm
--
PeterThoeny - 28 Dec 2002
Reply
I've tried to add debug statements but every time I save them and try the program I end up with the same error as I noted above. I'm thinking this is a rights issue. I've tried to follow the rights assignment on the docs install page but I'm confused about why I'm issue a 664 to the data directory and everything below and then a 755 to the same structure! I'm also not sure that my perl coding is correct. In the Store.pm I've added to the getFileName subroutine the following:
writeDebug("Entering getFileName")
I've also tried,
writeDebug("$web")
and
TWiki::writeDebug("$web")
I currently have that remarked.
I did locate the initialize and _traceExec routines and removed the remarking hash mark so they are active. I've found the debug.txt that results from them being unmarked but the info is only.
Store: rev = 25
Store: rev = 1
A clearer understanding of what my directory structure and there respective rights should be would be great. I'm using apache and it has a user and group apache installed. That is currently what I've chown to for all of the TWiki directory and files. I don't see a diffrence in 664 and 775 modes behaviour wise from TWiki.
Any suggestions?
--
KevinGagel - 22 Jan 2003
A quick
Google Groups search
revealed that the 'directory as script' issue is either permission based or due to Apache setup (e.g.
ScriptAlias config). See
TWiki:TWiki
docs - there is a list of valid permissions in
AppendixFileSystem for every file. To summarise:L CGI directories should be 755 and scripts should be 644; data directories are typically 777 and data files 666, unless you have a
SecureSetup in which your CGI scripts run as a normal user (e.g. as in
DreamhostSetupNotes). However, permissions can often vary depending on your local server and security setup.
--
RichardDonkin - 22 Jan 2003
What you want to put in saveAttachment will probably look something like this:
TWiki::writeDebug(join(", ", @_));
That'll print out the entire list of parameters, seperated by commas, to
data/debug.txt.
Also, make sure your permissions on the TWiki/pub directory are set correctly. That's the place where TWiki stores attachments, and it has to be writable by the user the TWiki
upload script runs as (usually
nobody).
--
WalterMundt - 22 Jan 2003
Additional Info
Thankyou Walter. That was helpful. Here is the resulting debug output
22 Jan 2003 - 15:34 Main, GeneralItems, , , Update.log, 1, 1, , , /usr/tmp/CGItemp7116
Where do I go from here?
--
KevinGagel - 22 Jan 2003
Try looking in
twikiDir/data/warning.txt...you should hopefully see something in there about this...
--
WalterMundt - 22 Jan 2003
Apache Log Entries
OK, now I'm getting log entries in the apache log file. Immediatly after clicking the send button the log shows this.
I can't fit the log here. So I'm attaching it in a txt file.
Next step please...
--
KevinGagel - 22 Jan 2003
- sample.txt: This is the small protion that shows the upload.
Using the writeDebug sub I've been able to get some good info out. I believe the problem is that the user "apache" which is what TWiki is runing under does not have write rights to a folder. There were no instructions to change rights in my /var/tmp folder. The cgi is trying to save a file to /usr/tmp/somefile. The /usr/tmp is a link to /var/tmp. The umask for that directory is 0022. Should it be something else?
--
KevinGagel - 22 Jan 2003
- It looks like you've managed to insert a $ before a "my" declaration when making a change in Store.pm.
- Yes, for file uploads to work with Apache, your temporary directory must by writable. This isn't mentioned because in 99.9% of Linux or UNIX installations, the temp. directory is already set up that way. Why it isn't in your case, I don't know.
--
WalterMundt - 23 Jan 2003
My servers error log now contains only these two lines when I attempt a attachment upload.
Insecure dependency in open while running with -T switch at /usr/lib/perl5/5.6.1/File/Copy.pm line 97.
[Thu Jan 23 22:23:23 2003] [error] [client 24.81.43.122] Premature end of script headers: /home/httpd/twiki/bin/upload
My servers access log contains.
24.81.43.122 - KevinGagel [23/Jan/2003:22:23:23 -0800] "POST /twiki/bin/upload/Main/GeneralItems HTTP/1.1" 500 611
The rights on the tmp directory are.
drwxrwxrwt 2 root root 1024 Jan 23 22:23 tmp
I don't understand what the t is about, should the tmp directory be owned by "nobody" and should I use chmod 775 on the tmp directory?
--
KevinGagel - 23 Jan 2003
Your tmp directory looks fine...but I think it's trying to use /usr/tmp...is that /tmp, or /usr/tmp? I can't tell from the listing. Both should have permissions like that (777).
As for the server error log: looks like the problem is with a Perl feature called "taint checking"...as a quick but insecure fix, you could remove the capital T from the end of the first line in
bin/upload...this will turn off taint checking entirely. Have you applied any patches to your TWiki installation other than the changes recommended here? It would be far better to find out WHY the taint-check is complaining rather than just shutting it up.
--
WalterMundt - 25 Jan 2003
Walter, I agree. I figure the T is there for a reason so I have resited removing it. No I have not patched TWiki at all. It is the original that I downloaded from TWiki.org. As for the tmp directory twiki is trying to use /usr/tmp but that is actually a link to /var/tmp I'll try changing the directory permissions to 777 and test again. I'll post result here later.
--
KevinGagel - 24 Jan 2003 (at least it still is here

)
For links, make sure you adjust the permissions both for the link (if necessary, most are 777 by default) AND the target directory. Oh, and BTW, my IM/e-mail info is in my topic, feel free to contact me directly via IM if you want to chat about this...might get more done faster that way.
--
WalterMundt - 26 Jan 2003
OK, Its a problem with
RCS but I'm not sure what exactly. I'm still researching and finding things out. The extra code in the upload script helped after I changed it to match case. Now I get this error:
During save of file Main.GeneralItems an error was found by the version control system. Please notify your TWiki administrator.
/usr/bin/ -q -i -t-none -kb /home/httpd/twiki/pub/Main/GeneralItems/test.doc,v 2>&1 1>/dev/null
sh: /usr/bin/: is a directory
Go back in your browser and save your changes locally.
Traking this one has led me to the TWiki.cfg file. While the file remarks indicate that
RCS is off by default for attachments mine was set on. Disabling it does not make a change in the above error message. The remarks also indicate that I need to make a
RCS directory, I've done that but no change. The file does get uploaded but there is no rcs files made in the
RCS directory.
--
KevinGagel - 29 Jan 2003
It looks like it doesn't know what to call your rcs program. The above command line SHOULD start with '/usr/bin/rcs", not just "/usr/bin"
--
WalterMundt - 30 Jan 2003
Here is my TWiki.cfg:
$mimeTypesFilename = "$dataDir/mime.types";
# RCS directory (find out by 'which rcs') :
$rcsDir = "/usr/bin";
Results of 'which rcs':
[root@spam lib]# which rcs
/usr/bin/rcs
[root@spam lib]#
As I was writing this, it dawned on me to find where the rcs is called and see what it has. Here it is:
# RCS init command, needed when initialising a file as binary
$revInitBinaryCmd = "$rcsDir/ $rcsArg -q -i -t-none -kb %FILENAME%";
It seemed to me that it needs to know the name of the program so added rcs to it and the system now works!
Thanks Walter.
In summary, there were three changes required to make uploading work. None of them were rights. Changes as follows:
In the /home/httpd/twiki/lib/TWiki/upload script the addition of the two following lines were required under the
#Update
remark.
-
$fileName =~ /(.*)/;
-
$fileName = $1;
Note:Thanks to
WalterMundt for this contribution. It successfully stoped the Internal Server Error and allow me to finally locate the next problem.
In the /home/httpd/twiki/lib/TWiki.cfg configuration file the following line needed to be changed from:
$revInitBinaryCmd = "$rcsDir/ $rcsArg -q -i -t-none -kb %FILENAME%";
To:
$revInitBinaryCmd = "$rcsDir/rcs $rcsArg -q -i -t-none -kb %FILENAME%";
Note the addition of rcs to the line.
--
KevinGagel 31 Jan 2003