Reputation: 5238
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.
Upvotes: 0
Views: 279
Reputation: 14489
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.
Upvotes: 1
Reputation: 132061
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.
Upvotes: 1