Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/hopeinstoughton_cdn1/include/ |
Upload File : |
<?php // Cron
// this is run once per hour on cdn3 and cdn4 to make sure these cdns have a complete copy of all media
// when run on cdn1, it will export old mp4/mp3 files to
// /Volumes/Externals/CDN/include
header('Content-type: text/plain');
require_once __DIR__ . '/class.media-source.php';
set_time_limit(0);
// determine server
$x = trim(`/bin/hostname`);
switch($x) {
case 'minimac18.local':
$server = MediaSource::BACKUP1;
break;
case 'stoughton':
$server = MediaSource::CHURCH;
break;
case 'aries':
$server = MediaSource::ARIES; // source server (this one)
ExportOldMedia($server);
die("Done\n");
default:
die('Unable to determine CDN from hostname');
}
// get file list
$url = "https://hopeinstoughton.org/~/cdn-sync?cdn={$server}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$returned_text = curl_exec($ch);
curl_close($ch);
$filelist = json_decode($returned_text);
if (is_array($filelist)) {
foreach($filelist as $fileitem) {
$txt = str_replace('.hopeinstoughton.org', '...', $fileitem->link);
$txt = str_replace('https://', '', $txt);
echo "[{$fileitem->id}, {$fileitem->type}] Processing {$txt}\n";
flush();
SynchronizeItem($fileitem, $server);
}
}
die("\nDone\n");
// assume that all folders have been created
function SynchronizeItem($fileitem, $server) {
// Extract the authorization
$auth = preg_match('~/file/(.*?)/~', $fileitem->link, $match) ? $match[1] : '';
$target = realpath(__DIR__ . '/../' . substr($fileitem->id, 0, 1));
$targetname = $target . '/' . $fileitem->id . '.' . $fileitem->type;
$fs = file_exists($targetname) ? filesize($targetname) : 0;
if ($fs != $fileitem->fs) {
$url = parse_url($fileitem->link);
$elements = explode('/', $url['path']);
$elements = array_map('rawurlencode', $elements);
$url['path'] = implode('/', $elements);
$link = $url['scheme'] . '://' . $url['host'] . $url['path'];
$safe_file = escapeshellarg($targetname);
$safe_url = escapeshellarg($link);
// download using curl external directly to target folder
$command = "curl -f -N -s -o $safe_file $safe_url";
`$command`;
// make sure length is correct (if incorrect, remove it and move onto next)
clearstatcache(TRUE, $targetname);
$fs = file_exists($targetname) ? filesize($targetname) : 0;
if ($fs != $fileitem->fs) {
echo "\nSize error: $targetname\n";
@unlink($targetname);
return FALSE;
}
}
$postRequest = [
'auth' => $auth,
'type' => $fileitem->type,
];
// mark as processed - curl request including: auth, type and $server
$url = "https://hopeinstoughton.org/~/cdn-sync?cdn={$server}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postRequest);
$returned_text = curl_exec($ch);
curl_close($ch);
$result = json_decode($returned_text);
return $result->success;
}
// move some files to make space for new files
function ExportOldMedia($server) {
clearstatcache(TRUE);
// how much free space?
$df = intval(disk_free_space('/') / 1024 / 1024); // in MB
$url = "https://hopeinstoughton.org/~/cdn-sync?cdn={$server}&oldfiles={$df}";
var_dump($url);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$returned_text = curl_exec($ch);
curl_close($ch);
$filelist = json_decode($returned_text);
var_dump($filelist);
// get some of the oldest 'other' files
// if none,
}