|
|
|
|
@ -39,7 +39,6 @@ use OCP\BackgroundJob\Job; |
|
|
|
|
use OCP\Http\Client\IClient; |
|
|
|
|
use OCP\Http\Client\IClientService; |
|
|
|
|
use OCP\Http\Client\IResponse; |
|
|
|
|
use OCP\ILogger; |
|
|
|
|
use OCP\IURLGenerator; |
|
|
|
|
use OCP\OCS\IDiscoveryService; |
|
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
@ -60,7 +59,6 @@ class GetSharedSecret extends Job { |
|
|
|
|
private LoggerInterface $logger; |
|
|
|
|
protected bool $retainJob = false; |
|
|
|
|
private string $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/shared-secret'; |
|
|
|
|
|
|
|
|
|
/** 30 day = 2592000sec */ |
|
|
|
|
private int $maxLifespan = 2592000; |
|
|
|
|
|
|
|
|
|
@ -83,16 +81,13 @@ class GetSharedSecret extends Job { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* run the job, then remove it from the joblist |
|
|
|
|
* |
|
|
|
|
* @param IJobList $jobList |
|
|
|
|
* @param ILogger|null $logger |
|
|
|
|
* Run the job, then remove it from the joblist |
|
|
|
|
*/ |
|
|
|
|
public function execute(IJobList $jobList, ILogger $logger = null) { |
|
|
|
|
public function start(IJobList $jobList): void { |
|
|
|
|
$target = $this->argument['url']; |
|
|
|
|
// only execute if target is still in the list of trusted domains |
|
|
|
|
if ($this->trustedServers->isTrustedServer($target)) { |
|
|
|
|
$this->parentExecute($jobList, $logger); |
|
|
|
|
$this->parentStart($jobList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$jobList->remove($this, $this->argument); |
|
|
|
|
@ -102,14 +97,8 @@ class GetSharedSecret extends Job { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Call execute() method of parent |
|
|
|
|
* |
|
|
|
|
* @param IJobList $jobList |
|
|
|
|
* @param ILogger $logger |
|
|
|
|
*/ |
|
|
|
|
protected function parentExecute($jobList, $logger = null) { |
|
|
|
|
parent::execute($jobList, $logger); |
|
|
|
|
protected function parentStart(IJobList $jobList): void { |
|
|
|
|
parent::start($jobList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected function run($argument) { |
|
|
|
|
@ -162,12 +151,10 @@ class GetSharedSecret extends Job { |
|
|
|
|
$status = -1; // There is no status code if we could not connect |
|
|
|
|
$this->logger->info('Could not connect to ' . $target, [ |
|
|
|
|
'exception' => $e, |
|
|
|
|
'app' => 'federation', |
|
|
|
|
]); |
|
|
|
|
} catch (\Throwable $e) { |
|
|
|
|
$status = Http::STATUS_INTERNAL_SERVER_ERROR; |
|
|
|
|
$this->logger->error($e->getMessage(), [ |
|
|
|
|
'app' => 'federation', |
|
|
|
|
'exception' => $e, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
@ -190,8 +177,8 @@ class GetSharedSecret extends Job { |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
$this->logger->error( |
|
|
|
|
'remote server "' . $target . '"" does not return a valid shared secret. Received data: ' . $body, |
|
|
|
|
['app' => 'federation'] |
|
|
|
|
'remote server "' . $target . '"" does not return a valid shared secret. Received data: ' . $body, |
|
|
|
|
['app' => 'federation'] |
|
|
|
|
); |
|
|
|
|
$this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE); |
|
|
|
|
} |
|
|
|
|
@ -199,13 +186,13 @@ class GetSharedSecret extends Job { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* re-add background job |
|
|
|
|
* Re-add background job |
|
|
|
|
* |
|
|
|
|
* @param array $argument |
|
|
|
|
*/ |
|
|
|
|
protected function reAddJob(array $argument): void { |
|
|
|
|
$url = $argument['url']; |
|
|
|
|
$created = isset($argument['created']) ? (int)$argument['created'] : $this->time->getTime(); |
|
|
|
|
$created = $argument['created'] ?? $this->time->getTime(); |
|
|
|
|
$token = $argument['token']; |
|
|
|
|
$this->jobList->add( |
|
|
|
|
GetSharedSecret::class, |
|
|
|
|
|