예제 #1
0
 /**
  * @param array $argument
  * @throws \Exception
  * @throws \OC\NeedsUpdateException
  */
 protected function run($argument)
 {
     if (!isset($argument['app']) || !isset($argument['step'])) {
         // remove the job - we can never execute it
         $this->jobList->remove($this, $this->argument);
         return;
     }
     $app = $argument['app'];
     try {
         $this->loadApp($app);
     } catch (NeedsUpdateException $ex) {
         // as long as the app is not yet done with it's offline migration
         // we better not start with the live migration
         return;
     }
     $step = $argument['step'];
     $repair = new Repair([], $this->dispatcher);
     try {
         $repair->addStep($step);
     } catch (\Exception $ex) {
         $this->logger->logException($ex, ['app' => 'migration']);
         // remove the job - we can never execute it
         $this->jobList->remove($this, $this->argument);
         return;
     }
     // execute the repair step
     $repair->run();
     // remove the job once executed successfully
     $this->jobList->remove($this, $this->argument);
 }
예제 #2
0
 /**
  * Schedule a command to be fired
  *
  * @param \OCP\Command\ICommand | callable $command
  */
 public function push($command)
 {
     if ($this->canRunAsync($command)) {
         $this->jobList->add($this->getJobClass($command), $this->serializeCommand($command));
     } else {
         $this->runCommand($command);
     }
 }
 /**
  * @return \OC_OCS_Result
  */
 public function disableMonthly()
 {
     $this->jobList->remove('OCA\\PopularityContestClient\\MonthlyReport');
     $notification = $this->manager->createNotification();
     $notification->setApp('popularitycontestclient');
     $this->manager->markProcessed($notification);
     return new \OC_OCS_Result();
 }
예제 #4
0
파일: dropoldjobs.php 프로젝트: kenwi/core
 /**
  * Run repair step.
  * Must throw exception on error.
  *
  * @throws \Exception in case of failure
  */
 public function run()
 {
     $oldJobs = $this->oldJobs();
     foreach ($oldJobs as $job) {
         if ($this->jobList->has($job['class'], $job['arguments'])) {
             $this->jobList->remove($job['class'], $job['arguments']);
         }
     }
 }
예제 #5
0
파일: dropoldjobs.php 프로젝트: evanjt/core
 public function testRun()
 {
     $this->assertTrue($this->jobList->has('OC\\Cache\\FileGlobalGC', null), 'Asserting that the job OC\\Cache\\FileGlobalGC exists before repairing');
     $this->assertTrue($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC exists before repairing');
     $repair = new \OC\Repair\DropOldJobs($this->jobList);
     $repair->run();
     $this->assertFalse($this->jobList->has('OC\\Cache\\FileGlobalGC', null), 'Asserting that the job OC\\Cache\\FileGlobalGC does not exist after repairing');
     $this->assertFalse($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC does not exist after repairing');
 }
예제 #6
0
 /**
  * @return DataResponse
  */
 public function createCredentials()
 {
     // Create a new job and store the creation date
     $this->jobList->add('OCA\\UpdateNotification\\ResetTokenBackgroundJob');
     $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime());
     // Create a new token
     $newToken = $this->secureRandom->generate(64);
     $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT));
     return new DataResponse($newToken);
 }
예제 #7
0
 public function testCreateCredentials()
 {
     $this->jobList->expects($this->once())->method('add')->with('OCA\\UpdateNotification\\ResetTokenBackgroundJob');
     $this->secureRandom->expects($this->once())->method('generate')->with(64)->willReturn('MyGeneratedToken');
     $this->config->expects($this->once())->method('setSystemValue')->with('updater.secret');
     $this->timeFactory->expects($this->once())->method('getTime')->willReturn(12345);
     $this->config->expects($this->once())->method('setAppValue')->with('core', 'updater.secret.created', 12345);
     $expected = new DataResponse('MyGeneratedToken');
     $this->assertEquals($expected, $this->adminController->createCredentials());
 }
