Merge pull request 'General cleanup of file locations' (#22) from I21_Improve_comment_system into main

Reviewed-on: #22
This commit is contained in:
Ken Fallon 2023-12-23 10:30:56 +00:00
commit 92902ffe47
11 changed files with 659 additions and 39 deletions

7
bin/hpr_db_backup.bash Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
pw=$(grep -E '^\$databasePassword = ' /home/hpr/php/credentials.php | awk -F "'" '{print $2}' )
pw=${pw##* }
mysqldump --user=hpr_hpr --password="$pw" -c -e --default-character-set=utf8 --single-transaction --skip-set-charset --add-drop-database --databases hpr_hpr > /home/hpr/hpr_hpr.sql
mysqldump --databases hpr_hpr --add-drop-database --tz-utc --host=localhost --user=hpr_hpr --password="$pw" > /home/hpr/mysqldump.sql
mysqldump --user=hpr_hpr --password="$pw" -c -e --default-character-set=utf8 --single-transaction --skip-set-charset --add-drop-database --databases hpr_hpr --ignore-table=hpr_hpr.reservations > /home/hpr/www/hpr.sql

4
bin/mdb.bash Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
pw=$(grep -E '^\$databasePassword = ' /home/hpr/php/credentials.php | awk -F "'" '{print $2}' )
pw=${pw##* }
mysql --host=localhost --user=hpr_hpr --password="$pw" hpr_hpr

40
bin/rename-reserve.bash Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env bash
# Copyright Ken Fallon - Released into the public domain. http://creativecommons.org/publicdomain/
#============================================================
upload_dir="/home/hpr/upload"
reserve_dir="/home/hpr/reserve"
while read reserve_show_dir
do
echo "Processing \"${reserve_show_dir}\""
shownotes="${reserve_show_dir}/shownotes.json"
if [ ! -s "${shownotes}" ]
then
echo "ERROR: \"${shownotes}\" not found"
exit 1
fi
Host_ID="$( jq --raw-output '.host.Host_ID' "${shownotes}" )"
Host_Name="$( jq --raw-output '.host.Host_Name' "${shownotes}" | sed -e 's/[^A-Za-z0-9]/_/g' -e 's/__/_/g' )"
Key="$( jq --raw-output '.metadata.Key' "${shownotes}" )"
Timestamp="$( jq --raw-output '.metadata.Timestamp' "${shownotes}" )"
Title="$( jq --raw-output '.episode.Title' "${shownotes}" | sed -e 's/[^A-Za-z0-9]/_/g' -e 's/__/_/g')"
Timestamp_Epoch="$( \date -u +%s -d "${Timestamp}" )"
#hostid="$( jq --raw-output '.host.Host_ID + "_" + .metadata.Key + "_" + .episode.Title' "${shownotes}" )"
mv -v "${reserve_show_dir}" "${reserve_dir}/${Timestamp_Epoch}_${Host_ID}_${Key}_${Host_Name}_${Title}"
done < <( find "${upload_dir}" -type d -iname "*_9999_*" )
#ls -al "${reserve_dir}"
# drwxr-xr-x. 1 ken ken 136 Jul 2 19:33 1688318808_198_321136810af5473fb011ae91d0e8b49264a1b35871d65_Ahuka_Audacity-Update
# drwxr-xr-x. 1 ken ken 148 Jul 2 19:42 1688319300_198_562721ff5261ef02277be37ade18bae364a1b544c445e_Ahuka_Creative_Commons_Search_Engine
# drwxr-xr-x. 1 ken ken 84 Jul 3 22:54 1688416961_391_aaf8e86be56a78cfd60e611af93d9d2e64a332c1b9572_Sgoti_confuses_everyone_with_bash_nonsense
# drwxr-xr-x. 1 ken ken 84 Jul 5 20:58 1688583277_391_b04748b6e57e5f72c7853be33889f3ce64a5bc6dca8e5_Sgoti_talks_about_driving_in_the_state_of_Virginia
# drwxr-xr-x. 1 ken ken 84 Jul 6 00:34 1688595802_391_6dffbcaf766aedaffed2a61b6a648f3c64a5ed5ac6341_Sgoti_rambles_about_a_video_game_called_GrimDawn
# drwxr-xr-x. 1 ken ken 84 Jul 9 20:25 1688926358_391_1c3ffa201045c40311b536ee4ef4a62864aaf8961d692_Sgoti_My_road_recording_setup
# drwxr-xr-x. 1 ken ken 84 Sep 8 07:30 1694150656_391_8504d8543e1cc8760b76fff27c5d1f4b64fab00057c8e_Some_Guy_On_The_Internet_Sextortion_Good_Heavens
# drwxr-xr-x. 1 ken ken 98 Oct 24 16:22 1698156039_9999_1970-01-01_6c585b3db2bfb5fc70216620ac97c0d56537ce07155a4
# drwxr-xr-x. 1 ken ken 110 Oct 24 16:25 1698157365_9999_1970-01-01_f8d61b32850177939428764c53dfb2006537d3353a95e
# drwxr-xr-x. 1 ken ken 92 Oct 24 16:26 1698157513_9999_1970-01-01_a85b7a7febda983fdeb8ba1c165736146537d3c93d27d
# drwxr-xr-x. 1 ken ken 96 Oct 24 16:28 1698157609_9999_1970-01-01_a85414f9074042bf14db0e56f62cc25d6537d4293c86e

View File

@ -231,6 +231,9 @@ logextra( "Found this reservation from the db" );
if ( ( $db["profile"] != "$host_profile" ) or ( $db["license"] != "$host_license" ) ) { if ( ( $db["profile"] != "$host_profile" ) or ( $db["license"] != "$host_license" ) ) {
logextra("The host_license is different to that in the db"); logextra("The host_license is different to that in the db");
$host_profile = mysqli_real_escape_string( $connection, $host_profile );
$host_license = mysqli_real_escape_string( $connection, $host_license );
$query = "UPDATE `hosts` SET `profile` = '$host_profile', `license` = '$host_license' WHERE `hosts`.`hostid` = '$hostid';"; $query = "UPDATE `hosts` SET `profile` = '$host_profile', `license` = '$host_license' WHERE `hosts`.`hostid` = '$hostid';";
$result = mysqli_query($connection, $query ); $result = mysqli_query($connection, $query );
if (!isset($result)) { if (!isset($result)) {

View File

@ -64,12 +64,108 @@ if ( ! filter_var($file_ip, FILTER_VALIDATE_IP) ) {
if ( $action === 'block' ) { if ( $action === 'block' ) {
file_put_contents($naughtyfile, date('Y-m-d\TH:i:s\Z') . "\t${file_ip}\tReported as comment spammer\t${key}\n", FILE_APPEND | LOCK_EX ); file_put_contents($naughtyfile, date('Y-m-d\TH:i:s\Z') . "\t${file_ip}\tReported as comment spammer\t${key}\n", FILE_APPEND | LOCK_EX );
unlink( "${file}" );
http_response_code(201);
exit;
} }
unlink( "${file}" ); if ( $action === 'delete' ) {
http_response_code(200); unlink( "${file}" );
http_response_code(202);
exit;
}
if ( $action === 'approve' ) {
$comment = file_get_contents("$file");
$json = json_decode($comment, true);
echo '<pre>' . print_r($json, true) . '</pre>';
// check json
if ( empty($json["eps_id"]) ) {
naughty("6740e9b34590fe5b8f1829aeb5da099d");
}
if ( empty($json["comment_timestamp"]) ) {
naughty("4850b4b0006a60d86bafee8a8592b3f8");
}
if ( empty($json["comment_author_name"]) ) {
naughty("15f377e657196bb8192ec11755b0ca75");
}
if ( empty($json["comment_title"]) ) {
naughty("ce604e6bf3c1e0aa0ec7ab78ae07e6cb");
}
if ( empty($json["comment_text"]) ) {
naughty("d4101542e2d0264c0cdb8ac4bdf6bf09");
}
if ( empty($json["justification"]) ) {
naughty("f87785f8eda5d75de8cb08c386c66c56");
}
if ( empty($json["key"]) ) {
naughty("f87785f8eda5d75de8cb08c386c66c56");
}
// check ip
if ( empty($json["ip"]) ) {
naughty("025622ea15552a7b8a3ae71405cf1fbf");
}
$ip = $json["ip"];
if ( ! filter_var($ip, FILTER_VALIDATE_IP)) {
naughty("571f2d51046da9c923e01ae8bbfc037e");
}
// check ep_num
$ep_num = $json["eps_id"];
if ( intval($ep_num) === 0 ) {
$x = intval($ep_num);
naughty("fdae5c63eb5608820b13c9d096166c84");
}
else {
$ep_num = intval($ep_num);
}
if ( ( $ep_num <= 0 ) OR ( $ep_num >= 9999) ) {
naughty("eb90a1a69fd531d5c649e3f5367bd570");
}
$show_array = array ();
$ep_retrieve = "SELECT id FROM eps WHERE id=$ep_num;";
if ($result = mysqli_query($connection, $ep_retrieve)) {
if ( ! $result->fetch_assoc()) {
naughty("b9ac28c5c661d7ed1c4c009de0279e07");
}
}
// date
$date = '2011-10-02T23:25:42Z';
var_dump(validateDate($date));
// OK I believe you
// INSERT INTO comments (eps_id,comment_timestamp,comment_author_name,comment_title,comment_text), VALUES ( $ep_num, $comment_timestamp, $comment_author_name, $comment_title, $comment_text);
// unlink( "${file}" );*/
http_response_code(200);
exit;
}
// exit; // exit;
http_response_code(500);
?> ?>

View File

@ -73,6 +73,22 @@ $max_episode_array = mysqli_fetch_row($query);
$max_episode_number = $max_episode_array[0]; $max_episode_number = $max_episode_array[0];
print "<!-- max_episode_number is $max_episode_number -->\n"; print "<!-- max_episode_number is $max_episode_number -->\n";
// --------------------------------------------
// Get the number of shows in the reserve queue.
$query = mysqli_query($connection, "SELECT COUNT(*) as count_reserve_queue FROM reservations WHERE status = 'RESERVE_SHOW_SUBMITTED' AND ip = '127.0.0.1';");
$response_array = mysqli_fetch_row($query);
$count_reserve_queue = $response_array[0];
print "<!-- count_reserve_queue is $count_reserve_queue -->\n";
// --------------------------------------------
// Get the number of shows in the reserve queue yet to be processed.
$query = mysqli_query($connection, "SELECT COUNT(*) as count_reserve_queue_unprocessed FROM reservations WHERE status = 'RESERVE_SHOW_SUBMITTED' AND ip != '127.0.0.1';");
$response_array = mysqli_fetch_row($query);
$count_reserve_queue_unprocessed = $response_array[0];
print "<!-- count_reserve_queue_unprocessed is $count_reserve_queue_unprocessed -->\n";
// -------------------------------------------- // --------------------------------------------
// Populate array with future shows and reservations // Populate array with future shows and reservations
$show_array = array (); $show_array = array ();
@ -162,6 +178,36 @@ if ($result = mysqli_query($connection, $ep_retrieve)) {
} }
} }
$ep_retrieve = "SELECT
hosts.host,
eps.id,
eps.title,
eps.date
FROM
eps,
hosts,
assets
WHERE
eps.valid = 0
AND eps.hostid = hosts.hostid
AND eps.id = assets.episode_id
AND eps.date >= '$current_episode_date'
ORDER BY
date DESC";
if ($result = mysqli_query($connection, $ep_retrieve)) {
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$date = $row['date'];
$title = $row['title'];
$host = $row['host'];
$show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
"title" => $title,
"host" => $host,
"status" => "Waiting for media"
);
}
}
$ep_retrieve = "SELECT $ep_retrieve = "SELECT
hosts.host, hosts.host,
eps.id, eps.id,

View File

@ -60,17 +60,20 @@ if (count($_POST) !== 8) {
if ( empty($_POST["comment_author_name"]) or strlen($_POST["comment_author_name"]) > 40 or strtolower($_POST["comment_author_name"]) == "testdog" ) { if ( empty($_POST["comment_author_name"]) or strlen($_POST["comment_author_name"]) > 40 or strtolower($_POST["comment_author_name"]) == "testdog" ) {
naughty("294356cd36d3f9b75da4d8c0a6108881"); naughty("294356cd36d3f9b75da4d8c0a6108881");
} }
$comment_author_name = json_encode( $_POST["comment_author_name"] ); $comment_author_name = $_POST["comment_author_name"];
$comment_author_name_json = json_encode( $_POST["comment_author_name"] );
if ( empty($_POST["comment_title"]) or strlen($_POST["comment_title"]) > 100 ) { if ( empty($_POST["comment_title"]) or strlen($_POST["comment_title"]) > 100 ) {
naughty("a89efb428cfe36996a65b371d5f4e303"); naughty("a89efb428cfe36996a65b371d5f4e303");
} }
$comment_title = json_encode( $_POST["comment_title"] ); $comment_title = $_POST["comment_title"];
$comment_title_json = json_encode( $_POST["comment_title"] );
if ( empty($_POST["comment_text"]) or strlen($_POST["comment_text"]) > 2000 or strpos(strtolower($_POST["comment_text"]), "outlook.con") !== false ) { if ( empty($_POST["comment_text"]) or strlen($_POST["comment_text"]) > 2000 or strpos(strtolower($_POST["comment_text"]), "outlook.con") !== false ) {
naughty("cd57ab4d7b77a131ed3deb441bd93dcd"); naughty("cd57ab4d7b77a131ed3deb441bd93dcd");
} }
$comment_text = json_encode( $_POST["comment_text"] ); $comment_text = $_POST["comment_text"];
$comment_text_json = json_encode( $_POST["comment_text"] );
if ( empty($_POST["spammer"]) or strcmp($_POST["spammer"], "No") !== 0 ) { if ( empty($_POST["spammer"]) or strcmp($_POST["spammer"], "No") !== 0 ) {
naughty("b2ec68bd04cee0f64143ce4827a97e7c"); naughty("b2ec68bd04cee0f64143ce4827a97e7c");
@ -154,7 +157,8 @@ if ( ( $eps_id <= $current_episode_number ) and ( $eps_id >= ( $current_episode_
naughty("9357d78bf73b03ee2dd902a4c975f91d"); naughty("9357d78bf73b03ee2dd902a4c975f91d");
} }
else { else {
$justification = json_encode("Current Comment"); $justification = "Current Comment";
$justification_json = json_encode("Current Comment");
} }
} }
else { else {
@ -163,7 +167,8 @@ else {
naughty("df4af9bdd0302f672d6311c76bdc461a"); naughty("df4af9bdd0302f672d6311c76bdc461a");
} }
else { else {
$justification = json_encode( $_POST["justification"] ); $justification = $_POST["justification"];
$justification_json = json_encode( $_POST["justification"] );
} }
} }
@ -183,8 +188,9 @@ $key = uniqid(md5(rand()));
$timestamp = time()+date("Z"); $timestamp = time()+date("Z");
$timestamp = gmdate("Y-m-d\TH:i:s\Z",$timestamp); $timestamp = gmdate("Y-m-d\TH:i:s\Z",$timestamp);
$comment_file = "${comment_directory}/${timestamp}_${ip}_${key}.json"; $comment_file = "${comment_directory}/${timestamp}_${ip}_${key}.json";
$timestamp = json_encode($timestamp); $timestamp = $timestamp;
$comment_key = json_encode( $key ); $timestamp_json = json_encode($timestamp);
$comment_key_json = json_encode( $key );
if ( file_exists( $comment_file ) ) { if ( file_exists( $comment_file ) ) {
naughty("ef5d14b33b262bfbf5d40544fdeb9ec3"); naughty("ef5d14b33b262bfbf5d40544fdeb9ec3");
} }
@ -192,12 +198,12 @@ if ( file_exists( $comment_file ) ) {
$comment_data = "{ $comment_data = "{
\"eps_id\": $eps_id, \"eps_id\": $eps_id,
\"ip\": \"$ip\", \"ip\": \"$ip\",
\"comment_timestamp\": $timestamp, \"comment_timestamp\": $timestamp_json,
\"comment_author_name\": $comment_author_name, \"comment_author_name\": $comment_author_name_json,
\"comment_title\": $comment_title, \"comment_title\": $comment_title_json,
\"comment_text\": $comment_text, \"comment_text\": $comment_text_json,
\"justification\": $justification, \"justification\": $justification_json,
\"key\": $comment_key \"key\": $comment_key_json
}"; }";
file_put_contents($comment_file, $comment_data ); file_put_contents($comment_file, $comment_data );
@ -241,6 +247,12 @@ $mailer->MsgHTML("<p>hpr${eps_id} on ${ep_date} by ${host} with the title <stron
<p> <p>
See attachment for the json comment file. See attachment for the json comment file.
</p> </p>
<p>
<a href=\"https://hub.hackerpublicradio.org/cms/comment_process.php?key=$key&action=block\">Block</a>,
<a href=\"https://hub.hackerpublicradio.org/cms/comment_process.php?key=$key&action=delete\">Delete</a>, or
<a href=\"https://hub.hackerpublicradio.org/cms/comment_process.php?key=$key&action=approve\">Approve</a>.
</p>
<p> <p>
There are now " . ++$unprocessed_comments . " unprocessed comments. There are now " . ++$unprocessed_comments . " unprocessed comments.
</p> </p>
@ -248,7 +260,27 @@ There are now " . ++$unprocessed_comments . " unprocessed comments.
Thanks,<br /> Thanks,<br />
HPR Bot HPR Bot
</p> </p>
<pre>" . date('Y-m-d\TH:i:s') . "\t" . getUserIP() . "\t" . $key . "\t" . $_SERVER["HTTP_USER_AGENT"] . "</pre>" <pre>" . date('Y-m-d\TH:i:s') . "\t" . getUserIP() . "\t" . $key . "\t" . $_SERVER["HTTP_USER_AGENT"] . "</pre>
<hr />
<p>
<strong>eps_id</strong>: $eps_id,<br />
<strong>ip</strong>: $ip,<br />
<strong>key</strong>: $key<br />
<strong>justification</strong>: $justification,<br />
<strong>comment_timestamp</strong>: $timestamp,<br />
<strong>comment_author_name</strong>: $comment_author_name,<br />
<strong>comment_title</strong>: $comment_title,<br />
<strong>comment_text</strong>:
</p>
<pre>
$comment_text
</pre>
<hr />
<strong>comment_text_json</strong>:
<pre>
$comment_text_json
</pre>
<hr />"
); );
$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>
@ -266,7 +298,6 @@ if (!$mailer->send()) {
echo 'Mailer Error: ' . $mailer->ErrorInfo; echo 'Mailer Error: ' . $mailer->ErrorInfo;
} }
$body="give"; $body="give";
//$body="index_full"; //$body="index_full";
include 'header.html'; include 'header.html';

111
social_media_rss.php Normal file
View File

@ -0,0 +1,111 @@
<?php
$atomurl=$_SERVER['PHP_SELF'];
require "/home/hpr/php/include.php";
$query = "SELECT
hosts.host as host,
eps.id as id,
eps.title as title,
eps.summary as summary,
eps.date as date,
hosts.email as email,
eps.hostid as hostid,
eps.explicit as explicit,
eps.version as version,
eps.valid as valid
FROM
eps,
hosts
WHERE
eps.valid = 1
AND eps.hostid = hosts.hostid
AND eps.date <= UTC_DATE()
ORDER BY
id DESC
Limit 10";
header("Content-type: application/xml");
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
date_default_timezone_set('UTC');
?>
<rss version="2.0" xmlns:atom="https://www.w3.org/2005/Atom" xmlns:itunes="https://www.itunes.com/dtds/podcast-1.0.dtd" >
<channel>
<title>Hacker Public Radio</title>
<link>https://hackerpublicradio.org/about.html</link>
<itunes:subtitle>A daily show hosted the community on topics that are of interest to hackers and hobbyists.</itunes:subtitle>
<description>Hacker Public Radio is an podcast that releases shows every weekday Monday through Friday. Our shows are produced by the community (you) and can be on any topic that are of interest to hackers and hobbyists.</description>
<language>en-us</language>
<itunes:category text="Technology">
<itunes:category text="Tech News"/>
</itunes:category>
<itunes:category text="Education">
<itunes:category text="Training"/>
</itunes:category>
<itunes:image href="https://hackerpublicradio.org/images/hpr_feed_itunes.png"/>
<itunes:explicit>yes</itunes:explicit>
<itunes:keywords>Community Radio, Tech Interviews, Linux, Open, Hobby, Software Freedom</itunes:keywords>
<copyright>Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) License</copyright>
<managingEditor>feedback@NOSPAM-hackerpublicradio.org (HPR Feedback)</managingEditor>
<itunes:owner>
<itunes:name>HPR Webmaster</itunes:name>
<itunes:email>admin@hackerpublicradio.org</itunes:email>
</itunes:owner>
<webMaster>admin@NOSPAM-hackerpublicradio.org (HPR Webmaster)</webMaster>
<generator>kate</generator>
<docs>https://www.rssboard.org/rss-specification</docs>
<ttl>43200</ttl>
<skipDays>
<day>Saturday</day>
<day>Sunday</day>
</skipDays>
<image>
<url>https://hackerpublicradio.org/images/hpr_feed_small.png</url>
<title>Hacker Public Radio</title>
<link>https://hackerpublicradio.org/about.html</link>
<description>The Hacker Public Radio Old Microphone Logo</description>
<height>164</height>
<width>144</width>
</image>
<?php
print " <atom:link href=\"https://hub.hackerpublicradio.org". str_replace('&', '&amp;', $_SERVER["REQUEST_URI"]) ."\" rel=\"self\" type=\"application/rss+xml\" />\n";
print " <pubDate>".date(DATE_RFC1123, strtotime(date('Y-m-d')))."</pubDate>\n";
//Set $r to SQL query for execution agains the table
if ($result = mysqli_query($connection, $query)) {
while ($row = mysqli_fetch_array($result)) {
$id = fixid(stripslashes($row['id']));
$version = fixid(stripslashes($row['version']));
$url="https://hackerpublicradio.org/eps/hpr".$id."/index.html";
$itunes_summary = htmlspecialchars(stripslashes(strip_tags(substr($row["summary"],0,100))));
$show_summary = $itunes_summary;
echo " <item>\n";
echo " <title>HPR$id: " . stripslashes(strip_tags($row["title"])) . "</title>\n";
// echo "<description> " . ($row["title"]) . "</description>\n";
$email_padded = formatemail($row['email']);
echo " <author>".$email_padded . " (" . htmlspecialchars(stripslashes(strip_tags($row["host"]))) .")</author>\n";
echo " <link>" . $url . "</link>\n";
echo " <description>" . $show_summary . "</description>\n";
echo " <pubDate>" .date(DATE_RFC1123, strtotime($row['date'])) . "</pubDate>\n";
echo " <guid>" . $url . "</guid>\n";
$explicit = $row['id'];
if ( $explicit === "0" ) {
echo " <itunes:explicit>clean</itunes:explicit>\n";
}
else {
echo " <itunes:explicit>yes</itunes:explicit>\n";
}
echo " </item>\n";
}
}
//Display non-connection errors
//Close sql connection
mysqli_close($connection);
echo " </channel>
</rss>
";
?>

284
stats.php Normal file
View File

@ -0,0 +1,284 @@
<?php
require "/home/hpr/php/include.php";
if (isset($_GET['format'])){
if ($_GET['format'] === "json") {
$format="json";
}
if ($_GET['format'] === "xml") {
$format="xml";
}
if ($_GET['format'] === "csv") {
$format="csv";
}
}
$twat_startdate = abs(strtotime(date("c")) - strtotime("2005-09-19T00:00:00Z"));
$twat_years = floor($twat_startdate / (365*60*60*24));
$twat_months = floor(($twat_startdate - $twat_years * 365*60*60*24) / (30*60*60*24));
$twat_days = floor(($twat_startdate - $twat_years * 365*60*60*24 - $twat_months*30*60*60*24)/ (60*60*24));
$agetwat = $twat_startdate;
$hpr_startdate = abs(strtotime(date("c")) - strtotime("2007-12-31T00:00:00Z"));
$hpr_years = floor($hpr_startdate / (365*60*60*24));
$hpr_months = floor(($hpr_startdate - $hpr_years * 365*60*60*24) / (30*60*60*24));
$hpr_days = floor(($hpr_startdate - $hpr_years * 365*60*60*24 - $hpr_months*30*60*60*24)/ (60*60*24));
$agehpr = $hpr_startdate;
$last_show = mysql_query("SELECT max(date), max(id) from eps");
$last_show_date = mysql_fetch_row($last_show);
$totalshows=$last_show_date[1]+300;
$totalhpr=$last_show_date[1];
// --------------------------------------------
// Get the number of hosts
$ep_retrieve = "SELECT hostid FROM hosts WHERE valid = '1' ORDER BY hostid ASC";
$num_of_hosts = "1";
if ($result = mysql_query($ep_retrieve)) {
while ($row = mysql_fetch_array($result)) {
$hostid = $row['hostid'];
$last_show = mysql_query("SELECT max(date) from eps WHERE hostid='$hostid' AND valid = '1'");
$last_show_date = mysql_fetch_row($last_show);
if (!empty($last_show_date[0])) {
$num_of_hosts++;
}
}
}
// --------------------------------------------
// Get first free slot
$query = mysql_query("SELECT id + 1 FROM eps mo
WHERE NOT EXISTS
(
SELECT NULL
FROM eps mi
WHERE mi.id = mo.id + 1
)
ORDER BY
id
LIMIT 1");
$next_show_num_array = mysql_fetch_row($query);
$next_show_num = $next_show_num_array[0];
// --------------------------------------------
// Get latest published show
$query = mysql_query("SELECT max(date), max(id) from eps WHERE eps.date <= UTC_DATE()");
$current_episode_array = mysql_fetch_row($query);
$current_episode_date = $current_episode_array[0];
$current_episode_number = $current_episode_array[1];
// --------------------------------------------
// Populate array with future shows
$un_delivered = -1;
$days_to_undelivered = 0;
$show_array = array ();
$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";
if ($result = mysql_query($ep_retrieve)) {
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$id = fixid($id);
$date = $row['date'];
$title = $row['title'];
$host = $row['host'];
if ( file_exists("./eps/hpr$id.ogg") and file_exists("./eps/hpr$id.spx") and file_exists("./eps/hpr$id.mp3") ) {
$delivered = 1;
if ($un_delivered === -1 ) {
$days_to_undelivered++;
}
}
else {
$delivered = 0;
$un_delivered = $days_to_undelivered;
}
$show_array[$id] = array ( "date" => $date,
"title" => $title,
"host" => $host,
"delivered" => $delivered
);
}
}
// --------------------------------------------
// Calculate the time to the next show
$next_show_date = date('Y-m-d', strtotime($show_array[$next_show_num - 1 ]["date"] . ' + 1 weekday'));
$days_to_wait = floor((strtotime($next_show_date) - strtotime(gmdate('Y-m-d')))/(60*60*24));
// --------------------------------------------
// Future Hosts
$ep_retrieve = "SELECT DISTINCT hostid FROM eps WHERE eps.date > UTC_DATE()";
// $ep_retrieve = "SELECT id, type, date, title, notes, host, hostid FROM eps WHERE valid = '1' ORDER BY id DESC LIMIT 10";
if ($result = mysql_query($ep_retrieve)) {
$num_future_hosts = mysql_num_rows($result);
}
// --------------------------------------------
// Shows in the Queue
$ep_retrieve = "SELECT DISTINCT id FROM eps WHERE eps.date > UTC_DATE() AND duration <> 0";
// $ep_retrieve = "SELECT id, type, date, title, notes, host, hostid FROM eps WHERE valid = '1' ORDER BY id DESC LIMIT 10";
if ($result = mysql_query($ep_retrieve)) {
$num_future_shows = mysql_num_rows($result);
}
// --------------------------------------------
// Shows in the Queue
$result=mysql_query("SELECT count(*) as total FROM `reservations` WHERE `status` LIKE 'SHOW_SUBMITTED' ORDER BY `ip` ASC ");
$data=mysql_fetch_assoc($result);
$num_submitted_shows = $data['total'];
// --------------------------------------------
// Duration of all shows
$result=mysql_query("SELECT SUM(duration) as total_duration FROM `eps`");
$data=mysql_fetch_assoc($result);
$total_duration = $data['total_duration'];
$human_total_duration = convertSecToTime($total_duration);
// --------------------------------------------
// Unprocessed comments
$comment_directory = "/home/hpr/comments";
$unprocessed_comments = iterator_count(new FilesystemIterator("$comment_directory", FilesystemIterator::SKIP_DOTS));
// --------------------------------------------
// Shows on the FTP server
$new_shows=0;
if ($handle = opendir('/home/hpr/upload')) {
while (false !== ($entry = readdir($handle))) {
if ( $entry != "." && $entry != "..") {
$new_shows++;
}
}
closedir($handle);
}
// --------------------------------------------
// Emergency Shows
$emergency_shows = count(glob('/home/hpr/www/emergency/*.ogg'));
$current_time = time();
if ($format === "json") {
header('Content-Type: application/json');
header("Content-disposition: inline; filename=hpr_stats.json");
echo "{
\"stats_generated\": ".$current_time.",
\"age\": {
\"start\": \"2005-09-19T00:00:00Z\",
\"rename\": \"2007-12-31T00:00:00Z\",
\"since_start\": {
\"total_seconds\": ".$agetwat.",
\"years\": ".$twat_years.",
\"months\": ".$twat_months.",
\"days\": ".$twat_days."
},
\"since_rename\": {
\"total_seconds\": ".$agehpr.",
\"years\": ".$hpr_years.",
\"months\": ".$hpr_months.",
\"days\": ".$hpr_days."
}
},
\"shows\": {
\"total\": ".$totalshows.",
\"twat\": 300,
\"hpr\": ".$totalhpr.",
\"duration\": ".$total_duration.",
\"human_duration\": \"".$human_total_duration."\"
},
\"hosts\": ".$num_of_hosts.",
\"slot\": {
\"next_free\": ".$days_to_wait.",
\"no_media\": ".$un_delivered."
},
\"queue\": {
\"number_future_hosts\": ".$num_future_hosts.",
\"number_future_shows\": ".$num_future_shows.",
\"unprocessed_comments\": ".$unprocessed_comments.",
\"submitted_shows\": ".$num_submitted_shows.",
\"shows_in_workflow\": ".$new_shows.",
\"emergency\": ".$emergency_shows."
}
}
";
}
elseif ($format === "xml") {
header("Content-type: application/xml");
header("Content-disposition: inline; filename=hpr_stats.xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<stats>
<stats_generated>".$current_time."</stats_generated>
<age>
<start>2005-09-19T00:00:00Z</start>
<rename>2007-12-31T00:00:00Z</rename>
<since_start>
<total_seconds>".$agetwat."</total_seconds>
<years>". $twat_years."</years>
<months>".$twat_months."</months>
<days>".$twat_days."</days>
</since_start>
<since_rename>
<total_seconds>".$agehpr."</total_seconds>
<years>".$hpr_years."</years>
<months>".$hpr_months."</months>
<days>".$hpr_days."</days>
</since_rename>
</age>
<shows>
<total>".$totalshows."</total>
<twat>300</twat>
<hpr>".$totalhpr."</hpr>
<duration>".$total_duration."</duration>
<human_duration>".$human_total_duration."</human_duration>
</shows>
<hosts>".$num_of_hosts."</hosts>
<slot>
<next_free>".$days_to_wait."</next_free>
<no_media>".$un_delivered."</no_media>
</slot>
<queue>
<number_future_hosts>".$num_future_hosts."</number_future_hosts>
<number_future_shows>".$num_future_shows."</number_future_shows>
<unprocessed_comments>".$unprocessed_comments."</unprocessed_comments>
<submitted_shows>".$num_submitted_shows."</submitted_shows>
<shows_in_workflow>".$new_shows."</shows_in_workflow>
<emergency>".$emergency_shows."</emergency>
</queue>
</stats>";
}
elseif ($format === "csv") {
header("Content-type: text/csv");
header("Content-disposition: inline; filename=hpr_stats.csv");
print "stats_generated,age_start,age_rename,age_since_start_total_seconds,age_since_start_years,age_since_start_months,age_since_start_days,age_since_rename_total_seconds,age_since_rename_years,age_since_rename_months,age_since_rename_days,shows_total,shows_twat,shows_hpr,hosts,slot_next_free,slot_no_media,number_future_hosts,number_future_shows,unprocessed_comments,shows_in_workflow,queue_emergency,duration\n";
print "${current_time},2005-09-19T00:00:00Z,2007-12-31T00:00:00Z,${agetwat},${twat_years},${twat_months},${twat_days},${agehpr},${hpr_years},${hpr_months},${hpr_days},${totalshows},300,${totalhpr},${num_of_hosts},${days_to_wait},${un_delivered},${num_future_hosts},${num_future_shows},${unprocessed_comments},${new_shows},${emergency_shows},${total_duration}\n";
}
else {
Header('Content-type: text/tab-separated-values');
header("Content-disposition: inline; filename=hpr_stats.txt");
printf("Started:\t%d years, %d months, %d days ago (2005-09-19)\n", $twat_years, $twat_months, $twat_days);
printf("Renamed HPR:\t%d years, %d months, %d days ago (2007-12-31)\n", $hpr_years, $hpr_months, $hpr_days);
echo "Total Shows:\t" . $totalshows . "\n";
echo "Total TWAT:\t300\n";
echo "Total HPR:\t" . $totalhpr . "\n";
echo "Duration:\t" . $total_duration . "\n";
echo "Human Duration:\t" . $human_total_duration . "\n";
echo "HPR Hosts:\t${num_of_hosts}\n";
echo "Days to next free slot:\t${days_to_wait}\n";
echo "Hosts in Queue:\t$num_future_hosts\n";
echo "Shows in Queue:\t$num_future_shows\n";
echo "Comments waiting approval:\t$unprocessed_comments\n";
echo "Files on the FTP Server:\t$new_shows\n";
echo "Number of Emergency Shows:\t$emergency_shows\n";
echo "Days until show without media:\t$un_delivered\n";
print "$current_time,$agetwat,$agehpr,$totalshows,300,$totalhpr,$num_of_hosts,$days_to_wait,$num_future_hosts,$num_future_shows,$unprocessed_comments,$new_shows,$emergency_shows,$un_delivered";
// print_r($show_array);
}
mysql_close();
?>

View File

@ -90,7 +90,6 @@ print '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
?> ?>
<rss version="2.0" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" > <rss version="2.0" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" >
<?php print "<!--\n${query}\n-->\n"; ?>
<channel> <channel>
<title>Hacker Public Radio - Future Feed</title> <title>Hacker Public Radio - Future Feed</title>
<link><?php print "${baseurl}"; ?>about.html</link> <link><?php print "${baseurl}"; ?>about.html</link>

View File

@ -171,7 +171,6 @@ print '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
?> ?>
<rss version="2.0" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" > <rss version="2.0" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" >
<?php print "<!--\n${query}\n-->"; ?>
<channel> <channel>
<title>Hacker Public Radio</title> <title>Hacker Public Radio</title>
<link>https://hackerpublicradio.org/about.html</link> <link>https://hackerpublicradio.org/about.html</link>