Forum Moderators: phranque

Message Too Old, No Replies

Scripts Not Working Because of Permissions

Some of the scripts I run require permissions that the server doesn't allow

         

webfirst

4:05 am on Jul 9, 2007 (gmt 0)

10+ Year Member



I recently move a site to a new server, and now some of the scripts won't work. One of the scripts I'm running is set on cron jobs that tells the script to run periodically.

This script auto-updates the sitemaps so the sitemap pages must have 666 file permissions in order for the script to update the info from the last run and write the new info. But when any of the files on the server are set to 666, the page will respond with a 500 error when trying to access.

I spoke to the hosting provider and their answer was that their servers are PHPSuExec servers and they require that all files that need to be read by PHP scripts have permissions set to 644, and folders have permissions set to 755.

Would have been nice to know that before I move a 3000+ page site to their server.

I am in need of some info on how to fix or get around this if possible. Either with htaccess or any other source. If anyone know anything about this, PLEASE HELP, the site not working is costing me money.

phranque

8:31 pm on Jul 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



chmod 644 /path/to/scripts/*.php

webfirst

5:40 am on Jul 10, 2007 (gmt 0)

10+ Year Member



I know I'm stupid, but what do I do with that piece of code?

Key_Master

6:08 am on Jul 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you code the script to open files in 644, chmod the file to 666, write the new info, then chmod the file back to 644?

phranque

6:51 am on Jul 10, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



what do I do with that piece of code?

that is the unix command to change the file mode to 644 for all php files in the /path/to/scripts/ directory.
you would have to get some sort of telnet or ssl application that would give you a command console on the server as well as a login with sufficient priveleges.

webfirst

7:57 am on Jul 10, 2007 (gmt 0)

10+ Year Member



Key_Master

I wish I could do that, but unfortunately, the script is encrypted to the point that I wouldn't even know where to start, and it is copyright protected. I hate to post this but I am anyway so you get the full picture. This is a very complicated program and don't think altering the script is possible, and probably not legal. There are over 50 pages like this, and this is the shortest, some cover 4 full page folds. If you know what to do with this, please let me know.

<?php // This file is protected by copyright law and provided under license. Reverse engineering of this file is strictly prohibited.
eval(base64_decode('Pz48P3BocAplY2hvICc8YnI+Q3JlYXRpbmcgSFRNTCBzaXRlbWFwLi4uJztmbHVzaCg
pOwokTHNLUWZXQzdoQ3EybSA9ICRncmFiX3BhcmFtZXRlcnNbJ3hzX2luaXR1cmwnXTsK
aWYoc3Vic3RyX2NvdW50KCRMc0tRZldDN2hDcTJtLCcvJyk+MikKJExzS1FmV0M3aENxM
m0gPSBzdWJzdHIoJExzS1FmV0M3aENxMm0sIDAsIHN0cnJwb3MoJExzS1FmV0M3aENxMm
<snip>
bCwgJ3cnKTsKZndyaXRlKCRwZiwgJHNUT0hrd1kwRWlXaSk7CmZjbG9zZSgkcGYpOwp9C
n0KPz4='));
?>

Lots of crap here so sorry in advance. As you can see, I need another alternative like with htaccess or another script to intercept and change codes back and forth as you implied.

[edited by: jdMorgan at 4:27 pm (utc) on July 10, 2007]
[edit reason] Let's not invite a copyright lawsuit, please. [/edit]

phranque

8:56 am on Jul 10, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



try printing the results of the eval(base64_decode('...')) to a file.

Key_Master

10:27 pm on Jul 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unfortunately, I think you're going to have to get another host unless you are able to reverse engineer the script and modify it yourself. Yes, it probably wouldn't be all that difficult to decode the script you are using but you never know what kind of other security features are built into it. Also, Apache cannot change file permissions at all so there isn't a .htaccess solution for you.

Maybe you can convince the author of the script to sell you an unprotected copy.

jezra

12:24 am on Jul 11, 2007 (gmt 0)

10+ Year Member



you should write a wrapper script around the update sitemap script that changes the privileges to 666, runs the update script and then changes the privileges back to 644.

Is cron running the script directly or is cron accessing the script via a web server?

Since cron should be running as root, and root should not have a problem writing to a file with 644 privileges, I'm going to presume that you are accessing the script via a webserver using wget or curl. If this is true, and you are running cron on the webserver where the files are hosted, you could change the cron to run a script with the following code:

#!/bin/sh
chmod 666 /path/to/site/map
curl http://example.com/updatescript.php > /dev/null 2>&1
chmod 644 /path/to/sitemap

Key_Master

12:32 am on Jul 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem with that technique and other similar ideas is that the script can only open the files if they are set to 644. So setting the permissions to 666 before the file is opened will result in a 500 error.