예제 #8
0
 /**
  * add server to the list of trusted ownCloud servers
  *
  * @param $url
  * @return int server id
  */
 public function addServer($url)
 {
     $url = $this->updateProtocol($url);
     $result = $this->dbHandler->addServer($url);
     if ($result) {
         $token = $this->secureRandom->generate(16);
         $this->dbHandler->addToken($url, $token);
         $this->jobList->add('OCA\\Federation\\BackgroundJob\\RequestSharedSecret', ['url' => $url, 'token' => $token]);
     }
     return $result;
 }
예제 #9
0
 public function testRun()
 {
     $this->assertTrue($this->jobList->has('OC\\Cache\\FileGlobalGC', null), 'Asserting that the job OC\\Cache\\FileGlobalGC exists before repairing');
     $this->assertTrue($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC exists before repairing');
     /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
     $outputMock = $this->getMockBuilder('\\OCP\\Migration\\IOutput')->disableOriginalConstructor()->getMock();
     $repair = new \OC\Repair\DropOldJobs($this->jobList);
     $repair->run($outputMock);
     $this->assertFalse($this->jobList->has('OC\\Cache\\FileGlobalGC', null), 'Asserting that the job OC\\Cache\\FileGlobalGC does not exist after repairing');
     $this->assertFalse($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC does not exist after repairing');
 }
예제 #10
0
 /**
  * request received to ask remote server for a shared secret
  *
  * @return \OC_OCS_Result
  */
 public function requestSharedSecret()
 {
     $url = $this->request->getParam('url');
     $token = $this->request->getParam('token');
     if ($this->trustedServers->isTrustedServer($url) === false) {
         return new \OC_OCS_Result(null, HTTP::STATUS_FORBIDDEN);
     }
     // if both server initiated the exchange of the shared secret the greater
     // token wins
     $localToken = $this->dbHandler->getToken($url);
     if (strcmp($localToken, $token) > 0) {
         return new \OC_OCS_Result(null, HTTP::STATUS_FORBIDDEN);
     }
     $this->jobList->add('OCA\\Federation\\BackgroundJob\\GetSharedSecret', ['url' => $url, 'token' => $token]);
     return new \OC_OCS_Result(null, Http::STATUS_OK);
 }
예제 #11
0
 protected function run($argument)
 {
     $target = $argument['url'];
     $source = $this->urlGenerator->getAbsoluteURL('/');
     $source = rtrim($source, '/');
     $token = $argument['token'];
     try {
         $result = $this->httpClient->get($target . $this->endPoint, ['query' => ['url' => $source, 'token' => $token], 'timeout' => 3, 'connect_timeout' => 3]);
         $status = $result->getStatusCode();
     } catch (ClientException $e) {
         $status = $e->getCode();
         $this->logger->logException($e);
     }
     // if we received a unexpected response we try again later
     if ($status !== Http::STATUS_OK && $status !== Http::STATUS_FORBIDDEN) {
         $this->jobList->add('OCA\\Federation\\BackgroundJob\\GetSharedSecret', $argument);
     } else {
         // reset token if we received a valid response
         $this->dbHandler->addToken($target, '');
     }
     if ($status === Http::STATUS_OK) {
         $body = $result->getBody();
         $result = json_decode($body, true);
         if (isset($result['ocs']['data']['sharedSecret'])) {
             $this->trustedServers->addSharedSecret($target, $result['ocs']['data']['sharedSecret']);
         } else {
             $this->logger->error('remote server "' . $target . '"" does not return a valid shared secret', ['app' => 'federation']);
             $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
         }
     }
 }
예제 #12
0
 protected function run($argument)
 {
     $target = $argument['url'];
     $source = $this->urlGenerator->getAbsoluteURL('/');
     $source = rtrim($source, '/');
     $token = $argument['token'];
     try {
         $result = $this->httpClient->post($target . $this->endPoint, ['body' => ['url' => $source, 'token' => $token], 'timeout' => 3, 'connect_timeout' => 3]);
         $status = $result->getStatusCode();
     } catch (ClientException $e) {
         $status = $e->getCode();
         $this->logger->logException($e);
     } catch (\Exception $e) {
         $status = HTTP::STATUS_INTERNAL_SERVER_ERROR;
         $this->logger->logException($e);
     }
     // if we received a unexpected response we try again later
     if ($status !== Http::STATUS_OK && $status !== Http::STATUS_FORBIDDEN) {
         $this->jobList->add('OCA\\Federation\\BackgroundJob\\RequestSharedSecret', $argument);
     }
     if ($status === Http::STATUS_FORBIDDEN) {
         // clear token if remote server refuses to ask for shared secret
         $this->dbHandler->addToken($target, '');
     }
 }
예제 #13
0
파일: asyncbus.php 프로젝트: evanjt/core
 private function runJobs()
 {
     $jobs = $this->jobList->getAll();
     foreach ($jobs as $job) {
         $job->execute($this->jobList);
     }
 }
예제 #14
0
 /**
  * send server-to-server unshare to remote server
  *
  * @param string $remote url
  * @param int $id share id
  * @param string $token
  * @param int $try how often did we already tried to send the un-share request
  * @return bool
  */
 public function sendRemoteUnShare($remote, $id, $token, $try = 0)
 {
     $url = rtrim($remote, '/');
     $fields = array('token' => $token, 'format' => 'json');
     $url = $this->addressHandler->removeProtocolFromUrl($url);
     $result = $this->tryHttpPostToShareEndpoint($url, '/' . $id . '/unshare', $fields);
     $status = json_decode($result['result'], true);
     if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) {
         return true;
     } elseif ($try === 0) {
         // only add new job on first try
         $this->jobList->add('OCA\\FederatedFileSharing\\BackgroundJob\\UnShare', ['remote' => $remote, 'id' => $id, 'token' => $token, 'try' => $try, 'lastRun' => $this->getTimestamp()]);
     }
     return false;
 }
예제 #15
0
 /**
  * inform remote server whether server-to-server share was accepted/declined
  *
  * @param string $remote
  * @param string $token
  * @param int $remoteId Share id on the remote host
  * @param string $action possible actions: accept, decline, unshare, revoke, permissions
  * @param array $data
  * @param int $try
  * @return boolean
  */
 public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0)
 {
     $fields = array('token' => $token);
     foreach ($data as $key => $value) {
         $fields[$key] = $value;
     }
     $url = $this->addressHandler->removeProtocolFromUrl($remote);
     $result = $this->tryHttpPostToShareEndpoint(rtrim($url, '/'), '/' . $remoteId . '/' . $action, $fields);
     $status = json_decode($result['result'], true);
     if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) {
         return true;
     } elseif ($try === 0) {
         // only add new job on first try
         $this->jobList->add('OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob', ['remote' => $remote, 'remoteId' => $remoteId, 'token' => $token, 'action' => $action, 'data' => json_encode($data), 'try' => $try, 'lastRun' => $this->getTimestamp()]);
     }
     return false;
 }
