Compare commits
No commits in common. "main" and "main" have entirely different histories.
690
cms/assets.php
690
cms/assets.php
@ -5,439 +5,347 @@
|
|||||||
|
|
||||||
require "/home/hpr/php/include.php";
|
require "/home/hpr/php/include.php";
|
||||||
|
|
||||||
date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
// curl --netrc-file $HOME/.netrc --verbose --request POST https://hub.hackerpublicradio.org/cms/assets.php --data-ascii @assets.json --header "Content-Type: application/json"
|
// curl --netrc-file $HOME/.netrc --verbose --request POST https://hub.hackerpublicradio.org/cms/assets.php --data-ascii @assets.json --header "Content-Type: application/json"
|
||||||
|
|
||||||
//Make sure that it is a POST request.
|
//Make sure that it is a POST request.
|
||||||
if ( strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0 && strcasecmp($_SERVER['REQUEST_METHOD'], 'GET') != 0 ){
|
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
|
||||||
throw new Exception('Request method must be POST!');
|
throw new Exception('Request method must be POST!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( strcasecmp($_SERVER['REQUEST_METHOD'], 'GET') == 0 ){
|
//Make sure that the content type of the POST request has been set to application/json
|
||||||
executeGET();
|
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
|
||||||
|
if(strcasecmp($contentType, 'application/json') != 0){
|
||||||
|
throw new Exception('Content type must be: application/json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Receive the RAW post data.
|
||||||
|
$content = trim(file_get_contents("php://input"));
|
||||||
|
|
||||||
if ( strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') == 0 ){
|
//Attempt to decode the incoming RAW post data from JSON.
|
||||||
executePOST();
|
$decoded = json_decode($content, true);
|
||||||
|
|
||||||
|
//If json_decode failed, the JSON is invalid.
|
||||||
|
if(!is_array($decoded)){
|
||||||
|
logextra( "Received content contained invalid JSON!" );
|
||||||
|
naughty( "0e0e69415750c96f19d234f83270fdea" );
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeGET() {
|
foreach($decoded['assets'] as $asset) {
|
||||||
global $connection;
|
|
||||||
|
|
||||||
$asset_array = array ();
|
// Check episode_id
|
||||||
|
|
||||||
|
if ( isset( $asset['episode_id'] ) ) {
|
||||||
|
|
||||||
|
$provided_episode_id = $asset['episode_id'];
|
||||||
|
|
||||||
|
$provided_episode_id = filter_var($provided_episode_id, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
||||||
|
|
||||||
if (isset($_GET['id'])) {
|
|
||||||
$id = $_GET['id'];
|
|
||||||
$result = mysqli_query($connection, 'SELECT MAX(id) FROM eps;');
|
$result = mysqli_query($connection, 'SELECT MAX(id) FROM eps;');
|
||||||
if (!isset($result)) {
|
if (!isset($result)) {
|
||||||
logextra( "unable to execute SELECT MAX(id) FROM eps;" );
|
logextra( "Can't connect to db" );
|
||||||
problem( "2f1497d7734f5dc7ce04e1a343cbd4cb" );
|
naughty( "4c85d7b9e1d2eb741cdb60fd9f97b852" );
|
||||||
die('Could not query:' . mysqli_error());
|
die('Could not query:' . mysqli_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
$maxhost_array = mysqli_fetch_row( $result );
|
$maxhost_array = mysqli_fetch_row( $result );
|
||||||
$maxhost = $maxhost_array[0];
|
$maxhost = $maxhost_array[0];
|
||||||
$num_get_args=0;
|
$num_get_args=0;
|
||||||
foreach($_GET as $k => $v) {
|
foreach($_GET as $k => $v) {
|
||||||
++$num_get_args;
|
++$num_get_args;
|
||||||
}
|
}
|
||||||
if ( (strval(intval($id)) != strval($id)) OR ( intval($id) <= 0 ) OR ( intval($id) > $maxhost ) OR ( $num_get_args > 1 ) ){
|
|
||||||
logextra( "The id \"$id\" is not valid." );
|
if (strval(intval($provided_episode_id)) != strval($provided_episode_id)) {
|
||||||
problem( "6b070390632e12a962338d2e31464f9f" );
|
logextra( "ID is not a valid number because strval(intval($provided_episode_id)) != strval($provided_episode_id))" );
|
||||||
exit;
|
naughty( "b2babb5bebde79e08ddf3c780c56615d" );
|
||||||
}
|
}
|
||||||
$query = "SELECT id FROM eps WHERE id = '$id'";
|
|
||||||
|
if ( intval($provided_episode_id) <= 0 ){
|
||||||
|
logextra( "ID is not a valid number because intval($provided_episode_id) <= 0" );
|
||||||
|
naughty( "b245522d0582e61612e8b7dcdb0e0f4c" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( intval($provided_episode_id) > $maxhost ){
|
||||||
|
logextra( "ID is not a valid number because intval($provided_episode_id) > $maxhost" );
|
||||||
|
naughty( "c6feadcf0b6eda204cbfba6824aa2c7a" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $num_get_args > 1 ){
|
||||||
|
logextra( "ID is not a valid number because \$num_get_args: $num_get_args > 1" );
|
||||||
|
naughty( "ba22518c5ced567cd0b855206985f036" );
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "SELECT id FROM eps WHERE id = '$provided_episode_id'";
|
||||||
$result = @mysqli_query($connection, $query);
|
$result = @mysqli_query($connection, $query);
|
||||||
if($result === FALSE) {
|
if($result === FALSE) {
|
||||||
logextra( "Cud not run SELECT id FROM eps WHERE id = $id" );
|
logextra( "No result returned for this query \"SELECT id FROM eps WHERE id = '$provided_episode_id'\"" );
|
||||||
problem( "568dff032398640456d749135358a88b" );
|
naughty( "fa0778750519cb140b4076c844b3ec78" );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$db = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
$db = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
||||||
if ( empty($db["id"]) ) {
|
if ( empty($db["id"]) ) {
|
||||||
logextra( "The \"$id\" is not in the database" );
|
logextra( "No result returned for this id:\"${id}\"" );
|
||||||
http_response_code(404);
|
naughty( "1e09df9f3896da3e80507ea4538a4aca" );
|
||||||
die();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$ep_retrieve = "SELECT episode_id, filename, extension, `size`, sha1sum, mime_type
|
$episode_id = $provided_episode_id;
|
||||||
FROM assets
|
logextra( "Found Valid \$episode_id: $episode_id" );
|
||||||
WHERE episode_id = '$id'
|
|
||||||
ORDER BY episode_id ASC;";
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$ep_retrieve = "SELECT episode_id, filename, extension, `size`, sha1sum, mime_type
|
logextra( "No episode_id provided" );
|
||||||
FROM assets
|
naughty( "eae535cc88680a5bdab4e7bb4e54d83e" );
|
||||||
ORDER BY episode_id ASC;";
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
|
// Check filename
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$episode_id = $row['episode_id'];
|
if ( isset( $asset['filename'] ) ) {
|
||||||
$filename = $row['filename'];
|
$provided_filename = $asset['filename'];
|
||||||
$extension = $row['extension'];
|
|
||||||
$size = $row['size'];
|
$provided_filename = filter_var($provided_filename, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
||||||
$sha1sum = $row['sha1sum'];
|
|
||||||
$mime_type = $row['mime_type'];
|
$this_dirname = dirname("$provided_filename", 2);
|
||||||
$asset_array["hpr$episode_id"][$filename] = array (
|
if ( empty($this_dirname) ) {
|
||||||
"episode_id" => $episode_id,
|
logextra( "no dirname" );
|
||||||
"filename" => $filename,
|
naughty("b23ed28377cf4cf36cbf01931377ddc7");
|
||||||
"extension" => $extension,
|
|
||||||
"size" => $size,
|
|
||||||
"sha1sum" => $sha1sum,
|
|
||||||
"mime_type" => $mime_type
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( $this_dirname === "/" ) {
|
||||||
|
logextra( "dirname is root" );
|
||||||
|
naughty("b90228a9c4d008eab57304bd36b75a08");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this_basename = basename($provided_filename);
|
||||||
|
if ( empty($this_basename) ) {
|
||||||
|
logextra( "Cound not extract basename from filename: $provided_filename" );
|
||||||
|
naughty("44b5022e3a32605c6b0afdf7699ed153");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $this_basename !== $provided_filename ) {
|
||||||
|
logextra( "filename: $provided_filename does not match name:$this_basename" );
|
||||||
|
naughty("832f0283544692bd6691e3802e67099c");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this_ext = pathinfo($provided_filename, PATHINFO_EXTENSION);
|
||||||
|
if ( empty($this_ext) ) {
|
||||||
|
logextra( "The extension for \"$provided_filename\" is empty" );
|
||||||
|
naughty("63166ba6572ac51b47804d9787152903");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this_prefix =pathinfo($provided_filename, PATHINFO_FILENAME);
|
||||||
|
if ( empty($this_prefix) ) {
|
||||||
|
logextra( "The prefix for \"$provided_filename\" is empty" );
|
||||||
|
naughty("9ad9a6b9e47e6960ff30442c3c808609");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( strlen($provided_filename) < 5 ) {
|
||||||
|
logextra( "The length of \"$provided_filename\" is less than 5" );
|
||||||
|
naughty("e131ae01530f4098c299aaca0a6ee8e1");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( strlen($provided_filename) > 60 ) {
|
||||||
|
logextra( "The length of \"$provided_filename\" is greater than 60" );
|
||||||
|
naughty("d90560ef4cac05954c93523d529ed20e");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array( $this_ext, $allowed_extensions, true )) {
|
||||||
|
logextra( "This extension $this_ext, is not in the list of allowed_extensions" );
|
||||||
|
naughty("dd98c84719083fb80fecbd0405504038 $this_ext");
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = $provided_filename;
|
||||||
|
logextra( "Found Valid \$filename: $filename" );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logextra( "No filename provided" );
|
||||||
|
naughty( "1edd3bcd2a16c152f0a97106372862f9" );
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
// Check extension
|
||||||
header("Content-disposition: inline; filename=hpr_stats.json");
|
|
||||||
|
|
||||||
echo json_encode($asset_array);
|
if ( isset( $asset['extension'] ) ) {
|
||||||
|
$provided_extension = $asset['extension'];
|
||||||
|
|
||||||
|
$provided_extension = filter_var($provided_extension, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
||||||
|
if ( $provided_extension !== $this_ext ) {
|
||||||
|
logextra( "The extensions provided \"$provided_extension\" and in the filename dont match \"$provided_filename\"" );
|
||||||
|
naughty("ed58e1493aa56e0eaf50362cc6f64425");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array( $provided_extension, $allowed_extensions, true )) {
|
||||||
|
logextra( "This extension $this_ext, is not in the list of allowed_extensions" );
|
||||||
|
naughty("dc406b9151871e38ac69c2bf44fa74da");
|
||||||
|
}
|
||||||
|
$extension = $provided_extension;
|
||||||
|
logextra( "Found Valid \$extension: $extension" );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logextra( "No extension provided" );
|
||||||
|
naughty( "04b53ecd0ffa3faa68db1e541554903d" );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check size
|
||||||
|
|
||||||
|
if ( isset( $asset['size'] ) ) {
|
||||||
|
|
||||||
|
$provided_size = $asset['size'];
|
||||||
|
|
||||||
|
$provided_size = filter_var($provided_size, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
||||||
|
|
||||||
|
if (strval(intval($provided_size)) != strval($provided_size)) {
|
||||||
|
logextra( "The provided size is not a valid number because strval(intval($provided_size)) != strval($provided_size))" );
|
||||||
|
naughty( "cc349935f0d80b40d5593b0fd54eaf58" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( intval($provided_size) <= 0 ){
|
||||||
|
logextra( "The provided size is not a valid number because intval($provided_size) <= 0" );
|
||||||
|
naughty( "91c54771bcf68f974c9aa8959f953dd8" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( intval($provided_size) > 3000000000 ){
|
||||||
|
logextra( "The provided size is not a valid number because it's a lot larger than any show so far" );
|
||||||
|
naughty( "8c085ec045b062e3a864e6fc22fceee4" );
|
||||||
|
}
|
||||||
|
|
||||||
|
$size = $provided_size;
|
||||||
|
logextra( "Found Valid \$size: $size" );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logextra( "No size provided" );
|
||||||
|
naughty( "a6d661c483c6d62d4df1df88a64118ce" );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check sha1sum
|
||||||
|
|
||||||
|
if ( isset( $asset['sha1sum'] ) ) {
|
||||||
|
|
||||||
|
$provided_sha1sum = $asset['sha1sum'];
|
||||||
|
|
||||||
|
$provided_sha1sum = filter_var($provided_sha1sum, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
||||||
|
if ( !preg_match('/^[0-9a-f]{40}$/i', $provided_sha1sum) ) {
|
||||||
|
logextra( "The format of the sha1sum is invalid $provided_sha1sum" );
|
||||||
|
naughty( "e30c8db8a7e07ba69ef18f957f3e8843" );
|
||||||
|
}
|
||||||
|
|
||||||
|
$sha1sum = $provided_sha1sum;
|
||||||
|
logextra( "Found Valid \$sha1sum: $sha1sum" );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logextra( "No sha1sum provided" );
|
||||||
|
naughty( "cd3d303dbefec08016d567080116ef77" );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check mime_type
|
||||||
|
|
||||||
|
if ( isset( $asset['mime_type'] ) ) {
|
||||||
|
|
||||||
|
$provided_mime_type = $asset['mime_type'];
|
||||||
|
|
||||||
|
$provided_mime_type = filter_var($provided_mime_type, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
||||||
|
if ( !preg_match('/^[\w-]+\/[\w-]+(?:;\s*[\w-]+=[\w-]+)*$/i', $provided_mime_type) ) {
|
||||||
|
logextra( "The format of the mime_type is invalid \"$provided_mime_type\"" );
|
||||||
|
naughty( "b36041a7d959730a9a541404db3b5025" );
|
||||||
|
}
|
||||||
|
|
||||||
|
list($content_type, $charset_type) = explode('; charset=', $provided_mime_type);
|
||||||
|
|
||||||
|
if ( !isset( $content_type ) ) {
|
||||||
|
logextra( "Can't find content_type in \"$provided_mime_type\"" );
|
||||||
|
naughty( "c28ac580f5281ab2d97cbf052c92a25c" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $content_type ) ) {
|
||||||
|
logextra( "Empty content_type in \"$provided_mime_type\"" );
|
||||||
|
naughty( "fcec6e4039bc60daede3434e24c97a9f" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array( $content_type, $allowed_content_type, true )) {
|
||||||
|
logextra( "This content_type \"$content_type\", is not in the list of allowed_extensions" );
|
||||||
|
naughty("4f29dcd2b3ef7efc5c4bc65be7a787ca");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !isset( $charset_type ) ) {
|
||||||
|
logextra( "Can't find charset_type in \"$provided_mime_type\"" );
|
||||||
|
naughty( "" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $charset_type ) ) {
|
||||||
|
logextra( "Empty charset_type in \"$provided_mime_type\"" );
|
||||||
|
naughty( "" );
|
||||||
|
}
|
||||||
|
|
||||||
|
$allowed_charset_type = array( "binary", "us-ascii", "utf-8");
|
||||||
|
if (!in_array( $charset_type, $allowed_charset_type, true )) {
|
||||||
|
logextra( "This charset_type \"$charset_type\", is not in the list of allowed_extensions" );
|
||||||
|
naughty("");
|
||||||
|
}
|
||||||
|
|
||||||
|
$mime_type = $provided_mime_type;
|
||||||
|
logextra( "Found Valid \$mime_type: $mime_type" );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logextra( "No mime_type provided" );
|
||||||
|
naughty( "0c85eb982665a4978fea8f85611fbe88" );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check file_type
|
||||||
|
|
||||||
|
if ( isset( $asset['file_type'] ) ) {
|
||||||
|
$provided_file_type = $asset['file_type'];
|
||||||
|
|
||||||
|
$provided_file_type = filter_var($provided_file_type, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
||||||
|
|
||||||
|
if ( strlen($provided_file_type) < 5 ) {
|
||||||
|
logextra( "The length of \"$provided_file_type\" is less than 5" );
|
||||||
|
naughty("60839aaddc82e0fbe4f5da269c361cf6");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( strlen($provided_file_type) > 140 ) {
|
||||||
|
logextra( "The length of \"$provided_file_type\" is greater than 140" );
|
||||||
|
naughty("cafbb1b0c9955b92303fe34102890fa3");
|
||||||
|
}
|
||||||
|
|
||||||
|
$file_type = $provided_file_type;
|
||||||
|
logextra( "Found Valid \$file_type: $file_type" );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logextra( "No file_type provided" );
|
||||||
|
naughty( "a1b6a02d68533f9749da16164cbe704e" );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write values to db
|
||||||
|
|
||||||
|
//$episode_id is a number
|
||||||
|
$filename = mysqli_real_escape_string( $connection, $filename );
|
||||||
|
$extension = mysqli_real_escape_string( $connection, $extension );
|
||||||
|
//$size is a number
|
||||||
|
$sha1sum = mysqli_real_escape_string( $connection, $sha1sum );
|
||||||
|
$mime_type = mysqli_real_escape_string( $connection, $mime_type );
|
||||||
|
$file_type = mysqli_real_escape_string( $connection, $file_type );
|
||||||
|
|
||||||
|
$query_replace = "REPLACE INTO assets VALUES ('$episode_id','{$filename}','{$extension}','$size','{$sha1sum}','{$mime_type}','{$file_type}')";
|
||||||
|
|
||||||
|
$result = mysqli_query($connection, $query_replace );
|
||||||
|
if(!$result) {
|
||||||
|
problem("ERROR: DB problem - The asset for \"$episode_id\" with filename of \"$filename\" was not added to the eps db.");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
logextra( "mysql_query.result: \"$result\"\n" );
|
||||||
|
}
|
||||||
|
if (mysqli_errno( $connection )) {
|
||||||
|
$error = "MySQL error ".mysqli_errno( $connection ).": ".mysqli_error()."\n";
|
||||||
|
problem("ERROR: MySQL error- The asset for \"$episode_id\" with filename of \"$filename\" was not added to the eps db.\n$error");
|
||||||
|
}
|
||||||
|
|
||||||
|
logextra( "Finished ." );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
http_response_code(200);
|
||||||
function executePOST() {
|
|
||||||
global $connection, $allowed_extensions, $allowed_content_type;
|
|
||||||
|
|
||||||
//Make sure that the content type of the POST request has been set to application/json
|
|
||||||
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
|
|
||||||
if(strcasecmp($contentType, 'application/json') != 0){
|
|
||||||
throw new Exception('Content type must be: application/json');
|
|
||||||
}
|
|
||||||
|
|
||||||
//Receive the RAW post data.
|
|
||||||
$content = trim(file_get_contents("php://input"));
|
|
||||||
|
|
||||||
//Attempt to decode the incoming RAW post data from JSON.
|
|
||||||
$decoded = json_decode($content, true);
|
|
||||||
|
|
||||||
//If json_decode failed, the JSON is invalid.
|
|
||||||
if(!is_array($decoded)){
|
|
||||||
logextra( "Received content contained invalid JSON!" );
|
|
||||||
problem( "0e0e69415750c96f19d234f83270fdea" );
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($decoded['assets'] as $asset) {
|
|
||||||
|
|
||||||
// Check episode_id
|
|
||||||
|
|
||||||
if ( isset( $asset['episode_id'] ) ) {
|
|
||||||
|
|
||||||
$provided_episode_id = $asset['episode_id'];
|
|
||||||
|
|
||||||
$provided_episode_id = filter_var($provided_episode_id, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
|
||||||
|
|
||||||
$result = mysqli_query($connection, 'SELECT MAX(id) FROM eps;');
|
|
||||||
if (!isset($result)) {
|
|
||||||
logextra( "Can't connect to db" );
|
|
||||||
problem( "4c85d7b9e1d2eb741cdb60fd9f97b852" );
|
|
||||||
die('Could not query:' . mysqli_error());
|
|
||||||
}
|
|
||||||
|
|
||||||
$maxhost_array = mysqli_fetch_row( $result );
|
|
||||||
$maxhost = $maxhost_array[0];
|
|
||||||
$num_get_args=0;
|
|
||||||
foreach($_GET as $k => $v) {
|
|
||||||
++$num_get_args;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strval(intval($provided_episode_id)) != strval($provided_episode_id)) {
|
|
||||||
logextra( "ID is not a valid number because strval(intval($provided_episode_id)) != strval($provided_episode_id))" );
|
|
||||||
problem( "b2babb5bebde79e08ddf3c780c56615d" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( intval($provided_episode_id) <= 0 ){
|
|
||||||
logextra( "ID is not a valid number because intval($provided_episode_id) <= 0" );
|
|
||||||
problem( "b245522d0582e61612e8b7dcdb0e0f4c" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( intval($provided_episode_id) > $maxhost ){
|
|
||||||
logextra( "ID is not a valid number because intval($provided_episode_id) > $maxhost" );
|
|
||||||
problem( "c6feadcf0b6eda204cbfba6824aa2c7a" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $num_get_args > 1 ){
|
|
||||||
logextra( "ID is not a valid number because \$num_get_args: $num_get_args > 1" );
|
|
||||||
problem( "ba22518c5ced567cd0b855206985f036" );
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = "SELECT id FROM eps WHERE id = '$provided_episode_id'";
|
|
||||||
$result = @mysqli_query($connection, $query);
|
|
||||||
if($result === FALSE) {
|
|
||||||
logextra( "No result returned for this query \"SELECT id FROM eps WHERE id = '$provided_episode_id'\"" );
|
|
||||||
problem( "fa0778750519cb140b4076c844b3ec78" );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$db = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
||||||
if ( empty($db["id"]) ) {
|
|
||||||
logextra( "No result returned for this id:\"${id}\"" );
|
|
||||||
problem( "1e09df9f3896da3e80507ea4538a4aca" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$episode_id = $provided_episode_id;
|
|
||||||
logextra( "Found Valid \$episode_id: $episode_id" );
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logextra( "No episode_id provided" );
|
|
||||||
problem( "eae535cc88680a5bdab4e7bb4e54d83e" );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check filename
|
|
||||||
|
|
||||||
if ( isset( $asset['filename'] ) ) {
|
|
||||||
$provided_filename = $asset['filename'];
|
|
||||||
|
|
||||||
$provided_filename = filter_var($provided_filename, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
|
||||||
|
|
||||||
$this_dirname = dirname("$provided_filename", 2);
|
|
||||||
if ( empty($this_dirname) ) {
|
|
||||||
logextra( "no dirname" );
|
|
||||||
problem("b23ed28377cf4cf36cbf01931377ddc7");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $this_dirname === "/" ) {
|
|
||||||
logextra( "dirname is root" );
|
|
||||||
problem("b90228a9c4d008eab57304bd36b75a08");
|
|
||||||
}
|
|
||||||
|
|
||||||
$this_basename = basename($provided_filename);
|
|
||||||
if ( empty($this_basename) ) {
|
|
||||||
logextra( "Cound not extract basename from filename: $provided_filename" );
|
|
||||||
problem("44b5022e3a32605c6b0afdf7699ed153");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $this_basename !== $provided_filename ) {
|
|
||||||
logextra( "filename: $provided_filename does not match name:$this_basename" );
|
|
||||||
problem("832f0283544692bd6691e3802e67099c");
|
|
||||||
}
|
|
||||||
|
|
||||||
$this_ext = pathinfo($provided_filename, PATHINFO_EXTENSION);
|
|
||||||
if ( empty($this_ext) ) {
|
|
||||||
logextra( "The extension for \"$provided_filename\" is empty" );
|
|
||||||
problem("63166ba6572ac51b47804d9787152903");
|
|
||||||
}
|
|
||||||
|
|
||||||
$this_prefix =pathinfo($provided_filename, PATHINFO_FILENAME);
|
|
||||||
if ( empty($this_prefix) ) {
|
|
||||||
logextra( "The prefix for \"$provided_filename\" is empty" );
|
|
||||||
problem("9ad9a6b9e47e6960ff30442c3c808609");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( strlen($provided_filename) < 5 ) {
|
|
||||||
logextra( "The length of \"$provided_filename\" is less than 5" );
|
|
||||||
problem("e131ae01530f4098c299aaca0a6ee8e1");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( strlen($provided_filename) > 60 ) {
|
|
||||||
logextra( "The length of \"$provided_filename\" is greater than 60" );
|
|
||||||
problem("d90560ef4cac05954c93523d529ed20e");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array( $this_ext, $allowed_extensions, true )) {
|
|
||||||
logextra( "This extension $this_ext, is not in the list of allowed_extensions" );
|
|
||||||
problem("dd98c84719083fb80fecbd0405504038 $this_ext");
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename = $provided_filename;
|
|
||||||
logextra( "Found Valid \$filename: $filename" );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logextra( "No filename provided" );
|
|
||||||
problem( "1edd3bcd2a16c152f0a97106372862f9" );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check extension
|
|
||||||
|
|
||||||
if ( isset( $asset['extension'] ) ) {
|
|
||||||
$provided_extension = $asset['extension'];
|
|
||||||
|
|
||||||
$provided_extension = filter_var($provided_extension, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
|
||||||
if ( $provided_extension !== $this_ext ) {
|
|
||||||
logextra( "The extensions provided \"$provided_extension\" and in the filename dont match \"$provided_filename\"" );
|
|
||||||
problem("ed58e1493aa56e0eaf50362cc6f64425");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array( $provided_extension, $allowed_extensions, true )) {
|
|
||||||
logextra( "This extension $this_ext, is not in the list of allowed_extensions" );
|
|
||||||
problem("dc406b9151871e38ac69c2bf44fa74da");
|
|
||||||
}
|
|
||||||
$extension = $provided_extension;
|
|
||||||
logextra( "Found Valid \$extension: $extension" );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logextra( "No extension provided" );
|
|
||||||
problem( "04b53ecd0ffa3faa68db1e541554903d" );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check size
|
|
||||||
|
|
||||||
if ( isset( $asset['size'] ) ) {
|
|
||||||
|
|
||||||
$provided_size = $asset['size'];
|
|
||||||
|
|
||||||
$provided_size = filter_var($provided_size, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
|
||||||
|
|
||||||
if (strval(intval($provided_size)) != strval($provided_size)) {
|
|
||||||
logextra( "The provided size is not a valid number because strval(intval($provided_size)) != strval($provided_size))" );
|
|
||||||
problem( "cc349935f0d80b40d5593b0fd54eaf58" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( intval($provided_size) <= 0 ){
|
|
||||||
logextra( "The provided size is not a valid number because intval($provided_size) <= 0" );
|
|
||||||
problem( "91c54771bcf68f974c9aa8959f953dd8" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( intval($provided_size) > 3000000000 ){
|
|
||||||
logextra( "The provided size is not a valid number because it's a lot larger than any show so far" );
|
|
||||||
problem( "8c085ec045b062e3a864e6fc22fceee4" );
|
|
||||||
}
|
|
||||||
|
|
||||||
$size = $provided_size;
|
|
||||||
logextra( "Found Valid \$size: $size" );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logextra( "No size provided" );
|
|
||||||
problem( "a6d661c483c6d62d4df1df88a64118ce" );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check sha1sum
|
|
||||||
|
|
||||||
if ( isset( $asset['sha1sum'] ) ) {
|
|
||||||
|
|
||||||
$provided_sha1sum = $asset['sha1sum'];
|
|
||||||
|
|
||||||
$provided_sha1sum = filter_var($provided_sha1sum, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
|
||||||
if ( !preg_match('/^[0-9a-f]{40}$/i', $provided_sha1sum) ) {
|
|
||||||
logextra( "The format of the sha1sum is invalid $provided_sha1sum" );
|
|
||||||
problem( "e30c8db8a7e07ba69ef18f957f3e8843" );
|
|
||||||
}
|
|
||||||
|
|
||||||
$sha1sum = $provided_sha1sum;
|
|
||||||
logextra( "Found Valid \$sha1sum: $sha1sum" );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logextra( "No sha1sum provided" );
|
|
||||||
problem( "cd3d303dbefec08016d567080116ef77" );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check mime_type
|
|
||||||
|
|
||||||
if ( isset( $asset['mime_type'] ) ) {
|
|
||||||
|
|
||||||
$provided_mime_type = $asset['mime_type'];
|
|
||||||
|
|
||||||
$provided_mime_type = filter_var($provided_mime_type, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
|
||||||
if ( !preg_match('/^[\w-]+\/[\w-]+(?:;\s*[\w-]+=[\w-]+)*$/i', $provided_mime_type) ) {
|
|
||||||
logextra( "The format of the mime_type is invalid \"$provided_mime_type\"" );
|
|
||||||
problem( "b36041a7d959730a9a541404db3b5025" );
|
|
||||||
}
|
|
||||||
|
|
||||||
list($content_type, $charset_type) = explode('; charset=', $provided_mime_type);
|
|
||||||
|
|
||||||
if ( !isset( $content_type ) ) {
|
|
||||||
logextra( "Can't find content_type in \"$provided_mime_type\"" );
|
|
||||||
problem( "c28ac580f5281ab2d97cbf052c92a25c" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( empty( $content_type ) ) {
|
|
||||||
logextra( "Empty content_type in \"$provided_mime_type\"" );
|
|
||||||
problem( "fcec6e4039bc60daede3434e24c97a9f" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array( $content_type, $allowed_content_type, true )) {
|
|
||||||
logextra( "This content_type \"$content_type\", is not in the list of allowed_extensions" );
|
|
||||||
problem("4f29dcd2b3ef7efc5c4bc65be7a787ca");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !isset( $charset_type ) ) {
|
|
||||||
logextra( "Can't find charset_type in \"$provided_mime_type\"" );
|
|
||||||
problem( "" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( empty( $charset_type ) ) {
|
|
||||||
logextra( "Empty charset_type in \"$provided_mime_type\"" );
|
|
||||||
problem( "" );
|
|
||||||
}
|
|
||||||
|
|
||||||
$allowed_charset_type = array( "binary", "us-ascii", "utf-8");
|
|
||||||
if (!in_array( $charset_type, $allowed_charset_type, true )) {
|
|
||||||
logextra( "This charset_type \"$charset_type\", is not in the list of allowed_extensions" );
|
|
||||||
problem("");
|
|
||||||
}
|
|
||||||
|
|
||||||
$mime_type = $provided_mime_type;
|
|
||||||
logextra( "Found Valid \$mime_type: $mime_type" );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logextra( "No mime_type provided" );
|
|
||||||
problem( "0c85eb982665a4978fea8f85611fbe88" );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check file_type
|
|
||||||
|
|
||||||
if ( isset( $asset['file_type'] ) ) {
|
|
||||||
$provided_file_type = $asset['file_type'];
|
|
||||||
|
|
||||||
$provided_file_type = filter_var($provided_file_type, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
|
|
||||||
|
|
||||||
if ( strlen($provided_file_type) < 5 ) {
|
|
||||||
logextra( "The length of \"$provided_file_type\" is less than 5" );
|
|
||||||
problem("60839aaddc82e0fbe4f5da269c361cf6");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( strlen($provided_file_type) > 140 ) {
|
|
||||||
logextra( "The length of \"$provided_file_type\" is greater than 140" );
|
|
||||||
problem("cafbb1b0c9955b92303fe34102890fa3");
|
|
||||||
}
|
|
||||||
|
|
||||||
$file_type = $provided_file_type;
|
|
||||||
logextra( "Found Valid \$file_type: $file_type" );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logextra( "No file_type provided" );
|
|
||||||
problem( "a1b6a02d68533f9749da16164cbe704e" );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write values to db
|
|
||||||
|
|
||||||
//$episode_id is a number
|
|
||||||
$filename = mysqli_real_escape_string( $connection, $filename );
|
|
||||||
$extension = mysqli_real_escape_string( $connection, $extension );
|
|
||||||
//$size is a number
|
|
||||||
$sha1sum = mysqli_real_escape_string( $connection, $sha1sum );
|
|
||||||
$mime_type = mysqli_real_escape_string( $connection, $mime_type );
|
|
||||||
$file_type = mysqli_real_escape_string( $connection, $file_type );
|
|
||||||
|
|
||||||
$query_replace = "REPLACE INTO assets VALUES ('$episode_id','{$filename}','{$extension}','$size','{$sha1sum}','{$mime_type}','{$file_type}')";
|
|
||||||
|
|
||||||
$result = mysqli_query($connection, $query_replace );
|
|
||||||
if(!$result) {
|
|
||||||
problem("ERROR: DB problem - The asset for \"$episode_id\" with filename of \"$filename\" was not added to the eps db.");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
logextra( "mysql_query.result: \"$result\"\n" );
|
|
||||||
}
|
|
||||||
if (mysqli_errno( $connection )) {
|
|
||||||
$error = "MySQL error ".mysqli_errno( $connection ).": ".mysqli_error()."\n";
|
|
||||||
problem("ERROR: MySQL error- The asset for \"$episode_id\" with filename of \"$filename\" was not added to the eps db.\n$error");
|
|
||||||
}
|
|
||||||
|
|
||||||
logextra( "Finished ." );
|
|
||||||
}
|
|
||||||
|
|
||||||
http_response_code(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
78
cms/say.php
78
cms/say.php
@ -1,14 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
require "/home/hpr/php/include.php";
|
require "/home/hpr/php/include.php";
|
||||||
|
|
||||||
date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
if (isset($_GET['id'])) {
|
if (isset($_GET['id'])) {
|
||||||
$id = $_GET['id'];
|
$id = $_GET['id'];
|
||||||
$result = mysqli_query($connection, 'SELECT MAX(id) FROM eps;');
|
$result = mysqli_query($connection, 'SELECT MAX(id) FROM eps;');
|
||||||
if (!isset($result)) {
|
if (!isset($result)) {
|
||||||
problem( "45f606ad99fe4fca7430b7b5bba1c681" );
|
die('Could not query:' . mysqli_error());
|
||||||
die('Could not query:' . mysqli_error());
|
|
||||||
}
|
}
|
||||||
$maxhost_array = mysqli_fetch_row( $result );
|
$maxhost_array = mysqli_fetch_row( $result );
|
||||||
$maxhost = $maxhost_array[0];
|
$maxhost = $maxhost_array[0];
|
||||||
@ -17,25 +14,26 @@ if (isset($_GET['id'])) {
|
|||||||
++$num_get_args;
|
++$num_get_args;
|
||||||
}
|
}
|
||||||
if ( (strval(intval($id)) != strval($id)) OR ( intval($id) <= 0 ) OR ( intval($id) > $maxhost ) OR ( $num_get_args > 1 ) ){
|
if ( (strval(intval($id)) != strval($id)) OR ( intval($id) <= 0 ) OR ( intval($id) > $maxhost ) OR ( $num_get_args > 1 ) ){
|
||||||
problem( "ea860134910fecd136229e45262709d7" );
|
exit;
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
$query = "SELECT id FROM eps WHERE id = '$id'";
|
$query = "SELECT id FROM eps WHERE id = '$id'";
|
||||||
$result = @mysqli_query($connection, $query);
|
$result = @mysqli_query($connection, $query);
|
||||||
if($result === FALSE) {
|
if($result === FALSE) {
|
||||||
problem( "dc5b8dae7ea2a7e70ac0b7ea65ce2d12" );
|
call412( "dc5b8dae7ea2a7e70ac0b7ea65ce2d12" );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$db = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
$db = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
||||||
if ( empty($db["id"]) ) {
|
if ( empty($db["id"]) ) {
|
||||||
problem( "2b6462ff2389405a796066dfc73ccf55" );
|
call412( "2b6462ff2389405a796066dfc73ccf55" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
problem( "ae1f3471af22d32d3bf2efc9130a00ae" );
|
call412( "ae1f3471af22d32d3bf2efc9130a00ae" );
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
Header('Content-type: text/tab-separated-values');
|
||||||
|
header("Content-disposition: inline; filename=say.txt");
|
||||||
|
|
||||||
$ep_retrieve = "SELECT
|
$ep_retrieve = "SELECT
|
||||||
UNIX_TIMESTAMP(eps.date) AS timestamp,
|
UNIX_TIMESTAMP(eps.date) AS timestamp,
|
||||||
@ -90,62 +88,42 @@ if ($result = mysqli_query($connection, $ep_retrieve)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
$HPR_summary = "This is Hacker Public Radio episode $id for " . date("l", $date) . " the " . date("jS", $date) . " of " . date("F Y", $date) . ". Todays show is entitled. ${title}.";
|
||||||
http_response_code(404);
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$synopsis = "This is Hacker Public Radio episode $id for " . date("l", $date) . " the " . date("jS", $date) . " of " . date("F Y", $date) . ". Todays show is entitled. ${title}.";
|
|
||||||
if ($series > "0"){
|
if ($series > "0"){
|
||||||
$series_query = mysqli_query($connection, "SELECT name, description FROM miniseries WHERE id = '$series'");
|
$series_query = mysqli_query($connection, "SELECT name, description FROM miniseries WHERE id = '$series'");
|
||||||
$series_result = mysqli_fetch_array($series_query);
|
$series_result = mysqli_fetch_array($series_query);
|
||||||
$series_title = $series_result['name'];
|
$series_title = $series_result['name'];
|
||||||
$desc = $series_result['description'];
|
$desc = $series_result['description'];
|
||||||
$synopsis = "${synopsis} It is part of the series \"$series_title\"";
|
$HPR_summary = "${HPR_summary} It is part of the series \"$series_title\"";
|
||||||
}
|
}
|
||||||
$synopsis = "${synopsis} ${host_notes} and is about " . round($duration/60) . " minutes long. It carries ";
|
$HPR_summary = "${HPR_summary} ${host_notes} and is about " . round($duration/60) . " minutes long. It carries ";
|
||||||
if ($explicit == 0) {
|
if ($explicit == 0) {
|
||||||
$synopsis = "${synopsis} a clean flag. ";
|
$HPR_summary = "${HPR_summary} a clean flag. ";
|
||||||
$explicit = "Clean";
|
$explicit = "Clean";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$synopsis = "${synopsis} an explicit flag. ";
|
$HPR_summary = "${HPR_summary} an explicit flag. ";
|
||||||
$explicit = "Explicit";
|
$explicit = "Explicit";
|
||||||
}
|
}
|
||||||
if ( !empty( $summary ) ) {
|
if ( !empty( $summary ) ) {
|
||||||
$synopsis = "${synopsis}. The summary is. $summary";
|
$HPR_summary = "${HPR_summary}. The summary is. $summary";
|
||||||
}
|
}
|
||||||
if (strcmp($license, "CC-BY-SA" ) !== 0) {
|
if (strcmp($license, "CC-BY-SA" ) !== 0) {
|
||||||
$synopsis = "${synopsis}. Todays show is licensed under a $license_long_name license.";
|
$HPR_summary = "${HPR_summary}. Todays show is licensed under a $license_long_name license.";
|
||||||
}
|
}
|
||||||
|
|
||||||
$synopsis = str_replace($host,$espeak_name,$synopsis);
|
$HPR_summary = str_replace($host,$espeak_name,$HPR_summary);
|
||||||
|
|
||||||
// --------------------------------------------
|
echo "HPR_summary: ${HPR_summary}\n";
|
||||||
// Display the results
|
echo "HPR_album: Hacker Public Radio\n";
|
||||||
|
echo "HPR_artist: ${host}\n";
|
||||||
$arr = array(
|
echo "HPR_hostid: ${hostid}\n";
|
||||||
'genre' => "Podcast",
|
echo "HPR_comment: https://hackerpublicradio.org ${explicit}; $summary\n";
|
||||||
'album' => "Hacker Public Radio",
|
echo "HPR_genre: Podcast\n";
|
||||||
'track' => "$id",
|
echo "HPR_license: ${license}\n";
|
||||||
'year' => date("Y", $date),
|
echo "HPR_title: ${title}\n";
|
||||||
'date' => date("Y-m-d", $date),
|
echo "HPR_track: $id\n";
|
||||||
'artist' => "${host}",
|
echo "HPR_year: " . date("Y", $date) . "\n";
|
||||||
'hostid' => "${hostid}",
|
echo "HPR_duration: ${duration}\n";
|
||||||
'title' => "${title}",
|
echo "HPR_explicit: ${explicit}\n";
|
||||||
'duration' => "${duration}",
|
?>
|
||||||
'license' => "${license}",
|
|
||||||
'explicit' => "${explicit}",
|
|
||||||
'summary' => "${summary}",
|
|
||||||
'comment' => "https://hackerpublicradio.org ${explicit}; $summary",
|
|
||||||
'synopsis' => "${synopsis}"
|
|
||||||
);
|
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
|
||||||
header("Content-disposition: inline; filename=hpr_stats.json");
|
|
||||||
|
|
||||||
echo json_encode($arr);
|
|
||||||
|
|
||||||
mysqli_close($connection);
|
|
||||||
|
@ -42,7 +42,7 @@ $current_episode_number = $current_episode_array[1];
|
|||||||
// Populate array with future shows and reservations
|
// Populate array with future shows and reservations
|
||||||
$show_array = array ();
|
$show_array = array ();
|
||||||
|
|
||||||
// REQUEST_UNVERIFIED → SHOW_SUBMITTED → METADATA_PROCESSED → SHOW_POSTED → MEDIA_TRANSCODED → UPLOADED_TO_IA → UPLOADED_TO_CCDN
|
// REQUEST_UNVERIFIED → SHOW_SUBMITTED → METADATA_PROCESSED → SHOW_POSTED → MEDIA_TRANSCODED → UPLOADED_TO_IA → UPLOADED_TO_RSYNC_NET
|
||||||
$ep_retrieve = "SELECT hosts.host, eps.id, eps.title, eps.date FROM eps, hosts WHERE eps.valid=1 AND eps.hostid = hosts.hostid AND eps.date >= '$current_episode_date' ORDER BY date DESC";
|
$ep_retrieve = "SELECT hosts.host, eps.id, eps.title, eps.date FROM eps, hosts WHERE eps.valid=1 AND eps.hostid = hosts.hostid AND eps.date >= '$current_episode_date' ORDER BY date DESC";
|
||||||
|
|
||||||
$ep_retrieve = "SELECT
|
$ep_retrieve = "SELECT
|
||||||
@ -76,12 +76,11 @@ if ($result = mysqli_query($connection, $ep_retrieve)) {
|
|||||||
$show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
|
$show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
|
||||||
"title" => $title,
|
"title" => $title,
|
||||||
"host" => $host,
|
"host" => $host,
|
||||||
"status" => $status,
|
"status" => $status
|
||||||
"workflow" => $status
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// REQUEST_UNVERIFIED → SHOW_SUBMITTED → METADATA_PROCESSED → SHOW_POSTED → MEDIA_TRANSCODED → UPLOADED_TO_IA → UPLOADED_TO_CCDN
|
// REQUEST_UNVERIFIED → SHOW_SUBMITTED → METADATA_PROCESSED → SHOW_POSTED → MEDIA_TRANSCODED → UPLOADED_TO_IA → UPLOADED_TO_RSYNC_NET
|
||||||
|
|
||||||
// Populate array with currently processing shows EMAIL_LINK_CLICKED
|
// Populate array with currently processing shows EMAIL_LINK_CLICKED
|
||||||
$ep_retrieve = "
|
$ep_retrieve = "
|
||||||
@ -105,8 +104,7 @@ if ($result = mysqli_query($connection, $ep_retrieve)) {
|
|||||||
$show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
|
$show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
|
||||||
"title" => $status,
|
"title" => $status,
|
||||||
"host" => "Unverified",
|
"host" => "Unverified",
|
||||||
"status" => "Processing",
|
"status" => "Processing"
|
||||||
"workflow" => $status
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,8 +122,7 @@ if ($result = mysqli_query($connection, $ep_retrieve)) {
|
|||||||
$show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
|
$show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
|
||||||
"title" => " Available again in $minutes minutes",
|
"title" => " Available again in $minutes minutes",
|
||||||
"host" => "Unverified",
|
"host" => "Unverified",
|
||||||
"status" => "Locked",
|
"status" => "Locked"
|
||||||
"workflow" => "Locked"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,8 +153,7 @@ if ($result = mysqli_query($connection, $ep_retrieve)) {
|
|||||||
$show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
|
$show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
|
||||||
"title" => $title,
|
"title" => $title,
|
||||||
"host" => $host,
|
"host" => $host,
|
||||||
"status" => "Finished",
|
"status" => "Finished"
|
||||||
"workflow" => "Finished"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,126 +0,0 @@
|
|||||||
<?php
|
|
||||||
require "/home/hpr/php/include.php";
|
|
||||||
|
|
||||||
date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
if (isset($_GET['id'])) {
|
|
||||||
$id = $_GET['id'];
|
|
||||||
$result = mysqli_query($connection, 'SELECT MAX(id) FROM eps;');
|
|
||||||
if (!isset($result)) {
|
|
||||||
problem( "d7f47a123af3ea10628ce44d2146b40e" );
|
|
||||||
die('Could not query:' . mysqli_error());
|
|
||||||
}
|
|
||||||
$maxhost_array = mysqli_fetch_row( $result );
|
|
||||||
$maxhost = $maxhost_array[0];
|
|
||||||
$num_get_args=0;
|
|
||||||
foreach($_GET as $k => $v) {
|
|
||||||
++$num_get_args;
|
|
||||||
}
|
|
||||||
if ( (strval(intval($id)) != strval($id)) OR ( intval($id) <= 0 ) OR ( intval($id) > $maxhost ) OR ( $num_get_args > 1 ) ){
|
|
||||||
problem( "5d45cb79dd9426e7e4ab5595ac647a62" );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
$query = "SELECT id FROM eps WHERE id = '$id'";
|
|
||||||
$result = @mysqli_query($connection, $query);
|
|
||||||
if($result === FALSE) {
|
|
||||||
problem( "b26e5cea3779b66c76bf1c3c266e1a51" );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$db = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
||||||
if ( empty($db["id"]) ) {
|
|
||||||
problem( "a5d5eab30290ba4460ceb337add11821" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
problem( "39122c23e90fcf5cb9ca9e03a5c5a3c5" );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$ep_retrieve = "SELECT
|
|
||||||
UNIX_TIMESTAMP(eps.date) AS timestamp,
|
|
||||||
eps.title,
|
|
||||||
eps.duration,
|
|
||||||
eps.summary,
|
|
||||||
eps.tags,
|
|
||||||
hosts.host,
|
|
||||||
hosts.email,
|
|
||||||
hosts.license as host_license,
|
|
||||||
hosts.profile,
|
|
||||||
eps.hostid,
|
|
||||||
eps.series,
|
|
||||||
eps.notes,
|
|
||||||
miniseries.name as series_name,
|
|
||||||
eps.license as show_license,
|
|
||||||
eps.explicit
|
|
||||||
FROM
|
|
||||||
eps
|
|
||||||
LEFT JOIN hosts ON eps.hostid = hosts.hostid
|
|
||||||
LEFT JOIN miniseries ON miniseries.id = eps.series
|
|
||||||
WHERE
|
|
||||||
hosts.valid = '1'
|
|
||||||
AND eps.id = '$id'";
|
|
||||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$date = $row['timestamp'];
|
|
||||||
$title = $row['title'];
|
|
||||||
$duration = $row['duration'];
|
|
||||||
$summary = $row['summary'];
|
|
||||||
$host = $row['host'];
|
|
||||||
$hostid = $row['hostid'];
|
|
||||||
$host_email = $row['email'];
|
|
||||||
$host_license = $row['host_license'];
|
|
||||||
$host_profile = $row['profile'];
|
|
||||||
$series = $row['series'];
|
|
||||||
$series_name = $row['series_name'];
|
|
||||||
$show_license = $row['show_license'];
|
|
||||||
$explicit = $row['explicit'];
|
|
||||||
$tags = $row['tags'];
|
|
||||||
$notes = $row['notes'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
http_response_code(404);
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($explicit == 0) {
|
|
||||||
$explicit = "Clean";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$explicit = "Explicit";
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------
|
|
||||||
// Display the results
|
|
||||||
|
|
||||||
$arr = array(
|
|
||||||
'host' => array (
|
|
||||||
'Host_ID' => "${hostid}",
|
|
||||||
'Host_Name' => "${host}",
|
|
||||||
'Host_Email' => "${host_email}",
|
|
||||||
'Host_License' => "${host_license}",
|
|
||||||
'Host_Profile' => "${host_profile}"
|
|
||||||
),
|
|
||||||
'episode' => array (
|
|
||||||
'Title' => "${title}",
|
|
||||||
'Summary' => "${summary}",
|
|
||||||
'Explicit' => "${explicit}",
|
|
||||||
'Show_License' => "${show_license}",
|
|
||||||
'Series' => "${series}",
|
|
||||||
'Series_Name' => "${series_name}",
|
|
||||||
'Tags' => "${tags}",
|
|
||||||
'Show_Notes' => "${notes}"
|
|
||||||
),
|
|
||||||
'metadata' => array (
|
|
||||||
'Episode_Number' => "${id}",
|
|
||||||
'Episode_Date' => date("Y-m-d", $date)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
|
||||||
header("Content-disposition: inline; filename=hpr_stats.json");
|
|
||||||
|
|
||||||
echo json_encode($arr);
|
|
||||||
|
|
||||||
mysqli_close($connection);
|
|
@ -8,7 +8,7 @@ require "/home/hpr/php/include.php";
|
|||||||
|
|
||||||
$ip = $_SERVER["REMOTE_ADDR"];
|
$ip = $_SERVER["REMOTE_ADDR"];
|
||||||
|
|
||||||
if ( $_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD' ) {
|
if ( $_SERVER['REQUEST_METHOD'] !== 'GET' ) {
|
||||||
naughty("34522f7b9ba88b319afa9f063b98905c");
|
naughty("34522f7b9ba88b319afa9f063b98905c");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ if (strcasecmp('public', $_POST["anti_spam_question"]) !== 0) {
|
|||||||
naughty("6aef421ce05e3ac34f4cd91ae3248a45");
|
naughty("6aef421ce05e3ac34f4cd91ae3248a45");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$comment_directory = "/home/hpr/comments";
|
||||||
|
|
||||||
if ( ! file_exists( $comment_directory ) ) {
|
if ( ! file_exists( $comment_directory ) ) {
|
||||||
# Looks like the comments directory has not been created
|
# Looks like the comments directory has not been created
|
||||||
naughty("d5342ea497f701656433e81fb5eed064");
|
naughty("d5342ea497f701656433e81fb5eed064");
|
||||||
@ -271,7 +273,7 @@ $mailer->addBCC('admin@hobbypublicradio.org');
|
|||||||
$mailer->AddAddress('comments@hackerpublicradio.org');
|
$mailer->AddAddress('comments@hackerpublicradio.org');
|
||||||
$mailer->isHTML(false);
|
$mailer->isHTML(false);
|
||||||
$mailer->Subject = "New Comment for show hpr${eps_id} on ${ep_date} ${key}";
|
$mailer->Subject = "New Comment for show hpr${eps_id} on ${ep_date} ${key}";
|
||||||
$mailer->MsgHTML("<p><a href=\"https://hackerpublicradio.org/eps/hpr${eps_id}\">hpr${eps_id}</a> on ${ep_date} by ${host} with the title <strong>${title}</strong> \"${summary}\"</p>
|
$mailer->MsgHTML("<p>hpr${eps_id} on ${ep_date} by ${host} with the title <strong>${title}</strong> \"${summary}\"</p>
|
||||||
<p>
|
<p>
|
||||||
See attachment for the json comment file.
|
See attachment for the json comment file.
|
||||||
</p>
|
</p>
|
||||||
@ -316,8 +318,6 @@ $justification
|
|||||||
);
|
);
|
||||||
$mailer->AltBody = "hpr${eps_id} on ${ep_date} by ${host} with the title ${title} \"${summary}\"</p>
|
$mailer->AltBody = "hpr${eps_id} on ${ep_date} by ${host} with the title ${title} \"${summary}\"</p>
|
||||||
|
|
||||||
https://hackerpublicradio.org/eps/hpr${eps_id}
|
|
||||||
|
|
||||||
See attachment for the json comment file.
|
See attachment for the json comment file.
|
||||||
|
|
||||||
There are now ${unprocessed_comments} unprocessed comments.
|
There are now ${unprocessed_comments} unprocessed comments.
|
||||||
|
@ -160,7 +160,7 @@ logextra( "license is a valid value" );
|
|||||||
// }
|
// }
|
||||||
// logextra( "Notes are less than max" );
|
// logextra( "Notes are less than max" );
|
||||||
|
|
||||||
$notes_length = strlen($_POST["notes"]);
|
$notes_length = strlen($_POST["notes"])
|
||||||
logextra( "Notes are $notes_length long." );
|
logextra( "Notes are $notes_length long." );
|
||||||
|
|
||||||
if ( ( empty($_POST["series"]) and ($_POST["series"] != 0 ) ) or (strlen($_POST["series"]) > 3 ) ) {
|
if ( ( empty($_POST["series"]) and ($_POST["series"] != 0 ) ) or (strlen($_POST["series"]) > 3 ) ) {
|
||||||
@ -460,7 +460,7 @@ $mailer->addBCC('admin@hackerpublicradio.org');
|
|||||||
$mailer->addBCC('admin@hobbypublicradio.org');
|
$mailer->addBCC('admin@hobbypublicradio.org');
|
||||||
$mailer->AddAddress("$db_email");
|
$mailer->AddAddress("$db_email");
|
||||||
$mailer->isHTML(false);
|
$mailer->isHTML(false);
|
||||||
if ( $ep_num == "9999" ) {
|
if ( $ep_num === 9999 ) {
|
||||||
$mailer->Subject = "Thank you for uploading to the Reserve Queue";
|
$mailer->Subject = "Thank you for uploading to the Reserve Queue";
|
||||||
$mailer->MsgHTML("<p><em>This email is an automatic reply. If you have not made this request then please ignore this email.</em></p>
|
$mailer->MsgHTML("<p><em>This email is an automatic reply. If you have not made this request then please ignore this email.</em></p>
|
||||||
<p>Thank You for recording an episode for the Reserve Queue.</p>
|
<p>Thank You for recording an episode for the Reserve Queue.</p>
|
||||||
@ -476,20 +476,20 @@ if ( $ep_num == "9999" ) {
|
|||||||
else {
|
else {
|
||||||
$mailer->Subject = "Thank you for uploading hpr${ep_num}::${ep_date}";
|
$mailer->Subject = "Thank you for uploading hpr${ep_num}::${ep_date}";
|
||||||
$mailer->MsgHTML("<p><em>This email is an automatic reply. If you have not made this request then please ignore this email.</em></p>
|
$mailer->MsgHTML("<p><em>This email is an automatic reply. If you have not made this request then please ignore this email.</em></p>
|
||||||
<p>Thank you for recording hpr${ep_num} for release on ${ep_date}.</p>
|
<p>Thank You for recording hpr${ep_num} for release on ${ep_date}.</p>
|
||||||
<pre>
|
<pre>
|
||||||
$message
|
$message
|
||||||
</pre>
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
Your show will now be processed by a HPR Volunteer.<br />
|
Your show will now be processed by a HPR Volunteer.<br />
|
||||||
Thanks,<br />
|
Thanks,<br />
|
||||||
HPR Bot.
|
HPR Bot
|
||||||
</p>");
|
</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
$mailer->AltBody = "This email is an automatic reply. If you have not made this request then please ignore this email.
|
$mailer->AltBody = "This email is an automatic reply. If you have not made this request then please ignore this email.
|
||||||
|
|
||||||
Thank you for recording hpr${ep_num}, for release on ${ep_date}.
|
Thank You for recording hpr${ep_num} for release on ${ep_date}.
|
||||||
|
|
||||||
$message
|
$message
|
||||||
|
|
||||||
|
@ -334,11 +334,11 @@ if ($pos !== false) {
|
|||||||
|
|
||||||
// General allowed Settings
|
// General allowed Settings
|
||||||
|
|
||||||
$allowed_content_type = array( "application/json", "application/octet-stream", "application/ogg", "application/x-subrip", "audio/flac", "audio/mpeg", "audio/ogg", "audio/x-flac", "audio/x-wav", "image/jpeg", "image/png", "image/webp", "text/plain", "text/x-c" );
|
$allowed_content_type = array( "application/json", "application/octet-stream", "application/ogg", "application/x-subrip", "audio/flac", "audio/mpeg", "audio/ogg", "audio/x-flac", "audio/x-wav", "image/jpeg", "image/png", "text/plain", "text/plain", "text/vtt", "text/x-c" );
|
||||||
|
|
||||||
$allowed_extensions = array("wav", "flac", "opus", "ogg", "mp3", "jpg", "jpeg", "png", "webp", "srt", "txt" );
|
$allowed_extensions = array("wav", "flac", "opus", "ogg", "spx", "mp3", "jpg", "png", "json", "srt", "tsv", "txt", "vtt");
|
||||||
|
|
||||||
$allowed_extensions_common = array("opus", "ogg", "mp3", "jpg", "jpeg", "png", "webp", "srt", "txt" );
|
$allowed_extensions_common = array("opus", "ogg", "spx", "mp3", "jpg", "png", "json", "srt", "tsv", "txt", "vtt");
|
||||||
|
|
||||||
#$ccdn_hosts_common = array("alpha.nl.eu.mirror.hackerpublicradio.org", "hpr.nyc3.cdn.digitaloceanspaces.com" );
|
#$ccdn_hosts_common = array("alpha.nl.eu.mirror.hackerpublicradio.org", "hpr.nyc3.cdn.digitaloceanspaces.com" );
|
||||||
$ccdn_hosts_common = array("alpha.nl.eu.mirror.hackerpublicradio.org", "hpr.nyc3.cdn.digitaloceanspaces.com" );
|
$ccdn_hosts_common = array("alpha.nl.eu.mirror.hackerpublicradio.org", "hpr.nyc3.cdn.digitaloceanspaces.com" );
|
||||||
|
Loading…
Reference in New Issue
Block a user