|
@@ -1360,12 +1360,18 @@ class FreshRSS_Feed extends Minz_Model {
|
|
|
//<WebSub>
|
|
//<WebSub>
|
|
|
|
|
|
|
|
public function pubSubHubbubEnabled(): bool {
|
|
public function pubSubHubbubEnabled(): bool {
|
|
|
|
|
+ // Whether the current user is enrolled in the WebSub of that topic
|
|
|
|
|
+ $currentUser = Minz_User::name() ?? '';
|
|
|
|
|
+ if ($currentUser === '') {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
$url = $this->selfUrl ?: $this->url;
|
|
$url = $this->selfUrl ?: $this->url;
|
|
|
- $hubFilename = PSHB_PATH . '/feeds/' . sha1($url) . '/!hub.json';
|
|
|
|
|
- if (($hubFile = @file_get_contents($hubFilename)) != false) {
|
|
|
|
|
|
|
+ $path = PSHB_PATH . '/feeds/' . sha1($url);
|
|
|
|
|
+ if (($hubFile = @file_get_contents($path . '/!hub.json')) != false) {
|
|
|
$hubJson = json_decode($hubFile, true);
|
|
$hubJson = json_decode($hubFile, true);
|
|
|
if (is_array($hubJson) && empty($hubJson['error']) &&
|
|
if (is_array($hubJson) && empty($hubJson['error']) &&
|
|
|
- (empty($hubJson['lease_end']) || $hubJson['lease_end'] > time())) {
|
|
|
|
|
|
|
+ (empty($hubJson['lease_end']) || $hubJson['lease_end'] > time()) &&
|
|
|
|
|
+ file_exists($path . '/' . $currentUser . '.txt')) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1399,6 +1405,7 @@ class FreshRSS_Feed extends Minz_Model {
|
|
|
$this->hubUrl !== '' && $this->selfUrl !== '' && @is_dir(PSHB_PATH)) {
|
|
$this->hubUrl !== '' && $this->selfUrl !== '' && @is_dir(PSHB_PATH)) {
|
|
|
$path = PSHB_PATH . '/feeds/' . sha1($this->selfUrl);
|
|
$path = PSHB_PATH . '/feeds/' . sha1($this->selfUrl);
|
|
|
$hubFilename = $path . '/!hub.json';
|
|
$hubFilename = $path . '/!hub.json';
|
|
|
|
|
+ $currentUser = Minz_User::name() ?? '';
|
|
|
if (($hubFile = @file_get_contents($hubFilename)) != false) {
|
|
if (($hubFile = @file_get_contents($hubFilename)) != false) {
|
|
|
$hubJson = json_decode($hubFile, true);
|
|
$hubJson = json_decode($hubFile, true);
|
|
|
if (!is_array($hubJson) || empty($hubJson['key']) || !is_string($hubJson['key']) || !ctype_xdigit($hubJson['key'])) {
|
|
if (!is_array($hubJson) || empty($hubJson['key']) || !is_string($hubJson['key']) || !ctype_xdigit($hubJson['key'])) {
|
|
@@ -1407,6 +1414,16 @@ class FreshRSS_Feed extends Minz_Model {
|
|
|
Minz_Log::warning($text, PSHB_LOG);
|
|
Minz_Log::warning($text, PSHB_LOG);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (($hubJson['hub'] ?? null) !== $this->hubUrl) {
|
|
|
|
|
+ if (FreshRSS_user_Controller::checkUsername($currentUser) && file_exists($path . '/' . $currentUser . '.txt')) {
|
|
|
|
|
+ unlink($path . '/' . $currentUser . '.txt');
|
|
|
|
|
+ }
|
|
|
|
|
+ $text = 'WebSub: Hub ' . $this->hubUrl . ' currently advertised by ' . $this->url .
|
|
|
|
|
+ ' does not match the hub file! Not subscribing ' . $currentUser;
|
|
|
|
|
+ Minz_Log::warning($text);
|
|
|
|
|
+ Minz_Log::warning($text, PSHB_LOG);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
if (!empty($hubJson['lease_end']) && is_int($hubJson['lease_end']) && $hubJson['lease_end'] < (time() + (3600 * 23))) { //TODO: Make a better policy
|
|
if (!empty($hubJson['lease_end']) && is_int($hubJson['lease_end']) && $hubJson['lease_end'] < (time() + (3600 * 23))) { //TODO: Make a better policy
|
|
|
$text = 'WebSub lease ends at '
|
|
$text = 'WebSub lease ends at '
|
|
|
. date('c', empty($hubJson['lease_end']) ? time() : $hubJson['lease_end'])
|
|
. date('c', empty($hubJson['lease_end']) ? time() : $hubJson['lease_end'])
|
|
@@ -1420,7 +1437,7 @@ class FreshRSS_Feed extends Minz_Model {
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
@mkdir($path, 0770, true);
|
|
@mkdir($path, 0770, true);
|
|
|
- $key = sha1($path . FreshRSS_Context::systemConf()->salt);
|
|
|
|
|
|
|
+ $key = bin2hex(random_bytes(32));
|
|
|
$hubJson = [
|
|
$hubJson = [
|
|
|
'hub' => $this->hubUrl,
|
|
'hub' => $this->hubUrl,
|
|
|
'key' => $key,
|
|
'key' => $key,
|
|
@@ -1432,7 +1449,6 @@ class FreshRSS_Feed extends Minz_Model {
|
|
|
Minz_Log::debug($text);
|
|
Minz_Log::debug($text);
|
|
|
Minz_Log::debug($text, PSHB_LOG);
|
|
Minz_Log::debug($text, PSHB_LOG);
|
|
|
}
|
|
}
|
|
|
- $currentUser = Minz_User::name() ?? '';
|
|
|
|
|
if (FreshRSS_user_Controller::checkUsername($currentUser) && !file_exists($path . '/' . $currentUser . '.txt')) {
|
|
if (FreshRSS_user_Controller::checkUsername($currentUser) && !file_exists($path . '/' . $currentUser . '.txt')) {
|
|
|
touch($path . '/' . $currentUser . '.txt');
|
|
touch($path . '/' . $currentUser . '.txt');
|
|
|
}
|
|
}
|