예제 #16
0
 /**
  * request received to ask remote server for a shared secret
  *
  * @return \OC_OCS_Result
  */
 public function requestSharedSecret()
 {
     $url = $this->request->getParam('url');
     $token = $this->request->getParam('token');
     if ($this->trustedServers->isTrustedServer($url) === false) {
         $this->logger->log(\OCP\Util::ERROR, 'remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']);
         return new \OC_OCS_Result(null, HTTP::STATUS_FORBIDDEN);
     }
     // if both server initiated the exchange of the shared secret the greater
     // token wins
     $localToken = $this->dbHandler->getToken($url);
     if (strcmp($localToken, $token) > 0) {
         $this->logger->log(\OCP\Util::ERROR, 'remote server (' . $url . ') presented lower token', ['app' => 'federation']);
         return new \OC_OCS_Result(null, HTTP::STATUS_FORBIDDEN);
     }
     $this->jobList->add('OCA\\Federation\\BackgroundJob\\GetSharedSecret', ['url' => $url, 'token' => $token]);
     return new \OC_OCS_Result(null, Http::STATUS_OK);
 }
예제 #17
0
 /**
  * re-add background job with new arguments
  *
  * @param IJobList $jobList
  * @param array $argument
  */
 protected function reAddJob(IJobList $jobList, array $argument)
 {
     $jobList->add('OCA\\FederatedFileSharing\\BackgroundJob\\UnShare', ['remote' => $argument['remote'], 'id' => $argument['id'], 'token' => $argument['token'], 'try' => (int) $argument['try'] + 1, 'lastRun' => time()]);
 }