Post by gocreative » Sun Apr 25, 2010 3:17 pm

Hi all,

I've recently come across a script that I thought some people might find handy, and it could possibly be integrated into the OpenCart installation process as well. What it does is automatically perform CHMOD for a defined list of files/folders. As I've set up a number of OpenCart stores, this script has been a handy time-saver for me.

To run the script, just customise the code below, save as a PHP file (e.g. chmod.php), upload to your server and visit the file's location in the address bar (e.g. yoursite.com/store/chmod.php). Optionally the script can use variables to override the permission levels set in your file, e.g. yoursite.com/store/chmod.php?chmod=0777.

Code: Select all

// your ftp credentials
$ftp_server='ftp.yourwebsite.com';
$ftp_user='your_ftp_username';
$ftp_pass='your_ftp_password';
 
// where is your shopping cart installed? (trailing slash required)
$base = '/public/www/store/';
 
// what files or directories need chmod applied? (trailing slash optional)
$dirs = array(	'image',
		'image/cache',
		'image/data',  
		'system/cache',
		'system/logs',
		'download',
		'config.php',
		'admin/config.php'
             );
 
// default to 0755 setting
if ($_GET['chmod']) {
    $ftp_chmod = $_GET['chmod']; 
} else {
    $ftp_chmod = "0755"; 
}
echo "chmod=".$ftp_chmod.'<br/>';
 
// connect via ftp and apply chmod
$conn_id = ftp_connect("$ftp_server");
ftp_login($conn_id, $ftp_user, $ftp_pass);
foreach( $dirs as $dir ){
    if (ftp_site($conn_id, 'CHMOD '.$ftp_chmod.' '.$base.$dir)) { 
        echo "success "; 
    } else { 
        echo "failed "; 
    }
    echo $base.$dir.'<br/>';
} 
ftp_close($conn_id);
 
echo 'DONE';
Hope this is helpful to someone.

Grant
Last edited by gocreative on Fri Apr 30, 2010 2:28 pm, edited 1 time in total.

User avatar
Active Member

Posts

Joined
Tue Jan 12, 2010 5:46 pm

Post by Qphoria » Mon Apr 26, 2010 4:39 am

Yes this is good code. I use a similar method with my upcoming package installer :)

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by mondy » Thu Apr 29, 2010 5:51 am

b"h

Furiousweebee & Qphoria,

1.) Actually, what is the best CHMOD for the files?
2.) Can you find a way to make this code re-usable from the admin panel ?

Thanks in advance

Mo

New member

Posts

Joined
Tue Nov 11, 2008 8:01 am

Post by gocreative » Thu Apr 29, 2010 7:22 am

This file should be used BEFORE installation, therefore it wouldn't be of much use from the admin panel (unless it was opened up to allow other files/folders to be CHMODed from the admin panel.

User avatar
Active Member

Posts

Joined
Tue Jan 12, 2010 5:46 pm

Post by Qphoria » Thu Apr 29, 2010 8:28 am

I use it for making file mods on the fly in the case where they are not writable. But furious is right, there really is no reason to have something like this be changed all the time. The files are normally fine in their default chmod. only the config.php and admin/config.php files should be changed to 444 or 644 (depending on what your webhost allows) as that will prevent them from being accidentally deleted/overwritten/hacked/etc

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by mondy » Fri Apr 30, 2010 6:14 am

b"h

Thanks for this replay.

Mo

New member

Posts

Joined
Tue Nov 11, 2008 8:01 am
Who is online

Users browsing this forum: No registered users and 56 guests