From bbaa57bed9332ced99fb8d9b1681a6872f536c41 Mon Sep 17 00:00:00 2001
From: Ken Fallon
Date: Sun, 2 Jul 2023 16:47:44 +0200
Subject: [PATCH] Initial push of the dynamic code
---
README.md | 24 +-
cms/add_show.php | 403 +++++++++++++++++++++++++++++
cms/comment_process.php | 75 ++++++
cms/say.php | 111 ++++++++
cms/schedule.php | 164 ++++++++++++
cms/status.php | 137 ++++++++++
hub/412.shtml | 14 ++
hub/calendar.php | 301 ++++++++++++++++++++++
hub/comment_confirm.php | 304 ++++++++++++++++++++++
hub/footer.html | 83 ++++++
hub/header.html | 67 +++++
hub/index.php | 3 +
hub/request.php | 209 +++++++++++++++
hub/request_confirm.php | 331 ++++++++++++++++++++++++
hub/upload.php | 297 ++++++++++++++++++++++
hub/upload_confirm.php | 546 ++++++++++++++++++++++++++++++++++++++++
ini/credentials.php | 16 ++
ini/hub.cms.htaccess | 12 +
ini/include.php | 339 +++++++++++++++++++++++++
ini/www.htaccess | 90 +++++++
www/rss-future.php | 214 ++++++++++++++++
www/rss.php | 303 ++++++++++++++++++++++
22 files changed, 4042 insertions(+), 1 deletion(-)
create mode 100644 cms/add_show.php
create mode 100755 cms/comment_process.php
create mode 100644 cms/say.php
create mode 100644 cms/schedule.php
create mode 100644 cms/status.php
create mode 100755 hub/412.shtml
create mode 100644 hub/calendar.php
create mode 100644 hub/comment_confirm.php
create mode 100644 hub/footer.html
create mode 100644 hub/header.html
create mode 100644 hub/index.php
create mode 100644 hub/request.php
create mode 100644 hub/request_confirm.php
create mode 100644 hub/upload.php
create mode 100755 hub/upload_confirm.php
create mode 100644 ini/credentials.php
create mode 100644 ini/hub.cms.htaccess
create mode 100644 ini/include.php
create mode 100644 ini/www.htaccess
create mode 100644 www/rss-future.php
create mode 100644 www/rss.php
diff --git a/README.md b/README.md
index 1cb36e7..45e2340 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,25 @@
# hpr_hub
-The dynamic code for the Hacker Public Radio project.
\ No newline at end of file
+The dynamic code for the Hacker Public Radio project.
+
+It consists of several directories
+
+## www
+
+This directory contains the static content that the site uses.
+
+There are some [rss php files](https://repo.anhonesthost.net/rho_n/hpr_generator/issues/140) that will be converted to statically rendered files.
+
+## hub
+
+This contains the files necessary to display the queue, upload shows, and submit comments.
+
+## cms
+
+Some tooling used by the Janitors to process comments, and shows.
+
+## ini
+
+Some sanitize settings files needed.
+
+
diff --git a/cms/add_show.php b/cms/add_show.php
new file mode 100644
index 0000000..3bc4267
--- /dev/null
+++ b/cms/add_show.php
@@ -0,0 +1,403 @@
+ 100 ) {
+ problem("ERROR: Title length is not OK");
+}
+logextra( "Title length is OK" );
+$title = $_POST["title"];
+
+if ( empty($_POST["summary"]) or strlen( $_POST["summary"]) > 200 or strlen(str_replace('\\', '', $_POST["summary"])) > 100 ) {
+ problem("ERROR: Summary length is not OK");
+}
+logextra( "Summary length is OK" );
+$summary = $_POST["summary"];
+
+if ( empty($_POST["explicit"]) ) {
+ problem("ERROR: explicit is missing");
+}
+logextra( "explicit exists" );
+
+if ( strcmp($_POST["explicit"], "Yes") !== 0 ) {
+ logextra( "explicit is not yes" );
+ if ( strcmp($_POST["explicit"], "Clean") !== 0 ) {
+ problem("ERROR: explicit needs to be either Yes or Clean");
+ }
+}
+logextra( "explicit is either Yes or Clean" );
+
+$explicit = $_POST["explicit"];
+
+if ( $explicit === "Clean" ) {
+ $explicit = 0;
+}
+else {
+ $explicit = 1;
+}
+if ( empty($_POST["episode_license"]) or strlen($_POST["episode_license"]) < 4 or strlen($_POST["episode_license"]) > 11 ) {
+ problem("ERROR: episode_license length is not fine");
+}
+logextra( "episode_license length is fine" );
+
+if ( !(
+ strcmp($_POST["episode_license"], "CC-BY-SA") === 0 or
+ strcmp($_POST["episode_license"], "CC-BY-NC-SA") === 0 or
+ strcmp($_POST["episode_license"], "CC-BY-NC-ND") === 0 or
+ strcmp($_POST["episode_license"], "CC-0") === 0 or
+ strcmp($_POST["episode_license"], "CC-BY-NC") === 0 or
+ strcmp($_POST["episode_license"], "CC-BY") === 0 or
+ strcmp($_POST["episode_license"], "Other") === 0 )
+ ) {
+ problem("ERROR: license is not a valid value");
+}
+logextra( "license is a valid value" );
+
+$episode_license = $_POST["episode_license"];
+
+if ( empty($_POST["notes"]) or strlen($_POST["notes"]) > 40000 ) {
+ problem("ERROR: Notes are missing not less than max");
+}
+logextra( "Notes are not missing and are less than max" );
+
+$notes = $_POST["notes"];
+
+if ( ( empty($_POST["series"]) and ($_POST["series"] != 0 ) ) or (strlen($_POST["series"]) > 3 ) ) {
+ problem("ERROR: Series id is not in the correct range");
+}
+$series = $_POST["series"];
+if ( (strval(intval($series)) != strval($series)) ){
+ problem("ERROR: series is not an int");
+}
+logextra( "series is int" );
+
+$result_series = mysqli_query($connection, "SELECT name FROM miniseries WHERE id='$series'");
+logextra( "Series id is in the correct range \"$series\"" );
+
+if (!isset($result_series)) {
+ problem("ERROR: Series has not been found");
+}
+$db_series_name_array = mysqli_fetch_row( $result_series );
+$db_series_name = $db_series_name_array[0];
+
+if ( empty($db_series_name) ) {
+ problem("ERROR: Series name \"${db_series_name}\" is missing from db ");
+}
+
+logextra( "Series name has been found in db: \"$db_series_name\"" );
+
+if ( empty($_POST["series_name"]) ) {
+ problem("ERROR: series_name length is not fine");
+}
+$series_name = $_POST["series_name"];
+
+if ( $series_name != $db_series_name ) {
+ problem("ERROR: series_name \"$series_name\" and db_series_name \"$db_series_name\" don't match.");
+}
+
+logextra( "series_name checkes passed: \"$series_name\"" );
+
+if ( !empty($_POST["tags"]) and strlen($_POST["tags"]) > 100 ) {
+ problem("ERROR: Tags are not the correct length");
+}
+logextra( "Tags are the correct length" );
+$tags = $_POST["tags"];
+
+#############
+# Host checks
+
+if ( empty($_POST["host_name"]) or strlen($_POST["host_name"]) > 40 ) {
+ problem("ERROR: host_name is not set and not the correct length");
+}
+logextra( "host_name is set and correct length" );
+$host_name = $_POST["host_name"];
+
+
+if ( strlen($_POST["host_profile"]) > 2000 ) {
+ problem("ERROR: host_profile is not the correct length");
+}
+logextra( "host_profile is correct length" );
+
+$host_profile = $_POST["host_profile"];
+
+if ( empty($_POST["host_license"]) or strlen($_POST["host_license"]) < 4 or strlen($_POST["host_license"]) > 11 ) {
+ problem("ERROR: host_license is not in the correct range");
+}
+logextra( "host_license is in the correct range" );
+
+if ( !(
+ strcmp($_POST["host_license"], "CC-BY-SA") === 0 or
+ strcmp($_POST["host_license"], "CC-BY-NC-SA") === 0 or
+ strcmp($_POST["host_license"], "CC-BY-NC-ND") === 0 or
+ strcmp($_POST["host_license"], "CC-0") === 0 or
+ strcmp($_POST["host_license"], "CC-BY-NC") === 0 or
+ strcmp($_POST["host_license"], "CC-BY") === 0 or
+ strcmp($_POST["host_license"], "Other") === 0 )
+ ) {
+ problem("ERROR: host_license is not a predfined value");
+}
+logextra( "host_license is a predfined value" );
+
+$host_license = $_POST["host_license"];
+
+if ( $_POST["hostid"] == 0 ) {
+ problem("ERROR: hostid is 0");
+}
+logextra( "hostid is not 0" );
+
+if ( empty($_POST["hostid"]) ) {
+ problem("ERROR: hostid doesn't exists ");
+}
+logextra( "hostid exists " );
+
+$result = mysqli_query($connection, 'SELECT MAX(hostid) FROM hosts;');
+if (!isset($result)) {
+ problem("ERROR: could not get the max host from db");
+}
+$maxhost_array = mysqli_fetch_row( $result );
+$maxhost = $maxhost_array[0];
+logextra( "retrieved the max host from db" );
+
+$hostid = $_POST["hostid"];
+if ( (strval(intval($hostid)) != strval($hostid)) ){
+ problem("ERROR: host id is not an int");
+}
+logextra( "host id is int" );
+
+if ( ( intval($hostid) < 0 ) or ( intval($hostid) > $maxhost ) ){
+ problem("ERROR: host id \"$hostid\" is not in the correct range \" $maxhost \"");
+}
+logextra( "host id is int, and in the correct range" );
+
+$query = "SELECT * FROM `hosts` WHERE `hostid` = '$hostid' and `host` = '$host_name';";
+$result = @mysqli_query($connection, $query);
+$db = mysqli_fetch_array($result, MYSQLI_ASSOC);
+
+logextra( "Getting this host from the db" );
+
+if ( ( $db["hostid"] != $hostid ) or ( $db["host"] != $host_name ) ) {
+ problem("ERROR: Could not find the host \"" . $db["hostid"] ."\", \"" . $db["host"] . "\" in the db \"${hostid}\", \"${host_name}\"" . $query );
+}
+logextra( "Found this reservation from the db" );
+
+if ( ( $db["profile"] != "$host_profile" ) or ( $db["license"] != "$host_license" ) ) {
+ logextra("The host_license is different to that in the db");
+ $query = "UPDATE `hosts` SET `profile` = '$host_profile', `license` = '$host_license' WHERE `hosts`.`hostid` = '$hostid';";
+ $result = mysqli_query($connection, $query );
+ if (!isset($result)) {
+ problem("ERROR: could not update the host profile");
+ } else {
+ logextra( "Updating the host profile" );
+ }
+}
+logextra( "The host_license is the same to that in the db" );
+
+##############
+# Episode Check
+// SHOW_SUBMITTED → METADATA_PROCESSED → SHOW_POSTED → MEDIA_TRANSCODED → UPLOADED_TO_IA → UPLOADED_TO_RSYNC_NET
+
+
+if ( !empty($_POST["ep_num"]) and isset( $_POST["ep_num"] ) ) {
+ $ep_num = intval( $_POST["ep_num"] );
+}
+else {
+ problem("ERROR: ep_num is empty");
+}
+
+// // SELECT MAX(ep_num) FROM `reservations` → 3627
+// // SELECT MIN(ep_num) FROM `reservations` WHERE ep_num > 0 → 3582
+//
+$result = mysqli_query($connection, 'SELECT MAX(ep_num) FROM `reservations`;');
+if (!isset($result)) {
+ problem("ERROR: Can't get max eps from reservations");
+}
+$max_eps_array = mysqli_fetch_row( $result );
+$max_eps = $max_eps_array[0];
+mysqli_free_result($result);
+
+$result = mysqli_query($connection, 'SELECT MIN(ep_num) FROM `reservations` WHERE ep_num > 0;');
+if (!isset($result)) {
+ problem("ERROR: Can't get min eps from reservations");
+}
+$min_eps_array = mysqli_fetch_row( $result );
+$min_eps = $min_eps_array[0];
+mysqli_free_result($result);
+
+if ( empty( $ep_num ) ) {
+ problem("ERROR: ep_num is empty");
+}
+
+if ( $ep_num < $min_eps ) {
+ problem("ERROR: ep_num is too small");
+}
+
+if ( $ep_num > $max_eps ) {
+ problem("ERROR: ep_num is too big");
+}
+
+if ( intval($ep_num) === 0 ) {
+ problem("ERROR: ep_num is 0");
+}
+else {
+ $ep_num = intval($ep_num);
+}
+
+$result = mysqli_query($connection, "SELECT ep_num FROM reservations WHERE ep_num='$ep_num' AND status='METADATA_PROCESSED';");
+if (!isset($result)) {
+ problem("ERROR: Cant get info from reservations db");
+}
+$db_ep_num_array = mysqli_fetch_row( $result );
+$db_ep_num = $db_ep_num_array[0];
+mysqli_free_result($result);
+
+if ( $db_ep_num != $ep_num ){
+ problem("ERROR: Cant find $ep_num with status of METADATA_PROCESSED");
+}
+
+$result = mysqli_query($connection, "SELECT `id` FROM `eps` WHERE `id` = '$ep_num';");
+if (!isset($result)) {
+ problem("ERROR: The show $ep_num is already in the eps db");
+}
+$db_ep_num_array = mysqli_fetch_row( $result );
+$db_ep_num = $db_ep_num_array[0];
+mysqli_free_result($result);
+if ( !empty( $db_ep_num ) ) {
+ problem("ERROR: $ep_num is already in the eps table");
+}
+if ( intval($db_ep_num) === $ep_num ) {
+ problem("ERROR: $ep_num is already in the eps table");
+}
+logextra( "ep_num checkes passed: $ep_num" );
+
+
+if ( !preg_match("/^\d{4}-\d{2}-\d{2}$/", $_POST["ep_date"]) ) {
+ problem("ERROR: ep_date fails the regex match ");
+}
+else {
+ $ep_date = $_POST["ep_date"];
+}
+
+if ( strtotime($ep_date) === false ) {
+ problem("ERROR: ep_date didn't convert to date");
+}
+else {
+ $ep_date_epoch = strtotime($ep_date);
+}
+logextra( "ep_date checkes passed: $ep_date" );
+
+
+if ( !empty($_POST["duration"]) and isset( $_POST["duration"] ) ) {
+ $duration = intval( $_POST["duration"] );
+}
+else {
+ problem("ERROR: duration is empty");
+}
+
+if ( empty( $duration ) ) {
+ problem("ERROR: duration is empty");
+}
+
+if ( $duration < 50 ) {
+ problem("ERROR: duration is too small");
+}
+
+if ( $duration > 26830 ) {
+ problem("ERROR: duration is too big");
+}
+
+if ( intval($duration) === 0 ) {
+ problem("ERROR: duration is 0");
+}
+else {
+ $duration = intval($duration);
+}
+logextra( "duration checkes passed: $duration" );
+
+$title = mysqli_real_escape_string( $connection, $title );
+$summary = mysqli_real_escape_string( $connection, $summary );
+$notes = mysqli_real_escape_string( $connection, $notes );
+$tags = mysqli_real_escape_string( $connection, $tags );
+
+$query_add = "INSERT INTO eps VALUES ('$ep_num', '{$ep_date}', '{$title}', '{$duration}', '{$summary}', '{$notes}', '{$hostid}', '{$series}', '{$explicit}', '{$episode_license}', '{$tags}', '0', '0', '0')";
+
+$result = mysqli_query($connection, $query_add );
+if(!$result) {
+ problem("ERROR: DB problem - The show $ep_num was not added to the eps db.");
+}
+if (mysqli_errno( $connection )) {
+ $error = "MySQL error ".mysqli_errno( $connection ).": ".mysqli_error()."\n";
+ problem("ERROR: MySQL error- The show $ep_num was not added to the eps db.\n$error");
+}
+
+$result = mysqli_query($connection, "SELECT `id` FROM `eps` WHERE `id` = '$ep_num';");
+if (!isset($result)) {
+ problem("ERROR: DB problem - The show $ep_num has not been added to the eps db");
+}
+$db_ep_num_array = mysqli_fetch_row( $result );
+$db_ep_num = $db_ep_num_array[0];
+mysqli_free_result($result);
+if (mysqli_errno( $connection )) {
+ $error = "MySQL error ".mysqli_errno( $connection ).": ".mysqli_error()."\n";
+ problem("ERROR: MySQL error- The show $ep_num was not added to the eps db.\n$error");
+}
+
+$result = mysqli_query($connection, "UPDATE reservations SET `status` = 'SHOW_POSTED' WHERE `ep_num` = '$ep_num' AND status='METADATA_PROCESSED';" );
+if (!isset($result)) {
+ problem("ERROR: DB problem - The show $ep_num has not been added to the eps db");
+}
+if (mysqli_errno( $connection )) {
+ $error = "MySQL error ".mysqli_errno( $connection ).": ".mysqli_error()."\n";
+ problem("ERROR: Could not update the show reservation to SHOW_POSTED in the db");
+}
+
+logextra( "Finished $ep_num ." );
+?>
diff --git a/cms/comment_process.php b/cms/comment_process.php
new file mode 100755
index 0000000..e592b23
--- /dev/null
+++ b/cms/comment_process.php
@@ -0,0 +1,75 @@
+ $v) {
+ ++$num_get_args;
+}
+if ( $num_get_args !== 2 ){
+ # they are trying to GET on a POST request
+ naughty("638709cc1d7f107c024eb2a663675e8c");
+}
+
+if ( empty($_GET["key"]) or empty($_GET["action"]) ) {
+ naughty("991ce46448d64b90bc8a837b58b7ad20");
+}
+
+if ( empty($_GET["key"]) or strlen($_GET["key"]) !== 45 ) {
+ naughty("c9e5ea8d870dda8db08bc570cbed7f84");
+}
+
+if ( !empty($_GET["key"]) and
+ isset( $_GET['key'] ) and
+ strlen( $_GET['key'] ) === 45 and
+ strlen( htmlspecialchars( stripslashes( strip_tags( $_GET['key'] ) ) ) ) === 45 and
+ ctype_xdigit( $_GET['key'] )
+ ) {
+ $key = htmlspecialchars( stripslashes( strip_tags( $_GET['key'] ) ) );
+}
+else {
+ naughty("868d9cc49b2f1e4a9319a8e8755d6189");
+}
+
+if ( !in_array($_GET["action"], array('approve','delete','block'), true ) ) {
+ naughty("c0ca62c918f9bb0ab72da0cdf2f2e8df ");
+}
+else {
+ $action = $_GET["action"];
+}
+
+$comment_directory = "/home/hpr/comments";
+
+if ( ! file_exists( $comment_directory ) ) {
+ # Looks like the comments directory has not been created
+ naughty("0fdffa1dbe94e0730cef457be93ebf40");
+}
+
+$files = glob( "${comment_directory}/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z_*_${key}.json" );
+if (count($files) === 0) {
+ naughty("3efef2971727905064855d7866cb0059");
+}
+else {
+ $file = $files[0];
+}
+
+list($begin, $file_ip, $end) = explode('_', $file);
+
+if ( ! filter_var($file_ip, FILTER_VALIDATE_IP) ) {
+ naughty("70ebe39c92b393c288e41a4d3128b5da");
+}
+
+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 );
+}
+
+unlink( "${file}" );
+http_response_code(200);
+
+
+// exit;
+
+?>
diff --git a/cms/say.php b/cms/say.php
new file mode 100644
index 0000000..72886f3
--- /dev/null
+++ b/cms/say.php
@@ -0,0 +1,111 @@
+ $v) {
+ ++$num_get_args;
+ }
+ if ( (strval(intval($id)) != strval($id)) OR ( intval($id) <= 0 ) OR ( intval($id) > $maxhost ) OR ( $num_get_args > 1 ) ){
+ exit;
+ }
+ $query = "SELECT id FROM eps WHERE id = '$id'";
+ $result = @mysqli_query($connection, $query);
+ if($result === FALSE) {
+ call412( "a9564ebc3289b7a14551baf8ad5ec60a" );
+ }
+ else {
+ $db = mysqli_fetch_array($result, MYSQLI_ASSOC);
+ if ( empty($db["id"]) ) {
+ call412( "a9564ebc3289b7a14551baf8ad5ec60a" );
+ }
+ }
+}
+else {
+ call412( "a9564ebc3289b7a14551baf8ad5ec60a" );
+ exit;
+}
+Header('Content-type: text/tab-separated-values');
+header("Content-disposition: inline; filename=say.txt");
+
+$ep_retrieve = "SELECT UNIX_TIMESTAMP(eps.date) AS timestamp, eps.title, eps.duration, eps.summary, hosts.host, eps.hostid, eps.series, eps.license, eps.explicit FROM eps, hosts WHERE hosts.valid = '1' AND id = '$id' AND eps.hostid = hosts.hostid";
+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'];
+ $series = $row['series'];
+ $license = $row['license'];
+ $explicit = $row['explicit'];
+
+ $id = fixid($id);
+
+ $host_retrieve = "SELECT host, espeak_name FROM hosts WHERE hostid = '$hostid'";
+ $result1 = mysqli_query($connection, $host_retrieve);
+ $row1 = mysqli_fetch_array($result1);
+ $espeak_name = $row1['espeak_name'];
+
+ $epcountquery = "SELECT count( id ) AS total FROM eps WHERE hostid = '$hostid'";
+ $result2 = mysqli_query($connection, $epcountquery);
+ $row2 = mysqli_fetch_array($result2);
+ $total = $row2['total'];
+ if ( $total == 1 ) {
+ $host_notes = ". It is the first show by new host ${espeak_name}, ";
+ }
+ else if ($total % 10 == 0) {
+ $host_notes = ". It is the ${total}th show of ${espeak_name}, ";
+ }
+ else {
+ $host_notes = ". It is hosted by ${espeak_name}, ";
+ }
+ }
+}
+$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}.";
+if ($series > "0"){
+ $series_query = mysqli_query($connection, "SELECT name, description FROM miniseries WHERE id = '$series'");
+ $series_result = mysqli_fetch_array($series_query);
+ $series_title = $series_result['name'];
+ $desc = $series_result['description'];
+ $HPR_summary = "${HPR_summary} It is part of the series \"$series_title\"";
+}
+$HPR_summary = "${HPR_summary} ${host_notes} and is about " . round($duration/60) . " minutes long. It carries ";
+if ($explicit == 0) {
+ $HPR_summary = "${HPR_summary} a clean flag. ";
+ $explicit = "Clean";
+}
+else{
+ $HPR_summary = "${HPR_summary} an explicit flag. ";
+ $explicit = "Explicit";
+}
+if ( !empty( $summary ) ) {
+ $HPR_summary = "${HPR_summary}. The summary is. $summary";
+}
+if (strcmp($license, "CC-BY-SA" ) !== 0) {
+ $HPR_summary = "${HPR_summary}. Todays show is licensed under a $license license.";
+}
+
+$HPR_summary = str_replace($host,$espeak_name,$HPR_summary);
+
+echo "HPR_summary: ${HPR_summary}\n";
+echo "HPR_album: Hacker Public Radio\n";
+echo "HPR_artist: ${host}\n";
+echo "HPR_hostid: ${hostid}\n";
+echo "HPR_comment: https://hackerpublicradio.org ${explicit}; $summary\n";
+echo "HPR_genre: Podcast\n";
+echo "HPR_license: ${license}\n";
+echo "HPR_title: ${title}\n";
+echo "HPR_track: $id\n";
+echo "HPR_year: " . date("Y", $date) . "\n";
+echo "HPR_duration: ${duration}\n";
+echo "HPR_explicit: ${explicit}\n";
+?>
diff --git a/cms/schedule.php b/cms/schedule.php
new file mode 100644
index 0000000..deb0992
--- /dev/null
+++ b/cms/schedule.php
@@ -0,0 +1,164 @@
+= '$current_episode_date' ORDER BY date DESC";
+
+$ep_retrieve = "SELECT
+ hosts.host,
+ eps.id,
+ eps.title,
+ eps.date,
+ COUNT( assets.extension) AS numfiles
+FROM
+ eps
+ LEFT JOIN hosts ON eps.hostid = hosts.hostid
+ LEFT JOIN assets ON eps.id = assets.episode_id
+WHERE
+ eps.valid = 1
+ AND eps.date >= '$current_episode_date'
+GROUP BY eps.id;";
+
+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'];
+ $numfiles = $row['numfiles'];
+ if( isset($numfiles) and $numfiles >= 3 ) {
+ $status = "Finished";
+ }
+ else {
+ $status = "Reserved";
+ }
+ $show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
+ "title" => $title,
+ "host" => $host,
+ "status" => $status
+ );
+ }
+}
+// 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
+$ep_retrieve = "
+SELECT
+ reservations.ep_num,
+ reservations.ep_date,
+ reservations.status
+FROM
+ reservations
+WHERE
+ reservations.verified = 1
+ AND reservations.ep_date >= '$current_episode_date'
+ORDER BY
+ reservations.ep_date DESC";
+
+if ($result = mysqli_query($connection, $ep_retrieve)) {
+ while ($row = mysqli_fetch_array($result)) {
+ $id = $row['ep_num'];
+ $date = $row['ep_date'];
+ $status = $row['status'];
+ $show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
+ "title" => $status,
+ "host" => "Unverified",
+ "status" => "Processing"
+ );
+ }
+}
+
+// Populate array with temporary reservations.
+$ep_retrieve = "SELECT r.ep_num, r.ep_date, r.timestamp + INTERVAL 1 HOUR - UTC_TIMESTAMP() AS seconds_to_expiration FROM reservations r
+WHERE r.timestamp + INTERVAL 1 HOUR > UTC_TIMESTAMP() AND r.verified =0 AND r.ep_date >= '$current_episode_date' ORDER BY r.ep_date DESC";
+
+if ($result = mysqli_query($connection, $ep_retrieve)) {
+ while ($row = mysqli_fetch_array($result)) {
+ $id = $row['ep_num'];
+ $date = $row['ep_date'];
+ $seconds_to_expiration = $row['seconds_to_expiration'];
+ $minutes = floor($seconds_to_expiration / 60) + 1;
+ $show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
+ "title" => " Available again in $minutes minutes",
+ "host" => "Unverified",
+ "status" => "Locked"
+ );
+ }
+}
+
+$ep_retrieve = "SELECT
+ hosts.host,
+ eps.id,
+ eps.title,
+ eps.date
+FROM
+ eps,
+ hosts,
+ assets
+WHERE
+ eps.valid = 1
+ AND eps.hostid = hosts.hostid
+ AND eps.id = assets.episode_id
+ AND assets.extension = 'ogg'
+ 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" => "Finished"
+ );
+ }
+}
+
+
+echo json_encode($show_array, JSON_FORCE_OBJECT);
+?>
+
diff --git a/cms/status.php b/cms/status.php
new file mode 100644
index 0000000..17056a2
--- /dev/null
+++ b/cms/status.php
@@ -0,0 +1,137 @@
+ $v) {
+ ++$num_get_args;
+}
+if ( $num_get_args !== 2 ){
+ $result = mysqli_query($connection, "SET time_zone = '+0:00';");
+ if (!isset($result)) {
+ naughty("cca6408ae1febc3f07974177b2d04375");
+ }
+
+ header("Content-type: text/csv");
+ print "timestamp_epoc,ep_num,ep_date,key,status,email\n";
+ # 1649790226_3710_2022-10-21_b291590ce4ba23b519935bde53d0a5936255cd12e96b4
+ $query = "SELECT UNIX_TIMESTAMP(timestamp) as timestamp_epoc, `ep_num`, `ep_date`, `key`, `status`, `email` FROM `reservations` WHERE `ep_num` > 0 ORDER BY `ep_num` ASC";
+ if($result = mysqli_query($connection, $query)) {
+ while($row = mysqli_fetch_array($result)) {
+ //handle text color
+ print "{$row['timestamp_epoc']},{$row['ep_num']},{$row['ep_date']},{$row['key']},{$row['status']},{$row['email']}\n";
+ }
+ }
+ else {
+ naughty("2dcabda45255713ea9bf04523e804016");
+ }
+ mysqli_close($connection);
+ exit;
+}
+
+if ( empty($_GET["ep_num"]) or empty($_GET["status"]) ) {
+ naughty("32bedea129648f27701f2f2f3ff4b7b5");
+}
+
+if ( !in_array($_GET["status"], array('METADATA_PROCESSED','SHOW_POSTED','MEDIA_TRANSCODED','UPLOADED_TO_IA','UPLOADED_TO_RSYNC_NET','REMOVE_RESERVATION'), true ) ) {
+ naughty("88882bc97094e7aabf2a258756f917f5 ");
+}
+else {
+ $status = $_GET["status"];
+}
+
+if ( !empty($_GET["ep_num"]) and isset( $_GET["ep_num"] ) ) {
+ $ep_num = intval( $_GET["ep_num"] );
+}
+else {
+ naughty("ecb0ebc5b38b4c09226ccbfce05978cb");
+}
+
+// // SELECT MAX(ep_num) FROM `reservations` → 3627
+// // SELECT MIN(ep_num) FROM `reservations` WHERE ep_num > 0 → 3582
+//
+$result = mysqli_query($connection, 'SELECT MAX(ep_num) FROM `reservations`;');
+if (!isset($result)) {
+ naughty("360e6381ffca736b6f12056abd7dcc7d");
+}
+$max_eps_array = mysqli_fetch_row( $result );
+$max_eps = $max_eps_array[0];
+mysqli_free_result($result);
+
+$result = mysqli_query($connection, 'SELECT MIN(ep_num) FROM `reservations` WHERE ep_num > 0;');
+if (!isset($result)) {
+ naughty("6971b6d378292e8fc9583de6082eddf4");
+}
+$min_eps_array = mysqli_fetch_row( $result );
+$min_eps = $min_eps_array[0];
+mysqli_free_result($result);
+
+if ( empty( $ep_num ) ) {
+ naughty("6cf46a9b21e667c61b2c5bf87a7104f9 $ep_num");
+}
+
+if ( $ep_num < $min_eps ) {
+ naughty("bbcef7cd8a263dc57e85195935ad600a $ep_num < $min_eps");
+}
+
+if ( $ep_num > $max_eps ) {
+ naughty("a75115f3fa706ceee4b61971cd22b8f9 $ep_num > $max_eps");
+}
+
+// SHOW_SUBMITTED → METADATA_PROCESSED → SHOW_POSTED → MEDIA_TRANSCODED → UPLOADED_TO_IA → UPLOADED_TO_RSYNC_NET
+switch ($status) {
+ case "METADATA_PROCESSED":
+ $current_status="SHOW_SUBMITTED";
+ break;
+ case "SHOW_POSTED":
+ $current_status="METADATA_PROCESSED";
+ break;
+ case "MEDIA_TRANSCODED":
+ $current_status="SHOW_POSTED";
+ break;
+ case "UPLOADED_TO_IA":
+ $current_status="MEDIA_TRANSCODED";
+ break;
+ case "UPLOADED_TO_RSYNC_NET":
+ $current_status="UPLOADED_TO_IA";
+ break;
+ case "REMOVE_RESERVATION":
+ $query = "DELETE FROM reservations WHERE `ep_num` = '$ep_num' ";
+ $result = @mysqli_query($connection, $query);
+ if (mysqli_errno( $connection)) {
+ $error = "MySQL error ".mysqli_errno( $connection).": ".mysqli_error($connection)."\n";
+ problem("Could not update the show reservation to $status in the db");
+ }
+ mysqli_free_result($result);
+ mysqli_close($connection);
+ logextra( "$query");
+ die;
+}
+
+$result = mysqli_query($connection, "SELECT ep_num FROM reservations WHERE `ep_num` = '$ep_num' AND status='$current_status';");
+if (!isset($result)) {
+ naughty("7f2d7228ca355be6dd2a24769595b18f");
+}
+$db_ep_num_array = mysqli_fetch_row( $result );
+$db_ep_num = $db_ep_num_array[0];
+mysqli_free_result($result);
+if ( $db_ep_num != $ep_num ){
+ problem("da59731c6ae6d1ce0fa2fa9fc4e1e726 $db_ep_num != $ep_num");
+}
+
+$query = "UPDATE reservations SET `status` = '$status' WHERE `ep_num` = '$ep_num' AND status='$current_status';";
+$result = mysqli_query($connection, $query );
+if(!isset($result)) {
+ problem("8a76bb408877b1d33bf31ea96b6fc02f");
+}
+if (mysqli_errno( $connection )) {
+ $error = "MySQL error ".mysqli_errno( $connection).": ".mysqli_error($connection)."\n";
+ problem("Could not update the show reservation to $status in the db");
+}
+mysqli_close($connection);
+
+logextra( "UPDATE reservations SET `status` = '$status' WHERE ep_num='$ep_num' AND status='$current_status';");
+?>
diff --git a/hub/412.shtml b/hub/412.shtml
new file mode 100755
index 0000000..207d546
--- /dev/null
+++ b/hub/412.shtml
@@ -0,0 +1,14 @@
+
+
+
+
+Hacker Public Radio
+
+
+412 Precondition Failed
+
+Interesting.
+Why not record a show telling us about what you were trying to do ?
+
+
+
diff --git a/hub/calendar.php b/hub/calendar.php
new file mode 100644
index 0000000..ab31f08
--- /dev/null
+++ b/hub/calendar.php
@@ -0,0 +1,301 @@
+\n";
+
+// --------------------------------------------
+// Get latest published show
+
+$query = mysqli_query($connection, "SELECT max(date), max(id) from eps WHERE eps.date <= UTC_DATE()");
+$current_episode_array = mysqli_fetch_row($query);
+$current_episode_date = $current_episode_array[0];
+$current_episode_number = $current_episode_array[1];
+
+print "\n";
+print "\n";
+
+// --------------------------------------------
+// Get highest scheduled or reserved show
+
+$query = mysqli_query($connection, "SELECT MAX(id) FROM eps as maxid;");
+$max_episode_array = mysqli_fetch_row($query);
+$max_episode_number = $max_episode_array[0];
+print "\n";
+
+// --------------------------------------------
+// Populate array with future shows and reservations
+$show_array = array ();
+
+// 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,
+ COUNT( assets.extension) AS numfiles
+FROM
+ eps
+ LEFT JOIN hosts ON eps.hostid = hosts.hostid
+ LEFT JOIN assets ON eps.id = assets.episode_id
+WHERE
+ eps.valid = 1
+ AND eps.date >= '$current_episode_date'
+GROUP BY eps.id;";
+
+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'];
+ $numfiles = $row['numfiles'];
+ if( isset($numfiles) and $numfiles >= 3 ) {
+ $status = "Finished";
+ }
+ else {
+ $status = "Reserved";
+ }
+ $show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
+ "title" => $title,
+ "host" => $host,
+ "status" => $status
+ );
+ }
+}
+// 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
+$ep_retrieve = "
+SELECT
+ reservations.ep_num,
+ reservations.ep_date,
+ reservations.status
+FROM
+ reservations
+WHERE
+ reservations.verified = 1
+ AND reservations.ep_date >= '$current_episode_date'
+ORDER BY
+ reservations.ep_date DESC";
+
+if ($result = mysqli_query($connection, $ep_retrieve)) {
+ while ($row = mysqli_fetch_array($result)) {
+ $id = $row['ep_num'];
+ $date = $row['ep_date'];
+ $status = $row['status'];
+ $show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
+ "title" => $status,
+ "host" => "Unverified",
+ "status" => "Processing"
+ );
+ }
+}
+
+// Populate array with temporary reservations.
+$ep_retrieve = "SELECT r.ep_num, r.ep_date, r.timestamp + INTERVAL 1 HOUR - UTC_TIMESTAMP() AS seconds_to_expiration FROM reservations r
+WHERE r.timestamp + INTERVAL 1 HOUR > UTC_TIMESTAMP() AND r.verified =0 AND r.ep_date >= '$current_episode_date' ORDER BY r.ep_date DESC";
+
+if ($result = mysqli_query($connection, $ep_retrieve)) {
+ while ($row = mysqli_fetch_array($result)) {
+ $id = $row['ep_num'];
+ $date = $row['ep_date'];
+ $seconds_to_expiration = $row['seconds_to_expiration'];
+ $minutes = floor($seconds_to_expiration / 60) + 1;
+ $show_array[$id] = array ( "date" => date('Y-m-d', strtotime($date) ),
+ "title" => " Available again in $minutes minutes",
+ "host" => "Unverified",
+ "status" => "Locked"
+ );
+ }
+}
+
+$ep_retrieve = "SELECT
+ hosts.host,
+ eps.id,
+ eps.title,
+ eps.date
+FROM
+ eps,
+ hosts,
+ assets
+WHERE
+ eps.valid = 1
+ AND eps.hostid = hosts.hostid
+ AND eps.id = assets.episode_id
+ AND assets.extension = 'ogg'
+ 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" => "Finished"
+ );
+ }
+}
+
+
+// --------------------------------------------
+// Calculate the time to the next show
+
+# aria-label=""
+
+$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));
+
+?>
+
+
+Upload Your Show
+
+
+The HPR Schedule is entirely community driven and we recommend that you decide when your show will be released.
+
+
+
+There are only days to wait until next free slot. Please consider ">recording a show for us.
+
+
+- Review the updated ">Stuff you need to know page.
+- Select a date, or post to the reserve queue.
+- Click the link in the confirmation email
+- Then ">fill in a form.
+
+
+Add to the Reserve Queue ?
+
+
+request.php?id=9999">Post your show to the reserve queue if you don't care when it will be released. ">ⓘ
+
+
+Select a date in the current schedule ?
+
+
+Schedule the release day your show will be aired. ">ⓘ
+
+
+Next Two Months ">ⓘ
+
+
+
+
+" . date('D Y-m-d', strtotime($show_array[$slot]["date"])) . ": hpr${slot} " . $show_array[$slot]["title"] . " by " . $show_array[$slot]["host"] . "
\n";
+ }
+ else {
+ echo "${this_episode_date}: hpr${slot} ". $show_array[$slot]["status"]. ": " . $show_array[$slot]["title"] . ".
\n";
+ }
+ $sizeof_show_array--;
+ }
+ elseif ( empty( $show_array[$slot] ) ) {
+ echo "${this_episode_date}: hpr${slot} is available - upload now.
\n";
+ }
+ elseif ( $show_array[$slot]["valid"] == 0 ) {
+ echo "${this_episode_date}: hpr${slot} Unavailable.
\n";
+ }
+ $this_episode_date = date('D Y-m-d', strtotime($this_episode_date . ' + 1 weekday'));
+ $new_week_number = date('W', strtotime($this_episode_date));
+ if ( $week_number != $new_week_number ) {
+ $week_number = $new_week_number;
+ echo "----------------- Week ${week_number} -----------------
\n";
+ }
+}
+?>
+
+Also Scheduled
+\n" ;
+ if ( !empty( $show_array[$slot] ) ) {
+ if ( $show_array[$slot]["status"] === "Finished" ) {
+ echo "" . date('D Y-m-d', strtotime($show_array[$slot]["date"])) . ": hpr${slot} " . $show_array[$slot]["title"] . " by " . $show_array[$slot]["host"] . "
\n";
+ }
+ else {
+ echo "" . date('D Y-m-d', strtotime($show_array[$slot]["date"])) . ": hpr${slot} ". $show_array[$slot]["status"]. ": " . $show_array[$slot]["title"] . ".
\n";
+ }
+
+ $sizeof_show_array--;
+ }
+ $slot++;
+}
+?>
+
+
+Pick other dates
+
+If you wish to pick an available slot in the next 12 months then go directly to the request page.
+
+
+
+
+
diff --git a/hub/comment_confirm.php b/hub/comment_confirm.php
new file mode 100644
index 0000000..2f9866d
--- /dev/null
+++ b/hub/comment_confirm.php
@@ -0,0 +1,304 @@
+ comment_confirm.php > eps.php
+require "/home/hpr/php/include.php";
+
+$num_get_args = 0;
+
+foreach($_GET as $k => $v) {
+ ++$num_get_args;
+}
+
+if ( $num_get_args > 0 ){
+ # they didn't supply any arguments
+ naughty("9e756ee22b7cdcdb150a5baf167caa25 $num_get_args");
+}
+
+if ( empty($_POST["anti_spam_question"]) ) {
+ naughty("0601a23e358374c293b086bb75606cca");
+}
+
+if ( strlen($_POST["anti_spam_question"]) !== 6 ) {
+ naughty("6f51e6e7e6820b3fdda5d4ca0df14db1");
+}
+
+if (strcasecmp('public', $_POST["anti_spam_question"]) !== 0) {
+ naughty("6aef421ce05e3ac34f4cd91ae3248a45");
+}
+
+$comment_directory = "/home/hpr/comments";
+
+if ( ! file_exists( $comment_directory ) ) {
+ # Looks like the comments directory has not been created
+ naughty("d5342ea497f701656433e81fb5eed064");
+}
+
+$unprocessed_comments = iterator_count(new FilesystemIterator("$comment_directory", FilesystemIterator::SKIP_DOTS));
+
+if( $unprocessed_comments >= 10 ) {
+ # There has to be at least one comment here as they are calling the script, and too many is suspicious
+ naughty("093f42abee30e69e0e4d5125c70a0f7c");
+}
+
+# This is to prevent anything except hits from the web form.
+# Anyone wanting to script uploads can do so via ftp
+if ( $_SERVER['REQUEST_METHOD'] !== 'POST' ) {
+ naughty("87613fc139b251b673e1dd51e378e462");
+}
+
+if ( empty($_SERVER["REMOTE_ADDR"]) ) {
+ naughty("d7d0b6ab9689be244e1b6a8fbe6effba");
+}
+else {
+ $ip = $_SERVER["REMOTE_ADDR"];
+}
+
+if (count($_POST) !== 8) {
+ naughty("086fe155b0588de68fc5d9e4580254a8");
+}
+
+// Basic POST Checks
+if ( empty($_POST["comment_author_name"]) or strlen($_POST["comment_author_name"]) > 40 or strtolower($_POST["comment_author_name"]) == "testdog" ) {
+ naughty("294356cd36d3f9b75da4d8c0a6108881");
+}
+$comment_author_name = json_encode( $_POST["comment_author_name"] );
+
+if ( empty($_POST["comment_title"]) or strlen($_POST["comment_title"]) > 100 ) {
+ naughty("a89efb428cfe36996a65b371d5f4e303");
+}
+$comment_title = 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 ) {
+ naughty("cd57ab4d7b77a131ed3deb441bd93dcd");
+}
+$comment_text = json_encode( $_POST["comment_text"] );
+
+if ( empty($_POST["spammer"]) or strcmp($_POST["spammer"], "No") !== 0 ) {
+ naughty("b2ec68bd04cee0f64143ce4827a97e7c");
+}
+
+# We check to see if the eps_id has been suplied, that it's a integer, and that it's in our range.
+
+if (isset($_POST['eps_id'])){
+ $eps_id = intval( $_POST['eps_id'] );
+
+ $query = "SELECT COUNT(*) FROM eps WHERE id='$eps_id'";
+ $result = mysqli_query($connection, "$query");
+ $row = mysqli_fetch_array($result, MYSQLI_NUM);
+ $total = $row[0];
+ if ( !isset($result) or ( $total != 1 ) ) {
+ naughty("5348e3c2aee3644730c70d3f000bcb01");
+ }
+ mysqli_free_result($result);
+
+ $result = mysqli_query($connection, 'SELECT MAX(id) as max FROM eps;');
+ if (!isset($result)) {
+ naughty("f00fb1f47affc3286aadc15038cfd5d7");
+ }
+ while ($row = mysqli_fetch_array($result)) {
+ $max_eps = $row['max'];
+ }
+ mysqli_free_result($result);
+}
+else {
+ naughty("02c560adf1ff39b140fe8b7abe02fd31");
+}
+
+if ( intval($eps_id) <= 0 ){
+ naughty("2903eeac51bb479edb428ae3c896671c");
+}
+
+if ( intval($eps_id) > $max_eps ){
+ naughty("54aa65c12ba71f3dfc451ff5bc82c798");
+}
+
+if ( intval($eps_id) === 0 ) {
+ naughty("11fe1f9b76bf9f30e6a3a784832cb738");
+}
+else {
+ $eps_id = intval($eps_id);
+}
+
+# extra spam checks to see if they supplied the correct host id
+$query = "SELECT hosts.host, eps.title, eps.summary, eps.date, eps.hostid, eps.series, miniseries.name, eps.explicit FROM eps, hosts, miniseries WHERE eps.id='$eps_id' AND eps.valid=1 AND eps.hostid = hosts.hostid AND eps.series = miniseries.id";
+if ($result = mysqli_query($connection, $query)) {
+ while ($row = mysqli_fetch_array($result)) {
+ $host = $row['host'];
+ $title = $row['title'];
+ $summary = $row['summary'];
+ $ep_date = $row['date'];
+ $host_id = $row['hostid'];
+ $series_id = $row['series'];
+ $series_name = $row['name'];
+ $explicit = $row['explicit'];
+ }
+}
+else {
+ naughty("c34561d684ad97241c95a1287688638b");
+}
+mysqli_free_result($result);
+
+if ( empty($_POST["hostid"]) or intval($_POST["hostid"]) != $host_id ) {
+ naughty("b4d71481b7055272728094292fd2a562");
+}
+
+if ( empty($_POST["justification"]) or strlen($_POST["justification"]) > 200 or strlen($_POST["justification"]) < 20) {
+ naughty("156d2d2d5780bd7f4a750f7c162b3394");
+}
+
+# Checks to see how old the show is
+#$current_episode_number = GetLatestPublishedShow($connection);
+list ($current_episode_date, $current_episode_number) = GetLatestPublishedShow($connection);
+
+if ( ( $eps_id <= $current_episode_number ) and ( $eps_id >= ( $current_episode_number - 20 ) ) ) {
+ if ( strcmp($_POST["justification"], "No justification is asked for or required.") !== 0 ) {
+ naughty("9357d78bf73b03ee2dd902a4c975f91d");
+ }
+ else {
+ $justification = json_encode("Current Comment");
+ }
+}
+else {
+ if ( strcmp($_POST["justification"], "No justification is asked for or required.") === 0 ) {
+ print ">" . $_POST["justification"] ."< eps_id: $eps_id, current_episode_number: $current_episode_number, ";
+ naughty("df4af9bdd0302f672d6311c76bdc461a");
+ }
+ else {
+ $justification = json_encode( $_POST["justification"] );
+ }
+}
+
+
+
+if ( empty($_SERVER["REMOTE_ADDR"]) ) {
+ naughty("611144d4c0d575fffbf8f3ef11f8ad68");
+}
+else {
+ $ip = $_SERVER["REMOTE_ADDR"];
+}
+$comment_ip = json_encode( $ip );
+
+// OK You convinced me.
+
+$key = uniqid(md5(rand()));
+$timestamp = time()+date("Z");
+$timestamp = gmdate("Y-m-d\TH:i:s\Z",$timestamp);
+$comment_file = "${comment_directory}/${timestamp}_${ip}_${key}.json";
+$timestamp = json_encode($timestamp);
+$comment_key = json_encode( $key );
+if ( file_exists( $comment_file ) ) {
+ naughty("ef5d14b33b262bfbf5d40544fdeb9ec3");
+}
+
+$comment_data = "{
+ \"eps_id\": $eps_id,
+ \"ip\": \"$ip\",
+ \"comment_timestamp\": $timestamp,
+ \"comment_author_name\": $comment_author_name,
+ \"comment_title\": $comment_title,
+ \"comment_text\": $comment_text,
+ \"justification\": $justification,
+ \"key\": $comment_key
+}";
+
+file_put_contents($comment_file, $comment_data );
+
+if ( filesize( $comment_file ) > 4000 ) {
+ naughty("56e00e793a27168511d1cfda11d3bc55");
+}
+
+// Mail the comment
+
+use PHPMailer\PHPMailer\PHPMailer;
+use PHPMailer\PHPMailer\Exception;
+use PHPMailer\PHPMailer\SMTP;
+
+require_once('/home/hpr/php/PHPMailer/Exception.php');
+require_once('/home/hpr/php/PHPMailer/PHPMailer.php');
+require_once('/home/hpr/php/PHPMailer/SMTP.php');
+
+date_default_timezone_set('Etc/UTC');
+
+$mailer = new PHPMailer(true);
+$mailer->isSMTP();
+$mailer->Host = "$mailerHost";
+$mailer->SMTPAuth = true;
+$mailer->SMTPSecure = "ssl";
+$mailer->Port = "465";
+$mailer->Username = "$mailerUsername";
+$mailer->Password = "$mailerPassword";
+
+
+// Set up to, from, and the message body. The body doesn't have to be HTML; check the PHPMailer documentation for details.
+$mailer->Sender = 'robot@hobbypublicradio.com';
+$mailer->addReplyTo('admin@hackerpublicradio.org', 'HPR Admins');
+$mailer->setFrom('robot@hobbypublicradio.com', 'HPR Robot');
+$mailer->addBCC('admin@hackerpublicradio.org');
+$mailer->addBCC('admin@hobbypublicradio.org');
+$mailer->AddAddress('comments@hackerpublicradio.org');
+$mailer->isHTML(false);
+$mailer->Subject = "New Comment for show hpr${eps_id} on ${ep_date} ${key}";
+$mailer->MsgHTML("hpr${eps_id} on ${ep_date} by ${host} with the title ${title} \"${summary}\"
+
+See attachment for the json comment file.
+
+
+There are now " . ++$unprocessed_comments . " unprocessed comments.
+
+
+Thanks,
+HPR Bot
+
+" . date('Y-m-d\TH:i:s') . "\t" . getUserIP() . "\t" . $key . "\t" . $_SERVER["HTTP_USER_AGENT"] . "
"
+);
+$mailer->AltBody = "hpr${eps_id} on ${ep_date} by ${host} with the title ${title} \"${summary}\"
+
+See attachment for the json comment file.
+
+There are now ${unprocessed_comments} unprocessed comments.
+
+Thanks,
+HPR Bot
+" . date('Y-m-d\TH:i:s') . "\t" . getUserIP() . "\t" . $key . "\t" . $_SERVER["HTTP_USER_AGENT"] . "\n";
+$mailer->addAttachment($comment_file, "${key}.json", "base64", "application/json");
+
+//send the message, check for errors
+if (!$mailer->send()) {
+ echo 'Mailer Error: ' . $mailer->ErrorInfo;
+}
+
+
+$body="give";
+//$body="index_full";
+include 'header.html';
+
+?>
+
+
+
+
+
+
+ Thank you for your comment. A moderator will get to your comment at some point.
+
+
+ Thanks,
+
+ HPR Bot
+
+
+
+
+
+
+
+
+
+
diff --git a/hub/footer.html b/hub/footer.html
new file mode 100644
index 0000000..9616906
--- /dev/null
+++ b/hub/footer.html
@@ -0,0 +1,83 @@
+
+
+
+
+