Skip to content

Commit 5caf97f

Browse files
committed
using iclient
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent c291c5c commit 5caf97f

File tree

7 files changed

+46
-50
lines changed

7 files changed

+46
-50
lines changed

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Command/CirclesTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
3434
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
3535
use daita\MySmallPhpTools\Exceptions\RequestServerException;
36+
use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
3637
use daita\MySmallPhpTools\Model\Request;
3738
use daita\MySmallPhpTools\Traits\TArrayTools;
3839
use daita\MySmallPhpTools\Traits\TRequest;
@@ -173,14 +174,9 @@ private function testLocalAddress(OutputInterface $output): bool {
173174
$absolute = $this->urlGenerator->linkToRouteAbsolute('core.CSRFToken.index');
174175
$output->write('- Simple request on ' . $absolute . ': ');
175176

176-
$request = new Request('', Request::TYPE_GET);
177+
$request = new NC19Request('', Request::TYPE_GET);
178+
$this->configService->configureRequest($request);
177179
$request->setAddressFromUrl($absolute);
178-
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
179-
$request->setVerifyPeer(false);
180-
}
181-
if (method_exists($request, 'setFollowLocation')) {
182-
$request->setFollowLocation(false);
183-
}
184180

185181
$this->doRequest($request);
186182
$color = 'error';

lib/Command/MembersCreate.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
3535
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
3636
use daita\MySmallPhpTools\Exceptions\RequestServerException;
37+
use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
3738
use daita\MySmallPhpTools\Model\Request;
3839
use daita\MySmallPhpTools\Traits\TRequest;
3940
use Exception;
@@ -174,10 +175,8 @@ private function findUserFromLookup(string $search, string &$instance = ''): str
174175
return '';
175176
}
176177

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

lib/Search/GlobalScaleUsers.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626

2727
namespace OCA\Circles\Search;
2828

29-
use daita\MySmallPhpTools\Exceptions\RequestContentException;
3029
use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
3130
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
32-
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
33-
use daita\MySmallPhpTools\Exceptions\RequestServerException;
31+
use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
3432
use daita\MySmallPhpTools\Model\Request;
33+
use daita\MySmallPhpTools\Traits\Nextcloud\TNC19Request;
3534
use daita\MySmallPhpTools\Traits\TArrayTools;
36-
use daita\MySmallPhpTools\Traits\TRequest;
3735
use OCA\Circles\Exceptions\GSStatusException;
3836
use OCA\Circles\ISearch;
3937
use OCA\Circles\Model\Member;
@@ -50,7 +48,7 @@
5048
class GlobalScaleUsers implements ISearch {
5149

5250

53-
use TRequest;
51+
use TNC19Request;
5452
use TArrayTools;
5553

5654

@@ -84,24 +82,21 @@ public function search($search) {
8482
return [];
8583
}
8684

87-
$request = new Request('/users', Request::TYPE_GET);
88-
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
89-
$request->setVerifyPeer(false);
90-
}
85+
$request = new NC19Request('/users', Request::TYPE_GET);
86+
$this->configService->configureRequest($request);
9187
$request->setProtocols(['https', 'http']);
9288
$request->addData('search', $search);
9389
$request->setAddressFromUrl($lookup);
9490

9591
try {
9692
$users = $this->retrieveJson($request);
9793
} catch (
98-
RequestContentException |
9994
RequestNetworkException |
100-
RequestResultSizeException |
101-
RequestServerException |
10295
RequestResultNotJsonException $e
10396
) {
104-
$this->miscService->log('Issue while retrieving instances from lookup: ' . get_class($e) . ' ' . $e->getMessage());
97+
$this->miscService->log(
98+
'Issue while retrieving instances from lookup: ' . get_class($e) . ' ' . $e->getMessage()
99+
);
105100

106101
return [];
107102
}

lib/Service/ConfigService.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
namespace OCA\Circles\Service;
2828

29+
use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
2930
use OCA\Circles\Exceptions\GSStatusException;
3031
use OCA\Circles\Model\Circle;
3132
use OCP\IConfig;
@@ -541,5 +542,19 @@ public function getInstanceId() {
541542
return $this->config->getSystemValue('instanceid');
542543
}
543544

