Skip to content

Commit

Permalink
Merge pull request #490 from nextcloud/iclient
Browse files Browse the repository at this point in the history
using iclient
  • Loading branch information
ArtificialOwl authored Sep 30, 2020
2 parents c291c5c + 6cdce43 commit 89a90c6
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 50 deletions.
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions lib/Command/CirclesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
use daita\MySmallPhpTools\Exceptions\RequestServerException;
use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TRequest;
Expand Down Expand Up @@ -173,14 +174,9 @@ private function testLocalAddress(OutputInterface $output): bool {
$absolute = $this->urlGenerator->linkToRouteAbsolute('core.CSRFToken.index');
$output->write('- Simple request on ' . $absolute . ': ');

$request = new Request('', Request::TYPE_GET);
$request = new NC19Request('', Request::TYPE_GET);
$this->configService->configureRequest($request);
$request->setAddressFromUrl($absolute);
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
$request->setVerifyPeer(false);
}
if (method_exists($request, 'setFollowLocation')) {
$request->setFollowLocation(false);
}

$this->doRequest($request);
$color = 'error';
Expand Down
7 changes: 3 additions & 4 deletions lib/Command/MembersCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
use daita\MySmallPhpTools\Exceptions\RequestServerException;
use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TRequest;
use Exception;
Expand Down Expand Up @@ -174,10 +175,8 @@ private function findUserFromLookup(string $search, string &$instance = ''): str
return '';
}

$request = new Request('/users', Request::TYPE_GET);
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
$request->setVerifyPeer(false);
}
$request = new NC19Request('/users', Request::TYPE_GET);
$this->configService->configureRequest($request);
$request->setProtocols(['https', 'http']);
$request->addData('search', $search);
$request->setAddressFromUrl($lookup);
Expand Down
21 changes: 8 additions & 13 deletions lib/Search/GlobalScaleUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@

namespace OCA\Circles\Search;

use daita\MySmallPhpTools\Exceptions\RequestContentException;
use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
use daita\MySmallPhpTools\Exceptions\RequestServerException;
use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\Nextcloud\TNC19Request;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TRequest;
use OCA\Circles\Exceptions\GSStatusException;
use OCA\Circles\ISearch;
use OCA\Circles\Model\Member;
Expand All @@ -50,7 +48,7 @@
class GlobalScaleUsers implements ISearch {


use TRequest;
use TNC19Request;
use TArrayTools;


Expand Down Expand Up @@ -84,24 +82,21 @@ public function search($search) {
return [];
}

$request = new Request('/users', Request::TYPE_GET);
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
$request->setVerifyPeer(false);
}
$request = new NC19Request('/users', Request::TYPE_GET);
$this->configService->configureRequest($request);
$request->setProtocols(['https', 'http']);
$request->addData('search', $search);
$request->setAddressFromUrl($lookup);

try {
$users = $this->retrieveJson($request);
} catch (
RequestContentException |
RequestNetworkException |
RequestResultSizeException |
RequestServerException |
RequestResultNotJsonException $e
) {
$this->miscService->log('Issue while retrieving instances from lookup: ' . get_class($e) . ' ' . $e->getMessage());
$this->miscService->log(
'Issue while retrieving instances from lookup: ' . get_class($e) . ' ' . $e->getMessage()
);

return [];
}
Expand Down
15 changes: 15 additions & 0 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace OCA\Circles\Service;

use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
use OCA\Circles\Exceptions\GSStatusException;
use OCA\Circles\Model\Circle;
use OCP\IConfig;
Expand Down Expand Up @@ -541,5 +542,19 @@ public function getInstanceId() {
return $this->config->getSystemValue('instanceid');
}


/**
* @param NC19Request $request
*/
public function configureRequest(NC19Request $request) {
if ($this->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
$request->setVerifyPeer(false);
}

// if ($this->getAppValue(ConfigService::CIRCLES_NON_SSL_LOCAL) === '1') {
$request->setLocalAddressAllowed(true);
// }
}

}

22 changes: 8 additions & 14 deletions lib/Service/GSUpstreamService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
use daita\MySmallPhpTools\Exceptions\RequestServerException;
use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Model\SimpleDataStore;
use daita\MySmallPhpTools\Traits\TArrayTools;
Expand Down Expand Up @@ -196,11 +197,8 @@ public function broadcastEvent(GSEvent $event, string $instance, string $protoco
$this->signEvent($event);

$path = $this->urlGenerator->linkToRoute('circles.GlobalScale.broadcast');
$request = new Request($path, Request::TYPE_POST);
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
$request->setVerifyPeer(false);
}

$request = new NC19Request($path, Request::TYPE_POST);
$this->configService->configureRequest($request);
$protocols = ['https', 'http'];
if ($protocol !== '') {
$protocols = [$protocol];
Expand Down Expand Up @@ -233,10 +231,9 @@ public function confirmEvent(GSEvent &$event): void {
$owner = $circle->getOwner();
$path = $this->urlGenerator->linkToRoute('circles.GlobalScale.event');

$request = new Request($path, Request::TYPE_POST);
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
$request->setVerifyPeer(false);
}
$request = new NC19Request($path, Request::TYPE_POST);
$this->configService->configureRequest($request);

if ($this->get('REQUEST_SCHEME', $_SERVER) !== '') {
$request->setProtocols([$_SERVER['REQUEST_SCHEME']]);
} else {
Expand Down Expand Up @@ -446,11 +443,8 @@ public function confirmCircleStatus(Circle $circle): bool {
$this->signEvent($event);

$path = $this->urlGenerator->linkToRoute('circles.GlobalScale.status');
$request = new Request($path, Request::TYPE_POST);
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
$request->setVerifyPeer(false);
}

$request = new NC19Request($path, Request::TYPE_POST);
$this->configService->configureRequest($request);
$request->setProtocols(['https', 'http']);
$request->setDataSerialize($event);

Expand Down
13 changes: 5 additions & 8 deletions lib/Service/GlobalScaleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
use daita\MySmallPhpTools\Exceptions\RequestServerException;
use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TRequest;
use daita\MySmallPhpTools\Traits\TStringTools;
Expand Down Expand Up @@ -140,10 +141,8 @@ public function asyncBroadcast(GSEvent $event): string {
'circles.GlobalScale.asyncBroadcast', ['token' => $wrapper->getToken()]
);

$request = new Request('', Request::TYPE_PUT);
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
$request->setVerifyPeer(false);
}
$request = new NC19Request('', Request::TYPE_PUT);
$this->configService->configureRequest($request);
$request->setAddressFromUrl($absolute);

try {
Expand Down Expand Up @@ -222,10 +221,8 @@ public function getInstances(bool $all = false): array {
/** @var string $lookup */
try {
$lookup = $this->configService->getGSStatus(ConfigService::GS_LOOKUP);
$request = new Request(ConfigService::GS_LOOKUP_INSTANCES, Request::TYPE_POST);
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
$request->setVerifyPeer(false);
}
$request = new NC19Request(ConfigService::GS_LOOKUP_INSTANCES, Request::TYPE_POST);
$this->configService->configureRequest($request);

$user = $this->getRandomUser();
$data = $this->signer->sign('lookupserver', ['federationId' => $user->getCloudId()], $user);
Expand Down

0 comments on commit 89a90c6

Please sign in to comment.