From ffa3ab8a7499e051b947648bd2283355f1b07bca Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Thu, 25 Jun 2020 01:28:07 -0500 Subject: [PATCH] Fix permissions on OPDS feeds --- lib/OpdsFeed.php | 24 +++++++++++++++--------- scripts/deploy-ebook-to-www | 5 ++++- templates/OpdsFeed.php | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/OpdsFeed.php b/lib/OpdsFeed.php index 05193dce..6d1f47ec 100644 --- a/lib/OpdsFeed.php +++ b/lib/OpdsFeed.php @@ -20,17 +20,23 @@ class OpdsFeed{ } private function Sha1Entries(string $xmlString): string{ - $xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', $xmlString)); - $xml->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/'); - $xml->registerXPathNamespace('schema', 'http://schema.org/'); - $entries = $xml->xpath('/feed/entry') ?? []; + try{ + $xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', $xmlString)); + $xml->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/'); + $xml->registerXPathNamespace('schema', 'http://schema.org/'); + $entries = $xml->xpath('/feed/entry') ?? []; - $output = ''; - foreach($entries as $entry){ - $output .= $entry->asXml(); + $output = ''; + foreach($entries as $entry){ + $output .= $entry->asXml(); + } + + return sha1(preg_replace('/\s/ius', '', $output)); + } + catch(Exception $ex){ + // Invalid XML + return ''; } - - return sha1(preg_replace('/\s/ius', '', $output)); } public function Save(string $filename): void{ diff --git a/scripts/deploy-ebook-to-www b/scripts/deploy-ebook-to-www index 9cba8e56..cf3643e6 100755 --- a/scripts/deploy-ebook-to-www +++ b/scripts/deploy-ebook-to-www @@ -227,7 +227,10 @@ if [ "${verbose}" = "true" ]; then printf "Rebuilding OPDS catalog ... " fi -bash -c "php \"${scriptsDir}\"/generate-opds.php --webroot \"${webRoot}\" --weburl \"${webUrl}\"" +php "${scriptsDir}/generate-opds.php" --webroot "${webRoot}" --weburl "${webUrl}" + +sudo chown se:committers /standardebooks.org/web/www/opds/*.xml +sudo chmod 664 /standardebooks.org/web/www/opds/*.xml if [ "${verbose}" = "true" ]; then printf "Done.\n" diff --git a/templates/OpdsFeed.php b/templates/OpdsFeed.php index 62287525..d5f7700c 100644 --- a/templates/OpdsFeed.php +++ b/templates/OpdsFeed.php @@ -14,7 +14,7 @@ if(!isset($isCrawlable)){ print("\n"); ?> - + xmlns:fh="http://purl.org/syndication/history/1.0">