Pārlūkot izejas kodu

Merge branch 'FreshRSS/dev' into multiuser-token

Alexandre Alapetite 9 gadi atpakaļ
vecāks
revīzija
510045b3c5

+ 2 - 0
CHANGELOG.md

@@ -13,8 +13,10 @@
 	* Add support for PHP 7.1 [#1471](https://github.com/FreshRSS/FreshRSS/issues/1471)
 	* PostgreSQL is not experimental anymore [#1476](https://github.com/FreshRSS/FreshRSS/pull/1476)
 * Bug fixing
+	* Fix PubSubHubbub bugs when deleting users, and improved behaviour when removing feeds [#1495](https://github.com/FreshRSS/FreshRSS/pull/1495)
 	* Fix SQL uniqueness bug with PostgreSQL [#1476](https://github.com/FreshRSS/FreshRSS/pull/1476)
 		* (Require manual update for existing installations)
+	* Do not require PHP extension `fileinfo` for favicons [#1461](https://github.com/FreshRSS/FreshRSS/issues/1461)
 	* Fix UI lowest subscription popup hidden [#1479](https://github.com/FreshRSS/FreshRSS/issues/1479)
 * I18n
 	* Improve English [#1465](https://github.com/FreshRSS/FreshRSS/pull/1465)

+ 1 - 0
app/Controllers/userController.php

@@ -217,6 +217,7 @@ class FreshRSS_user_Controller extends Minz_ActionController {
 			$userDAO = new FreshRSS_UserDAO();
 			$ok &= $userDAO->deleteUser($username);
 			$ok &= recursive_unlink($user_data);
+			array_map('unlink', glob(PSHB_PATH . '/feeds/*/' . $username . '.txt'));
 		}
 		return $ok;
 	}

+ 8 - 7
app/Models/Feed.php

@@ -429,7 +429,7 @@ class FreshRSS_Feed extends Minz_Model {
 				}
 			} else {
 				@mkdir($path, 0777, true);
-				$key = sha1($path . FreshRSS_Context::$system_conf->salt . uniqid(mt_rand(), true));
+				$key = sha1($path . FreshRSS_Context::$system_conf->salt);
 				$hubJson = array(
 					'hub' => $this->hubUrl,
 					'key' => $key,
@@ -451,15 +451,16 @@ class FreshRSS_Feed extends Minz_Model {
 
 	//Parameter true to subscribe, false to unsubscribe.
 	function pubSubHubbubSubscribe($state) {
-		if (FreshRSS_Context::$system_conf->base_url && $this->hubUrl && $this->selfUrl) {
-			$hubFilename = PSHB_PATH . '/feeds/' . base64url_encode($this->selfUrl) . '/!hub.json';
+		$url = $this->selfUrl ? $this->selfUrl : $this->url;
+		if (FreshRSS_Context::$system_conf->base_url && $url) {
+			$hubFilename = PSHB_PATH . '/feeds/' . base64url_encode($url) . '/!hub.json';
 			$hubFile = @file_get_contents($hubFilename);
 			if ($hubFile === false) {
 				Minz_Log::warning('JSON not found for PubSubHubbub: ' . $this->url);
 				return false;
 			}
 			$hubJson = json_decode($hubFile, true);
-			if (!$hubJson || empty($hubJson['key']) || !ctype_xdigit($hubJson['key'])) {
+			if (!$hubJson || empty($hubJson['key']) || !ctype_xdigit($hubJson['key']) || empty($hubJson['hub'])) {
 				Minz_Log::warning('Invalid JSON for PubSubHubbub: ' . $this->url);
 				return false;
 			}
@@ -474,13 +475,13 @@ class FreshRSS_Feed extends Minz_Model {
 			}
 			$ch = curl_init();
 			curl_setopt_array($ch, array(
-				CURLOPT_URL => $this->hubUrl,
+				CURLOPT_URL => $hubJson['hub'],
 				CURLOPT_FOLLOWLOCATION => true,
 				CURLOPT_RETURNTRANSFER => true,
 				CURLOPT_USERAGENT => 'FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ')',
 				CURLOPT_POSTFIELDS => 'hub.verify=sync'
 					. '&hub.mode=' . ($state ? 'subscribe' : 'unsubscribe')
-					. '&hub.topic=' . urlencode($this->selfUrl)
+					. '&hub.topic=' . urlencode($url)
 					. '&hub.callback=' . urlencode($callbackUrl)
 				)
 			);
@@ -488,7 +489,7 @@ class FreshRSS_Feed extends Minz_Model {
 			$info = curl_getinfo($ch);
 
 			file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" .
-				'PubSubHubbub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $this->selfUrl .
+				'PubSubHubbub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $url .
 				' with callback ' . $callbackUrl . ': ' . $info['http_code'] . ' ' . $response . "\n", FILE_APPEND);
 
 			if (substr($info['http_code'], 0, 1) == '2') {

+ 1 - 1
app/SQL/install.sql.mysql.php

@@ -92,7 +92,7 @@ INSERT IGNORE INTO `%1$sfeed` (url, category, name, website, description, ttl) V
 INSERT IGNORE INTO `%1$sfeed` (url, category, name, website, description, ttl) VALUES("https://github.com/FreshRSS/FreshRSS/releases.atom", 1, "FreshRSS @ GitHub", "https://github.com/FreshRSS/FreshRSS/", "FreshRSS releases @ GitHub", 86400);
 ');
 
-define('SQL_DROP_TABLES', 'DROP TABLE IF EXISTS `%1$sentry`, `%1$sfeed`, `%1$scategory`');
+define('SQL_DROP_TABLES', 'DROP TABLE IF EXISTS `%1$sentrytmp`, `%1$sentry`, `%1$sfeed`, `%1$scategory`');
 
 define('SQL_UPDATE_UTF8MB4', '
 ALTER DATABASE `%2$s` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

+ 1 - 1
app/SQL/install.sql.pgsql.php

@@ -84,4 +84,4 @@ $SQL_INSERT_FEEDS = array(
 'INSERT INTO "%1$sfeed" (url, category, name, website, description, ttl) SELECT \'https://github.com/FreshRSS/FreshRSS/releases.atom\', 1, \'FreshRSS @ GitHub\', \'https://github.com/FreshRSS/FreshRSS/\', \'FreshRSS releases @ GitHub\', 86400 WHERE NOT EXISTS (SELECT id FROM "%1$sfeed" WHERE url = \'https://github.com/FreshRSS/FreshRSS/releases.atom\');',
 );
 
-define('SQL_DROP_TABLES', 'DROP TABLE IF EXISTS "%1$sentry", "%1$sfeed", "%1$scategory"');
+define('SQL_DROP_TABLES', 'DROP TABLE IF EXISTS "%1$sentrytmp", "%1$sentry", "%1$sfeed", "%1$scategory"');

+ 1 - 1
app/SQL/install.sql.sqlite.php

@@ -86,4 +86,4 @@ $SQL_INSERT_FEEDS = array(
 'INSERT OR IGNORE INTO `feed` (url, category, name, website, description, ttl) VALUES("https://github.com/FreshRSS/FreshRSS/releases.atom", 1, "FreshRSS releases", "https://github.com/FreshRSS/FreshRSS/", "FreshRSS releases @ GitHub", 86400);',
 );
 
-define('SQL_DROP_TABLES', 'DROP TABLE IF EXISTS entry, feed, category');
+define('SQL_DROP_TABLES', 'DROP TABLE IF EXISTS `entrytmp`, `entry`, `feed`, `category`');

+ 1 - 1
app/i18n/en/gen.php

@@ -2,7 +2,7 @@
 
 return array(
 	'action' => array(
-		'actualize' => 'Updating',
+		'actualize' => 'Actualize',
 		'back_to_rss_feeds' => '← Go back to your RSS feeds',
 		'cancel' => 'Cancel',
 		'create' => 'Create',

+ 1 - 1
app/install.php

@@ -465,7 +465,7 @@ function printStep1() {
 	<?php if ($res['fileinfo'] == 'ok') { ?>
 	<p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.fileinfo.ok'); ?></p>
 	<?php } else { ?>
-	<p class="alert alert-error"><span class="alert-head"><?php echo _t('gen.short.damn'); ?></span> <?php echo _t('install.check.fileinfo.nok'); ?></p>
+	<p class="alert alert-warn"><span class="alert-head"><?php echo _t('gen.short.damn'); ?></span> <?php echo _t('install.check.fileinfo.nok'); ?></p>
 	<?php } ?>
 
 	<?php if ($res['data'] == 'ok') { ?>

+ 9 - 5
lib/Favicon/Favicon.php

@@ -179,7 +179,7 @@ class Favicon
         // Sometimes people lie, so check the status.
         // And sometimes, it's not even an image. Sneaky bastards!
         // If cacheDir isn't writable, that's not our problem
-        if ($favicon && is_writable($this->cacheDir) && !$this->checkImageMType($favicon)) {
+        if ($favicon && is_writable($this->cacheDir) && extension_loaded('fileinfo') && !$this->checkImageMType($favicon)) {
             $favicon = false;
         }
 
@@ -229,10 +229,14 @@ class Favicon
         $fileContent = $this->dataAccess->retrieveUrl($url);
         $this->dataAccess->saveCache($tmpFile, $fileContent);
         
-        $finfo = finfo_open(FILEINFO_MIME_TYPE);
-        $isImage = strpos(finfo_file($finfo, $tmpFile), 'image') !== false;
-        finfo_close($finfo);
-        
+        $isImage = true;
+        try {
+            $finfo = finfo_open(FILEINFO_MIME_TYPE);
+            $isImage = strpos(finfo_file($finfo, $tmpFile), 'image') !== false;
+            finfo_close($finfo);
+        } catch (Exception $e) {
+        }
+
         unlink($tmpFile);
         
         return $isImage;

+ 1 - 1
lib/lib_install.php

@@ -67,7 +67,7 @@ function checkRequirements($dbType = '') {
 		'favicons' => $favicons ? 'ok' : 'ko',
 		'http_referer' => $http_referer ? 'ok' : 'ko',
 		'message' => $message ?: 'ok',
-		'all' => $php && $minz && $curl && $pdo && $pcre && $ctype && $fileinfo && $dom && $xml &&
+		'all' => $php && $minz && $curl && $pdo && $pcre && $ctype && $dom && $xml &&
 		         $data && $cache && $users && $favicons && $http_referer && $message == '' ?
 		         'ok' : 'ko'
 	);

+ 30 - 9
p/api/pshb.php

@@ -23,8 +23,13 @@ if (!ctype_xdigit($key)) {
 chdir(PSHB_PATH);
 $canonical64 = @file_get_contents('keys/' . $key . '.txt');
 if ($canonical64 === false) {
+	if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] === 'unsubscribe') {
+		logMe('Warning: Accept unknown unsubscribe');
+		header('Connection: close');
+		exit(isset($_REQUEST['hub_challenge']) ? $_REQUEST['hub_challenge'] : '');
+	}
 	header('HTTP/1.1 404 Not Found');
-	logMe('Error: Feed key not found!: ' . $key);
+	logMe('Warning: Feed key not found!: ' . $key);
 	die('Feed key not found!');
 }
 $canonical64 = trim($canonical64);
@@ -36,7 +41,7 @@ if (!preg_match('/^[A-Za-z0-9_-]+$/D', $canonical64)) {
 $hubFile = @file_get_contents('feeds/' . $canonical64 . '/!hub.json');
 if ($hubFile === false) {
 	header('HTTP/1.1 404 Not Found');
-	//@unlink('keys/' . $key . '.txt');
+	unlink('keys/' . $key . '.txt');
 	logMe('Error: Feed info not found!: ' . $canonical64);
 	die('Feed info not found!');
 }
@@ -50,8 +55,19 @@ chdir('feeds/' . $canonical64);
 $users = glob('*.txt', GLOB_NOSORT);
 if (empty($users)) {
 	header('HTTP/1.1 410 Gone');
-	logMe('Error: Nobody is subscribed to this feed anymore!: ' . $canonical64);
-	die('Nobody is subscribed to this feed anymore!');
+	$url = base64url_decode($canonical64);
+	logMe('Warning: Nobody subscribes to this feed anymore!: ' . $url);
+	unlink('../../keys/' . $key . '.txt');
+	Minz_Configuration::register('system',
+		DATA_PATH . '/config.php',
+		DATA_PATH . '/config.default.php');
+	FreshRSS_Context::$system_conf = Minz_Configuration::get('system');
+	$feed = new FreshRSS_Feed($url);
+	$feed->pubSubHubbubSubscribe(false);
+	unlink('!hub.json');
+	chdir('..');
+	recursive_unlink($canonical64);
+	die('Nobody subscribes to this feed anymore!');
 }
 
 if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] === 'subscribe') {
@@ -108,7 +124,9 @@ $nb = 0;
 foreach ($users as $userFilename) {
 	$username = basename($userFilename, '.txt');
 	if (!file_exists(USERS_PATH . '/' . $username . '/config.php')) {
-		break;
+		logMe('Warning: Removing broken user link: ' . $username . ' for ' . $self);
+		unlink($userFilename);
+		continue;
 	}
 
 	try {
@@ -119,11 +137,14 @@ foreach ($users as $userFilename) {
 		new Minz_ModelPdo($username);	//TODO: FIXME: Quick-fix while waiting for a better FreshRSS() constructor/init
 		FreshRSS_Context::init();
 		list($updated_feeds, $feed) = FreshRSS_feed_Controller::actualizeFeed(0, $self, false, $simplePie);
-		if ($updated_feeds > 0) {
+		if ($updated_feeds > 0 || $feed != false) {
 			$nb++;
+		} else {
+			logMe('Warning: User ' . $username . ' does not subscribe anymore to ' . $self);
+			unlink($userFilename);
 		}
 	} catch (Exception $e) {
-		logMe('Error: ' . $e->getMessage());
+		logMe('Error: ' . $e->getMessage() . ' for user ' . $username . ' and feed ' . $self);
 	}
 }
 
@@ -132,8 +153,8 @@ unset($simplePie);
 
 if ($nb === 0) {
 	header('HTTP/1.1 410 Gone');
-	logMe('Error: Nobody is subscribed to this feed anymore after all!: ' . $self);
-	die('Nobody is subscribed to this feed anymore after all!');
+	logMe('Warning: Nobody subscribes to this feed anymore after all!: ' . $self);
+	die('Nobody subscribes to this feed anymore after all!');
 } elseif (!empty($hubJson['error'])) {
 	$hubJson['error'] = false;
 	file_put_contents('./!hub.json', json_encode($hubJson));