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
require_once __DIR__ . '/class.media-source.php';
require_once __DIR__ . '/mp4info/MP4Info.php';
require_once __DIR__ . '/class.mp3id.php';
define('FFMPEG', '/usr/bin/ffmpeg');
define('FFMPEG_MAC', '/Users/video/videos/ffmpeg');
define('TAGGER', '/usr/bin/id3tool'); // mid3v2 did not work
/*
For cdn3, Alcor accesses cdn files as user stoughton,
but https://cdn3.../ access it as user www-data; run on stoughton to fix:
setfacl -R -m d:u:www-data:rwx /var/www/hopeinstoughton_cdn3
setfacl -R -m u:www-data:rwx /var/www/hopeinstoughton_cdn3
*/
$FFMPEG = file_exists(FFMPEG_MAC) ? FFMPEG_MAC : FFMPEG;
$action = isset($_GET['action']) ? trim($_GET['action']) : '';
$query = $_SERVER['REQUEST_URI'];
if (($p = strpos($query, '?')) !== FALSE) {
$query = substr($query, $p + 1);
parse_str($query, $res);
} else {
$res = [];
}
switch($action) {
case 'youtube':
$id = $_GET['id'];
$type = isset($res['type']) ? $res['type'] : 'mt';
command_youtube($id, $type, $FFMPEG);
break;
case 'import':
$payload = $_GET['id'];
$mediasource = new MediaSource;
$param = $mediasource->decodeAuth($payload);
if (!$param->valid) {
header('Content-type: text/plain');
die("Invalid Link");
}
if ($param->expired) {
header('Content-type: text/plain');
die("Expired Link");
}
$src = isset($res['name']) ? $res['name'] : ''; // source basename 'yyyy.mm.dd ac'
$type = isset($res['type']) ? $res['type'] : '';
if ($src != '') {
command_import($param, $src, $type);
}
break;
case 'mp3tags': // set mp3 tags
$payload = $_GET['id'];
$mediasource = new MediaSource;
$param = $mediasource->decodeAuth($payload);
if (!$param->valid) {
header('Content-type: text/plain');
die("Invalid Link");
}
if ($param->expired) {
header('Content-type: text/plain');
die("Expired Link");
}
if ($param->ext != 'tag') {
header('Content-type: text/plain');
die("Not a Valid MP3 Link");
}
$output = command_setMpgTags($param->id, $res);
header('Content-type: application/json');
die(json_encode($output));
case '':
$id = explode('.', $_GET['id']);
$output = command_info($id);
header('Content-type: application/json');
// this will return zero-length string if there are invalid characters
die(json_encode($output));
default:
header('Content-type: text/plain');
var_dump($_GET);
}
function command_setMpgTags($id, $postdata) {
header('Content-type: text/plain');
$filename_source = dirname(__DIR__) . '/' . substr($id, 0, 1) . "/{$id}.mp3";
$dfilename = escapeshellarg($filename_source);
$dartist = escapeshellarg($postdata['artist']);
$dalbum = escapeshellarg($postdata['album']);
$dsong = escapeshellarg($postdata['title']);
$dyear = escapeshellarg($postdata['year']);
$dtrack = escapeshellarg($postdata['track']);
//define('TAGGER', '/usr/bin/mid3v2'); // this worked, but Windows did not pick up the tags, nor did our id3tag class
//$command = TAGGER . " -a $dartist -A $dalbum -t $dsong -y $dyear -T $dtrack $dfilename";
//define('TAGGER', '/usr/bin/id3tool');
$command = TAGGER . " -r $dartist -a $dalbum -t $dsong -y $dyear -c $dtrack $dfilename";
$output = `$command 2>&1`;
return [
'success' => strlen($output) < 1 ? 1: 0,
'output' => $output,
];
}
function command_youtube($id, $type, $FFMPEG) {
$id = str_replace(['/', '..', '\\'], '', $id);
$filename_source = dirname(__DIR__) . '/' . substr($id, 0, 1) . "/{$id}.mp3";
// use ffmpeg + thumbnail to create video
$folder = tempnam(sys_get_temp_dir(), 'mp4');
$filename_temp = $folder . '.mp4';
while (ob_get_level())
ob_end_clean();
if ($type == 'mt') {
$background = 'background-blu.jpg';
} else {
$background = 'background-grn.jpg';
}
$safe_bg = escapeshellarg(__DIR__ . '/' . $background);
$safe_in = escapeshellarg($filename_source);
$command = "$FFMPEG -loop 1 -i $safe_bg -i $safe_in -c:a copy -c:v libx264 -shortest -strict -1 $filename_temp";
$output = `$command 2>&1`;
if (!file_exists($filename_temp) || filesize($filename_temp) < 512) {
header('Content-type: text/plain');
echo "$command\n";
echo $output;
@unlink($filename_temp);
@unlink($folder);
exit;
}
header('Content-type: video/mp4');
header("Content-disposition: attachment; filename=\"{$id}.mp4\"");
readfile($filename_temp);
unlink($filename_temp); // delete temp files
unlink($folder);
}
// designed to only run on cdn2 (hostz)
function command_import($param, $src, $type) {
// copy file to new location
// then redirect back to hopeinstoughton with results
$src = str_replace(['..', '/', '\\'], '', $src);
switch($type) {
case 'ac':
$source = "/mnt/disk2/his/av/current/$src.{$param->ext}";
break;
case 'ex':
$source = "/mnt/disk2/his/av/exhort/video/$src.{$param->ext}";
break;
default:
die('Unknown type specified');
}
if (!file_exists($source)) {
die('Source file does not exist');
}
$tar = $param->id . '.' . $param->ext;
$target = dirname(__DIR__) . '/' . substr($param->id, 0, 1);
@mkdir($target);
$target .= '/' . $tar;
$sig = substr(md5('its-ok:' . $tar), 12, 8);
copy($source, $target);
header('Location: https://hopeinstoughton.org/~/media-class-update/' . $param->id . '/' . $sig);
echo "Copied: $source -> $target\n";
exit;
}
function command_info($ids) {
$output = [];
foreach($ids as $id) {
$id = str_replace(['/', '..', '\\'], '', $id);
_command_info_id($output, $id);
}
return $output;
}
function _command_info_id(&$output, $id) {
$path = dirname(__DIR__) . '/' . substr($id, 0, 1) . '/' . $id;
$files = glob($path . '.*');
foreach($files as $file) {
$elements = pathinfo($file);
$ext = $elements['extension'];
if ($elements['filename'] != $id) {
continue;
}
$fs = filesize($file);
if ($fs > 0) {
$res = [];
switch($ext) {
case 'mp4':
case 'm4a':
$res = fileinfo_mp4($file);
$res = fileinfo_mp4($file);
break;
case 'mp3':
$res = fileinfo_mp3($file);
break;
case 'gif':
case 'png':
case 'jpg':
$res = fileinfo_jpg($file);
break;
case 'vtt':
$res = fileinfo_vtt($file);
break;
case 'xml':
case 'txt':
case 'html':
case 'zip':
$res = fileinfo_null($file);
break;
default:
continue 2;
}
$res['filesize'] = $fs;
// include file hash?
$output[$id][$ext] = $res;
}
}
}
function fileinfo_mp4($file) {
$info = MP4Info::getInfo($file);
$node = [
'duration' => ceil($info->duration),
];
if ($info->hasVideo) {
$wd = ceil($info->video->width);
$node['framesize'] = $wd . 'x' . $info->video->height;
}
return $node;
}
// utf8 tag?
function _tag($txt) {
if (substr($txt, 0, 2) == "\xff\xfe") {
$txt = rtrim(iconv('UTF-16LE', 'UTF-8', $txt), "\0");
}
return $txt;
}
function fileinfo_mp3($file) {
$mp3id = new mp3id3($file);
$node = [
'duration' => floor($mp3id->milliseconds / 1000), // this is inaccurate
'bitrate' => $mp3id->bitrate,
'frequency' => $mp3id->frequency,
'track' => $mp3id->track,
// channels
];
if ($mp3id->v2tag) {
if (isset($mp3id->v2['TALB'])) $node['topic'] = _tag($mp3id->v2['TALB']);
if (isset($mp3id->v2['TIT2'])) $node['title'] = _tag($mp3id->v2['TIT2']);
if (isset($mp3id->v2['TYER'])) $node['year'] = _tag($mp3id->v2['TYER']);
if (isset($mp3id->v2['TPE1'])) $node['speaker'] = _tag($mp3id->v2['TPE1']);
if (isset($mp3id->v2['TRCK'])) $node['track'] = _tag($mp3id->v2['TRCK']);
} elseif ($mp3id->v1tag) {
$node['topic'] = rtrim($mp3id->v1['album'], "\0");
$node['title'] = rtrim($mp3id->v1['title'], "\0");
$node['year'] = rtrim($mp3id->v1['year'], "\0");
$node['speaker'] = rtrim($mp3id->v1['artist'], "\0");
}
return $node;
}
function fileinfo_jpg($file) {
$info = getimagesize($file);
$node = [
'framesize' => $info[0] . 'x' . $info[1],
];
return $node;
}
function fileinfo_vtt($file) {
return [];
}
function fileinfo_null($file) {
return [];
}