diff options
author | Joas Schilling <coding@schilljs.com> | 2016-11-18 15:57:26 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-11-18 16:14:08 +0300 |
commit | 31f58e67f43dbc231000730feb1fdec39e195d62 (patch) | |
tree | b68e59d8e773f7d20e83c91a71ff6bb30608d66f | |
parent | 44e7dd835c3feddc1e5797fe0a64e23be307c48d (diff) |
Add a little script to generate the feed and the signature
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | README.md | 16 | ||||
-rw-r--r-- | feed.txt | 2 | ||||
-rw-r--r-- | generate.php | 88 |
4 files changed, 110 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f6f011 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/nextcloud_announcements.key +/feed.rss +/feed.signature + diff --git a/README.md b/README.md new file mode 100644 index 0000000..1f65024 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Announcer + +This script generates the `feed.rss` and `feed.signature` which are published on https://pushfeed.nextcloud.com/. +The feed is then pulled by the [nextcloud_announcements](https://github.com/nextcloud/nextcloud_announcements) app. + +## How To + + +1. Ask @LukasReschke for the `nextcloud_announcements.key`, or generate a temporary one yourself. +2. Add the new announcement to `feed.txt` + + _Note: Lines starting with `#` are ignored_ + +3. Run `php generate.php` +4. Upload `feed.rss` and `feed.signature` to the server + diff --git a/feed.txt b/feed.txt new file mode 100644 index 0000000..4b7280b --- /dev/null +++ b/feed.txt @@ -0,0 +1,2 @@ +# 1 - 2016-11-15 - https://nextcloud.com/blog/nextcloud-sponsors-and-participates-in-open-2016/ - Nextcloud Sponsors and participates in OPEN! 2016 + diff --git a/generate.php b/generate.php new file mode 100644 index 0000000..63ecc60 --- /dev/null +++ b/generate.php @@ -0,0 +1,88 @@ +<?php +/** + * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +if (php_sapi_name() !== 'cli') { + echo 'Script can only run from command line' . "\n"; + exit(1); +} + +$content = file_get_contents(__DIR__ . '/feed.txt'); +$feeds = explode("\n", $content); +$items = ''; + +$maxDate = new \DateTime(); +$maxDate->setTimestamp(0); + +foreach ($feeds as $feed) { + $feed = trim($feed); + if ($feed === '' || $feed[0] === '#') { + continue; + } + list ($id, $date, $url, $title) = explode(' - ', $feed, 4); + + $dateTime = new \DateTime(); + call_user_func_array([$dateTime, 'setDate'], explode('-', $date)); + $dateTime->setTime(0, 0, 0); + + if ($dateTime->getTimestamp() > $maxDate->getTimestamp()) { + $maxDate = $dateTime; + } + + $items .= ' <item> + <guid isPermaLink="false">' . $id . '</guid> + <title>' . $title . '</title> + <link>' . $url . '</link> + <pubDate>' . $dateTime->format('r') . '</pubDate> + </item> +'; +} + +$beginning = '<?xml version="1.0" encoding="UTF-8"?> +<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> + <channel> + <title>Nextcloud organisation</title> + <language>en</language> + <link>https://pushfeed.nextcloud.com/feed.rss</link> + <description>Feed for announcements from Nextcloud</description> + <pubDate>' . $maxDate->format('r') . '</pubDate> + <lastBuildDate>' . $maxDate->format('r') . '</lastBuildDate> + <atom:link href="https://pushfeed.nextcloud.com/feed.rss" rel="self" type="application/rss+xml" /> +'; + +$content = $beginning . $items . ' </channel> +</rss> +'; + +file_put_contents(__DIR__ . '/feed.rss', $content); +echo 'Successfully generated feed.rss' . "\n"; + +$key = file_get_contents(__DIR__ . '/nextcloud_announcements.key'); +$signature = ''; +if (!openssl_sign($content, $signature, $key, OPENSSL_ALGO_SHA512)) { + echo 'Error signing the feed' . "\n"; + exit(1); +} + +$signature = base64_encode($signature); +$signature = implode("\n", str_split($signature, 64)); + +file_put_contents(__DIR__ . '/feed.signature', $signature); +echo 'Successfully generated feed.signature' . "\n"; |