545+
546+
/**
547+
* @param NC19Request $request
548+
*/
549+
public function configureRequest(NC19Request $request) {
550+
if ($this->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
551+
$request->setVerifyPeer(false);
552+
}
553+
554+
if ($this->getAppValue(ConfigService::CIRCLES_NON_SSL_LOCAL) === '1') {
555+
$request->setLocalAddressAllowed(true);
556+
}
557+
}
558+
544559
}
545560

lib/Service/GSUpstreamService.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
3636
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
3737
use daita\MySmallPhpTools\Exceptions\RequestServerException;
38+
use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
3839
use daita\MySmallPhpTools\Model\Request;
3940
use daita\MySmallPhpTools\Model\SimpleDataStore;
4041
use daita\MySmallPhpTools\Traits\TArrayTools;
@@ -196,11 +197,8 @@ public function broadcastEvent(GSEvent $event, string $instance, string $protoco
196197
$this->signEvent($event);
197198

198199
$path = $this->urlGenerator->linkToRoute('circles.GlobalScale.broadcast');
199-
$request = new Request($path, Request::TYPE_POST);
200-
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
201-
$request->setVerifyPeer(false);
202-
}
203-
200+
$request = new NC19Request($path, Request::TYPE_POST);
201+
$this->configService->configureRequest($request);
204202
$protocols = ['https', 'http'];
205203
if ($protocol !== '') {
206204
$protocols = [$protocol];
@@ -233,10 +231,9 @@ public function confirmEvent(GSEvent &$event): void {
233231
$owner = $circle->getOwner();
234232
$path = $this->urlGenerator->linkToRoute('circles.GlobalScale.event');
235233

236-
$request = new Request($path, Request::TYPE_POST);
237-
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
238-
$request->setVerifyPeer(false);
239-
}
234+
$request = new NC19Request($path, Request::TYPE_POST);
235+
$this->configService->configureRequest($request);
236+
240237
if ($this->get('REQUEST_SCHEME', $_SERVER) !== '') {
241238
$request->setProtocols([$_SERVER['REQUEST_SCHEME']]);
242239
} else {
@@ -446,11 +443,8 @@ public function confirmCircleStatus(Circle $circle): bool {
446443
$this->signEvent($event);
447444

448445
$path = $this->urlGenerator->linkToRoute('circles.GlobalScale.status');
449-
$request = new Request($path, Request::TYPE_POST);
450-
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
451-
$request->setVerifyPeer(false);
452-
}
453-
446+
$request = new NC19Request($path, Request::TYPE_POST);
447+
$this->configService->configureRequest($request);
454448
$request->setProtocols(['https', 'http']);
455449
$request->setDataSerialize($event);
456450

lib/Service/GlobalScaleService.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
3636
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
3737
use daita\MySmallPhpTools\Exceptions\RequestServerException;
38+
use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
3839
use daita\MySmallPhpTools\Model\Request;
3940
use daita\MySmallPhpTools\Traits\TRequest;
4041
use daita\MySmallPhpTools\Traits\TStringTools;
@@ -140,10 +141,8 @@ public function asyncBroadcast(GSEvent $event): string {
140141
'circles.GlobalScale.asyncBroadcast', ['token' => $wrapper->getToken()]
141142
);
142143

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

149148
try {
@@ -222,10 +221,8 @@ public function getInstances(bool $all = false): array {
222221
/** @var string $lookup */
223222
try {
224223
$lookup = $this->configService->getGSStatus(ConfigService::GS_LOOKUP);
225-
$request = new Request(ConfigService::GS_LOOKUP_INSTANCES, Request::TYPE_POST);
226-
if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
227-
$request->setVerifyPeer(false);
228-
}
224+
$request = new NC19Request(ConfigService::GS_LOOKUP_INSTANCES, Request::TYPE_POST);
225+
$this->configService->configureRequest($request);
229226

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

0 commit comments

Comments
 (0)