0

I have a set of files for a custom-made CMS, and now that the client base is actually growing, I need an auto-updater of some sort that will do it via cron job each night perhaps.

Basically it needs to replace all files under /admin (including .php and .js files, no .css files as it refers to the master domain all the time).

I'm wondering what the best way to do this is - my files are not on a public github repository of any sort, so I'll just have to manually ZIP and upload perhaps, or just do it on the server file manager to gzip it?

I just need some guidelines on how to go about this to reduce security issues etc. Is this the best approach? To download a compressed file, and then uncompress it? When uncompressing a file, does it automatically overwrite the existing files without question?

I don't want to use a command-line utility for this, as some of the accounts sit OUTSIDE of my server so I can't really do any copying of files via SSH or anything of the sort.

Thank you for your help.

2 Answers 2

1

You could try to run a cron php script that loops through the target directories on the client's build, creates a hash of its contents, and then compares it to your master copy:

$files = array();
if ($handle = opendir('/path/to/files')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {
            $file_hash = md5(file_get_contents('/path/to/files'.$entry));
            compare_and_get_contents('/path/to/files'.$entry, $file_hash);
        }
    }
    closedir($handle);
}

The compare_and_get_contents() function would look something like:

function compare_and_get_contents($file_path,$hash){
    $get_code = file_get_content('http://mysite.com/compare?path='.urlencode($file_path).'&hash='.$hash);
    if (strlen($get_code)>0){
        file_put_contents($file_path,$get_code);
    }
}

You'd just need to write a page (http://mysite.com/compare) that compared the hash of the client version to the hash of the parent version and prints the code of the parent version if they don't match. You may also want to encrypt the data as it is transferred if that's a concern. Obviously this code would need a bit of revision to work, and there are several potential security and permissions issues, but it may get the job done and it will be less bandwidth intensive than passing the whole thing around as a zip file.

Sign up to request clarification or add additional context in comments.

1 Comment

I ended up doing something like this - to fetch the file from the mother server and then put the zip file in, and then unzip!
1

Using a vcs like git you can create a cron, that will call the cvs every night like

git pull

Its not required, that the repository is public, but the server needs access.

8 Comments

Great idea - however to give the server access, I need a much larger GIT account. I'm hoping for a simpler solution using a PHP file downloader, similar to how Wordpress does it.
@jeffkee Just host the git repository on your own server?
Don't know, what you mean by "GIT account". You just need a system with a harddrive with size of choice and an installed SSH-Server. Thats all git needs.
Doh! Of course. I totally thought of it as a 'github' account, not git. I'm an idiot. Yup great idea.. I just have to install a git or something on my dedicated server I guess. What about using SVN? Same thing?
Don't like SVN ;) But something similar is probably possible. Settings should be similar: One repository in the "middle" (in SVN its probably "the one"), from your dev system you push/commit into, from the server your pull/update (via cron).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.